Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/putil/globPattern.h

Go to the documentation of this file.
00001 // Filename: globPattern.h
00002 // Created by:  drose (30May00)
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 #ifndef GLOBPATTERN_H
00020 #define GLOBPATTERN_H
00021 
00022 #include "pandabase.h"
00023 #include "filename.h"
00024 #include "vector_string.h"
00025 
00026 ////////////////////////////////////////////////////////////////////
00027 //       Class : GlobPattern
00028 // Description : This class can be used to test for string matches
00029 //               against standard Unix-shell filename globbing
00030 //               conventions.  It serves as a portable standin for the
00031 //               Posix fnmatch() call.
00032 //
00033 //               A GlobPattern is given a pattern string, which can
00034 //               contain operators like *, ?, and [].  Then it can be
00035 //               tested against any number of candidate strings; for
00036 //               each candidate, it will indicate whether the string
00037 //               matches the pattern or not.  It can be used, for
00038 //               example, to scan a directory for all files matching a
00039 //               particular pattern.
00040 ////////////////////////////////////////////////////////////////////
00041 class EXPCL_PANDA GlobPattern {
00042 public:
00043   INLINE GlobPattern(const string &pattern = string());
00044   INLINE GlobPattern(const GlobPattern &copy);
00045   INLINE void operator = (const GlobPattern &copy);
00046 
00047   INLINE void set_pattern(const string &pattern);
00048   INLINE const string &get_pattern() const;
00049 
00050   INLINE bool matches(const string &candidate) const;
00051 
00052   INLINE void output(ostream &out) const;
00053 
00054   bool has_glob_characters() const;
00055   int match_files(vector_string &results, const Filename &cwd = Filename());
00056 
00057 private:
00058   bool matches_substr(string::const_iterator pi,
00059                       string::const_iterator pend,
00060                       string::const_iterator ci,
00061                       string::const_iterator cend) const;
00062 
00063   bool matches_set(string::const_iterator &pi,
00064                    string::const_iterator pend,
00065                    char ch) const;
00066 
00067   int r_match_files(const Filename &prefix, const string &suffix,
00068                     vector_string &results, const Filename &cwd);
00069 
00070   string _pattern;
00071 };
00072 
00073 INLINE ostream &operator << (ostream &out, const GlobPattern &glob) {
00074   glob.output(out);
00075   return out;
00076 }
00077 
00078 
00079 #include "globPattern.I"
00080 
00081 #endif

Generated on Fri May 2 00:43:39 2003 for Panda by doxygen1.3