Panda3D
Loading...
Searching...
No Matches
globPattern.h
Go to the documentation of this file.
1/**
2 * PANDA 3D SOFTWARE
3 * Copyright (c) Carnegie Mellon University. All rights reserved.
4 *
5 * All use of this software is subject to the terms of the revised BSD
6 * license. You should have received a copy of this license along
7 * with this source code in a file named "LICENSE."
8 *
9 * @file globPattern.h
10 * @author drose
11 * @date 2000-05-30
12 */
13
14#ifndef GLOBPATTERN_H
15#define GLOBPATTERN_H
16
17#include "dtoolbase.h"
18#include "filename.h"
19#include "vector_string.h"
20
21/**
22 * This class can be used to test for string matches against standard Unix-
23 * shell filename globbing conventions. It serves as a portable standin for
24 * the Posix fnmatch() call.
25 *
26 * A GlobPattern is given a pattern string, which can contain operators like
27 * *, ?, and []. Then it can be tested against any number of candidate
28 * strings; for each candidate, it will indicate whether the string matches
29 * the pattern or not. It can be used, for example, to scan a directory for
30 * all files matching a particular pattern.
31 */
32class EXPCL_DTOOL_DTOOLUTIL GlobPattern {
33PUBLISHED:
34 INLINE GlobPattern(const std::string &pattern = std::string());
35 INLINE GlobPattern(const GlobPattern &copy);
36 INLINE void operator = (const GlobPattern &copy);
37
38 INLINE bool operator == (const GlobPattern &other) const;
39 INLINE bool operator != (const GlobPattern &other) const;
40 INLINE bool operator < (const GlobPattern &other) const;
41
42 INLINE void set_pattern(const std::string &pattern);
43 INLINE const std::string &get_pattern() const;
44 MAKE_PROPERTY(pattern, get_pattern, set_pattern);
45
46 INLINE void set_case_sensitive(bool case_sensitive);
47 INLINE bool get_case_sensitive() const;
48 MAKE_PROPERTY(case_sensitive, get_case_sensitive, set_case_sensitive);
49
50 INLINE void set_nomatch_chars(const std::string &nomatch_chars);
51 INLINE const std::string &get_nomatch_chars() const;
52 MAKE_PROPERTY(nomatch_chars, get_nomatch_chars, set_nomatch_chars);
53
54 INLINE bool matches(const std::string &candidate) const;
55 bool matches_file(Filename candidate) const;
56
57 INLINE void output(std::ostream &out) const;
58
59 bool has_glob_characters() const;
60 std::string get_const_prefix() const;
61 int match_files(vector_string &results, const Filename &cwd = Filename()) const;
62#ifdef HAVE_PYTHON
63 EXTENSION(PyObject *match_files(const Filename &cwd = Filename()) const);
64#endif
65
66private:
67 bool matches_substr(std::string::const_iterator pi,
68 std::string::const_iterator pend,
69 std::string::const_iterator ci,
70 std::string::const_iterator cend) const;
71
72 bool matches_set(std::string::const_iterator &pi,
73 std::string::const_iterator pend,
74 char ch) const;
75
76 int r_match_files(const Filename &prefix, const std::string &suffix,
77 vector_string &results, const Filename &cwd);
78 bool r_matches_file(const std::string &suffix, const Filename &candidate) const;
79
80 std::string _pattern;
81 bool _case_sensitive;
82 std::string _nomatch_chars;
83};
84
85INLINE std::ostream &operator << (std::ostream &out, const GlobPattern &glob) {
86 glob.output(out);
87 return out;
88}
89
90
91#include "globPattern.I"
92
93#endif
The name of a file, such as a texture file or an Egg file.
Definition filename.h:44
This class can be used to test for string matches against standard Unix- shell filename globbing conv...
Definition globPattern.h:32
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.