# data_tree.hpp

Go to the documentation of this file.

    00001 /*********************************************************************/
    00002 // dar - disk archive - a backup/restoration program
    00003 // Copyright (C) 2002-2052 Denis Corbin
    00004 //
    00005 // This program is free software; you can redistribute it and/or
    00006 // modify it under the terms of the GNU General Public License
    00007 // as published by the Free Software Foundation; either version 2
    00008 // of the License, or (at your option) any later version.
    00009 //
    00010 // This program is distributed in the hope that it will be useful,
    00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of
    00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    00013 // GNU General Public License for more details.
    00014 //
    00015 // You should have received a copy of the GNU General Public License
    00016 // along with this program; if not, write to the Free Software
    00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
    00018 //
    00019 // to contact the author : dar.linux@free.fr
    00020 /*********************************************************************/
    00021 // $Id: data_tree.hpp,v 1.2 2005/07/07 11:04:45 edrusb Rel $
    00022 //
    00023 /*********************************************************************/
    00024
    00028
    00029
    00030 #ifndef DATA_TREE_HPP
    00031 #define DATA_TREE_HPP
    00032
    00033 #include "../my_config.h"
    00034
    00035 #include <map>
    00036 #include <string>
    00037 #include <list>
    00038 #include "infinint.hpp"
    00039 #include "generic_file.hpp"
    00040 #include "infinint.hpp"
    00041 #include "catalogue.hpp"
    00042 #include "special_alloc.hpp"
    00043 #include "user_interaction.hpp"
    00044
    00045 namespace libdar
    00046 {
    00047     typedef U_16 archive_num;
    00048 #define ARCHIVE_NUM_MAX  65534
    00049
    00051
    00055     class data_tree
    00056     {
    00057     public:
    00058
    00059         data_tree(const std::string &name);
    00060         data_tree(generic_file &f);
    00061         virtual ~data_tree() {};
    00062
    00063         virtual void dump(generic_file & f) const;
    00064         std::string get_name() const { return filename; };
    00065
    00067         bool get_data(archive_num & archive, const infinint & date) const;
    00068
    00070         bool get_EA(archive_num & archive, const infinint & date) const;
    00071
    00073         bool read_data(archive_num num, infinint & val) const;
    00074
    00076         bool read_EA(archive_num num, infinint & val) const;
    00077
    00078         void set_data(const archive_num & archive, const infinint & date) { last_mod[archive] = date; };
    00079         void set_EA(const archive_num & archive, const infinint & date) { last_change[archive] = date; };
    00080
    00082         virtual bool remove_all_from(const archive_num & archive);
    00083
    00085         void listing(user_interaction & dialog) const;
    00086         virtual void apply_permutation(archive_num src, archive_num dst);
    00087
    00089         virtual void skip_out(archive_num num);
    00090         virtual void compute_most_recent_stats(std::vector<infinint> & data, std::vector<infinint> & ea,
    00091                                                std::vector<infinint> & total_data, std::vector<infinint> & total_ea) const;
    00092
    00093         virtual char obj_signature() const { return signature(); };
    00094         static char signature() { return 't'; };
    00095
    00096 #ifdef LIBDAR_SPECIAL_ALLOC
    00097         void *operator new(size_t taille) { return special_alloc_new(taille); };
    00098         void operator delete(void *ptr) { special_alloc_delete(ptr); };
    00099 #endif
    00100     private:
    00101         std::string filename;
    00102         std::map<archive_num, infinint> last_mod;    //< key is archive number ; value is last_mod time
    00103         std::map<archive_num, infinint> last_change; //< key is archive number ; value is last_change time
    00104     };
    00105
    00107
    00109     class data_dir : public data_tree
    00110     {
    00111     public:
    00112         data_dir(const std::string &name);
    00113         data_dir(generic_file &f);
    00114         data_dir(const data_dir & ref);
    00115         data_dir(const data_tree & ref);
    00116         ~data_dir();
    00117
    00118         void dump(generic_file & f) const;
    00119
    00120         void add(const inode *entry, const archive_num & archive);
    00121         const data_tree *read_child(const std::string & name) const;
    00122         void read_all_children(std::vector<std::string> & fils) const;
    00123
    00124         bool remove_all_from(const archive_num & archive);
    00125
    00127         void show(user_interaction & dialog, archive_num num, std::string marge = "") const;
    00128         void apply_permutation(archive_num src, archive_num dst);
    00129         void skip_out(archive_num num);
    00130         void compute_most_recent_stats(std::vector<infinint> & data, std::vector<infinint> & ea,
    00131                                        std::vector<infinint> & total_data, std::vector<infinint> & total_ea) const;
    00132
    00133         char obj_signature() const { return signature(); };
    00134         static char signature() { return 'd'; };
    00135
    00136 #ifdef LIBDAR_SPECIAL_ALLOC
    00137         void *operator new(size_t taille) { return special_alloc_new(taille); };
    00138         void operator delete(void *ptr) { special_alloc_delete(ptr); };
    00139 #endif
    00140
    00141     private:
    00142         std::list<data_tree *> rejetons;
    00143
    00144         void add_child(data_tree *fils);          //< "this" is now responsible of "fils" disalocation
    00145         void remove_child(const std::string & name);
    00146     };
    00147
    00148     extern data_dir *data_tree_read(generic_file & f);
    00149     extern bool data_tree_find(path chemin, const data_dir & racine, const data_tree *& ptr);
    00150     extern void data_tree_update_with(const directory *dir, archive_num archive, data_dir *racine);
    00151     extern archive_num data_tree_permutation(archive_num src, archive_num dst, archive_num x);
    00152
    00153 } // end of namespace
    00154
    00155 #endif