Main Page   Namespace List   Class Hierarchy   Compound List   File List   Namespace Members   Compound Members   File Members  

CdbType2Id.hh

Go to the documentation of this file.
00001 #ifndef CDB_TYPE_2_ID_HH
00002 #define CDB_TYPE_2_ID_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbType2Id.hh,v 1.1 2005/03/01 21:15:29 gapon Exp $
00006 
00007 #include "CdbBase/CdbCommon.hh"
00008 
00009 /// The default generator of unique type identifiers (a utility class)
00010 /**
00011   * The generator will produce unsigned integer numbers starting with 0 every
00012   * time the CdbDefaultTypeIdGenerator::next() method is invoked.
00013   *
00014   * The class is used in the unique mapping scheme between C++ types and numbers.
00015   *
00016   * IMPORTANT DESIGN NOTE:
00017   *
00018   *   That the mapping can't be persistent or it can't be used in any way beyong
00019   *   the lifespan of a process.
00020   *
00021   * @see class CdbType2Id
00022   */
00023 class CdbDefaultTypeIdGenerator {
00024 
00025 public:
00026 
00027   /// Produce the next unique number
00028   /**
00029     * The first time the method gets called it will produce 0.
00030     */
00031     static unsigned int next( )
00032     {
00033         static unsigned int current = 0;
00034         return current++;
00035     }
00036 };
00037 
00038 /// Translate the type into its identifier
00039 /**
00040   * This class will use the specified (or the default) generator of identifiers.
00041   * A reson why we may want to parameterize the current class with different
00042   * generators is that we may want to have a better control over actual number
00043   * of identifiers associated with transient types. For example, we may consider
00044   * using predefined type numbers rather than automatically generated ones. Or,
00045   * we may want to have two independent collections of transient types whose
00046   * identifiers both start with 0.
00047   */
00048 template< class T,
00049           class GENERATOR = CdbDefaultTypeIdGenerator >
00050 class CdbType2Id {
00051 
00052 public:
00053 
00054   /// The type to be mapped to its id
00055 
00056     typedef T type;
00057 
00058 public:
00059 
00060   /// Get the identifier corresponding to the type
00061 
00062     static unsigned int id( )
00063     {
00064         static unsigned int value = GENERATOR::next( );
00065         return value;
00066     }
00067 };
00068 
00069 #endif  // CDB_TYPE_2_ID_HH

Generated on Mon Dec 5 18:22:12 2005 for CDB by doxygen1.3-rc3