liblcf
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
writer_xml.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2014 liblcf authors
3  * This file is released under the MIT License
4  * http://opensource.org/licenses/MIT
5  */
6 
7 #ifndef LCF_WRITER_XML_H
8 #define LCF_WRITER_XML_H
9 
10 #include <string>
11 #include <vector>
12 #include <cstdio>
13 #include "reader_types.h"
14 
18 class XmlWriter {
19 
20 public:
26  XmlWriter(const char* filename);
27 
33  XmlWriter(const std::string& filename);
34 
38  ~XmlWriter();
39 
43  void Open();
44 
48  void Close();
49 
55  void WriteInt(int val);
56 
62  template <class T>
63  void Write(const T& val);
64 
72  template <class T>
73  void WriteNode(const std::string& name, const T& val);
74 
80  void BeginElement(const std::string& name);
81 
88  void BeginElement(const std::string& name, int ID);
89 
95  void EndElement(const std::string& name);
96 
100  void NewLine();
101 
108  bool IsOk() const;
109 
110 protected:
112  std::string filename;
114  FILE *stream;
116  int indent;
118  bool at_bol;
119 
123  void Indent();
124 
130  template <class T>
131  void WriteVector(const std::vector<T>& val);
132 
133 };
134 
135 #endif
void WriteInt(int val)
Definition: writer_xml.cpp:139
bool IsOk() const
Definition: writer_xml.cpp:199
bool at_bol
Definition: writer_xml.h:118
void BeginElement(const std::string &name)
Definition: writer_xml.cpp:163
void EndElement(const std::string &name)
Definition: writer_xml.cpp:177
FILE * stream
Definition: writer_xml.h:114
void NewLine()
Definition: writer_xml.cpp:184
void Open()
Definition: writer_xml.cpp:30
int indent
Definition: writer_xml.h:116
XmlWriter(const char *filename)
Definition: writer_xml.cpp:10
void Write(const T &val)
void Close()
Definition: writer_xml.cpp:35
void WriteVector(const std::vector< T > &val)
Definition: writer_xml.cpp:144
std::string filename
Definition: writer_xml.h:112
void WriteNode(const std::string &name, const T &val)
Definition: writer_xml.cpp:157
void Indent()
Definition: writer_xml.cpp:191