nidas v1.2.3
VariableIndex.h
Go to the documentation of this file.
1// -*- mode: C++; indent-tabs-mode: nil; c-basic-offset: 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#ifndef NIDAS_CORE_VARIABLEINDEX_H
27#define NIDAS_CORE_VARIABLEINDEX_H
28
29namespace nidas { namespace core {
30
31class Variable;
32
52{
53public:
54
60 _variable(0),
61 _index(-1)
62 {}
63
68 _variable(var),
70 {}
71
78 _index(rhs._index)
79 {}
80
86 {
87 _variable = rhs._variable;
88 _index = rhs._index;
89 return *this;
90 }
91
92 bool operator==(const VariableIndex& rhs) const
93 {
94 return (_variable == rhs._variable) && (_index == rhs._index);
95 }
96
99 {
100 return _variable;
101 }
102
103 int
105 {
106 return _index;
107 }
108
113 float
114 get(float* fdata, float dflt)
115 {
116 if (_index >= 0)
117 return fdata[_index];
118 return dflt;
119 }
120
125 void
126 set(float* fdata, float value)
127 {
128 if (_index >= 0)
129 fdata[_index] = value;
130 }
131
132 bool
133 operator!() const
134 {
135 return _index < 0 || !_variable;
136 }
137
138 bool
139 valid() const
140 {
141 return _index >= 0 && _variable;
142 }
143
144private:
145
148};
149
150}} // namespace nidas namespace core
151
152#endif
A VariableIndex associates a Variable pointer with it's index into it's SampleTag.
Definition VariableIndex.h:52
VariableIndex & operator=(const VariableIndex &rhs)
Assign the pointer and index of the given VariableIndex to this instance.
Definition VariableIndex.h:85
int _index
Definition VariableIndex.h:147
bool operator!() const
Definition VariableIndex.h:133
VariableIndex(const VariableIndex &rhs)
The copy constructor copies the pointer and index of the given VariableIndex.
Definition VariableIndex.h:76
bool operator==(const VariableIndex &rhs) const
Definition VariableIndex.h:92
float get(float *fdata, float dflt)
Return the data value at this variable's index into fdata.
Definition VariableIndex.h:114
int index()
Definition VariableIndex.h:104
VariableIndex()
Default constructor creates an invalid VariableIndex: the Variable pointer is null and the index is -...
Definition VariableIndex.h:59
Variable * variable()
Definition VariableIndex.h:98
VariableIndex(Variable *var, int index)
Construct a VariableIndex with the given Variable and index.
Definition VariableIndex.h:67
bool valid() const
Definition VariableIndex.h:139
void set(float *fdata, float value)
Set value at this variable's index into fdata.
Definition VariableIndex.h:126
Variable * _variable
Definition VariableIndex.h:146
Class describing a sampled variable.
Definition Variable.h:47
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