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 -------------------------------------------------------------------------------
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 "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 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::FatalIOError
IOerror FatalIOError
Foam::dictionary::foundCompat
bool foundCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option=keyType::REGEX) const
Search dictionary for given keyword and any compatibility names.
Definition: dictionaryCompat.C:75
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:369
Foam::dictionary::Searcher
Generic const/non-const dictionary entry searcher.
Definition: dictionary.H:140
Foam::dictionary::lookupEntryCompat
const entry & lookupEntryCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option) const
Definition: dictionaryCompat.C:97
Foam::ITstream
An input stream of tokens.
Definition: ITstream.H:52
Pstream.H
Foam::dictionary::Searcher::good
bool good() const noexcept
True if entry was found.
Definition: dictionary.H:201
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::dictionary::csearchCompat
const_searcher csearchCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option=keyType::REGEX) const
Search dictionary for given keyword and any compatibility names.
Definition: dictionaryCompat.C:34
Foam::nl
constexpr char nl
Definition: Ostream.H:404
Foam::dictionary::lookupCompat
ITstream & lookupCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option=keyType::REGEX) const
Definition: dictionaryCompat.C:118
dictionary.H
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:473
Foam::stringOps::validate
StringType validate(const std::string &str, const UnaryPredicate &accept, const bool invert=false)
Return a copy of the input string with validated characters.
Definition: stringOpsTemplates.C:71
Foam::dictionary::findCompat
const entry * findCompat(const word &keyword, std::initializer_list< std::pair< const char *, int >> compat, enum keyType::option) const
Definition: dictionaryCompat.C:86
Foam::dictionary::Searcher::ref
reference ref() const
A reference to the entry (Error if not found)
Definition: dictionary.H:225
Foam::keyType::option
option
Enumeration for the data type and search/match modes (bitmask)
Definition: keyType.H:78