7 #include <boost/utility/enable_if.hpp> 9 #include <fwData/camp/mapper.hpp> 10 #include <fwData/Float.hpp> 11 #include <fwData/Boolean.hpp> 12 #include <fwData/String.hpp> 13 #include <fwData/Integer.hpp> 15 #include "fwDataCamp/visitor/GetObject.hpp" 17 #include "fwDataCamp/exception/NullPointer.hpp" 18 #include "fwDataCamp/exception/ObjectNotFound.hpp" 28 std::string m_subObjPath;
29 PathVisitor::sptr m_pathVisitor;
32 m_subObjPath(subObjPath), m_pathVisitor(pathVisitor)
36 ::fwData::Object::sptr operator()(camp::NoType value)
38 SLM_FATAL(
"Enter in void GetCampValueVisitor()(camp::NoType value) : case not managed");
39 ::fwData::Object::sptr val;
43 ::fwData::Object::sptr operator()(
bool value)
45 return ::fwData::Boolean::New(value);
48 ::fwData::Object::sptr operator()(
long value)
50 return ::fwData::Integer::New(value);
53 ::fwData::Object::sptr operator()(
double value)
55 return ::fwData::Float::New(value);
58 ::fwData::Object::sptr operator()(
const std::string& value)
60 return ::fwData::String::New(value);
63 ::fwData::Object::sptr operator()(
const camp::EnumObject& value)
65 SLM_FATAL(
"Enter in void GetCampValueVisitor()(camp::EnumObject value) : case not managed");
66 ::fwData::Object::sptr val;
70 ::fwData::Object::sptr operator()(
const camp::UserObject& value)
72 ::fwData::Object::sptr val;
73 const camp::Class& metaclass = value.getClass();
74 if ( value.pointer() )
76 if ( !m_subObjPath.empty() )
78 OSLM_DEBUG(
"visit class= '" << metaclass.name() <<
"' ( classname = '"<< value.call(
79 "classname") <<
"' )" );
83 m_pathVisitor->merge(visitor.getPathVisitor());
94 "Object '" + metaclass.name() +
"' not instanced.")
105 m_object(object), m_subObjPath(subObjPath),
106 m_newSubObjPath(subObjPath),
109 SLM_FATAL_IF(
"Cannot retrieve an object with an empty path.", subObjPath.empty());
110 m_campObj = camp::UserObject( *
object );
111 m_propertyName = this->getNextPropertyName();
116 GetObject::~GetObject()
122 void GetObject::visit(
const camp::SimpleProperty& property)
125 const std::string name ( property.name() );
126 OSLM_DEBUG(
"SimpleProperty name =" << name );
127 if( name == m_propertyName )
130 OSLM_DEBUG(
"Ok SimpleProperty name =" << name );
131 ::camp::Value elemValue =
property.get( m_campObj );
133 m_subObject = elemValue.visit( visitor );
139 void GetObject::visit(
const camp::EnumProperty& property)
142 OSLM_FATAL_IF(
"EnumProperty is not still managed : name =" << property.name(),
143 property.name() == m_propertyName );
151 const std::string name ( property.name() );
153 if( name == m_propertyName )
156 OSLM_DEBUG(
"Ok MapProperty name =" << name );
157 std::string key = this->getNextPropertyName();
159 std::pair< ::camp::Value, ::camp::Value > value;
161 for (
unsigned int var = 0; var <
property.getSize(m_campObj); ++var)
163 value =
property.getElement(m_campObj, var);
164 mapKey = value.first.to< std::string >();
169 m_subObject = value.second.visit( visitor );
177 void GetObject::visit(
const camp::ArrayProperty& property)
180 const std::string name ( property.name() );
182 if( name == m_propertyName )
185 OSLM_DEBUG(
"Ok ArrayProperty name =" << name );
186 std::string key = this->getNextPropertyName();
188 size_t index = ::boost::lexical_cast<
size_t >( key );
194 ::camp::Value elemValue;
197 elemValue =
property.get( m_campObj, index );
199 catch(::camp::OutOfRange e)
202 "Index '" << index <<
"' not found in array property '" << name <<
"'.");
206 m_subObject = elemValue.visit( visitor );
212 void GetObject::visit(
const camp::UserProperty& property)
215 const std::string name ( property.name() );
217 if( name == m_propertyName )
220 OSLM_DEBUG(
"Ok UserProperty name =" << name );
221 ::camp::Value elemValue =
property.get( m_campObj );
223 m_subObject = elemValue.visit( visitor );
229 void GetObject::visit(
const camp::Function&
function)
236 std::string GetObject::getNextPropertyName()
238 SLM_FATAL_IF(
"Path is empty.", m_newSubObjPath.empty() );
239 size_t dotPos = m_newSubObjPath.find(
".");
240 std::string nextItem;
241 if ( dotPos != std::string::npos )
243 nextItem = m_newSubObjPath.substr( 0, dotPos );
244 m_newSubObjPath = m_newSubObjPath.substr( dotPos+1 );
248 nextItem = m_newSubObjPath;
249 m_newSubObjPath =
"";
252 OSLM_DEBUG(
"m_newSubObjPath = " << m_newSubObjPath );
260 const camp::Class& camClass = ::camp::classByName( m_object->getClassname() );
261 camClass.visit( *
this );
FWDATACAMP_API::fwData::Object::sptr get()
Launches visit process and returns the object designated by m_subObjPath.
#define SLM_TRACE_FUNC()
Trace contextual function signature.
Check if object introspection process mathes a given path.
#define SLM_FATAL(message)
This namespace contains data object descriptions used for introspection.
PathVisitor::sptr m_pathVisitor
Path visitor.
Base class for each data object.
#define SLM_FATAL_IF(message, cond)
FWDATACAMP_API GetObject(::fwData::Object::csptr object, const std::string &subObjPath)
Constructor.
FWDATACAMP_API bool objectsFound() const
Returns true if introspection process matched child object path.
#define OSLM_FATAL_IF(message, cond)
This class is an helper to introspect a data and find an object (contained into this data) from a nor...
#define OSLM_DEBUG(message)