Skip to content

Commit

Permalink
phbitmask is ready
Browse files Browse the repository at this point in the history
  • Loading branch information
oktonion committed Nov 8, 2017
1 parent 12a8058 commit cabd39e
Show file tree
Hide file tree
Showing 6 changed files with 116 additions and 172 deletions.
36 changes: 36 additions & 0 deletions src/Widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -327,3 +327,39 @@ std::string PhWidgets::Widget::getHelpTopic() const
{
return resource.argument[Arguments::help_topic].get();
}

cppbitmasks::bitmask<unsigned long, PhWidgets::Widget::Flags::Extended::eExFlags> operator|(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2)
{
cppbitmasks::bitmask<unsigned long, PhWidgets::Widget::Flags::Extended::eExFlags> bm(flag1);
return bm | flag2;
}

cppbitmasks::bitmask<unsigned long, PhWidgets::Widget::Flags::Extended::eExFlags> operator&(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2)
{
cppbitmasks::bitmask<unsigned long, PhWidgets::Widget::Flags::Extended::eExFlags> bm(flag1);
return bm & flag2;
}

cppbitmasks::bitmask<unsigned long, PhWidgets::Widget::Flags::Extended::eExFlags> operator^(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2)
{
cppbitmasks::bitmask<unsigned long, PhWidgets::Widget::Flags::Extended::eExFlags> bm(flag1);
return bm ^ flag2;
}

cppbitmasks::bitmask<long, PhWidgets::Widget::Flags::eFlags> operator|(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2)
{
cppbitmasks::bitmask<long, PhWidgets::Widget::Flags::eFlags> bm(flag1);
return bm | flag2;
}

cppbitmasks::bitmask<long, PhWidgets::Widget::Flags::eFlags> operator&(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2)
{
cppbitmasks::bitmask<long, PhWidgets::Widget::Flags::eFlags> bm(flag1);
return bm & flag2;
}

cppbitmasks::bitmask<long, PhWidgets::Widget::Flags::eFlags> operator^(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2)
{
cppbitmasks::bitmask<long, PhWidgets::Widget::Flags::eFlags> bm(flag1);
return bm ^ flag2;
}
40 changes: 8 additions & 32 deletions src/Widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -615,8 +615,8 @@ namespace PhWidgets
phproperty<PhDim_t>::bind<Widget, Arguments::eArgDim, Arguments::dim> Size; //!< Gets or sets the size of the widget.
phproperty<PhPoint_t>::bind<Widget, Arguments::eArgPoint, Arguments::pos> Location; //!< Gets or sets the position of the widget.

phproperty< bitmask<unsigned long, Flags::Extended::eExFlags> >::bind<Widget, ArgUnsignedLong::eArgUnsignedLong, ArgUnsignedLong::eflags> ExtendedFlags; //!< Gets or sets extended flags inherited by all widgets. See Flags::Extended.
phproperty< bitmask<long, Flags::eFlags> >::bind<Widget, ArgLong::eArgLong, ArgLong::flags> WidgetFlags; //!< Gets or sets flags inherited by all widgets. See Flags::eFlags.
phbitmask<unsigned long, Flags::Extended::eExFlags>::bind<Widget, ArgUnsignedLong::eArgUnsignedLong, ArgUnsignedLong::eflags> ExtendedFlags; //!< Gets or sets extended flags inherited by all widgets. See Flags::Extended.
phbitmask<long, Flags::eFlags>::bind<Widget, ArgLong::eArgLong, ArgLong::flags> WidgetFlags; //!< Gets or sets flags inherited by all widgets. See Flags::eFlags.

phwidgets_event<Widget, Widget::Callbacks::destroyed> Destroyed; //!< Occurs when the widget is destroyed.
phwidgets_event<Widget, Widget::Callbacks::blocked> Blocked; //!< Occurs when the widget is blocked.
Expand All @@ -639,41 +639,17 @@ namespace PhWidgets

}//namespace PhWidgets

cppbitmasks::bitmask<unsigned long, PhWidgets::Widget::Flags::Extended::eExFlags> operator|(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2)
{
cppbitmasks::bitmask<unsigned long, PhWidgets::Widget::Flags::Extended::eExFlags> bm(flag1);
return bm | flag2;
}
cppbitmasks::bitmask<unsigned long, PhWidgets::Widget::Flags::Extended::eExFlags> operator|(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2);

cppbitmasks::bitmask<unsigned long, PhWidgets::Widget::Flags::Extended::eExFlags> operator&(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2)
{
cppbitmasks::bitmask<unsigned long, PhWidgets::Widget::Flags::Extended::eExFlags> bm(flag1);
return bm & flag2;
}
cppbitmasks::bitmask<unsigned long, PhWidgets::Widget::Flags::Extended::eExFlags> operator&(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2);

