graph_analysis
GraphElement.hpp
Go to the documentation of this file.
1 #ifndef GRAPH_ANALYSIS_GRAPH_ELEMENT_HPP
2 #define GRAPH_ANALYSIS_GRAPH_ELEMENT_HPP
3 
4 #include <stdint.h>
5 #include <vector>
6 #include <map>
7 #include <boost/uuid/uuid.hpp>
8 #include <boost/uuid/uuid_io.hpp>
9 #include <boost/uuid/uuid_generators.hpp>
10 #include "SharedPtr.hpp"
11 
12 namespace graph_analysis {
13 namespace io {
14  class Reader;
15 } // end namespace io
16 } // end namespace graph_analysis
17 
18 namespace graph_analysis {
19 
20 typedef boost::uuids::uuid GraphElementUuid;
21 typedef uint32_t GraphElementId;
22 typedef uint32_t GraphId;
23 typedef std::map<GraphId, GraphElementId> GraphElementMap;
24 typedef std::vector<GraphId> GraphIdList;
25 
34 class GraphElement : public enable_shared_from_this<GraphElement>
35 {
37 
38 public:
42  GraphElement(const std::string& label = std::string());
43 
44  virtual ~GraphElement();
45 
46  typedef shared_ptr< GraphElement > Ptr;
47  typedef weak_ptr< GraphElement > WeakPtr;
48  typedef std::vector<Ptr> PtrList;
49 
53  virtual void setLabel(const std::string& label) { mLabel = label; }
54 
58  virtual const std::string& getLabel() const { return mLabel; }
59 
60  // Get class name
61  // \return class name
62  virtual std::string getClassName() const { return "graph_analysis::GraphElement"; }
63 
68  virtual std::string toString(uint32_t indent) const { return std::string(indent,' ') + getClassName(); }
69 
73  virtual std::string toString() const { return toString(0); }
74 
79  bool associated(GraphId graph) const { return mGraphElementMap.count(graph); }
80 
85  void associate(GraphId graph, GraphElementId elementId) { mGraphElementMap[graph] = elementId; }
86 
90  void disassociate(GraphId graph) { mGraphElementMap.erase(graph); }
91 
95  GraphElementId getId(GraphId graph) const;
96 
101  GraphElementUuid getUid() const { return mUuid; }
102 
107  GraphElementUuid getUuid() const { return mUuid; }
108 
113  static GraphElement::Ptr fromUuid(const GraphElementUuid& uuid);
114 
118  GraphIdList getGraphAssociations() const;
119 
123  std::string toPrefixedString(GraphId graph) const;
124 
125 protected:
130  GraphElement::Ptr getSharedFromThis() { return shared_from_this(); }
131 
132  void disassociateFromAll() { mGraphElementMap.clear(); }
133 
138  void setUuid(const GraphElementUuid& uuid) { mUuid = uuid; }
139 
140  void setUuid(const std::string& uuid);
141 
142  GraphElementMap mGraphElementMap;
143 
144  GraphElementUuid mUuid;
145  static boost::uuids::random_generator msUuidGenerator;
146  static std::map<GraphElementUuid, function<GraphElement::Ptr()> > msGraphElements;
147  std::string mLabel;
148 };
149 
150 } // end namespace graph_analysis
151 #endif // GRAPH_ANALYSIS_GRAPH_ELEMENT_HPP
GraphElement is the base class for all element in a graph, i.e. for edges and vertices.
Definition: GraphElement.hpp:34
uint32_t GraphElementId
Definition: GraphElement.hpp:21
GraphElementUuid getUuid() const
Definition: GraphElement.hpp:107
std::string mLabel
Definition: GraphElement.hpp:147
GraphElementUuid getUid() const
Definition: GraphElement.hpp:101
GraphElementUuid mUuid
Definition: GraphElement.hpp:144
void disassociate(GraphId graph)
Definition: GraphElement.hpp:90
static std::map< GraphElementUuid, function< GraphElement::Ptr()> > msGraphElements
Definition: GraphElement.hpp:146
std::vector< Ptr > PtrList
Definition: GraphElement.hpp:48
weak_ptr< GraphElement > WeakPtr
Definition: GraphElement.hpp:47
Interface for Reader implementation that perform custom graph deserialization.
Definition: GraphIO.hpp:56
void disassociateFromAll()
Definition: GraphElement.hpp:132
std::vector< GraphId > GraphIdList
Definition: GraphElement.hpp:24
GraphElementMap mGraphElementMap
Definition: GraphElement.hpp:142
static boost::uuids::random_generator msUuidGenerator
Definition: GraphElement.hpp:145
Main namespace of the graph analysis library.
Definition: BFS.cpp:3
shared_ptr< GraphElement > Ptr
Definition: GraphElement.hpp:46
virtual void setLabel(const std::string &label)
Definition: GraphElement.hpp:53
virtual std::string toString(uint32_t indent) const
Definition: GraphElement.hpp:68
GraphElement::Ptr getSharedFromThis()
Definition: GraphElement.hpp:130
void setUuid(const GraphElement::Ptr &element, const std::string &uuid) const
Definition: GraphIO.hpp:70
void associate(GraphId graph, GraphElementId elementId)
Definition: GraphElement.hpp:85
virtual const std::string & getLabel() const
Definition: GraphElement.hpp:58
virtual std::string getClassName() const
Definition: GraphElement.hpp:62
std::map< GraphId, GraphElementId > GraphElementMap
Definition: GraphElement.hpp:23
boost::uuids::uuid GraphElementUuid
Definition: GraphElement.hpp:20
void setUuid(const GraphElementUuid &uuid)
Definition: GraphElement.hpp:138
bool associated(GraphId graph) const
Definition: GraphElement.hpp:79
virtual std::string toString() const
Definition: GraphElement.hpp:73
uint32_t GraphId
Definition: GraphElement.hpp:22