MorphoGraphX
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Classes | Public Types | Public Member Functions | Static Public Attributes | Protected Member Functions | Protected Attributes | Friends | List of all members
mgx::graph::Vertex< VertexContent, Alloc > Class Template Reference

Vertex of a vv graph. More...

+ Inheritance diagram for mgx::graph::Vertex< VertexContent, Alloc >:

Classes

struct  CountedContent
 Type of the reference counted content. More...
 

Public Types

typedef vertex_identity_t identity_t
 Type of the identifier of the vertex.
 
typedef VertexContent content_t
 Type of the content of the vertex.
 
typedef WeakVertex
< VertexContent, Alloc > 
weak_ref_t
 
typedef VertexContent * pointer
 Type of the equivalent pointer.
 

Public Member Functions

 Vertex ()
 Creates a new vertex with a new content. More...
 
 Vertex (identity_t id)
 Creates a reference on the vertex of identifier id. More...
 
 Vertex (const Vertex &copy)
 Copy a vertex. More...
 
 Vertex (const weak_ref_t &w)
 Construct a strong reference from a weak one.
 
 ~Vertex ()
 Desctructor.
 
VertexContent * operator-> () const
 Access to the data. More...
 
VertexContent & operator* () const
 Access to the data. More...
 
Vertexoperator= (const Vertex &other)
 Change the vertex held by the current object. More...
 
Vertexoperator= (const identity_t &id)
 
Vertexoperator= (const weak_ref_t &other)
 
Vertexoperator= (const VertexContent *value)
 
bool operator== (const Vertex &other) const
 Comparison operators. More...
 
bool operator!= (const Vertex &other) const
 Comparison operators. More...
 
bool operator> (const Vertex &other) const
 Comparison operators. More...
 
bool operator< (const Vertex &other) const
 Comparison operators. More...
 
bool operator>= (const Vertex &other) const
 Comparison operators. More...
 
bool operator<= (const Vertex &other) const
 Comparison operators. More...
 
bool isNull () const
 Test if a vertex is a null vertex.
 
identity_t id () const
 Return the identifier of a vertex.
 
size_t num () const
 Return a number unique to each vertex, globally.
 
 operator bool () const
 Convert a vertex to true if it is not null.
 
bool isWeakRef () const
 Return true if the current object hold a weak reference on a vertex.
 
weak_ref_t weakRef () const
 Construct a weak reference on the current vertex.
 
unsigned int count () const
 Serialization method. More...
 

Static Public Attributes

static Vertex null
 Null vertex. More...
 

Protected Member Functions

void release ()
 Release the current pointer.
 
void acquire ()
 Acquire the current pointer.
 

Protected Attributes

CountedContentcontent
 Content of the vertex. More...
 

Friends

class WeakVertex< VertexContent, Alloc >
 

Detailed Description

template<typename VertexContent, typename Alloc>
class mgx::graph::Vertex< VertexContent, Alloc >

Vertex of a vv graph.

The vertexes handle their associated data using a reference counting scheme. As such, they can be used as smart pointers. They are also comparable (<,>,==,!=), which allow for use in any sorted structure and hashable for use in any hash table-based structure.

They also all have a unique identifier. This identifier can be used to retrieve a weak reference on the data.

Warning
A weak reference won't keep the data alive! So be careful when you use those. You can test if a vertex hold a weak reference using the Vertex<VertexContent>::isWeakRef() method.

Constructor & Destructor Documentation

template<typename VertexContent , typename Alloc >
mgx::graph::Vertex< VertexContent, Alloc >::Vertex ( )

Creates a new vertex with a new content.

Example:

struct VertexContent { int a; }
// ...
Vertex<VertexContent> v;
v->a = 10;
template<typename VertexContent , typename Alloc >
mgx::graph::Vertex< VertexContent, Alloc >::Vertex ( identity_t  id)
explicit

Creates a reference on the vertex of identifier id.