cppbitmasks::bitmask<unsigned long, PhWidgets::Widget::Flags::Extended::eExFlags> operator^(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2)
{
cppbitmasks::bitmask<unsigned long, PhWidgets::Widget::Flags::Extended::eExFlags> bm(flag1);
return bm ^ flag2;
}
cppbitmasks::bitmask<unsigned long, PhWidgets::Widget::Flags::Extended::eExFlags> operator^(const PhWidgets::Widget::Flags::Extended::eExFlags &flag1, const PhWidgets::Widget::Flags::Extended::eExFlags &flag2);

cppbitmasks::bitmask<long, PhWidgets::Widget::Flags::eFlags> operator|(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2)
{
cppbitmasks::bitmask<long, PhWidgets::Widget::Flags::eFlags> bm(flag1);
return bm | flag2;
}
cppbitmasks::bitmask<long, PhWidgets::Widget::Flags::eFlags> operator|(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2);

cppbitmasks::bitmask<long, PhWidgets::Widget::Flags::eFlags> operator&(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2)
{
cppbitmasks::bitmask<long, PhWidgets::Widget::Flags::eFlags> bm(flag1);
return bm & flag2;
}
cppbitmasks::bitmask<long, PhWidgets::Widget::Flags::eFlags> operator&(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2);

cppbitmasks::bitmask<long, PhWidgets::Widget::Flags::eFlags> operator^(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2)
{
cppbitmasks::bitmask<long, PhWidgets::Widget::Flags::eFlags> bm(flag1);
return bm ^ flag2;
}
cppbitmasks::bitmask<long, PhWidgets::Widget::Flags::eFlags> operator^(const PhWidgets::Widget::Flags::eFlags &flag1, const PhWidgets::Widget::Flags::eFlags &flag2);


#endif
9 changes: 9 additions & 0 deletions src/WidgetResource.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,15 @@ namespace PhWidgets
{
return this->setFlag(flag, static_cast<typename flag_detail::mask_type<A2>::type>(mask));
}

