fw4spl
getObject.cpp
1 /* ***** BEGIN LICENSE BLOCK *****
2  * FW4SPL - Copyright (C) IRCAD, 2009-2016.
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 <fwCore/base.hpp>
8 
9 #include <fwData/Object.hpp>
10 
11 #include "fwDataCamp/getObject.hpp"
12 #include "fwDataCamp/visitor/GetObject.hpp"
13 #include "fwDataCamp/exception/NullPointer.hpp"
14 #include "fwDataCamp/exception/ObjectNotFound.hpp"
15 
16 namespace fwDataCamp
17 {
18 
19 ::fwData::Object::sptr getObject( ::fwData::Object::csptr object,
20  const std::string& path,
21  bool raiseException )
22 {
23  SLM_FATAL_IF( "Path for desired object is empty.", path.empty() );
24  SLM_FATAL_IF( "Path for desired object doesn't start with '@'.", path[0] != '@' );
25  const std::string objectPath = path.substr( 1 );
26  ::fwDataCamp::visitor::GetObject visitor( object, objectPath );
27  ::fwData::Object::sptr subObject;
28  try
29  {
30  subObject = visitor.get();
31  }
32  catch(const ::fwDataCamp::exception::NullPointer& np)
33  {
34  FW_FORWARD_EXCEPTION_IF(np, raiseException);
35  }
36 
37  FW_RAISE_EXCEPTION_IF(
38  ::fwDataCamp::exception::ObjectNotFound("Object '" + path + "' not found."),
39  !visitor.objectsFound() && raiseException);
40 
41  return subObject;
42 }
43 
44 } // namespace fwDataCamp
45 
FWDATACAMP_API std::shared_ptr< ::fwData::Object > getObject(std::shared_ptr< const ::fwData::Object > object, const std::string &path, bool raiseException=false)
Returns the object designated by the given path within given object.
Definition: getObject.hpp:43
This namespace contains data object descriptions used for introspection.
#define SLM_FATAL_IF(message, cond)
Definition: spyLog.hpp:287
This class is an helper to introspect a data and find an object (contained into this data) from a nor...
Definition: GetObject.hpp:80