From: Matthias Braun Date: Thu, 20 May 2004 19:57:20 +0000 (+0000) Subject: forgot to add some files X-Git-Url: https://git.verplant.org/?a=commitdiff_plain;h=a07f98448499e7cecfd09c32509c4524f70d4e49;p=supertux.git forgot to add some files SVN-Revision: 1283 --- diff --git a/src/lispwriter.cpp b/src/lispwriter.cpp new file mode 100644 index 000000000..4221f8157 --- /dev/null +++ b/src/lispwriter.cpp @@ -0,0 +1,108 @@ +#include "lispwriter.h" +#include + +LispWriter::LispWriter(std::ostream& newout) + : out(newout), indent_depth(0) +{ +} + +LispWriter::~LispWriter() +{ + if(lists.size() > 0) { + std::cerr << "Warning: Not all sections closed in lispwriter!\n"; + } +} + +void +LispWriter::writeComment(const std::string& comment) +{ + out << "; " << comment << "\n"; +} + +void +LispWriter::startList(const std::string& listname) +{ + indent(); + out << '(' << listname << '\n'; + indent_depth += 2; + + lists.push_back(listname); +} + +void +LispWriter::endList(const std::string& listname) +{ + if(lists.size() == 0) { + std::cerr << "Trying to close list '" << listname + << "', which is not open.\n"; + return; + } + if(lists.back() != listname) { + std::cerr << "Warning: trying to close list '" << listname + << "' while list '" << lists.back() << "' is open.\n"; + return; + } + lists.pop_back(); + + indent_depth -= 2; + indent(); + out << ")\n"; +} + +void +LispWriter::writeInt(const std::string& name, int value) +{ + indent(); + out << '(' << name << ' ' << value << ")\n"; +} + +void +LispWriter::writeFloat(const std::string& name, float value) +{ + indent(); + out << '(' << name << ' ' << value << ")\n"; +} + +void +LispWriter::writeString(const std::string& name, const std::string& value) +{ + indent(); + out << '(' << name << " \"" << value << "\")\n"; +} + +void +LispWriter::writeBool(const std::string& name, bool value) +{ + indent(); + out << '(' << name << ' ' << (value ? "#t" : "#f") << ")\n"; +} + +void +LispWriter::writeIntVector(const std::string& name, + const std::vector& value) +{ + indent(); + out << '(' << name; + for(std::vector::const_iterator i = value.begin(); i != value.end(); ++i) + out << " " << *i; + out << ")\n"; +} + +void +LispWriter::writeIntVector(const std::string& name, + const std::vector& value) +{ + indent(); + out << '(' << name; + for(std::vector::const_iterator i = value.begin(); i != value.end(); ++i) + out << " " << *i; + out << ")\n"; +} + +void +LispWriter::indent() +{ + for(int i = 0; i +#include + +class LispWriter +{ +public: + LispWriter(std::ostream& out); + ~LispWriter(); + + void writeComment(const std::string& comment); + + void startList(const std::string& listname); + + void writeInt(const std::string& name, int value); + void writeFloat(const std::string& name, float value); + void writeString(const std::string& name, const std::string& value); + void writeBool(const std::string& name, bool value); + void writeIntVector(const std::string& name, const std::vector& value); + void writeIntVector(const std::string& name, const std::vector& value); + // add more write-functions when needed... + + void endList(const std::string& listname); + +private: + void indent(); + + std::ostream& out; + int indent_depth; + std::vector lists; +}; + +#endif + diff --git a/src/serializable.h b/src/serializable.h new file mode 100644 index 000000000..ab6bebcf4 --- /dev/null +++ b/src/serializable.h @@ -0,0 +1,13 @@ +#ifndef __SERIALIZABLE_H__ +#define __SERIALIZABLE_H__ + +class LispWriter; + +class Serializable +{ +public: + virtual void write(LispWriter& writer) = 0; +}; + +#endif +