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-------------------------------------------------------------------------------
11License
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
36namespace Foam
37{
38namespace functionEntries
39{
41 (
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// ************************************************************************* //
Macros for easy insertion into member function selection tables.
#define addNamedToMemberFunctionSelectionTable(baseType, thisType, funcName, argNames, lookupName)
Add to hash-table of functions with 'lookupName' as the key.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)....
Definition: Istream.H:64
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:126
bool remove(const word &keyword)
Remove an entry specified by keyword.
wordList toc() const
Return the table of contents.
Definition: dictionary.C:602
const_searcher searchScoped(const word &keyword, enum keyType::option matchOpt) const
Search using dot or slash scoping.
Remove a dictionary entry.
Definition: removeEntry.H:73
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
Definition: functionEntry.H:69
virtual bool execute()
Calculate the output fields.
@ LITERAL
String literal.
Definition: keyType.H:81
static constexpr uint64_t npos
Out of range position or size.
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition: wordRe.H:83
A List of wordRe with additional matching capabilities.
Definition: wordRes.H:54
Namespace for OpenFOAM.
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:87
Operations on lists of strings.