dictionaryCompat.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) 2017-2021 OpenCFD Ltd.
9-------------------------------------------------------------------------------
10License
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 "dictionary.H"
29#include "Pstream.H"
30
31// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
32
34(
35 const word& keyword,
36 std::initializer_list<std::pair<const char*,int>> compat,
37 enum keyType::option matchOpt
38) const
39{
40 const_searcher finder(csearch(keyword, matchOpt));
41
42 if (finder.good())
43 {
44 return finder;
45 }
46
47 for (const std::pair<const char*,int>& alt : compat)
48 {
49 finder = csearch(word::validate(alt.first), matchOpt);
50
51 if (finder.good())
52 {
53 if (error::warnAboutAge(alt.second) && error::master())
54 {
55 std::cerr
56 << "--> FOAM IOWarning :" << nl
57 << " Found [v" << alt.second << "] '"
58 << alt.first << "' entry instead of '"
59 << keyword.c_str() << "' in dictionary \""
60 << relativeName() << '"' << nl
61 << std::endl;
62
63 error::warnAboutAge("keyword", alt.second);
64 }
65
66 break;
67 }
68 }
69
70 return finder;
71}
72
73
75(
76 const word& keyword,
77 std::initializer_list<std::pair<const char*,int>> compat,
78 enum keyType::option matchOpt
79) const
80{
81 return csearchCompat(keyword, compat, matchOpt).good();
82}
83
84
86(
87 const word& keyword,
88 std::initializer_list<std::pair<const char*,int>> compat,
89 enum keyType::option matchOpt
90) const
91{
92 return csearchCompat(keyword, compat, matchOpt).ptr();
93}
94
95
97(
98 const word& keyword,
99 std::initializer_list<std::pair<const char*,int>> compat,
100 enum keyType::option matchOpt
101) const
102{
103 const const_searcher finder(csearchCompat(keyword, compat, matchOpt));
104
105 if (!finder.good())
106 {
108 << "Entry '" << keyword << "' not found in dictionary "
109 << relativeName()
110 << exit(FatalIOError);
111 }
112
113 return finder.ref();
114}
115
116
118(
119 const word& keyword,
120 std::initializer_list<std::pair<const char*,int>> compat,
121 enum keyType::option matchOpt
122) const
123{
124 return lookupEntryCompat(keyword, compat, matchOpt).stream();
125}
126
127
128// ************************************************************************* //
An input stream of tokens.
Definition: ITstream.H:56
Generic const/non-const dictionary entry searcher.
Definition: dictionary.H:141
bool good() const noexcept
True if entry was found.
Definition: dictionary.H:201
reference ref() const
A reference to the entry (Error if not found)
Definition: dictionary.H:225
const entry * findCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, enum keyType::option matchOpt) const
bool foundCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword and any compatibility names.
const_searcher csearchCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword and any compatibility names.
fileName relativeName(const bool caseTag=false) const
The dictionary name relative to the case.
Definition: dictionary.C:186
ITstream & lookupCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, enum keyType::option matchOpt=keyType::REGEX) const
const entry & lookupEntryCompat(const word &keyword, std::initializer_list< std::pair< const char *, int > > compat, enum keyType::option matchOpt) const
const_searcher csearch(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search dictionary for given keyword.
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:70
static bool warnAboutAge(const int version) noexcept
Test if an age warning should be emitted.
Definition: error.C:55
virtual void validate()
Validate the turbulence fields after construction.
Definition: kkLOmega.C:597
option
Enumeration for the data type and search/match modes (bitmask)
Definition: keyType.H:79
splitCell * master() const
Definition: splitCell.H:113
A class for handling words, derived from Foam::string.
Definition: word.H:68
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
IOerror FatalIOError
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
constexpr char nl
The newline '\n' character (0x0a)
Definition: Ostream.H:53