supertux
writer.hpp
1 // SuperTux
2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
3 //
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, either version 3 of the License, or
7 // (at your option) any later version.
8 //
9 // This program is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 // GNU General Public License for more details.
13 //
14 // You should have received a copy of the GNU General Public License
15 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 
17 #ifndef HEADER_SUPERTUX_UTIL_WRITER_HPP
18 #define HEADER_SUPERTUX_UTIL_WRITER_HPP
19 
20 #include <string>
21 #include <vector>
22 
23 namespace sexp {
24 class Value;
25 } // namespace sexp
26 
27 class Writer final
28 {
29 public:
30  Writer(const std::string& filename);
31  Writer(std::ostream& out);
32  ~Writer();
33 
34  void write_comment(const std::string& comment);
35 
36  void start_list(const std::string& listname, bool string = false);
37 
38  void write(const std::string& name, bool value);
39  void write(const std::string& name, int value);
40  void write(const std::string& name, float value);
41  void write(const std::string& name, const char* value);
42  void write(const std::string& name, const std::string& value, bool translatable = false);
43  void write(const std::string& name, const std::vector<int>& value);
44  void write(const std::string& name, const std::vector<unsigned int>& value, int width = 0);
45  void write(const std::string& name, const std::vector<float>& value);
46  void write(const std::string& name, const std::vector<std::string>& value);
47  void write(const std::string& name, const sexp::Value& value);
48  // add more write-functions when needed...
49 
50  void end_list(const std::string& listname);
51 
52 private:
53  void write_escaped_string(const std::string& str);
54  void write_sexp(const sexp::Value& value, bool fudge);
55  void indent();
56 
57 private:
58  std::string m_filename;
59  std::ostream* out;
60  bool out_owned;
61  int indent_depth;
62  std::vector<std::string> lists;
63 
64 private:
65  Writer(const Writer&) = delete;
66  Writer & operator=(const Writer&) = delete;
67 };
68 
69 #endif
70 
71 /* EOF */
Definition: object_option.hpp:39
Definition: writer.cpp:23