00001 // Filename: pathReplace.I 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 00020 //////////////////////////////////////////////////////////////////// 00021 // Function: PathReplace::clear 00022 // Access: Public 00023 // Description: Removes all the patterns from the specification. 00024 //////////////////////////////////////////////////////////////////// 00025 INLINE void PathReplace:: 00026 clear() { 00027 _entries.clear(); 00028 } 00029 00030 //////////////////////////////////////////////////////////////////// 00031 // Function: PathReplace::add_pattern 00032 // Access: Public 00033 // Description: Adds the indicated original/replace pattern to the 00034 // specification. If a filename is encountered whose 00035 // initial prefix matches the indicated orig_prefix, 00036 // that prefix will be replaced with replacement_prefix. 00037 //////////////////////////////////////////////////////////////////// 00038 INLINE void PathReplace:: 00039 add_pattern(const string &orig_prefix, const string &replacement_prefix) { 00040 _entries.push_back(Entry(orig_prefix, replacement_prefix)); 00041 } 00042 00043 //////////////////////////////////////////////////////////////////// 00044 // Function: PathReplace::get_num_patterns 00045 // Access: Public 00046 // Description: Returns the number of original/replace patterns that 00047 // have been added. 00048 //////////////////////////////////////////////////////////////////// 00049 INLINE int PathReplace:: 00050 get_num_patterns() const { 00051 return _entries.size(); 00052 } 00053 00054 //////////////////////////////////////////////////////////////////// 00055 // Function: PathReplace::get_orig_prefix 00056 // Access: Public 00057 // Description: Returns the original prefix associated with the nth 00058 // pattern. 00059 //////////////////////////////////////////////////////////////////// 00060 INLINE const string &PathReplace:: 00061 get_orig_prefix(int n) const { 00062 nassertr(n >= 0 && n < (int)_entries.size(), _entries[0]._orig_prefix); 00063 return _entries[n]._orig_prefix; 00064 } 00065 00066 //////////////////////////////////////////////////////////////////// 00067 // Function: PathReplace::get_replacement_prefix 00068 // Access: Public 00069 // Description: Returns the replacement prefix associated with the nth 00070 // pattern. 00071 //////////////////////////////////////////////////////////////////// 00072 INLINE const string &PathReplace:: 00073 get_replacement_prefix(int n) const { 00074 nassertr(n >= 0 && n < (int)_entries.size(), _entries[0]._replacement_prefix); 00075 return _entries[n]._replacement_prefix; 00076 } 00077 00078 //////////////////////////////////////////////////////////////////// 00079 // Function: PathReplace::is_empty 00080 // Access: Public 00081 // Description: Returns true if the PathReplace object specifies no 00082 // action, or false if convert_path() may do something. 00083 //////////////////////////////////////////////////////////////////// 00084 INLINE bool PathReplace:: 00085 is_empty() const { 00086 return (_entries.empty() && _path.is_empty() && _path_store == PS_keep); 00087 } 00088 00089 //////////////////////////////////////////////////////////////////// 00090 // Function: PathReplace::convert_path 00091 // Access: Public 00092 // Description: Calls match_path() followed by store_path(), to 00093 // replace the initial prefix and then convert the file 00094 // for storing, as the user indicated. 00095 //////////////////////////////////////////////////////////////////// 00096 INLINE Filename PathReplace:: 00097 convert_path(const Filename &orig_filename, const DSearchPath &additional_path) { 00098 return store_path(match_path(orig_filename, additional_path)); 00099 } 00100 00101 //////////////////////////////////////////////////////////////////// 00102 // Function: PathReplace::Component::Constructor 00103 // Access: Public 00104 // Description: 00105 //////////////////////////////////////////////////////////////////// 00106 INLINE PathReplace::Component:: 00107 Component(const string &component) : 00108 _orig_prefix(component), 00109 _double_star(component == "**") 00110 { 00111 } 00112 00113 //////////////////////////////////////////////////////////////////// 00114 // Function: PathReplace::Component::Copy Constructor 00115 // Access: Public 00116 // Description: 00117 //////////////////////////////////////////////////////////////////// 00118 INLINE PathReplace::Component:: 00119 Component(const PathReplace::Component ©) : 00120 _orig_prefix(copy._orig_prefix), 00121 _double_star(copy._double_star) 00122 { 00123 } 00124 00125 //////////////////////////////////////////////////////////////////// 00126 // Function: PathReplace::Component::Copy Assignment 00127 // Access: Public 00128 // Description: 00129 //////////////////////////////////////////////////////////////////// 00130 INLINE void PathReplace::Component:: 00131 operator = (const PathReplace::Component ©) { 00132 _orig_prefix = copy._orig_prefix; 00133 _double_star = copy._double_star; 00134 } 00135 00136 //////////////////////////////////////////////////////////////////// 00137 // Function: PathReplace::Entry::Copy Constructor 00138 // Access: Public 00139 // Description: 00140 //////////////////////////////////////////////////////////////////// 00141 INLINE PathReplace::Entry:: 00142 Entry(const PathReplace::Entry ©) : 00143 _orig_prefix(copy._orig_prefix), 00144 _orig_components(copy._orig_components), 00145 _is_local(copy._is_local), 00146 _replacement_prefix(copy._replacement_prefix) 00147 { 00148 } 00149 00150 //////////////////////////////////////////////////////////////////// 00151 // Function: PathReplace::Entry::Copy Assignment 00152 // Access: Public 00153 // Description: 00154 //////////////////////////////////////////////////////////////////// 00155 INLINE void PathReplace::Entry:: 00156 operator = (const PathReplace::Entry ©) { 00157 _orig_prefix = copy._orig_prefix; 00158 _orig_components = copy._orig_components; 00159 _is_local = copy._is_local; 00160 _replacement_prefix = copy._replacement_prefix; 00161 }