feisty meow concerns codebase 2.140
packable_tree.h
Go to the documentation of this file.
1#ifndef PACKABLE_TREE_CLASS
2#define PACKABLE_TREE_CLASS
3
4/*****************************************************************************\
5* *
6* Name : packable_tree *
7* Author : Chris Koeritz *
8* *
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\*****************************************************************************/
17
18#include "tree.h"
19
20#include <basis/byte_array.h>
21
22namespace nodes {
23
24// forward.
25class packable_tree_factory;
26
28
29class packable_tree : public tree, public virtual basis::packable
30{
31public:
34
35 // the recursive packing methods here will operate on all nodes starting at this one
36 // and moving downwards to all branches.
37
38 int recursive_packed_size() const;
40
41 void recursive_pack(basis::byte_array &packed_form) const;
43
45 packable_tree_factory &creator);
47
50 // standard pack, unpack and packed_size methods must be implemented by the derived tree.
51
52private:
53 static void packit(basis::byte_array &packed_form, const packable_tree *current_node);
55 static void calcit(int &size_accumulator, const packable_tree *current_node);
57};
58
60
62{
63public:
64 virtual ~packable_tree_factory();
65 virtual packable_tree *create() = 0;
67
69};
70
71} // namespace.
72
73#endif
74
A very common template for a dynamic array of bytes.
Definition byte_array.h:36
A base class for objects that can pack into an array of bytes.
Definition byte_array.h:87
virtual packable_tree * create()=0
a tree factory is needed when we are recreating the packed tree.
A tree object that can be packed into an array of bytes and unpacked again.
void recursive_pack(basis::byte_array &packed_form) const
packs the whole tree starting at this node into the packed form.
int recursive_packed_size() const
spiders the tree starting at this node to calculate the packed size.
packable_tree()
constructs a new tree with a root and zero branches.
static packable_tree * recursive_unpack(basis::byte_array &packed_form, packable_tree_factory &creator)
unpacks a tree stored in "packed_form" and returns it.
A dynamically linked tree with an arbitrary number of branches.
Definition tree.h:40