Back to index

supertuxkart  0.5+dfsg1
Public Types | Public Member Functions | Private Member Functions | Private Attributes | Friends
lisp::Lisp Class Reference

#include <lisp.hpp>

List of all members.

Public Types

enum  LispType {
  TYPE_CONS, TYPE_SYMBOL, TYPE_INTEGER, TYPE_STRING,
  TYPE_REAL, TYPE_BOOLEAN
}

Public Member Functions

 ~Lisp ()
LispType getType () const
const LispgetCar () const
const LispgetCdr () const
bool get (std::string &val) const
bool get (int &val) const
bool get (float &val) const
bool get (bool &val) const
template<class T >
bool get (const char *name, T &val) const
bool get (const char *name, sgVec4 &val) const
bool get (const char *name, sgVec3 &val) const
template<class T >
bool getVector (const char *name, std::vector< T > &vec) const
const LispgetLisp (const char *name) const
const LispgetLisp (const std::string &name) const
void print (int indent=0) const

Private Member Functions

 Lisp (LispType newtype)

Private Attributes

LispType m_type
union {
   struct {
Lispm_car
Lispm_cdr
   } m_cons
char * m_string
int m_integer
bool m_boolean
float m_real
m_v

Friends

class Parser

Detailed Description

Definition at line 30 of file lisp.hpp.


Member Enumeration Documentation

Enumerator:
TYPE_CONS 
TYPE_SYMBOL 
TYPE_INTEGER 
TYPE_STRING 
TYPE_REAL 
TYPE_BOOLEAN 

Definition at line 35 of file lisp.hpp.


Constructor & Destructor Documentation

Definition at line 31 of file lisp.cpp.

    {
        if(m_type == TYPE_SYMBOL || m_type == TYPE_STRING)
            delete[] m_v.m_string;
        if(m_type == TYPE_CONS)
        {
            delete m_v.m_cons.m_cdr;
            delete m_v.m_cons.m_car;
        }
    }
lisp::Lisp::Lisp ( LispType  newtype) [private]

Definition at line 25 of file lisp.cpp.

            : m_type(newtype)
    {}

Member Function Documentation

bool lisp::Lisp::get ( std::string &  val) const [inline]

Definition at line 52 of file lisp.hpp.

            {
                if(m_type != TYPE_STRING && m_type != TYPE_SYMBOL)
                    return false;
                val = m_v.m_string;
                return true;
            }

Here is the caller graph for this function:

bool lisp::Lisp::get ( int &  val) const [inline]

Definition at line 59 of file lisp.hpp.

            {
                if(m_type != TYPE_INTEGER)
                    return false;
                val = m_v.m_integer;
                return true;
            }
bool lisp::Lisp::get ( float &  val) const [inline]

Definition at line 66 of file lisp.hpp.

            {
                if(m_type != TYPE_REAL && m_type != TYPE_INTEGER)
                    return false;
                val = m_type==TYPE_REAL ? m_v.m_real : m_v.m_integer;
                return true;
            }
bool lisp::Lisp::get ( bool &  val) const [inline]

Definition at line 73 of file lisp.hpp.

            {
                if(m_type != TYPE_BOOLEAN)
                    return false;
                val = m_v.m_boolean;
                return true;
            }
template<class T >
bool lisp::Lisp::get ( const char *  name,
T &  val 
) const [inline]

Definition at line 90 of file lisp.hpp.

            {
                const Lisp* lisp = getLisp(name);
                if(!lisp)
                    return false;

                lisp = lisp->getCdr();
                if(!lisp)
                    return false;
                lisp = lisp->getCar();
                if(!lisp)
                    return false;
                return lisp->get(val);
            }

Here is the call graph for this function:

bool lisp::Lisp::get ( const char *  name,
sgVec4 &  val 
) const [inline]

Definition at line 104 of file lisp.hpp.

