CMS 3D CMS Logo

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Pages
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 // $Id: FWGenericParameter.h,v 1.3 2012/02/22 03:45:57 amraktad Exp $
19 //
20 
21 // system include files
22 #include <sigc++/signal.h>
23 #include <sstream>
24 
25 // user include files
28 
29 // forward declarations
30 
31 template <class T>
33 {
34 public:
35  typedef T value_type;
36 
38  FWParameterBase(0, "invalid")
39  {}
40 
42  const std::string& iName,
43  const T &iDefault=T()) :
44  FWParameterBase(iParent,iName),
45  m_value(iDefault)
46  {}
47 
48  template <class K>
50  const std::string& iName,
51  K iCallback,
52  const T &iDefault=T()) :
53  FWParameterBase(iParent,iName),
54  m_value(iDefault)
55  {
56  changed_.connect(iCallback);
57  }
58 
59  //virtual ~FWBoolParameter();
60 
61 
62  // ---------- const member functions ---------------------
63 
64  T value() const { return m_value; }
65 
66  virtual void addTo(FWConfiguration& iTo) const
67  {
68  std::ostringstream s;
69  s<<m_value;
70  iTo.addKeyValue(name(),FWConfiguration(s.str()));
71  }
72 
73  // ---------- static member functions --------------------
74 
75  // ---------- member functions ---------------------------
76 
77  virtual void setFrom(const FWConfiguration&iFrom)
78  {
79  if (const FWConfiguration* config = iFrom.valueForKey(name()))
80  {
81  std::istringstream s(config->value());
82  s>>m_value;
83  }
85  }
86 
87  void set(T iValue)
88  {
89  m_value = iValue;
90  changed_(iValue);
91  }
92 
93  sigc::signal<void,T> changed_;
94 
95 private:
96  FWGenericParameter(const FWGenericParameter&); // stop default
97  const FWGenericParameter& operator=(const FWGenericParameter&); // stop default
98 
99  // ---------- member data --------------------------------
100 
102 };
103 
104 
105 #endif
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