#include <CfgXMLconfigBuilder.h>
Inheritance diagram for CfgXMLconfigBuilder:

Public Member Functions | |
| CfgXMLconfigBuilder (const char *tag) | |
| void | Build (const MXMLAttributeList &attr, const std::string &buffer) |
Definition at line 16 of file CfgXMLconfigBuilder.h.
| CfgXMLconfigBuilder::CfgXMLconfigBuilder | ( | const char * | tag | ) |
Definition at line 22 of file CfgXMLconfigBuilder.cxx.
00022 : 00023 CfgConfigBuilder(), 00024 MXMLBuilder(tag) 00025 { }
| void CfgXMLconfigBuilder::Build | ( | const MXMLAttributeList & | attr, | |
| const std::string & | buffer | |||
| ) | [virtual] |
Implements MXMLBuilder.
Definition at line 29 of file CfgXMLconfigBuilder.cxx.
References CfgConfig::AdoptParam(), CfgConfig::Copy(), CfgTable::GetConfig(), MXMLParser::GetCurrentSource(), CfgTable::Instance(), MXMLStack< T >::Instance(), MXMLString::IsTrue(), name, CfgConfig::Param(), CfgConfigBuilder::Publish(), s, and CfgConfig::SetReadOnly().
00031 { 00032 //====================================================================== 00033 //! Construct a configuration from XML data. Most general format: 00034 //! 00035 //! <config name="NAME" version"VERSION" ro="T/F"> ... </config> 00036 //! 00037 //! Only "NAME" is required. 00038 //! 00039 //! \param attr - list of XML attributes 00040 //! \param buffer - text inside element (un used) 00041 //======================================================================x 00042 // Parse out the attributes 00043 std::string name = "<null>"; // name of config 00044 std::string version = "0"; // version of config 00045 std::string source = "??"; // Which one?? TODO 00046 std::string base = "0"; // Version of config this on is based on 00047 bool ronly = false; // Flagged as read only? 00048 00049 // Ask parser name of file/database we're looking at 00050 source = MXMLParser::GetCurrentSource(); 00051 00052 // Pull out attributes 00053 MXMLAttributeList::const_iterator itr (attr.begin()); 00054 MXMLAttributeList::const_iterator itrEnd(attr.end()); 00055 for (; itr!=itrEnd; ++itr) { 00056 if (itr->Name()=="name") name = itr->Value(); 00057 if (itr->Name()=="version") version= itr->Value(); 00058 if (itr->Name()=="base") base = itr->Value(); 00059 if (itr->Name()=="ro") ronly = MXMLString::IsTrue(itr->Value()); 00060 } 00061 00062 // Create the configuration using the attributes 00063 CfgConfig* cfg = new CfgConfig(name.c_str(), 00064 version.c_str(), 00065 source.c_str()); 00066 if (base=="0") { 00067 // Scoop up any parameters left on the stack by the XML parser and 00068 // add them to the configuration 00069 MXMLStack<CfgParam>& s = MXMLStack<CfgParam>::Instance(); 00070 for (; !s.empty(); s.pop()) cfg->AdoptParam( new CfgParam(s.top()) ); 00071 } 00072 else { 00073 // Find the existing configuration and make the new one a copy of 00074 // it 00075 const CfgConfig* basecfg = 00076 CfgTable::Instance().GetConfig(name.c_str(),base.c_str()); 00077 if (basecfg==0) { 00078 std::cout << "Failed to find base configuration " 00079 << name << ":" << base 00080 << " while constructing " 00081 << name << ":" << version << std::endl; 00082 abort(); 00083 } 00084 // Copy the base into the derived configuration 00085 CfgConfig::Copy(*cfg, *basecfg, version.c_str(), source.c_str()); 00086 00087 // Scoop up all the parameters which are associated with the 00088 // derived configuration 00089 MXMLStack<CfgParam>& s = MXMLStack<CfgParam>::Instance(); 00090 for (; !s.empty(); s.pop()) cfg->Param(s.top().GetName()) = s.top(); 00091 } 00092 // Finally, ship it! 00093 if (ronly) cfg->SetReadOnly(); 00094 this->Publish(cfg); 00095 }
1.4.7