feisty meow concerns codebase 2.140
path.cpp
Go to the documentation of this file.
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
23using namespace basis;
24using 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
29namespace nodes {
30
31class path_node_stack : public stack<node *>
32{
33public:
34 path_node_stack() : stack<node *>(0) {}
35};
36
38
39path::path(const node *start)
40: _stack(new path_node_stack)
41{ _stack->push(const_cast<node *>(start)); }
42
43path::path(const path &to_copy)
44: _stack(new path_node_stack(*to_copy._stack))
45{}
46
48{
49 while (_stack->elements()) _stack->pop();
50 WHACK(_stack);
51}
52
53node *path::operator [] (int index) const { return (*_stack)[index]; }
54
55int path::size() const { return _stack->size(); }
56
57node *path::root() const { return (*_stack)[0]; }
58
59node *path::current() const { return _stack->top(); }
60
61node *path::follow() const { return _stack->top(); }
62
63path &path::operator = (const path &to_copy)
64{
65 if (this == &to_copy) return *this;
66 *_stack = *to_copy._stack;
67 return *this;
68}
69
71{
72 node *to_return;
73 if (_stack->acquire_pop(to_return) != common::OKAY)
74 return NULL_POINTER;
75 return to_return;
76}
77
79{ return _stack->push(to_add); }
80
82{
83 if (!_stack->top()->get_link(index)) return common::NOT_FOUND;
84 return _stack->push(_stack->top()->get_link(index));
85}
86
87bool path::generate_path(node *to_locate, path &to_follow) const
88{
89 FUNCDEF("generate_path")
90
91if (to_locate || to_follow.current()) {}
92LOG("hmmm: path::generate_path is not implemented.");
93return false;
94}
95
96} // namespace.
97
#define LOG(s)
Outcomes describe the state of completion for an operation.
Definition outcome.h:31
An object representing the interstitial cell in most linked data structures.
Definition node.h:41
A method for tracing a route from a tree's root to a particular node.
Definition path.h:36
bool generate_path(node *to_locate, path &to_follow) const
finds the way to get from the root to the "to_locate" node.
Definition path.cpp:87
node * current() const
Definition path.cpp:59
path & operator=(const path &to_copy)
Definition path.cpp:63
node * root() const
returns the relative root node for this path.
Definition path.cpp:57
int size() const
returns the number of items in the path.
Definition path.cpp:55
node * follow() const
Returns the node specified by this path.
Definition path.cpp:61
path(const node *root)
the path is relative to the "root" node.
Definition path.cpp:39
basis::outcome push(node *to_add)
puts the node "to_add" on the top of the stack.
Definition path.cpp:78
node * operator[](int index) const
returns the node stored at "index", or NULL_POINTER if "index" is invalid.
Definition path.cpp:53
node * pop()
returns the top node on the path stack.
Definition path.cpp:70
An abstraction that represents a stack data structure.
Definition stack.h:30
#define NULL_POINTER
The value representing a pointer to nothing.
Definition definitions.h:32
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
Definition enhance_cpp.h:54
The guards collection helps in testing preconditions and reporting errors.
Definition array.h:30
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
Definition functions.h:121
A dynamic container class that holds any kind of object via pointers.
Definition amorph.h:55