OpenFOAM logo
The Open Source CFD Toolbox
  Source Guide OpenCFD Solutions Contact OpenFOAM

wordRe.H

Go to the documentation of this file.
00001 /*---------------------------------------------------------------------------*\
00002   =========                 |
00003   \\      /  F ield         | OpenFOAM: The Open Source CFD Toolbox
00004    \\    /   O peration     |
00005     \\  /    A nd           | Copyright (C) 1991-2009 OpenCFD Ltd.
00006      \\/     M anipulation  |
00007 -------------------------------------------------------------------------------
00008 License
00009     This file is part of OpenFOAM.
00010 
00011     OpenFOAM is free software; you can redistribute it and/or modify it
00012     under the terms of the GNU General Public License as published by the
00013     Free Software Foundation; either version 2 of the License, or (at your
00014     option) any later version.
00015 
00016     OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
00017     ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00018     FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00019     for more details.
00020 
00021     You should have received a copy of the GNU General Public License
00022     along with OpenFOAM; if not, write to the Free Software Foundation,
00023     Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
00024 
00025 Class
00026     Foam::wordRe
00027 
00028 Description
00029     A wordRe is a word, but can also have a regular expression for matching
00030     words.
00031 
00032     By default the constructors will generally preserve the argument as
00033     string literal and the assignment operators will use the wordRe::DETECT
00034     compOption to scan the string for regular expression meta characters
00035     and/or invalid word characters and react accordingly.
00036 
00037     The exceptions are when constructing/assigning from another
00038     Foam::wordRe (preserve the same type) or from a Foam::word (always
00039     literal).
00040 
00041 Note
00042     If the string contents are changed - eg, by the operator+=() or by
00043     string::replace(), etc - it will be necessary to use compile() or
00044     recompile() to synchronize the regular expression.
00045 
00046 SourceFiles
00047     wordRe.C
00048     wordReIO.C
00049 
00050 \*---------------------------------------------------------------------------*/
00051 
00052 #ifndef wordRe_H
00053 #define wordRe_H
00054 
00055 #include "word.H"
00056 #include "regExp.H"
00057 
00058 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00059 
00060 namespace Foam
00061 {
00062 
00063 // Forward declaration of friend functions and operators
00064 class wordRe;
00065 
00066 class Istream;
00067 class Ostream;
00068 
00069 Istream& operator>>(Istream&, wordRe&);
00070 Ostream& operator<<(Ostream&, const wordRe&);
00071 
00072 
00073 /*---------------------------------------------------------------------------*\
00074                            Class wordRe Declaration
00075 \*---------------------------------------------------------------------------*/
00076 
00077 class wordRe
00078 :
00079     public word
00080 {
00081     // Private member data
00082 
00083         //- The regular expression
00084         mutable regExp re_;
00085 
00086 public:
00087 
00088     // Public data types
00089 
00090         //- Enumeration with compile options
00091         //  Note that 'REGEXP' is implicit if 'NOCASE' is specified alone.
00092         enum compOption
00093         {
00094             LITERAL = 0, 
00095             DETECT  = 1, 
00096             REGEXP  = 2, 
00097             NOCASE  = 4, 
00098             DETECT_NOCASE = DETECT | NOCASE,
00099             REGEXP_NOCASE = REGEXP | NOCASE
00100         };
00101 
00102 
00103         //- Is this a meta character?
00104         static inline bool meta(char);
00105 
00106         //- Test string for regular expression meta characters
00107         static inline bool isPattern(const string&);
00108 
00109     // Constructors
00110 
00111         //- Construct null
00112         inline wordRe();
00113 
00114         //- Construct as copy
00115         inline wordRe(const wordRe&);
00116 
00117         //- Construct as copy of word
00118         inline wordRe(const word&);
00119 
00120         //- Construct as copy of character array
00121         //  Optionally specify how it should be treated.
00122         inline wordRe(const char*, const compOption=LITERAL);
00123 
00124         //- Construct as copy of string.
00125         //  Optionally specify how it should be treated.
00126         inline wordRe(const string&, const compOption=LITERAL);
00127 
00128         //- Construct as copy of std::string
00129         //  Optionally specify how it should be treated.
00130         inline wordRe(const std::string&, const compOption=LITERAL);
00131 
00132         //- Construct from Istream
00133         //  Words are treated as literals, strings with an auto-test
00134         wordRe(Istream&);
00135 
00136     // Member functions
00137 
00138     //- Access
00139 
00140         //- Should be treated as a match rather than a literal string?
00141         inline bool isPattern() const;
00142 
00143     //- Infrastructure
00144 
00145         //- Compile the regular expression
00146         inline bool compile() const;
00147 
00148         //- Possibly compile the regular expression, with greater control
00149         inline bool compile(const compOption) const;
00150 
00151         //- Recompile an existing regular expression
00152         inline bool recompile() const;
00153 
00154         //- Frees precompiled regular expression, making wordRe a literal.
00155         //  Optionally strips invalid word characters
00156         inline void uncompile(const bool doStripInvalid=false) const;
00157 
00158     //- Editing
00159 
00160         //- Copy string, auto-test for regular expression or other options
00161         inline void set(const std::string&, const compOption=DETECT);
00162 
00163         //- Copy string, auto-test for regular expression or other options
00164         inline void set(const char*, const compOption=DETECT);
00165 
00166         //- Clear string and precompiled regular expression
00167         inline void clear();
00168 
00169     //- Searching
00170 
00171         //- Smart match as regular expression or as a string
00172         //  Optionally specify a literal match only
00173         inline bool match(const string&, bool literalMatch=false) const;
00174 
00175     //- Miscellaneous
00176 
00177         //- Return a string with quoted meta-characters
00178         inline string quotemeta() const;
00179 
00180         //- Output some basic info
00181         Ostream& info(Ostream&) const;
00182 
00183 
00184     // Member operators
00185 
00186         // Assignment
00187 
00188             //- Assign copy
00189             //  Always case sensitive
00190             inline const wordRe& operator=(const wordRe&);
00191 
00192             //- Copy word, never a regular expression
00193             inline const wordRe& operator=(const word&);
00194 
00195             //- Copy string, auto-test for regular expression
00196             //  Always case sensitive
00197             inline const wordRe& operator=(const string&);
00198 
00199             //- Copy string, auto-test for regular expression
00200             //  Always case sensitive
00201             inline const wordRe& operator=(const std::string&);
00202 
00203             //- Copy string, auto-test for regular expression
00204             //  Always case sensitive
00205             inline const wordRe& operator=(const char*);
00206 
00207 
00208     // IOstream operators
00209 
00210         friend Istream& operator>>(Istream&, wordRe&);
00211         friend Ostream& operator<<(Ostream&, const wordRe&);
00212 };
00213 
00214 
00215 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00216 
00217 } // End namespace Foam
00218 
00219 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00220 
00221 #include "wordReI.H"
00222 
00223 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00224 
00225 #endif
00226 
00227 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd