Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

cfg::paramBuilder Class Reference

#include <paramBuilder.h>

Inheritance diagram for cfg::paramBuilder:

xmli::Builder List of all members.

Public Member Functions

 paramBuilder (const char *tag)
void Build (const xmli::AttributeList &attr, const std::string &buffer)

Constructor & Destructor Documentation

cfg::paramBuilder::paramBuilder const char *  tag  ) 
 

Definition at line 21 of file paramBuilder.cxx.

00021                                              :
00022   xmli::Builder(tag)
00023 { }


Member Function Documentation

void cfg::paramBuilder::Build const xmli::AttributeList attr,
const std::string &  buffer
[virtual]
 

Builders must implement this method which constructs a C++ object from XML attributes

Parameters:
attr : The list of key/value pairs of XML attributes
buffer : The text appearing inside the XML tags
For example, this XML string:
<beetle name="ringo" instrument="drums"> Ringo is my favorite </beetle>
is passed as two attributes name=ringo, and instrument=drums and with buffer='Ringo is my favorite'

Once C++ object is created, it should be placed on a xmli::Stack to be used by other pieces of code

See also:
xmli::Stack.h
For examples see
See also:
xmli::intBuilder.cxx

xmli::xmlfileBuilder.cxx

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 }


The documentation for this class was generated from the following files:
Generated on Thu Jul 24 12:01:15 2008 for NOvA Offline by doxygen 1.3.5