File indexing completed on 2024-04-06 12:11:31
0001 #ifndef Fireworks_Core_FWGenericParameter_h
0002 #define Fireworks_Core_FWGenericParameter_h
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021 #include <sigc++/signal.h>
0022 #include <sstream>
0023
0024
0025 #include "Fireworks/Core/interface/FWParameterBase.h"
0026 #include "Fireworks/Core/interface/FWConfiguration.h"
0027
0028
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
0047
0048
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
0059
0060
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;
0078 const FWGenericParameter& operator=(const FWGenericParameter&) = delete;
0079
0080 private:
0081
0082
0083 T m_value;
0084 };
0085
0086 #endif