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-2018 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:
57 
58  // Private data
59 
60  //- Reference to the dictionary
61  const dictionary& dict_;
62 
63  //- Keyword to look up
64  const word keyword_;
65 
66  //- Value
67  mutable Type value_;
68 
69  //- Flag to say that the value has been stored
70  mutable bool stored_;
71 
72 
73 public:
74 
75  //- Constructors
76 
77  //- Construct from dictionary and value - cannot be re-read
79  (
80  const dictionary& dict,
81  const Type& value
82  );
83 
84 
85  //- Construct from dictionary and keyword
87  (
88  const dictionary& dict,
89  const word& keyword
90  );
91 
92 
93  //- Construct from dictionary, keyword and default value
95  (
96  const dictionary& dict,
97  const word& keyword,
98  const Type& defaultValue,
99  const bool readIfPresent = true
100  );
101 
102  //- Copy constructor
104 
105 
106  // Public Member Functions
107 
108  //- Initialise
109  inline void initialise() const;
110 
111  //- Return the value
112  inline const Type& value() const;
113 
114  //- Set the value
115  inline void setValue(const Type& value);
116 
117  //- Reset the demand-driven entry
118  inline void reset();
119 };
120 
121 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
122 
123 } // End namespace Foam
124 
125 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
126 
127 #include "demandDrivenEntryI.H"
128 
129 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
130 
131 #ifdef NoRepository
132  #include "demandDrivenEntry.C"
133 #endif
134 
135 // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
136 
137 #endif
138 
139 // ************************************************************************* //
dictionary dict
A list of keyword definitions, which are a keyword followed by any number of values (e...
Definition: dictionary.H:137
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.