From 5638069842856b44d49612ea64b1fc2be8e060ca Mon Sep 17 00:00:00 2001 From: oktonion <0oktonion0@gmail.com> Date: Mon, 16 Oct 2017 00:53:51 +0300 Subject: [PATCH 01/10] implementing bitmasks broken since that commit --- src/Widget.cpp | 3 +++ src/Widget.h | 14 +++++++++- src/service/bitmask.hpp | 58 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 74 insertions(+), 1 deletion(-) create mode 100644 src/service/bitmask.hpp diff --git a/src/Widget.cpp b/src/Widget.cpp index 50a1a957..1ec1d294 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -127,6 +127,7 @@ Widget::Widget(int abn): BevelWidth(this), Size(this), Location(this), + ExtendedFlags(this), //callbacks: Destroyed(this), Blocked(this), @@ -154,6 +155,7 @@ Widget::Widget(PtWidget_t* wdg): BevelWidth(this), Size(this), Location(this), + ExtendedFlags(this), //callbacks: Destroyed(this), Blocked(this), @@ -218,6 +220,7 @@ Widget::Widget(const Widget &rhs): BevelWidth(this), Size(this), Location(this), + ExtendedFlags(this), //callbacks: Destroyed(this), Blocked(this), diff --git a/src/Widget.h b/src/Widget.h index dba94519..dc642811 100644 --- a/src/Widget.h +++ b/src/Widget.h @@ -15,6 +15,7 @@ #include "./service/stdex/stdex.h" #include "./service/phproperty.hpp" #include "./service/phevent.hpp" +#include "./service/bitmask.hpp" #include "./WidgetResource.hpp" @@ -28,6 +29,7 @@ namespace PhWidgets { using namespace cppproperties; using namespace phevents; + using namespace cppbitmasks; class Widget: protected detail::IPtWidget, @@ -445,7 +447,16 @@ namespace PhWidgets { }; - + struct ExFlags + { + enum eExFlags + { + consume_events, + internal_help, + damage_parent, + skip_layout + }; + }; private: @@ -546,6 +557,7 @@ namespace PhWidgets phproperty::bind BevelWidth; //!< Gets or sets the bevel width of the widget. phproperty::bind Size; //!< Gets or sets the size of the widget. phproperty::bind Location; //!< Gets or sets the position of the widget. + phproperty< bitmask >::bind ExtendedFlags; phwidgets_event Destroyed; //!< Occurs when the widget is destroyed. phwidgets_event Blocked; //!< Occurs when the widget is blocked. diff --git a/src/service/bitmask.hpp b/src/service/bitmask.hpp new file mode 100644 index 00000000..45029dde --- /dev/null +++ b/src/service/bitmask.hpp @@ -0,0 +1,58 @@ +#ifndef CPP_BITMASK_HPP +#define CPP_BITMASK_HPP + +namespace cppbitmasks +{ + template + class bitmask + { + public: + bitmask() : + _val(MaskT()) + { + } + bitmask(const MaskT &val) : + _val(val) + { + } + + bitmask(const bitmask &other) : + _val(other._val) + { + } + + bool test(const FlagT &flag) const + { + return 0 != (_val & flag); + } + + bitmask& set(const FlagT &flag) + { + _val |= flag; + return *this; + } + + bitmask& reset(const FlagT &flag) + { + _val &= ~flag; + return *this; + } + + bitmask& operator=(const MaskT &val) + { + _val = val; + return *this; + } + + bitmask& operator=(const bitmask &other) + { + _val = other._val; + return *this; + } + + private: + MaskT _val; + }; +} + +#endif \ No newline at end of file From dc5a201b89e885894917594664bea605652a4ef8 Mon Sep 17 00:00:00 2001 From: oktonion <0oktonion0@gmail.com> Date: Wed, 18 Oct 2017 17:26:05 +0300 Subject: [PATCH 02/10] + bitmask | --- src/service/bitmask.hpp | 79 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 8 deletions(-) diff --git a/src/service/bitmask.hpp b/src/service/bitmask.hpp index 45029dde..03784c4a 100644 --- a/src/service/bitmask.hpp +++ b/src/service/bitmask.hpp @@ -11,8 +11,9 @@ namespace cppbitmasks _val(MaskT()) { } - bitmask(const MaskT &val) : - _val(val) + + bitmask(const FlagT &flag) : + _val(flag) { } @@ -21,38 +22,100 @@ namespace cppbitmasks { } - bool test(const FlagT &flag) const + inline bool test(const FlagT &flag) const { return 0 != (_val & flag); } - bitmask& set(const FlagT &flag) + inline bool test(const bitmask &mask) const + { + return 0 != (_val & mask); + } + + inline bitmask& set(const FlagT &flag) { _val |= flag; return *this; } - bitmask& reset(const FlagT &flag) + inline bitmask& set(const bitmask &mask) + { + _val |= mask._val; + return *this; + } + + inline bitmask& reset(const FlagT &flag) { _val &= ~flag; return *this; } - bitmask& operator=(const MaskT &val) + inline bitmask& reset(const bitmask &mask) + { + _val &= ~mask._val; + return *this; + } + + inline bitmask& keep(const FlagT &flag) + { + _val &= flag; + return *this; + } + + inline bitmask& keep(const bitmask &mask) + { + _val &= mask._val; + return *this; + } + + inline bitmask& flip(const FlagT &flag) { - _val = val; + _val ^= flag; return *this; } - bitmask& operator=(const bitmask &other) + inline bitmask& flip(const bitmask &mask) + { + _val ^= mask._val; + return *this; + } + + inline bitmask& operator|(const FlagT &flag) + { + return set(flag); + } + + inline bitmask operator|(const bitmask &mask) const + { + return _val | mask._val; + } + + inline bitmask& operator=(const bitmask &other) { _val = other._val; return *this; } + inline bitmask& operator=(const FlagT &flag) + { + _val = flag; + return *this; + } + + inline operator const MaskT&() const + { + return _val; + } + private: MaskT _val; }; + + template + inline bitmask &operator|(const FlagT &flag1, const bitmask &flag2) + { + return flag2 | flag1; + } } #endif \ No newline at end of file From 13fd23113762e84c1f44853e5b1255fd13e02721 Mon Sep 17 00:00:00 2001 From: oktonion <0oktonion0@gmail.com> Date: Wed, 18 Oct 2017 21:40:02 +0300 Subject: [PATCH 03/10] bitmask finished --- src/service/bitmask.hpp | 40 ++++++++++++++++++++++++++++++++++++---- 1 file changed, 36 insertions(+), 4 deletions(-) diff --git a/src/service/bitmask.hpp b/src/service/bitmask.hpp index 03784c4a..d36e97d3 100644 --- a/src/service/bitmask.hpp +++ b/src/service/bitmask.hpp @@ -80,9 +80,9 @@ namespace cppbitmasks return *this; } - inline bitmask& operator|(const FlagT &flag) + inline bitmask operator|(const FlagT &flag) const { - return set(flag); + return _val | flag; } inline bitmask operator|(const bitmask &mask) const @@ -90,6 +90,26 @@ namespace cppbitmasks return _val | mask._val; } + inline bitmask operator&(const FlagT &flag) const + { + return _val & flag; + } + + inline bitmask operator&(const bitmask &mask) const + { + return _val & mask._val; + } + + inline bitmask operator^(const FlagT &flag) const + { + return _val ^ flag; + } + + inline bitmask operator^(const bitmask &mask) const + { + return _val ^ mask._val; + } + inline bitmask& operator=(const bitmask &other) { _val = other._val; @@ -112,9 +132,21 @@ namespace cppbitmasks }; template - inline bitmask &operator|(const FlagT &flag1, const bitmask &flag2) + inline bitmask operator|(const FlagT &flag, const bitmask &mask) + { + return mask | flag; + } + + template + inline bitmask operator&(const FlagT &flag, const bitmask &mask) + { + return mask & flag; + } + + template + inline bitmask operator^(const FlagT &flag, const bitmask &mask) { - return flag2 | flag1; + return mask ^ flag; } } From b7eaa6edb3e12c622214cec760af693591cd5b61 Mon Sep 17 00:00:00 2001 From: oktonion <0oktonion0@gmail.com> Date: Wed, 18 Oct 2017 23:38:12 +0300 Subject: [PATCH 04/10] flags for Widget added extended and widget flags to Widget bitmask fully implemented --- src/Widget.cpp | 7 ++- src/Widget.h | 117 +++++++++++++++++++++++++++++++++++----- src/service/bitmask.hpp | 48 +++++++++++++++-- 3 files changed, 155 insertions(+), 17 deletions(-) diff --git a/src/Widget.cpp b/src/Widget.cpp index 1ec1d294..73c0b082 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -128,6 +128,7 @@ Widget::Widget(int abn): Size(this), Location(this), ExtendedFlags(this), + WidgetFlags(this), //callbacks: Destroyed(this), Blocked(this), @@ -156,6 +157,7 @@ Widget::Widget(PtWidget_t* wdg): Size(this), Location(this), ExtendedFlags(this), + WidgetFlags(this), //callbacks: Destroyed(this), Blocked(this), @@ -221,6 +223,7 @@ Widget::Widget(const Widget &rhs): Size(this), Location(this), ExtendedFlags(this), + WidgetFlags(this), //callbacks: Destroyed(this), Blocked(this), @@ -307,12 +310,12 @@ Widget::operator PtWidget_t*() //for properties: void Widget::setEnabled(bool val) { - resource.argument[Arguments::flags].set(Pt_BLOCKED | Pt_GHOST, !val); + resource.argument[Arguments::flags].set(Flags::Blocked | Flags::Ghost, !val); } bool Widget::getEnabled() const { - return resource.argument[Arguments::flags].get(Pt_BLOCKED); + return resource.argument[Arguments::flags].get(Flags::Blocked); } void PhWidgets::Widget::setHelpTopic(std::string val) diff --git a/src/Widget.h b/src/Widget.h index dc642811..1f675261 100644 --- a/src/Widget.h +++ b/src/Widget.h @@ -176,8 +176,7 @@ namespace PhWidgets { enum eArgUnsignedLong { - eflags = Pt_ARG_EFLAGS //!< Extended flags inherited by all widgets: - //!< Documentation in progress... + eflags = Pt_ARG_EFLAGS //!< Extended \link Widget::ExtendedFlags flags\endlink inherited by all widgets. }; }; @@ -185,7 +184,7 @@ namespace PhWidgets { enum eArgLong { - flags = Pt_ARG_FLAGS, //!< Common flags used by all widgets. Except for those indicated as read-only, these flags are all read/write. + flags = Pt_ARG_FLAGS, //!< Common \link Widget::WidgetFlags flags\endlink used by all widgets. Except for those indicated as read-only, these flags are all read/write. resize_flags = Pt_ARG_RESIZE_FLAGS //!< Controls a widget's resize policy in both the x and y directions. //!< Documentation in progress... }; @@ -337,6 +336,69 @@ namespace PhWidgets }; }; + struct ThisFlags + { + struct Extended + { + //! Extended flags inherited by all widgets + enum eExFlags + { + //! Consume any event encountered, whether or not an action was performed as a result of that event. + //! (When a widget has processed an event and prevents another widget from interacting with the event, the first widget is said to have consumed the event.) + ConsumeEvents = Pt_CONSUME_EVENTS, + + InternalHelp = Pt_INTERNAL_HELP, //!< Display help information for the widget in a balloon, not in the Helpviewer. + //damage_parent = Pt_DAMAGE_PARENT, //!< If the widget is damaged for any reason, damage its parent instead (internal use only). + SkipLayout = Pt_SKIP_LAYOUT //!< Skip this widget when performing a layout. + }; + }; + + //! Common flags used by all widgets. Except for those indicated as read-only, these flags are all read/write. + enum eFlags + { + + AllButtons = Pt_ALL_BUTTONS, //!< Any pointer button can activate the widget. Default is the left button only. + Autohighlight = Pt_AUTOHIGHLIGHT, //!< Highlight and give focus to the widget when the cursor enters its extent, and unhighlight and remove focus when the cursor leaves. + Blocked = Pt_BLOCKED, //!< Prevent the widget and all its non-window-class children from interacting with Photon events. + + //! If certain widgets have this bit set, and your application sets their resources, the relevant callbacks are invoked. + //! Otherwise callbacks aren't invoked when your application sets resources. If a callback refers to this flag, its description says so explicitly. + //! For example, if this bit is set for a Divider and you use Divider::Undefined to change the size of one of its children, the Divider::DeviderDraged event is invoked. + CallbacksActive = Pt_CALLBACKS_ACTIVE, + + Clear = Pt_CLEAR, //!< (read-only) The widget's brothers-in-front don't intersect with its extent. + ClipHighlight = Pt_CLIP_HIGHLIGHT, //!< Clip the corners of the highlighting rectangle. + Damaged = Pt_DAMAGED, //!< (read-only) The Widget requires repair. + DamageFamily = Pt_DAMAGE_FAMILY, //!< (read-only) The widget and all its children need to be repaired. + DelayRealize = Pt_DELAY_REALIZE, //!< Prevent the widget from becoming realized unless it's explicitly realized with Widget::Realized event. + Destroyed = Pt_DESTROYED, //!< (read-only) The widget has been marked for destruction. + FocusRender = Pt_FOCUS_RENDER, //!< Render a focus indicator when the widget when it gets focus. + GetsFocus = Pt_GETS_FOCUS, //!< Allow the widget to be granted focus. The widget needs to have this bit set if it's to receive key events. + Ghost = Pt_GHOST, //!< Dim the widget. Setting this flag doesn't affect the widget's behavior, just its appearance. The simplest way to disable the widget is to set the Blocked flag in this resource. + Highlighted = Pt_HIGHLIGHTED, //!< Allow the widget to be highlighted as defined by the Widget::BevelWidth, and the Basic::BasicFlags. + InFlux = Pt_IN_FLUX, //!< (read-only) A call to PtContainerHold() has been made on the widget. + Menuable = Pt_MENUABLE, //!< Respond to clicks on the pointer's right button (i.e. enable the Basic::MenuActivate event). + MenuButton = Pt_MENU_BUTTON, //!< The widget is a menu item. + Obscured = Pt_OBSCURED, //!< (read-only) The widget is completely covered by one other widget, or it's completely outside its parent container's canvas. + Opaque = Pt_OPAQUE, //!< (read-only) This widget obscures everything directly behind it (i.e. it isn't transparent). + Procreated = Pt_PROCREATED, //!< (read-only) The widget was created by another widget (as opposed to an application), such as the List and Text created by a ComboBox. + Realized = Pt_REALIZED, //!< (read-only) The widget is realized. + Realizing = Pt_REALIZING, //!< (read-only) The widget is in the process of being realized. + Region = Pt_REGION, //!< Force the widget to have a region. + Selectable = Pt_SELECTABLE, //!< You can select (\link Basic::Repeat repeat \endlink, \link Basic::Arm arm \endlink, \link Basic::Disarm disarm \endlink and \link Basic::Activate activate \endlink) the widget. Widgets usually provide visual feedback when selected. + SelectNoredraw = Pt_SELECT_NOREDRAW, //!< The widget doesn't change its appearance when set or unset. This is meaningful only when the widget is Selectable. + Set = Pt_SET, //!< The widget is in a “set” state. Generally, this indicates that the widget has been selected. + + //! Pressing the pointer button on this widget causes it to toggle between being set and unset. + //! Normally, selectable widgets act as push buttons — they become set when you press the pointer button, and unset when you release the button. + Toggle = Pt_TOGGLE, + + WidgetRebuild = Pt_WIDGET_REBUILD, //!< (read-only) The widget will be rebuilt(rerealized) when the widget engine is finished applying resource changes. + WidgetResize = Pt_WIDGET_RESIZE, //!< (read-only) The widget will be resized when the widget engine is finished applying resource changes. + }; + + }; + struct ArgArea: public ThisArgs::ArgArea { @@ -447,17 +509,12 @@ namespace PhWidgets { }; - struct ExFlags + struct Flags: + public ThisFlags { - enum eExFlags - { - consume_events, - internal_help, - damage_parent, - skip_layout - }; }; + private: @@ -557,7 +614,9 @@ namespace PhWidgets phproperty::bind BevelWidth; //!< Gets or sets the bevel width of the widget. phproperty::bind Size; //!< Gets or sets the size of the widget. phproperty::bind Location; //!< Gets or sets the position of the widget. - phproperty< bitmask >::bind ExtendedFlags; + + phproperty< bitmask >::bind ExtendedFlags; //!< Gets or sets extended flags inherited by all widgets. See Flags::Extended. + phproperty< bitmask >::bind WidgetFlags; //!< Gets or sets flags inherited by all widgets. See Flags::eFlags. phwidgets_event Destroyed; //!< Occurs when the widget is destroyed. phwidgets_event Blocked; //!< Occurs when the widget is blocked. @@ -578,7 +637,41 @@ namespace PhWidgets }; + bitmask operator|(const Widget::Flags::Extended::eExFlags &flag1, const Widget::Flags::Extended::eExFlags &flag2) + { + bitmask bm(flag1); + return bm | flag2; + } + + bitmask operator&(const Widget::Flags::Extended::eExFlags &flag1, const Widget::Flags::Extended::eExFlags &flag2) + { + bitmask bm(flag1); + return bm & flag2; + } + + bitmask operator^(const Widget::Flags::Extended::eExFlags &flag1, const Widget::Flags::Extended::eExFlags &flag2) + { + bitmask bm(flag1); + return bm ^ flag2; + } + bitmask operator|(const Widget::Flags::eFlags &flag1, const Widget::Flags::eFlags &flag2) + { + bitmask bm(flag1); + return bm | flag2; + } + + bitmask operator&(const Widget::Flags::eFlags &flag1, const Widget::Flags::eFlags &flag2) + { + bitmask bm(flag1); + return bm & flag2; + } + + bitmask operator^(const Widget::Flags::eFlags &flag1, const Widget::Flags::eFlags &flag2) + { + bitmask bm(flag1); + return bm ^ flag2; + } }//namespace PhWidgets diff --git a/src/service/bitmask.hpp b/src/service/bitmask.hpp index d36e97d3..8dd27c23 100644 --- a/src/service/bitmask.hpp +++ b/src/service/bitmask.hpp @@ -110,16 +110,46 @@ namespace cppbitmasks return _val ^ mask._val; } + inline bitmask& operator=(const FlagT &flag) + { + _val = flag; + return *this; + } + inline bitmask& operator=(const bitmask &other) { _val = other._val; return *this; } - inline bitmask& operator=(const FlagT &flag) + inline bool operator==(const FlagT &flag) const { - _val = flag; - return *this; + return test(flag); + } + + inline bool operator==(const bitmask &other) const + { + return test(other); + } + + inline bool operator!=(const FlagT &flag) const + { + return !test(flag); + } + + inline bool operator!=(const bitmask &other) const + { + return !test(other); + } + + inline bool operator<(const bitmask &other) const + { + return _val < other._val; + } + + inline bool operator>(const bitmask &other) const + { + return _val > other._val; } inline operator const MaskT&() const @@ -148,6 +178,18 @@ namespace cppbitmasks { return mask ^ flag; } + + template + inline bitmask operator==(const FlagT &flag, const bitmask &mask) + { + return mask == flag; + } + + template + inline bitmask operator!=(const FlagT &flag, const bitmask &mask) + { + return mask != flag; + } } #endif \ No newline at end of file From 9b01cd85d906cf572c966f797dde5b9acdc423e6 Mon Sep 17 00:00:00 2001 From: oktonion <0oktonion0@gmail.com> Date: Thu, 19 Oct 2017 00:01:59 +0300 Subject: [PATCH 05/10] adding operators to global namespace --- src/Widget.h | 66 ++++++++++++++++++++--------------------- src/service/bitmask.hpp | 50 +++++++++++++++---------------- 2 files changed, 58 insertions(+), 58 deletions(-) diff --git a/src/Widget.h b/src/Widget.h index 1f675261..92e024b0 100644 --- a/src/Widget.h +++ b/src/Widget.h @@ -636,44 +636,44 @@ namespace PhWidgets }; - - bitmask operator|(const Widget::Flags::Extended::eExFlags &flag1, const Widget::Flags::Extended::eExFlags &flag2) - { - bitmask bm(flag1); - return bm | flag2; - } - bitmask operator&(const Widget::Flags::Extended::eExFlags &flag1, const Widget::Flags::Extended::eExFlags &flag2) - { - bitmask bm(flag1); - return bm & flag2; - } +}//namespace PhWidgets - bitmask operator^(const Widget::Flags::Extended::eExFlags &flag1, const Widget::Flags::Extended::eExFlags &flag2) - { - bitmask bm(flag1); - return bm ^ flag2; - } - - bitmask operator|(const Widget::Flags::eFlags &flag1, const Widget::Flags::eFlags &flag2) - { - bitmask bm(flag1); - return bm | flag2; - } +cppbitmasks::bitmask operator|(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2) +{ + cppbitmasks::bitmask bm(flag1); + return bm | flag2; +} - bitmask operator&(const Widget::Flags::eFlags &flag1, const Widget::Flags::eFlags &flag2) - { - bitmask bm(flag1); - return bm & flag2; - } +cppbitmasks::bitmask operator&(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2) +{ + cppbitmasks::bitmask bm(flag1); + return bm & flag2; +} - bitmask operator^(const Widget::Flags::eFlags &flag1, const Widget::Flags::eFlags &flag2) - { - bitmask bm(flag1); - return bm ^ flag2; - } +cppbitmasks::bitmask operator^(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2) +{ + cppbitmasks::bitmask bm(flag1); + return bm ^ flag2; +} -}//namespace PhWidgets +cppbitmasks::bitmask operator|(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2) +{ + cppbitmasks::bitmask bm(flag1); + return bm | flag2; +} + +cppbitmasks::bitmask operator&(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2) +{ + cppbitmasks::bitmask bm(flag1); + return bm & flag2; +} + +cppbitmasks::bitmask operator^(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2) +{ + cppbitmasks::bitmask bm(flag1); + return bm ^ flag2; +} #endif diff --git a/src/service/bitmask.hpp b/src/service/bitmask.hpp index 8dd27c23..feba12d8 100644 --- a/src/service/bitmask.hpp +++ b/src/service/bitmask.hpp @@ -160,36 +160,36 @@ namespace cppbitmasks private: MaskT _val; }; +} - template - inline bitmask operator|(const FlagT &flag, const bitmask &mask) - { - return mask | flag; - } +template +inline cppbitmasks::bitmask operator|(const FlagT &flag, const cppbitmasks::bitmask &mask) +{ + return mask | flag; +} - template - inline bitmask operator&(const FlagT &flag, const bitmask &mask) - { - return mask & flag; - } +template +inline cppbitmasks::bitmask operator&(const FlagT &flag, const cppbitmasks::bitmask &mask) +{ + return mask & flag; +} - template - inline bitmask operator^(const FlagT &flag, const bitmask &mask) - { - return mask ^ flag; - } +template +inline cppbitmasks::bitmask operator^(const FlagT &flag, const cppbitmasks::bitmask &mask) +{ + return mask ^ flag; +} - template - inline bitmask operator==(const FlagT &flag, const bitmask &mask) - { - return mask == flag; - } +template +inline cppbitmasks::bitmask operator==(const FlagT &flag, const cppbitmasks::bitmask &mask) +{ + return mask == flag; +} - template - inline bitmask operator!=(const FlagT &flag, const bitmask &mask) - { - return mask != flag; - } +template +inline cppbitmasks::bitmask operator!=(const FlagT &flag, const cppbitmasks::bitmask &mask) +{ + return mask != flag; } #endif \ No newline at end of file From 3eaaf23c6c3714e3e018e482b1585abdcfb93745 Mon Sep 17 00:00:00 2001 From: oktonion <0oktonion0@gmail.com> Date: Thu, 19 Oct 2017 00:15:00 +0300 Subject: [PATCH 06/10] added |=, &=, ^= operators to bitmask --- src/service/bitmask.hpp | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/service/bitmask.hpp b/src/service/bitmask.hpp index feba12d8..3f594de3 100644 --- a/src/service/bitmask.hpp +++ b/src/service/bitmask.hpp @@ -122,6 +122,36 @@ namespace cppbitmasks return *this; } + inline bitmask& operator|=(const FlagT &flag) + { + return set(flag); + } + + inline bitmask& operator|=(const bitmask &other) + { + return set(other); + } + + inline bitmask& operator&=(const FlagT &flag) + { + return keep(flag); + } + + inline bitmask& operator&=(const bitmask &other) + { + return keep(other); + } + + inline bitmask& operator^=(const FlagT &flag) + { + return flip(flag); + } + + inline bitmask& operator^=(const bitmask &other) + { + return flip(other); + } + inline bool operator==(const FlagT &flag) const { return test(flag); From f4c13ae1b408744c807cec48f31fa98deae3c3de Mon Sep 17 00:00:00 2001 From: oktonion <0oktonion0@gmail.com> Date: Mon, 23 Oct 2017 19:03:17 +0300 Subject: [PATCH 07/10] bit mask can be initialized now --- src/service/bitmask.hpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/service/bitmask.hpp b/src/service/bitmask.hpp index 3f594de3..6313eff2 100644 --- a/src/service/bitmask.hpp +++ b/src/service/bitmask.hpp @@ -7,8 +7,8 @@ namespace cppbitmasks class bitmask { public: - bitmask() : - _val(MaskT()) + bitmask(MaskT val = MaskT()) : + _val(val) { } From 12a8058e92a9b9ce608cf497f4c82b1c5b0552af Mon Sep 17 00:00:00 2001 From: oktonion <0oktonion0@gmail.com> Date: Wed, 25 Oct 2017 18:06:50 +0300 Subject: [PATCH 08/10] phbitmask Strictly for photon flags --- src/Widget.h | 2 +- src/service/bitmask.hpp | 4 +- src/service/phbitmask.hpp | 179 +++++++++++++++++++++++++++++++++++++ src/service/phproperty.hpp | 1 + 4 files changed, 183 insertions(+), 3 deletions(-) create mode 100644 src/service/phbitmask.hpp diff --git a/src/Widget.h b/src/Widget.h index 92e024b0..dba20cae 100644 --- a/src/Widget.h +++ b/src/Widget.h @@ -15,7 +15,7 @@ #include "./service/stdex/stdex.h" #include "./service/phproperty.hpp" #include "./service/phevent.hpp" -#include "./service/bitmask.hpp" +#include "./service/phbitmask.hpp" #include "./WidgetResource.hpp" diff --git a/src/service/bitmask.hpp b/src/service/bitmask.hpp index 6313eff2..3f594de3 100644 --- a/src/service/bitmask.hpp +++ b/src/service/bitmask.hpp @@ -7,8 +7,8 @@ namespace cppbitmasks class bitmask { public: - bitmask(MaskT val = MaskT()) : - _val(val) + bitmask() : + _val(MaskT()) { } diff --git a/src/service/phbitmask.hpp b/src/service/phbitmask.hpp new file mode 100644 index 00000000..1b93e9ae --- /dev/null +++ b/src/service/phbitmask.hpp @@ -0,0 +1,179 @@ +#ifndef PH_BITMASK_HPP +#define PH_BITMASK_HPP + +#include "bitmask.hpp" + +namespace PhWidgets +{ + struct IPhWidgetsProperty + { + template + inline ReturnT getArgument() const + { + return static_cast(this)->resource.argument[ArgumentID].get(); + } + + template + inline void setArgument(ValueT val) + { + static_cast(this)->resource.argument[ArgumentID].set(val); + } + }; + + template::flag)> + class phbitmask {}; + + //phbitmask: + template<> + class phbitmask : + public cppproperties::detail::property_flag + { + public: + typedef cppproperties::detail::property_flag flags; + }; + + template<> + class phbitmask : + public cppproperties::detail::property_flag + { + public: + typedef cppproperties::detail::property_flag flags; + }; + + template<> + class phbitmask : + public cppproperties::detail::property_flag + { + public: + typedef cppproperties::detail::property_flag flags; + }; + + //phbitmask: + template + class phbitmask//ValueT == const... + { + typedef cppproperties::property cpp_property_t; + + template::getter_t Getter> + struct bind_internal : + public cpp_property_t::template bind + { + bind_internal(WidgetClassT *parent) : + cpp_property_t::template bind(parent) + {} + + private: + inline bind_internal &operator=(ValueT const &); + inline bind_internal &operator=(bind_internal const &); + }; + + public: + template + class bind : + public bind_internal< + IPhWidgetsProperty, + &IPhWidgetsProperty::getArgument + > + { + typedef bind_internal< + IPhWidgetsProperty, + &IPhWidgetsProperty::getArgument + > cpp_bind_t; + + public: + bind(WidgetClassT *parent) : + cpp_bind_t(parent) + {} + + private: + inline bind &operator=(ValueT const &); + inline bind &operator=(bind const &); + }; + + }; + + + template + class phbitmask//ValueT != const... + { + typedef cppproperties::property cpp_property_t; + + template::getter_t Getter, typename cppproperties::detail::get_parent_func::setter_t Setter> + struct bind_internal : + public cpp_property_t::template bind + { + bind_internal(WidgetClassT *parent) : + cpp_property_t::template bind(parent) + {} + + using cpp_property_t::template bind::operator=; + }; + + public: + + template + class bind : + public bind_internal< + IPhWidgetsProperty, + &IPhWidgetsProperty::getArgument, + &IPhWidgetsProperty::setArgument + > + { + typedef bind_internal< + IPhWidgetsProperty, + &IPhWidgetsProperty::getArgument, + &IPhWidgetsProperty::setArgument + > cpp_bind_t; + + public: + bind(WidgetClassT *parent) : + cpp_bind_t(parent) + {} + + using cpp_bind_t::operator=; + }; + + }; + + template + class phbitmask//ValueT != const... + { + typedef cppproperties::property cpp_property_t; + + template::setter_t Setter> + struct bind_internal : + public cpp_property_t::template bind + { + bind_internal(WidgetClassT *parent) : + cpp_property_t::template bind(parent) + {} + + using cpp_property_t::template bind::operator=; + }; + + public: + template + class bind : + public bind_internal< + IPhWidgetsProperty, + &IPhWidgetsProperty::setArgument + > + { + typedef bind_internal< + IPhWidgetsProperty, + &IPhWidgetsProperty::setArgument + > cpp_bind_t; + + public: + bind(WidgetClassT *parent) : + cpp_bind_t(parent) + {} + + using cpp_bind_t::operator=; + }; + + }; +} + +#endif \ No newline at end of file diff --git a/src/service/phproperty.hpp b/src/service/phproperty.hpp index e9fcdd31..4496b0a6 100644 --- a/src/service/phproperty.hpp +++ b/src/service/phproperty.hpp @@ -90,6 +90,7 @@ namespace PhWidgets inline bind &operator=(ValueT const &); inline bind &operator=(bind const &); }; + }; From cabd39ed0829d07d30c4afd0f8debc335c4fea10 Mon Sep 17 00:00:00 2001 From: oktonion <0oktonion0@gmail.com> Date: Wed, 8 Nov 2017 17:03:52 +0300 Subject: [PATCH 09/10] phbitmask is ready --- src/Widget.cpp | 36 ++++++++ src/Widget.h | 40 ++------ src/WidgetResource.hpp | 9 ++ src/service/bitmask.hpp | 12 ++- src/service/phbitmask.hpp | 189 +++++++++++--------------------------- src/service/property.hpp | 2 - 6 files changed, 116 insertions(+), 172 deletions(-) diff --git a/src/Widget.cpp b/src/Widget.cpp index 73c0b082..10f2e987 100644 --- a/src/Widget.cpp +++ b/src/Widget.cpp @@ -327,3 +327,39 @@ std::string PhWidgets::Widget::getHelpTopic() const { return resource.argument[Arguments::help_topic].get(); } + +cppbitmasks::bitmask operator|(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2) +{ + cppbitmasks::bitmask bm(flag1); + return bm | flag2; +} + +cppbitmasks::bitmask operator&(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2) +{ + cppbitmasks::bitmask bm(flag1); + return bm & flag2; +} + +cppbitmasks::bitmask operator^(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2) +{ + cppbitmasks::bitmask bm(flag1); + return bm ^ flag2; +} + +cppbitmasks::bitmask operator|(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2) +{ + cppbitmasks::bitmask bm(flag1); + return bm | flag2; +} + +cppbitmasks::bitmask operator&(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2) +{ + cppbitmasks::bitmask bm(flag1); + return bm & flag2; +} + +cppbitmasks::bitmask operator^(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2) +{ + cppbitmasks::bitmask bm(flag1); + return bm ^ flag2; +} diff --git a/src/Widget.h b/src/Widget.h index dba20cae..aeeaf9e4 100644 --- a/src/Widget.h +++ b/src/Widget.h @@ -615,8 +615,8 @@ namespace PhWidgets phproperty::bind Size; //!< Gets or sets the size of the widget. phproperty::bind Location; //!< Gets or sets the position of the widget. - phproperty< bitmask >::bind ExtendedFlags; //!< Gets or sets extended flags inherited by all widgets. See Flags::Extended. - phproperty< bitmask >::bind WidgetFlags; //!< Gets or sets flags inherited by all widgets. See Flags::eFlags. + phbitmask::bind ExtendedFlags; //!< Gets or sets extended flags inherited by all widgets. See Flags::Extended. + phbitmask::bind WidgetFlags; //!< Gets or sets flags inherited by all widgets. See Flags::eFlags. phwidgets_event Destroyed; //!< Occurs when the widget is destroyed. phwidgets_event Blocked; //!< Occurs when the widget is blocked. @@ -639,41 +639,17 @@ namespace PhWidgets }//namespace PhWidgets -cppbitmasks::bitmask operator|(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2) -{ - cppbitmasks::bitmask bm(flag1); - return bm | flag2; -} +cppbitmasks::bitmask operator|(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2); -cppbitmasks::bitmask operator&(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2) -{ - cppbitmasks::bitmask bm(flag1); - return bm & flag2; -} +cppbitmasks::bitmask operator&(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2); -cppbitmasks::bitmask operator^(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2) -{ - cppbitmasks::bitmask bm(flag1); - return bm ^ flag2; -} +cppbitmasks::bitmask operator^(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2); -cppbitmasks::bitmask operator|(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2) -{ - cppbitmasks::bitmask bm(flag1); - return bm | flag2; -} +cppbitmasks::bitmask operator|(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2); -cppbitmasks::bitmask operator&(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2) -{ - cppbitmasks::bitmask bm(flag1); - return bm & flag2; -} +cppbitmasks::bitmask operator&(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2); -cppbitmasks::bitmask operator^(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2) -{ - cppbitmasks::bitmask bm(flag1); - return bm ^ flag2; -} +cppbitmasks::bitmask operator^(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2); #endif diff --git a/src/WidgetResource.hpp b/src/WidgetResource.hpp index 6aecf72c..e82299d1 100644 --- a/src/WidgetResource.hpp +++ b/src/WidgetResource.hpp @@ -503,6 +503,15 @@ namespace PhWidgets { return this->setFlag(flag, static_cast::type>(mask)); } + + template + inline int set(A1 bitmask) + { + int err = this->setFlag(bitmask, true); + if(0 != err) + return err; + return this->setFlag(~bitmask, false); + } inline resource_type get() const { diff --git a/src/service/bitmask.hpp b/src/service/bitmask.hpp index 3f594de3..d4cc1a43 100644 --- a/src/service/bitmask.hpp +++ b/src/service/bitmask.hpp @@ -6,6 +6,10 @@ namespace cppbitmasks template class bitmask { + bitmask(MaskT val) : + _val(val) + { + } public: bitmask() : _val(MaskT()) @@ -82,7 +86,7 @@ namespace cppbitmasks inline bitmask operator|(const FlagT &flag) const { - return _val | flag; + return *this | bitmask(flag); } inline bitmask operator|(const bitmask &mask) const @@ -92,7 +96,7 @@ namespace cppbitmasks inline bitmask operator&(const FlagT &flag) const { - return _val & flag; + return *this & bitmask(flag); } inline bitmask operator&(const bitmask &mask) const @@ -102,7 +106,7 @@ namespace cppbitmasks inline bitmask operator^(const FlagT &flag) const { - return _val ^ flag; + return *this ^ bitmask(flag); } inline bitmask operator^(const bitmask &mask) const @@ -112,7 +116,7 @@ namespace cppbitmasks inline bitmask& operator=(const FlagT &flag) { - _val = flag; + *this = bitmask(flag); return *this; } diff --git a/src/service/phbitmask.hpp b/src/service/phbitmask.hpp index 1b93e9ae..eb902bf6 100644 --- a/src/service/phbitmask.hpp +++ b/src/service/phbitmask.hpp @@ -1,179 +1,100 @@ #ifndef PH_BITMASK_HPP #define PH_BITMASK_HPP +#include "phproperty.hpp" #include "bitmask.hpp" +#include + namespace PhWidgets { - struct IPhWidgetsProperty - { - template - inline ReturnT getArgument() const - { - return static_cast(this)->resource.argument[ArgumentID].get(); - } - - template - inline void setArgument(ValueT val) - { - static_cast(this)->resource.argument[ArgumentID].set(val); - } - }; - - template::flag)> - class phbitmask {}; - - //phbitmask: - template<> - class phbitmask : - public cppproperties::detail::property_flag + template + class phbitmask { - public: - typedef cppproperties::detail::property_flag flags; - }; - - template<> - class phbitmask : - public cppproperties::detail::property_flag - { - public: - typedef cppproperties::detail::property_flag flags; - }; - - template<> - class phbitmask : - public cppproperties::detail::property_flag - { - public: - typedef cppproperties::detail::property_flag flags; - }; - - //phbitmask: - template - class phbitmask//ValueT == const... - { - typedef cppproperties::property cpp_property_t; - - template::getter_t Getter> - struct bind_internal : - public cpp_property_t::template bind - { - bind_internal(WidgetClassT *parent) : - cpp_property_t::template bind(parent) - {} - - private: - inline bind_internal &operator=(ValueT const &); - inline bind_internal &operator=(bind_internal const &); - }; - - public: template - class bind : - public bind_internal< - IPhWidgetsProperty, - &IPhWidgetsProperty::getArgument - > + class bind_internal : + private phproperty::template bind { - typedef bind_internal< - IPhWidgetsProperty, - &IPhWidgetsProperty::getArgument - > cpp_bind_t; + typedef cppbitmasks::bitmask value_t; + typedef phproperty ph_property_t; + typedef typename ph_property_t::template bind ph_bind_t; public: - bind(WidgetClassT *parent) : - cpp_bind_t(parent) + bind_internal(WidgetClassT *parent) : + ph_bind_t(parent) {} - private: - inline bind &operator=(ValueT const &); - inline bind &operator=(bind const &); - }; + inline void set(value_t value) + { + static_cast(this)->set(value); + } - }; + inline value_t get() const + { + value_t bm; + MaskT mask = static_cast(this)->get(); + std::memcpy(&bm, &mask, sizeof(MaskT)); + return bm; + } + inline operator value_t() const { return get(); } - template - class phbitmask//ValueT != const... - { - typedef cppproperties::property cpp_property_t; + inline bind_internal &operator=(value_t value) { set(value); return *this; } - template::getter_t Getter, typename cppproperties::detail::get_parent_func::setter_t Setter> - struct bind_internal : - public cpp_property_t::template bind - { - bind_internal(WidgetClassT *parent) : - cpp_property_t::template bind(parent) - {} + inline value_t operator()(void) const { return get(); } - using cpp_property_t::template bind::operator=; + inline void operator()(value_t value) { set(value); return *this; } }; - + public: - template class bind : - public bind_internal< - IPhWidgetsProperty, - &IPhWidgetsProperty::getArgument, - &IPhWidgetsProperty::setArgument - > + public bind_internal { - typedef bind_internal< - IPhWidgetsProperty, - &IPhWidgetsProperty::getArgument, - &IPhWidgetsProperty::setArgument - > cpp_bind_t; + typedef bind_internal internal_bind_t; public: bind(WidgetClassT *parent) : - cpp_bind_t(parent) + internal_bind_t(parent) {} - - using cpp_bind_t::operator=; + + using internal_bind_t::operator=; }; - }; - template - class phbitmask//ValueT != const... + /*template + class phbitmask { - typedef cppproperties::property cpp_property_t; - - template::setter_t Setter> - struct bind_internal : - public cpp_property_t::template bind - { - bind_internal(WidgetClassT *parent) : - cpp_property_t::template bind(parent) - {} - - using cpp_property_t::template bind::operator=; - }; - public: template class bind : - public bind_internal< - IPhWidgetsProperty, - &IPhWidgetsProperty::setArgument - > + private phproperty::template bind { - typedef bind_internal< - IPhWidgetsProperty, - &IPhWidgetsProperty::setArgument - > cpp_bind_t; + typedef cppbitmasks::bitmask value_t; + typedef phproperty::template bind ph_bind_t; public: bind(WidgetClassT *parent) : - cpp_bind_t(parent) + ph_bind_t(parent) {} - using cpp_bind_t::operator=; - }; + inline value_t get() const + { + value_t bm; + MaskT mask = static_cast(this)->get(); + std::memcpy(&bm, &mask, sizeof(MaskT)); + return bm; + } - }; + inline operator value_t() const { return get(); } + + inline value_t operator()(void) const { return get(); } + + private: + inline bind &operator=(value_t const &); + inline bind &operator=(bind const &); + }; + };*/ } #endif \ No newline at end of file diff --git a/src/service/property.hpp b/src/service/property.hpp index 2cc93962..baa04349 100644 --- a/src/service/property.hpp +++ b/src/service/property.hpp @@ -232,7 +232,6 @@ namespace cppproperties inline operator value_t() const { return get(); } - inline bind &operator=(bind const &) {return *this;} inline bind &operator=(value_t value) { set(value); return *this; } inline value_t operator()(void) const { return get(); } @@ -299,7 +298,6 @@ namespace cppproperties (_obj->*Setter)(value); } - inline bind &operator=(bind const &) {return *this;} inline bind &operator=(value_t value) { set(value); return *this; } inline void operator()(value_t value) { set(value); return *this; } From f75a8ffcf24ce35aea0e3b1812b26d83ee51d9b6 Mon Sep 17 00:00:00 2001 From: oktonion <0oktonion0@gmail.com> Date: Wed, 8 Nov 2017 17:10:08 +0300 Subject: [PATCH 10/10] - EOL convert for cripts --- .gitattributes | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.gitattributes b/.gitattributes index bdb0cabc..07e66bc7 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1,6 +1,8 @@ # Auto detect text files and perform LF normalization * text=auto +*.sh -text + # Custom for Visual Studio *.cs diff=csharp