PhoenixGraph  01.0.0
Set of tools to simplify graph manipulation
Loading...
Searching...
No Matches
Graph< T, UIdx > Class Template Reference

Abstract Graph of Node. More...

#include <Graph.h>

Public Member Functions

void clearAll ()
 
void clearFirstNode ()
 Clear the list of first Node.
 
void clearIsUpdated ()
 Clear the isUpdated attriburte of the Node.
 
void clearLastNode ()
 Clear the list of last Node.
 
void clearMapNode ()
 Clear the map of Node.
 
void connectNode (UIdx parent, const std::list< UIdx > &listChildren)
 Connect a parent to its children.
 
void connectNode (UIdx parent, const std::vector< UIdx > &vecChildren)
 Connect a parent to its children.
 
void connectNode (UIdx parent, UIdx child)
 Connect a parent to its child.
 
UIdx createNode (const T &data, const std::string &name)
 Create a node and get its index.
 
bool createNode (const T &data, const UIdx &index, const std::string &name)
 Create a node and get its index.
 
Node< T, UIdx > * createNodePtr (const T &data, const std::string &name)
 Create a node and get its pointer.
 
Node< T, UIdx > * createNodePtr (const T &data, const UIdx &index, const std::string &name)
 Create a node and get its pointer.
 
Node< T, UIdx > * getFirstNotUpdatedNode ()
 Get the first node which is not udpated (getIsUpdated() == false)
 
const Node< T, UIdx > * getFirstNotUpdatedNode () const
 Get the first node which is not udpated (getIsUpdated() == false)
 
const std::list< UIdx > & getListFirstNode () const
 Get the list of the first nodes (without parent)
 
const std::list< UIdx > & getListLastNode () const
 Get the list of the last nodes (without child)
 
Node< T, UIdx > * getNode (UIdx index)
 Get a Node by pointer.
 
const Node< T, UIdx > * getNode (UIdx index) const
 Get a Node by pointer.
 
 Graph ()
 Default constructeur of Graph.
 
 Graph (const Graph< T, UIdx > &other)
 Copy constructor of Graph.
 
bool isListNodeUdpated (const std::list< UIdx > &listNode) const
 Check if the list of given nodes are all updated or not.
 
bool isNodeExist (UIdx index) const
 Say if the node at index does exit.
 
bool iterateChildren (std::list< UIdx > &listNode) const
 Iterate from parents to chidren.
 
bool iterateChildrenCheckUpdate (std::list< UIdx > &listNode)
 Iterate from parents to chidren (all node are iterated only once)
 
bool iterateParent (std::list< UIdx > &listNode) const
 Iterate from children to parents.
 
bool iterateParentCheckUpdate (std::list< UIdx > &listNode)
 Iterate from children to parents (all node are iterated only once)
 
Graphoperator= (const Graph< T, UIdx > &other)
 Definition of equal operator of Graph.
 
void removeNode (UIdx index, bool reconnectParentToChildren=false)
 Remove a Node from the Graph.
 
bool saveDot (const std::string &fileName) const
 Save the Graph in a dot file.
 
bool saveDot (std::ofstream &fs) const
 Save the Graph in a dot file.
 
bool savePng (const std::string &fileNamePng) const
 Save a png file of the graph.
 
size_t size () const
 Get the number of nodes inside the graph.
 
std::string toDot () const
 Convert the graph to dot language.
 
void updateFirstLastNode ()
 Update the first and last Node of the Graph.
 
virtual ~Graph ()
 Destructeur of Graph.
 

Protected Member Functions

void copyGraph (const Graph< T, UIdx > &other)
 Copy function of Graph.
 

Private Member Functions

void initialisationGraph ()
 Initialisation function of the class Graph.
 

Private Attributes

std::list< UIdx > p_listFirstNode
 List of the first Node (without parent)
 
std::list< UIdx > p_listLastNode
 List of the last Node (without child)
 
std::map< UIdx, Node< T, UIdx > > p_mapNode
 Map of the Node.
 

Detailed Description

template<typename T, typename UIdx>
class Graph< T, UIdx >

Abstract Graph of Node.

T : type of the data to be connected in the graph UIdx : type of the index to be used to connect the Node together

