IOptions.h

Go to the documentation of this file.
00001 // @(#)root/mathcore:$Id: IOptions.h 36764 2010-11-19 10:02:00Z moneta $ 
00002 // Author: L. Moneta Fri Aug 15 2008
00003 
00004 /**********************************************************************
00005  *                                                                    *
00006  * Copyright (c) 2008  LCG ROOT Math Team, CERN/PH-SFT                *
00007  *                                                                    *
00008  *                                                                    *
00009  **********************************************************************/
00010 
00011 #ifndef ROOT_Math_IOptions
00012 #define ROOT_Math_IOptions
00013 
00014 
00015 #ifndef ROOT_Math_Error
00016 #include "Math/Error.h"
00017 #endif
00018 
00019 #include <iostream>
00020 
00021 namespace ROOT { 
00022    
00023 
00024    namespace Math { 
00025 
00026 //_______________________________________________________________________________
00027 /** 
00028     Generic interface for defining configuration options of a numerical algorithm
00029 
00030     @ingroup NumAlgo
00031 */
00032 class IOptions {
00033 
00034 public:
00035 
00036    IOptions() /* : fExtraOptions(0) */  {}
00037 
00038    virtual ~IOptions() {}// { if (fExtraOptions) delete fExtraOptions; }
00039 
00040    // copy the options 
00041    virtual IOptions * Clone() const = 0; 
00042 
00043    /** generic  methods for  retrivieng options */
00044 
00045    /// set option value 
00046    void SetValue(const char * name, double val) { SetRealValue(name,val);}
00047    void SetValue(const char * name, int val) { SetIntValue(name,val);}
00048    void SetValue(const char * name, const char * val) { SetNamedValue(name,val);}
00049 
00050    
00051    double  RValue(const char * name) const {
00052       double val = 0;
00053       bool ret = GetRealValue(name,val);
00054       if (!ret )  MATH_ERROR_MSGVAL("IOptions::RValue"," return 0 - real option not found",name); 
00055       return val;
00056    }
00057 
00058    int   IValue(const char * name) const {
00059       int val = 0;
00060       bool ret = GetIntValue(name,val);
00061       if (!ret )   MATH_ERROR_MSGVAL("IOptions::IValue"," return 0 - integer option not found",name); 
00062       return val;
00063    }
00064 
00065    std::string  NamedValue(const char * name) const {
00066       std::string val;
00067       bool ret = GetNamedValue(name,val);
00068       if (!ret )  MATH_ERROR_MSGVAL("IOptions::NamedValue"," return empty string - named option not found",name); 
00069       return val;
00070    }
00071 
00072 
00073    // generic method to retrieve  a type 
00074    template <typename T>
00075    bool GetValue(const char * name, T & t) const { 
00076       bool ret = DoGetValue(name, t);
00077       //if (!ret )  MATH_ERROR_MSG("IOptions::GetValue","option is not existing - returns 0"); 
00078       return ret; 
00079    }
00080 
00081 
00082    // methods to be re-implemented in the derived classes 
00083 
00084 
00085    virtual bool GetRealValue(const char *, double &) const { return false; }
00086 
00087    virtual bool GetIntValue(const char *, int &) const { return false; }
00088 
00089    virtual bool GetNamedValue(const char *, std::string &) const { return false; }
00090 
00091    /// method wich need to be re-implemented by the derived classes 
00092    virtual void SetRealValue(const char * , double )  {MATH_ERROR_MSG("IOptions::SetRealValue","Invalid setter method called"); }
00093 
00094    virtual void SetIntValue(const char * , int ) {MATH_ERROR_MSG("IOptions::SetIntValue","Invalid setter method called"); }
00095 
00096    virtual void SetNamedValue(const char * , const char * ) {MATH_ERROR_MSG("IOptions::SetNamedValue","Invalid setter method called"); }
00097 
00098 
00099    /// print options 
00100    virtual void Print(std::ostream & = std::cout ) const {MATH_INFO_MSG("IOptions::Print","it is not implemented");}
00101 
00102 
00103 private: 
00104 
00105    bool DoGetValue(const char *name, double &val) const { return GetRealValue(name,val); }
00106 
00107    bool DoGetValue(const char *name, int &val) const { return GetIntValue(name,val); }
00108 
00109    bool DoGetValue(const char *name, std::string &val) const { return GetNamedValue(name,val); }
00110 
00111    
00112 };
00113 
00114 
00115    } // end namespace Math
00116 
00117 } // end namespace ROOT
00118 
00119 #endif

Generated on Tue Jul 5 14:25:31 2011 for ROOT_528-00b_version by  doxygen 1.5.1