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;
66 template <
typename FieldType>
70 using GetMethod = std::function<
typename FieldType::FieldDataType()>;
71 using SetMethod = std::function<void(
const typename FieldType::FieldDataType& )>;
75 , m_keyword( keyword )
79 FieldInitHelper& withDefault(
const typename FieldType::FieldDataType& defaultValue )
81 m_field.setDefaultValue( defaultValue );
82 m_field = defaultValue;
86 FieldInitHelper& withScripting(
const std::string& scriptFieldKeyword,
bool readable =
true,
bool writable =
true )
88 m_field.addCapability(
89 std::make_unique<FieldScriptingCapability>( scriptFieldKeyword.empty() ? m_keyword : scriptFieldKeyword,
95 FieldInitHelper& withScripting(
bool readable =
true,
bool writable =
true )
97 m_field.addCapability( std::make_unique<FieldScriptingCapability>( m_keyword, readable, writable ) );
103 m_field.setAccessor( std::move( accessor ) );
109 auto accessor = std::make_unique<caffa::FieldProxyAccessor<typename FieldType::FieldDataType>>();
110 accessor->registerGetMethod( getMethod );
111 return withAccessor( std::move( accessor ) );
116 auto accessor = std::make_unique<caffa::FieldProxyAccessor<typename FieldType::FieldDataType>>();
117 accessor->registerSetMethod( setMethod );
118 return withAccessor( std::move( accessor ) );
121 FieldInitHelper& withProxyGetSetAccessor( GetMethod getMethod, SetMethod setMethod )
123 auto accessor = std::make_unique<caffa::FieldProxyAccessor<typename FieldType::FieldDataType>>();
124 accessor->registerGetMethod( getMethod );
125 accessor->registerSetMethod( setMethod );
126 return withAccessor( std::move( accessor ) );
131 m_field.addValidator( std::move( validator ) );
137 auto doc = std::make_unique<caffa::FieldDocumentationCapability>( documentation );
138 m_field.addCapability( std::move( doc ) );
151 const std::string& m_keyword;
159 Object(
bool generateUuid =
true );
160 ~
Object() noexcept
override;
167 template <
typename FieldType>
170 AddIoCapabilityToField( &field );
183 template <
typename MethodType,
typename CallbackT>
185 const std::string& keyword,
186 const std::vector<std::string>& argumentNames,
187 CallbackT&& callback,
188 MethodHandle::Type type = MethodHandle::Type::READ_WRITE )
191 method.setCallback( callback );
192 method.setArgumentNames( argumentNames );
204 template <
typename MethodType,
typename CallbackT>
206 const std::string& keyword,
207 const std::vector<std::string>& argumentNames,
208 const std::string& documentation,
209 CallbackT&& callback,
210 MethodHandle::Type type = MethodHandle::Type::READ_WRITE )
213 method.setCallback( callback );
214 method.setArgumentNames( argumentNames );
215 method.setDocumentation( documentation );
218 std::string uuid()
const override;
219 void setUuid(
const std::string& uuid )
override;
227 ObjectHandle::Ptr deepClone(
caffa::ObjectFactory* optionalObjectFactory =
nullptr )
const override;
236 template <
typename DerivedClass>
239 return std::dynamic_pointer_cast<DerivedClass>(
deepClone( optionalObjectFactory ) );
247 bool readFromJsonFile(
const std::string& filePath );
254 bool writeToJsonFile(
const std::string& filePath )
const;
Abstract but typed data field accessor. Inherit to create different storage mechanisms.
Definition: cafDataFieldAccessor.h:43
Definition: cafObject.h:68
Used to validate the value of data fields Implementations need the the validate method as well as rea...
Definition: cafFieldValidator.h:104
Definition: cafObjectFactory.h:39
Definition: cafObjectHandle.h:55
void addMethod(MethodHandle *method, const std::string &keyword, MethodHandle::Type type)
Definition: cafObjectHandle.cpp:106
void addField(FieldHandle *field, const std::string &keyword)
Definition: cafObjectHandle.cpp:91
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:184
ObjectHandle::Ptr deepClone(caffa::ObjectFactory *optionalObjectFactory=nullptr) const override
Deep clone the object using an optional object factory.
Definition: cafObject.cpp:53
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:205
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:237
FieldInitHelper< FieldType > initField(FieldType &field, const std::string &keyword)
Definition: cafObject.h:168
Main Caffa namespace.
Definition: __init__.py:1