elements.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029 #ifndef DISPLAY_FUNCTIONAL_ELEMENTS_H_
00030 #define DISPLAY_FUNCTIONAL_ELEMENTS_H_
00031 #include <math.h>
00032
00033 namespace casa {
00034
00035 namespace viewer {
00036
00037
00038 template<typename T> class RangeLimiter {
00039 public:
00040
00041 RangeLimiter( T (*mod)(T) = 0 ) : noop_(true), mod_(mod) { }
00042 RangeLimiter( T min, T max, T (*mod)(T) = 0 ) : noop_(false), min_(min), max_(max), mod_(mod) { }
00043 RangeLimiter( const RangeLimiter &other ) : noop_(other.noop_), min_(other.min_), max_(other.max_), mod_(other.mod_) { }
00044 const RangeLimiter &operator=( const RangeLimiter &other ) {
00045 noop_ = other.noop_;
00046 min_ = other.min_;
00047 max_ = other.max_;
00048 mod_ = other.mod_;
00049 return *this;
00050 }
00051 virtual T operator( )( T value ) {
00052 return noop_ ? (mod_ ? (*mod_)(value) : value) : value < min_ ? min_ : value > max_ ? max_ : (mod_ ? (*mod_)(value) : value);
00053 }
00054 virtual ~RangeLimiter( ) { }
00055 private:
00056 bool noop_;
00057 T min_;
00058 T max_;
00059 T (*mod_)(T);
00060 };
00061
00062 template<typename T,typename CT=std::vector<T> > class filter {
00063 public:
00064 enum comparisons { EQUAL, UNEQUAL };
00065 filter( T compare_element, comparisons c=UNEQUAL ) {
00066 comparitor = compare_element;
00067 if ( c == EQUAL ) op = &filter<T,CT>::equality;
00068 else op = &filter<T,CT>::inequality;
00069 }
00070 void operator( )( T ele ) {
00071 if ( (this->*op)(ele) ) cache.push_back(ele);
00072 }
00073 operator CT( ) { return cache; }
00074 void clear( ) { cache.clear( ); }
00075 private:
00076 T comparitor;
00077 bool (filter<T,CT>::*op)(T);
00078 bool equality( T ele ) { return ele == comparitor; }
00079 bool inequality( T ele ) { return ele != comparitor; }
00080 CT cache;
00081 };
00082
00083
00084 }
00085 }
00086
00087
00088 #endif