Definition at line 20 of file Graph.h.

Constructor & Destructor Documentation

◆ Graph() [1/2]

template<typename T, typename UIdx>
Graph< T, UIdx >::Graph ( )

Default constructeur of Graph.

Definition at line 17 of file Graph_impl.h.

17 {
19}
void initialisationGraph()
Initialisation function of the class Graph.
Definition Graph_impl.h:561

References initialisationGraph().

Referenced by copyGraph(), Graph(), and operator=().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ Graph() [2/2]

template<typename T, typename UIdx>
Graph< T, UIdx >::Graph ( const Graph< T, UIdx > & other)

Copy constructor of Graph.

Parameters
other: class to copy

Definition at line 25 of file Graph_impl.h.

25 {
27}
Abstract Graph of Node.
Definition Graph.h:20
void copyGraph(const Graph< T, UIdx > &other)
Copy function of Graph.
Definition Graph_impl.h:553

References copyGraph(), and Graph().

+ Here is the call graph for this function:

◆ ~Graph()

template<typename T, typename UIdx>
Graph< T, UIdx >::~Graph ( )
virtual

Destructeur of Graph.

Definition at line 31 of file Graph_impl.h.

31 {
32
33}

Member Function Documentation

◆ clearAll()

template<typename T, typename UIdx>
void Graph< T, UIdx >::clearAll ( )

Definition at line 199 of file Graph_impl.h.

199 {
202 clearMapNode();
203}
void clearMapNode()
Clear the map of Node.
Definition Graph_impl.h:187
void clearFirstNode()
Clear the list of first Node.
Definition Graph_impl.h:191
void clearLastNode()
Clear the list of last Node.
Definition Graph_impl.h:195

References clearFirstNode(), clearLastNode(), and clearMapNode().

+ Here is the call graph for this function:

◆ clearFirstNode()

template<typename T, typename UIdx>
void Graph< T, UIdx >::clearFirstNode ( )

Clear the list of first Node.

Definition at line 191 of file Graph_impl.h.

191{p_listFirstNode.clear();}
std::list< UIdx > p_listFirstNode
List of the first Node (without parent)
Definition Graph.h:80

References p_listFirstNode.

Referenced by clearAll(), and updateFirstLastNode().

+ Here is the caller graph for this function:

◆ clearIsUpdated()

template<typename T, typename UIdx>
void Graph< T, UIdx >::clearIsUpdated ( )

Clear the isUpdated attriburte of the Node.

Definition at line 179 of file Graph_impl.h.

179 {
180 for(typename std::map<UIdx, Node<T, UIdx> >::iterator it(p_mapNode.begin()); it != p_mapNode.end(); ++it){
181 it->second.setIsUpdated(false);
182 }
183}
std::map< UIdx, Node< T, UIdx > > p_mapNode
Map of the Node.
Definition Graph.h:78

References p_mapNode.

Referenced by iterateChildrenCheckUpdate(), and iterateParentCheckUpdate().

+ Here is the caller graph for this function:

◆ clearLastNode()

template<typename T, typename UIdx>
void Graph< T, UIdx >::clearLastNode ( )

Clear the list of last Node.

Definition at line 195 of file Graph_impl.h.

195{p_listLastNode.clear();}
std::list< UIdx > p_listLastNode
List of the last Node (without child)
Definition Graph.h:82

References p_listLastNode.

Referenced by clearAll(), and updateFirstLastNode().

+ Here is the caller graph for this function:

◆ clearMapNode()

template<typename T, typename UIdx>
void Graph< T, UIdx >::clearMapNode ( )

Clear the map of Node.

Definition at line 187 of file Graph_impl.h.

187{p_mapNode.clear();}

References p_mapNode.

Referenced by clearAll().

+ Here is the caller graph for this function:

◆ connectNode() [1/3]

template<typename T, typename UIdx>
void Graph< T, UIdx >::connectNode ( UIdx parent,
const std::list< UIdx > & listChildren )

Connect a parent to its children.

Parameters
parent: index of the parent Node
listChildren: list of the children index

Definition at line 282 of file Graph_impl.h.

