Photon microGUI widgets library 0.6.0
phbitmask.hpp
1#ifndef PH_BITMASK_HPP
2#define PH_BITMASK_HPP
3
4#include "phproperty.hpp"
5#include "bitmask.hpp"
6
7#include <cstring>
8
9namespace PhWidgets
10{
11 template<class MaskT, class FlagT, MaskT Mask = ~(MaskT())>
12 class phbitmask
13 {
14 template<class WidgetClassT, class ArgumentT, ArgumentT ArgumentID>
15 class bind_internal
16 {
17 typedef MaskT mask_type;
18 typedef phproperty<mask_type> ph_property_t;
19 typedef typename ph_property_t::template bind<WidgetClassT, ArgumentT, ArgumentID> ph_bind_t;
20
21 ph_bind_t _value;
22
23 public:
24 typedef cppbitmasks::bitmask<MaskT, FlagT, Mask> value_type;
25
26 bind_internal(WidgetClassT *parent) :
27 _value(parent)
28 {}
29
30 inline
31 void set(value_type value)
32 {
33 _value.set(value);
34 }
35
36 inline
37 value_type get() const
38 {
39 value_type bm;
40 mask_type mask = _value.get();
41 std::memcpy(&bm, &mask, sizeof(MaskT));
42 return bm;
43 }
44
45 inline
46 bool has(value_type value) const
47 {
48 return get().has(value);
49 }
50
51 inline
52 operator value_type() const { return get(); }
53 inline
54 operator mask_type() const { return get(); }
55
56 inline
57 bind_internal &operator=(value_type value) { set(value); return *this; }
58
59 inline
60 value_type operator()(void) const { return get(); }
61
62 inline
63 void operator()(value_type value) { set(value); return *this; }
64 };
65
66 public:
67 template<class WidgetClassT, class ArgumentT, ArgumentT ArgumentID>
68 class bind :
69 public bind_internal<WidgetClassT, ArgumentT, ArgumentID>
70 {
71 typedef bind_internal<WidgetClassT, ArgumentT, ArgumentID> internal_bind_t;
72
73 public:
74 bind(WidgetClassT *parent) :
75 internal_bind_t(parent)
76 {}
77
78 using internal_bind_t::operator=;
79 };
80 };
81}
82
83#endif
The main namespace for all widgets.
Definition: Basic.h:11