DDS  ver. 3.4
TopoBase.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 //
4 //
5 
6 #ifndef __DDS__TopoBase__
7 #define __DDS__TopoBase__
8 
9 // STD
10 #include <sstream>
11 #include <string>
12 #include <vector>
13 // BOOST
14 #include <boost/property_tree/ptree.hpp>
15 
16 namespace dds
17 {
18  namespace topology_api
19  {
20  class CTopoBase
21  {
22  public:
23  enum class EType
24  {
25  TOPO_BASE,
28  TASK,
29  COLLECTION,
30  GROUP,
32  TOPO_VARS,
33  TRIGGER
34  };
35 
36  using Ptr_t = std::shared_ptr<CTopoBase>;
37  using PtrVector_t = std::vector<CTopoBase::Ptr_t>;
38 
40  void setName(const std::string& _name);
41  void setParent(CTopoBase* _parent);
42 
44  const std::string& getName() const;
45  CTopoBase::EType getType() const;
46  CTopoBase* getParent() const;
47 
49  std::string getPath() const;
50 
57  template <class Object_t>
58  static typename Object_t::Ptr_t make(const std::string& _objectName,
59  const std::string& _filepath,
60  const std::string& _schemaFilepath = "",
61  std::string* _topologyName = nullptr)
62  {
63  typename Object_t::Ptr_t newObject = std::make_shared<Object_t>(_objectName);
64  newObject->initFromXML(_filepath, _schemaFilepath, _topologyName);
65  return newObject;
66  }
67 
72  template <class Object_t>
73  static typename Object_t::Ptr_t make(const std::string& _name, const boost::property_tree::ptree& _pt)
74  {
75  typename Object_t::Ptr_t newObject = std::make_shared<Object_t>(_name);
76  newObject->initFromPropertyTree(_pt);
77  return newObject;
78  }
79 
86  void initFromXML(const std::string& _filepath,
87  const std::string& _schemaFilepath = "",
88  std::string* _topologyName = nullptr);
89 
93  virtual void initFromPropertyTree(const boost::property_tree::ptree& _pt) = 0;
94 
97  virtual void saveToPropertyTree(boost::property_tree::ptree& _pt) = 0;
98 
101  virtual std::string toString() const;
102 
106  friend std::ostream& operator<<(std::ostream& _strm, const CTopoBase& _element);
107 
109  virtual std::string hashString() const = 0;
110 
111  protected:
113  CTopoBase(const std::string& _name);
114 
116  virtual ~CTopoBase();
117 
118  void setType(CTopoBase::EType _type);
119 
120  private:
121  std::string m_name;
123  CTopoBase* m_parent{ nullptr };
124  };
125  } // namespace topology_api
126 } // namespace dds
127 #endif /* defined(__DDS__TopoBase__) */
Definition: TopoBase.h:20
virtual void saveToPropertyTree(boost::property_tree::ptree &_pt)=0
Save object to a property tree.
static Object_t::Ptr_t make(const std::string &_objectName, const std::string &_filepath, const std::string &_schemaFilepath="", std::string *_topologyName=nullptr)
Convenience API to create topology object from XML file.
Definition: TopoBase.h:58
void initFromXML(const std::string &_filepath, const std::string &_schemaFilepath="", std::string *_topologyName=nullptr)
Initializes object with data from XML file.
Definition: TopoBase.cpp:68
virtual std::string toString() const
Returns string representation of an object.
Definition: TopoBase.cpp:77
std::shared_ptr< CTopoBase > Ptr_t
Definition: TopoBase.h:36
CTopoBase::EType getType() const
Definition: TopoBase.cpp:46
virtual void initFromPropertyTree(const boost::property_tree::ptree &_pt)=0
Initialize object with data from property tree.
virtual ~CTopoBase()
Destructor.
Definition: TopoBase.cpp:22
EType
Definition: TopoBase.h:23
Definition: AgentConnectionManager.h:13
void setType(CTopoBase::EType _type)
Definition: TopoBase.cpp:26
std::vector< CTopoBase::Ptr_t > PtrVector_t
Definition: TopoBase.h:37
static Object_t::Ptr_t make(const std::string &_name, const boost::property_tree::ptree &_pt)
Convenience API to create topology object with data from property tree.
Definition: TopoBase.h:73
void setParent(CTopoBase *_parent)
Definition: TopoBase.cpp:36
std::string getPath() const
Return full path to topo element or property.
Definition: TopoBase.cpp:56
const std::string & getName() const
Accessors.
Definition: TopoBase.cpp:41
friend std::ostream & operator<<(std::ostream &_strm, const CTopoBase &_element)
Operator << for convenient output to ostream.
void setName(const std::string &_name)
Modifiers.
Definition: TopoBase.cpp:31
CTopoBase * getParent() const
Definition: TopoBase.cpp:51
CTopoBase(const std::string &_name)
Constructor.
Definition: TopoBase.cpp:17
virtual std::string hashString() const =0
Returns string which is used to calculate CRC checksum of the object.