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

CdbStringUtils.hh

Go to the documentation of this file.
00001 #ifndef CDB_STRING_UTILS_HH
00002 #define CDB_STRING_UTILS_HH
00003 
00004 #include <CdbBase/CdbCommon.hh>
00005 
00006 #include <string>
00007 #include <sstream>
00008 
00009 /// A utility class with a pack of string manipulation operations
00010 
00011 class CdbStringUtils {
00012 
00013 public:
00014 
00015   /// Translate an object into a string
00016   /**
00017     * This method is using the String I/O facility, therefore a proper implementation
00018     * of the "<<" operator is expected for an input object's class.
00019     *
00020     * RETURN STATUS NOTES:
00021     *
00022     *   There is no return status for this method. Problems are supposed to be handled
00023     *   (in case of missing operator) at a compile time, or resulted as an empty string
00024     *   at the run time.
00025     */
00026     template< class T >
00027     static
00028     std::string toString( const T& theObject )
00029     {
00030         std::ostringstream result;
00031         result << theObject;
00032         return result.str( );
00033     }
00034 
00035   /// Translate a string into an object
00036   /**
00037     * This method is using the String I/O facility, therefore a proper implementation
00038     * of the ">>" operator is expected for an output object's class.
00039     *
00040     * The object's class is expected to maintain the public "value" interface, meaning that
00041     * it should have:
00042     *
00043     *   struct T {
00044     *     T();
00045     *     T(const T&);
00046     *     T& operator=(const T&);
00047     *     ~T();
00048     *   };
00049     *
00050     * RETURN STATUS NOTES:
00051     *
00052     *   There is no return status for this method. Problems are supposed to be handled 
00053     *   (in case of missing operator) at a compile time, or resulted as non-valid object
00054     *   returned at the run time.
00055     */
00056     template< class T >
00057     static
00058     T fromString( const std::string& theString )
00059     {
00060         T result;
00061         std::istringstream str( theString );
00062         str >> result;
00063         return result;
00064     }
00065 };
00066 
00067 #endif  /* CDB_STRING_UTILS_HH */

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