C++ Extensions (cppx) Documentation Internal Version
Main | Namespaces | Classes | NamespaceMembers | ClassMembers | Files

stdx::Enum Class Reference

Standard C++ enums have some problems including the type-safety issues, lack of a containing namespace, the inability to easily print enums, and no support for extending an enum. The following simple class solves these problems with relatively little burden on the programmer. An example is below:

 \\ In the header file
 struct Fruit : public stdx::Enum {

   static const Fruit apple;
   static const Fruit orange;
   static const Fruit pear;

  protected:
   Fruit( const char* name ) : stdx::Enum( name ) { }
    
 };

 \\ In the source file

 STDX_INIT_ENUM( Fruit, apple );
 STDX_INIT_ENUM( Fruit, orange );
 STDX_INIT_ENUM( Fruit, pear );

An enumeration should inherit from stdx::Enum and provide a a single constructor which takes a character string as input. The enumeration should contain static const members for each possible enum value. The helper macros in the source file initialize the static members and also makes sure the members get passed strings reflecting their value. This makes it easy to print out the value of an enum.

Inheritance diagram for stdx::Enum:

Inheritance graph
[legend]
List of all members.

Protected Methods

Friends

Related Functions

(Note that these are not member functions.)

Detailed Documentation

Constructor & Destructor Documentation

stdx::Enum::Enum const char *    name [protected]
 

Friends And Related Function Documentation

std::ostream& operator<< std::ostream &   ,
const Enum &   
[friend]
 

bool operator== const Enum &    e1,
const Enum &    e2
[friend]
 

bool operator!= const Enum &    e1,
const Enum &    e2
[friend]
 

STDX_INIT_ENUM type_,
name_    [related]
 

Initialize a stdx enum



The documentation for this class was generated from the following file:
Generated on Mon Aug 15 21:43:09 2005 by Doxygen 1.2.13-20020210 written by Dimitri van Heesch © 1997-2002