mirror of
https://github.com/OPM/ResInsight.git
synced 2025-02-25 18:55:39 -06:00
* Refactor interface to PdmObjectHandle and PdmFieldHandle Return objects instead of passing in structures as parameters * Add nodiscard to several functions * Remove redundant this-> * Rename to ptrReferencedObjectsByType
118 lines
4.1 KiB
C++
118 lines
4.1 KiB
C++
#pragma once
|
|
|
|
#include "cafPdmPtrArrayFieldHandle.h"
|
|
|
|
#include "cafAssert.h"
|
|
#include "cafPdmFieldHandle.h"
|
|
#include "cafPdmPointer.h"
|
|
|
|
#include <memory>
|
|
|
|
namespace caf
|
|
{
|
|
template <typename T>
|
|
class PdmFieldXmlCap;
|
|
|
|
//==================================================================================================
|
|
///
|
|
///
|
|
///
|
|
//==================================================================================================
|
|
class PdmChildArrayFieldHandle : public PdmPtrArrayFieldHandle
|
|
{
|
|
public:
|
|
PdmChildArrayFieldHandle() {}
|
|
~PdmChildArrayFieldHandle() override {}
|
|
|
|
virtual void deleteChildren() = 0;
|
|
|
|
bool hasSameFieldCountForAllObjects();
|
|
};
|
|
|
|
//==================================================================================================
|
|
/// PdmFieldClass to handle a collection of PdmObject derived pointers
|
|
/// The reasons for this class is to add itself as parentField into the objects being pointed to.
|
|
/// The interface is made similar to std::vector<>, and the complexity of the methods is similar too.
|
|
//==================================================================================================
|
|
|
|
template <typename DataType>
|
|
class PdmChildArrayField : public PdmFieldHandle
|
|
{
|
|
public:
|
|
PdmChildArrayField()
|
|
{
|
|
bool doNotUsePdmPointersFieldForAnythingButPointersToPdmObject = false;
|
|
CAF_ASSERT( doNotUsePdmPointersFieldForAnythingButPointersToPdmObject );
|
|
}
|
|
};
|
|
|
|
template <typename DataType>
|
|
class PdmChildArrayField<DataType*> : public PdmChildArrayFieldHandle
|
|
{
|
|
typedef DataType* DataTypePtr;
|
|
typedef std::unique_ptr<DataType> DataTypeUniquePtr;
|
|
|
|
public:
|
|
PdmChildArrayField() {}
|
|
~PdmChildArrayField() override;
|
|
|
|
PdmChildArrayField& operator()() { return *this; }
|
|
const PdmChildArrayField& operator()() const { return *this; }
|
|
|
|
// Reimplementation of PdmPointersFieldHandle methods
|
|
|
|
size_t size() const override { return m_pointers.size(); }
|
|
bool empty() const override { return m_pointers.empty(); }
|
|
void clearWithoutDelete() override;
|
|
void deleteChildren() override;
|
|
void insertAt( int indexAfter, PdmObjectHandle* obj ) override;
|
|
void insertAt( int indexAfter, std::unique_ptr<PdmObjectHandle> obj );
|
|
PdmObjectHandle* at( size_t index ) override;
|
|
void setValue( const std::vector<DataType*>& objects );
|
|
size_t indexOf( const PdmObjectHandle* obj ) const override;
|
|
|
|
virtual void deleteChildrenAsync();
|
|
|
|
// std::vector-like access
|
|
|
|
DataType* operator[]( size_t index ) const;
|
|
|
|
void push_back( DataTypePtr pointer );
|
|
void push_back( DataTypeUniquePtr pointer );
|
|
void set( size_t index, DataTypePtr pointer );
|
|
void set( size_t index, DataTypeUniquePtr pointer );
|
|
void insert( size_t indexAfter, DataTypePtr pointer );
|
|
void insert( size_t indexAfter, DataTypeUniquePtr pointer );
|
|
void insert( size_t indexAfter, const std::vector<PdmPointer<DataType>>& objects );
|
|
size_t count( const DataType* pointer ) const;
|
|
|
|
void erase( size_t index ) override;
|
|
|
|
typename std::vector<PdmPointer<DataType>>::iterator begin() { return m_pointers.begin(); };
|
|
typename std::vector<PdmPointer<DataType>>::iterator end() { return m_pointers.end(); };
|
|
|
|
typename std::vector<PdmPointer<DataType>>::const_iterator begin() const { return m_pointers.begin(); };
|
|
typename std::vector<PdmPointer<DataType>>::const_iterator end() const { return m_pointers.end(); };
|
|
|
|
// Child objects
|
|
std::vector<DataType*> childrenByType() const;
|
|
|
|
[[nodiscard]] std::vector<PdmObjectHandle*> children() const override;
|
|
void removeChild( PdmObjectHandle* object ) override;
|
|
|
|
private: // To be disabled
|
|
PDM_DISABLE_COPY_AND_ASSIGN( PdmChildArrayField );
|
|
|
|
private:
|
|
void removeThisAsParentField();
|
|
void addThisAsParentField();
|
|
|
|
private:
|
|
friend class PdmFieldXmlCap<PdmChildArrayField<DataType*>>;
|
|
std::vector<PdmPointer<DataType>> m_pointers;
|
|
};
|
|
|
|
} // End of namespace caf
|
|
|
|
#include "cafPdmChildArrayField.inl"
|