OpenFOAM
v2406
The open source CFD toolbox
dictionaryContent.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) 2021 OpenCFD Ltd.
9
-------------------------------------------------------------------------------
10
License
11
This file is part of OpenFOAM.
12
13
OpenFOAM is free software: you can redistribute it and/or modify it
14
under the terms of the GNU General Public License as published by
15
the Free Software Foundation, either version 3 of the License, or
16
(at your option) any later version.
17
18
OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
19
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
20
FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
21
for more details.
22
23
You should have received a copy of the GNU General Public License
24
along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
25
26
\*---------------------------------------------------------------------------*/
27
28
#include "
dictionaryContent.H
"
29
30
// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
31
32
namespace
Foam
33
{
34
35
template
<
class
UnaryPredicate>
36
static
dictionary
copyFilteredDict
37
(
38
const
dictionary
&
input
,
39
const
UnaryPredicate& pred
40
)
41
{
42
dictionary
dict
;
43
dict
.
name
() =
input
.
name
();
// rename
44
45
for
(
const
entry
&
e
:
input
)
46
{
47
const
keyType
&
key
=
e
.keyword();
48
49
bool
accept =
false
;
50
51
if
(
key
.isPattern())
52
{
53
// Non-trivial to filter a regex itself - so just accept it
54
// - could also have a "pruneRegex" flag (for example)
55
accept =
true
;
56
}
57
else
58
{
59
accept = pred(
key
);
60
}
61
62
if
(accept)
63
{
64
dict
.
add
(
e
,
false
);
// No merge - entries are already unique
65
}
66
}
67
68
return
dict
;
69
}
70
71
}
// End namespace Foam
72
73
74
// * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
75
76
Foam::dictionary
77
Foam::dictionaryContent::copyDict
78
(
79
const
dictionary
&
input
,
80
const
wordList
& allow,
81
const
wordList
& deny
82
)
83
{
84
if
(allow.
empty
())
85
{
86
if
(deny.
empty
())
87
{
88
// Pass-through
89
return
dictionary
(
input
);
90
}
91
92
// Deny only
93
return
copyFilteredDict
94
(
95
input
,
96
[&](
const
std::string&
key
) {
return
!deny.
found
(
key
); }
97
);
98
}
99
100
// Allow is non-empty
101
102
// No general case with deny as well
103
return
copyFilteredDict
104
(
105
input
,
106
[&](
const
std::string&
key
) {
return
allow.
found
(
key
); }
107
);
108
}
109
110
111
Foam::dictionary
112
Foam::dictionaryContent::copyDict
113
(
114
const
dictionary&
input
,
115
const
wordRes& allow,
116
const
wordRes& deny
117
)
118
{
119
if
(allow.empty())
120
{
121
if
(deny.empty())
122
{
123
// Pass-through
124
return
dictionary
(
input
);
125
}
126
127
// Deny only
128
return
copyFilteredDict
129
(
130
input
,
131
[&](
const
std::string&
key
) {
return
!deny.match(
key
); }
132
);
133
}
134
135
// Allow is non-empty
136
137
if
(deny.empty())
138
{
139
return
copyFilteredDict
140
(
141
input
,
142
[&](
const
std::string&
key
) {
return
allow.match(
key
); }
143
);
144
}
145
146
// General case - have both deny and allow
147
return
copyFilteredDict
148
(
149
input
,
150
[&](
const
std::string&
key
)
151
{
152
const
auto
result = allow.matched(
key
);
153
return
154
(
155
result ==
wordRe::LITERAL
156
?
true
157
: (result ==
wordRe::REGEX
&& !deny.match(
key
))
158
);
159
}
160
);
161
}
162
163
164
// ************************************************************************* //
Foam::keyType
A class for handling keywords in dictionaries.
Definition:
keyType.H:66
dict
dictionary dict
Definition:
searchingEngine.H:11
Foam::IOstream::name
virtual const fileName & name() const
The name of the stream.
Definition:
IOstream.C:33
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition:
dictionary.H:129
Foam::List< word >
Foam::copyFilteredDict
static dictionary copyFilteredDict(const dictionary &input, const UnaryPredicate &pred)
Definition:
dictionaryContent.C:30
Foam::UList::empty
bool empty() const noexcept
True if List is empty (ie, size() is zero)
Definition:
UList.H:675
Foam::UList::found
bool found(const T &val, label pos=0) const
Same as contains()
Definition:
UList.H:888
Foam::dictionary::add
entry * add(entry *entryPtr, bool mergeEntry=false)
Add a new entry.
Definition:
dictionary.C:625
Foam::dictionary::name
const fileName & name() const noexcept
The dictionary name.
Definition:
dictionaryI.H:41
Foam::constant::electromagnetic::e
const dimensionedScalar e
Elementary charge.
Definition:
createFields.H:11
Foam::wordRe::REGEX
Regular expression.
Definition:
wordRe.H:110
Foam::input
static Istream & input(Istream &is, IntRange< T > &range)
Definition:
IntRanges.C:33
dictionaryContent.H
Foam::dictionaryContent::copyDict
static dictionary copyDict(const dictionary &input, const wordList &allow=wordList(), const wordList &deny=wordList())
Copy construct a dictionary, filtered by simple allow/deny lists.
Definition:
dictionaryContent.C:71
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::wordRe::LITERAL
String literal.
Definition:
wordRe.H:109
writeChecksFormatType::dictionary
Foam
Namespace for OpenFOAM.
Definition:
atmBoundaryLayer.C:26
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition:
entry.H:63
src
OpenFOAM
db
dictionary
dictionaryContent
dictionaryContent.C
Generated by
1.8.14