282 {
284 if(parentNode == NULL){return;}
285 for(typename std::list<UIdx>::const_iterator it(listChildren.begin()); it != listChildren.end(); ++it){
286 UIdx child = *it;
288 if(childNode == NULL){continue;}
289 parentNode->addChild(child);
290 childNode->addParent(parent);
291 }
292}
const Node< T, UIdx > * getNode(UIdx index) const
Get a Node by pointer.
Definition Graph_impl.h:316

References Node< T, UIdx >::addChild(), Node< T, UIdx >::addParent(), and getNode().

+ Here is the call graph for this function:

◆ connectNode() [2/3]

template<typename T, typename UIdx>
void Graph< T, UIdx >::connectNode ( UIdx parent,
const std::vector< UIdx > & vecChildren )

Connect a parent to its children.

Parameters
parent: index of the parent Node
vecChildren: vector of the children index

Definition at line 299 of file Graph_impl.h.

299 {
301 if(parentNode == NULL){return;}
302 for(typename std::vector<UIdx>::const_iterator it(vecChildren.begin()); it != vecChildren.end(); ++it){
303 UIdx child = *it;
305 if(childNode == NULL){continue;}
306 parentNode->addChild(child);
307 childNode->addParent(parent);
308 }
309}

References Node< T, UIdx >::addChild(), Node< T, UIdx >::addParent(), and getNode().

+ Here is the call graph for this function:

◆ connectNode() [3/3]

template<typename T, typename UIdx>
void Graph< T, UIdx >::connectNode ( UIdx parent,
UIdx child )

Connect a parent to its child.

Parameters
parent: index of the parent Node
child: index of the child Node

Definition at line 268 of file Graph_impl.h.

268 {
270 if(parentNode == NULL){return;}
272 if(childNode == NULL){return;}
273 parentNode->addChild(child);
274 childNode->addParent(parent);
275}

References Node< T, UIdx >::addChild(), Node< T, UIdx >::addParent(), and getNode().

Referenced by removeNode().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ copyGraph()

template<typename T, typename UIdx>
void Graph< T, UIdx >::copyGraph ( const Graph< T, UIdx > & other)
protected

Copy function of Graph.

Parameters
other: class to copy

Definition at line 553 of file Graph_impl.h.

References Graph(), p_listFirstNode, p_listLastNode, and p_mapNode.

Referenced by Graph(), and operator=().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createNode() [1/2]

template<typename T, typename UIdx>
UIdx Graph< T, UIdx >::createNode ( const T & data,
const std::string & name )

Create a node and get its index.

Parameters
data: data of the Node
name: name of the Node
Returns
index of the Node

Definition at line 123 of file Graph_impl.h.

123 {
124 UIdx nodeIndex(p_mapNode.size());
125 while(getNode(nodeIndex) != NULL){
126 ++nodeIndex;
127 }
129 node.setIndex(nodeIndex);
131 return nodeIndex;
132}

References getNode(), p_mapNode, and Node< T, UIdx >::setIndex().

Referenced by createNodePtr(), and createNodePtr().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ createNode() [2/2]

template<typename T, typename UIdx>
bool Graph< T, UIdx >::createNode ( const T & data,
const UIdx & index,
const std::string & name )

Create a node and get its index.

Parameters
data: data of the Node
index: index of the Node
name: name of the Node
Returns
true if the node can be created, false if the index is already taken by an other Node

Definition at line 152 of file Graph_impl.h.

152 {
153 if(getNode(index) != NULL){ //Check if the Node already exists
154 return false;
155 }
157 node.setIndex(index);
159 return true;
160}

References getNode(), p_mapNode, and Node< T, UIdx >::setIndex().

+ Here is the call graph for this function:

◆ createNodePtr() [1/2]

template<typename T, typename UIdx>
Node< T, UIdx > * Graph< T, UIdx >::createNodePtr ( const T & data,
const std::string & name )

Create a node and get its pointer.

Parameters
data: data of the Node
name: name of the Node
Returns
pointer of the Node

Definition at line 140 of file Graph_impl.h.

140 {
142 return getNode(node);
143}
UIdx createNode(const T &data, const std::string &name)
Create a node and get its index.
Definition Graph_impl.h:123

