CVR-Lib last update 20 Sep 2009

cvrValidator.h

Go to the documentation of this file.
00001 /*
00002  * Copyright (C) 1998
00003  * Lehrstuhl fuer Technische Informatik, RWTH-Aachen, Germany
00004  *
00005  *
00006  * This file is part of the Computer Vision and Robotics Library (CVR-Lib)
00007  *
00008  * The CVR-Lib is free software; you can redistribute it and/or
00009  * modify it under the terms of the BSD License.
00010  *
00011  * All rights reserved.
00012  *
00013  * Redistribution and use in source and binary forms, with or without
00014  * modification, are permitted provided that the following conditions are met:
00015  *
00016  * 1. Redistributions of source code must retain the above copyright notice,
00017  *    this list of conditions and the following disclaimer.
00018  *
00019  * 2. Redistributions in binary form must reproduce the above copyright notice,
00020  *    this list of conditions and the following disclaimer in the documentation
00021  *    and/or other materials provided with the distribution.
00022  *
00023  * 3. Neither the name of the authors nor the names of its contributors may be
00024  *    used to endorse or promote products derived from this software without
00025  *    specific prior written permission.
00026  *
00027  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00028  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00029  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00030  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
00031  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00032  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00033  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00034  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00035  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00036  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00037  * POSSIBILITY OF SUCH DAMAGE.
00038  */
00039 
00040 
00041 /**
00042  * \file   cvrValidator.h
00043  *         Contains a class that checks the validity of the elements of
00044  *         matrices and vectors of floating point types (e.g. float and double). * \author Jochen Wickel
00045  * \date   05.12.2001
00046  *
00047  * $Id: cvrValidator.h,v 1.4 2005/01/03 16:17:52 alvarado Exp $
00048  */
00049 
00050 #ifndef _CVR_VALIDATOR_H_
00051 #define _CVR_VALIDATOR_H_
00052 
00053 
00054 #include "cvrFunctor.h"
00055 #include "cvrMatrix.h"
00056 #include "cvrComplex.h"
00057 
00058 namespace cvr {
00059   /**
00060    * Matrix and Vector validity check.
00061    *
00062    * Checks the validity of a matrix or vector with float or double
00063    * elements. A matrix is invalid, if it contains nan or inf elements.
00064    * Otherwise, it is assumed to be valid.
00065    *
00066    * @todo The pointer to functions are not a good idea, since it is
00067    *       not easily serializable.  We need a family of functors that can
00068    *       belong to a factory, which can then be easily serialized through
00069    *       their names.
00070    */
00071   class validator : public functor {
00072   public:
00073 
00074     /**
00075      * Type of a function that checks a single double value
00076      */
00077     typedef bool (doubleValidator)(double);
00078 
00079     /**
00080      * Type of a function that checks a single float value
00081      */
00082     typedef bool (floatValidator)(float);
00083 
00084     /**
00085      * The parameters for the class validator
00086      */
00087     class parameters : public functor::parameters {
00088     public:
00089       /**
00090        * Default constructor
00091        */
00092       parameters();
00093 
00094       /**
00095        * Copy constructor
00096        * @param other the parameters object to be copied
00097        */
00098       parameters(const parameters& other);
00099 
00100       /**
00101        * Destructor
00102        */
00103       ~parameters();
00104 
00105       /**
00106        * Copy the contents of a parameters object
00107        * @param other the parameters object to be copied
00108        * @return a reference to this parameters object
00109        */
00110       parameters& copy(const parameters& other);
00111 
00112       /**
00113        * Copy the contents of a parameters object
00114        * @param other the parameters object to be copied
00115        * @return a reference to this parameters object
00116        */
00117       parameters& operator=(const parameters& other);
00118 
00119       /**
00120        * Returns the name of this class.
00121        */
00122       virtual const std::string& name() const;
00123 
00124       /**
00125        * Returns a pointer to a clone of the parameters
00126        */
00127       virtual functor::parameters* clone() const;
00128 
00129       /**
00130        * Returns a pointer to a clone of the parameters
00131        */
00132       virtual functor::parameters* newInstance() const;
00133 
00134       /**
00135        * Write the parameters in the given ioHandler
00136        * @param handler the ioHandler to be used
00137        * @param complete if true (the default) the enclosing begin/end will
00138        *        be also written, otherwise only the data block will be written.
00139        * @return true if write was successful
00140        */
00141       virtual bool write(ioHandler& handler,const bool complete=true) const;
00142 
00143       /**
00144        * Read the parameters from the given ioHandler
00145        * @param handler the ioHandler to be used
00146        * @param complete if true (the default) the enclosing begin/end will
00147        *        be also written, otherwise only the data block will be written.
00148        * @return true if write was successful
00149        */
00150       virtual bool read(ioHandler& handler,const bool complete=true);
00151 
00152       // ------------------------------------------------
00153       // the parameters
00154       // ------------------------------------------------
00155 
00156       /**
00157        * Pointer to a C function or a static member function that
00158        * evaluates if a value is a valid floating point representation
00159        * for the double type.
00160        *
00161        * Default value: defaultValidateDouble()
00162        */
00163       doubleValidator* isDoubleValid;
00164 
00165       /**
00166        * Pointer to a C function or a static member function that
00167        * evaluates if a value is a valid floating point representation
00168        * for the float type.
00169        *
00170        * Default value: defaultValidateFloat()
00171        */
00172       floatValidator* isFloatValid;
00173 
00174       /**
00175        * Default function to check the validity of a double value
00176        */
00177       static bool defaultValidateDouble(double x);
00178 
00179       /**
00180        * Default function to check the validity of a float value
00181        */
00182       static bool defaultValidateFloat(float x);
00183 
00184     };
00185 
00186     /**
00187      * Default constructor
00188      */
00189     validator();
00190 
00191     /**
00192      * Copy constructor
00193      * @param other the object to be copied
00194      */
00195     validator(const validator& other);
00196 
00197     /**
00198      * Destructor
00199      */
00200     virtual ~validator();
00201 
00202     /**
00203      * Operates on the given %parameter.
00204      * @param src vector<double> with the source data.
00205      * @return true if the vector is valid or false otherwise.
00206      */
00207     bool apply(const vector<double>& src) const;
00208 
00209     /**
00210      * Operates on the given %parameter.
00211      * @param src vector<float> with the source data.
00212      * @return true if the vector is valid or false otherwise.
00213      */
00214     bool apply(const vector<float>& src) const;
00215 
00216     /**
00217      * Operates on the given %parameter.
00218      * @param src vector<double> with the source data.
00219      * @return true if the vector is valid or false otherwise.
00220      */
00221     bool apply(const vector<dcomplex>& src) const;
00222 
00223     /**
00224      * Operates on the given %parameter.
00225      * @param src vector<float> with the source data.
00226      * @return true if the vector is valid or false otherwise.
00227      */
00228     bool apply(const vector<fcomplex>& src) const;
00229 
00230     /**
00231      * Operates on the given %parameter.
00232      * @param src matrix<double> with the source data.
00233      * @return true if the matrix is valid or false otherwise.
00234      */
00235     bool apply(const matrix<double>& src) const;
00236 
00237     /**
00238      * Operates on the given %parameter.
00239      * @param src matrix<float> with the source data.
00240      * @return true if the matrix is valid  or false otherwise.
00241      */
00242     bool apply(const matrix<float>& src) const;
00243 
00244     /**
00245      * Operates on the given %parameter.
00246      * @param src matrix<double> with the source data.
00247      * @return true if the matrix is valid or false otherwise.
00248      */
00249     bool apply(const matrix<dcomplex>& src) const;
00250 
00251     /**
00252      * Operates on the given %parameter.
00253      * @param src matrix<float> with the source data.
00254      * @return true if the matrix is valid  or false otherwise.
00255      */
00256     bool apply(const matrix<fcomplex>& src) const;
00257 
00258     /**
00259      * Copy data of "other" functor.
00260      * @param other the functor to be copied
00261      * @return a reference to this functor object
00262      */
00263     validator& copy(const validator& other);
00264 
00265     /**
00266      * Alias for copy member
00267      * @param other the functor to be copied
00268      * @return a reference to this functor object
00269      */
00270     validator& operator=(const validator& other);
00271 
00272     /**
00273      * Returns the name of this class.
00274      */
00275     virtual const std::string& name() const;
00276 
00277     /**
00278      * Returns a pointer to a clone of this functor.
00279      */
00280     virtual functor* clone() const;
00281 
00282     /**
00283      * Returns a pointer to a new instance of this functor.
00284      */
00285     virtual functor* newInstance() const;
00286 
00287     /**
00288      * Returns used parameters
00289      */
00290     const parameters& getParameters() const;
00291   };
00292 }
00293 
00294 #endif
00295 

Generated on Sun Sep 20 22:08:00 2009 for CVR-Lib by Doxygen 1.5.8