2 // Copyright (C) 2006 Matthias Braun <matze@braunis.de>
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.
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.
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/>.
17 #include "lisp/writer.hpp"
19 #include "physfs/physfs_stream.hpp"
20 #include "util/log.hpp"
24 Writer::Writer(const std::string& filename)
26 out = new OFileStream(filename);
32 Writer::Writer(std::ostream* newout)
42 if(lists.size() > 0) {
43 log_warning << "Not all sections closed in lispwriter" << std::endl;
50 Writer::write_comment(const std::string& comment)
52 *out << "; " << comment << "\n";
56 Writer::start_list(const std::string& listname, bool string)
61 write_escaped_string(listname);
67 lists.push_back(listname);
71 Writer::end_list(const std::string& listname)
73 if(lists.size() == 0) {
74 log_warning << "Trying to close list '" << listname << "', which is not open" << std::endl;
77 if(lists.back() != listname) {
78 log_warning << "trying to close list '" << listname << "' while list '" << lists.back() << "' is open" << std::endl;
89 Writer::write(const std::string& name, int value)
92 *out << '(' << name << ' ' << value << ")\n";
96 Writer::write(const std::string& name, float value)
99 *out << '(' << name << ' ' << value << ")\n";
103 Writer::write(const std::string& name, const std::string& value,
110 write_escaped_string(value);
114 write_escaped_string(value);
120 Writer::write(const std::string& name, bool value)
123 *out << '(' << name << ' ' << (value ? "#t" : "#f") << ")\n";
127 Writer::write(const std::string& name,
128 const std::vector<int>& value)
132 for(std::vector<int>::const_iterator i = value.begin(); i != value.end(); ++i)
138 Writer::write(const std::string& name,
139 const std::vector<unsigned int>& value)
143 for(std::vector<unsigned int>::const_iterator i = value.begin(); i != value.end(); ++i)
149 Writer::write(const std::string& name,
150 const std::vector<float>& value)
154 for(std::vector<float>::const_iterator i = value.begin(); i != value.end(); ++i)
160 Writer::write(const std::string& name,
161 const std::vector<std::string>& value)
165 for(std::vector<std::string>::const_iterator i = value.begin(); i != value.end(); ++i) {
167 write_escaped_string(*i);
173 Writer::write_escaped_string(const std::string& str)
176 for(const char* c = str.c_str(); *c != 0; ++c) {
190 for(int i = 0; i<indent_depth; ++i)
194 } // end of namespace lisp