Loading...
Searching...
No Matches
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-2024 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 "wordRes.H"
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{
61
62 for (const wordRe& key : patterns)
63 {
64 if (key.isLiteral() && key.contains('/'))
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 = wordRes::matching(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:60
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition dictionary.H:133
bool remove(const word &keyword)
Remove an entry specified by keyword.
wordList toc() const
Return the table of contents.
Definition dictionary.C:587
const_searcher searchScoped(const word &keyword, enum keyType::option matchOpt) const
Search using dot or slash scoping.
Remove a dictionary entry.
Definition removeEntry.H:69
static bool execute(dictionary &parentDict, Istream &is)
Remove single or multiple entries. Local or scoped entries.
Definition removeEntry.C:48
A functionEntry causes entries to be added/manipulated on the specified dictionary given an input str...
static List< StringType > readStringList(Istream &is)
Read a List of strings values, treating a single entry like a list of size 1.
@ LITERAL
String literal.
Definition keyType.H:82
A wordRe is a Foam::word, but can contain a regular expression for matching words or strings.
Definition wordRe.H:81
A List of wordRe with additional matching capabilities.
Definition wordRes.H:56
static labelList matching(const wordRe &select, const UList< StringType > &input, const bool invert=false)
Determine the list indices for all matches.
Namespace for containing a functionEntry.
Definition calcEntry.C:33
Namespace for OpenFOAM.
List< word > wordList
List of word.
Definition fileName.H:60
List< label > labelList
A List of labels.
Definition List.H:62