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 {
33 public:
34  typedef T value_type;
35 
37  FWParameterBase(0, "invalid")
38  {}
39 
41  const std::string& iName,
42  const T &iDefault=T()) :
43  FWParameterBase(iParent,iName),
44  m_value(iDefault)
45  {}
46 
47  template <class K>
49  const std::string& iName,
50  K iCallback,
51  const T &iDefault=T()) :
52  FWParameterBase(iParent,iName),
53  m_value(iDefault)
54  {
55  changed_.connect(iCallback);
56  }
57 
58  //virtual ~FWBoolParameter();
59 
60 
61  // ---------- const member functions ---------------------
62 
63  T value() const { return m_value; }
64 
65  virtual void addTo(FWConfiguration& iTo) const
66  {
67  std::ostringstream s;
68  s<<m_value;
69  iTo.addKeyValue(name(),FWConfiguration(s.str()));
70  }
71 
72  // ---------- static member functions --------------------
73 
74  // ---------- member functions ---------------------------
75 
76  virtual void setFrom(const FWConfiguration&iFrom)
77  {
78  if (const FWConfiguration* config = iFrom.valueForKey(name()))
79  {
80  std::istringstream s(config->value());
81  s>>m_value;
82  }
84  }
85 
86  void set(T iValue)
87  {
88  m_value = iValue;
89  changed_(iValue);
90  }
91 
92  sigc::signal<void,T> changed_;
93 
94 private:
95  FWGenericParameter(const FWGenericParameter&); // stop default
96  const FWGenericParameter& operator=(const FWGenericParameter&); // stop default
97 
98  // ---------- member data --------------------------------
99 
101 };
102 
103 
104 #endif
Definition: config.py:1
sigc::signal< void, T > changed_
FWGenericParameter(FWParameterizable *iParent, const std::string &iName, K iCallback, const T &iDefault=T())
FWConfiguration & addKeyValue(const std::string &, const FWConfiguration &)
const FWGenericParameter & operator=(const FWGenericParameter &)
FWGenericParameter(FWParameterizable *iParent, const std::string &iName, const T &iDefault=T())
virtual void addTo(FWConfiguration &iTo) const
virtual void setFrom(const FWConfiguration &iFrom)
const FWConfiguration * valueForKey(const std::string &iKey) const
long double T
const std::string & name() const