sensorfw
datarange.h
Go to the documentation of this file.
1
27#ifndef DATARANGE_H
28#define DATARANGE_H
29
30#include <QObject>
31#include <QDBusArgument>
32#include <QPair>
33
34/* Datatype for storing integer ranges. */
35typedef QPair<unsigned int, unsigned int> IntegerRange;
36
37/* Datatype for storing list of integer ranges. */
38typedef QList<IntegerRange> IntegerRangeList;
39
42
43
46class DataRange : public QObject {
47 Q_OBJECT;
48public:
49
53 DataRange() : QObject(), min(0), max(0), resolution(0) {}
54
60 DataRange(const DataRange &other) :
61 QObject(), min(other.min), max(other.max), resolution(other.resolution) {}
62
70 DataRange(double min, double max, double resolution) :
71 QObject(), min(min), max(max), resolution(resolution) {}
72
73 double min;
74 double max;
75 double resolution;
83 {
84 min = origin.min;
85 max = origin.max;
86 resolution = origin.resolution;
87 return *this;
88 }
89
96 bool operator==(const DataRange& right) const
97 {
98 return (min == right.min &&
99 max == right.max &&
100 resolution == right.resolution);
101 }
102};
103
104/* Datatype for list of data ranges */
105typedef QList<DataRange> DataRangeList;
106
109
110
117inline QDBusArgument &operator<<(QDBusArgument &argument, const DataRange &data)
118{
119 argument.beginStructure();
120 argument << data.min << data.max << data.resolution;
121 argument.endStructure();
122 return argument;
123}
124
132inline const QDBusArgument &operator>>(const QDBusArgument &argument, DataRange &data)
133{
134 argument.beginStructure();
135 argument >> data.min >> data.max >> data.resolution;
136 argument.endStructure();
137 return argument;
138}
139
147inline QDBusArgument &operator<<(QDBusArgument &argument, const DataRangeList &data)
148{
149 argument.beginArray(qMetaTypeId<DataRange>());
150 foreach(const DataRange& range, data)
151 {
152 argument << range;
153 }
154 argument.endArray();
155 return argument;
156}
157
165inline const QDBusArgument &operator>>(const QDBusArgument &argument, DataRangeList &data)
166{
167 argument.beginArray();
168 data.clear();
169 while ( !argument.atEnd() ) {
170 DataRange element;
171 argument >> element;
172 data.append( element );
173 }
174 argument.endArray();
175 return argument;
176}
177
185inline QDBusArgument &operator<<(QDBusArgument &argument, const IntegerRange &data)
186{
187 argument.beginStructure();
188 argument << data.first << data.second;
189 argument.endStructure();
190 return argument;
191}
192
200inline const QDBusArgument &operator>>(const QDBusArgument &argument, IntegerRange &data)
201{
202 argument.beginStructure();
203 argument >> data.first >> data.second;
204 argument.endStructure();
205 return argument;
206}
207
215inline QDBusArgument &operator<<(QDBusArgument &argument, const IntegerRangeList &data)
216{
217 argument.beginArray(qMetaTypeId<IntegerRange>());
218 foreach(const IntegerRange& range, data)
219 {
220 argument << range;
221 }
222 argument.endArray();
223 return argument;
224}
225
233inline const QDBusArgument &operator>>(const QDBusArgument &argument, IntegerRangeList &data)
234{
235 argument.beginArray();
236 data.clear();
237 while ( !argument.atEnd() ) {
238 IntegerRange element;
239 argument >> element;
240 data.append( element );
241 }
242 argument.endArray();
243 return argument;
244}
245
250{
251public:
252
253 int id;
261 DataRangeRequest(int newId) :
262 id(newId) {};
263
270 DataRangeRequest(int newId, const DataRange& newRange) :
271 id(newId),
272 range(newRange) {};
273
280 bool operator==(const DataRangeRequest& right) const
281 {
282 return (id == right.id && range == right.range);
283 }
284};
285
290public:
291 int id;
292 unsigned value;
300 IntervalRequest(int newId, unsigned newValue) :
301 id(newId),
302 value(newValue) {}
303
310 bool operator==(const IntervalRequest& right) const
311 {
312 return (id == right.id && value == right.value);
313 }
314};
315
323template<typename T, typename U>
324inline bool isInRange(T ref, const U& container)
325{
326 foreach(const typename U::value_type& value, container)
327 {
328 if(ref >= value.first && ref <= value.second)
329 return true;
330 }
331 return false;
332}
333
334#endif // DATARANGE_H
DataRange request class.
Definition: datarange.h:250
DataRangeRequest(int newId)
Constructor.
Definition: datarange.h:261
DataRange range
Resuested range.
Definition: datarange.h:254
DataRangeRequest(int newId, const DataRange &newRange)
Constructor.
Definition: datarange.h:270
int id
Request ID.
Definition: datarange.h:253
bool operator==(const DataRangeRequest &right) const
Comparison operator.
Definition: datarange.h:280
Datatype for storing sensor data range information.
Definition: datarange.h:46
bool operator==(const DataRange &right) const
Comparison operator.
Definition: datarange.h:96
DataRange & operator=(const DataRange &origin)
Assignment operator.
Definition: datarange.h:82
double min
Range lower end.
Definition: datarange.h:73
DataRange(const DataRange &other)
Copy constructor.
Definition: datarange.h:60
double max
Range higher end.
Definition: datarange.h:74
double resolution
Range resolution.
Definition: datarange.h:75
DataRange(double min, double max, double resolution)
Constructor.
Definition: datarange.h:70
DataRange()
Default constructor.
Definition: datarange.h:53
Interval Request class.
Definition: datarange.h:289
IntervalRequest(int newId, unsigned newValue)
Constructor.
Definition: datarange.h:300
bool operator==(const IntervalRequest &right) const
Comparison operator.
Definition: datarange.h:310
int id
Request ID.
Definition: datarange.h:291
unsigned value
Requested interval value.
Definition: datarange.h:292
Q_DECLARE_METATYPE(TMatrix)
bool isInRange(T ref, const U &container)
Checks is given value inside range list.
Definition: datarange.h:324
const QDBusArgument & operator>>(const QDBusArgument &argument, DataRange &data)
Unmarshall DataRange from the D-Bus argument.
Definition: datarange.h:132
QList< IntegerRange > IntegerRangeList
Definition: datarange.h:38
QDBusArgument & operator<<(QDBusArgument &argument, const DataRange &data)
Marshall the DataRange into a D-Bus argument.
Definition: datarange.h:117
QPair< unsigned int, unsigned int > IntegerRange
Definition: datarange.h:35
QList< DataRange > DataRangeList
Definition: datarange.h:105