OpendTect-6_4  6.4
selector.h
Go to the documentation of this file.
1 #ifndef selector_h
2 #define selector_h
3 
4 /*+
5 ________________________________________________________________________
6 
7  (C) dGB Beheer B.V.; (LICENSE) http://opendtect.org/OpendTect_license.txt
8  Author: A.H.Bril
9  Date: 18-10-1995
10  Contents: Selectors
11  RCS: $Id$
12 ________________________________________________________________________
13 
14 -*/
15 
16 #include "ranges.h"
17 
24 template <class T>
26 {
27 public:
28 
29  virtual ~Selector() {}
30  virtual const char* selectorType() const = 0;
31  virtual bool isOK() const { return true; }
32  bool isEqual( const Selector<T>& s ) const
33  {
34  return selectorType() == s.selectorType()
35  && isEq(s);
36  }
37  virtual Selector<T>* clone() const = 0;
38 
39  virtual bool includes(const T&) const = 0;
40  virtual bool canDoRange() const {return false;}
41  virtual char includesRange(const T& start,
42  const T& stop) const { return -1; }
47  virtual bool include(const T&,const char* =0) { return false; }
48 
49 private:
50 
51  virtual bool isEq(const Selector<T>&) const = 0;
52 
53 };
54 
55 
60 template <class T>
61 mClass(Basic) SingleSelector : public Selector<T>
62 {
63 public:
64 
66  SingleSelector( const T& t ) : val_(t) {}
67  virtual const char* selectorType() const { return "Single"; }
68  virtual Selector<T>* clone() const
69  { return new SingleSelector( val_ ); }
70 
71  virtual bool includes( const T& t ) const
72  { return val_ == t; }
73  virtual bool canDoRange() const {return true;}
74  virtual char includesRange(const T& start,
75  const T& stop) const;
76  virtual bool include( const T& t, const char* )
77  { val_ = t; return true; }
78 
79  T val_;
80 
81 protected:
82 
83  virtual bool isEq( const Selector<T>& ss ) const
84  { return val_ == ((const SingleSelector<T>&)ss).val_; }
85 
86 };
87 
88 
93 template <class T>
94 mClass(Basic) RangeSelector : public Selector<T>
95 {
96 public:
97 
99  RangeSelector( const T& t1, const T& t2 )
100  : range_(t1,t2) {}
101  virtual const char* selectorType() const { return "Range"; }
102  virtual Selector<T>* clone() const
103  { return new RangeSelector(range_.start,range_.stop); }
104 
105  virtual bool includes( const T& t ) const
106  { return range_.includes( t, true ); }
107  virtual bool include( const T& t, const char* )
108  { range_.include( t ); return true; }
109 
111 
112 protected:
113 
114  virtual bool isEq( const Selector<T>& rs ) const
115  { return range_==((const RangeSelector<T>&)rs).range_; }
116 
117 };
118 
119 
124 template <class T>
125 mClass(Basic) ArraySelector : public Selector<T>
126 {
127 public:
128 
130  : vals_(0), sz_(0), valsmine_(true) {}
131  ArraySelector( const T* v, int s )
132  : vals_(v), sz_(s), valsmine_(false) {}
134  : vals_(x.vals_), sz_(x.sz_), valsmine_(false) {}
136  { if ( valsmine_ ) delete [] const_cast<T*>(vals_); }
137 
138  virtual const char* selectorType() const { return "Array"; }
139  virtual Selector<T>* clone() const
140  { return new ArraySelector( vals_, sz_ ); }
141 
142  virtual bool includes( const T& t ) const
143  {
144  for ( int idx=0; idx<sz_; idx++ )
145  { if ( vals_[idx] == t ) return true; }
146  return false;
147  }
148  void manageVals( bool yn=true ) { valsmine_ = yn; }
149 
150  const T* vals_;
151  int sz_;
152 
153 protected:
154 
155  virtual bool isEq( const Selector<T>& ss ) const
156  {
157  const ArraySelector<T>& ass
158  = (const ArraySelector<T>&)ss;
159  if ( sz_ != ass.sz_ ) return false;
160  for ( int idx=0; idx<sz_; idx++ )
161  { if ( !ss.includes(vals_[idx]) ) return false;}
162  return true;
163  }
164 
165  bool valsmine_;
166 
167 };
168 
169 
170 template <class T> inline
171 char SingleSelector<T>::includesRange( const T& start, const T& stop ) const
172 {
173  const Interval<T> rg( start, stop );
174  if ( start==stop==val_ )
175  return 2;
176 
177  if ( rg.includes( val_, true ) )
178  return 1;
179 
180  return 0;
181 }
182 
183 #endif
void manageVals(bool yn=true)
Definition: selector.h:148
virtual bool canDoRange() const
Definition: selector.h:40
virtual bool isOK() const
Definition: selector.h:31
virtual const char * selectorType() const
Definition: selector.h:67
SingleSelector(const T &t)
Definition: selector.h:66
virtual ~Selector()
Definition: selector.h:29
bool isEqual(const Selector< T > &s) const
Definition: selector.h:32
Interval< T > range_
Definition: selector.h:110
virtual bool include(const T &t, const char *)
Definition: selector.h:107
const T * vals_
Definition: selector.h:150
virtual Selector< T > * clone() const
Definition: selector.h:68
ArraySelector()
Definition: selector.h:129
RangeSelector(const T &t1, const T &t2)
Definition: selector.h:99
Selector based on range specification (an Interval).
Definition: selector.h:94
virtual const char * selectorType() const =0
Interval of values.
Definition: commontypes.h:31
virtual bool isEq(const Selector< T > &ss) const
Definition: selector.h:83
int sz_
Definition: selector.h:151
Selector selecting only a single value.
Definition: selector.h:61
virtual bool isEq(const Selector< T > &rs) const
Definition: selector.h:114
virtual bool include(const T &, const char *=0)
Definition: selector.h:47
virtual bool isEq(const Selector< T > &ss) const
Definition: selector.h:155
virtual bool includes(const T &t) const
Definition: selector.h:105
virtual Selector< T > * clone() const
Definition: selector.h:139
Interface for classes that select on basis of a key.
Definition: selector.h:25
virtual const char * selectorType() const
Definition: selector.h:138
virtual bool includes(const T &t) const
Definition: selector.h:142
T val_
Definition: selector.h:79
virtual Selector< T > * clone() const
Definition: selector.h:102
virtual char includesRange(const T &start, const T &stop) const
Definition: selector.h:41
virtual bool includes(const T &t) const
Definition: selector.h:71
virtual const char * selectorType() const
Definition: selector.h:101
ArraySelector(const T *v, int s)
Definition: selector.h:131
bool includes(const X &, bool allowrev) const
Definition: ranges.h:482
virtual bool include(const T &t, const char *)
Definition: selector.h:76
~ArraySelector()
Definition: selector.h:135
virtual char includesRange(const T &start, const T &stop) const
Definition: selector.h:171
virtual bool canDoRange() const
Definition: selector.h:73
RangeSelector()
Definition: selector.h:98
#define mClass(module)
Definition: commondefs.h:164
ArraySelector(const ArraySelector &x)
Definition: selector.h:133
SingleSelector()
Definition: selector.h:65
Selector based on array.
Definition: selector.h:125
bool valsmine_
Definition: selector.h:165
virtual bool includes(const T &) const =0

Generated at for the OpendTect seismic interpretation project. Copyright (C): dGB Beheer B. V. 2019