sensorfw: datatypes/datarange.h Source File

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. */
35 typedef QPair<unsigned int, unsigned int> IntegerRange;
36
37/* Datatype for storing list of integer ranges. */
38 typedef QList<IntegerRange> IntegerRangeList;
39
40 Q_DECLARE_METATYPE( IntegerRange )
41 Q_DECLARE_METATYPE( IntegerRangeList )
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;
82 DataRange& operator=(const DataRange& origin)
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 */
105 typedef QList<DataRange> DataRangeList;
106
107 Q_DECLARE_METATYPE( DataRange )
108 Q_DECLARE_METATYPE( DataRangeList )
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
132 inline 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
147 inline 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
165 inline 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
185 inline 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
200 inline 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
215 inline 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
233 inline 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
249 class DataRangeRequest
250{
251public:
252
253 int id;
254 DataRange range;
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
289 class IntervalRequest {
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>
324 inline 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
DataRangeRequest
DataRange request class.
Definition datarange.h:250
DataRangeRequest::DataRangeRequest
DataRangeRequest(int newId)
Constructor.
Definition datarange.h:261
DataRangeRequest::range
DataRange range
Resuested range.
Definition datarange.h:254
DataRangeRequest::DataRangeRequest
DataRangeRequest(int newId, const DataRange &newRange)
Constructor.
Definition datarange.h:270
DataRangeRequest::id
int id
Request ID.
Definition datarange.h:253
DataRangeRequest::operator==
bool operator==(const DataRangeRequest &right) const
Comparison operator.
Definition datarange.h:280
DataRange
Datatype for storing sensor data range information.
Definition datarange.h:46
DataRange::operator==
bool operator==(const DataRange &right) const
Comparison operator.
Definition datarange.h:96
DataRange::operator=
DataRange & operator=(const DataRange &origin)
Assignment operator.
Definition datarange.h:82
DataRange::min
double min
Range lower end.
Definition datarange.h:73
DataRange::DataRange
DataRange(const DataRange &other)
Copy constructor.
Definition datarange.h:60
DataRange::max
double max
Range higher end.
Definition datarange.h:74
DataRange::resolution
double resolution
Range resolution.
Definition datarange.h:75
DataRange::DataRange
DataRange(double min, double max, double resolution)
Constructor.
Definition datarange.h:70
DataRange::DataRange
DataRange()
Default constructor.
Definition datarange.h:53
IntervalRequest
Interval Request class.
Definition datarange.h:289
IntervalRequest::IntervalRequest
IntervalRequest(int newId, unsigned newValue)
Constructor.
Definition datarange.h:300
IntervalRequest::operator==
bool operator==(const IntervalRequest &right) const
Comparison operator.
Definition datarange.h:310
IntervalRequest::id
int id
Request ID.
Definition datarange.h:291
IntervalRequest::value
unsigned value
Requested interval value.
Definition datarange.h:292
Q_DECLARE_METATYPE
Q_DECLARE_METATYPE(TMatrix)
isInRange
bool isInRange(T ref, const U &container)
Checks is given value inside range list.
Definition datarange.h:324
operator>>
const QDBusArgument & operator>>(const QDBusArgument &argument, DataRange &data)
Unmarshall DataRange from the D-Bus argument.
Definition datarange.h:132
IntegerRangeList
QList< IntegerRange > IntegerRangeList
Definition datarange.h:38
operator<<
QDBusArgument & operator<<(QDBusArgument &argument, const DataRange &data)
Marshall the DataRange into a D-Bus argument.
Definition datarange.h:117
IntegerRange
QPair< unsigned int, unsigned int > IntegerRange
Definition datarange.h:35
DataRangeList
QList< DataRange > DataRangeList
Definition datarange.h:105