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

CdbCompositeName.hh

Go to the documentation of this file.
00001 #ifndef CDB_COMPOSITE_NAME_HH
00002 #define CDB_COMPOSITE_NAME_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbCompositeName.hh,v 1.4 2005/08/16 22:23:53 gapon Exp $
00006 
00007 #include "CdbBase/CdbCommon.hh"
00008 
00009 #include <iostream>
00010 #include <string>
00011 
00012 /// This class represents a composite name
00013 /**
00014   * A composite name is a name made of two simple names - the <first> one
00015   * and the <last> one separated by a <separator> substring. The <separator>
00016   * substring is delivered through the corresponding static method of
00017   * the class. The <first> and <last> names of the composite name
00018   * are guarantied not to contain the value of <separator>. The class
00019   * provides constructors to build a composite name either from its components
00020   * or by translating a text string, which already has both names combined
00021   * with the <separator>.
00022   *
00023   * The main reason to introduce this class into the current project was
00024   * to support the naming mechanizm for several API entities, which requires
00025   * the scope name and the entity name itself at that scope. In terms
00026   * of the composite name class, the scope name can be represented by the <first>
00027   * name, and the entity name - by the <last> one (or vice versa).
00028   */
00029 class CdbCompositeName {
00030 
00031     friend std::ostream& operator<<( std::ostream&           o,
00032                                      const CdbCompositeName& theName );
00033 
00034 public:
00035 
00036   /// The separator of elements
00037   /**
00038     */
00039     static const char* separator( );
00040 
00041 public:
00042 
00043   /// The normal & default constructor
00044   /**
00045     * Loads the object from specified string. This constructor expects
00046     * a string pointer to be passed as value of the parameter. If this
00047     * is a null pointer or if it points onto a nono-translatable string
00048     * then the new object will remain in the invalid state.
00049     *
00050     * @see CdbCompositeName::isValid()
00051     */
00052     explicit CdbCompositeName( const char* theStr = 0 );
00053 
00054   /// The normal constructor
00055   /**
00056     * Requirements to the strings:
00057     *
00058     * - must be non-null pointers
00059     * - must not contain the separator
00060     *
00061     * @see CdbCompositeName::isValid()
00062     */
00063     CdbCompositeName( const char* theFirst,
00064                       const char* theLast );
00065 
00066   /// The copy constructor
00067   /**
00068     * More details...
00069     */
00070     CdbCompositeName( const CdbCompositeName& theName );
00071 
00072   /// The destructor
00073   /**
00074     * More details...
00075     */
00076     virtual ~CdbCompositeName( );
00077 
00078   /// The assignment operator
00079   /**
00080     * More details...
00081     */
00082     CdbCompositeName& operator=( const CdbCompositeName& theName );
00083 
00084   /// Check if the object has the valid state
00085   /**
00086     * Any other operations with the object can only make sense
00087     * if this method will return true.
00088     */
00089     bool isValid( ) const;
00090 
00091   /// Get the first element in the name
00092 
00093     std::string first( ) const;
00094 
00095   /// Get the last element in the name
00096 
00097     std::string last( ) const;
00098 
00099   /// Get the whole name
00100 
00101     std::string getName( ) const;
00102 
00103   /// The "equal" operator
00104   /**
00105     */
00106     bool operator==( const CdbCompositeName& theName ) const;
00107 
00108   /// The "not-equal" operator
00109   /**
00110     */
00111     inline bool operator!=( const CdbCompositeName& theName ) const;
00112 
00113 private:
00114 
00115   /// Translate specified string into tokens
00116   /**
00117     * This method will tokenize (if successfull) an input string
00118     * and return the boolean value to indicate if the operation
00119     * was successfull or not.
00120     */
00121     bool translate( const char* theStr );
00122 
00123   /// Load the object's context from specified strings
00124   /**
00125     * The strings are checked for not being empty and non containing
00126     * separators.
00127     */
00128     bool load( const char* theFirst,
00129                const char* theLast );
00130 
00131   /// Dump object contence into a steram
00132 
00133     void dump( std::ostream& o ) const;
00134 
00135 private:
00136 
00137     bool _isValid;
00138 
00139     std::string _first;
00140     std::string _last;
00141 };
00142 
00143 // Inline implementation for teh class's methods and operators
00144 
00145 inline
00146 bool
00147 CdbCompositeName::operator!=( const CdbCompositeName& theName ) const
00148 {
00149     return ! operator==( theName );
00150 }
00151 
00152 inline
00153 std::ostream&
00154 operator<<( std::ostream&                o,
00155             const CdbCompositeName& theName )
00156 {
00157     theName.dump( o );
00158     return o;
00159 }
00160 #endif  // CDB_COMPOSITE_NAME_HH

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