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

Public Member Functions | |
| configBuilder (const char *tag) | |
| void | Build (const xmli::AttributeList &attr, const std::string &buffer) |
|
|
Definition at line 24 of file configBuilder.cxx.
00024 : 00025 cfg::ConfigBuilder(), 00026 xmli::Builder(tag) 00027 { } |
|
||||||||||||
|
Builders must implement this method which constructs a C++ object from XML attributes
Implements xmli::Builder. Definition at line 31 of file configBuilder.cxx. References cfg::Config::AdoptParam(), xmli::AttributeList, cfg::Config::Copy(), cfg::Table::GetConfig(), xmli::Parser::GetCurrentSource(), cfg::Table::Instance(), xmli::Stack< T >::Instance(), xmli::ChString::IsTrue(), cfg::Config::Par(), cfg::ConfigBuilder::Publish(), and cfg::Config::SetReadOnly().
00033 {
00034 //======================================================================
00045 //======================================================================
00046 // Parse out the attributes
00047 std::string name = "<null>"; // name of config
00048 std::string version = "0"; // version of config
00049 std::string source = "??"; // Where config was loaded from
00050 std::string base = "0"; // Version of config this one is based on
00051 bool ronly = false; // Flagged as read only?
00052
00053 // Ask parser name of file/database we're looking at
00054 source = xmli::Parser::GetCurrentSource();
00055
00056 // Pull out attributes
00057 xmli::AttributeList::const_iterator itr (attr.begin());
00058 xmli::AttributeList::const_iterator itrEnd(attr.end());
00059 for (; itr!=itrEnd; ++itr) {
00060 if (itr->Name()=="name") name = itr->Value();
00061 if (itr->Name()=="version") version= itr->Value();
00062 if (itr->Name()=="base") base = itr->Value();
00063 if (itr->Name()=="ro") ronly = xmli::ChString::IsTrue(itr->Value());
00064 }
00065 // Create a new configuration using the attributes
00066 cfg::Config* cfg = new cfg::Config(name.c_str(),
00067 version.c_str(),
00068 source.c_str());
00069 if (base=="0") {
00070 // Scoop up any parameters left on the stack by the XML parser and
00071 // add them to the configuration
00072 xmli::Stack<cfg::Param>& s = xmli::Stack<cfg::Param>::Instance();
00073 for (; !s.empty(); s.pop()) cfg->AdoptParam( new cfg::Param(s.top()) );
00074 }
00075 else {
00076 // Find the existing configuration and make the new one a copy of
00077 // it
00078 const cfg::Config* basecfg =
00079 cfg::Table::Instance().GetConfig(name.c_str(), base.c_str());
00080 if (basecfg==0) {
00081 std::ostringstream os;
00082 os << "Failed to find base configuration "
00083 << name << ":" << base
00084 << " while constructing "
00085 << name << ":" << version << std::endl;
00086 throw cfg::Exception(Exception::kConfigNotFound,
00087 os.str().c_str(),__FILE__,__LINE__);
00088 }
00089
00090 // Copy the base into the derived configuration
00091 cfg::Config::Copy(*cfg,
00092 *basecfg,
00093 version.c_str(),
00094 source.c_str());
00095
00096 // Scoop up all the parameters which are associated with the
00097 // derived configuration
00098 xmli::Stack<cfg::Param>& s = xmli::Stack<cfg::Param>::Instance();
00099 for (; !s.empty(); s.pop()) cfg->Par(s.top().GetName()) = s.top();
00100 }
00101
00102 // Finally, ship it!
00103 if (ronly) cfg->SetReadOnly();
00104 this->Publish(cfg);
00105 }
|
1.3.5