References createNode(), and getNode().

+ Here is the call graph for this function:

◆ createNodePtr() [2/2]

template<typename T, typename UIdx>
Node< T, UIdx > * Graph< T, UIdx >::createNodePtr ( const T & data,
const UIdx & index,
const std::string & name )

Create a node and get its pointer.

Parameters
data: data of the Node
index: index of the Node
name: name of the Node
Returns
pointer of the Node

Definition at line 169 of file Graph_impl.h.

169 {
170 if(createNode(data, index, name)){
171 return getNode(index);
172 }else{
173 return NULL;
174 }
175}

References createNode(), and getNode().

+ Here is the call graph for this function:

◆ getFirstNotUpdatedNode() [1/2]

template<typename T, typename UIdx>
Node< T, UIdx > * Graph< T, UIdx >::getFirstNotUpdatedNode ( )

Get the first node which is not udpated (getIsUpdated() == false)

Returns
pointer to the first node which is not udpated or NULL if there is no

Definition at line 356 of file Graph_impl.h.

356 {
357 for(typename std::map<UIdx, Node<T, UIdx> >::iterator itNode(p_mapNode.begin()); itNode != p_mapNode.end(); ++itNode){
358 if(!itNode->second.getIsUpdated()){
359 return &(itNode->second);
360 }
361 }
362 return NULL;
363}

References p_mapNode.

◆ getFirstNotUpdatedNode() [2/2]

template<typename T, typename UIdx>
const Node< T, UIdx > * Graph< T, UIdx >::getFirstNotUpdatedNode ( ) const

Get the first node which is not udpated (getIsUpdated() == false)

Returns
pointer to the first node which is not udpated or NULL if there is no

Definition at line 343 of file Graph_impl.h.

343 {
344 for(typename std::map<UIdx, Node<T, UIdx> >::const_iterator itNode(p_mapNode.begin()); itNode != p_mapNode.end(); ++itNode){
345 if(!itNode->second.getIsUpdated()){
346 return &(itNode->second);
347 }
348 }
349 return NULL;
350}

References p_mapNode.

◆ getListFirstNode()

template<typename T, typename UIdx>
const std::list< UIdx > & Graph< T, UIdx >::getListFirstNode ( ) const

Get the list of the first nodes (without parent)

Returns
list of the first nodes (without parent)

Definition at line 387 of file Graph_impl.h.

387 {
388 return p_listFirstNode;
389}

References p_listFirstNode.

Referenced by iterateChildren(), and iterateChildrenCheckUpdate().

+ Here is the caller graph for this function:

◆ getListLastNode()

template<typename T, typename UIdx>
const std::list< UIdx > & Graph< T, UIdx >::getListLastNode ( ) const

Get the list of the last nodes (without child)

Returns
list of the last nodes (without child)

Definition at line 395 of file Graph_impl.h.

395 {
396 return p_listLastNode;
397}

References p_listLastNode.

Referenced by iterateParent(), and iterateParentCheckUpdate().

+ Here is the caller graph for this function:

◆ getNode() [1/2]

template<typename T, typename UIdx>
Node< T, UIdx > * Graph< T, UIdx >::getNode ( UIdx index)

Get a Node by pointer.

Parameters
index: index of the node to be used
Returns
pointer to this Node or NULL if the Node does not exist

Definition at line 330 of file Graph_impl.h.

330 {
332 if(it != p_mapNode.end()){
333 return &(it->second);
334 }else{
335 return NULL;
336 }
337}

References p_mapNode.

◆ getNode() [2/2]

template<typename T, typename UIdx>
const Node< T, UIdx > * Graph< T, UIdx >::getNode ( UIdx index) const

Get a Node by pointer.

Parameters
index: index of the node to be used
Returns
pointer to this Node or NULL if the Node does not exist

Definition at line 316 of file Graph_impl.h.

316 {
318 if(it != p_mapNode.end()){
319 return &(it->second);
320 }else{
321 return NULL;
322 }
323}

References p_mapNode.

Referenced by connectNode(), connectNode(), connectNode(), createNode(), createNode(), createNodePtr(), createNodePtr(), isListNodeUdpated(), iterateChildren(), iterateChildrenCheckUpdate(), iterateParent(), iterateParentCheckUpdate(), removeNode(), and toDot().

