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 
32 inline int Foam::dictionary::reportOptional() noexcept
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 
48 inline const Foam::fileName& Foam::dictionary::name() const noexcept
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 
80 inline const Foam::dictionary& Foam::dictionary::parent() const noexcept
81 {
82  return parent_;
83 }
84 
85 
86 inline bool Foam::dictionary::found
87 (
88  const word& keyword,
89  enum keyType::option matchOpt
90 ) const
91 {
92  return csearch(keyword, matchOpt).good();
93 }
94 
95 
97 (
98  const word& keyword,
99  enum keyType::option matchOpt
100 )
101 {
102  return search(keyword, matchOpt).ptr();
103 }
104 
105 
107 (
108  const word& keyword,
109  enum keyType::option matchOpt
110 ) const
111 {
112  return csearch(keyword, matchOpt).ptr();
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 )
131 {
132  return search(keyword, matchOpt).dictPtr();
133 }
134 
135 
137 (
138  const word& keyword,
139  enum keyType::option matchOpt
140 ) const
141 {
142  return 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 csearch(keyword, matchOpt).isDict();
153 }
154 
155 
156 // ************************************************************************* //
Foam::entry
A keyword and a list of tokens is an 'entry'.
Definition: entry.H:67
Foam::dictionary::findDict
dictionary * findDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find and return a sub-dictionary pointer if present.
Definition: dictionaryI.H:127
Foam::word
A class for handling words, derived from Foam::string.
Definition: word.H:65
Foam::fileName
A class for handling file names.
Definition: fileName.H:73
Foam::dictionary::found
bool found(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Search for an entry (const access) with the given keyword.
Definition: dictionaryI.H:87
Foam::dictionary::name
const fileName & name() const noexcept
The dictionary name.
Definition: dictionaryI.H:48
Foam::dictionary::null
static const dictionary null
An empty dictionary, which is also the parent for all dictionaries.
Definition: dictionary.H:392
Foam::dictionary
A list of keyword definitions, which are a keyword followed by a number of values (eg,...
Definition: dictionary.H:123
Foam::dictionary::writeOptionalEntries
static int writeOptionalEntries
Report optional keywords and values if not present in dictionary.
Definition: dictionary.H:389
Foam::dictionary::isDict
bool isDict(const word &keyword, enum keyType::option matchOpt=keyType::REGEX) const
Check if entry is found and is a sub-dictionary.
Definition: dictionaryI.H:147
Foam::dictionary::parent
const dictionary & parent() const noexcept
Return the parent dictionary.
Definition: dictionaryI.H:80
Foam::dictionary::reportOptional
static int reportOptional() noexcept
Return the state of reporting optional (default) entries.
Definition: dictionaryI.H:32
Foam::dictionary::findScoped
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:117
Foam::dictionary::findEntry
entry * findEntry(const word &keyword, enum keyType::option matchOpt=keyType::REGEX)
Find for an entry (non-const access) with the given keyword.
Definition: dictionaryI.H:97
dictionary.H
Foam::search
fileName search(const word &file, const fileName &directory)
Recursively search the given directory for the file.
Definition: fileName.C:571
Foam::keyType::option
option
Enumeration for the data type and search/match modes (bitmask)
Definition: keyType.H:78
Foam::dictionary::isNullDict
bool isNullDict() const noexcept
The dictionary is actually dictionary::null (root dictionary)
Definition: dictionaryI.H:74
Foam::dictionary::dictName
word dictName() const
The local dictionary name (final part of scoped name)
Definition: dictionaryI.H:60