fw4spl
src/fwData/Vector.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/Vector.hpp"
10 
11 #include <fwCom/Signal.hpp>
12 #include <fwCom/Signal.hxx>
13 
14 fwDataRegisterMacro( ::fwData::Vector );
15 
16 namespace fwData
17 {
18 
19 const ::fwCom::Signals::SignalKeyType Vector::s_ADDED_OBJECTS_SIG = "addedObjects";
20 const ::fwCom::Signals::SignalKeyType Vector::s_REMOVED_OBJECTS_SIG = "removedObjects";
21 
22 //------------------------------------------------------------------------------
23 
25 {
26  newSignal< AddedObjectsSignalType >(s_ADDED_OBJECTS_SIG);
27  newSignal< RemovedObjectsSignalType >(s_REMOVED_OBJECTS_SIG);
28 }
29 
30 //------------------------------------------------------------------------------
31 
33 {
34 }
35 
36 //------------------------------------------------------------------------------
37 
38 void Vector::shallowCopy(const Object::csptr &_source )
39 {
40  Vector::csptr other = Vector::dynamicConstCast(_source);
41  FW_RAISE_EXCEPTION_IF( ::fwData::Exception(
42  "Unable to copy" + (_source ? _source->getClassname() : std::string("<NULL>"))
43  + " to " + this->getClassname()), !bool(other) );
44  this->fieldShallowCopy( _source );
45  m_container = other->m_container;
46 }
47 
48 //------------------------------------------------------------------------------
49 
50 void Vector::cachedDeepCopy(const Object::csptr &source, DeepCopyCacheType &cache)
51 {
52  Vector::csptr other = Vector::dynamicConstCast(source);
53  FW_RAISE_EXCEPTION_IF( ::fwData::Exception(
54  "Unable to copy" + (source ? source->getClassname() : std::string("<NULL>"))
55  + " to " + this->getClassname()), !bool(other) );
56  this->fieldDeepCopy( source, cache );
57  m_container.clear();
58  m_container.reserve(other->m_container.size());
59  for(const ContainerType::value_type &obj : other->m_container)
60  {
61  m_container.push_back( ::fwData::Object::copy(obj, cache) );
62  }
63 }
64 
65 //------------------------------------------------------------------------------
66 
67 }
FWDATA_API void shallowCopy(const Object::csptr &_source) override
Defines shallow copy.
FWDATA_API Vector(::fwData::Object::Key key)
Constructor.
Key class used to restrict access to Object construction. See http://www.drdobbs.com/184402053.
FWDATA_API void cachedDeepCopy(const Object::csptr &_source, DeepCopyCacheType &cache) override
Defines deep copy.
Implements data exception class.
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_ADDED_OBJECTS_SIG
Type of signal when objects are added.
virtual const std::string & getClassname() const override
return full object&#39;s classname with its namespace, i.e. fwCore::BaseObject
This class defines a vector of objects.
FWDATA_API void fieldDeepCopy(const ::fwData::Object::csptr &source)
A deep copy of fields (objects in m_children)
virtual FWDATA_API ~Vector()
Destructor.
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.
Contains the representation of the data objects used in the framework.
FWDATA_API void fieldShallowCopy(const ::fwData::Object::csptr &source)
A shallow copy of fields (objects in m_children)
static FWDATA_APIconst::fwCom::Signals::SignalKeyType s_REMOVED_OBJECTS_SIG
Type of signal when objects are added.