If id is 0, creates a null vertex.

Parameters
[in]idLabel of the vertex to retrieve.
Warning
This function is very unsafe if used with anything but 0 as an identifier.

Example:

typedef Vertex<VertexContent> vertex;
vertex v;
vertex::identity_t i = v.id();
vertex v1(i);
assert(v1 == v);
template<typename VertexContent , typename Alloc >
mgx::graph::Vertex< VertexContent, Alloc >::Vertex ( const Vertex< VertexContent, Alloc > &  copy)

Copy a vertex.

The data is not copied. The quality of the copy (i.e. weak/strong reference) is the same as the copied.

Member Function Documentation

template<typename VertexContent, typename Alloc>
unsigned int mgx::graph::Vertex< VertexContent, Alloc >::count ( ) const
inline

Serialization method.

Warning
You need to include <storage/graph.h> to use this serialization method
template<typename VertexContent, typename Alloc>
bool mgx::graph::Vertex< VertexContent, Alloc >::operator!= ( const Vertex< VertexContent, Alloc > &  other) const
inline

Comparison operators.

Note
the comparisons work on the identifiers, not the contents!
template<typename VertexContent, typename Alloc>
VertexContent& mgx::graph::Vertex< VertexContent, Alloc >::operator* ( ) const
inline

Access to the data.

Warning
Do not try to access the data of the null vertex.
template<typename VertexContent, typename Alloc>
VertexContent* mgx::graph::Vertex< VertexContent, Alloc >::operator-> ( ) const
inline

Access to the data.

Warning
Do not try to access the data of the null vertex.
template<typename VertexContent, typename Alloc>
bool mgx::graph::Vertex< VertexContent, Alloc >::operator< ( const Vertex< VertexContent, Alloc > &  other) const
inline

Comparison operators.

Note
the comparisons work on the identifiers, not the contents!
template<typename VertexContent, typename Alloc>
bool mgx::graph::Vertex< VertexContent, Alloc >::operator<= ( const Vertex< VertexContent, Alloc > &  other) const
inline

Comparison operators.

Note
the comparisons work on the identifiers, not the contents!
template<typename VertexContent , typename Alloc >
Vertex< VertexContent, Alloc > & mgx::graph::Vertex< VertexContent, Alloc >::operator= ( const Vertex< VertexContent, Alloc > &  other)

Change the vertex held by the current object.

The data is never modified by this operation. If you wish to copy the data of a vertex v1 into a vertex v2 use:

*v2 = *v1;
template<typename VertexContent, typename Alloc>
bool mgx::graph::Vertex< VertexContent, Alloc >::operator== ( const Vertex< VertexContent, Alloc > &  other) const
inline

Comparison operators.

Note
the comparisons work on the identifiers, not the contents!
template<typename VertexContent, typename Alloc>
bool mgx::graph::Vertex< VertexContent, Alloc >::operator> ( const Vertex< VertexContent, Alloc > &  other) const
inline

Comparison operators.

Note
the comparisons work on the identifiers, not the contents!
template<typename VertexContent, typename Alloc>
bool mgx::graph::Vertex< VertexContent, Alloc >::operator>= ( const Vertex< VertexContent, Alloc > &  other) const
inline

Comparison operators.

Note
the comparisons work on the identifiers, not the contents!

Member Data Documentation

template<typename VertexContent, typename Alloc>
CountedContent* mgx::graph::Vertex< VertexContent, Alloc >::content
mutableprotected

Content of the vertex.

This member is mutable to allow for modification of constant references. This is useful as no operation on the vertex depend on this.

template<typename VertexContent, typename Alloc>
Vertex< VertexContent, Alloc > mgx::graph::Vertex< VertexContent, Alloc >::null
static

Null vertex.

Useful to return a constant reference on a vertex all the time.

Example:

const vertex& fct(bool cond)
{
static vertex a;
if(cond)
return a;
return vertex::null;
}

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