diff --git a/parser/Node.cc b/parser/Node.cc new file mode 100644 index 0000000..c4f5e9e --- /dev/null +++ b/parser/Node.cc @@ -0,0 +1,22 @@ + +#include "Node.h" +#include +#include "util/refptr.h" +using namespace std; + +void Node::addChildren(refptr other) +{ + if (other.isNull()) + return; + + for (vector< refptr >::const_iterator it = other->m_children.begin(); + it != other->m_children.end(); + it++) + { + addChild(*it); + } +} + +Node::~Node() +{ +} diff --git a/parser/Node.h b/parser/Node.h new file mode 100644 index 0000000..3d88e5c --- /dev/null +++ b/parser/Node.h @@ -0,0 +1,36 @@ + +#ifndef NODES_H +#define NODES_H NODES_H + +#include "util/refptr.h" +#include +#include + +class Node +{ + public: + virtual ~Node(); + void addChild(refptr child) { m_children.push_back(child); } + void addChildren(refptr other); + std::vector< refptr > & getChildren() { return m_children; } + + virtual std::string getString() { return ""; } + + protected: + std::vector< refptr > m_children; +}; + + +class StringNode : public Node +{ + public: + StringNode(const std::string & str) { m_string = str; } + std::string getString() + { + return m_string; + } + protected: + std::string m_string; +}; + +#endif diff --git a/util/refptr.h b/util/refptr.h index 7e6ecf8..af4b2a0 100644 --- a/util/refptr.h +++ b/util/refptr.h @@ -21,6 +21,14 @@ class refptr T & operator*() const; T * operator->() const; bool isNull() const { return m_ptr == NULL; } + bool operator==(const refptr & other) const + { + return m_ptr == other.m_ptr; + } + bool operator==(T * ptr) const + { + return m_ptr == ptr; + } private: void cloneFrom(const refptr & orig);