fpmas 1.6
graph.h
Go to the documentation of this file.
1#ifndef FPMAS_GRAPH_API_H
2#define FPMAS_GRAPH_API_H
3
8#include <unordered_map>
10#include "fpmas/api/graph/id.h"
12
13namespace fpmas { namespace api { namespace graph {
20 template<typename NodeType, typename EdgeType>
21 class Graph {
22 static_assert(std::is_base_of<typename NodeType::EdgeType, EdgeType>::value,
23 "NodeType::EdgeType must be a base of EdgeType.");
24 static_assert(std::is_base_of<typename EdgeType::NodeType, NodeType>::value,
25 "EdgeType::NodeType must be a base of NodeType.");
26 public:
30 typedef typename NodeType::IdType NodeIdType;
34 typedef typename EdgeType::IdType EdgeIdType;
35
44
48 typedef std::unordered_map<
49 NodeIdType, NodeType*, NodeIdHash
54 typedef std::unordered_map<
55 EdgeIdType, EdgeType*, EdgeIdHash
57
58 public:
71 virtual void insert(NodeType* node) = 0;
72
85 virtual void insert(EdgeType* edge) = 0;
86
87
108 virtual void erase(NodeType* node) = 0;
109
125 virtual void erase(EdgeType* edge) = 0;
126
133
139 virtual std::vector<api::utils::Callback<NodeType*>*> onInsertNodeCallbacks() const = 0;
140
147
153 virtual std::vector<api::utils::Callback<NodeType*>*> onEraseNodeCallbacks() const = 0;
154
161
167 virtual std::vector<api::utils::Callback<EdgeType*>*> onInsertEdgeCallbacks() const = 0;
168
175
181 virtual std::vector<api::utils::Callback<EdgeType*>*> onEraseEdgeCallbacks() const = 0;
182
183 // Node getters
197 virtual NodeType* getNode(NodeIdType id) = 0;
201 virtual const NodeType* getNode(NodeIdType id) const = 0;
207 virtual const NodeMap& getNodes() const = 0;
208
209 // Edge getters
223 virtual EdgeType* getEdge(EdgeIdType id) = 0;
227 virtual const EdgeType* getEdge(EdgeIdType) const = 0;
233 virtual const EdgeMap& getEdges() const = 0;
234
241 virtual void clear() = 0;
242
243 virtual ~Graph() {}
244 };
245 }}
246}
247#endif
Definition: graph.h:21
virtual void addCallOnEraseNode(api::utils::Callback< NodeType * > *callback)=0
virtual std::vector< api::utils::Callback< NodeType * > * > onEraseNodeCallbacks() const =0
virtual std::vector< api::utils::Callback< EdgeType * > * > onInsertEdgeCallbacks() const =0
virtual void clear()=0
std::unordered_map< EdgeIdType, EdgeType *, EdgeIdHash > EdgeMap
Definition: graph.h:56
virtual void erase(NodeType *node)=0
virtual std::vector< api::utils::Callback< EdgeType * > * > onEraseEdgeCallbacks() const =0
virtual const NodeMap & getNodes() const =0
fpmas::api::graph::IdHash< typename NodeType::IdType > NodeIdHash
Definition: graph.h:39
virtual void addCallOnInsertNode(api::utils::Callback< NodeType * > *callback)=0
virtual NodeType * getNode(NodeIdType id)=0
fpmas::api::graph::IdHash< typename EdgeType::IdType > EdgeIdHash
Definition: graph.h:43
virtual void insert(NodeType *node)=0
virtual const NodeType * getNode(NodeIdType id) const =0
virtual void erase(EdgeType *edge)=0
virtual const EdgeMap & getEdges() const =0
virtual EdgeType * getEdge(EdgeIdType id)=0
std::unordered_map< NodeIdType, NodeType *, NodeIdHash > NodeMap
Definition: graph.h:50
virtual const EdgeType * getEdge(EdgeIdType) const =0
virtual void insert(EdgeType *edge)=0
EdgeType::IdType EdgeIdType
Definition: graph.h:34
virtual void addCallOnInsertEdge(api::utils::Callback< EdgeType * > *callback)=0
virtual std::vector< api::utils::Callback< NodeType * > * > onInsertNodeCallbacks() const =0
virtual void addCallOnEraseEdge(api::utils::Callback< EdgeType * > *callback)=0
NodeType::IdType NodeIdType
Definition: graph.h:23
Definition: fpmas.cpp:3
Definition: id.h:58