00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015 #ifndef PATHREPLACE_H
00016 #define PATHREPLACE_H
00017
00018 #include "pandatoolbase.h"
00019 #include "pathStore.h"
00020 #include "referenceCount.h"
00021 #include "globPattern.h"
00022 #include "filename.h"
00023 #include "dSearchPath.h"
00024 #include "pvector.h"
00025 #include "pmap.h"
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 class PathReplace : public ReferenceCount {
00041 public:
00042 PathReplace();
00043 ~PathReplace();
00044
00045 INLINE void clear_error();
00046 INLINE bool had_error() const;
00047
00048 INLINE void clear();
00049 INLINE void add_pattern(const string &orig_prefix, const string &replacement_prefix);
00050
00051 INLINE int get_num_patterns() const;
00052 INLINE const string &get_orig_prefix(int n) const;
00053 INLINE const string &get_replacement_prefix(int n) const;
00054
00055 INLINE bool is_empty() const;
00056
00057 Filename match_path(const Filename &orig_filename,
00058 const DSearchPath &additional_path = DSearchPath());
00059 Filename store_path(const Filename &orig_filename);
00060
00061 INLINE Filename convert_path(const Filename &orig_filename,
00062 const DSearchPath &additional_path = DSearchPath());
00063
00064 void full_convert_path(const Filename &orig_filename,
00065 const DSearchPath &additional_path,
00066 Filename &resolved_path,
00067 Filename &output_path);
00068
00069 void write(ostream &out, int indent_level = 0) const;
00070
00071 public:
00072
00073 DSearchPath _path;
00074
00075
00076 PathStore _path_store;
00077 Filename _path_directory;
00078 bool _copy_files;
00079 Filename _copy_into_directory;
00080
00081
00082
00083
00084
00085 bool _noabs;
00086
00087
00088
00089 bool _exists;
00090
00091 private:
00092 bool copy_this_file(Filename &filename);
00093
00094 class Component {
00095 public:
00096 INLINE Component(const string &component);
00097 INLINE Component(const Component ©);
00098 INLINE void operator = (const Component ©);
00099
00100 GlobPattern _orig_prefix;
00101 bool _double_star;
00102 };
00103 typedef pvector<Component> Components;
00104
00105 class Entry {
00106 public:
00107 Entry(const string &orig_prefix, const string &replacement_prefix);
00108 INLINE Entry(const Entry ©);
00109 INLINE void operator = (const Entry ©);
00110
00111 bool try_match(const Filename &filename, Filename &new_filename) const;
00112 size_t r_try_match(const vector_string &components, size_t oi, size_t ci) const;
00113
00114 string _orig_prefix;
00115 Components _orig_components;
00116 bool _is_local;
00117 string _replacement_prefix;
00118 };
00119
00120 typedef pvector<Entry> Entries;
00121 Entries _entries;
00122
00123 bool _error_flag;
00124
00125 typedef pmap<Filename, Filename> Copied;
00126 Copied _orig_to_target;
00127 Copied _target_to_orig;
00128 };
00129
00130 #include "pathReplace.I"
00131
00132 #endif
00133
00134
00135