#include <Param.h>
Public Member Functions | |
Param () | |
Param (const Param &p) | |
Param (const char *name, const char *comment) | |
template<class T> | |
Param (const char *name, const T &d, const char *comment) | |
~Param () | |
const char * | GetName () const |
const char * | GetComment () const |
const char * | XMLTag () const |
void | Print (std::ostream &os) const |
template<class T> | |
void | Get (T &t) const |
template<class T> | |
void | Set (const T &t) |
Param & | operator= (const Param &rhs) |
Private Attributes | |
std::string | fName |
Name of parameter. | |
std::string | fComment |
Explanation of what parameter is used for. | |
void * | fData |
Data values held by parameter. | |
const std::type_info &(* | fDataType )(void) |
void(* | fDataDelete )(void *) |
void(* | fDataCopyCons )(void **dest, const void *src) |
void(* | fDataCopy )(void *dest, const void *src) |
void(* | fDataPrint )(std::ostream &os, const void *d) |
Friends | |
std::ostream & | operator<< (std::ostream &os, const Param &p) |
A parameter consists of a name, and explanation ("comment") and a collection of data values all of which must be of a single type
Definition at line 22 of file Param.h.
|
Definition at line 95 of file Param.cxx. 00095 : 00096 fName ( "<null>" ), 00097 fComment ( "" ), 00098 fData ( 0 ), 00099 fDataType ( 0 ), 00100 fDataDelete ( 0 ), 00101 fDataCopyCons ( 0 ), 00102 fDataCopy ( 0 ), 00103 fDataPrint ( 0 ) 00104 { }
|
|
Definition at line 108 of file Param.cxx. References fData, and fDataCopyCons. 00108 : 00109 fName ( p.fName ), 00110 fComment ( p.fComment ), 00111 fData ( 0 ), 00112 fDataType ( p.fDataType ), 00113 fDataDelete ( p.fDataDelete ), 00114 fDataCopyCons ( p.fDataCopyCons ), 00115 fDataCopy ( p.fDataCopy ), 00116 fDataPrint ( p.fDataPrint ) 00117 { 00118 fDataCopyCons(&fData, p.fData); 00119 }
|
|
Definition at line 123 of file Param.cxx. 00123 : 00124 fName ( name ), 00125 fComment ( comment ), 00126 fData ( 0 ), 00127 fDataType ( 0 ), 00128 fDataDelete ( 0 ), 00129 fDataCopyCons ( 0 ), 00130 fDataCopy ( 0 ), 00131 fDataPrint ( 0 ) 00132 { }
|
|
Construct a parameter from a name, comment, and data Definition at line 161 of file Param.h. References Set(). 00161 : 00162 fName ( name ), 00163 fComment ( comment ), 00164 fData ( 0 ), 00165 fDataType ( 0 ), 00166 fDataDelete ( 0 ), 00167 fDataCopyCons( 0 ), 00168 fDataCopy ( 0 ), 00169 fDataPrint ( 0 ) 00170 { 00171 this->Set(d); 00172 }
|
|
Definition at line 136 of file Param.cxx. References fData, and fDataDelete. 00137 { 00138 if (fData) { 00139 fDataDelete(fData); 00140 fData = 0; 00141 } 00142 }
|
|
Retrieve the data held by the parameter into t Definition at line 180 of file Param.h. References fDataType, and GetName(). Referenced by cfg::operator<<(), and testGet(). 00181 { 00182 // Check that types match 00183 const std::type_info& ti = typeid(T); 00184 if (ti != this->fDataType()) { 00185 std::ostringstream os; 00186 os << "Attempt to get data of type " << ti.name() 00187 << " from parameter " << this->GetName() << " which is of type " 00188 << this->fDataType().name(); 00189 throw cfg::Exception(Exception::kTypeMismatch, 00190 os.str().c_str(), 00191 __FILE__, 00192 __LINE__); 00193 } 00194 // Normal case: types match so just make a copy to t 00195 t = (*(T*)fData); 00196 }
|
|
Definition at line 150 of file Param.cxx. References fComment. Referenced by cfg::Config::AsXML(), and evdb::ParamFrame::ParamFrame(). 00150 { return fComment.c_str(); }
|
|
Definition at line 146 of file Param.cxx. References fName. Referenced by cfg::Config::AdoptParam(), cfg::Config::AsXML(), Get(), and evdb::ParamFrame::ParamFrame(). 00146 { return fName.c_str(); }
|
|
Definition at line 158 of file Param.cxx. References fComment, fData, fDataCopy, fDataCopyCons, fDataDelete, fDataPrint, fDataType, and fName. 00159 { 00160 //====================================================================== 00161 // Copy operation 00162 //====================================================================== 00163 // Avoid self-copy 00164 if (&rhs == this) return *this; 00165 00166 // Copy the name and comments over 00167 fName = rhs.fName; 00168 fComment = rhs.fComment; 00169 00170 // Copy the data handlers 00171 fDataType = rhs.fDataType; 00172 fDataDelete = rhs.fDataDelete; 00173 fDataCopyCons = rhs.fDataCopyCons; 00174 fDataCopy = rhs.fDataCopy; 00175 fDataPrint = rhs.fDataPrint; 00176 00177 // Delete the data from the left-hand side and reallocate it using the 00178 // copy constructor 00179 if (fData) { fDataDelete(fData); fData = 0; } 00180 fDataCopyCons(&fData, rhs.fData); 00181 00182 return *this; 00183 }
|
|
Definition at line 154 of file Param.cxx. References fData, and fDataPrint. Referenced by cfg::operator<<(). 00154 { fDataPrint(os, fData); }
|
|
Set the value of the data held by the parameter to t Definition at line 204 of file Param.h. References fData, fDataCopy, fDataCopyCons, fDataDelete, fDataPrint, and fDataType. Referenced by Param(), and testSet(). 00205 { 00206 // Delete the data currently held 00207 if (fData) { 00208 this->fDataDelete(fData); 00209 fData = 0; 00210 } 00211 00212 // Setup the methods for handling this datum 00213 fDataType = gsDataType<T>; 00214 fDataDelete = gsDataDelete<T>; 00215 fDataCopyCons = gsDataCopyCons<T>; 00216 fDataCopy = gsDataCopy<T>; 00217 fDataPrint = gsDataPrint<T>; 00218 00219 // Create the data from the data passed in 00220 fDataCopyCons(&fData, &t); 00221 }
|
|
Definition at line 36 of file Param.cxx. References fDataType. Referenced by cfg::Config::AsXML(), cfg::operator<<(), and evdb::ParamFrame::ParamFrame(). 00037 { 00038 // 00039 // Return a recommended xml tag for this data type 00040 // 00041 static const std::type_info& bool_id = typeid(bool); 00042 static const std::type_info& char_id = typeid(char); 00043 static const std::type_info& short_id = typeid(short); 00044 static const std::type_info& int_id =typeid(int); 00045 static const std::type_info& uchar_id =typeid(unsigned char); 00046 static const std::type_info& ushort_id =typeid(unsigned short); 00047 static const std::type_info& uint_id =typeid(unsigned int); 00048 static const std::type_info& float_id =typeid(float); 00049 static const std::type_info& double_id =typeid(double); 00050 static const std::type_info& string_id =typeid(std::string); 00051 static const std::type_info& time_id =typeid(time_t); 00052 static const std::type_info& boolv_id =typeid(std::vector<bool>); 00053 static const std::type_info& charv_id =typeid(std::vector<char>); 00054 static const std::type_info& shortv_id =typeid(std::vector<short>); 00055 static const std::type_info& intv_id =typeid(std::vector<int>); 00056 static const std::type_info& ucharv_id =typeid(std::vector<unsigned char>); 00057 static const std::type_info& ushortv_id =typeid(std::vector<unsigned short>); 00058 static const std::type_info& uintv_id =typeid(std::vector<unsigned int>); 00059 static const std::type_info& floatv_id =typeid(std::vector<float>); 00060 static const std::type_info& doublev_id =typeid(std::vector<double>); 00061 static const std::type_info& stringv_id =typeid(std::vector<std::string>); 00062 static const std::type_info& timev_id =typeid(std::vector<time_t>); 00063 00064 if (bool_id == this->fDataType()) return "bool"; 00065 if (char_id == this->fDataType()) return "char"; 00066 if (short_id == this->fDataType()) return "short"; 00067 if (int_id == this->fDataType()) return "int"; 00068 if (uint_id == this->fDataType()) return "uint"; 00069 if (uchar_id == this->fDataType()) return "uchar"; 00070 if (ushort_id == this->fDataType()) return "ushort"; 00071 if (uint_id == this->fDataType()) return "uint"; 00072 if (float_id == this->fDataType()) return "float"; 00073 if (double_id == this->fDataType()) return "double"; 00074 if (string_id == this->fDataType()) return "string"; 00075 if (time_id == this->fDataType()) return "time_t"; 00076 00077 if (boolv_id == this->fDataType()) return "bool"; 00078 if (charv_id == this->fDataType()) return "char"; 00079 if (shortv_id == this->fDataType()) return "short"; 00080 if (intv_id == this->fDataType()) return "int"; 00081 if (uintv_id == this->fDataType()) return "uint"; 00082 if (ucharv_id == this->fDataType()) return "uchar"; 00083 if (ushortv_id == this->fDataType()) return "ushort"; 00084 if (uintv_id == this->fDataType()) return "uint"; 00085 if (floatv_id == this->fDataType()) return "float"; 00086 if (doublev_id == this->fDataType()) return "double"; 00087 if (stringv_id == this->fDataType()) return "string"; 00088 if (timev_id == this->fDataType()) return "time_t"; 00089 00090 return "?"; 00091 }
|
|
Definition at line 16 of file Param.cxx. 00017 { 00018 if (std::string(p.XMLTag())=="time_t") { 00019 time_t t; 00020 p.Get(t); 00021 struct tm* ts = gmtime(&t); 00022 os << ts->tm_year+1900 << "-" << ts->tm_mon+1 << "-" 00023 << ts->tm_mday << " " << ts->tm_hour << ":" << ts->tm_min << ":" 00024 << ts->tm_sec; 00025 return os; 00026 } 00027 else { 00028 p.Print(os); 00029 return os; 00030 } 00031 }
|
|
Explanation of what parameter is used for.
Definition at line 49 of file Param.h. Referenced by GetComment(), and operator=(). |
|
Data values held by parameter.
Definition at line 50 of file Param.h. Referenced by operator=(), Param(), Print(), Set(), and ~Param(). |
|
Referenced by operator=(), and Set(). |
|
Referenced by operator=(), Param(), and Set(). |
|
Referenced by operator=(), Set(), and ~Param(). |
|
Referenced by operator=(), Print(), and Set(). |
|
Referenced by Get(), operator=(), Set(), and XMLTag(). |
|
Name of parameter.
Definition at line 48 of file Param.h. Referenced by GetName(), and operator=(). |