elements.h

Go to the documentation of this file.
00001 //# elements.h: templates, classes and functions for "functional" programming, e.g. with STL iterators
00002 //# with surrounding Gui functionality
00003 //# Copyright (C) 2005,2009
00004 //# Associated Universities, Inc. Washington DC, USA.
00005 //#
00006 //# This library is free software; you can redistribute it and/or modify it
00007 //# under the terms of the GNU Library General Public License as published by
00008 //# the Free Software Foundation; either version 2 of the License, or (at your
00009 //# option) any later version.
00010 //#
00011 //# This library is distributed in the hope that it will be useful, but WITHOUT
00012 //# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00013 //# FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Library General Public
00014 //# License for more details.
00015 //#
00016 //# You should have received a copy of the GNU Library General Public License
00017 //# along with this library; if not, write to the Free Software Foundation,
00018 //# Inc., 675 Massachusetts Ave, Cambridge, MA 02139, USA.
00019 //#
00020 //# Correspondence concerning AIPS++ should be addressed as follows:
00021 //#        Internet email: aips2-request@nrao.edu.
00022 //#        Postal address: AIPS++ Project Office
00023 //#                        National Radio Astronomy Observatory
00024 //#                        520 Edgemont Road
00025 //#                        Charlottesville, VA 22903-2475 USA
00026 //#
00027 //# $Id: QtDisplayPanelGui.qo.h,v 1.7 2006/10/10 21:42:05 dking Exp $
00028 
00029 #ifndef DISPLAY_FUNCTIONAL_ELEMENTS_H_
00030 #define DISPLAY_FUNCTIONAL_ELEMENTS_H_
00031 #include <math.h>
00032 
00033 namespace casa { //# NAMESPACE CASA - BEGIN
00034 
00035         namespace viewer {
00036 
00037                 // class for applying a range limit to values...
00038                 template<typename T> class RangeLimiter {
00039                 public:
00040                         // No-Op range limiter...
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
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 31 Aug 2016 for casa by  doxygen 1.6.1