41 #include "cafDataFieldAccessor.h" 43 #include "cafFieldDocumentationCapability.h" 44 #include "cafFieldJsonCapability.h" 45 #include "cafFieldJsonCapabilitySpecializations.h" 46 #include "cafFieldProxyAccessor.h" 47 #include "cafFieldScriptingCapability.h" 48 #include "cafFieldValidator.h" 49 #include "cafObjectCapability.h" 50 #include "cafObjectHandle.h" 51 #include "cafObjectMacros.h" 57 class UiEditorAttribute;
59 class ObjectCapability;
63 concept DerivesFromFieldHandle = std::is_base_of<FieldHandle, T>::value;
69 template <DerivesFromFieldHandle FieldType>
73 using GetMethod = std::function<typename FieldType::FieldDataType()>;
74 using SetMethod = std::function<void( const typename FieldType::FieldDataType& )>;
78 , m_keyword( keyword )
82 FieldInitHelper& withDefault(
const typename FieldType::FieldDataType& defaultValue )
84 m_field.setDefaultValue( defaultValue );
85 m_field = defaultValue;
89 FieldInitHelper& withScripting(
const std::string& scriptFieldKeyword,
bool readable =
true,
bool writable =
true )
91 m_field.addCapability(
92 std::make_unique<FieldScriptingCapability>( scriptFieldKeyword.empty() ? m_keyword : scriptFieldKeyword,
98 FieldInitHelper& withScripting(
bool readable =
true,
bool writable =
true )
100 m_field.addCapability( std::make_unique<FieldScriptingCapability>( m_keyword, readable, writable ) );
106 m_field.setAccessor( std::move( accessor ) );
112 auto accessor = std::make_unique<caffa::FieldProxyAccessor<typename FieldType::FieldDataType>>();
113 accessor->registerGetMethod( getMethod );
114 return withAccessor( std::move( accessor ) );
119 auto accessor = std::make_unique<caffa::FieldProxyAccessor<typename FieldType::FieldDataType>>();
120 accessor->registerSetMethod( setMethod );
121 return withAccessor( std::move( accessor ) );
124 FieldInitHelper& withProxyGetSetAccessor( GetMethod getMethod, SetMethod setMethod )
126 auto accessor = std::make_unique<caffa::FieldProxyAccessor<typename FieldType::FieldDataType>>();
127 accessor->registerGetMethod( getMethod );
128 accessor->registerSetMethod( setMethod );
129 return withAccessor( std::move( accessor ) );
134 m_field.addValidator( std::move( validator ) );
140 auto doc = std::make_unique<caffa::FieldDocumentationCapability>( documentation );
141 m_field.addCapability( std::move( doc ) );
147 m_field.markDeprecated();
160 const std::string& m_keyword;
168 Object(
bool generateUuid =
true );
169 ~
Object() noexcept
override;
176 template <
typename FieldType>
179 AddIoCapabilityToField( &field );
180 addField( &field, keyword );
192 template <
typename MethodType,
typename CallbackT>
194 const std::string& keyword,
195 const std::vector<std::string>& argumentNames,
196 CallbackT&& callback,
197 MethodHandle::Type type = MethodHandle::Type::READ_WRITE )
199 addMethod( &method, keyword, type );
200 method.setCallback( callback );
201 method.setArgumentNames( argumentNames );
212 template <
typename MethodType,
typename CallbackT>
214 const std::string& keyword,
215 const std::vector<std::string>& argumentNames,
216 CallbackT&& callback,
217 MethodHandle::Type type = MethodHandle::Type::READ_WRITE )
219 addMethod( &method, keyword, type );
220 method.setCallbackWithSession( callback );
221 method.setArgumentNames( argumentNames );
233 template <
typename MethodType,
typename CallbackT>
235 const std::string& keyword,
236 const std::vector<std::string>& argumentNames,
237 const std::string& documentation,
238 CallbackT&& callback,
239 MethodHandle::Type type = MethodHandle::Type::READ_WRITE )
241 addMethod( &method, keyword, type );
242 method.setCallback( callback );
243 method.setArgumentNames( argumentNames );
244 method.setDocumentation( documentation );
255 template <
typename MethodType,
typename CallbackT>
257 const std::string& keyword,
258 const std::vector<std::string>& argumentNames,
259 const std::string& documentation,
260 CallbackT&& callback,
261 MethodHandle::Type type = MethodHandle::Type::READ_WRITE )
263 addMethod( &method, keyword, type );
264 method.setCallbackWithSession( callback );
265 method.setArgumentNames( argumentNames );
266 method.setDocumentation( documentation );
269 std::string uuid()
const override;
270 void setUuid(
const std::string& uuid )
override;
278 ObjectHandle::Ptr deepClone(
caffa::ObjectFactory* optionalObjectFactory =
nullptr )
const override;
287 template <
typename DerivedClass>
290 return std::dynamic_pointer_cast<DerivedClass>( deepClone( optionalObjectFactory ) );
298 bool readFromJsonFile(
const std::string& filePath );
305 bool writeToJsonFile(
const std::string& filePath )
const;
void initMethodWithSession(MethodType &method, const std::string &keyword, const std::vector< std::string > &argumentNames, CallbackT &&callback, MethodHandle::Type type=MethodHandle::Type::READ_WRITE)
Definition: cafObject.h:213
Used to validate the value of data fields Implementations need the the validate method as well as rea...
Definition: cafFieldValidator.h:103
Definition: cafObject.h:70
void initMethodWithDoc(MethodType &method, const std::string &keyword, const std::vector< std::string > &argumentNames, const std::string &documentation, CallbackT &&callback, MethodHandle::Type type=MethodHandle::Type::READ_WRITE)
Definition: cafObject.h:234
Abstract but typed data field accessor. Inherit to create different storage mechanisms.
Definition: cafDataFieldAccessor.h:42
Definition: cafObjectFactory.h:38
Definition: cafObject.h:163
std::shared_ptr< DerivedClass > typedDeepClone(caffa::ObjectFactory *optionalObjectFactory=nullptr) const
Deep clone and cast to the typed class using an optional object factory.
Definition: cafObject.h:288
void initMethod(MethodType &method, const std::string &keyword, const std::vector< std::string > &argumentNames, CallbackT &&callback, MethodHandle::Type type=MethodHandle::Type::READ_WRITE)
Definition: cafObject.h:193
Definition: cafObjectHandle.h:53
void initMethodWithSessionAndDoc(MethodType &method, const std::string &keyword, const std::vector< std::string > &argumentNames, const std::string &documentation, CallbackT &&callback, MethodHandle::Type type=MethodHandle::Type::READ_WRITE)
Definition: cafObject.h:256
FieldInitHelper< FieldType > initField(FieldType &field, const std::string &keyword)
Definition: cafObject.h:177
Main Caffa namespace.
Definition: cafAppEnum.h:38