CMS 3D CMS Logo

FWGenericParameter.h
Go to the documentation of this file.
1 #ifndef Fireworks_Core_FWGenericParameter_h
2 #define Fireworks_Core_FWGenericParameter_h
3 // -*- C++ -*-
4 //
5 // Package: Core
6 // Class : FWBoolParameter
7 //
15 //
16 // Original Author: Chris Jones
17 // Created: Fri Mar 7 14:36:34 EST 2008
18 //
19 
20 // system include files
21 #include <sigc++/signal.h>
22 #include <sstream>
23 
24 // user include files
27 
28 // forward declarations
29 
30 template <class T>
32 public:
33  typedef T value_type;
34 
35  FWGenericParameter() : FWParameterBase(nullptr, "invalid") {}
36 
37  FWGenericParameter(FWParameterizable* iParent, const std::string& iName, const T& iDefault = T())
38  : FWParameterBase(iParent, iName), m_value(iDefault) {}
39 
40  template <class K>
41  FWGenericParameter(FWParameterizable* iParent, const std::string& iName, K iCallback, const T& iDefault = T())
42  : FWParameterBase(iParent, iName), m_value(iDefault) {
43  changed_.connect(iCallback);
44  }
45 
46  //virtual ~FWBoolParameter();
47 
48  // ---------- const member functions ---------------------
49 
50  T value() const { return m_value; }
51 
52  void addTo(FWConfiguration& iTo) const override {
53  std::ostringstream s;
54  s << m_value;
55  iTo.addKeyValue(name(), FWConfiguration(s.str()));
56  }
57 
58  // ---------- static member functions --------------------
59 
60  // ---------- member functions ---------------------------
61 
62  void setFrom(const FWConfiguration& iFrom) override {
63  if (const FWConfiguration* config = iFrom.valueForKey(name())) {
64  std::istringstream s(config->value());
65  s >> m_value;
66  }
68  }
69 
70  void set(T iValue) {
71  m_value = iValue;
72  changed_(iValue);
73  }
74 
75  sigc::signal<void(T)> changed_;
76 
77  FWGenericParameter(const FWGenericParameter&) = delete; // stop default
78  const FWGenericParameter& operator=(const FWGenericParameter&) = delete; // stop default
79 
80 private:
81  // ---------- member data --------------------------------
82 
84 };
85 
86 #endif
void setFrom(const FWConfiguration &iFrom) override
Definition: config.py:1
const FWGenericParameter & operator=(const FWGenericParameter &)=delete
const std::string & name() const
FWGenericParameter(FWParameterizable *iParent, const std::string &iName, K iCallback, const T &iDefault=T())
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
void addTo(FWConfiguration &iTo) const override
FWGenericParameter(FWParameterizable *iParent, const std::string &iName, const T &iDefault=T())
const FWConfiguration * valueForKey(const std::string &iKey) const
sigc::signal< void(T)> changed_
long double T