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-2019 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 // * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * //
32 
33 namespace
34 {
35 
36 // Should issue warning if there is +ve versioning (+ve version number)
37 // and the this version number is older than the current OpenFOAM version
38 // as conveyed by the OPENFOAM compiler define.
39 
40 static inline constexpr bool shouldWarnVersion(const int version)
41 {
42  return (version > 0 && version < OPENFOAM);
43 }
44 
45 } // End anonymous namespace
46 
47 
48 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
49 
51 (
52  const word& keyword,
53  std::initializer_list<std::pair<const char*,int>> compat,
54  enum keyType::option matchOpt
55 ) const
56 {
57  const_searcher finder(csearch(keyword, matchOpt));
58 
59  if (finder.good())
60  {
61  return finder;
62  }
63 
64  for (const std::pair<const char*,int>& iter : compat)
65  {
66  finder = csearch(word::validate(iter.first), matchOpt);
67 
68  if (finder.good())
69  {
70  // Want single warning (on master), but guard with parRun to avoid
71  // Pstream::master() when Pstream has not yet been initialized
72  if
73  (
74  shouldWarnVersion(iter.second)
75  && (Pstream::parRun() ? Pstream::master() : true)
76  )
77  {
78  std::cerr
79  << "--> FOAM IOWarning :" << nl
80  << " Found [v" << iter.second << "] '"
81  << iter.first << "' entry instead of '"
82  << keyword.c_str() << "' in dictionary \""
83  << name().c_str() << "\" "
84  << nl
85  << std::endl;
86 
87  error::warnAboutAge("keyword", iter.second);
88  }
89 
90  break;
91  }
92  }
93 
94  return finder;
95 }
96 
97 
99 (
100  const word& keyword,
101  std::initializer_list<std::pair<const char*,int>> compat,
102  enum keyType::option matchOpt
103 ) const
104 {
105  return csearchCompat(keyword, compat, matchOpt).good();
106 }
107 
108 
110 (
111  const word& keyword,
112  std::initializer_list<std::pair<const char*,int>> compat,
113  enum keyType::option matchOpt
114 ) const
115 {
116  return csearchCompat(keyword, compat, matchOpt).ptr();
117 }
118 
119 
121 (
122  const word& keyword,
123  std::initializer_list<std::pair<const char*,int>> compat,
124  enum keyType::option matchOpt
125 ) const
126 {
127  const const_searcher finder(csearchCompat(keyword, compat, matchOpt));
128 
129  if (!finder.good())
130  {
132  << "Entry '" << keyword << "' not found in dictionary "
133  << name()
134  << exit(FatalIOError);
135  }
136 
137  return finder.ref();
138 }
139 
140 
142 (
143  const word& keyword,
144  std::initializer_list<std::pair<const char*,int>> compat,
145  enum keyType::option matchOpt
146 ) const
147 {
148  return lookupEntryCompat(keyword, compat, matchOpt).stream();
149 }
150 
151 
152 // ************************************************************************* //
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:62
validate
thermo validate(args.executable(), "h")
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:99
Foam::endl
Ostream & endl(Ostream &os)
Add newline and flush stream.
Definition: Ostream.H:350
Foam::dictionary::Searcher
Generic const/non-const dictionary entry searcher.
Definition: dictionary.H:138
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:121
Foam::ITstream
An input stream of tokens.
Definition: ITstream.H:55
Foam::name
word name(const complex &c)
Return string representation of complex.
Definition: complex.C:76
Foam::dictionary::Searcher::good
bool good() const
True if entry was found.
Definition: dictionary.H:198
Pstream.H
Foam::exit
errorManipArg< error, int > exit(error &err, const int errNo=1)
Definition: errorManip.H:130
Foam::foamVersion::version
const std::string version
OpenFOAM version (name or stringified number) as a std::string.
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:51
Foam::nl
constexpr char nl
Definition: Ostream.H:385
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:142
dictionary.H
FatalIOErrorInFunction
#define FatalIOErrorInFunction(ios)
Report an error message using Foam::FatalIOError.
Definition: error.H:401
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:110
Foam::dictionary::Searcher::ref
reference ref() const
A reference to the entry (Error if not found)
Definition: dictionary.H:222
Foam::keyType::option
option
Enumeration for the data type and search/match modes (bitmask)
Definition: keyType.H:70