next up previous contents
Next: Enumeration Type Template Class Up: Derived Type Classes Previous: Integer Type Template Class

Derived Enumeration Type Classes


  
Figure 5.4: Structure of derived enumeration type classes.
\begin{figure}\begin{center}
\epsfig{file=cdr/etype.eps}\end{center}\end{figure}

Similar to integer type classes a template is used to build up the required type classes automatically (see Figure 5.4).

template<class R> class enum_type : public enum_base {
   ... 
};
R denotes the corresponding enumeration type info class. Note, only static methods defined in the class are executed within the template class.

Example:

template<class R> class enum_type : public enum_base {
public:
  // Note, ``R'' is the type info class of the enumeration type and
  // R::low() is a static method which returns the low bound
  // of the enumeration type. Usually, this bound is 0. However,
  // if the current enumeration type is a subtype of another
  // enumeration type, then the values are taken from these
  // type.
  enum_type(const int a=R::low()) : enum_base(a) { };
  enum_type &operator=(const int a) { value = a; }
  enum_type &operator=(const enum_type a) { ... }
  enum_type &operator=(const enum_base a) { ... }

  /* Compare operators */
  int &operator<(const enum_type a);
  int &operator>(const enum_type a);
  ...
};



 


1998-11-17