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

stringListOps.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 InNamspace
00025     Foam
00026 
00027 Description
00028     Operations on lists of strings.
00029 
00030 SourceFiles
00031     stringListOpsTemplates.C
00032 
00033 \*---------------------------------------------------------------------------*/
00034 
00035 #ifndef stringListOps_H
00036 #define stringListOps_H
00037 
00038 #include <OSspecific/regExp.H>
00039 #include "labelList.H"
00040 #include "stringList.H"
00041 #include "wordReList.H"
00042 #include "wordReListMatcher.H"
00043 
00044 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00045 
00046 namespace Foam
00047 {
00048     // single-string matches:
00049 
00050     //- Return true if string matches one of the regular expressions
00051     inline bool findStrings
00052     (
00053         const wordReListMatcher& matcher,
00054         const std::string& str
00055     )
00056     {
00057         return matcher.match(str);
00058     }
00059 
00060     // multi-string matches:
00061 
00062     //- Return list indices for matching strings
00063     template<class Matcher, class StringType>
00064     labelList findMatchingStrings
00065     (
00066         const Matcher&,
00067         const UList<StringType>&,
00068         const bool invert=false
00069     );
00070 
00071     //- Return list indices for strings matching the regular expression
00072     //  Template partial specialization of findMatchingStrings
00073     template<class StringType>
00074     labelList findStrings
00075     (
00076         const regExp& re,
00077         const UList<StringType>& lst,
00078         const bool invert=false
00079     )
00080     {
00081         return findMatchingStrings(re, lst, invert);
00082     }
00083 
00084     //- Return list indices for strings matching the regular expression
00085     //  Template partial specialization of findMatchingStrings
00086     template<class StringType>
00087     labelList findStrings
00088     (
00089         const char* rePattern,
00090         const UList<StringType>& lst,
00091         const bool invert=false
00092     )
00093     {
00094         regExp re(rePattern);
00095         return findStrings(re, lst, invert);
00096     }
00097 
00098     //- Return list indices for strings matching the regular expression
00099     //  Template partial specialization of findMatchingStrings
00100     template<class StringType>
00101     labelList findStrings
00102     (
00103         const std::string& rePattern,
00104         const UList<StringType>& lst,
00105         const bool invert=false
00106     )
00107     {
00108         regExp re(rePattern);
00109         return findMatchingStrings(re, lst, invert);
00110     }
00111 
00112     //- Return list indices for strings matching the regular expression
00113     //  Template partial specialization of findMatchingStrings
00114     template<class StringType>
00115     labelList findStrings
00116     (
00117         const wordRe& wre,
00118         const UList<StringType>& lst,
00119         const bool invert=false
00120     )
00121     {
00122         return findMatchingStrings(wre, lst, invert);
00123     }
00124 
00125 
00126     //- Return list indices for strings matching one of the regular expression
00127     //  Template partial specialization of findMatchingStrings
00128     template<class StringType>
00129     labelList findStrings
00130     (
00131         const wordReListMatcher& matcher,
00132         const UList<StringType>& lst,
00133         const bool invert=false
00134     )
00135     {
00136         return findMatchingStrings(matcher, lst, invert);
00137     }
00138 
00139     // subsetting multi-string matches (similar to ListOp):
00140 
00141     //- Extract elements of StringList when regular expression matches
00142     //  optionally invert the match
00143     //  eg, to extract all selected elements:
00144     //    subsetMatchingStrings<regExp, stringList>(myRegExp, lst);
00145     template<class Matcher, class StringListType>
00146     StringListType subsetMatchingStrings
00147     (
00148         const Matcher&,
00149         const StringListType&,
00150         const bool invert=false
00151     );
00152 
00153     //- Extract elements of StringList when regular expression matches
00154     //  Template partial specialization of subsetMatchingStrings
00155     template<class StringListType>
00156     StringListType subsetStrings
00157     (
00158         const regExp& re,
00159         const StringListType& lst,
00160         const bool invert=false
00161     )
00162     {
00163         return subsetMatchingStrings(re, lst, invert);
00164     }
00165 
00166     //- Extract elements of StringList when regular expression matches
00167     //  Template partial specialization of subsetMatchingStrings
00168     template<class StringListType>
00169     StringListType subsetStrings
00170     (
00171         const char* rePattern,
00172         const StringListType& lst,
00173         const bool invert=false
00174     )
00175     {
00176         regExp re(rePattern);
00177         return subsetMatchingStrings(re, lst, invert);
00178     }
00179 
00180     //- Extract elements of StringList when regular expression matches
00181     //  Template partial specialization of subsetMatchingStrings
00182     template<class StringListType>
00183     StringListType subsetStrings
00184     (
00185         const std::string& rePattern,
00186         const StringListType& lst,
00187         const bool invert=false
00188     )
00189     {
00190         regExp re(rePattern);
00191         return subsetMatchingStrings(re, lst, invert);
00192     }
00193 
00194     //- Extract elements of StringList when regular expression matches
00195     //  Template partial specialization of subsetMatchingStrings
00196     template<class StringListType>
00197     StringListType subsetStrings
00198     (
00199         const wordRe& wre,
00200         const StringListType& lst,
00201         const bool invert=false
00202     )
00203     {
00204         return subsetMatchingStrings(wre, lst, invert);
00205     }
00206 
00207     //- Extract elements of StringList when regular expression matches
00208     //  Template partial specialization of subsetMatchingStrings
00209     template<class StringListType>
00210     StringListType subsetStrings
00211     (
00212         const wordReListMatcher& matcher,
00213         const StringListType& lst,
00214         const bool invert=false
00215     )
00216     {
00217         return subsetMatchingStrings(matcher, lst, invert);
00218     }
00219 
00220 
00221     //- Inplace extract elements of StringList when regular expression matches
00222     //  optionally invert the match
00223     //  eg, to extract all selected elements:
00224     //    inplaceSubsetMatchingStrings<regExp, stringList>(myRegExp, lst);
00225     template<class Matcher, class StringListType>
00226     void inplaceSubsetMatchingStrings
00227     (
00228         const Matcher&,
00229         StringListType&,
00230         const bool invert=false
00231     );
00232 
00233     //- Inplace extract elements of StringList when regular expression matches
00234     //  Template partial specialization of inplaceSubsetMatchingStrings
00235     template<class StringListType>
00236     void inplaceSubsetStrings
00237     (
00238         const regExp& re,
00239         StringListType& lst,
00240         const bool invert=false
00241     )
00242     {
00243         inplaceSubsetMatchingStrings(re, lst, invert);
00244     }
00245 
00246     //- Inplace extract elements of StringList when regular expression matches
00247     //  Template partial specialization of inplaceSubsetMatchingStrings
00248     template<class StringListType>
00249     void inplaceSubsetStrings
00250     (
00251         const char* rePattern,
00252         StringListType& lst,
00253         const bool invert=false
00254     )
00255     {
00256         regExp re(rePattern);
00257         inplaceSubsetMatchingStrings(re, lst, invert);
00258     }
00259 
00260     //- Inplace extract elements of StringList when regular expression matches
00261     //  Template partial specialization of inplaceSubsetMatchingStrings
00262     template<class StringListType>
00263     void inplaceSubsetStrings
00264     (
00265         const std::string& rePattern,
00266         StringListType& lst,
00267         const bool invert=false
00268     )
00269     {
00270         regExp re(rePattern);
00271         inplaceSubsetMatchingStrings(re, lst, invert);
00272     }
00273 
00274     //- Inplace extract elements of StringList when regular expression matches
00275     //  Template partial specialization of inplaceSubsetMatchingStrings
00276     template<class StringListType>
00277     void inplaceSubsetStrings
00278     (
00279         const wordRe& wre,
00280         StringListType& lst,
00281         const bool invert=false
00282     )
00283     {
00284         inplaceSubsetMatchingStrings(wre, lst, invert);
00285     }
00286 
00287     //- Inplace extract elements of StringList when regular expression matches
00288     //  Template partial specialization of inplaceSubsetMatchingStrings
00289     template<class StringListType>
00290     void inplaceSubsetStrings
00291     (
00292         const wordReListMatcher& matcher,
00293         StringListType& lst,
00294         const bool invert=false
00295     )
00296     {
00297         inplaceSubsetMatchingStrings(matcher, lst, invert);
00298     }
00299 
00300 }
00301 
00302 
00303 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00304 
00305 #ifdef NoRepository
00306 #   include "stringListOpsTemplates.C"
00307 #endif
00308 
00309 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
00310 
00311 #endif
00312 
00313 // ************************ vim: set sw=4 sts=4 et: ************************ //
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines