DDS  ver. 3.6
TopoCore.h
Go to the documentation of this file.
1 // Copyright 2014 GSI, Inc. All rights reserved.
2 //
3 //
4 //
5 
6 #ifndef __DDS__Topology__
7 #define __DDS__Topology__
8 
9 // DDS Topo
10 #include "TopoCollection.h"
11 #include "TopoDef.h"
12 #include "TopoElement.h"
13 #include "TopoGroup.h"
14 #include "TopoTask.h"
15 // STD
16 #include <map>
17 #include <ostream>
18 #include <set>
19 #include <string>
20 
21 namespace dds
22 {
23  namespace topology_api
24  {
25  class CTopoCore
26  {
27  public:
30  using IdSet_t = std::set<Id_t>;
31 
33  using IdPathToIdMap_t = std::map<std::string, Id_t>;
34 
36  using Ptr_t = std::shared_ptr<CTopoCore>;
37 
38  public:
40  CTopoCore();
41 
43  virtual ~CTopoCore();
44 
47  void init(const std::string& _fileName);
48 
51  void init(const std::string& _fileName, const std::string& _schemaFileName);
52 
55  void init(std::istream& _stream);
56 
59  void init(std::istream& _stream, const std::string& _schemaFileName);
60 
67  void getDifference(const CTopoCore& _topology,
68  IdSet_t& _removedTasks,
69  IdSet_t& _removedCollections,
70  IdSet_t& _addedTasks,
71  IdSet_t& _addedCollections);
72 
73  void setXMLValidationDisabled(bool _val);
74 
76  std::string getName() const;
77  std::string getFilepath() const;
78  uint32_t getHash() const;
81  const STopoRuntimeTask& getRuntimeTaskById(Id_t _id) const;
85  const STopoRuntimeTask& getRuntimeTaskByIdPath(const std::string& _idPath) const;
87  const STopoRuntimeCollection& getRuntimeCollectionByIdPath(const std::string& _idPath) const;
89  const STopoRuntimeTask& getRuntimeTask(const std::string& _path) const;
91  const STopoRuntimeCollection& getRuntimeCollection(const std::string& _path) const;
92  std::pair<size_t, size_t> getRequiredNofAgents(size_t _defaultNumSlots) const;
93  size_t getTotalNofTasks() const;
94 
97  const STopoRuntimeTask::Map_t& _map, STopoRuntimeTask::Condition_t _condition) const;
99  STopoRuntimeTask::Condition_t _condition = nullptr) const;
101  STopoRuntimeCollection::Condition_t _condition = nullptr) const;
103  const std::string& _propertyName, Id_t _taskId) const;
105  const std::string& _pathPattern) const;
107  const std::string& _pathPattern) const;
108 
112  const IdPathToIdMap_t& getTaskIdPathToIdMap() const;
114 
115  std::string stringOfTasks(const IdSet_t& _ids) const;
116  std::string stringOfCollections(const IdSet_t& _ids) const;
117 
120  virtual std::string toString() const;
121 
125  friend std::ostream& operator<<(std::ostream& _strm, const CTopoCore& _topology);
126 
127  private:
128  void FillTopoIndexToTopoElementMap(const CTopoElement::Ptr_t& _element);
129  void FillIdToTopoElementMap(const CTopoElement::Ptr_t& _element);
130  uint32_t CalculateHash(std::istream& _stream);
131  Id_t calculateId(const std::string& _idPath, const std::string& _hashString);
132 
133  CTopoGroup::Ptr_t m_main{ nullptr };
134 
135  STopoRuntimeTask::Map_t m_idToRuntimeTaskMap;
137  m_idToRuntimeCollectionMap;
138  IdPathToIdMap_t m_taskIdPathToIdMap;
139  IdPathToIdMap_t m_collectionIdPathToIdMap;
140  std::map<std::string, size_t> m_counterMap;
142  std::string m_currentCollectionIdPath;
143  Id_t m_currentCollectionId{ 0 };
144 
145  bool m_bXMLValidationDisabled{ false };
146  std::string m_name;
147  uint32_t m_hash{ 0 };
148  std::string m_filepath;
149  };
150  } // namespace topology_api
151 } // namespace dds
152 #endif /* defined(__DDS__Topology__) */
CTopoGroup::Ptr_t getMainGroup() const
Definition: TopoCore.cpp:37
virtual std::string toString() const
Returns string representation of an object.
Definition: TopoCore.cpp:537
const STopoRuntimeCollection & getRuntimeCollection(const std::string &_path) const
Returns runtime collection by either ID or runtime path.
Definition: TopoCore.cpp:266
const STopoRuntimeCollection & getRuntimeCollectionByIdPath(const std::string &_idPath) const
Returns runtime collection by runtime path.
Definition: TopoCore.cpp:242
const IdPathToIdMap_t & getTaskIdPathToIdMap() const
Definition: TopoCore.cpp:208
std::string getName() const
Accessors.
Definition: TopoCore.cpp:147
std::function< bool(std::pair< Id_t, const STopoRuntimeTask & >)> Condition_t
Definition: TopoTask.h:104
virtual ~CTopoCore()
Destructor.
Definition: TopoCore.cpp:33
std::map< std::string, Id_t > IdPathToIdMap_t
Task/Collection ID path to Task/Collection ID map.
Definition: TopoCore.h:33
const STopoRuntimeTask::Map_t & getIdToRuntimeTaskMap() const
Accessors to internal data structures. Used for unit tests.
Definition: TopoCore.cpp:198
const STopoRuntimeTask & getRuntimeTask(const std::string &_path) const
Returns runtime task by either ID or runtime path.
Definition: TopoCore.cpp:250
STopoRuntimeCollection::FilterIteratorPair_t getRuntimeCollectionIterator(STopoRuntimeCollection::Condition_t _condition=nullptr) const
Definition: TopoCore.cpp:300
std::map< Id_t, STopoRuntimeCollection > Map_t
Definition: TopoCollection.h:59
const IdPathToIdMap_t & getCollectionIdPathToIdMap() const
Definition: TopoCore.cpp:213
std::pair< STopoRuntimeCollection::FilterIterator_t, STopoRuntimeCollection::FilterIterator_t > FilterIteratorPair_t
Definition: TopoCollection.h:65
std::shared_ptr< CTopoGroup > Ptr_t
Definition: TopoGroup.h:18
Definition: TopoTask.h:101
STopoRuntimeTask::FilterIteratorPair_t getRuntimeTaskIterator(const STopoRuntimeTask::Map_t &_map, STopoRuntimeTask::Condition_t _condition) const
Iterators.
Definition: TopoCore.cpp:282
std::pair< size_t, size_t > getRequiredNofAgents(size_t _defaultNumSlots) const
Definition: TopoCore.cpp:175
uint64_t Id_t
Definition: TopoDef.h:15
std::map< Id_t, STopoRuntimeTask > Map_t
Definition: TopoTask.h:103
const STopoRuntimeTask & getRuntimeTaskById(Id_t _id) const
Returns runtime task by ID.
Definition: TopoCore.cpp:218
Miscellaneous functions and helpers are located here.
Definition: AgentConnectionManager.h:13
friend std::ostream & operator<<(std::ostream &_strm, const CTopoCore &_topology)
Operator << for convenient output to ostream.
const STopoRuntimeCollection::Map_t & getIdToRuntimeCollectionMap() const
Definition: TopoCore.cpp:203
std::shared_ptr< CTopoElement > Ptr_t
Definition: TopoElement.h:21
uint32_t getHash() const
Definition: TopoCore.cpp:161
Definition: TopoCore.h:25
STopoRuntimeTask::FilterIteratorPair_t getRuntimeTaskIteratorMatchingPath(const std::string &_pathPattern) const
Definition: TopoCore.cpp:364
CTopoCore()
Constructor.
Definition: TopoCore.cpp:29
std::string getFilepath() const
Definition: TopoCore.cpp:156
void setXMLValidationDisabled(bool _val)
Definition: TopoCore.cpp:170
size_t getTotalNofTasks() const
Definition: TopoCore.cpp:193
void getDifference(const CTopoCore &_topology, IdSet_t &_removedTasks, IdSet_t &_removedCollections, IdSet_t &_addedTasks, IdSet_t &_addedCollections)
Get difference between THIS topology and a new one.
Definition: TopoCore.cpp:104
std::string stringOfCollections(const IdSet_t &_ids) const
Definition: TopoCore.cpp:509
std::pair< STopoRuntimeTask::FilterIterator_t, STopoRuntimeTask::FilterIterator_t > FilterIteratorPair_t
Definition: TopoTask.h:108
void init(const std::string &_fileName)
Initializes topology from specified file.
Definition: TopoCore.cpp:42
std::shared_ptr< CTopoCore > Ptr_t
std::shared_ptr
Definition: TopoCore.h:36
std::function< bool(std::pair< Id_t, const STopoRuntimeCollection & >)> Condition_t
Definition: TopoCollection.h:60
const STopoRuntimeTask & getRuntimeTaskByIdPath(const std::string &_idPath) const
Returns runtime task by runtime path.
Definition: TopoCore.cpp:234
Definition: TopoCollection.h:57
STopoRuntimeTask::FilterIteratorPair_t getRuntimeTaskIteratorForPropertyName(const std::string &_propertyName, Id_t _taskId) const
Definition: TopoCore.cpp:315
STopoRuntimeCollection::FilterIteratorPair_t getRuntimeCollectionIteratorMatchingPath(const std::string &_pathPattern) const
Definition: TopoCore.cpp:373
std::set< Id_t > IdSet_t
Note that ID is of type uint_64. ID is calculated using CRC64 algorithm.
Definition: TopoCore.h:30
std::string stringOfTasks(const IdSet_t &_ids) const
Definition: TopoCore.cpp:486
const STopoRuntimeCollection & getRuntimeCollectionById(Id_t _id) const
Returns runtime collection by ID.
Definition: TopoCore.cpp:226