removeEntry.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 | www.openfoam.com
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8  Copyright (C) 2011 OpenFOAM Foundation
9  Copyright (C) 2017-2019 OpenCFD Ltd.
10 -------------------------------------------------------------------------------
11 License
12  This file is part of OpenFOAM.
13 
14  OpenFOAM is free software: you can redistribute it and/or modify it
15  under the terms of the GNU General Public License as published by
16  the Free Software Foundation, either version 3 of the License, or
17  (at your option) any later version.
18 
19  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
20  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
21  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
22  for more details.
23 
24  You should have received a copy of the GNU General Public License
25  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
26 
27 \*---------------------------------------------------------------------------*/
28 
29 #include "removeEntry.H"
30 #include "dictionary.H"
31 #include "stringListOps.H"
33 
34 // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * //
35 
36 namespace Foam
37 {
38 namespace functionEntries
39 {
41  (
42  functionEntry,
43  removeEntry,
44  execute,
45  dictionaryIstream,
46  remove
47  );
48 } // End namespace functionEntries
49 } // End namespace Foam
50 
51 
52 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
53 
55 (
56  dictionary& parentDict,
57  Istream& is
58 )
59 {
60  const wordRes patterns(functionEntry::readStringList<wordRe>(is));
61 
62  for (const wordRe& key : patterns)
63  {
64  if (key.isLiteral() && key.find('/') != string::npos)
65  {
66  // Remove scoped keyword, or keyword in the local scope
67  auto finder(parentDict.searchScoped(key, keyType::LITERAL));
68 
69  if (finder.good())
70  {
71  finder.context().remove(finder.ptr()->keyword());
72  }
73  }
74  else
75  {
76  // Remove by pattern
77  const wordList dictKeys = parentDict.toc();
78  const labelList indices = findStrings(key, dictKeys);
79 
80  for (const auto idx : indices)
81  {
82  parentDict.remove(dictKeys[idx]);
83  }
84  }
85  }
86 
87  return true;
88 }
89 
90 
91 // ************************************************************************* //
Foam::labelList
List< label > labelList
A List of labels.
Definition: List.H:63
removeEntry.H
Foam::glTF::key
auto key(const Type &t) -> typename std::enable_if< std::is_enum< Type >::value, typename std::underlying_type< Type >::type >::type
Definition: foamGltfBase.H:103
Foam::dictionary::searchScoped
const_searcher searchScoped(const word &keyword, enum keyType::option) const
Definition: dictionarySearch.C:348
Foam::wordRe
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:78
Foam::functionEntries::removeEntry::execute
static bool execute(dictionary &parentDict, Istream &is)
Definition: removeEntry.C:48
Foam::wordList
List< word > wordList
A List of words.
Definition: fileName.H:58
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:57
addToMemberFunctionSelectionTable.H
Macros for easy insertion into member function selection tables.
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:119
Foam::functionEntries::addNamedToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, dictionaryIstream, calc)
Foam
Definition: atmBoundaryLayer.C:26
Foam::findStrings
labelList findStrings(const regExp &matcher, const UList< StringType > &input, const bool invert=false)
Definition: stringListOps.H:83
Foam::dictionary::remove
bool remove(const word &keyword)
Definition: dictionarySearch.C:575
Foam::List
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
Definition: BitOps.H:58
dictionary.H
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:47
stringListOps.H
Operations on lists of strings.
Foam::dictionary::toc
wordList toc() const
Definition: dictionary.C:595
Foam::keyType::LITERAL
@ LITERAL
String literal.
Definition: keyType.H:79