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

Derived Integer Type Classes

Because all integer type classes differ only in their bounds a template is used to build up the required type classes automatically:

template<class R> class integer_type : public integer_base {
   ... 
};

R denotes the corresponding integer type info class. Note, only static methods defined in the class are executed within the template class. The template uses this class to query the actual bounds of the integer type. Figure 5.3 shows the structure of a derived integer type class.


  
Figure 5.3: Structure of derived integer type classes.
\begin{figure}\begin{center}
\epsfig{file=cdr/itype.eps}\end{center}\end{figure}

Example:

template<class R> class integer_type : public integer_base {
public:
  // Note, ``R'' is the type info class of the integer type and
  // R::left() is a static method which returns the left bound
  // of the integer type.
  integer_type(const int a=R::left()) : integer_base(a) { ... }
  integer_type &operator=(const integer_type a) {
    value = a.value;
    return *this;
  }
  integer_type(const integer_base a) : integer_base(a) {};

  /** Predefined VHDL integer operators */
  /* Arithmetical operators */
  integer_type operator+(const integer_type a) { ... }
  integer_type operator-(const integer_type a) { ... }
  ...
  /* Compare operators */
  int operator<(const integer_type a) { return value < a.value; }
  int operator<=(const integer_type a) { return value <= a.value; }
  ...
};



 


1998-11-17