+ Here is the caller graph for this function:

◆ initialisationGraph()

template<typename T, typename UIdx>
void Graph< T, UIdx >::initialisationGraph ( )
private

Initialisation function of the class Graph.

Definition at line 561 of file Graph_impl.h.

561 {
562
563}

Referenced by Graph().

+ Here is the caller graph for this function:

◆ isListNodeUdpated()

template<typename T, typename UIdx>
bool Graph< T, UIdx >::isListNodeUdpated ( const std::list< UIdx > & listNode) const

Check if the list of given nodes are all updated or not.

Parameters
listNode: list of nodes to be checked
Returns
true fi all nodes are updated, false otherwise

Definition at line 460 of file Graph_impl.h.

460 {
461 bool b(true);
462 for(typename std::list<UIdx>::const_iterator itNode(listNode.begin()); itNode != listNode.end() && b; ++itNode){
463 const Node<T, UIdx> * node = getNode(*itNode);
464 if(node != NULL){
465 b &= node->getIsUpdated();
466 }
467 }
468 return b;
469}

References Node< T, UIdx >::getIsUpdated(), and getNode().

Referenced by iterateChildrenCheckUpdate(), and iterateParentCheckUpdate().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ isNodeExist()

template<typename T, typename UIdx>
bool Graph< T, UIdx >::isNodeExist ( UIdx index) const

Say if the node at index does exit.

Parameters
index: index of the node to be searched
Returns
true if the Node does exist, false otheriwse

Definition at line 370 of file Graph_impl.h.

370 {
372 return it != p_mapNode.end();
373}

References p_mapNode.

◆ iterateChildren()

template<typename T, typename UIdx>
bool Graph< T, UIdx >::iterateChildren ( std::list< UIdx > & listNode) const

Iterate from parents to chidren.

Parameters
[out]listNode: list node which can be treated simultaneously
Returns
true if the returned list of nodes is not empty, false if the bottom of the Graph has been reached

Definition at line 404 of file Graph_impl.h.

404 {
405 if(listNode.size() == 0lu){
407 }else{
409 for(typename std::list<UIdx>::iterator itNode(listNode.begin()); itNode != listNode.end(); ++itNode){
410 const Node<T, UIdx> * node = getNode(*itNode);
411 if(node != NULL){
412 const std::list<UIdx> & listChildren = node->getListChild();
413 for(typename std::list<UIdx>::const_iterator it(listChildren.begin()); it != listChildren.end(); ++it){
414 mapListChildren[*it] = true;
415 }
416 }
417 }
419 for(typename std::map<UIdx, bool>::iterator it(mapListChildren.begin()); it != mapListChildren.end(); ++it){
420 listNodeOut.push_back(it->first);
421 }
423 }
424 return listNode.size() != 0lu;
425}
size_t size() const
Get the number of nodes inside the graph.
Definition Graph_impl.h:379
const std::list< UIdx > & getListFirstNode() const
Get the list of the first nodes (without parent)
Definition Graph_impl.h:387

References Node< T, UIdx >::getListChild(), getListFirstNode(), and getNode().

+ Here is the call graph for this function:

◆ iterateChildrenCheckUpdate()

template<typename T, typename UIdx>
bool Graph< T, UIdx >::iterateChildrenCheckUpdate ( std::list< UIdx > & listNode)

Iterate from parents to chidren (all node are iterated only once)

Parameters
[out]listNode: list node which can be treated simultaneously
Returns
true if the returned list of nodes is not empty, false if the bottom of the Graph has been reached

Definition at line 476 of file Graph_impl.h.

