Back to index

supertuxkart  0.5+dfsg1
Public Member Functions | Private Member Functions | Private Attributes
lisp::Writer Class Reference

#include <writer.hpp>

Collaboration diagram for lisp::Writer:
Collaboration graph
[legend]

List of all members.

Public Member Functions

 Writer (const std::string &filename)
 Writer (std::ostream &out)
 ~Writer ()
void writeComment (const std::string &comment)
void beginList (const std::string &listname)
void write (const std::string &name, int value)
void write (const std::string &name, unsigned int value)
void write (const std::string &name, float value)
void write (const std::string &name, const std::string &value)
void write (const std::string &name, const char *value)
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< std::string > &value)
void endList (const std::string &listname)

Private Member Functions

void indent ()

Private Attributes

bool m_owner
std::ostream * m_out
int m_indent_depth
std::vector< std::string > m_lists

Detailed Description

Definition at line 30 of file writer.hpp.


Constructor & Destructor Documentation

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

Definition at line 34 of file writer.cpp.

            : m_indent_depth(0)
    {
        m_owner = true;
#ifdef WIN32
       // With mingw, the files are written dos style (crlf), but
       // these files can't be read with the lexer here. So we have
       // to force the file to be written as binary for windows.
        m_out = new std::ofstream(filename.c_str(),::std::ios_base::binary);
#else
        m_out = new std::ofstream(filename.c_str());
#endif
        if(!m_out->good())
        {
            char msg[MAX_ERROR_MESSAGE_LENGTH];
            snprintf(msg, sizeof(msg), 
                     "LispWriter Error: Couldn't open file '%s' for writing.",
                     filename.c_str());
            throw std::runtime_error(msg);
        }
    }
lisp::Writer::Writer ( std::ostream &  out)

Definition at line 58 of file writer.cpp.

            : m_indent_depth(0)
    {
        m_owner = false;
        m_out = &newout;
    }

Definition at line 67 of file writer.cpp.

    {
        if(m_lists.size() > 0)
        {
            std::cerr << "Warning: Not all sections closed in lispwriter!\n";
        }

        if(m_owner)
            delete m_out;
    }

Member Function Documentation

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

Definition at line 90 of file writer.cpp.

    {
        indent();
        *m_out << '(' << listname << '\n';
        m_indent_depth += 2;

        m_lists.push_back(listname);
    }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 102 of file writer.cpp.

    {
        if(m_lists.size() == 0)
        {
            fprintf(stderr, "Trying to close list '%s, which is not open.\n",
                    listname.c_str());
            return;
        }
        if(m_lists.back() != listname)
        {
            fprintf(stderr, 
                    "Warning: trying to close list '%s' while list '%s' is open.\n",
                    listname.c_str(),  m_lists.back().c_str());
            return;
        }
        m_lists.pop_back();

        m_indent_depth -= 2;
        indent();
        *m_out << ")\n";
    }

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 208 of file writer.cpp.

    {
        for(int i = 0; i<m_indent_depth; ++i)
            *m_out << ' ';
    }

Here is the caller graph for this function:

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

Definition at line 127 of file writer.cpp.

    {
        indent();
        *m_out << '(' << name << ' ' << value << ")\n";
    }

Here is the call graph for this function:

Here is the caller graph for this function:

void lisp::Writer::write ( const std::string &  name,
unsigned int  value 
) [inline]

Definition at line 42 of file writer.hpp.

{write(name, (int)value);}

Here is the call graph for this function:

Here is the caller graph for this function:

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

Definition at line 136 of file writer.cpp.

    {
        indent();
        *m_out << '(' << name << ' ' << value << ")\n";
    }

Here is the call graph for this function:

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

Definition at line 145 of file writer.cpp.

    {
        indent();
        *m_out << '(' << name << " \"" << value << "\")\n";
    }

Here is the call graph for this function:

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

Definition at line 154 of file writer.cpp.

    {
        indent();
        *m_out << '(' << name << " \"" << value << "\")\n";
    }

Here is the call graph for this function:

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

Definition at line 163 of file writer.cpp.

    {
        indent();
        *m_out << '(' << name << ' ' << (value ? "#t" : "#f") << ")\n";
    }

Here is the call graph for this function:

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

Definition at line 172 of file writer.cpp.

    {
        indent();
        *m_out << '(' << name;
        for(std::vector<int>::const_iterator i = value.begin(); i != value.end(); ++i)
            *m_out << " " << *i;
        *m_out << ")\n";
    }

Here is the call graph for this function:

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

Definition at line 184 of file writer.cpp.

    {
        indent();
        *m_out << '(' << name;
        for(std::vector<unsigned int>::const_iterator i = value.begin(); i != value.end(); ++i)
            *m_out << " " << *i;
        *m_out << ")\n";
    }

Here is the call graph for this function:

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

Definition at line 196 of file writer.cpp.

    {
        indent();
        *m_out << '(' << name;
        for(std::vector<std::string>::const_iterator i = value.begin(); i != value.end(); ++i)
            *m_out << " " << "\"" << *i << "\"";
        *m_out << ")\n";
    }

Here is the call graph for this function:

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

Definition at line 81 of file writer.cpp.

    {
        indent();
        *m_out << "; " << comment << "\n";
    }

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 59 of file writer.hpp.

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

Definition at line 60 of file writer.hpp.

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

Definition at line 58 of file writer.hpp.

bool lisp::Writer::m_owner [private]

Definition at line 57 of file writer.hpp.


The documentation for this class was generated from the following files: