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 $
10 
11 #include <fstream>
12 #include <stdexcept>
13 #include <string>
14 #include <vector>
15 #include "rapidxml.hpp"
16 
17 namespace rapidxml {
18 
20 template <class Ch = char>
21 class file {
22  public:
25  file(const char *filename) {
26  using namespace std;
27 
28  // Open stream
29  basic_ifstream<Ch> stream(filename, ios::binary);
30  if (!stream) throw runtime_error(string("cannot open file ") + filename);
31  stream.unsetf(ios::skipws);
32 
33  // Determine stream size
34  stream.seekg(0, ios::end);
35  size_t size = stream.tellg();
36  stream.seekg(0);
37 
38  // Load data and add terminating 0
39  m_data.resize(size + 1);
40  stream.read(&m_data.front(), static_cast<streamsize>(size));
41  m_data[size] = 0;
42  }
43 
46  file(std::basic_istream<Ch> &stream) {
47  using namespace std;
48 
49  // Load data and add terminating 0
50  stream.unsetf(ios::skipws);
51  m_data.assign(istreambuf_iterator<Ch>(stream), istreambuf_iterator<Ch>());
52  if (stream.fail() || stream.bad())
53  throw runtime_error("error reading stream");
54  m_data.push_back(0);
55  }
56 
59  Ch *data() { return &m_data.front(); }
60 
63  const Ch *data() const { return &m_data.front(); }
64 
67  std::size_t size() const { return m_data.size(); }
68 
69  private:
70  std::vector<Ch> m_data; // File data
71 };
72 
75 template <class Ch>
76 inline std::size_t count_children(xml_node<Ch> *node) {
77  xml_node<Ch> *child = node->first_node();
78  std::size_t count = 0;
79  while (child) {
80  ++count;
81  child = child->next_sibling();
82  }
83  return count;
84 }
85 
88 template <class Ch>
89 inline std::size_t count_attributes(xml_node<Ch> *node) {
90  xml_attribute<Ch> *attr = node->first_attribute();
91  std::size_t count = 0;
92  while (attr) {
93  ++count;
94  attr = attr->next_attribute();
95  }
96  return count;
97 }
98 
99 } // namespace rapidxml
100 
101 #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:820
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:895
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:993
xml_node< Ch > * next_sibling(const Ch *name=0, std::size_t name_size=0, bool case_sensitive=true) const
Definition: rapidxml.hpp:970
std::size_t size() const
const Ch * data() const
std::vector< Ch > m_data
std::size_t count_attributes(xml_node< Ch > *node)


livox_ros_driver
Author(s): Livox Dev Team
autogenerated on Mon Mar 15 2021 02:40:46