XMLreaderProxy XMLreaderProxy::operator[] (plint newId) const { if (!reader) { plbIOError(std::string("Cannot read value from XML element")); } if (!reader->idExists(newId)) { std::stringstream newIdStr; newIdStr << newId; plbIOError ( std::string("Id ") + newIdStr.str() + std::string(" does not exist in XML element") ); } return XMLreaderProxy(reader, newId); }
XMLreaderProxy XMLreaderProxy::operator[] (std::string name) const { if (!reader) { plbIOError(std::string("Cannot read value from XML element ") + name); } return reader->getElement(name, id); }
std::vector<XMLreader*> const& XMLreader::getChildren(plint id) const { std::map<plint,Data>::const_iterator it = data_map.find(id); if (it==data_map.end()) { plbIOError(std::string("Cannot access id ")+util::val2str(id)+" in XML element " + name); } return it->second.children; }
XMLreaderProxy XMLreader::getElement(std::string name, plint id) const { std::map<plint,Data>::const_iterator it = data_map.find(id); if (it==data_map.end()) { std::stringstream idStr; idStr << id; plbIOError ( std::string("Element with id ") + idStr.str() + std::string(" does not exist") ); } std::vector<XMLreader*> const& children = it->second.children; for (pluint iNode=0; iNode<children.size(); ++iNode) { if (children[iNode]->name == name) { return XMLreaderProxy(children[iNode]); } } plbIOError( std::string("Element ")+name+std::string(" not found in XML file.") ); return XMLreaderProxy(0); }
XMLreaderProxy XMLreader::operator[] (std::string name) const { Data const& data = data_map.begin()->second; for (pluint iNode=0; iNode<data.children.size(); ++iNode) { if (data.children[iNode]->name == name) { return XMLreaderProxy(data.children[iNode]); } } plbIOError( std::string("Element ")+name+std::string(" not found in XML file.") ); return XMLreaderProxy(0); }
WriteVtk::WriteVtk(PlbXmlController2D const *controller, XMLreaderProxy const &r) : TaskBase(controller,r.getId()), fileNameLength(8) { try{ r["fileName"].read(prefix); } catch(PlbIOException &e) { plbIOError("No file name for VTK output specified"); } if(ioUtils::elementExists(r,"fileNameLength")) r["fileNameLength"].read(fileNameLength); }
XMLreaderProxy XMLreaderProxy::iterId() const { if (!reader) { plbIOError(std::string("Use of invalid XML element")); } plint newId = id; if (reader->getNextId(newId)) { return XMLreaderProxy(reader, newId); } else { return XMLreaderProxy(0); } }
void XMLwriter::print(std::string fName) const { plb_ofstream ofile(fName.c_str()); plbIOError( !ofile.is_open(), std::string("Could not open file ") + fName + std::string(" for write access") ); toOutputStream(ofile); }
std::vector<XMLreader*> const& XMLreaderProxy::getChildren() const { if (!reader) { plbIOError(std::string("Cannot read value from XML element ")); } return reader->getChildren(id); }
std::string XMLreaderProxy::getName() const { if (!reader) { plbIOError(std::string("Cannot read value from XML element ")); } return reader->getName(); }