fw4spl
SrcLib/core/fwAtoms/src/fwAtoms/Object.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2017.
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 "fwAtoms/Object.hpp"
8 
9 #include "fwAtoms/registry/macros.hpp"
10 
11 #include <fwCamp/UserObject.hpp>
12 
13 fwAtomsRegisterMacro( ::fwAtoms::Object );
14 
15 namespace fwAtoms
16 {
17 
18 //------------------------------------------------------------------------------
19 
20 void Object::setAttribute(const std::string& key, const Base::sptr& value)
21 {
22  m_attributes[key] = value;
23 }
24 
25 //------------------------------------------------------------------------------
26 
27 Base::sptr Object::getAttribute(const std::string& key) const
28 {
29  AttributesType::const_iterator iterAttr = m_attributes.find(key);
30  if (iterAttr != m_attributes.end())
31  {
32  return iterAttr->second;
33  }
34  return Base::sptr();
35 }
36 
37 //------------------------------------------------------------------------------
38 
39 void Object::setAttributes(const Object::AttributesType& attrs)
40 {
41  m_attributes = attrs;
42 }
43 
44 //------------------------------------------------------------------------------
45 
46 Base::sptr Object::clone() const
47 {
48  Object::sptr obj = Object::New();
49  obj->m_metaInfos = m_metaInfos;
50 
51  for(const AttributesType::value_type& elem : m_attributes)
52  {
53  if ( elem.second )
54  {
55  obj->m_attributes.insert( AttributesType::value_type(elem.first, elem.second->clone() ) );
56  }
57  else
58  {
59  Base::sptr nullData;
60  obj->m_attributes.insert( AttributesType::value_type(elem.first, nullData) );
61  }
62  }
63 
64  return obj;
65 }
66 
67 //------------------------------------------------------------------------------
68 
69 void Object::setMetaInfo(const std::string& key, const std::string& value)
70 {
71  m_metaInfos[key] = value;
72 }
73 
74 //------------------------------------------------------------------------------
75 
76 std::string Object::getMetaInfo(const std::string& key) const
77 {
78  MetaInfosType::const_iterator iterMetaInfos = m_metaInfos.find(key);
79  if(iterMetaInfos != m_metaInfos.end())
80  {
81  return iterMetaInfos->second;
82  }
83  return "";
84 }
85 
86 //------------------------------------------------------------------------------
87 
88 void Object::setMetaInfos(const MetaInfosType& metaInfos)
89 {
90  m_metaInfos = metaInfos;
91 }
92 
93 //------------------------------------------------------------------------------
94 
95 Object::AttributesType::size_type Object::eraseAttribute(const std::string& key)
96 {
97  return m_attributes.erase(key);
98 }
99 
100 //------------------------------------------------------------------------------
101 
103 {
104  m_attributes.clear();
105 }
106 
107 //------------------------------------------------------------------------------
108 
109 Object::MetaInfosType::size_type Object::eraseMetaInfo(const std::string& key)
110 {
111  return m_metaInfos.erase(key);
112 }
113 
114 //------------------------------------------------------------------------------
115 
117 {
118  m_metaInfos.clear();
119 }
120 
121 } // namespace fwAtoms
122 
FWATOMS_API void setAttribute(const std::string &key, const Base::sptr &)
add a atrtribut, old value is erased
fwAtoms contains basic objects to represent any other kind of object
FWATOMS_API void setMetaInfo(const std::string &key, const std::string &value)
Add a metainfo in the object MetaInfo coud be anything limited to string type.
FWATOMS_API Base::sptr getAttribute(const std::string &key) const
Returns requested attribute if exists, empty sptr else.
FWATOMS_API void clearAttribute()
clear attributes
virtual FWATOMS_API Base::sptr clone() const override
Returns a clone object.
FWATOMS_API AttributesType::size_type eraseAttribute(const std::string &key)
Removes an attributes.
Class represented a fwData::Object.
FWATOMS_API void setAttributes(const AttributesType &attrs)
Sets the attributes map.
FWATOMS_API std::string getMetaInfo(const std::string &key) const
Returns one meta information.
FWATOMS_API MetaInfosType::size_type eraseMetaInfo(const std::string &key)
Removes a MetaInfo.
FWATOMS_API void clearMetaInfo()
clear MetaInfos
FWATOMS_API void setMetaInfos(const MetaInfosType &metaInfos)
Replace metaInfos.