CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_5_2_7_hltpatch1/src/Fireworks/Core/interface/FWGenericParameter.h

Go to the documentation of this file.
00001 #ifndef Fireworks_Core_FWGenericParameter_h
00002 #define Fireworks_Core_FWGenericParameter_h
00003 // -*- C++ -*-
00004 //
00005 // Package:     Core
00006 // Class  :     FWBoolParameter
00007 //
00015 //
00016 // Original Author:  Chris Jones
00017 //         Created:  Fri Mar  7 14:36:34 EST 2008
00018 // $Id: FWGenericParameter.h,v 1.3 2012/02/22 03:45:57 amraktad Exp $
00019 //
00020 
00021 // system include files
00022 #include <sigc++/signal.h>
00023 #include <sstream>
00024 
00025 // user include files
00026 #include "Fireworks/Core/interface/FWParameterBase.h"
00027 #include "Fireworks/Core/interface/FWConfiguration.h"
00028 
00029 // forward declarations
00030 
00031 template <class T>
00032 class FWGenericParameter : public FWParameterBase
00033 {
00034 public:
00035    typedef T value_type;
00036 
00037    FWGenericParameter() :
00038       FWParameterBase(0, "invalid")
00039    {}
00040 
00041    FWGenericParameter(FWParameterizable* iParent,
00042                       const std::string& iName,
00043                       const T &iDefault=T()) :
00044       FWParameterBase(iParent,iName),
00045       m_value(iDefault)
00046    {}
00047 
00048    template <class K>
00049    FWGenericParameter(FWParameterizable* iParent,
00050                       const std::string& iName,
00051                       K iCallback,
00052                       const T &iDefault=T()) :
00053       FWParameterBase(iParent,iName),
00054       m_value(iDefault)
00055    {
00056       changed_.connect(iCallback);
00057    }
00058 
00059    //virtual ~FWBoolParameter();
00060 
00061 
00062    // ---------- const member functions ---------------------
00063 
00064    T value() const { return m_value; }
00065 
00066    virtual void addTo(FWConfiguration& iTo) const 
00067    {
00068       std::ostringstream s;
00069       s<<m_value;
00070       iTo.addKeyValue(name(),FWConfiguration(s.str()));
00071    }
00072 
00073    // ---------- static member functions --------------------
00074 
00075    // ---------- member functions ---------------------------
00076 
00077    virtual void setFrom(const FWConfiguration&iFrom)
00078    {
00079       if (const FWConfiguration* config = iFrom.valueForKey(name()))
00080       {
00081          std::istringstream s(config->value());
00082          s>>m_value;
00083       }
00084       changed_(m_value);
00085    }
00086 
00087    void set(T iValue)
00088    {
00089       m_value = iValue;
00090       changed_(iValue);
00091    }
00092 
00093    sigc::signal<void,T> changed_;
00094 
00095 private:
00096    FWGenericParameter(const FWGenericParameter&);                  // stop default
00097    const FWGenericParameter& operator=(const FWGenericParameter&); // stop default
00098 
00099    // ---------- member data --------------------------------
00100 
00101    T m_value;
00102 };
00103 
00104 
00105 #endif