PhoenixGraph  01.0.0
Set of tools to simplify graph manipulation
Loading...
Searching...
No Matches
Graph.h
Go to the documentation of this file.
1/***************************************
2 Auteur : Pierre Aubert
3 Mail : pierre.aubert@lapp.in2p3.fr
4 Licence : CeCILL-C
5****************************************/
6
7#ifndef __GRAPH_H__
8#define __GRAPH_H__
9
10#include <fstream>
11#include <map>
12#include <vector>
13#include "Node.h"
14
16
19template<typename T, typename UIdx>
20class Graph{
21 public:
22 Graph();
23 Graph(const Graph<T, UIdx> & other);
24 virtual ~Graph();
25 Graph & operator = (const Graph<T, UIdx> & other);
26
27 bool savePng(const std::string & fileNamePng) const;
28 bool saveDot(const std::string & fileName) const;
29 bool saveDot(std::ofstream & fs) const;
30 std::string toDot() const;
31
32 UIdx createNode(const T & data, const std::string & name);
33 Node<T, UIdx> * createNodePtr(const T & data, const std::string & name);
34
35 bool createNode(const T & data, const UIdx & index, const std::string & name);
36 Node<T, UIdx> * createNodePtr(const T & data, const UIdx & index, const std::string & name);
37
38 void clearIsUpdated();
39 void clearMapNode();
40 void clearFirstNode();
41 void clearLastNode();
42 void clearAll();
43
44 void removeNode(UIdx index, bool reconnectParentToChildren = false);
45
47
48 void connectNode(UIdx parent, UIdx child);
49 void connectNode(UIdx parent, const std::list<UIdx> & listChildren);
50 void connectNode(UIdx parent, const std::vector<UIdx> & vecChildren);
51
52 const Node<T, UIdx> * getNode(UIdx index) const;
53 Node<T, UIdx> * getNode(UIdx index);
54
57
58 bool isNodeExist(UIdx index) const;
59
60 size_t size() const;
61 const std::list<UIdx> & getListFirstNode() const;
62 const std::list<UIdx> & getListLastNode() const;
63
64 bool iterateChildren(std::list<UIdx> & listNode) const;
65 bool iterateParent(std::list<UIdx> & listNode) const;
66
67 bool isListNodeUdpated(const std::list<UIdx> & listNode) const;
68 bool iterateChildrenCheckUpdate(std::list<UIdx> & listNode);
69 bool iterateParentCheckUpdate(std::list<UIdx> & listNode);
70
71 protected:
72 void copyGraph(const Graph<T, UIdx> & other);
73
74 private:
76
78 std::map<UIdx, Node<T, UIdx> > p_mapNode;
80 std::list<UIdx> p_listFirstNode;
82 std::list<UIdx> p_listLastNode;
83};
84
85#include "Graph_impl.h"
86
87
88#endif
89
UIdx createNode(const T &data, const std::string &name)
Create a node and get its index.
Definition Graph_impl.h:123
void initialisationGraph()
Initialisation function of the class Graph.
Definition Graph_impl.h:561
bool savePng(const std::string &fileNamePng) const
Save a png file of the graph.
Definition Graph_impl.h:50
void updateFirstLastNode()
Update the first and last Node of the Graph.
Definition Graph_impl.h:250
bool isListNodeUdpated(const std::list< UIdx > &listNode) const
Check if the list of given nodes are all updated or not.
Definition Graph_impl.h:460
bool iterateParent(std::list< UIdx > &listNode) const
Iterate from children to parents.
Definition Graph_impl.h:432
bool saveDot(const std::string &fileName) const
Save the Graph in a dot file.
Definition Graph_impl.h:69
void removeNode(UIdx index, bool reconnectParentToChildren=false)
Remove a Node from the Graph.
Definition Graph_impl.h:210
size_t size() const
Get the number of nodes inside the graph.
Definition Graph_impl.h:379
bool iterateChildrenCheckUpdate(std::list< UIdx > &listNode)
Iterate from parents to chidren (all node are iterated only once)
Definition Graph_impl.h:476
Graph()
Default constructeur of Graph.
Definition Graph_impl.h:17
void clearAll()
Definition Graph_impl.h:199
const Node< T, UIdx > * getNode(UIdx index) const
Get a Node by pointer.
Definition Graph_impl.h:316
Node< T, UIdx > * createNodePtr(const T &data, const std::string &name)
Create a node and get its pointer.
Definition Graph_impl.h:140
const std::list< UIdx > & getListFirstNode() const
Get the list of the first nodes (without parent)
Definition Graph_impl.h:387
Graph & operator=(const Graph< T, UIdx > &other)
Definition of equal operator of Graph.
Definition Graph_impl.h:40
bool iterateChildren(std::list< UIdx > &listNode) const
Iterate from parents to chidren.
Definition Graph_impl.h:404
std::map< UIdx, Node< T, UIdx > > p_mapNode
Map of the Node.
Definition Graph.h:78
bool isNodeExist(UIdx index) const
Say if the node at index does exit.
Definition Graph_impl.h:370
const std::list< UIdx > & getListLastNode() const
Get the list of the last nodes (without child)
Definition Graph_impl.h:395
std::list< UIdx > p_listFirstNode
List of the first Node (without parent)
Definition Graph.h:80
std::list< UIdx > p_listLastNode
List of the last Node (without child)
Definition Graph.h:82
std::string toDot() const
Convert the graph to dot language.
Definition Graph_impl.h:95
void copyGraph(const Graph< T, UIdx > &other)
Copy function of Graph.
Definition Graph_impl.h:553
void clearMapNode()
Clear the map of Node.
Definition Graph_impl.h:187
const Node< T, UIdx > * getFirstNotUpdatedNode() const
Get the first node which is not udpated (getIsUpdated() == false)
Definition Graph_impl.h:343
void clearIsUpdated()
Clear the isUpdated attriburte of the Node.
Definition Graph_impl.h:179
void connectNode(UIdx parent, UIdx child)
Connect a parent to its child.
Definition Graph_impl.h:268
void clearFirstNode()
Clear the list of first Node.
Definition Graph_impl.h:191
bool iterateParentCheckUpdate(std::list< UIdx > &listNode)
Iterate from children to parents (all node are iterated only once)
Definition Graph_impl.h:515
void clearLastNode()
Clear the list of last Node.
Definition Graph_impl.h:195
virtual ~Graph()
Destructeur of Graph.
Definition Graph_impl.h:31
Node of a Graph.
Definition Node.h:17