00001 #ifndef PATH_IMPLEMENTATION_FILE 00002 #define PATH_IMPLEMENTATION_FILE 00003 00004 /*****************************************************************************\ 00005 * * 00006 * Name : path * 00007 * Author : Chris Koeritz * 00008 * * 00009 ******************************************************************************* 00010 * Copyright (c) 1992-$now By Author. This program is free software; you can * 00011 * redistribute it and/or modify it under the terms of the GNU General Public * 00012 * License as published by the Free Software Foundation; either version 2 of * 00013 * the License or (at your option) any later version. This is online at: * 00014 * http://www.fsf.org/copyleft/gpl.html * 00015 * Please send any updates to: fred@gruntose.com * 00016 \*****************************************************************************/ 00017 00018 #include "node.h" 00019 #include "path.h" 00020 00021 #include <basis/log_base.h> 00022 #include <data_struct/stack.cpp> 00023 00024 namespace nodes { 00025 00026 class path_node_stack : public stack<node *> 00027 { 00028 public: 00029 path_node_stack() : stack<node *>(0) {} 00030 }; 00031 00033 00034 path::path(const node *start) 00035 : _stack(new path_node_stack) 00036 { _stack->push(const_cast<node *>(start)); } 00037 00038 path::path(const path &to_copy) 00039 : _stack(new path_node_stack(*to_copy._stack)) 00040 {} 00041 00042 path::~path() 00043 { 00044 while (_stack->elements()) _stack->pop(); 00045 WHACK(_stack); 00046 } 00047 00048 node *path::operator [] (int index) const { return (*_stack)[index]; } 00049 00050 int path::size() const { return _stack->size(); } 00051 00052 node *path::root() const { return (*_stack)[0]; } 00053 00054 node *path::current() const { return _stack->top(); } 00055 00056 node *path::follow() const { return _stack->top(); } 00057 00058 path &path::operator = (const path &to_copy) 00059 { 00060 if (this == &to_copy) return *this; 00061 *_stack = *to_copy._stack; 00062 return *this; 00063 } 00064 00065 node *path::pop() 00066 { 00067 node *to_return; 00068 if (_stack->acquire_pop(to_return) != common::OKAY) 00069 return NIL; 00070 return to_return; 00071 } 00072 00073 outcome path::push(node *to_add) 00074 { return _stack->push(to_add); } 00075 00076 outcome path::push(int index) 00077 { 00078 if (!_stack->top()->get_link(index)) return common::NOT_FOUND; 00079 return _stack->push(_stack->top()->get_link(index)); 00080 } 00081 00082 bool path::generate_path(node *to_locate, path &to_follow) const 00083 { 00084 if (to_locate || to_follow.current()) {} 00085 program_wide_logger().log("hmmm: path::generate_path is not implemented."); 00086 return false; 00087 } 00088 00089 } // namespace. 00090 00091 #endif //PATH_IMPLEMENTATION_FILE 00092
1.5.1