7 #ifndef __FWDATA_OBJECT_HPP__ 8 #define __FWDATA_OBJECT_HPP__ 10 #include "fwData/config.hpp" 11 #include "fwData/factory/new.hpp" 12 #include "fwData/registry/detail.hpp" 14 #include <fwCamp/macros.hpp> 15 #ifdef CAMP_COMPILATION 16 #include <fwCamp/Mapper/ArrayMapper.hpp> 17 #include <fwCamp/camp/ExtendedClassVisitor.hpp> 18 #include <fwCamp/camp/MapMapper.hpp> 19 #include <fwCamp/camp/MapProperty.hpp> 20 #include <fwCamp/camp/MapValueMapper.hpp> 21 #include <fwCamp/camp/customtype.hpp> 22 #include <fwCamp/camp/detail/MapPropertyImpl.hpp> 25 #include <fwCom/HasSignals.hpp> 26 #include <fwCom/Signal.hpp> 28 #include <fwCore/base.hpp> 29 #include <fwCore/mt/types.hpp> 31 #include <fwTools/Object.hpp> 34 #include <unordered_map> 36 fwCampAutoDeclareDataMacro((
fwData)(Object), FWDATA_API);
53 typedef ::fwData::factory::Key
Key;
71 ::fwData::registry::get()->addFactory(T::classname(), &::fwData::factory::New<T>);
101 typedef std::string FieldNameType;
102 typedef std::vector<FieldNameType> FieldNameVectorType;
103 typedef ::std::unordered_map< FieldNameType, ::fwData::Object::sptr > FieldMapType;
105 typedef ::std::unordered_map< ::fwData::Object::csptr, ::fwData::Object::sptr > DeepCopyCacheType;
113 FWDATA_API ::fwData::Object::sptr getField(
const FieldNameType& name,
114 ::fwData::Object::sptr defaultValue = ::fwData::Object::sptr() )
const;
121 template<
typename DATA_TYPE >
122 SPTR(DATA_TYPE) getField( const FieldNameType &name ) const;
130 template< typename DATA_TYPE >
131 SPTR(DATA_TYPE) getField( const FieldNameType &name,
SPTR(DATA_TYPE) defaultValue ) const;
140 template< typename DATA_TYPE >
141 SPTR(DATA_TYPE) setDefaultField( const FieldNameType &name,
SPTR(DATA_TYPE) defaultValue );
148 FWDATA_API ::
fwData::
Object::csptr getConstField( const FieldNameType& name ) const;
153 FWDATA_API const FieldMapType& getFields() const;
158 FWDATA_API FieldNameVectorType getFieldNames() const;
165 FWDATA_API
void setField( const FieldNameType& name, ::
fwData::
Object::sptr obj );
170 FWDATA_API
void setFields( const FieldMapType& fieldMap );
176 FWDATA_API
void removeField( const FieldNameType& name );
182 FWDATA_API virtual
void shallowCopy( const ::
fwData::
Object::csptr& source );
189 FWDATA_API
void deepCopy( const ::
fwData::
Object::csptr& source );
196 template <typename DATA_TYPE>
197 static
SPTR(DATA_TYPE) copy(const
CSPTR(DATA_TYPE) &source);
198 template <typename DATA_TYPE>
199 static
SPTR(DATA_TYPE) copy(const
SPTR(DATA_TYPE) &source);
206 FWDATA_API
void fieldShallowCopy( const ::
fwData::
Object::csptr& source );
212 FWDATA_API
void fieldDeepCopy( const ::
fwData::
Object::csptr& source );
217 ::
fwCore::mt::ReadWriteMutex &getMutex()
const 222 FWDATA_API
virtual ~
Object();
232 FWDATA_API static ::fwData::Object::sptr copy(const ::fwData::Object::csptr& source, DeepCopyCacheType& cache);
233 FWDATA_API
void fieldDeepCopy( const ::fwData::Object::csptr& source, DeepCopyCacheType& cache );
234 FWDATA_API
virtual void cachedDeepCopy(const ::fwData::Object::csptr& source, DeepCopyCacheType& cache) = 0;
235 template <
typename DATA_TYPE>
236 static SPTR(DATA_TYPE) copy(
const CSPTR(DATA_TYPE) &source, DeepCopyCacheType &cache);
237 template <
typename DATA_TYPE>
238 static SPTR(DATA_TYPE) copy(
const SPTR(DATA_TYPE) &source, DeepCopyCacheType &cache);
241 FieldMapType m_fields;
248 template <
typename DATA_TYPE>
249 SPTR(DATA_TYPE)
Object::copy(const
CSPTR(DATA_TYPE) &source, DeepCopyCacheType &cache)
251 return DATA_TYPE::dynamicCast( ::
fwData::Object::copy(::fwData::Object::csptr(source), cache) );
254 template <
typename DATA_TYPE>
255 SPTR(DATA_TYPE)
Object::copy(const
SPTR(DATA_TYPE) &source, DeepCopyCacheType &cache)
257 return DATA_TYPE::dynamicCast( ::
fwData::Object::copy(::fwData::Object::csptr(source), cache) );
260 template <
typename DATA_TYPE>
266 template <
typename DATA_TYPE>
274 template<
typename DATA_TYPE >
275 SPTR(DATA_TYPE)
Object::getField( const FieldNameType &name )
const 277 ::fwData::Object::sptr field;
278 field = this->getField( name, field );
279 SPTR(DATA_TYPE) result = DATA_TYPE::dynamicCast( field );
285 template<
typename DATA_TYPE >
286 SPTR(DATA_TYPE)
Object::getField( const FieldNameType &name,
SPTR(DATA_TYPE) defaultValue )
const 288 ::fwData::Object::sptr field = defaultValue;
289 field = this->getField( name, field );
290 SPTR(DATA_TYPE) result = DATA_TYPE::dynamicCast( field );
296 template<
typename DATA_TYPE >
297 SPTR(DATA_TYPE)
Object::setDefaultField( const FieldNameType &name,
SPTR(DATA_TYPE) defaultValue )
299 SPTR(DATA_TYPE) result = getField< DATA_TYPE >(name);
300 if( !result && defaultValue)
302 result = defaultValue;
303 this->setField(name, defaultValue);
310 #endif //__FWDATA_OBJECT_HPP__
#define fwCoreNonInstanciableClassDefinitionsMacro(_classinfo_)
Generate common code for Non Instanciable classes (Interfaces, Abstract classes, ...)
::fwCom::Signal< void(FieldsContainerType) > AddedFieldsSignalType
Type of signal when objects are added.
mutable::fwCore::mt::ReadWriteMutex m_mutex
Mutex to protect object access.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
This namespace fwCore provides common foundations for FW4SPL.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_CHANGED_FIELDS_SIG
Type of signal m_sigModified.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_FIELDS_SIG
Type of signal m_sigModified.
std::map< std::string,::fwData::Object::sptr > FieldsContainerType
Type of signal m_sigModified.
Class used to register a class factory in factory registry. This class defines also the object factor...
::fwCom::Signal< void(FieldsContainerType, FieldsContainerType) > ChangedFieldsSignalType
Type of signal when objects are changed (newObjects, oldObjects)
static FWDATA_API::fwData::Object::sptr copy(const ::fwData::Object::csptr &source)
return a copy of the source. if source is a null pointer, return a null pointer.
Base class for each data object.
#define fwCoreAllowSharedFromThis()
Generate getSptr and getConstSptr methods.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_MODIFIED_SIG
Key in m_signals map of signal m_sigModified.
::fwCom::Signal< void(FieldsContainerType) > RemovedFieldsSignalType
Type of signal when objects are removed.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_REMOVED_FIELDS_SIG
Type of signal m_sigModified.
Contains the representation of the data objects used in the framework.
This class proposes a mapping between a SignalKeyType and a SignalBase.