FreeFOAM The Cross-Platform CFD Toolkit
Hosted by SourceForge:
Get FreeFOAM at SourceForge.net.
            Fast, secure and Free Open Source software downloads

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