dictionaryI.H
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 "dictionary.H"
29 
30 // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * //
31 
33 {
34  return writeOptionalEntries;
35 }
36 
37 
38 inline int Foam::dictionary::reportOptional(const int level) noexcept
39 {
40  int old(writeOptionalEntries);
41  writeOptionalEntries = level;
42  return old;
43 }
44 
45 
46 // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
47 
49 {
50  return name_;
51 }
52 
53 
55 {
56  return name_;
57 }
58 
59 
61 {
62  word scopedName(name_.name());
63 
64  const auto i = scopedName.rfind('.');
65  if (i == std::string::npos)
66  {
67  return scopedName;
68  }
69 
70  return scopedName.substr(i+1);
71 }
72 
73 
74 inline bool Foam::dictionary::isNullDict() const noexcept
75 {
76  return (this == &dictionary::null);
77 }
78 
79 
81 {
82  return parent_;
83 }
84 
85 
87 (
88  const word& keyword,
89  enum keyType::option matchOpt
90 ) const
91 {
92  return csearch(keyword, matchOpt).ptr();
93 }
94 
95 
97 (
98  const word& keyword,
99  enum keyType::option matchOpt
100 )
101 {
102  return const_cast<entry*>(csearch(keyword, matchOpt).ptr());
103 }
104 
105 
106 inline bool Foam::dictionary::found
107 (
108  const word& keyword,
109  enum keyType::option matchOpt
110 ) const
111 {
112  return static_cast<bool>(findEntry(keyword, matchOpt));
113 }
114 
115 
117 (
118  const word& keyword,
119  enum keyType::option matchOpt
120 ) const
121 {
122  return csearchScoped(keyword, matchOpt).ptr();
123 }
124 
125 
127 (
128  const word& keyword,
129  enum keyType::option matchOpt
130 ) const
131 {
132  return csearch(keyword, matchOpt).dictPtr();
133 }
134 
135 
137 (
138  const word& keyword,
139  enum keyType::option matchOpt
140 )
141 {
142  return const_cast<dictionary*>(csearch(keyword, matchOpt).dictPtr());
143 }
144 
145 
146 inline bool Foam::dictionary::isDict
147 (
148  const word& keyword,
149  enum keyType::option matchOpt
150 ) const
151 {
152  return static_cast<bool>(findDict(keyword, matchOpt));
153 }
154 
155 
156 // ************************************************************************* //
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionaryI.H:53
static int reportOptional() noexcept
Return the state of reporting optional (default) entries.
Definition: dictionaryI.H:25
A class for handling file names.
Definition: fileName.H:71
A list of keyword definitions, which are a keyword followed by a number of values (eg...
Definition: dictionary.H:120
const entry * findEntry(const dictionary &dict, const label val)
Linear search for labelled entry, nullptr if not found.
const fileName & name() const noexcept
The dictionary name.
Definition: dictionaryI.H:41
const entry * findScoped(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for a scoped entry (const access) with the given keyword.
Definition: dictionaryI.H:110
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:100
const dictionary & parent() const noexcept
Return the parent dictionary.
Definition: dictionaryI.H:73
A class for handling words, derived from Foam::string.
Definition: word.H:63
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:465
const direction noexcept
Definition: Scalar.H:258
static int writeOptionalEntries
Report optional keywords and values if not present in dictionary.
Definition: dictionary.H:460
bool isDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find a sub-dictionary.
Definition: dictionaryI.H:140
option
Enumeration for the data type and search/match modes (bitmask)
Definition: keyType.H:79
const entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find an entry (const access) with the given keyword.
Definition: dictionaryI.H:80
bool isNullDict() const noexcept
The dictionary is actually dictionary::null (root dictionary)
Definition: dictionaryI.H:67
A keyword and a list of tokens is an &#39;entry&#39;.
Definition: entry.H:63
const dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Find and return a sub-dictionary pointer if present (and a sub-dictionary) otherwise return nullptr...
Definition: dictionaryI.H:120