#include <paramBuilder.h>
Inheritance diagram for cfg::paramBuilder:

Public Member Functions | |
| paramBuilder (const char *tag) | |
| void | Build (const xmli::AttributeList &attr, const std::string &buffer) |
|
|
Definition at line 21 of file paramBuilder.cxx.
00021 : 00022 xmli::Builder(tag) 00023 { } |
|
||||||||||||
|
Builders must implement this method which constructs a C++ object from XML attributes
Implements xmli::Builder. Definition at line 27 of file paramBuilder.cxx. References xmli::AttributeList, GETVAL, xmli::Stack< T >::Instance(), and xmli::ChString::Trim().
00029 {
00030 //======================================================================
00035 //======================================================================
00036 std::string name = "<null>";
00037 xmli::AttributeList::const_iterator itr (attr.begin());
00038 xmli::AttributeList::const_iterator itrEnd(attr.end());
00039 for (; itr!=itrEnd; ++itr) {
00040 if (itr->Name()=="name") name = itr->Value();
00041 }
00042 std::string comment = buffer;
00043 xmli::ChString::Trim(comment);
00044
00045 // Look for data fields left on the stack
00046 cfg::Param p(name.c_str(),comment.c_str());
00047 int nval = 0;
00048
00049 #define GETVAL(TYPE,DEFLT) \
00050 { \
00051 xmli::Stack<std::vector<TYPE> >& \
00052 s = xmli::Stack<std::vector<TYPE> >::Instance(); \
00053 for (; !s.empty(); s.pop()) { \
00054 std::vector<TYPE>& v = s.top(); \
00055 if (v.size()==0) p.Set(DEFLT); \
00056 if (v.size()==1) p.Set(v[0]); \
00057 else p.Set(v); \
00058 ++nval; \
00059 } \
00060 }
00061 GETVAL(bool, 0);
00062 GETVAL(short, 0);
00063 GETVAL(unsigned short, 0);
00064 GETVAL(int, 0);
00065 GETVAL(unsigned int, 0);
00066 GETVAL(float, 0);
00067 GETVAL(double, 0);
00068 GETVAL(std::string,std::string(""));
00069
00070 // Must have one and only one data parameter defined
00071 if (nval!=1) {
00072 std::cerr << "CfgXMLparamBuilder: "
00073 << nval << " values specified for parameter "
00074 << name << ". Aborting..." << std::endl;
00075 abort();
00076 }
00077
00078 // Put the parameter on the stack
00079 xmli::Stack<cfg::Param>::Instance().push(p);
00080 }
|
1.3.5