fw4spl
Field.hpp
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 #ifndef __FWDATATOOLS_HELPER_FIELD_HPP__
8 #define __FWDATATOOLS_HELPER_FIELD_HPP__
9 
10 #include "fwDataTools/config.hpp"
11 
12 #include <fwData/Object.hpp>
13 
14 namespace fwDataTools
15 {
16 namespace helper
17 {
18 
22 class FWDATATOOLS_CLASS_API Field
23 {
24 
25 public:
26 
28  FWDATATOOLS_API Field( ::fwData::Object::sptr object );
29 
31  FWDATATOOLS_API ~Field();
32 
40  template< typename DATA_TYPE >
41  SPTR(DATA_TYPE) setDefaultField( const ::fwData::Object::FieldNameType& name, SPTR(DATA_TYPE) defaultValue );
42 
47  FWDATATOOLS_API void setField( const ::fwData::Object::FieldNameType& name, ::fwData::Object::sptr obj );
48 
52  FWDATATOOLS_API void setFields( const ::fwData::Object::FieldMapType& newFields );
53 
58  FWDATATOOLS_API void removeField( const ::fwData::Object::FieldNameType& name );
59 
68  FWDATATOOLS_API void add( const ::fwData::Object::FieldNameType& _name, ::fwData::Object::sptr _obj );
69 
79  FWDATATOOLS_API void swap( const ::fwData::Object::FieldNameType& _name, ::fwData::Object::sptr _obj );
80 
88  FWDATATOOLS_API void addOrSwap( const ::fwData::Object::FieldNameType& _name, ::fwData::Object::sptr _obj );
89 
98  FWDATATOOLS_API void remove( const ::fwData::Object::FieldNameType& _name );
99 
105  FWDATATOOLS_API void clear();
106 
108  FWDATATOOLS_API void notify();
109 
110 protected:
111  FWDATATOOLS_API void buildMessage(
112  const ::fwData::Object::FieldMapType& oldFields,
113  const ::fwData::Object::FieldMapType& newFields
114  );
115 
125 
126  ::fwData::Object::wptr m_object;
127 };
128 
129 template<typename DATA_TYPE>
130 inline SPTR(DATA_TYPE) Field::setDefaultField(const fwData::Object::FieldNameType& name, SPTR(DATA_TYPE) defaultValue)
131 {
132  SLM_ASSERT("Field helper need a non-null object pointer", !m_object.expired());
133  ::fwData::Object::sptr object = m_object.lock();
134  ::fwData::Object::sptr field = object->getField(name);
135  if (!field)
136  {
137  m_addedFields[name] = defaultValue;
138  }
139  return object->setDefaultField(name, defaultValue);
140 }
141 
142 } // namespace helper
143 } // namespace fwDataTools
144 
145 #endif // __FWDATATOOLS_HELPER_FIELD_HPP__
#define SPTR(_cls_)
Defines a helper to modify field on a fwData::Object and create a message notifying this modification...
Definition: Field.hpp:22
::fwData::Object::FieldsContainerType m_addedFields
Map of added objects, send on notify.
Definition: Field.hpp:117
The namespace fwDataTools contains classes which provide helpers to manipulate fwData::Object. *.
std::map< std::string,::fwData::Object::sptr > FieldsContainerType
Type of signal m_sigModified.
::fwData::Object::FieldsContainerType m_newChangedFields
Map of new changed objects, send on notify.
Definition: Field.hpp:119
::fwData::Object::FieldsContainerType m_removedFields
Map of removed objects, send on notify.
Definition: Field.hpp:123
#define SLM_ASSERT(message, cond)
work like &#39;assert&#39; from &#39;cassert&#39;, with in addition a message logged by spylog (with FATAL loglevel) ...
Definition: spyLog.hpp:308
Contains the representation of the data objects used in the framework.
::fwData::Object::FieldsContainerType m_oldChangedFields
Map of old changed objects, send on notify.
Definition: Field.hpp:121
::fwData::Object::wptr m_object
Composite to add/remove/change objects.
Definition: Field.hpp:126