demandDrivenEntry.H
Go to the documentation of this file.
1 /*---------------------------------------------------------------------------*\
2  ========= |
3  \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
4  \\ / O peration | Website: https://openfoam.org
5  \\ / A nd | Copyright (C) 2013-2020 OpenFOAM Foundation
6  \\/ M anipulation |
7 -------------------------------------------------------------------------------
8 License
9  This file is part of OpenFOAM.
10 
11  OpenFOAM is free software: you can redistribute it and/or modify it
12  under the terms of the GNU General Public License as published by
13  the Free Software Foundation, either version 3 of the License, or
14  (at your option) any later version.
15 
16  OpenFOAM is distributed in the hope that it will be useful, but WITHOUT
17  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19  for more details.
20 
21  You should have received a copy of the GNU General Public License
22  along with OpenFOAM. If not, see <http://www.gnu.org/licenses/>.
23 
24 Class
25  Foam::demandDrivenEntry
26 
27 Description
28  Class for demand-driven dictionary entries
29 
30  Holds a reference to a dictionary, which is then queried if the value
31  is requested and has not already been cached
32 
33 SourceFiles
34  demandDrivenEntry.C
35  demandDrivenEntryI.H
36 
37 \*---------------------------------------------------------------------------*/
38 
39 #ifndef demandDrivenEntry_H
40 #define demandDrivenEntry_H
41 
42 #include "dictionary.H"
43 
44 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
45 
46 namespace Foam
47 {
48 
49 /*---------------------------------------------------------------------------*\
50  Class demandDrivenEntry Declaration
51 \*---------------------------------------------------------------------------*/
52 
53 template<class Type>
55 {
56  // Private Data
57 
58  //- Reference to the dictionary
59  const dictionary& dict_;
60 
61  //- Keyword to look up
62  const word keyword_;
63 
64  //- Value
65  mutable Type value_;
66 
67  //- Flag to say that the value has been stored
68  mutable bool stored_;
69 
70 
71 public:
72 
73  //- Constructors
74 
75  //- Construct from dictionary and value - cannot be re-read
77  (
78  const dictionary& dict,
79  const Type& value
80  );
81 
82 
83  //- Construct from dictionary and keyword
85  (
86  const dictionary& dict,
87  const word& keyword
88  );
89 
90 
91  //- Construct from dictionary, keyword and default value
93  (
94  const dictionary& dict,
95  const word& keyword,
96  const Type& defaultValue,
97  const bool readIfPresent = true
98  );
99 
100  //- Copy constructor
102 
103 
104  // Public Member Functions
105 
106  //- Initialise
107  inline void initialise() const;
108 
109  //- Return the value
110  inline const Type& value() const;
111 
112  //- Set the value
113  inline void setValue(const Type& value);
114 
115  //- Reset the demand-driven entry
116  inline void reset();
117 };
118 
119 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
120 
121 } // End namespace Foam
122 
123 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
124 
125 #include "demandDrivenEntryI.H"
126 
127 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
128 
129 #ifdef NoRepository
130  #include "demandDrivenEntry.C"
131 #endif
132 
133 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
134 
135 #endif
136 
137 // ************************************************************************* //
dictionary dict
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:156
Class for demand-driven dictionary entries.
const Type & value() const
Return the value.
A class for handling words, derived from string.
Definition: word.H:59
void initialise() const
Initialise.
void reset()
Reset the demand-driven entry.
demandDrivenEntry(const dictionary &dict, const Type &value)
Constructors.
void setValue(const Type &value)
Set the value.
Namespace for OpenFOAM.