fw4spl
SrcLib/core/fwData/src/fwData/Composite.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2015.
3  * Distributed under the terms of the GNU Lesser General Public License (LGPL) as
4  * published by the Free Software Foundation.
5  * ****** END LICENSE BLOCK ****** */
6 
7 #include "fwData/registry/macros.hpp"
8 #include "fwData/Exception.hpp"
9 #include "fwData/Composite.hpp"
10 
11 #include <fwCom/Signal.hpp>
12 #include <fwCom/Signal.hxx>
13 
14 #include <algorithm>
15 
16 
17 fwDataRegisterMacro( ::fwData::Composite );
18 
19 namespace fwData
20 {
21 
22 const ::fwCom::Signals::SignalKeyType Composite::s_ADDED_OBJECTS_SIG = "addedObjects";
23 const ::fwCom::Signals::SignalKeyType Composite::s_CHANGED_OBJECTS_SIG = "changedObjects";
24 const ::fwCom::Signals::SignalKeyType Composite::s_REMOVED_OBJECTS_SIG = "removedObjects";
25 
26 //------------------------------------------------------------------------------
27 
29 {
30  newSignal< AddedObjectsSignalType >(s_ADDED_OBJECTS_SIG);
31  newSignal< ChangedObjectsSignalType >(s_CHANGED_OBJECTS_SIG);
32  newSignal< RemovedObjectsSignalType >(s_REMOVED_OBJECTS_SIG);
33 }
34 
35 //------------------------------------------------------------------------------
36 
38 {
39 }
40 
41 //------------------------------------------------------------------------------
42 
43 void Composite::shallowCopy(const Object::csptr &_source )
44 {
45  Composite::csptr other = Composite::dynamicConstCast(_source);
46  FW_RAISE_EXCEPTION_IF( ::fwData::Exception(
47  "Unable to copy" + (_source ? _source->getClassname() : std::string("<NULL>"))
48  + " to " + this->getClassname()), !bool(other) );
49  this->fieldShallowCopy( _source );
50  m_container.clear();
51 
52  m_container = other->m_container;
53 }
54 
55 //------------------------------------------------------------------------------
56 
57 void Composite::cachedDeepCopy(const Object::csptr &_source, DeepCopyCacheType &cache)
58 {
59  Composite::csptr other = Composite::dynamicConstCast(_source);
60  FW_RAISE_EXCEPTION_IF( ::fwData::Exception(
61  "Unable to copy" + (_source ? _source->getClassname() : std::string("<NULL>"))
62  + " to " + this->getClassname()), !bool(other) );
63  this->fieldDeepCopy( _source, cache );
64 
65  m_container.clear();
66 
67  for(const ValueType &elem : *other)
68  {
69  m_container.insert( ValueType(elem.first, ::fwData::Object::copy(elem.second, cache) ) );
70  }
71 }
72 
73 //------------------------------------------------------------------------------
74 
75 }
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_CHANGED_OBJECTS_SIG
Type of signal when objects are added.
Implements data exception class.
FWDATA_API void shallowCopy(const Object::csptr &_source) override
Defines shallow copy.
FWDATA_API void fieldDeepCopy(const ::fwData::Object::csptr &source)
A deep copy of fields (objects in m_children)
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_REMOVED_OBJECTS_SIG
Type of signal when objects are added.
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.
virtual const std::string & getClassname() const override
return full object&#39;s classname with its namespace, i.e. fwCore::BaseObject
FWDATA_API Composite(::fwData::Object::Key key)
Constructor.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_OBJECTS_SIG
Type of signal when objects are added.
Contains the representation of the data objects used in the framework.
This class defines a composite object.
FWDATA_API void fieldShallowCopy(const ::fwData::Object::csptr &source)
A shallow copy of fields (objects in m_children)
virtual FWDATA_API ~Composite()
Destructor.
FWDATA_API void cachedDeepCopy(const Object::csptr &_source, DeepCopyCacheType &cache) override
Defines deep copy.