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 // ************************************************************************* //
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:108
Foam::dictionary::searchScoped
const_searcher searchScoped(const word &keyword, enum keyType::option) const
Search using dot or slash scoping.
Definition: dictionarySearch.C:355
Foam::wordRe
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:80
Foam::functionEntries::removeEntry::execute
static bool execute(dictionary &parentDict, Istream &is)
Remove single or multiple entries. Local or scoped entries.
Definition: removeEntry.C:55
Foam::Istream
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:61
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:123
Foam::functionEntries::addNamedToMemberFunctionSelectionTable
addNamedToMemberFunctionSelectionTable(functionEntry, calcEntry, execute, dictionaryIstream, calc)
Foam
Namespace for OpenFOAM.
Definition: atmBoundaryLayer.C:33
Foam::findStrings
labelList findStrings(const regExp &matcher, const UList< StringType > &input, const bool invert=false)
Return list indices for strings matching the regular expression.
Definition: stringListOps.H:86
Foam::dictionary::remove
bool remove(const word &keyword)
Remove an entry specified by keyword.
Definition: dictionarySearch.C:582
Foam::List< word >
dictionary.H
Foam::wordRes
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:51
stringListOps.H
Operations on lists of strings.
Foam::dictionary::toc
wordList toc() const
Return the table of contents.
Definition: dictionary.C:602