13 class XMLCoreParserDebugger{
15 static bool get_debug_state(){
16 return ::getenv (
"XMLDEBUG") != 0;
19 static const bool debug_state = get_debug_state();
42 other.m_node =
nullptr;
60 if (XMLCoreParserDebugger::debug ()){
61 std::cout <<
"XMLCoreFactory::~XMLCoreFactory> factory=" <<
this << std::endl;
67 if (XMLCoreParserDebugger::debug ()){
68 std::cout <<
"XMLCoreFactory::start> factory=" <<
this << std::endl;
75 if (XMLCoreParserDebugger::debug ()){
76 std::cout <<
"XMLCoreFactory::end>" << std::endl;
83 if (XMLCoreParserDebugger::debug ()){
84 std::cout <<
"XMLCoreFactory::comment>" << std::endl;
91 if (XMLCoreParserDebugger::debug ()){
92 std::cout <<
"XMLCoreFactory::do_start>" << std::endl;
98 if (XMLCoreParserDebugger::debug ()){
99 std::cout <<
"XMLCoreFactory::do_end>" << std::endl;
105 if (XMLCoreParserDebugger::debug ()){
106 std::cout <<
"XMLCoreFactory::do_comment>" << std::endl;
113 return (attrs.size ());
119 CoreParser::DOMNamedNodeMap::const_iterator it = attrs.find (name);
120 if (it == attrs.end ())
return (
false);
128 sscanf (s.c_str (),
"%80d", &
result);
136 sscanf (s.c_str (),
"%80lg", &
result);
144 if (s ==
"TRUE")
result =
true;
155 if (XMLCoreParserDebugger::debug ()){
156 std::cout <<
"XMLCoreFactory::get_value> name=" << name << std::endl;
159 CoreParser::DOMNamedNodeMap::const_iterator it = attrs.find (name);
160 if (it == attrs.end ())
return (
"");
161 std::string
result = (*it).second;
162 if (XMLCoreParserDebugger::debug ()) {
163 std::cout <<
"XMLCoreFactory::get_value>2 value=" <<
result << std::endl;
170 return node.get_node().get_name ();
175 return node.get_node ().sibling_number ();
181 CoreParser::DOMNamedNodeMap::const_iterator it;
182 for (it = attrs.begin (); (
index > 0) && (it != attrs.end ()); ++it){
185 if (it == attrs.end ())
return (
"");
193 while ((
result.length () > 0) &&
196 while ((
result.length () > 0) &&
199 for (std::string::size_type i = 0; i <
result.length (); ++i){
215 std::string t = checkstring +
" " + checkstring;
216 std::istringstream tmpstr (t.c_str());
217 while (tmpstr.good ()) {
222 if (counter/2 != n) {
223 std::cerr <<
"XMLCoreFactory::check_int error: no " << n
224 <<
" ints in \"" << checkstring <<
"\" for attribute " <<
225 name <<
". exit." << std::endl;
230 if (nodename !=
"" ) std::cerr <<
"for name=" << nodename << std::endl;
231 if (volume !=
"" ) std::cerr <<
"for volume=" << volume << std::endl;
247 std::string t = checkstring +
" " + checkstring;
248 std::istringstream tmpstr (t.c_str());
249 while (tmpstr.good ()) {
254 if (counter/2 != n) {
255 std::cerr <<
"XMLCoreFactory::check_double error: (" << counter <<
") no " << n
256 <<
" doubles in \"" << checkstring <<
"\" for attribute " <<
257 name <<
". exit." << std::endl;
260 if (name1 !=
"" ) std::cerr <<
"for name=" << name << std::endl;
261 if (volume !=
"" ) std::cerr <<
"for volume=" << volume << std::endl;
275 if (XMLCoreParserDebugger::debug ()){
276 if (doc !=
nullptr) doc->print (
"============ ALL =============");
279 throw std::runtime_error(
"XMLCoreParser: no such file ["+file_name+
"]");
286 if (XMLCoreParserDebugger::debug ()){
287 std::cout <<
"XMLCoreParser::visit file_name "
288 << file_name << std::endl;
291 if (XMLCoreParserDebugger::debug ()){
294 std::cout <<
"XMLCoreParser::visit node=" << nptr << std::endl;
304 const std::string& nodeName =
node.get_name();
305 const std::string& nodeValue =
node.get_value();
306 if (XMLCoreParserDebugger::debug ()){
307 std::cout <<
"XMLCoreParser::visit node(" << nptr <<
") " << nodeName << std::endl;
310 if (XMLCoreParserDebugger::debug ()){
311 std::cout <<
"XMLCoreParser::visit factory " << factory << std::endl;
314 switch (
node.get_type()) {
324 if (XMLCoreParserDebugger::debug ()){
325 std::cout <<
"XMLCoreParser::visit ELEMENT_NODE "
326 <<
" factory=" << factory
330 factory->
start (*
this, core_node);
332 std::cerr <<
"XMLCoreParser> Cannot find factory for element "
333 << nodeName << std::endl;
341 if (factory != 0) factory->
end (*
this, core_node);
345 if (factory != 0) factory->
comment (*
this, nodeValue);
349 std::cout <<
"ENTITY_NODE " << nodeValue << std::endl;
353 std::cout <<
"ENTITY_REFERENCE_NODE " << nodeValue << std::endl;
357 std::cerr <<
"Unrecognized node type = " << (long)
node.get_type() << std::endl;
361 if (XMLCoreParserDebugger::debug ()){
362 std::cout <<
"XMLCoreParser::visit-2" << std::endl;
373 std::unique_ptr<XMLCoreFactory> factory) {
374 if (XMLCoreParserDebugger::debug ()){
375 std::cout <<
"XMLCoreFactory::register_factory> name=" << name
376 <<
" factory=" << factory.get() << std::endl;
383 if (XMLCoreParserDebugger::debug ()){
384 std::cout <<
"XMLCoreParser::register_external_entity> name=" << name
385 <<
" file_name=" << file_name << std::endl;
392 if (XMLCoreParserDebugger::debug ()){
393 std::cout <<
"XMLCoreParser::register_text_entity> name=" << name
404 return (*it).second.get();
static void register_text_entity(const std::string &name, const std::string &text)
static std::unique_ptr< CoreParser::DOMNode > parse(const std::string &file_name)
static void register_external_entity(const std::string &name, const std::string &file_name)
virtual void do_comment(XMLCoreParser &parser, const std::string &comment)
virtual void do_start(XMLCoreParser &parser, const XMLCoreNode &node)
static std::string get_value(const XMLCoreNode &node, const std::string &name)
void end(XMLCoreParser &parser, const XMLCoreNode &node)
std::string get_name(const XMLCoreNode &node)
static bool has_attribute(const XMLCoreNode &node, const std::string &name)
virtual ~XMLCoreFactory()
virtual void do_end(XMLCoreParser &parser, const XMLCoreNode &node)
static int attribute_number(const XMLCoreNode &node)
static double get_double(const XMLCoreNode &node, const std::string &name)
int sibling_number(const XMLCoreNode &node)
static bool check_int(const int n, const XMLCoreNode &node, const std::string &name)
void comment(XMLCoreParser &parser, const std::string &comment)
static bool check_double(const int n, const XMLCoreNode &node, const std::string &name)
static int get_int(const XMLCoreNode &node, const std::string &name)
static std::string get_ID(const XMLCoreNode &node, const std::string &name)
void start(XMLCoreParser &parser, const XMLCoreNode &node)
static bool get_boolean(const XMLCoreNode &node, const std::string &name)
static std::string get_token(const XMLCoreNode &node, const std::string &name)
const CoreParser::DOMNode & get_node() const
const CoreParser::DOMNode * m_node
XMLCoreNode & operator=(const XMLCoreNode &other)
XMLCoreNode(const CoreParser::DOMNode *node)
std::unique_ptr< XMLCoreFactory > m_default_factory
XMLCoreNode parse(const std::string &file_name)
void visit(const std::string &file_name)
void register_factory(const std::string &name, std::unique_ptr< XMLCoreFactory > factory)
void register_text_entity(const std::string &name, const std::string &text)
void register_external_entity(const std::string &name, const std::string &file_name)
XMLCoreFactory * find_factory(const std::string &name)
void register_default_factory(std::unique_ptr< XMLCoreFactory > factory)
std::vector< DOMNode * > DOMSiblings
std::map< std::string, std::string > DOMNamedNodeMap