Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

Param.cxx

Go to the documentation of this file.
00001 
00002 // $Id: Param.cxx,v 1.1 2007/02/09 05:38:27 fmwk Exp $
00003 //
00005 //
00008 //
00009 // messier@indiana.edu
00011 #include "Config/Param.h"
00012 
00013 //......................................................................
00014 
00015 namespace cfg {
00016   std::ostream& operator<<(std::ostream& os, const Param& p) 
00017   {
00018     p.Print(os); 
00019     return os;
00020   }
00021 }
00022 
00023 //......................................................................
00024 
00025 const char* cfg::Param::XMLTag() const 
00026 {
00027 //
00028 // Return a recommended xml tag for this data type
00029 //
00030   static const std::type_info& bool_id   = typeid(bool);
00031   static const std::type_info& char_id   = typeid(char);
00032   static const std::type_info& short_id  = typeid(short);
00033   static const std::type_info& int_id     =typeid(int);
00034   static const std::type_info& uchar_id   =typeid(unsigned char);
00035   static const std::type_info& ushort_id  =typeid(unsigned short);
00036   static const std::type_info& uint_id    =typeid(unsigned int);
00037   static const std::type_info& float_id   =typeid(float);
00038   static const std::type_info& double_id  =typeid(double);
00039   static const std::type_info& string_id  =typeid(std::string);
00040   static const std::type_info& boolv_id   =typeid(std::vector<bool>);
00041   static const std::type_info& charv_id   =typeid(std::vector<char>);
00042   static const std::type_info& shortv_id  =typeid(std::vector<short>);
00043   static const std::type_info& intv_id    =typeid(std::vector<int>);
00044   static const std::type_info& ucharv_id  =typeid(std::vector<unsigned char>);
00045   static const std::type_info& ushortv_id =typeid(std::vector<unsigned short>);
00046   static const std::type_info& uintv_id   =typeid(std::vector<unsigned int>);
00047   static const std::type_info& floatv_id  =typeid(std::vector<float>);
00048   static const std::type_info& doublev_id =typeid(std::vector<double>);
00049   static const std::type_info& stringv_id =typeid(std::vector<std::string>);
00050 
00051   if (bool_id   == this->fDataType()) return "bool";
00052   if (char_id   == this->fDataType()) return "char";
00053   if (short_id  == this->fDataType()) return "short";
00054   if (int_id    == this->fDataType()) return "int";
00055   if (uint_id   == this->fDataType()) return "uint";
00056   if (uchar_id  == this->fDataType()) return "uchar";
00057   if (ushort_id == this->fDataType()) return "ushort";
00058   if (uint_id   == this->fDataType()) return "uint";
00059   if (float_id  == this->fDataType()) return "float";
00060   if (double_id == this->fDataType()) return "double";
00061   if (string_id == this->fDataType()) return "string";
00062 
00063   if (boolv_id   == this->fDataType()) return "bool";
00064   if (charv_id   == this->fDataType()) return "char";
00065   if (shortv_id  == this->fDataType()) return "short";
00066   if (intv_id    == this->fDataType()) return "int";
00067   if (uintv_id   == this->fDataType()) return "uint";
00068   if (ucharv_id  == this->fDataType()) return "uchar";
00069   if (ushortv_id == this->fDataType()) return "ushort";
00070   if (uintv_id   == this->fDataType()) return "uint";
00071   if (floatv_id  == this->fDataType()) return "float";
00072   if (doublev_id == this->fDataType()) return "double";
00073   if (stringv_id == this->fDataType()) return "string";
00074   
00075   return "?";
00076 }
00077 
00078 //......................................................................
00079 
00080 cfg::Param::Param() :
00081   fName         ( "<null>" ),
00082   fComment      ( "" ),
00083   fData         ( 0 ),
00084   fDataType     ( 0 ),
00085   fDataDelete   ( 0 ),
00086   fDataCopyCons ( 0 ),
00087   fDataCopy     ( 0 ),
00088   fDataPrint    ( 0 )
00089 { }
00090 
00091 //......................................................................
00092 
00093 cfg::Param::Param(const cfg::Param& p) :
00094   fName         ( p.fName    ),
00095   fComment      ( p.fComment ),
00096   fData         ( 0 ),
00097   fDataType     ( p.fDataType     ),
00098   fDataDelete   ( p.fDataDelete   ),
00099   fDataCopyCons ( p.fDataCopyCons ),
00100   fDataCopy     ( p.fDataCopy     ),
00101   fDataPrint    ( p.fDataPrint    )
00102 {
00103   fDataCopyCons(&fData, p.fData);
00104 }
00105 
00106 //......................................................................
00107 
00108 cfg::Param::Param(const char* name, const char* comment) :
00109   fName         ( name ),
00110   fComment      ( comment ),
00111   fData         ( 0 ),
00112   fDataType     ( 0 ),
00113   fDataDelete   ( 0 ),
00114   fDataCopyCons ( 0 ),
00115   fDataCopy     ( 0 ),
00116   fDataPrint    ( 0 )
00117 { }
00118 
00119 //......................................................................
00120 
00121 cfg::Param::~Param() 
00122 { 
00123   if (fData) {
00124     fDataDelete(fData); 
00125     fData = 0;
00126   }
00127 }
00128 
00129 //......................................................................
00130 
00131 const char* cfg::Param::GetName() const { return fName.c_str(); }
00132 
00133 //......................................................................
00134 
00135 const char* cfg::Param::GetComment() const { return fComment.c_str(); }
00136 
00137 //......................................................................
00138 
00139 void cfg::Param::Print(std::ostream& os) const { fDataPrint(os, fData); }
00140 
00141 //......................................................................
00142 
00143 cfg::Param& cfg::Param::operator=(const cfg::Param& rhs) 
00144 {
00145 //======================================================================
00146 // Copy operation
00147 //======================================================================
00148   // Avoid self-copy
00149   if (&rhs == this) return *this;
00150   
00151   // Copy the name and comments over
00152   fName    = rhs.fName;
00153   fComment = rhs.fComment;
00154   
00155   // Copy the data handlers
00156   fDataType     = rhs.fDataType;
00157   fDataDelete   = rhs.fDataDelete;
00158   fDataCopyCons = rhs.fDataCopyCons;
00159   fDataCopy     = rhs.fDataCopy;
00160   fDataPrint    = rhs.fDataPrint;
00161   
00162   // Delete the data from the left-hand side and reallocate it using the
00163   // copy constructor
00164   if (fData) { fDataDelete(fData); fData = 0; }
00165   fDataCopyCons(&fData, rhs.fData);
00166 
00167   return *this;
00168 }
00169 

Generated on Thu Sep 4 02:05:28 2008 for NOvA Offline by doxygen 1.3.5