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
23namespace sexp {
24class Value;
25} // namespace sexp
26
27class Writer final
28{
29public:
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
52private:
53 void write_escaped_string(const std::string& str);
54 void write_sexp(const sexp::Value& value, bool fudge);
55 void indent();
56
57private:
58 std::string m_filename;
59 std::ostream* out;
60 bool out_owned;
61 int indent_depth;
62 std::vector<std::string> lists;
63
64private:
65 Writer(const Writer&) = delete;
66 Writer & operator=(const Writer&) = delete;
67};
68
69#endif
70
71/* EOF */
72