Ilwis-Objects  1.0
GIS and Remote Sensing framework for data access and processing
 All Classes Functions Enumerations Pages
numericrange.h
1 #ifndef NUMERICVALUERANGE_H
2 #define NUMERICVALUERANGE_H
3 
4 #include <QString>
5 #include "range.h"
6 
7 namespace Ilwis {
8 
12 class KERNELSHARED_EXPORT NumericRange : public Range
13 {
14 public:
15  NumericRange();
26  NumericRange(double mi, double ma, double resolution=0);
31  NumericRange(const NumericRange &vr);
32 
33 
34  bool isValid() const;
35  Range *clone() const ;
36 
37  bool contains(double v, bool inclusive = true) const{
38  if (!isValid())
39  return false;
40 
41  if ( inclusive)
42  return v >= _min && v <= _max;
43  return v > _min && v < _max;
44  }
45 
46 
47  bool contains(const QVariant &value, bool inclusive = true) const;
48  bool contains(SPRange rng, bool inclusive=true) const;
49  bool contains(NumericRange *rng, bool inclusive=true) const;
50  double max() const;
51  void max(double v);
52  double min() const;
53  void min(double v);
54  double distance() const;
55 
56  void resolution(double resolution);
57  double resolution() const ;
58 
59  NumericRange& operator+=(double v);
60 
61  bool operator==(const NumericRange& vr);
62  bool operator<(const NumericRange& vr);
63  bool operator>(const NumericRange& vr);
64 
65  QString toString() const ;
66  QVariant impliedValue(const QVariant& v) const;
67  void set(const NumericRange& vr);
68  QVariant ensure(const QVariant& v, bool inclusive=true) const
69  {
70  if ( !contains(v, inclusive))
71  return _undefined;
72 
73  if ( _resolution != 0.0)
74  return (qint64)(v.toDouble() / _resolution) * _resolution;
75  return v;
76  }
77  IlwisTypes determineType() const;
78  void clear();
79 
80  static NumericRange *merge(const QSharedPointer<NumericRange>& nr1, const QSharedPointer<NumericRange>& nr2,RenumberMap *rnm=0);
81 
82 private:
83  double _min;
84  double _max;
85  double _resolution;
86  double _undefined;
87 
88  long significantDigits(double m1) const;
89 };
90 
91 typedef QSharedPointer<NumericRange> SPNumericRange;
92 
93 }
94 
95 #endif // NUMERICVALUERANGE_H