5#include <libxml++/libxml++.h>
6#include <boost/lexical_cast.hpp>
13#if LIBXMLXX_MAJOR_VERSION == 2
23 current_node_ = parser.
Document()->get_root_node();
32 while (!spawned_children_.empty()) {
33 InfileTree* qe_child = *spawned_children_.begin();
34 spawned_children_.erase(spawned_children_.begin());
45 const xmlpp::Node::NodeList nodelist = current_node_->get_children();
46 xmlpp::Node::NodeList::const_iterator it;
47 for (it = nodelist.begin(); it != nodelist.end(); it++) {
48 const Element* element =
dynamic_cast<const Element*
>(*it);
58 return current_node_->find(query).size();
65 using xmlpp::TextNode;
66 const NodeSet nodeset = current_node_->find(query);
67 if (nodeset.empty()) {
68 throw KeyError(
"Could not find a node by the name: " + query);
71 if (nodeset.size() < index + 1) {
72 throw ValueError(
"Index exceeds number of nodes in query: " + query);
75 const Element* element =
dynamic_cast<const Element*
>(nodeset.at(index));
78 throw CastError(
"Node: " + nodeset.at(index)->get_name() +
79 " is not an Element node.");
83 if (nodelist.size() != 1) {
84 throw ValueError(
"Element node " + element->get_name() +
85 " has more content than expected.");
88 const TextNode* text =
89 dynamic_cast<const xmlpp::TextNode*
>(element->get_children().front());
92 throw CastError(
"Node: " + element->get_name() +
" is not a Text node.");
95 return text->get_content();
102 std::vector<xmlpp::Element*> elements;
103 const Node::NodeList nodelist = current_node_->get_children();
104 Node::NodeList::const_iterator it;
105 for (it = nodelist.begin(); it != nodelist.end(); it++) {
106 xmlpp::Element* element =
dynamic_cast<xmlpp::Element*
>(*it);
108 elements.push_back(element);
111 if (elements.size() < index + 1) {
112 throw ValueError(
"Index exceeds number of elements in node: " +
113 current_node_->get_name());
115 return elements.at(index)->get_name();
122 const NodeSet nodeset = current_node_->find(query);
124 if (nodeset.size() < index + 1) {
125 throw ValueError(
"Index exceeds number of nodes in query: " + query);
128 xmlpp::Element* element =
dynamic_cast<xmlpp::Element*
>(nodeset.at(index));
131 throw CastError(
"Node: " + nodeset.at(index)->get_name() +
132 " is not an Element node.");
140 spawned_children_.insert(qe_child);
For failed casts that shouldn't.
virtual InfileTree * GetEngineFromQuery(std::string query, int index)
every derived infile must return a new instance initialized by a query.
InfileTree(XMLParser &parser)
constructor given a parser
virtual int NMatches(std::string query)
investigates the current status and returns the number of elements matching a query
virtual std::string GetElementName(int index=0)
investigates the current status and returns a string representing the name of a given index
InfileTree * SubTree(std::string query, int index=0)
populates a child infile based on a query and index
virtual std::string GetString(std::string query, int index=0)
investigates the current status and returns a string representing the content of a query at a given i...
For failed retrieval/insertion of key-based data into/from data structures.
For values that are too big, too small, etc.
A helper class to hold xml file data and provide automatic validation.
xmlpp::Document * Document()
taken directly from OsiSolverInterface.cpp on 2/17/14 from https://projects.coin-or....
xmlpp::Node::NodeSet NodeSet
xmlpp::Node::const_NodeList const_NodeList