rapidxml_utils.hpp
Go to the documentation of this file.
1 #ifndef RAPIDXML_UTILS_HPP_INCLUDED
2 #define RAPIDXML_UTILS_HPP_INCLUDED
3 
4 // Copyright (C) 2006, 2009 Marcin Kalicinski
5 // Version 1.13
6 // Revision $DateTime: 2009/05/13 01:46:17 $
9 
10 #include "rapidxml.hpp"
11 #include <vector>
12 #include <string>
13 #include <fstream>
14 #include <stdexcept>
15 
16 namespace rapidxml
17 {
18 
20  template<class Ch = char>
21  class file
22  {
23 
24  public:
25 
28  file(const char *filename)
29  {
30  using namespace std;
31 
32  // Open stream
33  basic_ifstream<Ch> stream(filename, ios::binary);
34  if (!stream)
35  throw runtime_error(string("cannot open file ") + filename);
36  stream.unsetf(ios::skipws);
37 
38  // Determine stream size
39  stream.seekg(0, ios::end);
40  size_t size = stream.tellg();
41  stream.seekg(0);
42 
43  // Load data and add terminating 0
44  m_data.resize(size + 1);
45  stream.read(&m_data.front(), static_cast<streamsize>(size));
46  m_data[size] = 0;
47  }
48 
51  file(std::basic_istream<Ch> &stream)
52  {
53  using namespace std;
54 
55  // Load data and add terminating 0
56  stream.unsetf(ios::skipws);
57  m_data.assign(istreambuf_iterator<Ch>(stream), istreambuf_iterator<Ch>());
58  if (stream.fail() || stream.bad())
59  throw runtime_error("error reading stream");
60  m_data.push_back(0);
61  }
62 
65  Ch *data()
66  {
67  return &m_data.front();
68  }
69 
72  const Ch *data() const
73  {
74  return &m_data.front();
75  }
76 
79  std::size_t size() const
80  {
81  return m_data.size();
82  }
83 
84  private:
85 
86  std::vector<Ch> m_data; // File data
87 
88  };
89 
92  template<class Ch>
93  inline std::size_t count_children(xml_node<Ch> *node)
94  {
95  xml_node<Ch> *child = node->first_node();
96  std::size_t count = 0;
97  while (child)
98  {
99  ++count;
100  child = child->next_sibling();
101  }
102  return count;
103  }
104 
107  template<class Ch>
108  inline std::size_t count_attributes(xml_node<Ch> *node)
109  {
110  xml_attribute<Ch> *attr = node->first_attribute();
111  std::size_t count = 0;
112  while (attr)
113  {
114  ++count;
115  attr = attr->next_attribute();
116  }
117  return count;
118  }
119 
120 }
121 
122 #endif
This file contains rapidxml parser and DOM implementation.
std::size_t count_children(xml_node< Ch > *node)
Represents data loaded from a file.
xml_attribute< Ch > * next_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:856
file(const char *filename)
xml_node< Ch > * first_node(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:936
file(std::basic_istream< Ch > &stream)
xml_attribute< Ch > * first_attribute(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:1025
GLsizeiptr size
xml_node< Ch > * next_sibling(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:1004
std::size_t size() const
const Ch * data() const
GLuint GLuint GLsizei count
std::vector< Ch > m_data
std::size_t count_attributes(xml_node< Ch > *node)


mvsim
Author(s):
autogenerated on Fri May 7 2021 03:05:51