VAPOR3 3.9.4
PWidgetHLI.h
Go to the documentation of this file.
1#pragma once
2
4
5#define CreateHLIBase(T, LT) \
6 template<class P> class PWidgetHLIBase<P, T> { \
7 protected: \
8 typedef std::function<T(P *)> GetterType; \
9 typedef std::function<void(P *, T)> SetterType; \
10 \
11 public: \
12 PWidgetHLIBase(PWidget *w, GetterType getter, SetterType setter) \
13 { \
14 w->_usingHLI = true; \
15 w->_setter##LT = [setter](void *p, T v) { setter((P *)p, v); }; \
16 w->_getter##LT = [getter](void *p) { return getter((P *)p); }; \
17 } \
18 };
19
20#define CreateInferredTemplateConstructor(className, T, constModifier) \
21 template<class P> className##HLI<P> *new_##className##HLI(const std::string &label, T (P::*getter)() constModifier, void (P::*setter)(T)) { return new className##HLI<P>(label, getter, setter); }
22
23#define CreateHLI(className, T) \
24 template<class P> class className##HLI final : public className, public PWidgetHLIBase<P, T> { \
25 public: \
26 className##HLI(const std::string &label, typename PWidgetHLIBase<P, T>::GetterType getter, typename PWidgetHLIBase<P, T>::SetterType setter) \
27 : className("", label), PWidgetHLIBase<P, T>((PWidget *)this, getter, setter) \
28 { \
29 } \
30 }; \
31 CreateInferredTemplateConstructor(className, T, ); \
32 CreateInferredTemplateConstructor(className, T, const);
33
34CreateHLIBase(long, Long);
35CreateHLIBase(bool, Long);
36CreateHLIBase(int, Long);
37CreateHLIBase(double, Double);
38CreateHLIBase(float, Double);
39CreateHLIBase(std::string, String);
40
41//
42// My attempt at implementing this using purely function templates and no defines. Below is pretty close.
43// It works but requires too much specilization code so I stopped working on it for now.
44//
45
46#ifdef SAVED_FOR_LATER
47template<class Base, class Derived> void AssertInheritance() { (void)static_cast<Base *>((Derived *)0); }
48
49template<class PW, typename T, class P, typename... Args> class PWidgetHLI : public PW {
50 typedef std::function<T(P *)> GetterType;
51 typedef std::function<void(P *, T)> SetterType;
52
53 GetterType _getter;
54 SetterType _setter;
55
56public:
57 PWidgetHLI(std::string label, Args... args, GetterType getter, SetterType setter) : PW("", args..., label)
58 {
59 printf("PWidgetHLI Constructor (%s)\n", label.c_str());
60 AssertInheritance<PWidget, PW>();
61 AssertInheritance<VAPoR::ParamsBase, P>();
62
63 this->_usingHLI = true;
64
65 this->_getter = getter;
66 this->_setter = setter;
67 }
68
69 virtual long getParamsLong() const override
70 {
71 static_assert(std::is_convertible<T, long>(), "");
72 // return this->_getterLong(this->getParams());
73 return this->_getter((P *)this->getParams());
74 }
75
76 virtual void _setParamsLong(long v) override
77 {
78 static_assert(std::is_convertible<T, long>(), "");
79 // return this->_setterLong(this->getParams(), v);
80 this->_setter((P *)this->getParams(), v);
81 }
82
83 // template <typename=typename std::enable_if<std::is_convertible<T, std::string>::type>>
84 virtual std::string getParamsString() const override
85 {
86 static_assert(std::is_convertible<T, std::string>(), "");
87 // return this->_getterLong(this->getParams());
88 return this->_getter((P *)this->getParams());
89 }
90
91 virtual void _setParamsString(const std::string &v) override
92 {
93 static_assert(std::is_convertible<T, std::string>(), "");
94 // return this->_setterLong(this->getParams(), v);
95 this->_setter((P *)this->getParams(), v);
96 }
97};
98
99template<class PW, typename T, class P, typename... Args> class PWidgetHLI2 : public PWidgetHLI<PW, T, P, Args...> {
100 using PWidgetHLI<PW, T, P, Args...>::PWidgetHLI;
101};
102
103template<class PW, class P, typename... Args> class PWidgetHLI2<PW, std::string, P, Args...> : public PWidgetHLI<PW, std::string, P, Args...> {
104 using PWidgetHLI<PW, std::string, P, Args...>::PWidgetHLI;
105 virtual std::string getParamsString() const override {}
106};
107
108template<class PW, typename T, class P, typename... Args> typename std::enable_if<std::is_same<T, bool>::value, T>::type class PWidgetHLI2 : public PWidgetHLI<PW, T, P, Args...> {
109 virtual long getParamsLong() const override {}
110};
111
112// template <class PW, class P, typename... Args>
113// class PWidgetHLI2<PW, std::string, P, Args...> : public PWidgetHLI<PW, std::string, P, Args...> {
114
115//
116//};
117#endif
#define CreateHLIBase(T, LT)
Creates the framework for creating Params Widgets that use the Params Database high level interface.
Definition: PWidgetHLI.h:5