24 #include "cafAssert.h" 25 #include "cafChildArrayFieldAccessor.h" 26 #include "cafChildArrayFieldHandle.h" 27 #include "cafObjectHandle.h" 28 #include "cafObjectHandlePortableDataType.h" 39 template <
typename DataTypePtr>
40 requires is_pointer<DataTypePtr>
44 using DataType =
typename std::remove_pointer<DataTypePtr>::type;
46 using Ptr = std::shared_ptr<DataType>;
47 using ConstPtr = std::shared_ptr<const DataType>;
48 using FieldDataType = DataTypePtr;
54 : m_fieldDataAccessor( std::make_unique<DirectStorageAccessor>(
this ) )
56 static_assert( std::is_base_of<ObjectHandle, DataType>::value &&
57 "Child Array fields can only contain ObjectHandle-derived objects" );
62 operator std::vector<std::shared_ptr<DataType>>() {
return this->objects(); }
63 operator std::vector<std::shared_ptr<const DataType>>()
const {
return this->objects(); }
65 size_t size()
const override {
return m_fieldDataAccessor->size(); }
66 void clear()
override;
67 std::shared_ptr<ObjectHandle>
at(
size_t index )
override;
68 std::vector<std::shared_ptr<DataType>> objects();
69 std::vector<std::shared_ptr<const DataType>> objects()
const;
70 void setObjects( std::vector<std::shared_ptr<DataType>>& objects );
74 std::shared_ptr<DataType> operator[](
size_t index )
const;
76 void push_back( std::shared_ptr<DataType> pointer );
77 void push_back_obj( std::shared_ptr<ObjectHandle> obj )
override;
78 void insert(
size_t index, std::shared_ptr<DataType> pointer );
79 void insertAt(
size_t index, std::shared_ptr<ObjectHandle> obj )
override;
80 void erase(
size_t index )
override;
83 std::vector<std::shared_ptr<ObjectHandle>> childObjects()
override;
84 std::vector<std::shared_ptr<const ObjectHandle>> childObjects()
const override;
89 bool isReadable()
const override {
return m_fieldDataAccessor !=
nullptr && m_fieldDataAccessor->hasGetter(); }
90 bool isWritable()
const override {
return m_fieldDataAccessor !=
nullptr && m_fieldDataAccessor->hasSetter(); }
92 void setAccessor( std::unique_ptr<ChildArrayFieldAccessor> accessor )
override 94 m_fieldDataAccessor = std::move( accessor );
97 virtual std::string
childClassKeyword()
const override {
return std::string( DataType::classKeywordStatic() ); }
104 std::unique_ptr<DataAccessor> m_fieldDataAccessor;
109 #include "cafChildArrayField.inl" void push_back(std::shared_ptr< DataType > pointer)
Assign a shared pointer.
Definition: cafChildArrayField.inl:64
A non-templated base interface for ChildArrayField<DataType*> Used so we can have pointers to any Chi...
Definition: cafChildArrayFieldHandle.h:38
void insertAt(size_t index, std::shared_ptr< ObjectHandle > obj) override
Insert an object at a particular index. Ownership will be taken.
Definition: cafChildArrayField.inl:120
virtual std::string childClassKeyword() const override
Get the class keyword of the contained child(ren)
Definition: cafChildArrayField.h:97
void push_back_obj(std::shared_ptr< ObjectHandle > obj) override
Assign a shared pointer.
Definition: cafChildArrayField.inl:83
void clear() override
Clears the container.
Definition: cafChildArrayField.inl:135
bool isReadable() const override
Definition: cafChildArrayField.h:89
void erase(size_t index) override
Removes the pointer at index from the container and deletes the object pointed to.
Definition: cafChildArrayField.inl:152
~ChildArrayField() override
Implementation of ChildArrayField<>
Definition: cafChildArrayField.inl:35
size_t size() const override
Get the number of child objects.
Definition: cafChildArrayField.h:65
std::shared_ptr< ObjectHandle > at(size_t index) override
Get a raw pointer to the object at a particular index.
Definition: cafChildArrayField.inl:283
void insert(size_t index, std::shared_ptr< DataType > pointer)
Definition: cafChildArrayField.inl:100
Field class to handle a collection of Object derived pointers The ChildArrayField will take over owne...
Definition: cafChildArrayField.h:41
Definition: cafPortableDataType.h:35
Definition: cafChildArrayFieldAccessor.h:64
void setAccessor(std::unique_ptr< ChildArrayFieldAccessor > accessor) override
Set a new accessor.
Definition: cafChildArrayField.h:92
Main Caffa namespace.
Definition: cafApplication.h:30
Definition: cafChildArrayFieldAccessor.h:29
bool isWritable() const override
Definition: cafChildArrayField.h:90
void removeChildObject(std::shared_ptr< const ObjectHandle > object)
Removes all instances of object pointer from the container without deleting the object.
Definition: cafChildArrayField.inl:187
void setObjects(std::vector< std::shared_ptr< DataType >> &objects)
Assign objects to the field, replacing the current child objects.
Definition: cafChildArrayField.inl:171