1 #ifndef PACKABLE_TREE_CLASS
2 #define PACKABLE_TREE_CLASS
4 /*****************************************************************************\
6 * Name : packable_tree *
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 \*****************************************************************************/
20 #include <basis/byte_array.h>
25 class packable_tree_factory;
27 //! A tree object that can be packed into an array of bytes and unpacked again.
29 class packable_tree : public tree, public virtual basis::packable
33 //!< constructs a new tree with a root and zero branches.
35 // the recursive packing methods here will operate on all nodes starting at this one
36 // and moving downwards to all branches.
38 int recursive_packed_size() const;
39 //!< spiders the tree starting at this node to calculate the packed size.
41 void recursive_pack(basis::byte_array &packed_form) const;
42 //!< packs the whole tree starting at this node into the packed form.
44 static packable_tree *recursive_unpack(basis::byte_array &packed_form,
45 packable_tree_factory &creator);
46 //!< unpacks a tree stored in "packed_form" and returns it.
47 /*!< if NULL_POINTER is returned, then the unpack failed. the "creator" is needed
48 for making new derived packable_tree objects of the type stored. */
50 // standard pack, unpack and packed_size methods must be implemented by the derived tree.
53 static void packit(basis::byte_array &packed_form, const packable_tree *current_node);
54 //!< used by our recursive packing methods.
55 static void calcit(int &size_accumulator, const packable_tree *current_node);
56 //!< used by recursive packed size calculator.
61 class packable_tree_factory
64 virtual ~packable_tree_factory();
65 virtual packable_tree *create() = 0;
66 //!< a tree factory is needed when we are recreating the packed tree.
67 /*!< this is because the real type held is always a derived object.
68 this method should just create a blank object of the appropriate type. */