first check-in of feisty meow codebase. many things broken still due to recent
[feisty_meow.git] / core / library / nodes / path.cpp
1 /*****************************************************************************\
2 *                                                                             *
3 *  Name   : path                                                              *
4 *  Author : Chris Koeritz                                                     *
5 *                                                                             *
6 *******************************************************************************
7 * Copyright (c) 1992-$now By Author.  This program is free software; you can  *
8 * redistribute it and/or modify it under the terms of the GNU General Public  *
9 * License as published by the Free Software Foundation; either version 2 of   *
10 * the License or (at your option) any later version.  This is online at:      *
11 *     http://www.fsf.org/copyleft/gpl.html                                    *
12 * Please send any updates to: fred@gruntose.com                               *
13 \*****************************************************************************/
14
15 #include "node.h"
16 #include "path.h"
17
18 #include <basis/astring.h>
19 #include <structures/stack.h>
20
21 #include <stdio.h>
22
23 using namespace basis;
24 using namespace structures;
25
26 #undef LOG
27 #define LOG(to_print) printf("%s::%s: %s\n", static_class_name(), func, astring(to_print).s())
28
29 namespace nodes {
30
31 class path_node_stack : public stack<node *>
32 {
33 public:
34   path_node_stack() : stack<node *>(0) {}
35 };
36
37 //////////////
38
39 path::path(const node *start)
40 : _stack(new path_node_stack)
41 { _stack->push(const_cast<node *>(start)); }
42
43 path::path(const path &to_copy)
44 : _stack(new path_node_stack(*to_copy._stack))
45 {}
46
47 path::~path()
48 {
49   while (_stack->elements()) _stack->pop(); 
50   WHACK(_stack);
51 }
52
53 node *path::operator [] (int index) const { return (*_stack)[index]; }
54
55 int path::size() const { return _stack->size(); }
56
57 node *path::root() const { return (*_stack)[0]; }
58
59 node *path::current() const { return _stack->top(); }
60
61 node *path::follow() const { return _stack->top(); }
62
63 path &path::operator = (const path &to_copy)
64 {
65   if (this == &to_copy) return *this;
66   *_stack = *to_copy._stack;
67   return *this;
68 }
69
70 node *path::pop()
71 {
72   node *to_return;
73   if (_stack->acquire_pop(to_return) != common::OKAY)
74     return NIL;
75   return to_return;
76 }
77
78 outcome path::push(node *to_add)
79 { return _stack->push(to_add); }
80
81 outcome path::push(int index)
82 {
83   if (!_stack->top()->get_link(index)) return common::NOT_FOUND;
84   return _stack->push(_stack->top()->get_link(index));
85 }
86
87 bool path::generate_path(node *to_locate, path &to_follow) const
88 {
89   FUNCDEF("generate_path")
90
91 if (to_locate || to_follow.current()) {}
92 LOG("hmmm: path::generate_path is not implemented.");
93 return false;
94 }
95
96 } // namespace.
97