scalarterm.hh

Go to the documentation of this file.
00001 /*************************************************************************
00002 
00003 Copyright Rice University, 2004.
00004 All rights reserved.
00005 
00006 Permission is hereby granted, free of charge, to any person obtaining a
00007 copy of this software and associated documentation files (the "Software"),
00008 to deal in the Software without restriction, including without limitation
00009 the rights to use, copy, modify, merge, publish, distribute, and/or sell
00010 copies of the Software, and to permit persons to whom the Software is
00011 furnished to do so, provided that the above copyright notice(s) and this
00012 permission notice appear in all copies of the Software and that both the
00013 above copyright notice(s) and this permission notice appear in supporting
00014 documentation.
00015 
00016 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
00017 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
00018 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY
00019 RIGHTS. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR HOLDERS INCLUDED IN THIS
00020 NOTICE BE LIABLE FOR ANY CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL
00021 DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
00022 PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
00023 ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF
00024 THIS SOFTWARE.
00025 
00026 Except as contained in this notice, the name of a copyright holder shall
00027 not be used in advertising or otherwise to promote the sale, use or other
00028 dealings in this Software without prior written authorization of the
00029 copyright holder.
00030 
00031 **************************************************************************/
00032 
00033 #ifndef __RVLALG_SCALAR_TERMINATOR
00034 #define __RVLALG_SCALAR_TERMINATOR
00035 
00036 #include "alg.hh"
00037 #include "functional.hh"
00038 #include "except.hh"
00039 
00046 namespace RVLAlg {
00047 
00052 class CountTerminator: public Terminator {
00053 public:
00054 
00063   CountTerminator( int maxcount ) : mc(maxcount), count(0), i(1) {}
00064 
00075   CountTerminator( int init, int maxcount, int inc ) 
00076     : mc(maxcount), count(init), i(inc) {
00077     if ( inc <= 0 ) {
00078       RVL::RVLException e; e << "Error in CountTerminator constructor: parameters cause infinite loop";
00079       throw e;
00080     }
00081   }
00082   
00083   ~CountTerminator() {}
00084 
00085   virtual bool query() {
00086     count += i;
00087     return (count >= mc );
00088   }
00089 
00090   int getCount() { return count; }
00091 
00092 protected:
00093   int mc;
00094   int count;
00095   int i;
00096 
00097 private:
00098 
00099   CountTerminator();
00100   CountTerminator(CountTerminator const &);
00101 };
00102 
00108 template<class Scalar>
00109 class MaxTerminator: public Terminator {
00110 public:
00111   MaxTerminator(const Scalar & tx, Scalar maxval) : x(tx), mv(maxval) {}
00112   
00113   virtual bool query() {
00114     return (x > mv);
00115   }
00116 
00117 protected:
00118   const Scalar & x;
00119   Scalar mv;
00120 };
00121 
00127 template<class Scalar>
00128 class MinTerminator: public Terminator {
00129 public:
00130   MinTerminator(const Scalar & tx, Scalar minval) : x(tx), mv(minval) {}
00131   
00132   virtual bool query() {
00133     cout<<"   MinTerminator: test scalar = "<<x<<" threshold = "<<mv<<endl;
00134     return (x < mv);
00135   }
00136 
00137 protected:
00138   const Scalar & x;
00139   Scalar mv;
00140 };
00141 
00147   template<class Scalar>
00148   class MinTerminatorFE: public Terminator {
00149   public:
00150     MinTerminatorFE(RVL::FunctionalEvaluation<Scalar> & _fx, Scalar minval) 
00151       : fx(_fx), mv(minval) {}
00152     
00153     virtual bool query() {
00154       Scalar x = fx.getValue();
00155       cout<<"   MinTerminator: test scalar = "<<x<<" threshold = "<<mv<<endl;
00156       return (x < mv);
00157     }
00158     
00159   protected:
00160     Scalar mv;
00161   private:
00162     RVL::FunctionalEvaluation<Scalar> & fx;
00163   };
00164 
00165 
00166 }
00167 
00168 #endif

Generated on 5 Jan 2017 for RvlAlg by  doxygen 1.4.7