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

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