24 #include "cafChildFieldAccessor.h" 25 #include "cafChildFieldHandle.h" 26 #include "cafFieldHandle.h" 27 #include "cafObjectHandle.h" 28 #include "cafObjectHandlePortableDataType.h" 32 #include <type_traits> 42 template <
typename DataTypePtr>
43 requires is_pointer<DataTypePtr>
47 using DataType =
typename std::remove_pointer<DataTypePtr>::type;
48 using Ptr = std::shared_ptr<DataType>;
49 using ConstPtr = std::shared_ptr<const DataType>;
50 using FieldDataType = DataTypePtr;
54 : m_fieldDataAccessor( std::make_unique<ChildFieldDirectStorageAccessor>(
this ) )
56 static_assert( DerivesFromObjectHandle<DataType> &&
57 "Child fields can only contain ObjectHandle-derived objects" );
62 bool empty()
const override {
return !object(); }
67 bool operator==( std::shared_ptr<const ObjectHandle>
object )
const;
72 std::shared_ptr<DataType> object()
74 if ( !m_fieldDataAccessor )
76 std::string errorMessage =
"Failed to get object for '" + this->keyword() +
"': Field is not accessible";
77 CAFFA_ERROR( errorMessage );
78 throw std::runtime_error( errorMessage );
81 return std::dynamic_pointer_cast<DataType>( m_fieldDataAccessor->object() );
83 std::shared_ptr<const DataType> object()
const 85 if ( !m_fieldDataAccessor )
87 std::string errorMessage =
"Failed to get object for '" + this->keyword() +
"': Field is not accessible";
88 CAFFA_ERROR( errorMessage );
89 throw std::runtime_error( errorMessage );
92 return std::dynamic_pointer_cast<
const DataType>( m_fieldDataAccessor->object() );
94 void setObject( Ptr
object );
97 operator std::shared_ptr<DataType>() {
return this->object(); }
98 operator std::shared_ptr<const DataType>()
const {
return this->object(); }
100 operator bool()
const {
return !!this->object(); }
102 std::shared_ptr<DataType> operator->() {
return this->object(); }
103 std::shared_ptr<const DataType> operator->()
const {
return this->object(); }
105 std::shared_ptr<DataType> operator()() {
return this->object(); }
106 std::shared_ptr<const DataType> operator()()
const {
return this->object(); }
109 std::vector<std::shared_ptr<ObjectHandle>> childObjects()
override;
110 std::vector<std::shared_ptr<const ObjectHandle>> childObjects()
const override;
111 void clear()
override;
112 void removeChildObject( std::shared_ptr<const ObjectHandle>
object );
113 void setChildObject( std::shared_ptr<ObjectHandle>
object )
override;
117 bool isReadable()
const override {
return m_fieldDataAccessor !=
nullptr && m_fieldDataAccessor->hasGetter(); }
118 bool isWritable()
const override {
return m_fieldDataAccessor !=
nullptr && m_fieldDataAccessor->hasSetter(); }
120 void setAccessor( std::unique_ptr<ChildFieldAccessor> accessor )
override 122 m_fieldDataAccessor = std::move( accessor );
125 std::string
childClassKeyword()
const override {
return std::string( DataType::classKeywordStatic() ); }
131 mutable std::unique_ptr<ChildFieldAccessor> m_fieldDataAccessor;
136 #include "cafChildField.inl" Field class to handle a pointer to a caffa Object.
Definition: cafChildField.h:44
Definition: cafChildFieldHandle.h:53
bool isWritable() const override
Definition: cafChildField.h:118
bool isReadable() const override
Definition: cafChildField.h:117
Definition: cafObjectHandle.h:47
Definition: cafPortableDataType.h:35
std::string childClassKeyword() const override
Get the class keyword of the contained child(ren)
Definition: cafChildField.h:125
Main Caffa namespace.
Definition: cafApplication.h:30