Merge branch 'master' of git+ssh://ares@repo.or.cz/srv/git/lispp
[lispp.git] / LispCons.h
blob219f47cbc663da00c6f50811e6fc7ccca8efc5d5
1 #if !defined(H_LISPCONS)
2 #define H_LISPCONS
4 #include "LispNil.h"
5 #include <utility>
7 namespace Lisp
9 class Cons;
11 class Cons : public Obj
13 public:
15 typedef Cons* ConsPtr;
16 typedef Cons& ConsRef;
18 Cons() :
19 value_(NIL::make(), NIL::make())
23 Cons(const Cons& other)
25 if (this != &other)
26 value_ = other.value_;
29 Obj::eObjectType Cons::getObjectType() const
31 return Obj::eConsObj;
35 Cons* make() const
37 return new Cons();
40 Cons* create() const
42 return new Cons();
46 Cons* clone() const
48 return new Cons(*this);
51 virtual void print(std::ostream& out) const
53 out << " ";
54 value_.first->print(out);
55 out << " . ";
56 value_.second->print(out);
57 out << " ";
60 bool operator==(const Obj* other)
62 bool result = false;
63 if (other->getObjectType() == eConsObj)
64 result = ( ( value_.first == dynamic_cast<const Cons*>(other)->value_.first ) &&
65 ( value_.second == dynamic_cast<const Cons*>(other)->value_.second ) );
66 return result;
69 Obj* car()
71 return value_.first;
74 Obj* cdr()
76 return value_.second;
79 private:
81 std::pair<Obj*, Obj*> value_;
85 #endif