ModelParamBatch.H

Go to the documentation of this file.
00001 /*!@file Component/ModelParamBatch.H Batch setting and restoring of model parameter values */
00002 
00003 // //////////////////////////////////////////////////////////////////// //
00004 // The iLab Neuromorphic Vision C++ Toolkit - Copyright (C) 2000-2005   //
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: Rob Peters <rjpeters at usc dot edu>
00034 // $HeadURL: svn://isvn.usc.edu/software/invt/trunk/saliency/src/Component/ModelParamBatch.H $
00035 // $Id: ModelParamBatch.H 8762 2007-09-06 22:58:08Z rjpeters $
00036 //
00037 
00038 #ifndef COMPONENT_MODELPARAMBATCH_H_DEFINED
00039 #define COMPONENT_MODELPARAMBATCH_H_DEFINED
00040 
00041 #include "Component/ModelParamBase.H" // for TRefHolder
00042 #include "rutz/shared_ptr.h"
00043 
00044 #include <string>
00045 #include <utility>
00046 #include <vector>
00047 
00048 class ModelComponent;
00049 
00050 /// A helper class for batch setting and restoring groups of parameter values
00051 /** Typical usage would be like this:
00052 
00053     \code
00054     ModelParamBatch params;
00055     params.addParamValue("SomeParam", int(1));
00056     params.addParamValue("SomeFlag", true);
00057     params.addParamValue("SomeString", "hello");
00058 
00059     ModelManager manager;
00060 
00061     params.installValues(&manager); // params are now 1,true,"hello"
00062     // ... do some work
00063 
00064     // ... later:
00065     params.restoreValues(&manager); // params are now back to their original values
00066     \endcode
00067 
00068  */
00069 class ModelParamBatch
00070 {
00071 public:
00072   ModelParamBatch();
00073 
00074   ~ModelParamBatch();
00075 
00076   /// Add a new parameter name and associated value to our list of managed parameters
00077   template <class T>
00078   void addParamValue(const std::string& paramname,
00079                      const T& val)
00080   {
00081     addParamValueAux(paramname,
00082                      rutz::shared_ptr<RefHolder>
00083                      (new TRefHolder<const T>(val)));
00084   }
00085 
00086   /// Install our stored parameter values in the given component
00087   /** The component's current values for those parameters will be
00088       remembered so that they can later be restored with
00089       restoreValue(). */
00090   void installValues(ModelComponent* comp);
00091 
00092   /// Restore parameter values saved during a previous installValues() call
00093   void restoreValues(ModelComponent* comp);
00094 
00095   /// Auxiliary implementation function for addParamValue()
00096   void addParamValueAux(const std::string& paramname,
00097                         const rutz::shared_ptr<RefHolder>& valref);
00098 
00099 private:
00100   std::vector<std::vector<std::pair<std::string, std::string> > > itsRestoreStack;
00101   std::vector<std::pair<std::string, rutz::shared_ptr<RefHolder> > > itsParamValues;
00102 };
00103 
00104 // ######################################################################
00105 /* So things look consistent in everyone's emacs... */
00106 /* Local Variables: */
00107 /* mode: c++ */
00108 /* indent-tabs-mode: nil */
00109 /* End: */
00110 
00111 #endif // COMPONENT_MODELPARAMBATCH_H_DEFINED
Generated on Sun May 8 08:40:23 2011 for iLab Neuromorphic Vision Toolkit by  doxygen 1.6.3