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

CdbNTuplePrintDefaultConverter.hh

Go to the documentation of this file.
00001 #ifndef CDB_NTUPLE_PRINT_DEFAULT_CONVERTER_HH
00002 #define CDB_NTUPLE_PRINT_DEFAULT_CONVERTER_HH
00003 
00004 // File and Version Information:
00005 //      $Id: CdbNTuplePrintDefaultConverter.hh,v 1.3 2004/08/06 05:54:41 bartoldu Exp $
00006 
00007 #include "CdbBase/CdbCommon.hh"
00008 
00009 #include "BbrStdUtils/BbrIOStreamUtils.hh"
00010 
00011 #include <iostream>
00012 #include <iomanip>
00013 
00014 #include <string>
00015 
00016 /// The default convertor suitable for most primitive data types of C++
00017 /**
00018   * This converter policy assumes that a type of elements has the corresponding
00019   * streaming operator ">>" defined.
00020   */
00021 template < class T >
00022 struct CdbNTuplePrintDefaultConverter {
00023     static void convertAndPrint( std::ostream&     theOutputStream,
00024                                  unsigned int theWidth,
00025                                  const T&     theValue )
00026     {
00027         theOutputStream << std::setw( theWidth ) << theValue;
00028     }
00029 };
00030 
00031 /// The specialized convertor for strings
00032 /**
00033   * We use this convertor here as the Standard Library's C++ string class
00034   * does not have a streaming operator defined.
00035   *
00036   * NOTE: Strings longer than the specified length would be truncated
00037   *       at the output and the last symbols would be ".." to indicate
00038   *       the continuation.
00039   */
00040 template < >
00041 struct CdbNTuplePrintDefaultConverter< std::string > {
00042     static void convertAndPrint( std::ostream&           theOutputStream,
00043                                  unsigned int       theWidth,
00044                                  const std::string& theValue )
00045     {
00046         babar::IOStream::all_format_guard guard( theOutputStream );
00047         theOutputStream.setf( std::ios::left, std::ios::adjustfield );
00048 
00049         if( theValue.length( ) <= theWidth ) {
00050             theOutputStream << std::setw( theWidth ) << theValue.c_str( );
00051         } else {
00052             theOutputStream << std::setw( theWidth - 2 ) << theValue.substr( 0, theWidth - 2 ).c_str( ) << "..";
00053         }
00054     }
00055 };
00056 
00057 #endif // CDB_NTUPLE_PRINT_DEFAULT_CONVERTER_HH
00058 

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