DDS  ver. 3.4
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 
35  public:
37  CTopoCore();
38 
40  virtual ~CTopoCore();
41 
44  void init(const std::string& _fileName);
45 
48  void init(const std::string& _fileName, const std::string& _schemaFileName);
49 
56  void getDifference(const CTopoCore& _topology,
57  IdSet_t& _removedTasks,
58  IdSet_t& _removedCollections,
59  IdSet_t& _addedTasks,
60  IdSet_t& _addedCollections);
61 
62  void setXMLValidationDisabled(bool _val);
63 
65  std::string getName() const;
66  std::string getFilepath() const;
67  uint32_t getHash() const;
69  const STopoRuntimeTask& getRuntimeTaskById(Id_t _id) const;
71  const STopoRuntimeTask& getRuntimeTaskByIdPath(const std::string& _idPath) const;
72  const STopoRuntimeCollection& getRuntimeCollectionByIdPath(const std::string& _idPath) const;
73  std::pair<size_t, size_t> getRequiredNofAgents(size_t _defaultNumSlots) const;
74  size_t getTotalNofTasks() const;
75 
78  const STopoRuntimeTask::Map_t& _map, STopoRuntimeTask::Condition_t _condition) const;
80  STopoRuntimeTask::Condition_t _condition = nullptr) const;
82  STopoRuntimeCollection::Condition_t _condition = nullptr) const;
84  const std::string& _propertyName, Id_t _taskId) const;
86  const std::string& _pathPattern) const;
88  const std::string& _pathPattern) const;
89 
95 
96  std::string stringOfTasks(const IdSet_t& _ids) const;
97  std::string stringOfCollections(const IdSet_t& _ids) const;
98 
101  virtual std::string toString() const;
102 
106  friend std::ostream& operator<<(std::ostream& _strm, const CTopoCore& _topology);
107 
108  private:
109  void FillTopoIndexToTopoElementMap(const CTopoElement::Ptr_t& _element);
110  void FillIdToTopoElementMap(const CTopoElement::Ptr_t& _element);
111  uint32_t CalculateHash(const std::string& _filename);
112  Id_t calculateId(const std::string& _idPath, const std::string& _hashString);
113 
114  CTopoGroup::Ptr_t m_main{ nullptr };
115 
116  STopoRuntimeTask::Map_t m_idToRuntimeTaskMap;
118  m_idToRuntimeCollectionMap;
119  IdPathToIdMap_t m_taskIdPathToIdMap;
120  IdPathToIdMap_t m_collectionIdPathToIdMap;
121  std::map<std::string, size_t> m_counterMap;
123  std::string m_currentCollectionIdPath;
124  Id_t m_currentCollectionId{ 0 };
125 
126  bool m_bXMLValidationDisabled{ false };
127  std::string m_name;
128  uint32_t m_hash{ 0 };
129  std::string m_filepath;
130  };
131  } // namespace topology_api
132 } // namespace dds
133 #endif /* defined(__DDS__Topology__) */
CTopoGroup::Ptr_t getMainGroup() const
Definition: TopoCore.cpp:36
virtual std::string toString() const
Returns string representation of an object.
Definition: TopoCore.cpp:485
const STopoRuntimeCollection & getRuntimeCollectionByIdPath(const std::string &_idPath) const
Definition: TopoCore.cpp:223
const IdPathToIdMap_t & getTaskIdPathToIdMap() const
Definition: TopoCore.cpp:189
std::string getName() const
Accessors.
Definition: TopoCore.cpp:128
std::function< bool(std::pair< Id_t, const STopoRuntimeTask & >)> Condition_t
Definition: TopoTask.h:104
virtual ~CTopoCore()
Destructor.
Definition: TopoCore.cpp:32
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:179
STopoRuntimeCollection::FilterIteratorPair_t getRuntimeCollectionIterator(STopoRuntimeCollection::Condition_t _condition=nullptr) const
Definition: TopoCore.cpp:249
std::map< Id_t, STopoRuntimeCollection > Map_t
Definition: TopoCollection.h:59
const IdPathToIdMap_t & getCollectionIdPathToIdMap() const
Definition: TopoCore.cpp:194
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:231
std::pair< size_t, size_t > getRequiredNofAgents(size_t _defaultNumSlots) const
Definition: TopoCore.cpp:156
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
Definition: TopoCore.cpp:199
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:184
std::shared_ptr< CTopoElement > Ptr_t
Definition: TopoElement.h:21
uint32_t getHash() const
Definition: TopoCore.cpp:142
Definition: TopoCore.h:25
STopoRuntimeTask::FilterIteratorPair_t getRuntimeTaskIteratorMatchingPath(const std::string &_pathPattern) const
Definition: TopoCore.cpp:311
CTopoCore()
Constructor.
Definition: TopoCore.cpp:28
std::string getFilepath() const
Definition: TopoCore.cpp:137
void setXMLValidationDisabled(bool _val)
Definition: TopoCore.cpp:151
size_t getTotalNofTasks() const
Definition: TopoCore.cpp:174
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:85
std::string stringOfCollections(const IdSet_t &_ids) const
Definition: TopoCore.cpp:456
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:41
std::function< bool(std::pair< Id_t, const STopoRuntimeCollection & >)> Condition_t
Definition: TopoCollection.h:60
const STopoRuntimeTask & getRuntimeTaskByIdPath(const std::string &_idPath) const
Definition: TopoCore.cpp:215
Definition: TopoCollection.h:57
STopoRuntimeTask::FilterIteratorPair_t getRuntimeTaskIteratorForPropertyName(const std::string &_propertyName, Id_t _taskId) const
Definition: TopoCore.cpp:264
STopoRuntimeCollection::FilterIteratorPair_t getRuntimeCollectionIteratorMatchingPath(const std::string &_pathPattern) const
Definition: TopoCore.cpp:321
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:433
const STopoRuntimeCollection & getRuntimeCollectionById(Id_t _id) const
Definition: TopoCore.cpp:207