00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00035 #include "passiveprojectiontreenode.h"
00036
00037 PassiveProjectionTreeNode::PassiveProjectionTreeNode():
00038 parent(NULL), label(NULL) {
00039 }
00040
00041 PassiveProjectionTreeNode::PassiveProjectionTreeNode(PassiveProjectionTreeNode * _parent, PathStepExpression * _label):
00042 parent(_parent), label(_label) {
00043 }
00044
00045 PassiveProjectionTreeNode::~PassiveProjectionTreeNode() {
00046 for (unsigned i = 0; i < children.size(); i++) {
00047 delete children[i];
00048 }
00049 delete label;
00050 }
00051
00052 void PassiveProjectionTreeNode::registerPath(PathExpression * path,
00053 unsigned pos) {
00054
00055
00056 for (unsigned i = 0; i < children.size(); i++) {
00057 PathStepExpression *lc = children[i]->getLabel();
00058 PathStepExpression *lp = path->getPathStepAt(pos);
00059
00060 if (lc->isSyntacticallyEqualTo(lp)) {
00061 if (pos < path->getPathSize() - 1) {
00062 return children[i]->registerPath(path, ++pos);
00063 } else {
00064 return;
00065 }
00066 }
00067 }
00068
00069
00070 PassiveProjectionTreeNode *new_child = new PassiveProjectionTreeNode(this,
00071 path->
00072 getPathStepAt
00073 (pos)->
00074 clone
00075 ());
00076 children.push_back(new_child);
00077 if (pos < path->getPathSize() - 1) {
00078 new_child->registerPath(path, ++pos);
00079 }
00080 }
00081
00082 void PassiveProjectionTreeNode::print(OutputStream & dos) {
00083 print(dos, 0);
00084 dos << resetIndents();
00085 }
00086
00087 void PassiveProjectionTreeNode::print(OutputStream & dos, unsigned indents) {
00088 dos << resetIndents() << incrementIndents(indents);
00089 dos << writeIndents();
00090 if (!label) {
00091 dos << "/";
00092 } else {
00093 dos << *label;
00094 }
00095 dos << NEWLINE;
00096 for (unsigned i = 0; i < children.size(); i++) {
00097 children[i]->print(dos, indents + 1);
00098 }
00099 }