Graph. More...
#include <rgraph.h>
Collaboration diagram for RGraph< V, E, bAllocVertices, bAllocEdges >:
Public Member Functions | |
void | Clear (void) |
virtual E * | CreateEdge (V *v1, V *v2, double w) |
virtual V * | CreateVertex (void) |
virtual V * | CreateVertex (const size_t id) |
void | DeleteEdge (E *e) |
void | DeleteVertex (V *v) |
RCursor< E > | GetEdges (void) const |
V * | GetVertex (const size_t id) |
RCursor< V > | GetVertices (void) const |
void | Insert (V *v) |
void | InsertEdge (E *e) |
void | MinSpanningTree (RGraph *g) |
RGraph (size_t nb) | |
virtual | ~RGraph (void) |
Protected Attributes | |
RContainer< E, bAllocEdges, false > | Edges |
RContainer< V, bAllocVertices, false > | Vertices |
Detailed Description
template<class V, class E, bool bAllocVertices = true, bool bAllocEdges = true>
class R::RGraph< V, E, bAllocVertices, bAllocEdges >
Graph.
The RGraph class provides a template that represents of a graph.
- Template Parameters
-
V Class representing a vertex. It must inherits from RVertex. E Class representing an edge. It must inherits from REdge. bAllocVertices Specify if the vertices are deallocated by the graph. bAllocEdges Specify if the edges are deallocated by the graph. In practice, the RVertex and REdge classes can be used directly to initialize an instance: int main(){// Create a graphRGraph<RVertex,REdge,true,true> Graph(5);RVertex* v1(Graph.CreateVertex());RVertex* v2(Graph.CreateVertex());RVertex* v3(Graph.CreateVertex());Graph.CreateEdge(v1,v2,2.0);Graph.CreateEdge(v2,v3,1.0);Graph.CreateEdge(v2,v3,5.0);// Compute the minimum spanning treeRGraph<RVertex,REdge,true,true> MinTree(5);Graph.MinSpanningTree(&MinTree);}
Constructor & Destructor Documentation
RGraph | ( | size_t | nb | ) |
Constructor of the graph.
- Parameters
-
nb Number of edges.
|
virtual |
Destruct the graph.
Member Function Documentation
void Clear | ( | void | ) |
Clear the graph and destruct the elements.
RCursor<V> GetVertices | ( | void | ) | const |
Get a cursor over the vertices of the graph.
RCursor<E> GetEdges | ( | void | ) | const |
Get a cursor over the edges of the graph.
void Insert | ( | V * | v | ) |
Insert a vertex. It cannot have edges.
- Parameters
-
v Vertex to insert.
|
virtual |
Create a vertex.
- Returns
- Pointer to the new created vertex.
|
virtual |
Create a vertex with a given identifier.
- Parameters
-
id Identifier.
- Returns
- Pointer to the new created vertex.
V* GetVertex | ( | const size_t | id | ) |
Get the vertex with a given identifier. If the vertex doesn't exist, it's created.
- Parameters
-
id Identifier.
- Returns
- Pointer to the vertex.
void InsertEdge | ( | E * | e | ) |
Insert an edge.
- Parameters
-
e Edge to insert.
|
virtual |
Create an edge.
- Parameters
-
v1 First Vertex. v2 First Vertex. w Weight.
void DeleteVertex | ( | V * | v | ) |
Delete a vertex with all the edges connected to it.
- Parameters
-
v Vertex.
void DeleteEdge | ( | E * | e | ) |
Delete an edge with all the corresponding vertices.
- Parameters
-
e Edge.
void MinSpanningTree | ( | RGraph< V, E, bAllocVertices, bAllocEdges > * | g | ) |
Compute the minimum spanning trees using the Prim's algorithm.
- Parameters
-
g The graph that will hold the result.
Member Data Documentation
|
protected |
The vertices of the graph.
|
protected |
The edges of the graph.