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 argument << range;
152 }
153 argument.endArray();
154 return argument;
155}
156
164inline const QDBusArgument &operator>>(const QDBusArgument &argument, DataRangeList &data)
165{
166 argument.beginArray();
167 data.clear();
168 while (!argument.atEnd()) {
169 DataRange element;
170 argument >> element;
171 data.append(element);
172 }
173 argument.endArray();
174 return argument;
175}
176
184inline QDBusArgument &operator<<(QDBusArgument &argument, const IntegerRange &data)
185{
186 argument.beginStructure();
187 argument << data.first << data.second;
188 argument.endStructure();
189 return argument;
190}
191
199inline const QDBusArgument &operator>>(const QDBusArgument &argument, IntegerRange &data)
200{
201 argument.beginStructure();
202 argument >> data.first >> data.second;
203 argument.endStructure();
204 return argument;
205}
206
214inline QDBusArgument &operator<<(QDBusArgument &argument, const IntegerRangeList &data)
215{
216 argument.beginArray(qMetaTypeId<IntegerRange>());
217 foreach (const IntegerRange& range, data) {
218 argument << range;
219 }
220 argument.endArray();
221 return argument;
222}
223
231inline const QDBusArgument &operator>>(const QDBusArgument &argument, IntegerRangeList &data)
232{
233 argument.beginArray();
234 data.clear();
235 while (!argument.atEnd()) {
236 IntegerRange element;
237 argument >> element;
238 data.append(element);
239 }
240 argument.endArray();
241 return argument;
242}
243
248{
249public:
250
251 int id;
259 DataRangeRequest(int newId) :
260 id(newId) {};
261
268 DataRangeRequest(int newId, const DataRange& newRange) :
269 id(newId),
270 range(newRange) {};
271
278 bool operator==(const DataRangeRequest& right) const
279 {
280 return (id == right.id && range == right.range);
281 }
282};
283
288public:
289 int id;
290 unsigned value;
298 IntervalRequest(int newId, unsigned newValue) :
299 id(newId),
300 value(newValue) {}
301
308 bool operator==(const IntervalRequest& right) const
309 {
310 return (id == right.id && value == right.value);
311 }
312};
313
321template<typename T, typename U>
322inline bool isInRange(T ref, const U& container)
323{
324 foreach (const typename U::value_type& value, container) {
325 if (ref >= value.first && ref <= value.second)
326 return true;
327 }
328 return false;
329}
330
331#endif // DATARANGE_H
DataRange request class.
Definition datarange.h:248
DataRangeRequest(int newId)
Constructor.
Definition datarange.h:259
DataRange range
Resuested range.
Definition datarange.h:252
DataRangeRequest(int newId, const DataRange &newRange)
Constructor.
Definition datarange.h:268
int id
Request ID.
Definition datarange.h:251
bool operator==(const DataRangeRequest &right) const
Comparison operator.
Definition datarange.h:278
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:287
IntervalRequest(int newId, unsigned newValue)
Constructor.
Definition datarange.h:298
bool operator==(const IntervalRequest &right) const
Comparison operator.
Definition datarange.h:308
int id
Request ID.
Definition datarange.h:289
unsigned value
Requested interval value.
Definition datarange.h:290
Q_DECLARE_METATYPE(TMatrix)
bool isInRange(T ref, const U &container)
Checks is given value inside range list.
Definition datarange.h:322
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