FreeFOAM The Cross-Platform CFD Toolkit
stringListOpsTemplates.C
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration |
5  \\ / A nd | Copyright (C) 1991-2010 OpenCFD Ltd.
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 \*---------------------------------------------------------------------------*/
25 
26 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
27 
28 template<class Matcher, class StringType>
30 (
31  const Matcher& matcher,
32  const UList<StringType>& lst,
33  const bool invert
34 )
35 {
36  labelList indices(lst.size());
37 
38  label nElem = 0;
39  forAll(lst, elemI)
40  {
41  if (matcher.match(lst[elemI]) ? !invert : invert)
42  {
43  indices[nElem++] = elemI;
44  }
45  }
46  indices.setSize(nElem);
47 
48  return indices;
49 }
50 
51 
52 template<class Matcher, class StringListType>
53 StringListType Foam::subsetMatchingStrings
54 (
55  const Matcher& matcher,
56  const StringListType& lst,
57  const bool invert
58 )
59 {
60  StringListType newLst(lst.size());
61 
62  label nElem = 0;
63  forAll(lst, elemI)
64  {
65  if (matcher.match(lst[elemI]) ? !invert : invert)
66  {
67  newLst[nElem++] = lst[elemI];
68  }
69  }
70  newLst.setSize(nElem);
71 
72  return newLst;
73 }
74 
75 
76 template<class Matcher, class StringListType>
78 (
79  const Matcher& matcher,
80  StringListType& lst,
81  const bool invert
82 )
83 {
84  label nElem = 0;
85  forAll(lst, elemI)
86  {
87  if (matcher.match(lst[elemI]) ? !invert : invert)
88  {
89  lst[nElem++] = lst[elemI];
90  }
91  }
92  lst.setSize(nElem);
93 }
94 
95 
96 // ************************ vim: set sw=4 sts=4 et: ************************ //