00001 // Filename: globPattern.I 00002 // Created by: drose (30May00) 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: GlobPattern::Constructor 00018 // Access: Public 00019 // Description: 00020 //////////////////////////////////////////////////////////////////// 00021 INLINE GlobPattern:: 00022 GlobPattern(const string &pattern) : _pattern(pattern) { 00023 _case_sensitive = true; 00024 } 00025 00026 //////////////////////////////////////////////////////////////////// 00027 // Function: GlobPattern::Copy Constructor 00028 // Access: Public 00029 // Description: 00030 //////////////////////////////////////////////////////////////////// 00031 INLINE GlobPattern:: 00032 GlobPattern(const GlobPattern ©) : 00033 _pattern(copy._pattern), 00034 _case_sensitive(copy._case_sensitive) 00035 { 00036 } 00037 00038 //////////////////////////////////////////////////////////////////// 00039 // Function: GlobPattern::Copy Assignment Operator 00040 // Access: Public 00041 // Description: 00042 //////////////////////////////////////////////////////////////////// 00043 INLINE void GlobPattern:: 00044 operator = (const GlobPattern ©) { 00045 _pattern = copy._pattern; 00046 _case_sensitive = copy._case_sensitive; 00047 } 00048 00049 //////////////////////////////////////////////////////////////////// 00050 // Function: GlobPattern::operator == 00051 // Access: Public 00052 // Description: 00053 //////////////////////////////////////////////////////////////////// 00054 INLINE bool GlobPattern:: 00055 operator == (const GlobPattern &other) const { 00056 return (_pattern == other._pattern && _case_sensitive == other._case_sensitive); 00057 } 00058 00059 //////////////////////////////////////////////////////////////////// 00060 // Function: GlobPattern::operator != 00061 // Access: Public 00062 // Description: 00063 //////////////////////////////////////////////////////////////////// 00064 INLINE bool GlobPattern:: 00065 operator != (const GlobPattern &other) const { 00066 return !operator == (other); 00067 } 00068 00069 //////////////////////////////////////////////////////////////////// 00070 // Function: GlobPattern::operator < 00071 // Access: Public 00072 // Description: 00073 //////////////////////////////////////////////////////////////////// 00074 INLINE bool GlobPattern:: 00075 operator < (const GlobPattern &other) const { 00076 if (_case_sensitive != other._case_sensitive) { 00077 return (int)_case_sensitive < (int)other._case_sensitive; 00078 } 00079 return _pattern < other._pattern; 00080 } 00081 00082 //////////////////////////////////////////////////////////////////// 00083 // Function: GlobPattern::set_pattern 00084 // Access: Public 00085 // Description: Changes the pattern string that the GlobPattern 00086 // object matches. 00087 //////////////////////////////////////////////////////////////////// 00088 INLINE void GlobPattern:: 00089 set_pattern(const string &pattern) { 00090 _pattern = pattern; 00091 } 00092 00093 //////////////////////////////////////////////////////////////////// 00094 // Function: GlobPattern::get_pattern 00095 // Access: Public 00096 // Description: Returns the pattern string that the GlobPattern 00097 // object matches. 00098 //////////////////////////////////////////////////////////////////// 00099 INLINE const string &GlobPattern:: 00100 get_pattern() const { 00101 return _pattern; 00102 } 00103 00104 //////////////////////////////////////////////////////////////////// 00105 // Function: GlobPattern::set_case_sensitive 00106 // Access: Public 00107 // Description: Sets whether the match is case sensitive (true) or 00108 // case insensitive (false). The default is case 00109 // sensitive. 00110 //////////////////////////////////////////////////////////////////// 00111 INLINE void GlobPattern:: 00112 set_case_sensitive(bool case_sensitive) { 00113 _case_sensitive = case_sensitive; 00114 } 00115 00116 //////////////////////////////////////////////////////////////////// 00117 // Function: GlobPattern::get_case_sensitive 00118 // Access: Public 00119 // Description: Returns whether the match is case sensitive (true) or 00120 // case insensitive (false). The default is case 00121 // sensitive. 00122 //////////////////////////////////////////////////////////////////// 00123 INLINE bool GlobPattern:: 00124 get_case_sensitive() const { 00125 return _case_sensitive; 00126 } 00127 00128 //////////////////////////////////////////////////////////////////// 00129 // Function: GlobPattern::set_nomatch_chars 00130 // Access: Public 00131 // Description: Specifies a set of characters that are not matched by 00132 // * or ?. 00133 //////////////////////////////////////////////////////////////////// 00134 INLINE void GlobPattern:: 00135 set_nomatch_chars(const string &nomatch_chars) { 00136 _nomatch_chars = nomatch_chars; 00137 } 00138 00139 //////////////////////////////////////////////////////////////////// 00140 // Function: GlobPattern::get_nomatch_chars 00141 // Access: Public 00142 // Description: Returns the set of characters that are not matched by 00143 // * or ?. 00144 //////////////////////////////////////////////////////////////////// 00145 INLINE const string &GlobPattern:: 00146 get_nomatch_chars() const { 00147 return _nomatch_chars; 00148 } 00149 00150 //////////////////////////////////////////////////////////////////// 00151 // Function: GlobPattern::matches 00152 // Access: Public 00153 // Description: Returns true if the candidate string matches the 00154 // pattern, false otherwise. 00155 //////////////////////////////////////////////////////////////////// 00156 INLINE bool GlobPattern:: 00157 matches(const string &candidate) const { 00158 return matches_substr(_pattern.begin(), _pattern.end(), 00159 candidate.begin(), candidate.end()); 00160 } 00161 00162 //////////////////////////////////////////////////////////////////// 00163 // Function: GlobPattern::output 00164 // Access: Public 00165 // Description: 00166 //////////////////////////////////////////////////////////////////// 00167 INLINE void GlobPattern:: 00168 output(ostream &out) const { 00169 out << _pattern; 00170 }