Back to home page

Project CMSSW displayed by LXR

 
 

    


File indexing completed on 2021-12-14 11:45:01

0001 #ifndef Fireworks_Core_FWGenericParameter_h
0002 #define Fireworks_Core_FWGenericParameter_h
0003 // -*- C++ -*-
0004 //
0005 // Package:     Core
0006 // Class  :     FWBoolParameter
0007 //
0008 /**\class FWGenericParameter FWGenericParameter.h Fireworks/Core/interface/FWGenericParameter.h
0009 
0010    Description: Provides access to a simple generic parameter.
0011 
0012    Usage:
0013 
0014  */
0015 //
0016 // Original Author:  Chris Jones
0017 //         Created:  Fri Mar  7 14:36:34 EST 2008
0018 //
0019 
0020 // system include files
0021 #include <sigc++/signal.h>
0022 #include <sstream>
0023 
0024 // user include files
0025 #include "Fireworks/Core/interface/FWParameterBase.h"
0026 #include "Fireworks/Core/interface/FWConfiguration.h"
0027 
0028 // forward declarations
0029 
0030 template <class T>
0031 class FWGenericParameter : public FWParameterBase {
0032 public:
0033   typedef T value_type;
0034 
0035   FWGenericParameter() : FWParameterBase(nullptr, "invalid") {}
0036 
0037   FWGenericParameter(FWParameterizable* iParent, const std::string& iName, const T& iDefault = T())
0038       : FWParameterBase(iParent, iName), m_value(iDefault) {}
0039 
0040   template <class K>
0041   FWGenericParameter(FWParameterizable* iParent, const std::string& iName, K iCallback, const T& iDefault = T())
0042       : FWParameterBase(iParent, iName), m_value(iDefault) {
0043     changed_.connect(iCallback);
0044   }
0045 
0046   //virtual ~FWBoolParameter();
0047 
0048   // ---------- const member functions ---------------------
0049 
0050   T value() const { return m_value; }
0051 
0052   void addTo(FWConfiguration& iTo) const override {
0053     std::ostringstream s;
0054     s << m_value;
0055     iTo.addKeyValue(name(), FWConfiguration(s.str()));
0056   }
0057 
0058   // ---------- static member functions --------------------
0059 
0060   // ---------- member functions ---------------------------
0061 
0062   void setFrom(const FWConfiguration& iFrom) override {
0063     if (const FWConfiguration* config = iFrom.valueForKey(name())) {
0064       std::istringstream s(config->value());
0065       s >> m_value;
0066     }
0067     changed_(m_value);
0068   }
0069 
0070   void set(T iValue) {
0071     m_value = iValue;
0072     changed_(iValue);
0073   }
0074 
0075   sigc::signal<void(T)> changed_;
0076 
0077   FWGenericParameter(const FWGenericParameter&) = delete;                   // stop default
0078   const FWGenericParameter& operator=(const FWGenericParameter&) = delete;  // stop default
0079 
0080 private:
0081   // ---------- member data --------------------------------
0082 
0083   T m_value;
0084 };
0085 
0086 #endif