PSCF v1.3
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
8#include <util/mpi/MpiSendRecv.h>
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>
105
106 /*
107 * Save C-array of n values to an output archive
108 */
109 template <class Type>
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
int n() const
Get the logical array dimension.
Definition ArrayParam.h:86
ArrayParam(const char *label, int n, bool isRequired=true)
Constructor.
std::string label() const
Return label string.
void writeParam(std::ostream &out) const
Write an array-valued parameter to stream.
virtual void readValue(std::istream &in)
Read array of element values from an input stream.
bool isRequired() const
Is this an optional parameter?
void unpack(T &data)
Unpack a single T object.
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.
virtual void loadValue(Serializable::IArchive &ar)
Load bare parameter value from an archive.
BinaryFileIArchive IArchive
Type of input archive used by load method.
BinaryFileOArchive OArchive
Type of output archive used by save method.
File containing preprocessor macros for error handling.
Utility classes for scientific computation.