27 #define LOG(s) CLASS_EMERGENCY_LOG(program_wide_logger::get(), astring(s) + a_sprintf(" [obj=%p]", this))
30 using namespace basis;
37 class symbol_tree_associations :
public symbol_table<symbol_tree *>
40 symbol_tree_associations(
int estimated_elements)
42 virtual ~symbol_tree_associations() {
52 symbol_tree::symbol_tree(
const astring &node_name,
int estimated_elements)
54 _associations(new symbol_tree_associations(estimated_elements)),
63 #ifdef DEBUG_SYMBOL_TREE
64 LOG(
"symtree dtor: prior to whacks");
67 #ifdef DEBUG_SYMBOL_TREE
68 LOG(
"symtree dtor: after whacking associations");
71 #ifdef DEBUG_SYMBOL_TREE
72 LOG(
"symtree dtor: after all whacks");
89 #ifdef DEBUG_SYMBOL_TREE
94 _associations->add(to_add->
name(), to_add);
100 #ifdef DEBUG_SYMBOL_TREE
105 #ifdef DEBUG_SYMBOL_TREE
108 int found =
which(to_zap);
109 if (
negative(found))
return common::NOT_FOUND;
110 #ifdef DEBUG_SYMBOL_TREE
111 int kids = _associations->symbols();
113 _associations->whack(to_zap->
name());
114 #ifdef DEBUG_SYMBOL_TREE
115 if (kids - 1 != _associations->symbols())
116 throw(
"error: symbol_tree::prune: failed to crop kid in symtab");
119 #ifdef DEBUG_SYMBOL_TREE
120 LOG(
"skip symtree prune steps due to null symtree after dynamic cast.");
124 #ifdef DEBUG_SYMBOL_TREE
125 LOG(
"about to call base tree::prune...");
128 #ifdef DEBUG_SYMBOL_TREE
129 LOG(
"after called base tree::prune.");
143 for (gap = n / 2; gap > 0; gap /= 2) {
144 for (i = gap; i < n; i++) {
162 #ifdef DEBUG_SYMBOL_TREE
166 #ifdef DEBUG_SYMBOL_TREE
167 LOG(
astring(
"finding node called ") + to_find);
170 if (comp(
name(), to_find))
return this;
176 return our_parent->
find(to_find, how, comp);
180 symbol_tree **found = _associations->find(to_find, comp);
181 #ifdef DEBUG_SYMBOL_TREE
182 if (!found)
LOG(to_find +
" was not found.")
183 else LOG(to_find +
" was found successfully.");
189 for (
int i = 0; i <
branches(); i++) {
193 #ifdef DEBUG_SYMBOL_TREE
197 answer = curr->
find(to_find, how, comp);
210 astring indent = string_manipulation::indentation( (depth - 1) * 2);
211 if (!depth)
return "";
212 else if (!kids)
return indent +
"|--";
213 else return indent +
"+--";
218 #ifdef DEBUG_SYMBOL_TREE
235 #ifdef DEBUG_SYMBOL_TREE
236 LOG(
"logic error: unknown type in symbol tree.");
242 if (!ted.
size()) name_to_log =
"";
243 #ifdef DEBUG_SYMBOL_TREE
248 to_return += name_to_log;
249 to_return += parser_bits::platform_eol_to_chars();
a_sprintf is a specialization of astring that provides printf style support.
Provides a dynamically resizable ASCII character string.
const char * s() const
synonym for observe. the 's' stands for "string", if that helps.
Outcomes describe the state of completion for an operation.
int size() const
returns the number of items in the path.
A symbol table that supports scope nesting and/or trees of symbol tables.
void sort()
sorts the sub-nodes of this symbol_tree.
basis::astring text_form() const
traverses the tree to build a textual list of the nodes.
virtual basis::outcome prune(tree *to_zap)
removes a sub-tree "to_zap".
void hash_appropriately(int estimated_elements)
resizes the hashing parameter to limit bucket sizes.
bool add(symbol_tree *to_add)
adds a child to this symbol_tree.
symbol_tree * find(const basis::astring &to_find, find_methods how, basis::string_comparator_function *comp=NULL_POINTER)
returns the node specified by "to_find" or NULL_POINTER.
const basis::astring & name() const
returns the name of this node.
virtual ~symbol_tree()
all child nodes will be deleted too.
symbol_tree * branch(int index) const
returns the "index"th branch.
void rehash(int estimated_elements)
resizes the underlying symbol_table for this node.
int estimated_elements() const
returns the number of bits in this node's table.
int children() const
returns the number of children of this node.
tree * next()
Returns a pointer to the next tree in the direction of traversal.
A dynamically linked tree with an arbitrary number of branches.
virtual int depth() const
Returns the distance of "this" from the root. The root's depth is 0.
virtual void insert(int branch_place, tree *new_branch)
inserts "new_branch" before the branches starting at "branch_place".
virtual basis::outcome prune_index(int branch_to_cut)
Removes the branch at the specified index from this tree.
virtual int which(tree *branch_to_find) const
Returns the branch number for a particular branch in this tree.
virtual int branches() const
Returns the number of branches currently connected to this tree.
virtual void attach(tree *new_branch)
Attaches the specified branch to the current tree.
virtual basis::outcome prune(tree *branch_to_cut)
Removes the specified branch from this tree.
virtual tree * parent() const
Returns the tree node that is the immediate ancestor of this one.
iterator start(traversal_directions direction) const
Returns a fresh iterator positioned at this tree node.
virtual tree * branch(int branch_number) const
Returns the specified branch of this tree.
Maintains a list of names, where each name has a type and some contents.
#define NULL_POINTER
The value representing a pointer to nothing.
#define FUNCDEF(func_in)
FUNCDEF sets the name of a function (and plugs it into the callstack).
The guards collection helps in testing preconditions and reporting errors.
void WHACK(contents *&ptr)
deletion with clearing of the pointer.
bool string_comparator_function(const astring &a, const astring &b)
returns true if the strings "a" and "b" are considered equal.
bool negative(const type &a)
negative returns true if "a" is less than zero.
bool astring_comparator(const astring &a, const astring &b)
implements a string comparator that just does simple astring ==.
A logger that sends to the console screen using the standard output device.
astring hier_prefix(int depth, int kids)
A dynamic container class that holds any kind of object via pointers.