OSB_LIB::TypeId< T, ST > Class Template Reference

Inheritance diagram for OSB_LIB::TypeId< T, ST >:

Inheritance graph
[legend]
Collaboration diagram for OSB_LIB::TypeId< T, ST >:

Collaboration graph
[legend]
List of all members.

Detailed Description

template<typename T, int ST = 1>
class OSB_LIB::TypeId< T, ST >

Type-safe type identifiers.

Parameters:
T Class that defines the type identifier.
ST Optional identification of the subtype if T needs more than one type.
This template allows type-safe type identifiers without need to include the header file of the respective class. It acts as glue between the client of a class and a type enumeration defined inside or outside the class.

      // *****************************************************
      // client header file
      #include <osbtype.h>              // get this header
      class Demo;                       // forward declaration

      // check the Demo type identfier
      bool checkType(TypeId<Demo> t);

      // *****************************************************
      // class header file
      class Demo {
      public:
          enum { t1 = 1, t2, t3 };
          typedef TypeId<Demo> Type;
      };

      // *****************************************************
      // client implementation
      #include <demo.h>                 // class Demo

      bool checkType(Demo::Type t)
      {
          return t.valid();
      }

      // *****************************************************
      // class implementation file
      template<> const long Demo::Type::minType_ = Demo::t1;
      template<> const long Demo::Type::maxType_ = Demo::t3;

Note:
In the above example above it whould not even be necessary to include the header file of the class Demo.
The header of the latter may provide suitable conversion functions between TypeId<T> and the enumeration constants:
      class Demo {
      public:
          typedef TypeId<Demo> Type;
          enum DemoType { t1 = 1, t2, t3 };
      public:
          Type type() const
          {
              return type_;
          }

          DemoType demoType() const
          {
              return type().toLong();
          }
      private:
          Type type_;
      };

Definition at line 120 of file osbtype.h.

Public Member Functions

Static Public Member Functions

Private Attributes

Static Private Attributes


Constructor & Destructor Documentation

template<typename T, int ST = 1>
OSB_LIB::TypeId< T, ST >::TypeId ( long  type = notSet_  )  [inline, explicit]

Default constructor with optional type.

Parameters:
type Identifier of the type. If it is not between minType_ and maxType_ (included) its value is set to unknown_.

Definition at line 129 of file osbtype.h.

Referenced by OSB_LIB::TypeId< OSB_LIB::Device >::mkUnknown().


Member Function Documentation

template<typename T, int ST = 1>
static long OSB_LIB::TypeId< T, ST >::maxType (  )  [inline, static]

Get the maximum type id.

Definition at line 140 of file osbtype.h.

template<typename T, int ST = 1>
static long OSB_LIB::TypeId< T, ST >::minType (  )  [inline, static]

Get the minimum type id.

Definition at line 138 of file osbtype.h.

template<typename T, int ST = 1>
static TypeId OSB_LIB::TypeId< T, ST >::mkUnknown (  )  [inline, static]

Create an unkown type id.

Definition at line 142 of file osbtype.h.

template<typename T, int ST = 1>
bool OSB_LIB::TypeId< T, ST >::notSet (  )  const [inline]

Type identifier not set?

Definition at line 155 of file osbtype.h.

Referenced by OSB_DB::OtlType::OtlType(), and OSB_LIB::TypeId< OSB_LIB::Device >::TypeId().

template<typename T, int ST = 1>
bool OSB_LIB::TypeId< T, ST >::operator!= ( const TypeId< T, ST > &  rhs  )  const [inline]

Different type identifier?

Definition at line 170 of file osbtype.h.

template<typename T, int ST = 1>
bool OSB_LIB::TypeId< T, ST >::operator< ( const TypeId< T, ST > &  rhs  )  const [inline]

Weak ordering.

Definition at line 175 of file osbtype.h.

template<typename T, int ST = 1>
bool OSB_LIB::TypeId< T, ST >::operator== ( const TypeId< T, ST > &  rhs  )  const [inline]

Same type identifier?

Definition at line 165 of file osbtype.h.

Referenced by OSB_LIB::TypeId< OSB_LIB::Device >::operator!=().

template<typename T, int ST = 1>
long OSB_LIB::TypeId< T, ST >::toLong (  )  const [inline]

Convert to long.

This is member should be used only:

Definition at line 189 of file osbtype.h.

Referenced by OSB_LIB::operator<<().

template<typename T, int ST = 1>
bool OSB_LIB::TypeId< T, ST >::unKnown (  )  const [inline]

Type identifier not known?

Definition at line 160 of file osbtype.h.

template<typename T, int ST = 1>
bool OSB_LIB::TypeId< T, ST >::valid (  )  const [inline]

Type identifier valid?

Returns:
true if type_ is neither notSet_ nor unknown_, else false.

Definition at line 150 of file osbtype.h.


Member Data Documentation

template<typename T, int ST = 1>
const long OSB_LIB::TypeId< T, ST >::maxType_ [static, private]

Maximum type identifer.

Contrary to notSet_ and unknown_ this member is NOT defined in this header.
The class that defines the type must do this in its implementation file, see class description for an example.

Definition at line 218 of file osbtype.h.

Referenced by OSB_LIB::TypeId< OSB_LIB::Device >::maxType(), and OSB_LIB::TypeId< OSB_LIB::Device >::TypeId().

template<typename T, int ST = 1>
const long OSB_LIB::TypeId< T, ST >::minType_ [static, private]

Minimum type identifer.

Contrary to notSet_ and unknown_ this member is NOT defined in this header.
The class that defines the type must do this in its implementation file, see class description for an example.

Definition at line 209 of file osbtype.h.

Referenced by OSB_LIB::TypeId< OSB_LIB::Device >::minType(), and OSB_LIB::TypeId< OSB_LIB::Device >::TypeId().

template<typename T, int ST = 1>
const long OSB_LIB::TypeId< T, ST >::notSet_ = 0 [static, private]

Value if type is not set.

Definition at line 198 of file osbtype.h.

Referenced by OSB_LIB::TypeId< OSB_LIB::Device >::notSet(), and OSB_LIB::TypeId< OSB_LIB::Device >::valid().

template<typename T, int ST = 1>
long OSB_LIB::TypeId< T, ST >::type_ [private]

The type identifier.

Definition at line 195 of file osbtype.h.

Referenced by OSB_LIB::TypeId< OSB_LIB::Device >::notSet(), OSB_LIB::TypeId< OSB_LIB::Device >::operator<(), OSB_LIB::TypeId< OSB_LIB::Device >::operator==(), OSB_LIB::TypeId< OSB_LIB::Device >::toLong(), OSB_LIB::TypeId< OSB_LIB::Device >::TypeId(), OSB_LIB::TypeId< OSB_LIB::Device >::unKnown(), and OSB_LIB::TypeId< OSB_LIB::Device >::valid().

template<typename T, int ST = 1>
const long OSB_LIB::TypeId< T, ST >::unknown_ = -1 [static, private]

Value if type is unknown.

Definition at line 200 of file osbtype.h.

Referenced by OSB_LIB::TypeId< OSB_LIB::Device >::mkUnknown(), OSB_LIB::TypeId< OSB_LIB::Device >::TypeId(), OSB_LIB::TypeId< OSB_LIB::Device >::unKnown(), and OSB_LIB::TypeId< OSB_LIB::Device >::valid().


The documentation for this class was generated from the following file:
Generated on Sat Sep 2 14:12:19 2006 for OSB Library by  doxygen 1.4.7