DDS  ver. 3.6
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 
74  template <class Object_t>
75  static typename Object_t::Ptr_t make(const std::string& _objectName,
76  std::istream& _stream,
77  const std::string& _schemaFilepath = "",
78  std::string* _topologyName = nullptr)
79  {
80  typename Object_t::Ptr_t newObject{ std::make_shared<Object_t>(_objectName) };
81  newObject->initFromXML(_stream, _schemaFilepath, _topologyName);
82  return newObject;
83  }
84 
89  template <class Object_t>
90  static typename Object_t::Ptr_t make(const std::string& _name, const boost::property_tree::ptree& _pt)
91  {
92  typename Object_t::Ptr_t newObject{ std::make_shared<Object_t>(_name) };
93  newObject->initFromPropertyTree(_pt);
94  return newObject;
95  }
96 
102  void initFromXML(const std::string& _filepath,
103  const std::string& _schemaFilepath = "",
104  std::string* _topologyName = nullptr);
105 
111  void initFromXML(std::istream& _stream,
112  const std::string& _schemaFilepath = "",
113  std::string* _topologyName = nullptr);
114 
118  virtual void initFromPropertyTree(const boost::property_tree::ptree& _pt) = 0;
119 
122  virtual void saveToPropertyTree(boost::property_tree::ptree& _pt) = 0;
123 
126  virtual std::string toString() const;
127 
131  friend std::ostream& operator<<(std::ostream& _strm, const CTopoBase& _element);
132 
134  virtual std::string hashString() const = 0;
135 
136  protected:
138  CTopoBase(const std::string& _name);
139 
141  virtual ~CTopoBase();
142 
143  void setType(CTopoBase::EType _type);
144 
145  private:
146  std::string m_name;
148  CTopoBase* m_parent{ nullptr };
149  };
150  } // namespace topology_api
151 } // namespace dds
152 #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
virtual std::string toString() const
Returns string representation of an object.
Definition: TopoBase.cpp:84
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
Miscellaneous functions and helpers are located here.
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:90
void setParent(CTopoBase *_parent)
Definition: TopoBase.cpp:36
std::string getPath() const
Return full path to topo element or property.
Definition: TopoBase.cpp:56
static Object_t::Ptr_t make(const std::string &_objectName, std::istream &_stream, const std::string &_schemaFilepath="", std::string *_topologyName=nullptr)
Convenience API to create topology object from XML file.
Definition: TopoBase.h:75
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 initFromXML(const std::string &_filepath, const std::string &_schemaFilepath="", std::string *_topologyName=nullptr)
Initializes object with data from XML file.
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.