nidas v1.2.3
Parameter.h
Go to the documentation of this file.
1// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4; -*-
2// vim: set shiftwidth=4 softtabstop=4 expandtab:
3/*
4 ********************************************************************
5 ** NIDAS: NCAR In-situ Data Acquistion Software
6 **
7 ** 2005, Copyright University Corporation for Atmospheric Research
8 **
9 ** This program is free software; you can redistribute it and/or modify
10 ** it under the terms of the GNU General Public License as published by
11 ** the Free Software Foundation; either version 2 of the License, or
12 ** (at your option) any later version.
13 **
14 ** This program is distributed in the hope that it will be useful,
15 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
16 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 ** GNU General Public License for more details.
18 **
19 ** The LICENSE.txt file accompanying this software contains
20 ** a copy of the GNU General Public License. If it is not found,
21 ** write to the Free Software Foundation, Inc.,
22 ** 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23 **
24 ********************************************************************
25*/
26/*
27
28 A fairly generic parameter.
29
30*/
31
32#ifndef NIDAS_CORE_PARAMETER_H
33#define NIDAS_CORE_PARAMETER_H
34
35#include "DOMable.h"
36
37#include <string>
38#include <vector>
39#include <sstream>
40#include <iostream>
41
42namespace nidas { namespace core {
43
44class Dictionary;
45
47{
48public:
49
51
52 typedef enum parType parType;
53
54 virtual void assign(const Parameter&) = 0;
55
56 virtual ~Parameter() {}
57
58 virtual Parameter* clone() const = 0;
59
60 const std::string& getName() const { return _name; }
61
62 void setName(const std::string& val) { _name = val; }
63
64 parType getType() const { return _type; }
65
66 virtual int getLength() const = 0;
67
68 virtual double getNumericValue(int i) const;
69
70 virtual std::string getStringValue(int i) const;
71
75 static Parameter*
76 createParameter(const xercesc::DOMElement*, const Dictionary* d = 0);
77
81 virtual void
82 fromDOMElement(const xercesc::DOMElement*, const Dictionary* dict) = 0;
83
84protected:
85
87
88 std::string _name;
89
91};
92
98{
100}
101
103{
105}
106
108{
110}
111
113{
115}
116
120template <class T>
121class ParameterT : public Parameter {
122public:
123
125
126 ParameterT* clone() const;
127
131 void assign(const Parameter& x);
132
133 int getLength() const { return _values.size(); }
134
135 const std::vector<T> getValues() const { return _values; }
136
137 void setValues(const std::vector<T>& vals) { _values = vals; }
138
142 void setValue(unsigned int i, const T& val)
143 {
144 for (unsigned int j = _values.size(); j < i; j++) _values.push_back(T());
145 if (_values.size() > i) _values[i] = val;
146 else _values.push_back(val);
147 }
148
152 void setValue(const T& val) {
153 _values.clear();
154 _values.push_back(val);
155 }
156
157 T getValue(int i) const { return _values[i]; }
158
162 void fromDOMElement(const xercesc::DOMElement*);
163
167 void fromDOMElement(const xercesc::DOMElement*, const Dictionary* dict);
168
169protected:
170
174 std::vector<T> _values;
175
176};
177
183public:
185 bool operator()(const Parameter* x) const {
186 return x->getName() == p->getName() &&
187 x->getType() == p->getType();
188 }
189private:
190 const Parameter* p;
191};
192
193}} // namespace nidas namespace core
194
195#endif
Interface for a Dictionary class, which can return a string value for a string token name.
Definition Dictionary.h:38
Functor class for Parameter, doing an equality check of parameter name and type.
Definition Parameter.h:182
ParameterNameTypeComparator(const Parameter *param)
Definition Parameter.h:184
const Parameter * p
Definition Parameter.h:190
bool operator()(const Parameter *x) const
Definition Parameter.h:185
A typed Parameter, with data of type T.
Definition Parameter.h:121
void assign(const Parameter &x)
A virtual assignment operator.
Definition Parameter.cc:124
int getLength() const
Definition Parameter.h:133
ParameterT * clone() const
Definition Parameter.cc:118
T getValue(int i) const
Definition Parameter.h:157
void setValue(const T &val)
For parameters of length one, set its value.
Definition Parameter.h:152
ParameterT()
Definition Parameter.h:124
std::vector< T > _values
Vector of values.
Definition Parameter.h:174
void fromDOMElement(const xercesc::DOMElement *)
Definition Parameter.cc:135
const std::vector< T > getValues() const
Definition Parameter.h:135
void setValues(const std::vector< T > &vals)
Definition Parameter.h:137
void setValue(unsigned int i, const T &val)
Set ith value.
Definition Parameter.h:142
Definition Parameter.h:47
virtual double getNumericValue(int i) const
Definition Parameter.cc:39
virtual void fromDOMElement(const xercesc::DOMElement *, const Dictionary *dict)=0
enum parType parType
Definition Parameter.h:52
virtual ~Parameter()
Definition Parameter.h:56
Parameter(parType t)
Definition Parameter.h:86
virtual int getLength() const =0
void setName(const std::string &val)
Definition Parameter.h:62
parType getType() const
Definition Parameter.h:64
virtual Parameter * clone() const =0
const std::string & getName() const
Definition Parameter.h:60
parType
Definition Parameter.h:50
@ FLOAT_PARAM
Definition Parameter.h:50
@ STRING_PARAM
Definition Parameter.h:50
@ BOOL_PARAM
Definition Parameter.h:50
@ INT_PARAM
Definition Parameter.h:50
static Parameter * createParameter(const xercesc::DOMElement *, const Dictionary *d=0)
Definition Parameter.cc:78
std::string _name
Definition Parameter.h:88
parType _type
Definition Parameter.h:90
virtual std::string getStringValue(int i) const
Definition Parameter.cc:57
virtual void assign(const Parameter &)=0
Parameter::parType getParamType(std::string)
Overloaded function to return a enumerated value corresponding to the type pointed to by the argument...
Definition Parameter.h:97
Sample * getSample(sampleType type, unsigned int len)
A convienence method for getting a sample of an enumerated type from a pool.
Definition Sample.cc:70
Root namespace for the NCAR In-Situ Data Acquisition Software.
Definition A2DConverter.h:31