#include <CfgParam.h>
Public Member Functions | |
| CfgParam () | |
| CfgParam (const CfgParam &p) | |
| CfgParam (const char *name, const char *comment) | |
| template<class T> | |
| CfgParam (const char *name, const T &d, const char *comment) | |
| ~CfgParam () | |
| 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) |
| CfgParam & | operator= (const CfgParam &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 CfgParam &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 20 of file CfgParam.h.
| CfgParam::CfgParam | ( | ) |
Definition at line 78 of file CfgParam.cxx.
00078 : 00079 fName ( "<null>" ), 00080 fComment ( "" ), 00081 fData ( 0 ), 00082 fDataType ( 0 ), 00083 fDataDelete ( 0 ), 00084 fDataCopyCons ( 0 ), 00085 fDataCopy ( 0 ), 00086 fDataPrint ( 0 ) 00087 { }
| CfgParam::CfgParam | ( | const CfgParam & | p | ) |
Definition at line 91 of file CfgParam.cxx.
References fData, fDataCopyCons, and p.
00091 : 00092 fName ( p.fName ), 00093 fComment ( p.fComment ), 00094 fData ( 0 ), 00095 fDataType ( p.fDataType ), 00096 fDataDelete ( p.fDataDelete ), 00097 fDataCopyCons ( p.fDataCopyCons ), 00098 fDataCopy ( p.fDataCopy ), 00099 fDataPrint ( p.fDataPrint ) 00100 { 00101 fDataCopyCons(&fData, p.fData); 00102 }
| CfgParam::CfgParam | ( | const char * | name, | |
| const char * | comment | |||
| ) |
Definition at line 106 of file CfgParam.cxx.
00106 : 00107 fName ( name ), 00108 fComment ( comment ), 00109 fData ( 0 ), 00110 fDataType ( 0 ), 00111 fDataDelete ( 0 ), 00112 fDataCopyCons ( 0 ), 00113 fDataCopy ( 0 ), 00114 fDataPrint ( 0 ) 00115 { }
| CfgParam::CfgParam | ( | const char * | name, | |
| const T & | d, | |||
| const char * | comment | |||
| ) |
Definition at line 156 of file CfgParam.h.
References Set().
00156 : 00157 fName ( name ), 00158 fComment ( comment ), 00159 fData ( 0 ), 00160 fDataType ( 0 ), 00161 fDataDelete ( 0 ), 00162 fDataCopyCons( 0 ), 00163 fDataCopy ( 0 ), 00164 fDataPrint ( 0 ) 00165 { 00166 //====================================================================== 00167 // Construct a parameter from a name, comment, and data 00168 //====================================================================== 00169 this->Set(d); 00170 }
| CfgParam::~CfgParam | ( | ) |
Definition at line 119 of file CfgParam.cxx.
References fData, and fDataDelete.
00120 { 00121 if (fData) { 00122 fDataDelete(fData); 00123 fData = 0; 00124 } 00125 }
| void CfgParam::Get | ( | T & | t | ) | const |
Definition at line 175 of file CfgParam.h.
References fData, fDataType, GetName(), CfgException::kTypeMismatch, and os.
Referenced by testGet().
00176 { 00177 //====================================================================== 00178 // Retrieve the data held by the parameter into t 00179 //====================================================================== 00180 // Check that types match 00181 const std::type_info& ti = typeid(T); 00182 if (ti != this->fDataType()) { 00183 std::ostringstream os; 00184 os << "Attempt to get data of type " << ti.name() 00185 << " from parameter " << this->GetName() << " which is of type " 00186 << this->fDataType().name(); 00187 throw CfgException(CfgException::kTypeMismatch, 00188 os.str().c_str(), 00189 __FILE__, 00190 __LINE__); 00191 } 00192 // Normal case: types match so just make a copy to t 00193 t = (*(T*)fData); 00194 }
| const char * CfgParam::GetComment | ( | ) | const |
| const char * CfgParam::GetName | ( | ) | const |
Definition at line 129 of file CfgParam.cxx.
References fName.
Referenced by Get().
00129 { return fName.c_str(); }
Definition at line 141 of file CfgParam.cxx.
References fComment, fData, fDataCopy, fDataCopyCons, fDataDelete, fDataPrint, fDataType, and fName.
00142 { 00143 //====================================================================== 00144 // Copy operation 00145 //====================================================================== 00146 // Avoid self-copy 00147 if (&rhs == this) return *this; 00148 00149 // Copy the name and comments over 00150 fName = rhs.fName; 00151 fComment = rhs.fComment; 00152 00153 // Copy the data handlers 00154 fDataType = rhs.fDataType; 00155 fDataDelete = rhs.fDataDelete; 00156 fDataCopyCons = rhs.fDataCopyCons; 00157 fDataCopy = rhs.fDataCopy; 00158 fDataPrint = rhs.fDataPrint; 00159 00160 // Delete the data from the left-hand side and reallocate it using the 00161 // copy constructor 00162 if (fData) { fDataDelete(fData); fData = 0; } 00163 fDataCopyCons(&fData, rhs.fData); 00164 00165 return *this; 00166 }
| void CfgParam::Print | ( | std::ostream & | os | ) | const |
Definition at line 137 of file CfgParam.cxx.
References fData, and fDataPrint.
00137 { fDataPrint(os, fData); }
| void CfgParam::Set | ( | const T & | t | ) |
Definition at line 199 of file CfgParam.h.
References fData, fDataCopy, fDataCopyCons, fDataDelete, fDataPrint, and fDataType.
Referenced by CfgParam(), and TestEditor::EditConfig().
00200 { 00201 //====================================================================== 00202 // Set the value of the data held by the parameter to t 00203 //====================================================================== 00204 // Delete the data currently held 00205 if (fData) { 00206 this->fDataDelete(fData); 00207 fData = 0; 00208 } 00209 00210 // Setup the methods for handling this datum 00211 fDataType = gsDataType<T>; 00212 fDataDelete = gsDataDelete<T>; 00213 fDataCopyCons = gsDataCopyCons<T>; 00214 fDataCopy = gsDataCopy<T>; 00215 fDataPrint = gsDataPrint<T>; 00216 00217 // Create the data from the data passed in 00218 fDataCopyCons(&fData, &t); 00219 }
| const char * CfgParam::XMLTag | ( | ) | const |
Definition at line 23 of file CfgParam.cxx.
00024 { 00025 // 00026 // Return a recommended xml tag for this data type 00027 // 00028 static const std::type_info& bool_id = typeid(bool); 00029 static const std::type_info& char_id = typeid(char); 00030 static const std::type_info& short_id = typeid(short); 00031 static const std::type_info& int_id =typeid(int); 00032 static const std::type_info& uchar_id =typeid(unsigned char); 00033 static const std::type_info& ushort_id =typeid(unsigned short); 00034 static const std::type_info& uint_id =typeid(unsigned int); 00035 static const std::type_info& float_id =typeid(float); 00036 static const std::type_info& double_id =typeid(double); 00037 static const std::type_info& string_id =typeid(std::string); 00038 static const std::type_info& boolv_id =typeid(std::vector<bool>); 00039 static const std::type_info& charv_id =typeid(std::vector<char>); 00040 static const std::type_info& shortv_id =typeid(std::vector<short>); 00041 static const std::type_info& intv_id =typeid(std::vector<int>); 00042 static const std::type_info& ucharv_id =typeid(std::vector<unsigned char>); 00043 static const std::type_info& ushortv_id =typeid(std::vector<unsigned short>); 00044 static const std::type_info& uintv_id =typeid(std::vector<unsigned int>); 00045 static const std::type_info& floatv_id =typeid(std::vector<float>); 00046 static const std::type_info& doublev_id =typeid(std::vector<double>); 00047 static const std::type_info& stringv_id =typeid(std::vector<std::string>); 00048 00049 if (bool_id == this->fDataType()) return "bool"; 00050 if (char_id == this->fDataType()) return "char"; 00051 if (short_id == this->fDataType()) return "short"; 00052 if (int_id == this->fDataType()) return "int"; 00053 if (uint_id == this->fDataType()) return "uint"; 00054 if (uchar_id == this->fDataType()) return "uchar"; 00055 if (ushort_id == this->fDataType()) return "ushort"; 00056 if (uint_id == this->fDataType()) return "uint"; 00057 if (float_id == this->fDataType()) return "float"; 00058 if (double_id == this->fDataType()) return "double"; 00059 if (string_id == this->fDataType()) return "string"; 00060 00061 if (boolv_id == this->fDataType()) return "bool"; 00062 if (charv_id == this->fDataType()) return "char"; 00063 if (shortv_id == this->fDataType()) return "short"; 00064 if (intv_id == this->fDataType()) return "int"; 00065 if (uintv_id == this->fDataType()) return "uint"; 00066 if (ucharv_id == this->fDataType()) return "uchar"; 00067 if (ushortv_id == this->fDataType()) return "ushort"; 00068 if (uintv_id == this->fDataType()) return "uint"; 00069 if (floatv_id == this->fDataType()) return "float"; 00070 if (doublev_id == this->fDataType()) return "double"; 00071 if (stringv_id == this->fDataType()) return "string"; 00072 00073 return "?"; 00074 }
| std::ostream& operator<< | ( | std::ostream & | os, | |
| const CfgParam & | p | |||
| ) | [friend] |
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 15 of file CfgParam.cxx.
std::string CfgParam::fComment [private] |
Explanation of what parameter is used for.
Definition at line 48 of file CfgParam.h.
Referenced by GetComment(), and operator=().
void* CfgParam::fData [private] |
Data values held by parameter.
Definition at line 49 of file CfgParam.h.
Referenced by CfgParam(), Get(), operator=(), Print(), Set(), and ~CfgParam().
void(* CfgParam::fDataCopy)(void *dest, const void *src) [private] |
Referenced by operator=(), and Set().
void(* CfgParam::fDataCopyCons)(void **dest, const void *src) [private] |
Referenced by CfgParam(), operator=(), and Set().
void(* CfgParam::fDataDelete)(void *) [private] |
Referenced by operator=(), Set(), and ~CfgParam().
void(* CfgParam::fDataPrint)(std::ostream &os, const void *d) [private] |
Referenced by operator=(), Print(), and Set().
const std::type_info&(* CfgParam::fDataType)(void) [private] |
Referenced by Get(), operator=(), and Set().
std::string CfgParam::fName [private] |
Name of parameter.
Definition at line 47 of file CfgParam.h.
Referenced by GetName(), and operator=().
1.4.7