476 {
477 if(listNode.size() == 0lu){
480 }else{
482 for(typename std::list<UIdx>::iterator itNode(listNode.begin()); itNode != listNode.end(); ++itNode){
484 if(node != NULL){
485 node->setIsUpdated(true); //This node has been iterated, so we do not want to pick it as a child
486 std::list<UIdx> & listChildren = node->getListChild();
487 for(typename std::list<UIdx>::iterator it(listChildren.begin()); it != listChildren.end(); ++it){
489 if(nodeChild != NULL){
490 if(!nodeChild->getIsUpdated()){
491 //The child node is added only if its parents are updated
492 if(isListNodeUdpated(nodeChild->getListParent())){
493 mapListChildren[*it] = true;
494 nodeChild->setIsUpdated(true);
495 }
496 }
497 }
498 }
499 }
500 }
502 for(typename std::map<UIdx, bool>::iterator it(mapListChildren.begin()); it != mapListChildren.end(); ++it){
503 listNodeOut.push_back(it->first);
504 }
506 }
507 return listNode.size() != 0lu;
508}
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
void clearIsUpdated()
Clear the isUpdated attriburte of the Node.
Definition Graph_impl.h:179

References clearIsUpdated(), Node< T, UIdx >::getIsUpdated(), Node< T, UIdx >::getListChild(), getListFirstNode(), Node< T, UIdx >::getListParent(), getNode(), isListNodeUdpated(), and Node< T, UIdx >::setIsUpdated().

+ Here is the call graph for this function:

◆ iterateParent()

template<typename T, typename UIdx>
bool Graph< T, UIdx >::iterateParent ( std::list< UIdx > & listNode) const

Iterate from children to parents.

Parameters
[out]listNode: list node which can be treated simultaneously
Returns
true if the returned list of nodes is not empty, false if the top of the Graph has been reached

Definition at line 432 of file Graph_impl.h.

432 {
433 if(listNode.size() == 0lu){
435 }else{
437 for(typename std::list<UIdx>::iterator itNode(listNode.begin()); itNode != listNode.end(); ++itNode){
438 const Node<T, UIdx> * node = getNode(*itNode);
439 if(node != NULL){
440 const std::list<UIdx> & listParent = node->getListParent();
441 for(typename std::list<UIdx>::const_iterator it(listParent.begin()); it != listParent.end(); ++it){
442 mapListParent[*it] = true;
443 }
444 }
445 }
447 for(typename std::map<UIdx, bool>::iterator it(mapListParent.begin()); it != mapListParent.end(); ++it){
448 listNodeOut.push_back(it->first);
449 }
451 }
452 return listNode.size() != 0lu;
453}
const std::list< UIdx > & getListLastNode() const
Get the list of the last nodes (without child)
Definition Graph_impl.h:395

References getListLastNode(), Node< T, UIdx >::getListParent(), and getNode().

+ Here is the call graph for this function:

◆ iterateParentCheckUpdate()

template<typename T, typename UIdx>
bool Graph< T, UIdx >::iterateParentCheckUpdate ( std::list< UIdx > & listNode)

Iterate from children to parents (all node are iterated only once)

Parameters
[out]listNode: list node which can be treated simultaneously
Returns
true if the returned list of nodes is not empty, false if the top of the Graph has been reached

Definition at line 515 of file Graph_impl.h.

515 {
516 if(listNode.size() == 0lu){
519 }else{
521 for(typename std::list<UIdx>::iterator itNode(listNode.begin()); itNode != listNode.end(); ++itNode){
523 if(node != NULL){
524 node->setIsUpdated(true); //This node has been iterated, so we do not want to pick it as a parent
525 std::list<UIdx> & listParent = node->getListParent();
526 for(typename std::list<UIdx>::iterator it(listParent.begin()); it != listParent.end(); ++it){
528 if(nodeParent != NULL){
529 if(!nodeParent->getIsUpdated()){
530 //The parent node is added only if its children are updated
531 if(isListNodeUdpated(nodeParent->getListChild())){
532 mapListParent[*it] = true;
533 nodeParent->setIsUpdated(true);
534 }
535 }
536 }
537 }
538 }
539 }
541 for(typename std::map<UIdx, bool>::iterator it(mapListParent.begin()); it != mapListParent.end(); ++it){
542 listNodeOut.push_back(it->first);
543 }
545 }
546 return listNode.size() != 0lu;
547}

References clearIsUpdated(), Node< T, UIdx >::getIsUpdated(), Node< T, UIdx >::getListChild(), getListLastNode(), Node< T, UIdx >::getListParent(), getNode(), isListNodeUdpated(), and Node< T, UIdx >::setIsUpdated().

