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 
119 
123  std::string toPrefixedString(GraphId graph) const;
124 
125 protected:
130  GraphElement::Ptr getSharedFromThis() { return shared_from_this(); }
131 
133 
138  void setUuid(const GraphElementUuid& uuid) { mUuid = uuid; }
139 
140  void setUuid(const std::string& uuid);
141 
143 
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
graph_analysis::GraphElement::toPrefixedString
std::string toPrefixedString(GraphId graph) const
Definition: GraphElement.cpp:66
graph_analysis::GraphElementMap
std::map< GraphId, GraphElementId > GraphElementMap
Definition: GraphElement.hpp:23
graph_analysis::GraphElement::GraphElement
GraphElement(const std::string &label=std::string())
Default constructor.
Definition: GraphElement.cpp:11
SharedPtr.hpp
graph_analysis::GraphElement::~GraphElement
virtual ~GraphElement()
Definition: GraphElement.cpp:18
graph_analysis::GraphElementUuid
boost::uuids::uuid GraphElementUuid
Definition: GraphElement.hpp:20
graph_analysis::GraphElement::disassociate
void disassociate(GraphId graph)
Definition: GraphElement.hpp:90
graph_analysis::GraphElement::WeakPtr
weak_ptr< GraphElement > WeakPtr
Definition: GraphElement.hpp:47
graph_analysis::GraphElement::toString
virtual std::string toString() const
Definition: GraphElement.hpp:73
graph_analysis::GraphId
uint32_t GraphId
Definition: GraphElement.hpp:22
graph_analysis::GraphElement
GraphElement is the base class for all element in a graph, i.e. for edges and vertices.
Definition: GraphElement.hpp:34
graph_analysis::GraphElement::setUuid
void setUuid(const GraphElementUuid &uuid)
Definition: GraphElement.hpp:138
graph_analysis::GraphElement::getUuid
GraphElementUuid getUuid() const
Definition: GraphElement.hpp:107
graph_analysis::GraphElement::toString
virtual std::string toString(uint32_t indent) const
Definition: GraphElement.hpp:68
graph_analysis
Main namespace of the graph analysis library.
Definition: BFS.cpp:3
graph_analysis::GraphElement::getLabel
virtual const std::string & getLabel() const
Definition: GraphElement.hpp:58
graph_analysis::GraphElement::getUid
GraphElementUuid getUid() const
Definition: GraphElement.hpp:101
graph_analysis::GraphElement::msUuidGenerator
static boost::uuids::random_generator msUuidGenerator
Definition: GraphElement.hpp:145
graph_analysis::GraphElement::fromUuid
static GraphElement::Ptr fromUuid(const GraphElementUuid &uuid)
Definition: GraphElement.cpp:40
graph_analysis::GraphElement::getId
GraphElementId getId(GraphId graph) const
Definition: GraphElement.cpp:26
graph_analysis::GraphElement::associate
void associate(GraphId graph, GraphElementId elementId)
Definition: GraphElement.hpp:85
graph_analysis::GraphElement::msGraphElements
static std::map< GraphElementUuid, function< GraphElement::Ptr()> > msGraphElements
Definition: GraphElement.hpp:146
graph_analysis::GraphElement::setLabel
virtual void setLabel(const std::string &label)
Definition: GraphElement.hpp:53
graph_analysis::GraphElement::getSharedFromThis
GraphElement::Ptr getSharedFromThis()
Definition: GraphElement.hpp:130
graph_analysis::GraphElement::mLabel
std::string mLabel
Definition: GraphElement.hpp:147
graph_analysis::GraphElementId
uint32_t GraphElementId
Definition: GraphElement.hpp:21
graph_analysis::GraphElement::mUuid
GraphElementUuid mUuid
Definition: GraphElement.hpp:144
graph_analysis::GraphIdList
std::vector< GraphId > GraphIdList
Definition: GraphElement.hpp:24
graph_analysis::GraphElement::disassociateFromAll
void disassociateFromAll()
Definition: GraphElement.hpp:132
graph_analysis::GraphElement::Ptr
shared_ptr< GraphElement > Ptr
Definition: GraphElement.hpp:46
graph_analysis::GraphElement::associated
bool associated(GraphId graph) const
Definition: GraphElement.hpp:79
graph_analysis::GraphElement::getGraphAssociations
GraphIdList getGraphAssociations() const
Definition: GraphElement.cpp:54
graph_analysis::GraphElement::PtrList
std::vector< Ptr > PtrList
Definition: GraphElement.hpp:48
graph_analysis::io::Reader
Interface for Reader implementation that perform custom graph deserialization.
Definition: GraphIO.hpp:56
graph_analysis::GraphElement::mGraphElementMap
GraphElementMap mGraphElementMap
Definition: GraphElement.hpp:142
graph_analysis::GraphElement::getClassName
virtual std::string getClassName() const
Definition: GraphElement.hpp:62