PSCF v1.1
Parameter.h
1#ifndef UTIL_PARAMETER_H
2#define UTIL_PARAMETER_H
3
4/*
5* Util Package - C++ Utilities for Scientific Computation
6*
7* Copyright 2010 - 2017, The Regents of the University of Minnesota
8* Distributed under the terms of the GNU General Public License.
9*/
10
11#include <util/param/ParamComponent.h>
12#include <util/archives/Serializable_includes.h>
13#include <util/param/Label.h>
14#include <util/global.h>
15
16namespace Util
17{
18
46 {
47
48 public:
49
50 // Static members
51
53 static const int Width = 20;
54
56 static const int Precision = 12;
57
65 template <class Type>
66 static void
67 saveOptional(Serializable::OArchive& ar, Type& value, bool isActive);
68
77 template <class Type>
78 static void
79 saveOptionalCArray(Serializable::OArchive& ar, Type* ptr, int n,
80 bool isActive);
81
92 template <class Type>
93 static void
95 int m, int n, int np, bool isActive);
96
97 // Non-static member functions
98
105 Parameter(const char *label, bool isRequired = true);
106
110 virtual ~Parameter();
111
134 virtual void readParam(std::istream &in);
135
150 virtual void load(Serializable::IArchive& ar);
151
165 virtual void save(Serializable::OArchive& ar);
166
170 std::string label() const;
171
175 bool isRequired() const;
176
180 bool isActive() const;
181
182 protected:
183
186
189
195 virtual void readLabel(std::istream& in);
196
202 virtual void readValue(std::istream& in){}
203
210
217
218 #ifdef UTIL_MPI
222 virtual void bcastValue(){}
223 #endif
224
225 };
226
227 /*
228 * Save a parameter value to an output archive
229 */
230 template <class Type>
232 Type& value, bool isActive)
233 {
234 ar << isActive;
235 if (isActive) {
236 ar & value;
237 }
238 }
239
240 /*
241 * Save C-array of n ptrs to an output archive
242 */
243 template <class Type>
245 Type* ptr, int n, bool isActive)
246 {
247 ar << isActive;
248 if (isActive) {
249 ar.pack(ptr, n);
250 }
251 }
252
253 /*
254 * Save a two-dimensional C array to an output archive.
255 */
256 template <class Type>
258 Type* ptr, int m, int n, int np,
259 bool isActive)
260 {
261 ar << isActive;
262 if (isActive) {
263 ar.pack(ptr, m, n, np);
264 }
265 }
266
267}
268#endif
Saving archive for binary istream.
Saving / output archive for binary ostream.
void pack(const T &data)
Pack one object of type T.
A label string in a file format.
Definition: Label.h:73
Abstract base class for classes that input and ouput parameters to file.
A single variable in a parameter file.
Definition: Parameter.h:46
static void saveOptionalCArray(Serializable::OArchive &ar, Type *ptr, int n, bool isActive)
Save an optional C-array of n values to an output archive.
Definition: Parameter.h:244
virtual ~Parameter()
Destructor.
Definition: Parameter.cpp:30
virtual void readLabel(std::istream &in)
Read and attempt to match label string.
Definition: Parameter.cpp:36
std::string label() const
Return label string.
Definition: Parameter.cpp:164
virtual void save(Serializable::OArchive &ar)
Save to an archive.
Definition: Parameter.cpp:151
virtual void readValue(std::istream &in)
Read parameter value from an input stream.
Definition: Parameter.h:202
static const int Precision
Precision for io of floating point data field.
Definition: Parameter.h:56
virtual void saveValue(Serializable::OArchive &ar)
Save parameter value to an archive.
Definition: Parameter.h:216
bool isActive_
Is this parameter active (always true if isRequired).
Definition: Parameter.h:188
virtual void readParam(std::istream &in)
Read a label and (if the label matches) a parameter value.
Definition: Parameter.cpp:42
static void saveOptionalCArray2D(Serializable::OArchive &ar, Type *ptr, int m, int n, int np, bool isActive)
Save an optional two-dimensional C array to an output archive.
Definition: Parameter.h:257
virtual void loadValue(Serializable::IArchive &ar)
Load bare parameter value from an archive.
Definition: Parameter.h:209
bool isRequired() const
Is this an optional parameter?
Definition: Parameter.cpp:170
Label label_
Label object that contains parameter label string.
Definition: Parameter.h:185
virtual void bcastValue()
Broadcast parameter value within the ioCommunicator.
Definition: Parameter.h:222
static void saveOptional(Serializable::OArchive &ar, Type &value, bool isActive)
Save an optional parameter value to an output archive.
Definition: Parameter.h:231
bool isActive() const
Is this parameter active?
Definition: Parameter.cpp:176
static const int Width
Width of output field for a scalar variable.
Definition: Parameter.h:53
virtual void load(Serializable::IArchive &ar)
Load from an archive.
Definition: Parameter.cpp:104
File containing preprocessor macros for error handling.
Utility classes for scientific computation.
Definition: accumulators.mod:1