CMS 3D CMS Logo

/data/refman/pasoursint/CMSSW_4_1_8_patch9/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.2 2010/02/13 14:01:33 eulisse 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    //virtual ~FWBoolParameter();
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    // ---------- const member functions ---------------------
00059    T value() const {
00060       return m_value;
00061    }
00062 
00063    virtual void addTo(FWConfiguration& iTo) const 
00064    {
00065       std::ostringstream s;
00066       s<<m_value;
00067       iTo.addKeyValue(name(),FWConfiguration(s.str()));
00068    }
00069 
00070    // ---------- static member functions --------------------
00071 
00072    // ---------- member functions ---------------------------
00073    virtual void setFrom(const FWConfiguration&iFrom) {
00074       if (const FWConfiguration* config = iFrom.valueForKey(name()) ) {
00075          std::istringstream s(config->value());
00076          s>>m_value;
00077       }
00078       changed_(m_value);
00079    }
00080 
00081    void set(T iValue)
00082    {
00083       m_value = iValue;
00084       changed_(iValue);
00085    }
00086 
00087    sigc::signal<void,T> changed_;
00088 
00089 private:
00090    FWGenericParameter(const FWGenericParameter&);   // stop default
00091 
00092    const FWGenericParameter& operator=(const FWGenericParameter&);   // stop default
00093 
00094    // ---------- member data --------------------------------
00095    T m_value;
00096 };
00097 
00098 
00099 #endif