Panda3D

pathReplace.I

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