Bitstream Interpretation Library (BIL)  0.1
XMLWriter.hpp
Go to the documentation of this file.
1 
6 #pragma once
7 #ifndef BIL_XMLWRITER_HPP
8 #define BIL_XMLWRITER_HPP
9 
10 #include <cstring>
11 #include <ostream>
12 #include <stack>
13 #include <string>
14 
15 
16 namespace bil {
17 
32  class XMLWriter {
33  public:
34 
41  explicit XMLWriter(std::ostream& os, size_t baseIndent = 0, size_t levelIndent = 2);
42 
43 
54  void beginElement(const std::string& name, bool newLine = true);
55 
63  void endElement(bool newLine = true);
64 
65 
75  void addAttribute(const std::string& name, const std::string& value);
76 
86  void addAttribute(const std::string& name, unsigned value);
87 
88 
98  void addData(const std::string& data, bool newLine = true);
99 
100 
107  void addProcessingInstruction(const std::string& target, const std::string& instruction, bool newLine = true);
108 
109 
114  size_t depth() const;
115 
120  std::string element() const;
121 
122 
123  private:
124 
125  XMLWriter(const XMLWriter&);
126  XMLWriter& operator=(const XMLWriter&);
127 
128 
129  std::ostream& m_outputStream;
130 
131  std::stack<std::string> m_elementStack;
132  bool m_insideOpeningTag;
133 
134  size_t m_levelIndent;
135  std::string m_lineIndentString;
136 
137  };
138 
139 }
140 
141 #endif