template<typename A1>
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
{
Expand Down
12 changes: 8 additions & 4 deletions src/service/bitmask.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ namespace cppbitmasks
template<class MaskT, class FlagT>
class bitmask
{
bitmask(MaskT val) :
_val(val)
{
}
public:
bitmask() :
_val(MaskT())
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand All @@ -112,7 +116,7 @@ namespace cppbitmasks

inline bitmask& operator=(const FlagT &flag)
{
_val = flag;
*this = bitmask(flag);
return *this;
}

Expand Down
189 changes: 55 additions & 134 deletions src/service/phbitmask.hpp
Original file line number Diff line number Diff line change
@@ -1,179 +1,100 @@
#ifndef PH_BITMASK_HPP
#define PH_BITMASK_HPP

#include "phproperty.hpp"
#include "bitmask.hpp"

#include <cstring>

namespace PhWidgets
{
struct IPhWidgetsProperty
{
template<class ReturnT, class WidgetClassT, class ArgumentT, ArgumentT ArgumentID>
inline ReturnT getArgument() const
{
return static_cast<const WidgetClassT*>(this)->resource.argument[ArgumentID].get();
}

template<class ValueT, class WidgetClassT, class ArgumentT, ArgumentT ArgumentID>
inline void setArgument(ValueT val)
{
static_cast<const WidgetClassT*>(this)->resource.argument[ArgumentID].set(val);
}
};

template<class ValueT = void,
const cppproperties::detail::property_flag::e_property_flag Flag = (const cppproperties::detail::property_flag::e_property_flag)(cppproperties::detail::flag_chooser<ValueT>::flag)>
class phbitmask {};

//phbitmask<void>:
template<>
class phbitmask<void, cppproperties::detail::property_flag::ro> :
public cppproperties::detail::property_flag
template<class MaskT, class FlagT>
class phbitmask
{
public:
typedef cppproperties::detail::property_flag flags;
};

template<>
class phbitmask<void, cppproperties::detail::property_flag::wo> :
public cppproperties::detail::property_flag
{
public:
typedef cppproperties::detail::property_flag flags;
};

template<>
class phbitmask<void, cppproperties::detail::property_flag::rw> :
public cppproperties::detail::property_flag
{
public:
typedef cppproperties::detail::property_flag flags;
};

//phbitmask<Value>:
template<typename ValueT>
class phbitmask<ValueT, cppproperties::detail::property_flag::ro>//ValueT == const...
{
typedef cppproperties::property<ValueT, cppproperties::detail::property_flag::ro> cpp_property_t;

template<class WidgetClassT, typename cppproperties::detail::get_parent_func<ValueT, WidgetClassT>::getter_t Getter>
struct bind_internal :
public cpp_property_t::template bind<WidgetClassT, Getter>
{
bind_internal(WidgetClassT *parent) :
cpp_property_t::template bind<WidgetClassT, Getter>(parent)
{}

private:
inline bind_internal &operator=(ValueT const &);
inline bind_internal &operator=(bind_internal const &);
};

public:
template<class WidgetClassT, class ArgumentT, ArgumentT ArgumentID>
class bind :
public bind_internal<
IPhWidgetsProperty,
&IPhWidgetsProperty::getArgument<ValueT, WidgetClassT, ArgumentT, ArgumentID>
>
class bind_internal :
private phproperty<MaskT>::template bind<WidgetClassT, ArgumentT, ArgumentID>
{
typedef bind_internal<
IPhWidgetsProperty,
&IPhWidgetsProperty::getArgument<ValueT, WidgetClassT, ArgumentT, ArgumentID>
> cpp_bind_t;
typedef cppbitmasks::bitmask<MaskT, FlagT> value_t;
typedef phproperty<MaskT> ph_property_t;
typedef typename ph_property_t::template bind<WidgetClassT, ArgumentT, ArgumentID> 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<ph_bind_t*>(this)->set(value);
}

};
inline value_t get() const
{
value_t bm;
MaskT mask = static_cast<ph_bind_t*>(this)->get();
std::memcpy(&bm, &mask, sizeof(MaskT));
return bm;
}

inline operator value_t() const { return get(); }

template<typename ValueT>
class phbitmask<ValueT, cppproperties::detail::property_flag::rw>//ValueT != const...
{
typedef cppproperties::property<ValueT, cppproperties::detail::property_flag::rw> cpp_property_t;
inline bind_internal &operator=(value_t value) { set(value); return *this; }

template<class WidgetClassT, typename cppproperties::detail::get_parent_func<ValueT, WidgetClassT>::getter_t Getter, typename cppproperties::detail::get_parent_func<ValueT, WidgetClassT>::setter_t Setter>
struct bind_internal :
public cpp_property_t::template bind<WidgetClassT, Getter, Setter>
{
bind_internal(WidgetClassT *parent) :
cpp_property_t::template bind<WidgetClassT, Getter, Setter>(parent)
{}
inline value_t operator()(void) const { return get(); }

using cpp_property_t::template bind<WidgetClassT, Getter, Setter>::operator=;
inline void operator()(value_t value) { set(value); return *this; }
};

public:

template<class WidgetClassT, class ArgumentT, ArgumentT ArgumentID>
class bind :
public bind_internal<
IPhWidgetsProperty,
&IPhWidgetsProperty::getArgument<ValueT, WidgetClassT, ArgumentT, ArgumentID>,
&IPhWidgetsProperty::setArgument<ValueT, WidgetClassT, ArgumentT, ArgumentID>
>
public bind_internal<WidgetClassT, ArgumentT, ArgumentID>
{
typedef bind_internal<
IPhWidgetsProperty,
&IPhWidgetsProperty::getArgument<ValueT, WidgetClassT, ArgumentT, ArgumentID>,
&IPhWidgetsProperty::setArgument<ValueT, WidgetClassT, ArgumentT, ArgumentID>
> cpp_bind_t;
typedef bind_internal<WidgetClassT, ArgumentT, ArgumentID> 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<typename ValueT>
class phbitmask<ValueT, cppproperties::detail::property_flag::wo>//ValueT != const...
/*template<class MaskT, class FlagT>
class phbitmask<const MaskT, FlagT>
{
typedef cppproperties::property<ValueT, cppproperties::detail::property_flag::wo> cpp_property_t;

template<class WidgetClassT, typename cppproperties::detail::get_parent_func<ValueT, WidgetClassT>::setter_t Setter>
struct bind_internal :
public cpp_property_t::template bind<WidgetClassT, Setter>
{
bind_internal(WidgetClassT *parent) :
cpp_property_t::template bind<WidgetClassT, Setter>(parent)
{}

using cpp_property_t::template bind<WidgetClassT, Setter>::operator=;
};

public:
template<class WidgetClassT, class ArgumentT, ArgumentT ArgumentID>
class bind :
public bind_internal<
IPhWidgetsProperty,
&IPhWidgetsProperty::setArgument<ValueT, WidgetClassT, ArgumentT, ArgumentID>
>
private phproperty<const MaskT>::template bind<WidgetClassT, ArgumentT, ArgumentID>
{
typedef bind_internal<
IPhWidgetsProperty,
&IPhWidgetsProperty::setArgument<ValueT, WidgetClassT, ArgumentT, ArgumentID>
> cpp_bind_t;
typedef cppbitmasks::bitmask<MaskT, FlagT> value_t;
typedef phproperty<const MaskT>::template bind<WidgetClassT, ArgumentT, ArgumentID> 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<ph_bind_t*>(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
Loading

0 comments on commit cabd39e

Please sign in to comment.