4 /*****************************************************************************\
7 * Author : Chris Koeritz *
9 *******************************************************************************
10 * Copyright (c) 1992-$now By Author. This program is free software; you can *
11 * redistribute it and/or modify it under the terms of the GNU General Public *
12 * License as published by the Free Software Foundation; either version 2 of *
13 * the License or (at your option) any later version. This is online at: *
14 * http://www.fsf.org/copyleft/gpl.html *
15 * Please send any updates to: fred@gruntose.com *
16 \*****************************************************************************/
18 #include <basis/contracts.h>
19 #include <basis/enhance_cpp.h>
20 #include <basis/outcome.h>
26 class path_node_stack;
28 //! A method for tracing a route from a tree's root to a particular node.
30 A path has a starting point at a particular node and a list of links to
31 take from that node to another node. For the path to remain valid, none
32 of the links contained within it may be destroyed.
35 class path : public virtual basis::nameable
38 path(const node *root);
39 //!< the path is relative to the "root" node.
40 /*!< this will be the first object pushed onto the stack that we use
43 path(const path &to_copy);
47 DEFINE_CLASS_NAME("path");
49 path &operator =(const path &to_copy);
52 //!< returns the number of items in the path.
55 //!< returns the relative root node for this path.
57 node *current() const;
59 //!< Returns the node specified by this path.
60 /*!< if the path is not valid, NULL_POINTER is returned. */
63 //!< returns the top node on the path stack.
64 /*!< this returns the node at the farthest distance from the relative
65 root node and removes it from this path. */
67 basis::outcome push(node *to_add);
68 //!< puts the node "to_add" on the top of the stack.
69 /*!< adds a node to the path as long as "to_add" is one of the current
70 node's descendants. */
72 basis::outcome push(int index);
73 //!< indexed push uses the current top node's index'th link as new top.
74 /*!< adds the node at "index" of the current top node to the path,
75 providing that such a link number exists on the current node. */
77 bool generate_path(node *to_locate, path &to_follow) const;
78 //!< finds the way to get from the root to the "to_locate" node.
79 /*!< returns true if there is a path between the relative root of
80 this path and the node "to_locate". if there is such a path,
81 "to_follow" is set to one of the possible paths. */
83 node *operator [] (int index) const;
84 //!< returns the node stored at "index", or NULL_POINTER if "index" is invalid.
87 path_node_stack *_stack; //!< implementation of our pathway.