123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118 |
- #ifndef _NODE_H
- #define _NODE_H
- #include "ptrlist.h"
- class Node {
- private:
- PtrList<Node> childlist;
- Node * parent;
- protected:
- #ifdef _DEBUG
- static int count;
- #endif
- public:
- Node(Node * myParent = NULL) : childlist(), parent(myParent) {
- #ifdef _DEBUG
- count++;
- #endif
- }
- Node(const Node & a) : childlist(a.childlist), parent(a.parent) {
- #ifdef _DEBUG
- count++;
- #endif
- }
- virtual ~Node() {
- #ifdef _DEBUG
- count--;
- #endif
- };
- int nodeCount() {
- #ifdef _DEBUG
- return count;
- #else
- return -1;
- #endif
- }
-
-
- int getNumChildren() const {
- return childlist.getNumItems();
- }
- Node * enumChild(int index) const {
- return childlist[index];
- }
- Node * getParent() const {
- return parent;
- }
-
-
- Node * addChild(Node * child) {
- child->setParent(this);
- return childlist.addItem(child);
- }
- Node * setParent(Node * myParent) {
- return parent = myParent;
- }
- PtrList< Node > & ChildList() {
- return childlist;
- }
- };
- template < class TPayload >
- class NodeC : public Node {
- protected:
- TPayload payload;
- public:
- NodeC( const TPayload & myPayload, NodeC * myParent = NULL ) : Node( myParent ), payload( myPayload ) {}
- NodeC( const NodeC & a ) : Node( a ), payload( a.payload ) {}
-
-
-
-
-
- TPayload & operator () ( void ) { return payload; }
-
- operator TPayload & ( void ) { return payload; }
- };
- #endif
|