added parser/Node, operator==() to util/refptr

git-svn-id: svn://anubis/jtlc/trunk@8 f5bc74b8-7b62-4e90-9214-7121d538519f
This commit is contained in:
josh 2010-01-12 21:39:17 +00:00
parent c9c59e41fc
commit 798342ec0b
3 changed files with 66 additions and 0 deletions

22
parser/Node.cc Normal file
View File

@ -0,0 +1,22 @@
#include "Node.h"
#include <vector>
#include "util/refptr.h"
using namespace std;
void Node::addChildren(refptr<Node> other)
{
if (other.isNull())
return;
for (vector< refptr<Node> >::const_iterator it = other->m_children.begin();
it != other->m_children.end();
it++)
{
addChild(*it);
}
}
Node::~Node()
{
}

36
parser/Node.h Normal file
View File

@ -0,0 +1,36 @@
#ifndef NODES_H
#define NODES_H NODES_H
#include "util/refptr.h"
#include <vector>
#include <string>
class Node
{
public:
virtual ~Node();
void addChild(refptr<Node> child) { m_children.push_back(child); }
void addChildren(refptr<Node> other);
std::vector< refptr<Node> > & getChildren() { return m_children; }
virtual std::string getString() { return ""; }
protected:
std::vector< refptr<Node> > 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

View File

@ -21,6 +21,14 @@ class refptr
T & operator*() const; T & operator*() const;
T * operator->() const; T * operator->() const;
bool isNull() const { return m_ptr == NULL; } bool isNull() const { return m_ptr == NULL; }
bool operator==(const refptr<T> & other) const
{
return m_ptr == other.m_ptr;
}
bool operator==(T * ptr) const
{
return m_ptr == ptr;
}
private: private:
void cloneFrom(const refptr<T> & orig); void cloneFrom(const refptr<T> & orig);