feisty meow concerns codebase  2.140
filename_tree.cpp
Go to the documentation of this file.
1 /*****************************************************************************\
2 * *
3 * Name : filename_tree *
4 * Author : Chris Koeritz *
5 * *
6 *******************************************************************************
7 * Copyright (c) 2004-$now By Author. This program is free software; you can *
8 * redistribute it and/or modify it under the terms of the GNU General Public *
9 * License as published by the Free Software Foundation; either version 2 of *
10 * the License or (at your option) any later version. This is online at: *
11 * http://www.fsf.org/copyleft/gpl.html *
12 * Please send any updates to: fred@gruntose.com *
13 \*****************************************************************************/
14 
15 #include "filename_tree.h"
16 
18 
19 using namespace basis;
20 using namespace nodes;
21 using namespace structures;
22 
23 namespace filesystem {
24 
25 nodes::packable_tree *fname_tree_creator::create() { return new filename_tree; }
26 
28 
29 filename_tree::filename_tree() : _depth(0) {}
30 
32 
35 }
36 
37 void filename_tree::pack(byte_array &packed_form) const {
38  structures::attach(packed_form, _depth);
39  _dirname.pack(packed_form);
40  _files.pack(packed_form);
41 }
42 
43 bool filename_tree::unpack(byte_array &packed_form) {
44  if (!structures::detach(packed_form, _depth)) return false;
45  if (!_dirname.unpack(packed_form)) return false;
46  if (!_files.unpack(packed_form)) return false;
47  return true;
48 }
49 
50 } //namespace.
51 
52 
A very common template for a dynamic array of bytes.
Definition: byte_array.h:36
virtual void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
virtual bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
virtual int packed_size() const
Estimates the space needed for the packed structure.
int _depth
how far below root node are we.
Definition: filename_tree.h:37
filename_list _files
the filenames that are at this node in the tree.
Definition: filename_tree.h:36
filename _dirname
the full directory name at this position.
Definition: filename_tree.h:35
virtual int packed_size() const
Estimates the space needed for the packed structure.
virtual void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
virtual bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
virtual bool unpack(basis::byte_array &packed_form)
Restores the packable from the "packed_form".
Definition: filename.cpp:471
virtual void pack(basis::byte_array &packed_form) const
Creates a packed form of the packable object in "packed_form".
Definition: filename.cpp:465
virtual int packed_size() const
Estimates the space needed for the packed structure.
Definition: filename.cpp:460
A tree object that can be packed into an array of bytes and unpacked again.
Definition: packable_tree.h:30
void reset()
cleans out all of the contents.
Definition: amorph.h:81
The guards collection helps in testing preconditions and reporting errors.
Definition: array.h:30
A platform independent way to obtain the timestamp of a file.
Definition: byte_filer.cpp:37
A dynamic container class that holds any kind of object via pointers.
Definition: amorph.h:55
void attach(byte_array &packed_form, const byte_array &to_attach)
Packs a byte_array "to_attach" into "packed_form".
const int PACKED_SIZE_INT32
bool detach(byte_array &packed_form, byte_array &to_detach)
Unpacks a byte_array "to_detach" from "packed_form".