PSCF v1.1
ArrayParam.h
1#ifndef UTIL_ARRAY_PARAM_H
2#define UTIL_ARRAY_PARAM_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/Parameter.h>
12
13namespace Util
14{
15
54 template <typename Type>
55 class ArrayParam : public Parameter
56 {
57
58 public:
59
67 ArrayParam(const char *label, int n, bool isRequired = true);
68
72 virtual ~ArrayParam();
73
81 void writeParam(std::ostream &out) const;
82
86 int n() const
87 { return n_; }
88
90 using Parameter::load;
91 using Parameter::save;
92 using Parameter::label;
95
96 protected:
97
103 virtual void readLabel(std::istream& in);
104
114 virtual void readValue(std::istream& in);
115
126 void readEndBracket(std::istream& in);
127
136 virtual Type& element(int i) = 0;
137
146 virtual Type const & element(int i) const = 0;
147
151 bool hasBrackets() const
152 { return hasBrackets_; }
153
154 using Parameter::label_;
155
156 private:
157
159 std::string name_;
160
162 int n_;
163
165 bool isRequired_;
166
168 bool hasBrackets_;
169
170 };
171
172}
173#include <util/param/ArrayParam.tpp>
174#endif
An array-valued parameter in a parameter file.
Definition: ArrayParam.h:56
int n() const
Get the logical array dimension.
Definition: ArrayParam.h:86
bool hasBrackets() const
Are square brackets being used as delimiters?
Definition: ArrayParam.h:151
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 Type & element(int i)=0
Return a non-const reference to one element of the array.
virtual void readValue(std::istream &in)
Read array of element values from an input stream.
Definition: ArrayParam.tpp:103
virtual Type const & element(int i) const =0
Return a non-const reference to one element of the array.
virtual ~ArrayParam()
Destructor.
Definition: ArrayParam.tpp:43
void readEndBracket(std::istream &in)
Read a closing bracket, if necessary.
Definition: ArrayParam.tpp:115
bool isRequired() const
Is this an optional parameter?
Definition: Parameter.cpp:170
virtual void readLabel(std::istream &in)
Read parameter label from an input stream.
Definition: ArrayParam.tpp:50
std::string indent() const
Return indent string for this object (string of spaces).
A single variable in a parameter file.
Definition: Parameter.h:46
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
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
bool isActive() const
Is this parameter active?
Definition: Parameter.cpp:176
virtual void load(Serializable::IArchive &ar)
Load from an archive.
Definition: Parameter.cpp:104
Utility classes for scientific computation.
Definition: accumulators.mod:1