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

CdbId.hh

Go to the documentation of this file.
00001 #ifndef CDB_ID_HH
00002 #define CDB_ID_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbId.hh,v 1.6 2004/08/06 05:54:14 bartoldu Exp $
00006 
00007 #include "CdbBase/CdbCommon.hh"
00008 
00009 #include <iostream>
00010 
00011 class CdbCompositeName;
00012 
00013 /// Object of this class represent "extended" identifier for Condition/DB objects
00014 /**
00015   * The "extended" object identifier defines an address of some entiry in the distributed
00016   * database as:
00017   *
00018   *     16-bit "origin" identifier
00019   *     16-bit "local" object's id in the scope of an origin
00020   */
00021 class CdbId {
00022 
00023 public:
00024 
00025   /// Normal & also default constructor
00026   /**
00027     */
00028     CdbId( unsigned short theOriginId = 0,
00029            unsigned short theLocalId  = 0 ) :
00030         origin(theOriginId),
00031         local(theLocalId)
00032     { }
00033 
00034   /// Copy constructor
00035   /**
00036     */
00037     CdbId( const CdbId& theId )
00038     {
00039         origin = theId.origin;
00040         local  = theId.local;
00041     }
00042 
00043   /// The destructor
00044   /**
00045     * NOTE: The destructor is NOT virtual because this is an embedded
00046     *       class.
00047     */
00048     ~CdbId( ) { }
00049 
00050   /// The assignment operator
00051   /**
00052     */
00053     CdbId& operator=( const CdbId& theId )
00054     {
00055         if( this != &theId ) {
00056             origin = theId.origin;
00057             local  = theId.local;
00058         }
00059         return *this;
00060     }
00061 
00062   /// The "equal" operator
00063   /**
00064     * This operator is required to insert objects of this class
00065     * into a B-tree.
00066     */
00067     bool operator==( const CdbId& theId ) const
00068     {
00069         return ( origin == theId.origin ) && ( local == theId.local );
00070     }
00071 
00072   /// The "not-equal" operator
00073   /**
00074     */
00075     bool operator!=( const CdbId& theId ) const
00076     {
00077         return ! operator==( theId );
00078     }
00079 
00080   /// The "less" operator
00081   /**
00082     * This operator is required to insert objects of this class
00083     * into a B-tree.
00084     */
00085     bool operator<( const CdbId& theId ) const
00086     {
00087         return ( origin < theId.origin ) || (( origin == theId.origin ) && ( local < theId.local ));
00088     }
00089 
00090 public:
00091 
00092   /// Translate a string into an identifier
00093   /**
00094     * This utility method would attempt to translate the specified string into
00095     * an object of the current class. A non zero pointer onto a string is expected.
00096     * If the translation will be successfull then the resulting flagg would be set
00097     * to "true" and the reference would be properly initialized. Otherwise
00098     * the reference would not be affected.
00099     *
00100     * @return a boolen flag indicating the result of the translation.
00101     */
00102     static bool translate( CdbId&      theId,       /**< the reference to be initialized */
00103                            const char* theString    /**< the input string */
00104                          );
00105 
00106   /// Translate a 'composite name' into an identifier
00107   /**
00108     * Similarily to the above defined translation method this one would also
00109     * translate the specified composite name into an identifier. The composite
00110     * name must be 'valid'.
00111     *
00112     * @see class CdbCompositeName
00113     *
00114     * @return a boolen flag indicating the result of the translation.
00115     */
00116     static bool translate( CdbId&                  theId,           /**< the reference to be initialized */
00117                            const CdbCompositeName& theCompositeName /**< the input 'composite' name */
00118                          );
00119 
00120 public:
00121 
00122     unsigned short origin;  // The identifier of an "origin"
00123     unsigned short local;   // The local identifier of an object in the scope of an origin
00124 };
00125 
00126 inline
00127 std::ostream&
00128 operator<<( std::ostream&     o,
00129             const CdbId& theId )
00130 {
00131     o << theId.origin << "::" << theId.local;
00132     return o;
00133 }
00134 
00135 #endif  // CDB_ID_HH

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