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

wordReI.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 \*---------------------------------------------------------------------------*/
00026 
00027 // * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * * //
00028 
00029 inline bool Foam::wordRe::meta(char c)
00030 {
00031     return regExp::meta(c);
00032 }
00033 
00034 
00035 inline bool Foam::wordRe::isPattern(const string& str)
00036 {
00037     return string::meta<regExp>(str);
00038 }
00039 
00040 
00041 // * * * * * * * * * * * * * * * * Constructors  * * * * * * * * * * * * * * //
00042 
00043 inline Foam::wordRe::wordRe()
00044 :
00045     word(),
00046     re_()
00047 {}
00048 
00049 
00050 inline Foam::wordRe::wordRe(const wordRe& str)
00051 :
00052     word(str),
00053     re_()
00054 {
00055     if (str.isPattern())
00056     {
00057         compile();
00058     }
00059 }
00060 
00061 
00062 inline Foam::wordRe::wordRe(const word& str)
00063 :
00064     word(str),
00065     re_()
00066 {}
00067 
00068 
00069 inline Foam::wordRe::wordRe(const char* str, const compOption opt)
00070 :
00071     word(str, false),
00072     re_()
00073 {
00074     compile(opt);
00075 }
00076 
00077 
00078 inline Foam::wordRe::wordRe(const string& str, const compOption opt)
00079 :
00080     word(str, false),
00081     re_()
00082 {
00083     compile(opt);
00084 }
00085 
00086 
00087 inline Foam::wordRe::wordRe(const std::string& str, const compOption opt)
00088 :
00089     word(str, false),
00090     re_()
00091 {
00092     compile(opt);
00093 }
00094 
00095 
00096 // * * * * * * * * * * * * * * * Member Functions  * * * * * * * * * * * * * //
00097 
00098 inline bool Foam::wordRe::isPattern() const
00099 {
00100     return re_.exists();
00101 }
00102 
00103 
00104 inline bool Foam::wordRe::compile(const compOption opt) const
00105 {
00106     bool doCompile = false;
00107 
00108     if (opt & wordRe::REGEXP)
00109     {
00110         doCompile = true;
00111     }
00112     else if (opt & wordRe::DETECT)
00113     {
00114         if (string::meta<regExp>(*this) || !string::valid<word>(*this))
00115         {
00116             doCompile = true;
00117         }
00118     }
00119     else if (opt & wordRe::NOCASE)
00120     {
00121         doCompile = true;
00122     }
00123 
00124 
00125     if (doCompile)
00126     {
00127         re_.set(*this, (opt & wordRe::NOCASE));
00128     }
00129     else
00130     {
00131         re_.clear();
00132     }
00133 
00134     return re_.exists();
00135 }
00136 
00137 
00138 inline bool Foam::wordRe::compile() const
00139 {
00140     re_ = *this;
00141     return re_.exists();
00142 }
00143 
00144 
00145 inline bool Foam::wordRe::recompile() const
00146 {
00147     if (re_.exists())
00148     {
00149         re_ = *this;
00150     }
00151 
00152     return re_.exists();
00153 }
00154 
00155 
00156 inline void Foam::wordRe::uncompile(const bool doStripInvalid) const
00157 {
00158     if (re_.clear())
00159     {
00160         // skip stripping unless debug is active to avoid costly operations
00161         if (word::debug && doStripInvalid)
00162         {
00163             string::stripInvalid<word>
00164             (
00165                 const_cast<word&>(static_cast<const word&>(*this))
00166             );
00167         }
00168     }
00169 }
00170 
00171 
00172 inline void Foam::wordRe::clear()
00173 {
00174     word::clear();
00175     re_.clear();
00176 }
00177 
00178 
00179 inline bool Foam::wordRe::match(const string& str, bool literalMatch) const
00180 {
00181     if (literalMatch || !re_.exists())
00182     {
00183         // check as string
00184         return (*this == str);
00185     }
00186     else
00187     {
00188         // check as regex
00189         return re_.match(str);
00190     }
00191 }
00192 
00193 
00194 inline Foam::string Foam::wordRe::quotemeta() const
00195 {
00196     return string::quotemeta<regExp>(*this);
00197 }
00198 
00199 
00200 inline void Foam::wordRe::set(const std::string& str, const compOption opt)
00201 {
00202     string::operator=(str);
00203     compile(opt);
00204 }
00205 
00206 
00207 inline void Foam::wordRe::set(const char* str, const compOption opt)
00208 {
00209     string::operator=(str);
00210     compile(opt);
00211 }
00212 
00213 
00214 // * * * * * * * * * * * * * * * Member Operators  * * * * * * * * * * * * * //
00215 
00216 inline const Foam::wordRe& Foam::wordRe::operator=(const wordRe& str)
00217 {
00218     string::operator=(str);
00219 
00220     if (str.isPattern())
00221     {
00222         compile();
00223     }
00224     else
00225     {
00226         re_.clear();
00227     }
00228     return *this;
00229 }
00230 
00231 
00232 inline const Foam::wordRe& Foam::wordRe::operator=(const word& str)
00233 {
00234     word::operator=(str);
00235     re_.clear();
00236     return *this;
00237 }
00238 
00239 
00240 inline const Foam::wordRe& Foam::wordRe::operator=(const string& str)
00241 {
00242     string::operator=(str);
00243     compile(DETECT);  // auto-detect regex
00244     return *this;
00245 }
00246 
00247 
00248 inline const Foam::wordRe& Foam::wordRe::operator=(const std::string& str)
00249 {
00250     string::operator=(str);
00251     compile(DETECT);  // auto-detect regex
00252     return *this;
00253 }
00254 
00255 
00256 inline const Foam::wordRe& Foam::wordRe::operator=(const char* str)
00257 {
00258     string::operator=(str);
00259     compile(DETECT);  // auto-detect regex
00260     return *this;
00261 }
00262 
00263 
00264 // ************************************************************************* //
Copyright © 2000-2009 OpenCFD Ltd