Mace C++ Graph Library 1.0
The fast and flexible graph library for C++. Developed by Matthias Mace H├Ądrich.
Public Member Functions | Protected Member Functions | Private Attributes
graph Class Reference

This is the abstract base class for all graphs. More...

#include <graph.h>

Inheritance diagram for graph:
directed_graph undirected_graph

List of all members.

Public Member Functions

 graph ()
 The constructor.
 ~graph ()
 The destructor.
DLL bool add_vertex (std::string name, int weight=0)
 Add a vertex to the graph.
DLL bool add_vertex (vertex *p_vertex)
 Add a vertex to the graph.
virtual DLL bool add_edge (vertex *p_src, vertex *p_dest, int weight=0)=0
virtual DLL bool add_edge (vertex *p_src, edge *p_edge)=0
DLL bool remove_vertex (std::string name)
 Removes a vertex with a given name name.
DLL bool remove_vertex (vertex *p_vertex)
 Removes the vertex p_vertex from the graph.
virtual DLL bool remove_edge (vertex *p_vertex_0, vertex *p_vertex_1)=0
virtual DLL bool remove_edge (edge *p_edge)=0
DLL void vertices_output (std::ostream &ostream)
 Output function which receives a reference to an output stream to operate on.
DLL std::vector< vertex * > & vertices ()
 Get all vertices of the graph.

Protected Member Functions

size_t vertices_count ()
 Return the count of vertices in the graph.
size_t edges_count ()
 Return the count of edges in the graph.
std::string name ()
 Return the name of the graph.
void set_name (std::string name)
 Set the name of the graph.
bool parallels_allowed ()
 Return parallels allowed state.
void set_parallels_allowed (bool allowed)
 Set parallels allowed state.
bool has_loop ()
 Check the graph for loops.
bool are_adjacent (vertex *p_vertex_0, vertex *p_vertex_1)
 Check if two vertices are adjacent.
vertexget_vertex_by_name (std::string name)
 Find a vertex with the given name name.
vertexfind_source (edge *p_edge)
 Find the source vertex of the edge.
bool remove_edges_pointing_to (vertex *p_vertex)
 Remove all edges poiting to the vertex p_vertex.

Private Attributes

std::string m_name
bool m_parallels_allowed
std::vector< vertex * > m_vertices

Detailed Description

This is the abstract base class for all graphs.

This class is the base class for all graphs. It's made abstract by containing pure virtual functions.
These functions have to be reimplemented in the classes that inherit this class.

Definition at line 77 of file graph.h.


Constructor & Destructor Documentation

graph::graph ( )

The constructor.

Definition at line 12 of file graph.cpp.

graph::~graph ( )

The destructor.

For all vertices there has been memory allocated which should be freed now.

Definition at line 21 of file graph.cpp.


Member Function Documentation

virtual DLL bool graph::add_edge ( vertex p_src,
vertex p_dest,
int  weight = 0 
) [pure virtual]

Implemented in directed_graph, and undirected_graph.

virtual DLL bool graph::add_edge ( vertex p_src,
edge p_edge 
) [pure virtual]

Implemented in directed_graph, and undirected_graph.

bool graph::add_vertex ( vertex p_vertex)

Add a vertex to the graph.

Adds the vertex _vertex to the vector of vertices of the graph.

Returns:
True if vertex could be added, false if vertex could not be added.

Definition at line 142 of file graph.cpp.

bool graph::add_vertex ( std::string  name,
int  weight = 0 
)

Add a vertex to the graph.

Creates a vertex with the given name and weight, then adds it to the graph.

Returns:
True if vertex could be added, false if vertex could not be added.

Definition at line 121 of file graph.cpp.

bool graph::are_adjacent ( vertex p_vertex_0,
vertex p_vertex_1 
) [protected]

Check if two vertices are adjacent.

Note:
The class directed_graph can also be checked for strong adjacency.
Returns:
True if vertices are adjacent, false if not.
See also:
directed_graph

Definition at line 298 of file graph.cpp.

size_t graph::edges_count ( ) [protected]

Return the count of edges in the graph.

Returns:
Edge count.

Definition at line 62 of file graph.cpp.

vertex * graph::find_source ( edge p_edge) [protected]

Find the source vertex of the edge.

Returns:
A pointer to the source vertex of the edge.

Definition at line 313 of file graph.cpp.

vertex * graph::get_vertex_by_name ( std::string  name) [protected]

Find a vertex with the given name name.

Returns:
A pointer to the vertex with the name name.

Definition at line 220 of file graph.cpp.

bool graph::has_loop ( ) [protected]

Check the graph for loops.

Checks every vertex in the graph for edges that point to the vertex itself. Cancels the search if a loop has been found.

Returns:
True if a loop has been found, false if the graph doesn't contain a loop.

Definition at line 245 of file graph.cpp.

std::string graph::name ( ) [protected]

Return the name of the graph.

Returns:
Graph name.

Definition at line 80 of file graph.cpp.

bool graph::parallels_allowed ( ) [protected]

Return parallels allowed state.

Returns:
True if parallel edges are allowed, false if not.

Definition at line 101 of file graph.cpp.

virtual DLL bool graph::remove_edge ( vertex p_vertex_0,
vertex p_vertex_1 
) [pure virtual]

Implemented in directed_graph, and undirected_graph.

virtual DLL bool graph::remove_edge ( edge p_edge) [pure virtual]

Implemented in directed_graph, and undirected_graph.

bool graph::remove_edges_pointing_to ( vertex p_vertex) [protected]

Remove all edges poiting to the vertex p_vertex.

This finds and removes all edges which have p_vertex as destination.

Returns:
True if one or more edges have been removed, false if no linked edges could be found.

Definition at line 337 of file graph.cpp.

bool graph::remove_vertex ( std::string  name)

Removes a vertex with a given name name.

Returns:
True if vertex could be deleted, false if not.

Definition at line 168 of file graph.cpp.

bool graph::remove_vertex ( vertex p_vertex)

Removes the vertex p_vertex from the graph.

When removing a vertex, all edges linked to this vertex have to be removed to.
This means that every edge that has this vertex as source or destination has to be found and removed.

Returns:
True if vertex could be deleted, false if not.

Definition at line 188 of file graph.cpp.

void graph::set_name ( std::string  name) [protected]

Set the name of the graph.

Definition at line 88 of file graph.cpp.

void graph::set_parallels_allowed ( bool  allowed) [protected]

Set parallels allowed state.

Definition at line 109 of file graph.cpp.

std::vector< vertex * > & graph::vertices ( )

Get all vertices of the graph.

Returns:
A reference to the vector containing pointers to every vertex in the graph.

Definition at line 42 of file graph.cpp.

size_t graph::vertices_count ( ) [protected]

Return the count of vertices in the graph.

Returns:
Vertex count.

Definition at line 52 of file graph.cpp.

void graph::vertices_output ( std::ostream &  ostream)

Output function which receives a reference to an output stream to operate on.

Returns:
No return value. But the given output stream will be modified.

Definition at line 268 of file graph.cpp.


Member Data Documentation

std::string graph::m_name [private]

Definition at line 120 of file graph.h.

Definition at line 121 of file graph.h.

std::vector<vertex*> graph::m_vertices [private]

Definition at line 122 of file graph.h.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Defines