Panda3D
|
00001 // Filename: pathReplace.h 00002 // Created by: drose (07Feb03) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) Carnegie Mellon University. All rights reserved. 00008 // 00009 // All use of this software is subject to the terms of the revised BSD 00010 // license. You should have received a copy of this license along 00011 // with this source code in a file named "LICENSE." 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 00026 //////////////////////////////////////////////////////////////////// 00027 // Class : PathReplace 00028 // Description : This encapsulates the user's command-line request to 00029 // replace existing, incorrect pathnames to models and 00030 // textures from a file with correct pathnames. It 00031 // corresponds to a sequence of -pr command-line 00032 // options, as well as the -pp option. 00033 // 00034 // This can also go the next step, which is to convert a 00035 // known file into a suitable form for storing in a 00036 // model file. In this capacity, it corresponds to the 00037 // -ps and -pd options. 00038 //////////////////////////////////////////////////////////////////// 00039 class PathReplace : public ReferenceCount { 00040 public: 00041 PathReplace(); 00042 ~PathReplace(); 00043 00044 INLINE void clear_error(); 00045 INLINE bool had_error() const; 00046 00047 INLINE void clear(); 00048 INLINE void add_pattern(const string &orig_prefix, const string &replacement_prefix); 00049 00050 INLINE int get_num_patterns() const; 00051 INLINE const string &get_orig_prefix(int n) const; 00052 INLINE const string &get_replacement_prefix(int n) const; 00053 00054 INLINE bool is_empty() const; 00055 00056 Filename match_path(const Filename &orig_filename, 00057 const DSearchPath &additional_path = DSearchPath()); 00058 Filename store_path(const Filename &orig_filename); 00059 00060 INLINE Filename convert_path(const Filename &orig_filename, 00061 const DSearchPath &additional_path = DSearchPath()); 00062 00063 void full_convert_path(const Filename &orig_filename, 00064 const DSearchPath &additional_path, 00065 Filename &resolved_path, 00066 Filename &output_path); 00067 00068 void write(ostream &out, int indent_level = 0) const; 00069 00070 public: 00071 // This is used (along with _entries) to support match_path(). 00072 DSearchPath _path; 00073 00074 // These are used to support store_path(). 00075 PathStore _path_store; 00076 Filename _path_directory; 00077 00078 // If this is this true, then the error flag is set (see had_error() 00079 // and clear_error()) if any Filename passed to match_path() or 00080 // convert_path(), and unmatched by one of the prefixes, happens to 00081 // be an absolute pathname. 00082 bool _noabs; 00083 00084 // If this is true, then the error flag is set if any Filename 00085 // passed to match_path() or convert_path() cannot be found. 00086 bool _exists; 00087 00088 private: 00089 class Component { 00090 public: 00091 INLINE Component(const string &component); 00092 INLINE Component(const Component ©); 00093 INLINE void operator = (const Component ©); 00094 00095 GlobPattern _orig_prefix; 00096 bool _double_star; 00097 }; 00098 typedef pvector<Component> Components; 00099 00100 class Entry { 00101 public: 00102 Entry(const string &orig_prefix, const string &replacement_prefix); 00103 INLINE Entry(const Entry ©); 00104 INLINE void operator = (const Entry ©); 00105 00106 bool try_match(const Filename &filename, Filename &new_filename) const; 00107 size_t r_try_match(const vector_string &components, size_t oi, size_t ci) const; 00108 00109 string _orig_prefix; 00110 Components _orig_components; 00111 bool _is_local; 00112 string _replacement_prefix; 00113 }; 00114 00115 typedef pvector<Entry> Entries; 00116 Entries _entries; 00117 00118 bool _error_flag; 00119 }; 00120 00121 #include "pathReplace.I" 00122 00123 #endif 00124 00125 00126