graph_analysis
VertexTypeManager.hpp
Go to the documentation of this file.
1 #ifndef GRAPH_ANALYSIS_VERTEX_TYPE_MANAGER_HPP
2 #define GRAPH_ANALYSIS_VERTEX_TYPE_MANAGER_HPP
3 
4 #include <map>
5 #include <set>
6 #include <string>
7 #include <base-logging/Singleton.hpp>
8 
9 #include "Vertex.hpp"
10 #include "AttributeManager.hpp"
11 
12 namespace graph_analysis {
13 
14 namespace vertex {
15  // datatype for vertex type specification
16  typedef std::string Type;
17 } // end namespace vertex
18 
28 class VertexTypeManager : public base::Singleton<VertexTypeManager>, public AttributeManager
29 {
30 public:
31  typedef std::map<vertex::Type, Vertex::Ptr> TypeMap;
32 
33 private:
34 
36  TypeMap mTypeMap;
38  std::set<std::string> mRegisteredTypes;
39  std::string mDefaultVertexType;
40 
47  Vertex::Ptr vertexByType(const vertex::Type& type, bool throwOnMissing = false);
48 
49 protected:
52  friend class base::Singleton<VertexTypeManager>;
53 
54 public:
58  void setDefaultType(const std::string& type);
59 
63  const std::string& getDefaultType() const { return mDefaultVertexType; }
64 
65  // Register vertex class
66  void registerType(const Vertex::Ptr& vertex, bool throwOnAlreadyRegistered = false);
67 
68  // Register vertex class
69  void registerType(const vertex::Type& type, const Vertex::Ptr& vertex, bool throwOnAlreadyRegistered = false);
70 
79  Vertex::Ptr createVertex(const vertex::Type& type, const std::string& label = std::string(),
80  bool throwOnMissing = false);
81 
86  std::set<std::string> getSupportedTypes() const;
87 
95  std::vector<Attribute> getKnownAttributes(const std::set<std::string>& classnames = std::set<std::string>()) const;
96 
101  std::vector< std::pair<Attribute::Id, std::string> >
102  getAttributeValues(const Vertex::Ptr& vertex) const;
103 };
104 
105 } // end namespace graph_analysis
106 #endif /* GRAPH_ANALYSIS_VERTEX_TYPE_MANAGER_HPP */
const std::string & getDefaultType() const
Definition: VertexTypeManager.hpp:63
std::map< vertex::Type, Vertex::Ptr > TypeMap
Definition: VertexTypeManager.hpp:31
Manage object (vertex/edge) attributes and allow them to be serialized, e.g., using GEXF or GraphML...
Definition: AttributeManager.hpp:13
Main namespace of the graph analysis library.
Definition: BFS.cpp:3
shared_ptr< Vertex > Ptr
Definition: Vertex.hpp:22
Factory for Vertex subclasses.
Definition: VertexTypeManager.hpp:28
std::string Type
Definition: VertexTypeManager.hpp:16