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

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