00001 // Filename: pathReplace.h 00002 // Created by: drose (07Feb03) 00003 // 00004 //////////////////////////////////////////////////////////////////// 00005 // 00006 // PANDA 3D SOFTWARE 00007 // Copyright (c) 2001, Disney Enterprises, Inc. All rights reserved 00008 // 00009 // All use of this software is subject to the terms of the Panda 3d 00010 // Software license. You should have received a copy of this license 00011 // along with this source code; you will also find a current copy of 00012 // the license at http://www.panda3d.org/license.txt . 00013 // 00014 // To contact the maintainers of this program write to 00015 // panda3d@yahoogroups.com . 00016 // 00017 //////////////////////////////////////////////////////////////////// 00018 00019 #ifndef PATHREPLACE_H 00020 #define PATHREPLACE_H 00021 00022 #include "pandatoolbase.h" 00023 #include "pathStore.h" 00024 #include "referenceCount.h" 00025 #include "globPattern.h" 00026 #include "filename.h" 00027 #include "dSearchPath.h" 00028 #include "pvector.h" 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Class : PathReplace 00032 // Description : This encapsulates the user's command-line request to 00033 // replace existing, incorrect pathnames to models and 00034 // textures from a file with correct pathnames. It 00035 // corresponds to a sequence of -pr command-line 00036 // options, as well as the -pp option. 00037 // 00038 // This can also go the next step, which is to convert a 00039 // known file into a suitable form for storing in a 00040 // model file. In this capacity, it corresponds to the 00041 // -ps and -pd options. 00042 //////////////////////////////////////////////////////////////////// 00043 class PathReplace : public ReferenceCount { 00044 public: 00045 PathReplace(); 00046 ~PathReplace(); 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 write(ostream &out, int indent_level = 0) const; 00065 00066 public: 00067 // This is used (along with _entries) to support match_path(). 00068 DSearchPath _path; 00069 00070 // These are used to support store_path(). 00071 PathStore _path_store; 00072 Filename _path_directory; 00073 00074 private: 00075 class Component { 00076 public: 00077 INLINE Component(const string &component); 00078 INLINE Component(const Component ©); 00079 INLINE void operator = (const Component ©); 00080 00081 GlobPattern _orig_prefix; 00082 bool _double_star; 00083 }; 00084 typedef pvector<Component> Components; 00085 00086 class Entry { 00087 public: 00088 Entry(const string &orig_prefix, const string &replacement_prefix); 00089 INLINE Entry(const Entry ©); 00090 INLINE void operator = (const Entry ©); 00091 00092 bool try_match(const Filename &filename, Filename &new_filename) const; 00093 size_t r_try_match(const vector_string &components, size_t oi, size_t ci) const; 00094 00095 string _orig_prefix; 00096 Components _orig_components; 00097 bool _is_local; 00098 string _replacement_prefix; 00099 }; 00100 00101 typedef pvector<Entry> Entries; 00102 Entries _entries; 00103 }; 00104 00105 #include "pathReplace.I" 00106 00107 #endif 00108 00109 00110