00001
00002
00003
00005
00008
00009
00011 #include "Config/Param.h"
00012
00013
00014
00015 namespace cfg {
00016 std::ostream& operator<<(std::ostream& os, const Param& p)
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 }
00032 }
00033
00034
00035
00036 const char* cfg::Param::XMLTag() const
00037 {
00038
00039
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 }
00092
00093
00094
00095 cfg::Param::Param() :
00096 fName ( "<null>" ),
00097 fComment ( "" ),
00098 fData ( 0 ),
00099 fDataType ( 0 ),
00100 fVectorType ( 0 ),
00101 fDataDelete ( 0 ),
00102 fDataCopyCons ( 0 ),
00103 fDataCopy ( 0 ),
00104 fDataPrint ( 0 )
00105 { }
00106
00107
00108
00109 cfg::Param::Param(const cfg::Param& p) :
00110 fName ( p.fName ),
00111 fComment ( p.fComment ),
00112 fData ( 0 ),
00113 fDataType ( p.fDataType ),
00114 fVectorType ( p.fVectorType ),
00115 fDataDelete ( p.fDataDelete ),
00116 fDataCopyCons ( p.fDataCopyCons ),
00117 fDataCopy ( p.fDataCopy ),
00118 fDataPrint ( p.fDataPrint )
00119 {
00120 fDataCopyCons(&fData, p.fData);
00121 }
00122
00123
00124
00125 cfg::Param::Param(const char* name, const char* comment) :
00126 fName ( name ),
00127 fComment ( comment ),
00128 fData ( 0 ),
00129 fDataType ( 0 ),
00130 fVectorType ( 0 ),
00131 fDataDelete ( 0 ),
00132 fDataCopyCons ( 0 ),
00133 fDataCopy ( 0 ),
00134 fDataPrint ( 0 )
00135 { }
00136
00137
00138
00139 cfg::Param::~Param()
00140 {
00141 if (fData) {
00142 fDataDelete(fData);
00143 fData = 0;
00144 }
00145 }
00146
00147
00148
00149 const char* cfg::Param::GetName() const { return fName.c_str(); }
00150
00151
00152
00153 const char* cfg::Param::GetComment() const { return fComment.c_str(); }
00154
00155
00156
00157 void cfg::Param::Print(std::ostream& os) const { fDataPrint(os, fData); }
00158
00159
00160
00161 cfg::Param& cfg::Param::operator=(const cfg::Param& rhs)
00162 {
00163
00164
00165
00166
00167 if (&rhs == this) return *this;
00168
00169
00170 fName = rhs.fName;
00171 fComment = rhs.fComment;
00172
00173
00174 fDataType = rhs.fDataType;
00175 fVectorType = rhs.fVectorType;
00176 fDataDelete = rhs.fDataDelete;
00177 fDataCopyCons = rhs.fDataCopyCons;
00178 fDataCopy = rhs.fDataCopy;
00179 fDataPrint = rhs.fDataPrint;
00180
00181
00182
00183 if (fData) { fDataDelete(fData); fData = 0; }
00184 fDataCopyCons(&fData, rhs.fData);
00185
00186 return *this;
00187 }
00188