            {
                const Lisp* lisp = getLisp(name);
                if(!lisp)
                    return false;

                lisp = lisp->getCdr();
                if(!lisp)
                    return false;
                for(int i = 0; i < 4 && lisp; ++i)
                {
                    const Lisp* m_car = lisp->getCar();
                    if(!m_car)
                        return false;
                    m_car->get(val[i]);
                    lisp = lisp->getCdr();
                }
                return true;
            }

Here is the call graph for this function:

bool lisp::Lisp::get ( const char *  name,
sgVec3 &  val 
) const [inline]

Definition at line 123 of file lisp.hpp.

            {
                const Lisp* lisp = getLisp(name);
                if(!lisp)
                    return false;

                lisp = lisp->getCdr();
                if(!lisp)
                    return false;
                for(int i = 0; i < 3 && lisp; ++i)
                {
                    const Lisp* m_car = lisp->getCar();
                    if(!m_car)
                        return false;
                    m_car->get(val[i]);
                    lisp = lisp->getCdr();
                }
                return true;
            }

Here is the call graph for this function:

const Lisp* lisp::Lisp::getCar ( ) const [inline]

Definition at line 48 of file lisp.hpp.

            { return m_v.m_cons.m_car; }

Here is the caller graph for this function:

const Lisp* lisp::Lisp::getCdr ( ) const [inline]

Definition at line 50 of file lisp.hpp.

            { return m_v.m_cons.m_cdr; }

Here is the caller graph for this function:

const Lisp * lisp::Lisp::getLisp ( const char *  name) const

Definition at line 45 of file lisp.cpp.

    {
        const Lisp* P;

        for(P = getCdr(); P != 0; P = P->getCdr())
        {
            const Lisp* CHILD = P->getCar();
            // Also ignore if the child is not a CONS type, i.e.
            // a TYPE_INTEGER is found, for which car is not defined!
            if(!CHILD || CHILD->m_type!=TYPE_CONS) 
                continue;
            if(!CHILD->getCar())
                continue;
            std::string CHILDName;
            if(!CHILD->getCar()->get(CHILDName))
                continue;
            if(CHILDName == name)
                return CHILD;
        }

        return 0;
    }

Here is the call graph for this function:

Here is the caller graph for this function:

const Lisp* lisp::Lisp::getLisp ( const std::string &  name) const [inline]

Definition at line 165 of file lisp.hpp.

            { return getLisp(name.c_str()); }

Here is the call graph for this function:

Here is the caller graph for this function:

LispType lisp::Lisp::getType ( ) const [inline]

Definition at line 45 of file lisp.hpp.

            { return m_type; }

Here is the caller graph for this function:

template<class T >
bool lisp::Lisp::getVector ( const char *  name,
std::vector< T > &  vec 
) const [inline]

Definition at line 144 of file lisp.hpp.

        {
            const Lisp* child = getLisp(name);
            if(!child)
                return false;

            for(child = child->getCdr(); child != 0; child = child->getCdr())
            {
                T val;
                if(!child->getCar())
                    continue;
                if(child->getCar()->get(val))
                {
                    vec.insert(vec.begin(),val);
                }
            }

            return true;
        }

Here is the call graph for this function:

Here is the caller graph for this function:

void lisp::Lisp::print ( int  indent = 0) const

Definition at line 73 of file lisp.cpp.

    {
        if(m_type == TYPE_CONS)
        {
            printf("(");
            if(m_v.m_cons.m_car)
                m_v.m_cons.m_car->print();
            if(m_v.m_cons.m_cdr)
            {
                printf(",");
                if(m_v.m_cons.m_cdr)
                    m_v.m_cons.m_cdr->print();
            }
            printf(")");
        }
        if(m_type == TYPE_STRING)
        {
            printf("'%s' ", m_v.m_string);
        }
        if(m_type == TYPE_INTEGER)
        {
            printf("%d", m_v.m_integer);
        }
        if(m_type == TYPE_REAL)
        {
            printf("%f", m_v.m_real);
        }
        if(m_type == TYPE_SYMBOL)
        {
            printf("%s ", m_v.m_string);
        }
    }

Friends And Related Function Documentation

friend class Parser [friend]

Definition at line 172 of file lisp.hpp.


Member Data Documentation

Definition at line 175 of file lisp.hpp.

union { ... } lisp::Lisp::m_v [private]

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