Functions defined in Types.h facilitate the (de)serialization of enum labels, here refered to as types. This is useful, e.g., when reading/writing the type of an object to a file. More...

Functions

template<class T >
std::string nuklei::catTypeNames ()
 Cats all type names into a string. More...
 
template<class T >
std::vector< std::string > nuklei::listTypeNames ()
 Fills a std::vector with all type names.
 
template<class T >
std::string nuklei::defaultTypeName ()
 Returns the default type name.
 
template<class T >
T::Type nuklei::defaultType ()
 Returns the default type.
 
template<class T >
std::string nuklei::nameFromType (int t)
 Returns the name of type t.
 
template<class T >
T::Type nuklei::typeFromName (std::string s)
 Returns the type whose name is s.
 

Detailed Description

Functions defined in Types.h facilitate the (de)serialization of enum labels, here refered to as types. This is useful, e.g., when reading/writing the type of an object to a file.

In order to afford the functions defined above, a class MyClass needs to define the following members:

class MyClass
{
public:
typedef enum { TYPE1, TYPE2, UNKNOWN } Type;
static const Type defaultType = TYPE1;
static const std::string TypeNames[];
};
// (The following line should be put in an implementation file (a .cpp file):
const std::string MyClass::TypeNames[] = { "type1", "type2", "unknown" };

Then, an expression such as

nameFromType(MyClass::TYPE1)

will return the string "type1".

Examples of classes implementing this interface: nuklei::kernel::base, nuklei::Observation, nuklei::Color.

Function Documentation

◆ catTypeNames()

template<class T >
std::string nuklei::catTypeNames ( )

Cats all type names into a string.

Names are separated by a bar. The default name is followed by a star.

Definition at line 28 of file Types.h.

References nuklei::defaultType().

std::string nameFromType(int t)
Returns the name of type t.
Definition: Types.h:66
T::Type defaultType()
Returns the default type.
Definition: Types.h:59
© Copyright 2007-2013 Renaud Detry.
Distributed under the terms of the GNU General Public License (GPL).
(See accompanying file LICENSE.txt or copy at http://www.gnu.org/copyleft/gpl.html.)
Revised Sun Sep 13 2020 19:10:07.