+ Here is the call graph for this function:

◆ operator=()

template<typename T, typename UIdx>
Graph< T, UIdx > & Graph< T, UIdx >::operator= ( const Graph< T, UIdx > & other)

Definition of equal operator of Graph.

Parameters
other: class to copy
Returns
copied class

Definition at line 40 of file Graph_impl.h.

40 {
42 return *this;
43}

References copyGraph(), and Graph().

+ Here is the call graph for this function:

◆ removeNode()

template<typename T, typename UIdx>
void Graph< T, UIdx >::removeNode ( UIdx index,
bool reconnectParentToChildren = false )

Remove a Node from the Graph.

Parameters
index: index of the Node to be removed
reconnectParentToChildren: true to reconnect parents of the node to be removed to its children

Definition at line 210 of file Graph_impl.h.

210 {
212 if(indexNode == NULL){return;} //If the Node does not exist, we stop
213 //Get the parents of the current Node
214 std::list<UIdx> & listParent = indexNode->getListParent();
215 if(listParent.size() != 0lu){
216 //Tell them they do not have child anymore
217 for(typename std::list<UIdx>::iterator it(listParent.begin()); it != listParent.end(); ++it){
219 if(parentNode == NULL){continue;}
220 parentNode->removeChild(index);
221 }
222 }else{
223 //Let's remove the current Node from first Node
225 }
226 //Get the children of the current Node
227 std::list<UIdx> & listChild = indexNode->getListChild();
228 if(listChild.size() != 0lu){
229 //Tell them they do not have parent anymore
230 for(typename std::list<UIdx>::iterator it(listChild.begin()); it != listChild.end(); ++it){
232 if(childNode == NULL){continue;}
233 childNode->removeParent(index);
234 }
235 }else{
236 //Let's remove the current Node from last Node
238 }
240 for(typename std::list<UIdx>::iterator it(listParent.begin()); it != listParent.end(); ++it){
242 }
243 }
244 //Now, let's remove the current Node
245 p_mapNode.erase(index);
246}
void connectNode(UIdx parent, UIdx child)
Connect a parent to its child.
Definition Graph_impl.h:268
void listindex_remove(std::list< UIdx > &listIndex, UIdx index)
Remove index from listIndex.

References connectNode(), Node< T, UIdx >::getListChild(), Node< T, UIdx >::getListParent(), getNode(), listindex_remove(), p_listFirstNode, p_listLastNode, p_mapNode, Node< T, UIdx >::removeChild(), and Node< T, UIdx >::removeParent().

+ Here is the call graph for this function:

◆ saveDot() [1/2]

template<typename T, typename UIdx>
bool Graph< T, UIdx >::saveDot ( const std::string & fileName) const

Save the Graph in a dot file.

Parameters
fileName: name of the file to be created

Definition at line 69 of file Graph_impl.h.

69 {
70 if(fileName == ""){return false;}
72 fs.open(fileName.c_str());
73 if(!fs.is_open()){
74 std::cerr << "Graph<T, UIdx>::saveDot : can't open file '" << fileName << "'" << std::endl;
75 return false;
76 }
77 bool b(saveDot(fs));
78 fs.close();
79 return b;
80}
bool saveDot(const std::string &fileName) const
Save the Graph in a dot file.
Definition Graph_impl.h:69

References saveDot().

Referenced by saveDot(), and savePng().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ saveDot() [2/2]

template<typename T, typename UIdx>
bool Graph< T, UIdx >::saveDot ( std::ofstream & fs) const

Save the Graph in a dot file.

Parameters
[out]fs: file stream to be modified

Definition at line 86 of file Graph_impl.h.

86 {
87 fs << toDot();
88 return true;
89}
std::string toDot() const
Convert the graph to dot language.
Definition Graph_impl.h:95

References toDot().

+ Here is the call graph for this function:

◆ savePng()

template<typename T, typename UIdx>
bool Graph< T, UIdx >::savePng ( const std::string & fileNamePng) const

Save a png file of the graph.

Parameters
fileNamePng: name of the png file
Returns
true on success, false otherwise

Definition at line 50 of file Graph_impl.h.

50 {
51 if(fileNamePng == "") return false;
52 std::string fileTxt("output.dot");
53 if(!saveDot(fileTxt)){
54 std::cerr << "Graph<T, UIdx>::savePng : can't create file '" << fileTxt << "'" << std::endl;
55 return false;
56 }
57 std::string commande("dot -Tpng -o " + fileNamePng + " " + fileTxt + " && rm " + fileTxt);
58 if(system(commande.c_str()) != 0){
59 std::cerr << "Graph<T, UIdx>::savePng : can't create png file '" << fileNamePng << "'" << std::endl;
60 return false;
61 }
62 return true;
63}

References saveDot().

+ Here is the call graph for this function:

◆ size()

template<typename T, typename UIdx>
size_t Graph< T, UIdx >::size ( ) const

Get the number of nodes inside the graph.

Returns
number of nodes inside the graph

Definition at line 379 of file Graph_impl.h.

379 {
380 return p_mapNode.size();
381}

References p_mapNode.

◆ toDot()

template<typename T, typename UIdx>
std::string Graph< T, UIdx >::toDot ( ) const

Convert the graph to dot language.

Returns
dot

Definition at line 95 of file Graph_impl.h.

95 {
96 std::string body("");
97 body += "digraph G{\n";
98 //save the node definition
99 for(typename std::map<UIdx, Node<T, UIdx> >::const_iterator it(p_mapNode.begin()); it != p_mapNode.end(); ++it){
100 body += it->second.getDotDefinition();
101 }
102 //save the connections between nodes
103 for(typename std::map<UIdx, Node<T, UIdx> >::const_iterator itNode(p_mapNode.begin()); itNode != p_mapNode.end(); ++itNode){
104 const std::string & parentNodeName(itNode->second.getDotName());
105 const std::list<UIdx> & listChild = itNode->second.getListChild();
106 for(typename std::list<UIdx>::const_iterator it(listChild.begin()); it != listChild.end(); ++it){
107 const Node<T, UIdx> * childNode = getNode(*it);
108 if(childNode == NULL){continue;}
109 const std::string & childNodeName(childNode->getDotName());
110 body += "\t" + parentNodeName + " -> " + childNodeName + "[color=\"red\"];\n";
111 }
112 }
113 body += "}\n\n";
114 return body;
115}

References Node< T, UIdx >::getDotName(), getNode(), and p_mapNode.

Referenced by saveDot().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ updateFirstLastNode()

template<typename T, typename UIdx>
void Graph< T, UIdx >::updateFirstLastNode ( )

Update the first and last Node of the Graph.

Definition at line 250 of file Graph_impl.h.

250 {
253 for(typename std::map<UIdx, Node<T, UIdx> >::iterator itNode(p_mapNode.begin()); itNode != p_mapNode.end(); ++itNode){
254 if(itNode->second.isStart()){ //If the Node does not have any parent, it is a first Node
255 p_listFirstNode.push_back(itNode->first);
256 }
257 if(itNode->second.isEnd()){ //If the Node does not have any child, it is a last Node
258 p_listLastNode.push_back(itNode->first);
259 }
260 }
261}

References clearFirstNode(), clearLastNode(), p_listFirstNode, p_listLastNode, and p_mapNode.

+ Here is the call graph for this function:

Member Data Documentation

◆ p_listFirstNode

template<typename T, typename UIdx>
std::list<UIdx> Graph< T, UIdx >::p_listFirstNode
private

List of the first Node (without parent)

Definition at line 80 of file Graph.h.

Referenced by clearFirstNode(), copyGraph(), getListFirstNode(), removeNode(), and updateFirstLastNode().

◆ p_listLastNode

template<typename T, typename UIdx>
std::list<UIdx> Graph< T, UIdx >::p_listLastNode
private

List of the last Node (without child)

Definition at line 82 of file Graph.h.

Referenced by clearLastNode(), copyGraph(), getListLastNode(), removeNode(), and updateFirstLastNode().

◆ p_mapNode

template<typename T, typename UIdx>
std::map<UIdx, Node<T, UIdx> > Graph< T, UIdx >::p_mapNode
private

The documentation for this class was generated from the following files: