added kdenlive
[feisty_meow.git] / nucleus / library / filesystem / filename_tree.cpp
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
17 #include <structures/object_packers.h>
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
27 //////////////
28
29 filename_tree::filename_tree() : _depth(0) {}
30
31 filename_tree::~filename_tree() { _dirname = ""; _files.reset(); }
32
33 int filename_tree::packed_size() const {
34   return PACKED_SIZE_INT32 + _dirname.packed_size() + _files.packed_size();
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