mirror of
https://github.com/OPM/ResInsight.git
synced 2026-11-02 09:00:14 -06:00
#6106 Apply clang-format on AppFwk
This commit is contained in:
1 parent
e2ef6a910b
commit
bdc536dfc4
407 files changed
+88976
-42309
No files matched your search
@@ -34,73 +34,101 @@
|
||||
//
|
||||
//##################################################################################################
|
||||
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstddef>
|
||||
|
||||
|
||||
namespace caf
|
||||
namespace caf
|
||||
{
|
||||
|
||||
class PdmObjectHandle;
|
||||
|
||||
//==================================================================================================
|
||||
/// Helper class for the PdmPointer class
|
||||
/// The add and removing of references is put into a pure static class to
|
||||
/// The add and removing of references is put into a pure static class to
|
||||
/// resolve circular include problems.
|
||||
//
|
||||
/// Overall idea of the referencing system:
|
||||
/// The addressToObjectPointer is added to a std::set in the object pointed to.
|
||||
/// when the object pointed to is deleted, its destructor sets the object pointers
|
||||
/// when the object pointed to is deleted, its destructor sets the object pointers
|
||||
/// it has addresses to to NULL
|
||||
//==================================================================================================
|
||||
|
||||
class PdmPointerImpl
|
||||
{
|
||||
private:
|
||||
template < class T > friend class PdmPointer;
|
||||
static void addReference(PdmObjectHandle ** addressToObjectPointer);
|
||||
static void removeReference(PdmObjectHandle ** addressToObjectPointer);
|
||||
template <class T>
|
||||
friend class PdmPointer;
|
||||
static void addReference( PdmObjectHandle** addressToObjectPointer );
|
||||
static void removeReference( PdmObjectHandle** addressToObjectPointer );
|
||||
};
|
||||
|
||||
//==================================================================================================
|
||||
/// Guarded pointer class to point at PdmObjects
|
||||
/// Use a PdmPointer<SomePdmObject> in the same way as a normal pointer.
|
||||
/// Use a PdmPointer<SomePdmObject> in the same way as a normal pointer.
|
||||
/// The guarding sets the pointer to NULL if the object pointed to dies
|
||||
///
|
||||
/// NOTE: This is not reference counting. The user is responsible to delete the objects pointed to.
|
||||
/// It _can_ be used together with the cvf::ref system if neccesary (this is no recomendation)
|
||||
//==================================================================================================
|
||||
|
||||
template < class T >
|
||||
template <class T>
|
||||
class PdmPointer
|
||||
{
|
||||
PdmObjectHandle* m_object;
|
||||
public :
|
||||
inline PdmPointer () : m_object(nullptr) { }
|
||||
inline PdmPointer ( T * p ) : m_object(p) { PdmPointerImpl::addReference(&m_object); }
|
||||
inline PdmPointer ( const PdmPointer<T> & p ) : m_object ( p.m_object )
|
||||
{ PdmPointerImpl::addReference(&m_object); }
|
||||
inline ~PdmPointer () { PdmPointerImpl::removeReference(&m_object); }
|
||||
|
||||
T* p() const { return static_cast<T*>(const_cast<PdmObjectHandle*>(m_object)); }
|
||||
bool isNull() const { return !m_object; }
|
||||
bool notNull() const { return !isNull(); }
|
||||
operator T* () const { return static_cast<T*>(const_cast<PdmObjectHandle*>(m_object)); }
|
||||
T& operator* () const { return *static_cast<T*>(const_cast<PdmObjectHandle*>(m_object)); }
|
||||
T* operator->() const { return static_cast<T*>(const_cast<PdmObjectHandle*>(m_object)); }
|
||||
PdmPointer<T> & operator= ( const PdmPointer<T>& p ) { if (this != &p) PdmPointerImpl::removeReference(&m_object); m_object = p.m_object; PdmPointerImpl::addReference(&m_object); return *this; }
|
||||
PdmPointer<T> & operator= ( T* p ) { if (m_object != p) PdmPointerImpl::removeReference(&m_object); m_object = p; PdmPointerImpl::addReference(&m_object); return *this; }
|
||||
public:
|
||||
inline PdmPointer()
|
||||
: m_object( nullptr )
|
||||
{
|
||||
}
|
||||
inline PdmPointer( T* p )
|
||||
: m_object( p )
|
||||
{
|
||||
PdmPointerImpl::addReference( &m_object );
|
||||
}
|
||||
inline PdmPointer( const PdmPointer<T>& p )
|
||||
: m_object( p.m_object )
|
||||
{
|
||||
PdmPointerImpl::addReference( &m_object );
|
||||
}
|
||||
inline ~PdmPointer() { PdmPointerImpl::removeReference( &m_object ); }
|
||||
|
||||
T* p() const { return static_cast<T*>( const_cast<PdmObjectHandle*>( m_object ) ); }
|
||||
bool isNull() const { return !m_object; }
|
||||
bool notNull() const { return !isNull(); }
|
||||
operator T*() const { return static_cast<T*>( const_cast<PdmObjectHandle*>( m_object ) ); }
|
||||
T& operator*() const { return *static_cast<T*>( const_cast<PdmObjectHandle*>( m_object ) ); }
|
||||
T* operator->() const { return static_cast<T*>( const_cast<PdmObjectHandle*>( m_object ) ); }
|
||||
PdmPointer<T>& operator=( const PdmPointer<T>& p )
|
||||
{
|
||||
if ( this != &p ) PdmPointerImpl::removeReference( &m_object );
|
||||
m_object = p.m_object;
|
||||
PdmPointerImpl::addReference( &m_object );
|
||||
return *this;
|
||||
}
|
||||
PdmPointer<T>& operator=( T* p )
|
||||
{
|
||||
if ( m_object != p ) PdmPointerImpl::removeReference( &m_object );
|
||||
m_object = p;
|
||||
PdmPointerImpl::addReference( &m_object );
|
||||
return *this;
|
||||
}
|
||||
template <class S>
|
||||
bool operator==(const PdmPointer<S>& rhs) const { return m_object == rhs.rawPtr(); }
|
||||
bool operator==( const PdmPointer<S>& rhs ) const
|
||||
{
|
||||
return m_object == rhs.rawPtr();
|
||||
}
|
||||
// Private methods used by PdmField<T*> and PdmPointersField<T*>. Do not use unless you mean it !
|
||||
PdmObjectHandle* rawPtr() const { return m_object; }
|
||||
void setRawPtr( PdmObjectHandle* p) { if (m_object != p) PdmPointerImpl::removeReference(&m_object); m_object = p; PdmPointerImpl::addReference(&m_object); }
|
||||
PdmObjectHandle* rawPtr() const { return m_object; }
|
||||
void setRawPtr( PdmObjectHandle* p )
|
||||
{
|
||||
if ( m_object != p ) PdmPointerImpl::removeReference( &m_object );
|
||||
m_object = p;
|
||||
PdmPointerImpl::addReference( &m_object );
|
||||
}
|
||||
};
|
||||
|
||||
} // End of namespace caf
|
||||
|
||||
#include <QMetaType>
|
||||
Q_DECLARE_METATYPE(caf::PdmPointer<caf::PdmObjectHandle>);
|
||||
|
||||
Q_DECLARE_METATYPE( caf::PdmPointer<caf::PdmObjectHandle> );
|
||||
Reference in new issue
Block a user