path.cpp
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #include "node.h"
00016 #include "path.h"
00017
00018 #include <basis/astring.h>
00019 #include <structures/stack.h>
00020
00021 #include <stdio.h>
00022
00023 using namespace basis;
00024 using namespace structures;
00025
00026 #undef LOG
00027 #define LOG(to_print) printf("%s::%s: %s\n", static_class_name(), func, astring(to_print).s())
00028
00029 namespace nodes {
00030
00031 class path_node_stack : public stack<node *>
00032 {
00033 public:
00034 path_node_stack() : stack<node *>(0) {}
00035 };
00036
00038
00039 path::path(const node *start)
00040 : _stack(new path_node_stack)
00041 { _stack->push(const_cast<node *>(start)); }
00042
00043 path::path(const path &to_copy)
00044 : _stack(new path_node_stack(*to_copy._stack))
00045 {}
00046
00047 path::~path()
00048 {
00049 while (_stack->elements()) _stack->pop();
00050 WHACK(_stack);
00051 }
00052
00053 node *path::operator [] (int index) const { return (*_stack)[index]; }
00054
00055 int path::size() const { return _stack->size(); }
00056
00057 node *path::root() const { return (*_stack)[0]; }
00058
00059 node *path::current() const { return _stack->top(); }
00060
00061 node *path::follow() const { return _stack->top(); }
00062
00063 path &path::operator = (const path &to_copy)
00064 {
00065 if (this == &to_copy) return *this;
00066 *_stack = *to_copy._stack;
00067 return *this;
00068 }
00069
00070 node *path::pop()
00071 {
00072 node *to_return;
00073 if (_stack->acquire_pop(to_return) != common::OKAY)
00074 return NIL;
00075 return to_return;
00076 }
00077
00078 outcome path::push(node *to_add)
00079 { return _stack->push(to_add); }
00080
00081 outcome path::push(int index)
00082 {
00083 if (!_stack->top()->get_link(index)) return common::NOT_FOUND;
00084 return _stack->push(_stack->top()->get_link(index));
00085 }
00086
00087 bool path::generate_path(node *to_locate, path &to_follow) const
00088 {
00089 FUNCDEF("generate_path")
00090
00091 if (to_locate || to_follow.current()) {}
00092 LOG("hmmm: path::generate_path is not implemented.");
00093 return false;
00094 }
00095
00096 }
00097