casa  5.7.0-16
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
elements.h
Go to the documentation of this file.
1 //# elements.h: templates, classes and functions for "functional" programming, e.g. with STL iterators
2 //# with surrounding Gui functionality
3 //# Copyright (C) 2005,2009
4 //# Associated Universities, Inc. Washington DC, USA.
5 //#
6 //# This library is free software; you can redistribute it and/or modify it
7 //# under the terms of the GNU Library General Public License as published by
8 //# the Free Software Foundation; either version 2 of the License, or (at your
9 //# option) any later version.
10 //#
11 //# This library is distributed in the hope that it will be useful, but WITHOUT
12 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 //# FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public
14 //# License for more details.
15 //#
16 //# You should have received a copy of the GNU Library General Public License
17 //# along with this library; if not, write to the Free Software Foundation,
18 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
19 //#
20 //# Correspondence concerning AIPS++ should be addressed as follows:
21 //# Internet email: aips2-request@nrao.edu.
22 //# Postal address: AIPS++ Project Office
23 //# National Radio Astronomy Observatory
24 //# 520 Edgemont Road
25 //# Charlottesville, VA 22903-2475 USA
26 //#
27 //# $Id: QtDisplayPanelGui.qo.h,v 1.7 2006/10/10 21:42:05 dking Exp $
28 
29 #ifndef DISPLAY_FUNCTIONAL_ELEMENTS_H_
30 #define DISPLAY_FUNCTIONAL_ELEMENTS_H_
31 #include <math.h>
32 
33 namespace casa { //# NAMESPACE CASA - BEGIN
34 
35  namespace viewer {
36 
37  // class for applying a range limit to values...
38  template<typename T> class RangeLimiter {
39  public:
40  // No-Op range limiter...
41  RangeLimiter( T (*mod)(T) = 0 ) : noop_(true), mod_(mod) { }
42  RangeLimiter( T min, T max, T (*mod)(T) = 0 ) : noop_(false), min_(min), max_(max), mod_(mod) { }
43  RangeLimiter( const RangeLimiter &other ) : noop_(other.noop_), min_(other.min_), max_(other.max_), mod_(other.mod_) { }
44  const RangeLimiter &operator=( const RangeLimiter &other ) {
45  noop_ = other.noop_;
46  min_ = other.min_;
47  max_ = other.max_;
48  mod_ = other.mod_;
49  return *this;
50  }
51  virtual T operator( )( T value ) {
52  return noop_ ? (mod_ ? (*mod_)(value) : value) : value < min_ ? min_ : value > max_ ? max_ : (mod_ ? (*mod_)(value) : value);
53  }
54  virtual ~RangeLimiter( ) { }
55  private:
56  bool noop_;
57  T min_;
58  T max_;
59  T (*mod_)(T);
60  };
61 
62  template<typename T,typename CT=std::vector<T> > class filter {
63  public:
65  filter( T compare_element, comparisons c=UNEQUAL ) {
66  comparitor = compare_element;
67  if ( c == EQUAL ) op = &filter<T,CT>::equality;
69  }
70  void operator( )( T ele ) {
71  if ( (this->*op)(ele) ) cache.push_back(ele);
72  }
73  operator CT( ) { return cache; }
74  void clear( ) { cache.clear( ); }
75  private:
77  bool (filter<T,CT>::*op)(T);
78  bool equality( T ele ) { return ele == comparitor; }
79  bool inequality( T ele ) { return ele != comparitor; }
80  CT cache;
81  };
82 
83 
84  }
85 }
86 
87 
88 #endif
#define max(a, b)
Definition: hio.h:44
#define min(a, b)
Definition: hio.h:45
const RangeLimiter & operator=(const RangeLimiter &other)
Definition: elements.h:44
RangeLimiter(const RangeLimiter &other)
Definition: elements.h:43
filter(T compare_element, comparisons c=UNEQUAL)
Definition: elements.h:65
bool inequality(T ele)
Definition: elements.h:79
RangeLimiter(T min, T max, T(*mod)(T)=0)
Definition: elements.h:42
bool(filter< T, CT >::* op)(T)
Definition: elements.h:77
const Double c
Fundamental physical constants (SI units):
class for applying a range limit to values...
Definition: elements.h:38
bool equality(T ele)
Definition: elements.h:78
RangeLimiter(T(*mod)(T)=0)
No-Op range limiter...
Definition: elements.h:41
LatticeExprNode value(const LatticeExprNode &expr)
This function returns the value of the expression without a mask.