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 
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 
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 
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 
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 
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 
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:57
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
string path
Definition: eml_to_txt.py:139
A dynamic container class that holds any kind of object via pointers.
Definition: amorph.h:55
#define LOG(to_print)
Definition: path.cpp:27