directory_tree.h
Go to the documentation of this file.00001 #ifndef DIRECTORY_TREE_CLASS
00002 #define DIRECTORY_TREE_CLASS
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #include "directory.h"
00019 #include "file_info.h"
00020
00021 #include <basis/byte_array.h>
00022 #include <basis/contracts.h>
00023 #include <basis/outcome.h>
00024 #include <structures/string_array.h>
00025
00026 namespace filesystem {
00027
00028
00029 class dir_tree_iterator;
00030 class filename;
00031 class filename_list;
00032 class filename_tree;
00033 class fname_tree_creator;
00034
00036
00037 class directory_tree : public virtual basis::packable
00038 {
00039 public:
00040 directory_tree();
00041
00042 directory_tree(const basis::astring &path, const char *pattern = "*",
00043 bool ignore_files = false);
00045
00055 ~directory_tree();
00056
00057 DEFINE_CLASS_NAME("directory_tree");
00058
00059 bool good() const { return _scanned_okay; }
00061
00062 const basis::astring &path() const;
00064
00065 bool reset(const basis::astring &path, const char *pattern = "*");
00067
00071 filename_tree *seek(const basis::astring &dir_name, bool ignore_initial) const;
00073
00078 virtual int packed_size() const;
00080 virtual void pack(basis::byte_array &packed_form) const;
00082 virtual bool unpack(basis::byte_array &packed_form);
00084
00085 bool calculate(bool just_size);
00087
00090 bool calculate(filename_tree *start, bool just_size);
00092
00093 basis::outcome add_path(const basis::astring &new_item, bool just_size = false);
00095
00101 basis::outcome remove_path(const basis::astring &zap_item);
00103
00107 static bool compare_trees(const directory_tree &source,
00108 const directory_tree &target, filename_list &differences,
00109 file_info::file_similarity how_to_compare);
00111
00120 static bool compare_trees(const directory_tree &source,
00121 const basis::astring &source_start, const directory_tree &target,
00122 const basis::astring &target_start, filename_list &differences,
00123 file_info::file_similarity how_to_compare);
00124
00125
00126
00127
00128
00129
00130 void text_form(basis::astring &tree_dump, bool show_files = true);
00132
00135
00136
00137
00138
00139 enum traversal_types {
00140 prefix,
00141 infix,
00142 postfix
00143 };
00144
00145 dir_tree_iterator *start(traversal_types type) const;
00147
00148 dir_tree_iterator *start_at(filename_tree *start,
00149 traversal_types type) const;
00151
00152 static bool jump_to(dir_tree_iterator &scanning, const basis::astring &sub_path);
00154
00157 static bool current_dir(dir_tree_iterator &scanning, filename &dir_name);
00159
00160 static bool current(dir_tree_iterator &scanning, filename &dir_name,
00161 structures::string_array &to_fill);
00163
00168 static bool current(dir_tree_iterator &scanning, filename &dir_name,
00169 filename_list &to_fill);
00171
00172 static filename_list *access(dir_tree_iterator &scanning);
00174
00177 static bool depth(dir_tree_iterator &scanning, int &depth);
00179
00181 static bool children(dir_tree_iterator &scanning, int &children);
00183
00184 static bool next(dir_tree_iterator &scanning);
00186
00188 static void throw_out(dir_tree_iterator * &to_whack);
00190
00191 private:
00192 bool _scanned_okay;
00193 basis::astring *_path;
00194 basis::astring *_pattern;
00195 filename_tree *_real_tree;
00196 bool _ignore_files;
00197 fname_tree_creator *_creator;
00198
00199 static filename_tree *goto_current(dir_tree_iterator &scanning);
00201
00203 void traverse(const basis::astring &path, const char *pattern,
00204 filename_tree &add_to);
00206
00210 basis::outcome find_common_root(const basis::astring &path, bool exists,
00211 filename_tree * &common_root, basis::astring &common_path,
00212 structures::string_array &pieces, int &match_place);
00214
00219 };
00220
00221 }
00222
00223 #endif
00224