Tuesday, July 7, 2009

Traits

#ifndef EDGETYPETRAITS_H
#define EDGETYPETRAITS_H

// General
template
class edgeTypeTraits;
// =============================================
// Edge Specialization
template <>
class edgeTypeTraits
{
public:
typedef edge edgeType;
};
// =============================================
// Arcs Specialization
template <>
class edgeTypeTraits
{
public:
typedef arcs edgeType;
};
// =============================================
#endif


#ifndef VERTEXTYPETRAITS_H
#define VERTEXTYPETRAITS_H

class edge;
class arcs;

template
class vertex;


// Base class no definition
template
class vertexTypeTraits;


// Partial Specialization
template
class vertexTypeTraits
{
public:
typedef boost::shared_ptr > vertexPtr;
typedef std::vector allVertexVector;
typedef edge edgeType;
};


// Partial Specialization
template
class vertexTypeTraits
{
public:
typedef boost::shared_ptr > vertexPtr;
typedef std::vector allVertexVector;
typedef arcs edgeType;
};
#endif

/*
Traits
= A class template used to describle
another class template parameter
= If/else of type
= Used to Type Parameterize

The compiler looks up information
about the edgeType from graph class template
in the vertex's traits class

Example:
1. char_traits
2. float_traits(std::numeric_limits)

*/



Usage in Graph.h

template
class graph
{
public:

typedef edgeType edgeType;
typedef typename vertexTypeTraits::vertexPtr vertexPtr;
}




No comments: