lisp::Writer Class Reference

#include <writer.hpp>

List of all members.

Public Member Functions

 Writer (const std::string &filename)
 Writer (std::ostream *out)
 ~Writer ()
void write_comment (const std::string &comment)
void start_list (const std::string &listname, bool string=false)
void write (const std::string &name, int value)
void write (const std::string &name, float value)
void write (const std::string &name, const std::string &value, bool translatable=false)
void write (const std::string &name, const char *value, bool translatable=false)
void write (const std::string &name, bool value)
void write (const std::string &name, const std::vector< int > &value)
void write (const std::string &name, const std::vector< unsigned int > &value)
void write (const std::string &name, const std::vector< float > &value)
void write (const std::string &name, const std::vector< std::string > &value)
void end_list (const std::string &listname)

Private Member Functions

void write_escaped_string (const std::string &str)
void indent ()
 Writer (const Writer &)
Writeroperator= (const Writer &)

Private Attributes

std::ostream * out
bool out_owned
int indent_depth
std::vector< std::string > lists


Detailed Description

Definition at line 25 of file writer.hpp.


Constructor & Destructor Documentation

lisp::Writer::Writer ( const std::string &  filename  ) 

Definition at line 24 of file writer.cpp.

References indent_depth, out, and out_owned.

00024                                         :
00025   out(),
00026   out_owned(),
00027   indent_depth(),
00028   lists()
00029 {
00030   out = new OFileStream(filename);
00031   out_owned = true;
00032   indent_depth = 0;
00033   out->precision(10);
00034 }

lisp::Writer::Writer ( std::ostream *  out  ) 

Definition at line 36 of file writer.cpp.

References indent_depth, out, and out_owned.

00036                                  :
00037   out(),
00038   out_owned(),
00039   indent_depth(),
00040   lists()
00041 {
00042   out = newout;
00043   out_owned = false;
00044   indent_depth = 0;
00045   out->precision(10);
00046 }

lisp::Writer::~Writer (  ) 

Definition at line 48 of file writer.cpp.

References lists, log_warning, out, and out_owned.

00049 {
00050   if(lists.size() > 0) {
00051     log_warning << "Not all sections closed in lispwriter" << std::endl;
00052   }
00053   if(out_owned)
00054     delete out;
00055 }

lisp::Writer::Writer ( const Writer  )  [private]


Member Function Documentation

void lisp::Writer::write_comment ( const std::string &  comment  ) 

Definition at line 58 of file writer.cpp.

References out.

00059 {
00060   *out << "; " << comment << "\n";
00061 }

void lisp::Writer::start_list ( const std::string &  listname,
bool  string = false 
)

Definition at line 64 of file writer.cpp.

References indent(), indent_depth, lists, out, and write_escaped_string().

Referenced by Config::save(), scripting::save_squirrel_table(), World::save_state(), JoystickKeyboardController::write(), and Addon::write().

00065 {
00066   indent();
00067   *out << '(';
00068   if(string)
00069     write_escaped_string(listname);
00070   else
00071     *out << listname;
00072   *out << '\n';
00073   indent_depth += 2;
00074 
00075   lists.push_back(listname);
00076 }

void lisp::Writer::write ( const std::string &  name,
int  value 
)

Definition at line 97 of file writer.cpp.

References indent(), and out.

Referenced by Config::save(), scripting::save_squirrel_table(), World::save_state(), PlayerStatus::write(), write(), JoystickKeyboardController::write(), AddonManager::write(), and Addon::write().

00098 {
00099   indent();
00100   *out << '(' << name << ' ' << value << ")\n";
00101 }

void lisp::Writer::write ( const std::string &  name,
float  value 
)

Definition at line 104 of file writer.cpp.

References indent(), and out.

00105 {
00106   indent();
00107   *out << '(' << name << ' ' << value << ")\n";
00108 }

void lisp::Writer::write ( const std::string &  name,
const std::string &  value,
bool  translatable = false 
)

Definition at line 111 of file writer.cpp.

References indent(), out, and write_escaped_string().

00113 {
00114   indent();
00115   *out << '(' << name;
00116   if(translatable) {
00117     *out << " (_ ";
00118     write_escaped_string(value);
00119     *out << "))\n";
00120   } else {
00121     *out << " ";
00122     write_escaped_string(value);
00123     *out << ")\n";
00124   }
00125 }

void lisp::Writer::write ( const std::string &  name,
const char *  value,
bool  translatable = false 
) [inline]

Definition at line 40 of file writer.hpp.

References write().

00041                                         { write(name, static_cast<const std::string&>(value), translatable); }

void lisp::Writer::write ( const std::string &  name,
bool  value 
)

Definition at line 128 of file writer.cpp.

References indent(), and out.

00129 {
00130   indent();
00131   *out << '(' << name << ' ' << (value ? "#t" : "#f") << ")\n";
00132 }

void lisp::Writer::write ( const std::string &  name,
const std::vector< int > &  value 
)

Definition at line 135 of file writer.cpp.

References indent(), and out.

00137 {
00138   indent();
00139   *out << '(' << name;
00140   for(std::vector<int>::const_iterator i = value.begin(); i != value.end(); ++i)
00141     *out << " " << *i;
00142   *out << ")\n";
00143 }

void lisp::Writer::write ( const std::string &  name,
const std::vector< unsigned int > &  value 
)

Definition at line 146 of file writer.cpp.

References indent(), and out.

00148 {
00149   indent();
00150   *out << '(' << name;
00151   for(std::vector<unsigned int>::const_iterator i = value.begin(); i != value.end(); ++i)
00152     *out << " " << *i;
00153   *out << ")\n";
00154 }

void lisp::Writer::write ( const std::string &  name,
const std::vector< float > &  value 
)

Definition at line 157 of file writer.cpp.

References indent(), and out.

00159 {
00160   indent();
00161   *out << '(' << name;
00162   for(std::vector<float>::const_iterator i = value.begin(); i != value.end(); ++i)
00163     *out << " " << *i;
00164   *out << ")\n";
00165 }

void lisp::Writer::write ( const std::string &  name,
const std::vector< std::string > &  value 
)

Definition at line 168 of file writer.cpp.

References indent(), out, and write_escaped_string().

00170 {
00171   indent();
00172   *out << '(' << name;
00173   for(std::vector<std::string>::const_iterator i = value.begin(); i != value.end(); ++i) {
00174     *out << " ";
00175     write_escaped_string(*i);
00176   }
00177   *out << ")\n";
00178 }

void lisp::Writer::end_list ( const std::string &  listname  ) 

Definition at line 79 of file writer.cpp.

References indent(), indent_depth, lists, log_warning, and out.

Referenced by Config::save(), scripting::save_squirrel_table(), World::save_state(), JoystickKeyboardController::write(), and Addon::write().

00080 {
00081   if(lists.size() == 0) {
00082     log_warning << "Trying to close list '" << listname << "', which is not open" << std::endl;
00083     return;
00084   }
00085   if(lists.back() != listname) {
00086     log_warning << "trying to close list '" << listname << "' while list '" << lists.back() << "' is open" << std::endl;
00087     return;
00088   }
00089   lists.pop_back();
00090 
00091   indent_depth -= 2;
00092   indent();
00093   *out << ")\n";
00094 }

void lisp::Writer::write_escaped_string ( const std::string &  str  )  [private]

Definition at line 181 of file writer.cpp.

References out.

Referenced by start_list(), and write().

00182 {
00183   *out << '"';
00184   for(const char* c = str.c_str(); *c != 0; ++c) {
00185     if(*c == '\"')
00186       *out << "\\\"";
00187     else if(*c == '\\')
00188       *out << "\\\\";
00189     else
00190       *out << *c;
00191   }
00192   *out << '"';
00193 }

void lisp::Writer::indent (  )  [private]

Definition at line 196 of file writer.cpp.

References indent_depth, and out.

Referenced by end_list(), start_list(), and write().

00197 {
00198   for(int i = 0; i<indent_depth; ++i)
00199     *out << ' ';
00200 }

Writer& lisp::Writer::operator= ( const Writer  )  [private]


Member Data Documentation

std::ostream* lisp::Writer::out [private]

Definition at line 56 of file writer.hpp.

Referenced by end_list(), indent(), start_list(), write(), write_comment(), write_escaped_string(), Writer(), and ~Writer().

bool lisp::Writer::out_owned [private]

Definition at line 57 of file writer.hpp.

Referenced by Writer(), and ~Writer().

int lisp::Writer::indent_depth [private]

Definition at line 58 of file writer.hpp.

Referenced by end_list(), indent(), start_list(), and Writer().

std::vector<std::string> lisp::Writer::lists [private]

Definition at line 59 of file writer.hpp.

Referenced by end_list(), start_list(), and ~Writer().


The documentation for this class was generated from the following files:
Generated on Mon Jun 9 03:38:38 2014 for SuperTux by  doxygen 1.5.1