Panda3D
 All Classes Functions Variables Enumerations
globPattern.I
1 // Filename: globPattern.I
2 // Created by: drose (30May00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 
16 ////////////////////////////////////////////////////////////////////
17 // Function: GlobPattern::Constructor
18 // Access: Public
19 // Description:
20 ////////////////////////////////////////////////////////////////////
21 INLINE GlobPattern::
22 GlobPattern(const string &pattern) : _pattern(pattern) {
23  _case_sensitive = true;
24 }
25 
26 ////////////////////////////////////////////////////////////////////
27 // Function: GlobPattern::Copy Constructor
28 // Access: Public
29 // Description:
30 ////////////////////////////////////////////////////////////////////
31 INLINE GlobPattern::
32 GlobPattern(const GlobPattern &copy) :
33  _pattern(copy._pattern),
34  _case_sensitive(copy._case_sensitive)
35 {
36 }
37 
38 ////////////////////////////////////////////////////////////////////
39 // Function: GlobPattern::Copy Assignment Operator
40 // Access: Public
41 // Description:
42 ////////////////////////////////////////////////////////////////////
43 INLINE void GlobPattern::
44 operator = (const GlobPattern &copy) {
45  _pattern = copy._pattern;
46  _case_sensitive = copy._case_sensitive;
47 }
48 
49 ////////////////////////////////////////////////////////////////////
50 // Function: GlobPattern::operator ==
51 // Access: Public
52 // Description:
53 ////////////////////////////////////////////////////////////////////
54 INLINE bool GlobPattern::
55 operator == (const GlobPattern &other) const {
56  return (_pattern == other._pattern && _case_sensitive == other._case_sensitive);
57 }
58 
59 ////////////////////////////////////////////////////////////////////
60 // Function: GlobPattern::operator !=
61 // Access: Public
62 // Description:
63 ////////////////////////////////////////////////////////////////////
64 INLINE bool GlobPattern::
65 operator != (const GlobPattern &other) const {
66  return !operator == (other);
67 }
68 
69 ////////////////////////////////////////////////////////////////////
70 // Function: GlobPattern::operator <
71 // Access: Public
72 // Description:
73 ////////////////////////////////////////////////////////////////////
74 INLINE bool GlobPattern::
75 operator < (const GlobPattern &other) const {
76  if (_case_sensitive != other._case_sensitive) {
77  return (int)_case_sensitive < (int)other._case_sensitive;
78  }
79  return _pattern < other._pattern;
80 }
81 
82 ////////////////////////////////////////////////////////////////////
83 // Function: GlobPattern::set_pattern
84 // Access: Public
85 // Description: Changes the pattern string that the GlobPattern
86 // object matches.
87 ////////////////////////////////////////////////////////////////////
88 INLINE void GlobPattern::
89 set_pattern(const string &pattern) {
90  _pattern = pattern;
91 }
92 
93 ////////////////////////////////////////////////////////////////////
94 // Function: GlobPattern::get_pattern
95 // Access: Public
96 // Description: Returns the pattern string that the GlobPattern
97 // object matches.
98 ////////////////////////////////////////////////////////////////////
99 INLINE const string &GlobPattern::
100 get_pattern() const {
101  return _pattern;
102 }
103 
104 ////////////////////////////////////////////////////////////////////
105 // Function: GlobPattern::set_case_sensitive
106 // Access: Public
107 // Description: Sets whether the match is case sensitive (true) or
108 // case insensitive (false). The default is case
109 // sensitive.
110 ////////////////////////////////////////////////////////////////////
111 INLINE void GlobPattern::
112 set_case_sensitive(bool case_sensitive) {
113  _case_sensitive = case_sensitive;
114 }
115 
116 ////////////////////////////////////////////////////////////////////
117 // Function: GlobPattern::get_case_sensitive
118 // Access: Public
119 // Description: Returns whether the match is case sensitive (true) or
120 // case insensitive (false). The default is case
121 // sensitive.
122 ////////////////////////////////////////////////////////////////////
123 INLINE bool GlobPattern::
125  return _case_sensitive;
126 }
127 
128 ////////////////////////////////////////////////////////////////////
129 // Function: GlobPattern::set_nomatch_chars
130 // Access: Public
131 // Description: Specifies a set of characters that are not matched by
132 // * or ?.
133 ////////////////////////////////////////////////////////////////////
134 INLINE void GlobPattern::
135 set_nomatch_chars(const string &nomatch_chars) {
136  _nomatch_chars = nomatch_chars;
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function: GlobPattern::get_nomatch_chars
141 // Access: Public
142 // Description: Returns the set of characters that are not matched by
143 // * or ?.
144 ////////////////////////////////////////////////////////////////////
145 INLINE const string &GlobPattern::
147  return _nomatch_chars;
148 }
149 
150 ////////////////////////////////////////////////////////////////////
151 // Function: GlobPattern::matches
152 // Access: Public
153 // Description: Returns true if the candidate string matches the
154 // pattern, false otherwise.
155 ////////////////////////////////////////////////////////////////////
156 INLINE bool GlobPattern::
157 matches(const string &candidate) const {
158  return matches_substr(_pattern.begin(), _pattern.end(),
159  candidate.begin(), candidate.end());
160 }
161 
162 ////////////////////////////////////////////////////////////////////
163 // Function: GlobPattern::output
164 // Access: Public
165 // Description:
166 ////////////////////////////////////////////////////////////////////
167 INLINE void GlobPattern::
168 output(ostream &out) const {
169  out << _pattern;
170 }
const string & get_pattern() const
Returns the pattern string that the GlobPattern object matches.
Definition: globPattern.I:100
bool matches(const string &candidate) const
Returns true if the candidate string matches the pattern, false otherwise.
Definition: globPattern.I:157
void set_case_sensitive(bool case_sensitive)
Sets whether the match is case sensitive (true) or case insensitive (false).
Definition: globPattern.I:112
void set_nomatch_chars(const string &nomatch_chars)
Specifies a set of characters that are not matched by or ?.
Definition: globPattern.I:135
bool get_case_sensitive() const
Returns whether the match is case sensitive (true) or case insensitive (false).
Definition: globPattern.I:124
const string & get_nomatch_chars() const
Returns the set of characters that are not matched by or ?.
Definition: globPattern.I:146
void set_pattern(const string &pattern)
Changes the pattern string that the GlobPattern object matches.
Definition: globPattern.I:89
This class can be used to test for string matches against standard Unix-shell filename globbing conve...
Definition: globPattern.h:37