#include "preXmlManager.hh" #include "xmlToolDir.hh" #include #include #include #include void preXml::Manager::_mandatoryInitialisation() { // Here we could check here that we have a preXml-Xml file. // May put that in later. //Want to be absolutely certain of these: this->_geometry = NULL; this->_geometryManager = NULL; this->_sectionManager = NULL; _geometryManager = new xmlTool::Directory(this->_doc, std::string("geometry"), std::string("name") ); // We's better stop if that failed. assert(_geometryManager); }; preXml::Manager::~Manager() { if (this->_geometryManager) delete this->_geometryManager; if (this->_sectionManager) delete this->_sectionManager; // Note - we most definitely do not delete _geometry ! }; preXml::Manager::Manager(const std::string & preXmlFileName) { std::cout << "Atempting to open "<_mandatoryInitialisation(); }; preXml::Manager::Manager(std::istream & preXmlInputStream) { _doc.load(preXmlInputStream); this->_mandatoryInitialisation(); }; xmlTool::Directory & preXml::Manager::geoManager() const { // We are guaranteed that the _geometryManager exists // by the constructors of preXml::Manager, // so we can just say: return *(this->_geometryManager); }; void preXml::Manager::setGeometry() { // Must check that we are at the end of a geometry branch. if (this->_geometryManager->getDirNames().size() !=0 ) { std::cerr << "You've tried to set the geometry in " << this->_geometryManager->getCurDirName() << " but there are still further sub-geometries " << "to chose from. " << (this->_geometryManager->getDirNames())[0] << " for example." << endl; } assert(this->_geometryManager->getDirNames().size()==0 ); // Good. Let's set things up! this->_geometry = &(this->_geometryManager->getCurDirElt()); // and check that that did something assert(this->_geometry); // So now that the geometry is chosen, // let's fire up the secManager this->_sectionManager = new xmlTool::Directory(*(this->_geometry), string("section"), string("name")); // Better check that that worked. assert(this->_sectionManager); }; xmlTool::Directory & preXml::Manager::secManager() const { // Must check that a valid geometry exists. if (!this->_geometry) { std::cerr << "You've tried to start messing about in " << "sections long before having chosen and set " << "the directory. Set the geometry with " << "setGeometry() which is a preXml method." << endl; } assert(this->_geometry); // O.K. The existence of the geometry ensures // the existence of the sectionManager, so: return *(this->_sectionManager); }; void preXml::Manager::fill(preXml::Quantity & quantity, const xml::Element & elt) const { // cout << "Hey, I am Simple Filler." << endl; // Check that we have indeed been given a param. assert(elt.getTagName()==string("param")); // That's good. Let's examine elt's children. const xml::Element::ElementCollection & children = elt.getChildren(); // All good params should have exactly one child. assert(children.size()==1); // For clarity, let's now identify this only child const xml::Element & child = *(children[0]); // And now we read into "quantity" the information stored in "elt". quantity.readFrom(child); }; void preXml::Manager::fill(preXml::Quantity & quantity, const std::string & paramName) { // Only allowed to start doing this once a geometry has been chosen. // However, the call to secManager will sort that check out. // Let's find the element corresponding to the name const xml::Element & elt = this->_finder.findUnderTheUniqueElement(this->secManager().getCurDirElt(), string("param"), string("name"), paramName); // Well, if that didn't complain, then the elt was found. this->fill(quantity, elt); };