a0db57df504daf9a6606037194e0308e9e872a9c
[supertux.git] / src / lisp / 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_LISP_WRITER_HPP
18 #define HEADER_SUPERTUX_LISP_WRITER_HPP
19
20 #include <string>
21 #include <vector>
22
23 namespace lisp {
24
25 class Writer
26 {
27 public:
28   Writer(const std::string& filename);
29   Writer(std::ostream* out);
30   ~Writer();
31
32   void write_comment(const std::string& comment);
33
34   void start_list(const std::string& listname, bool string = false);
35
36   void write(const std::string& name, int value);
37   void write(const std::string& name, float value);
38   void write(const std::string& name, const std::string& value,
39              bool translatable = false);
40   void write(const std::string& name, const char* value,
41              bool translatable = false) { write(name, static_cast<const std::string&>(value), translatable); }
42   void write(const std::string& name, bool value);
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);
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   // add more write-functions when needed...
48
49   void end_list(const std::string& listname);
50
51 private:
52   void write_escaped_string(const std::string& str);
53   void indent();
54
55   std::ostream* out;
56   bool out_owned;
57   int indent_depth;
58   std::vector<std::string> lists;
59
60 private:
61   Writer(const Writer&);
62   Writer & operator=(const Writer&);
63 };
64
65 } //namespace lisp
66
67 #endif //SUPERTUX_LISPWRITER_H
68
69 /* EOF */