CBMC
xml_parser.cpp
Go to the documentation of this file.
1 /*******************************************************************\
2 
3 Module:
4 
5 Author: Daniel Kroening, kroening@kroening.com
6 
7 \*******************************************************************/
8 
9 #include "xml_parser.h"
10 
11 #include <fstream>
12 
14 
16 int yyxmllex_destroy(void *);
17 int yyxmlparse(xml_parsert &, void *);
18 
20 {
21  void *scanner;
22  yyxmllex_init_extra(this, &scanner);
23  bool parse_fail = yyxmlparse(*this, scanner) != 0;
24  yyxmllex_destroy(scanner);
25  return parse_fail;
26 }
27 
28 // 'do it all' function
29 bool parse_xml(
30  std::istream &in,
31  const std::string &filename,
32  message_handlert &message_handler,
33  xmlt &dest)
34 {
35  xml_parsert xml_parser{message_handler};
36 
37  xml_parser.set_file(filename);
38  xml_parser.in=&in;
39 
40  bool result = xml_parser.parse();
41 
42  // save result
43  xml_parser.parse_tree.element.swap(dest);
44 
45  return result;
46 }
47 
48 // 'do it all' function
49 bool parse_xml(
50  const std::string &filename,
51  message_handlert &message_handler,
52  xmlt &dest)
53 {
54  std::ifstream in(filename);
55 
56  if(!in)
57  return true;
58 
59  return parse_xml(in, filename, message_handler, dest);
60 }
static int instance_count
Definition: xml_parser.h:54
bool parse() override
Definition: xml_parser.cpp:19
Definition: xml.h:21
int yyxmllex_init_extra(xml_parsert *, void **)
bool parse_xml(std::istream &in, const std::string &filename, message_handlert &message_handler, xmlt &dest)
Definition: xml_parser.cpp:29
int yyxmllex_destroy(void *)
int yyxmlparse(xml_parsert &, void *)