Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | 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]
 

Build a cfg::Param object from XML data and put in on the stack

Parameters:
attr - list of tag attributes (unused)
buffer - text inside buffer (used as comment for parameter)

Implements xmli::Builder.

Definition at line 27 of file paramBuilder.cxx.

References 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   // 20-Apr-2009 seligman@nevis.columbia.edu
00050 
00051   // The purpose of the following C++ macro is to convert all the
00052   // xmli::Stack<T> objects (created by the various <T>Builder.cxx
00053   // classes in XMLInterface) into a single xmli::Stack<cfg::Param>
00054   // object.  The cfg::Param object will be of type vector<T>.
00055 
00056 #define GETVAL(TYPE,DEFLT) \
00057   { \
00058     xmli::Stack<std::vector<TYPE> >&  \
00059       s = xmli::Stack<std::vector<TYPE> >::Instance(); \
00060     for (; !s.empty(); s.pop()) { \
00061       std::vector<TYPE>& v = s.top(); \
00062       if ( v.empty() ) v.push_back( DEFLT ); \
00063       p.Set(v); \
00064       ++nval; \
00065     } \
00066   }
00067 
00068   GETVAL(bool,           0);
00069   GETVAL(short,          0);
00070   GETVAL(unsigned short, 0);
00071   GETVAL(int,            0);
00072   GETVAL(unsigned int,   0);
00073   GETVAL(float,          0);
00074   GETVAL(double,         0);
00075   GETVAL(std::string,std::string(""));
00076   GETVAL(time_t,         0);
00077 
00078   // Must have one and only one data parameter defined
00079   if (nval!=1) {
00080     std::cerr << "CfgXMLparamBuilder: " 
00081               << nval << " values specified for parameter " 
00082               << name << ". Aborting..." << std::endl;
00083     abort();
00084   }
00085 
00086   // Put the parameter on the stack
00087   xmli::Stack<cfg::Param>::Instance().push(p);  
00088 }


The documentation for this class was generated from the following files:
Generated on Sat Nov 21 04:45:36 2009 for NOvA Offline by  doxygen 1.3.9.1