#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 21 of file Param.h.
|
|
Definition at line 80 of file Param.cxx.
00080 : 00081 fName ( "<null>" ), 00082 fComment ( "" ), 00083 fData ( 0 ), 00084 fDataType ( 0 ), 00085 fDataDelete ( 0 ), 00086 fDataCopyCons ( 0 ), 00087 fDataCopy ( 0 ), 00088 fDataPrint ( 0 ) 00089 { } |
|
|
Definition at line 93 of file Param.cxx. References fData, and fDataCopyCons.
00093 : 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 } |
|
||||||||||||
|
Definition at line 108 of file Param.cxx.
00108 : 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 { } |
|
||||||||||||||||||||
|
Construct a parameter from a name, comment, and data Definition at line 160 of file Param.h. References Set().
00160 : 00161 fName ( name ), 00162 fComment ( comment ), 00163 fData ( 0 ), 00164 fDataType ( 0 ), 00165 fDataDelete ( 0 ), 00166 fDataCopyCons( 0 ), 00167 fDataCopy ( 0 ), 00168 fDataPrint ( 0 ) 00169 { 00170 this->Set(d); 00171 } |
|
|
Definition at line 121 of file Param.cxx. References fData, and fDataDelete.
00122 {
00123 if (fData) {
00124 fDataDelete(fData);
00125 fData = 0;
00126 }
00127 }
|
|
||||||||||
|
Retrieve the data held by the parameter into t Definition at line 179 of file Param.h. References fData, fDataType, and GetName(). Referenced by testGet().
00180 {
00181 // Check that types match
00182 const std::type_info& ti = typeid(T);
00183 if (ti != this->fDataType()) {
00184 std::ostringstream os;
00185 os << "Attempt to get data of type " << ti.name()
00186 << " from parameter " << this->GetName() << " which is of type "
00187 << this->fDataType().name();
00188 throw cfg::Exception(Exception::kTypeMismatch,
00189 os.str().c_str(),
00190 __FILE__,
00191 __LINE__);
00192 }
00193 // Normal case: types match so just make a copy to t
00194 t = (*(T*)fData);
00195 }
|
|
|
Definition at line 135 of file Param.cxx. References fComment. Referenced by evdb::ParamFrame::ParamFrame().
00135 { return fComment.c_str(); }
|
|
|
Definition at line 131 of file Param.cxx. References fName. Referenced by cfg::Config::AdoptParam(), Get(), and evdb::ParamFrame::ParamFrame().
00131 { return fName.c_str(); }
|
|
|
Definition at line 143 of file Param.cxx. References fComment, fData, fDataCopy, fDataCopyCons, fDataDelete, fDataPrint, fDataType, and fName.
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 }
|
|
|
Definition at line 139 of file Param.cxx. References fData, and fDataPrint. Referenced by cfg::operator<<().
00139 { fDataPrint(os, fData); }
|
|
||||||||||
|
Set the value of the data held by the parameter to t Definition at line 203 of file Param.h. References fData, fDataCopy, fDataCopyCons, fDataDelete, fDataPrint, and fDataType. Referenced by Param(), and testSet().
00204 {
00205 // Delete the data currently held
00206 if (fData) {
00207 this->fDataDelete(fData);
00208 fData = 0;
00209 }
00210
00211 // Setup the methods for handling this datum
00212 fDataType = gsDataType<T>;
00213 fDataDelete = gsDataDelete<T>;
00214 fDataCopyCons = gsDataCopyCons<T>;
00215 fDataCopy = gsDataCopy<T>;
00216 fDataPrint = gsDataPrint<T>;
00217
00218 // Create the data from the data passed in
00219 fDataCopyCons(&fData, &t);
00220 }
|
|
|
Definition at line 25 of file Param.cxx. References fDataType. Referenced by evdb::ParamFrame::ParamFrame().
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 }
|
|
||||||||||||
|
Definition at line 16 of file Param.cxx.
00017 {
00018 p.Print(os);
00019 return os;
00020 }
|
|
|
Explanation of what parameter is used for.
Definition at line 48 of file Param.h. Referenced by GetComment(), and operator=(). |
|
|
Data values held by parameter.
Definition at line 49 of file Param.h. Referenced by Get(), 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 47 of file Param.h. Referenced by GetName(), and operator=(). |
1.3.5