PSCF v1.1
CArrayParam.h
1#ifndef UTIL_CARRAY_PARAM_H
2#define UTIL_CARRAY_PARAM_H
3
4#include <util/param/ArrayParam.h>
5#include <util/global.h>
6
7#ifdef UTIL_MPI
9#endif
10
11#include <iomanip>
12
13namespace Util
14{
15
21 template <class Type>
22 class CArrayParam : public ArrayParam<Type>
23 {
24
25 public:
26
35 CArrayParam(const char* label, Type* value, int n,
36 bool isRequired = true);
37
38 using ArrayParam<Type>::writeParam;
39
40 protected:
41
42 using ArrayParam<Type>::readValue;
43 using ArrayParam<Type>::n;
44
50 Type& element(int i)
51 { return value_[i]; }
52
58 Type const & element(int i) const
59 { return value_[i]; }
60
66 virtual void loadValue(Serializable::IArchive& ar);
67
73 virtual void saveValue(Serializable::OArchive& ar);
74
75 #ifdef UTIL_MPI
79 virtual void bcastValue();
80 #endif
81
82 private:
83
85 Type* value_;
86
87 };
88
89 /*
90 * CArrayParam<Type> constructor.
91 */
92 template <class Type>
93 CArrayParam<Type>::CArrayParam(const char *label, Type* value, int n,
94 bool isRequired)
95 : ArrayParam<Type>(label, n, isRequired),
96 value_(value)
97 {}
98
99 /*
100 * Load C-array of n values from an input archive
101 */
102 template <class Type>
104 { ar.unpack(value_, n()); }
105
106 /*
107 * Save C-array of n values to an output archive
108 */
109 template <class Type>
111 { ar.pack(value_, n()); }
112
113 #ifdef UTIL_MPI
114 /*
115 * Broadcast an array of n values
116 */
117 template <class Type>
119 { bcast<Type>(ioCommunicator(), value_, n(), 0); }
120 #endif
121
122}
123#endif
This file contains templates for global functions send<T>, recv<T> and bcast<T>.
An array-valued parameter in a parameter file.
Definition: ArrayParam.h:56
int n() const
Get the logical array dimension.
Definition: ArrayParam.h:86
std::string label() const
Return label string.
Definition: Parameter.cpp:164
void writeParam(std::ostream &out) const
Write an array-valued parameter to stream.
Definition: ArrayParam.tpp:139
virtual void readValue(std::istream &in)
Read array of element values from an input stream.
Definition: ArrayParam.tpp:103
bool isRequired() const
Is this an optional parameter?
Definition: Parameter.cpp:170
Saving archive for binary istream.
void unpack(T &data)
Unpack a single T object.
Saving / output archive for binary ostream.
void pack(const T &data)
Pack one object of type T.
A Parameter associated with a 1D C array.
Definition: CArrayParam.h:23
Type const & element(int i) const
Return a reference to one element of the array (const ref).
Definition: CArrayParam.h:58
CArrayParam(const char *label, Type *value, int n, bool isRequired=true)
Constructor.
Definition: CArrayParam.h:93
Type & element(int i)
Return a reference to one element of the array (non const).
Definition: CArrayParam.h:50
virtual void saveValue(Serializable::OArchive &ar)
Save parameter value to an archive.
Definition: CArrayParam.h:110
virtual void loadValue(Serializable::IArchive &ar)
Load bare parameter value from an archive.
Definition: CArrayParam.h:103
virtual void bcastValue()
Broadcast parameter value within the ioCommunicator.
Definition: CArrayParam.h:118
File containing preprocessor macros for error handling.
Utility classes for scientific computation.
Definition: accumulators.mod:1