feisty meow concerns codebase  2.140
nodes::packable_tree Class Reference

A tree object that can be packed into an array of bytes and unpacked again. More...

#include <packable_tree.h>

Inheritance diagram for nodes::packable_tree:
Collaboration diagram for nodes::packable_tree:

Public Member Functions

 packable_tree ()
 constructs a new tree with a root and zero branches. More...
 
int recursive_packed_size () const
 spiders the tree starting at this node to calculate the packed size. More...
 
void recursive_pack (basis::byte_array &packed_form) const
 packs the whole tree starting at this node into the packed form. More...
 
- Public Member Functions inherited from nodes::tree
 tree ()
 constructs a new tree with a root and zero branches. More...
 
virtual ~tree ()
 destroys the tree by recursively destroying all child tree nodes. More...
 
 DEFINE_CLASS_NAME ("tree")
 
virtual treebranch (int branch_number) const
 Returns the specified branch of this tree. More...
 
virtual int which (tree *branch_to_find) const
 Returns the branch number for a particular branch in this tree. More...
 
virtual int branches () const
 Returns the number of branches currently connected to this tree. More...
 
virtual treeparent () const
 Returns the tree node that is the immediate ancestor of this one. More...
 
virtual treeroot () const
 Locates and returns the absolute root of the tree containing this tree. More...
 
virtual int depth () const
 Returns the distance of "this" from the root. The root's depth is 0. More...
 
virtual void attach (tree *new_branch)
 Attaches the specified branch to the current tree. More...
 
virtual void insert (int branch_place, tree *new_branch)
 inserts "new_branch" before the branches starting at "branch_place". More...
 
virtual basis::outcome prune (tree *branch_to_cut)
 Removes the specified branch from this tree. More...
 
virtual basis::outcome prune_index (int branch_to_cut)
 Removes the branch at the specified index from this tree. More...
 
iterator start (traversal_directions direction) const
 Returns a fresh iterator positioned at this tree node. More...
 
virtual bool generate_path (path &to_follow) const
 Returns the path to "this" path_tree from its root. More...
 
- Public Member Functions inherited from nodes::node
 node (int number_of_links=0)
 the constructor provides for "number_of_links" links initially. More...
 
virtual ~node ()
 the destructor simply invalidates the node. More...
 
int links () const
 Returns the number of links the node currently holds. More...
 
void set_link (int link_number, node *new_link)
 Connects the node "new_link" to this node. More...
 
nodeget_link (int link_number) const
 Returns the node that is connected to the specified "link_number". More...
 
void zap_link (int link_number)
 the specified link is removed from the node. More...
 
void insert_link (int where, node *to_add=NULL_POINTER)
 adds a new link prior to the position specified in "where". More...
 
int which (node *to_find) const
 locates the index where "to_find" lives in our list of links. More...
 
- Public Member Functions inherited from basis::packable
virtual void pack (byte_array &packed_form) const =0
 Creates a packed form of the packable object in "packed_form". More...
 
virtual bool unpack (byte_array &packed_form)=0
 Restores the packable from the "packed_form". More...
 
virtual int packed_size () const =0
 Estimates the space needed for the packed structure. More...
 

Static Public Member Functions

static packable_treerecursive_unpack (basis::byte_array &packed_form, packable_tree_factory &creator)
 unpacks a tree stored in "packed_form" and returns it. More...
 

Additional Inherited Members

- Public Types inherited from nodes::tree
enum  traversal_directions {
  prefix , infix , postfix , to_branches ,
  reverse_branches
}
 
enum  elevator_directions { TOWARD_ROOT , AWAY_FROM_ROOT }
 

Detailed Description

A tree object that can be packed into an array of bytes and unpacked again.

Definition at line 29 of file packable_tree.h.

Constructor & Destructor Documentation

◆ packable_tree()

nodes::packable_tree::packable_tree ( )

constructs a new tree with a root and zero branches.

Definition at line 81 of file packable_tree.cpp.

Member Function Documentation

◆ recursive_pack()

void nodes::packable_tree::recursive_pack ( basis::byte_array packed_form) const

packs the whole tree starting at this node into the packed form.

Definition at line 142 of file packable_tree.cpp.

References nodes::FINISH, NULL_POINTER, nodes::tree::postfix, and nodes::tree::start().

Referenced by filesystem::directory_tree::pack().

◆ recursive_packed_size()

int nodes::packable_tree::recursive_packed_size ( ) const

spiders the tree starting at this node to calculate the packed size.

Definition at line 131 of file packable_tree.cpp.

References NULL_POINTER, nodes::tree::postfix, and nodes::tree::start().

Referenced by filesystem::directory_tree::packed_size().

◆ recursive_unpack()

packable_tree * nodes::packable_tree::recursive_unpack ( basis::byte_array packed_form,
packable_tree_factory creator 
)
static

unpacks a tree stored in "packed_form" and returns it.

if NULL_POINTER is returned, then the unpack failed. the "creator" is needed for making new derived packable_tree objects of the type stored.

Definition at line 156 of file packable_tree.cpp.

References structures::stack< contents >::acquire_pop(), nodes::tree::attach(), nodes::ATTACH_BRANCHES, nodes::BRANCHES_FOLLOW, nodes::packable_tree_factory::create(), nodes::FINISH, NULL_POINTER, structures::stack< contents >::push(), structures::stack< contents >::size(), basis::packable::unpack(), and basis::WHACK().


The documentation for this class was generated from the following files: