
00001 /*!@file Component/ModelParamBase.H A tunable ModelComponent parameter base class */ 00002 00003 // //////////////////////////////////////////////////////////////////// // 00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2003 // 00005 // by the University of Southern California (USC) and the iLab at USC. // 00006 // See http://iLab.usc.edu for information about this project. // 00007 // //////////////////////////////////////////////////////////////////// // 00008 // Major portions of the iLab Neuromorphic Vision Toolkit are protected // 00009 // under the U.S. patent ``Computation of Intrinsic Perceptual Saliency // 00010 // in Visual Environments, and Applications'' by Christof Koch and // 00011 // Laurent Itti, California Institute of Technology, 2001 (patent // 00012 // pending; application number 09/912,225 filed July 23, 2001; see // 00013 // http://pair.uspto.gov/cgi-bin/final/home.pl for current status). // 00014 // //////////////////////////////////////////////////////////////////// // 00015 // This file is part of the iLab Neuromorphic Vision C++ Toolkit. // 00016 // // 00017 // The iLab Neuromorphic Vision C++ Toolkit is free software; you can // 00018 // redistribute it and/or modify it under the terms of the GNU General // 00019 // Public License as published by the Free Software Foundation; either // 00020 // version 2 of the License, or (at your option) any later version. // 00021 // // 00022 // The iLab Neuromorphic Vision C++ Toolkit is distributed in the hope // 00023 // that it will be useful, but WITHOUT ANY WARRANTY; without even the // 00024 // implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR // 00025 // PURPOSE. See the GNU General Public License for more details. // 00026 // // 00027 // You should have received a copy of the GNU General Public License // 00028 // along with the iLab Neuromorphic Vision C++ Toolkit; if not, write // 00029 // to the Free Software Foundation, Inc., 59 Temple Place, Suite 330, // 00030 // Boston, MA 02111-1307 USA. // 00031 // //////////////////////////////////////////////////////////////////// // 00032 // 00033 // Primary maintainer for this file: Laurent Itti <itti@usc.edu> 00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Component/ModelParamBase.H $ 00035 // $Id: ModelParamBase.H 8758 2007-09-06 19:21:04Z rjpeters $ 00036 // 00037 00038 #ifndef MODELPARAMBASE_H_DEFINED 00039 #define MODELPARAMBASE_H_DEFINED 00040 00041 #include "Component/ParamFlags.H" 00042 00043 #include <string> 00044 #include <typeinfo> 00045 00046 class ModelOptionDef; 00047 class ParamMap; 00048 00049 //! Base class for TRefHolder 00050 class RefHolder 00051 { 00052 public: 00053 RefHolder(); 00054 virtual ~RefHolder(); 00055 00056 virtual const std::type_info& type() const = 0; 00057 00058 private: 00059 RefHolder(const RefHolder&); // not implemented 00060 RefHolder& operator=(const RefHolder&); // not implemented 00061 }; 00062 00063 //! Template implementation of RefHolder 00064 /*! Essentially this class just provides a way to dynamic_cast to any 00065 type. We do this by wrapping the type in a TRefHolder, which is 00066 dynamic_cast-able by virtue of having a virtual function. Thus we 00067 can construct for example a TRefHolder<int>, pass it somewhere as 00068 a RefHolder, and then somewhen can later dynamic_cast it back to a 00069 TRefHolder<int> and get the original int& back out. */ 00070 template <class T> 00071 class TRefHolder : public RefHolder 00072 { 00073 public: 00074 TRefHolder(T& r) : ref(r) {} 00075 virtual ~TRefHolder() {} 00076 00077 virtual const std::type_info& type() const { return typeid(T); } 00078 00079 T& ref; 00080 }; 00081 00082 // ###################################################################### 00083 //! ModelParamBase is a persistent ModelComponent parameter base class 00084 /*! Various model parameter types can be derived from this base, see 00085 the NModelParam and OModelParam template class 00086 definitions. ModelParamBase is persistent in the sense that it can 00087 be saved/loaded into a ParamMap, which itself provides disk 00088 save/load capabilities. ModelParamBase is intended to be used as a 00089 data member in a ModelComponent (or derived) 00090 object. ModelComponent provides an interface by which 00091 ModelParamBase derivatives may also be tuned via command-line 00092 options. */ 00093 class ModelParamBase 00094 { 00095 public: 00096 // ###################################################################### 00097 /*! @name Constructors and Destructors */ 00098 //@{ 00099 00100 //! Constructor 00101 /*! @param flags Will be checked for ALLOW_ONLINE_CHANGES to set 00102 up our return value from allowsOnlineChanges() appropriately. */ 00103 ModelParamBase(const ParamFlag flags); 00104 00105 //! Destructor 00106 virtual ~ModelParamBase(); 00107 00108 //@} 00109 00110 // ###################################################################### 00111 /*! @name Basic access functions */ 00112 //@{ 00113 00114 //! get the parameter's name 00115 virtual std::string getName() const = 0; 00116 00117 //! get the parameter's name with spaces separating words 00118 /*! This function decodes the CamelCase string that is typically 00119 returned by getName() into space-separated words, using some 00120 heuristics to figure out where to place word boundaries. It is 00121 not guaranteed to be perfectly accurate in finding word 00122 boundaries; this result is only intended for user-interface 00123 display to the end user and should not be relied on for 00124 programmatic usage. */ 00125 virtual std::string getNameWithSpaces() const; 00126 00127 //! Get current value as a string (must be implemented by derived classes) 00128 virtual std::string getValString() const = 0; 00129 00130 //! Set the parameter value from a textual representation, notify client of the change 00131 /*! @return true if the change succeeded; false otherwise. */ 00132 virtual bool setValString(const std::string& textval) = 0; 00133 00134 //! Get the current value through a dynamically-typed RefHolder. 00135 virtual void getValGeneric(RefHolder& ref) const = 0; 00136 00137 //! Set the current value through a dynamically-typed RefHolder, notify client of the change 00138 /*! @return true if the change succeeded; false otherwise. */ 00139 virtual bool setValGeneric(const RefHolder& ref) = 0; 00140 00141 //! Check whether this param is allowed to have its value changed while the model is active 00142 bool allowsOnlineChanges() const { return itsFlags & ALLOW_ONLINE_CHANGES; } 00143 00144 //! Change the param's active/inactive setting 00145 void setInactive(bool v) { if (v) itsFlags |= MP_INACTIVE; else itsFlags &= ~MP_INACTIVE; } 00146 00147 //! Check the param's active/inactive setting 00148 bool getInactive() const { return itsFlags & MP_INACTIVE; } 00149 00150 //! Change the param's hidden/visible setting 00151 void setHidden(bool v) { if (v) itsFlags |= MP_HIDDEN; else itsFlags &= ~MP_HIDDEN; } 00152 00153 //! Check the param's hidden/visible setting 00154 bool getHidden() const { return itsFlags & MP_HIDDEN; } 00155 00156 //@} 00157 00158 // ###################################################################### 00159 /*! @name Input/Output functions */ 00160 //@{ 00161 00162 //! Print out our name and contents, mostly for debugging 00163 virtual void printout(std::ostream& s, 00164 const std::string& prefix = "") const = 0; 00165 00166 //! Write parameter value to ParamMap 00167 virtual void writeTo(ParamMap& pmap) const = 0; 00168 00169 //! Get parameter value from ParamMap, notify client of the value change 00170 /*! @param noerr will not generate an error message if the parameter 00171 does not exist in ParamMap. */ 00172 virtual void readFrom(const ParamMap& pmap, 00173 const bool noerr = true) = 0; 00174 00175 //@} 00176 00177 private: 00178 ModelParamBase(const ModelParamBase& m); //!< forbid copy-contruction 00179 ModelParamBase& operator=(const ModelParamBase& m); //!< forbid copy 00180 00181 ParamFlag itsFlags; 00182 }; 00183 00184 // ###################################################################### 00185 //! OptionedModelParam extends ModelParamBase for params associated with a ModelOptionDef 00186 class OptionedModelParam : public ModelParamBase 00187 { 00188 public: 00189 OptionedModelParam(const ParamFlag flags); 00190 virtual ~OptionedModelParam(); 00191 00192 virtual const ModelOptionDef* getOptionDef() const = 0; 00193 }; 00194 00195 #endif // !MODELPARAMBASE_H_DEFINED 00196 00197 // ###################################################################### 00198 /* So things look consistent in everyone's emacs... */ 00199 /* Local Variables: */ 00200 /* indent-tabs-mode: nil */ 00201 /* End: */
1.4.4