MyGUI_EventPair.h
Go to the documentation of this file.
/*
* This source file is part of MyGUI. For the latest info, see http://mygui.info/
* Distributed under the MIT License
* (See accompanying file COPYING.MIT or copy at http://opensource.org/licenses/MIT)
*/
#ifndef MYGUI_EVENT_PAIR_H_
#define MYGUI_EVENT_PAIR_H_
#include "MyGUI_Prerequest.h"
namespace MyGUI
{
#ifndef MYGUI_DONT_USE_OBSOLETE
template<typename EventObsolete, typename Event>
class CompositeEvent
{
using IObsoleteDelegate = typename EventObsolete::IDelegate;
public:
using IDelegate = typename Event::IDelegate;
template<class T>
CompositeEvent& operator=(T* _delegate)
{
m_eventObsolete.clear();
m_event = _delegate;
return *this;
}
template<class T>
CompositeEvent& operator=(const T& _delegate)
{
m_eventObsolete.clear();
m_event = _delegate;
return *this;
}
MYGUI_OBSOLETE("use : signature : Event::IDelegate * _delegate")
CompositeEvent& operator=(IObsoleteDelegate* _delegate)
{
m_eventObsolete = _delegate;
m_event.clear();
return *this;
}
template<class T>
void operator+=(T*) = delete;
template<class T>
void operator-=(T*) = delete;
MYGUI_OBSOLETE("use : signature : Event::IDelegate * _delegate")
void operator+=(IObsoleteDelegate* _delegate)
{
m_eventObsolete += _delegate;
m_event.clear();
}
void operator+=(IDelegate* _delegate)
{
m_eventObsolete.clear();
m_event += _delegate;
}
MYGUI_OBSOLETE("use : signature : Event::IDelegate * _delegate")
void operator-=(IObsoleteDelegate* _delegate)
{
m_eventObsolete -= _delegate;
m_event.clear();
}
void operator-=(IDelegate* _delegate)
{
m_eventObsolete.clear();
m_event -= _delegate;
}
void clear()
{
m_eventObsolete.clear();
m_event.clear();
}
bool empty() const
{
return m_eventObsolete.empty() && m_event.empty();
}
EventObsolete m_eventObsolete;
Event m_event;
};
#endif
template<typename EventObsolete, typename Event>
#ifdef MYGUI_DONT_USE_OBSOLETE
using EventPair = Event;
#else
class EventPair : public CompositeEvent<EventObsolete, Event>
{
public:
using CompositeEvent<EventObsolete, Event>::operator=;
using CompositeEvent<EventObsolete, Event>::m_eventObsolete;
using CompositeEvent<EventObsolete, Event>::m_event;
template<typename TP1>
void operator()(TP1 p1) const
{
m_eventObsolete(p1);
m_event(p1);
}
template<typename TP1, typename TP2>
void operator()(TP1 p1, TP2 p2) const
{
m_eventObsolete(p1, p2);
m_event(p1, p2);
}
template<typename TP1, typename TP2, typename TP3>
void operator()(TP1 p1, TP2 p2, TP3 p3) const
{
m_eventObsolete(p1, p2, p3);
m_event(p1, p2, p3);
}
template<typename TP1, typename TP2, typename TP3, typename TP4>
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4) const
{
m_eventObsolete(p1, p2, p3, p4);
m_event(p1, p2, p3, p4);
}
template<typename TP1, typename TP2, typename TP3, typename TP4, typename TP5>
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5) const
{
m_eventObsolete(p1, p2, p3, p4, p5);
m_event(p1, p2, p3, p4, p5);
}
template<typename TP1, typename TP2, typename TP3, typename TP4, typename TP5, typename TP6>
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6) const
{
m_eventObsolete(p1, p2, p3, p4, p5, p6);
m_event(p1, p2, p3, p4, p5, p6);
}
template<typename TP1, typename TP2, typename TP3, typename TP4, typename TP5, typename TP6, typename TP7>
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6, TP7 p7) const
{
m_eventObsolete(p1, p2, p3, p4, p5, p6, p7);
m_event(p1, p2, p3, p4, p5, p6, p7);
}
template<
typename TP1,
typename TP2,
typename TP3,
typename TP4,
typename TP5,
typename TP6,
typename TP7,
typename TP8>
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6, TP7 p7, TP8 p8) const
{
m_eventObsolete(p1, p2, p3, p4, p5, p6, p7, p8);
m_event(p1, p2, p3, p4, p5, p6, p7, p8);
}
};
#endif
template<typename EventObsolete, typename Event>
#ifdef MYGUI_DONT_USE_OBSOLETE
using EventPairAddParameter = Event;
#else
class EventPairAddParameter : public CompositeEvent<EventObsolete, Event>
{
public:
using CompositeEvent<EventObsolete, Event>::operator=;
using CompositeEvent<EventObsolete, Event>::m_eventObsolete;
using CompositeEvent<EventObsolete, Event>::m_event;
// 1 to 2
template<typename TP1, typename TP2>
void operator()(TP1 p1, TP2 p2)
{
m_eventObsolete(p1);
m_event(p1, p2);
}
// 2 to 3
template<typename TP1, typename TP2, typename TP3, typename TP4>
void operator()(TP1 p1, TP2 p2, TP3 p3)
{
m_eventObsolete(p1, p2);
m_event(p1, p2, p3);
}
// 3 to 4
template<typename TP1, typename TP2, typename TP3, typename TP4>
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4)
{
m_eventObsolete(p1, p2, p3);
m_event(p1, p2, p3, p4);
}
};
#endif
template<typename EventObsolete, typename Event>
#ifdef MYGUI_DONT_USE_OBSOLETE
using EventPairConvertStringView = Event;
#else
class EventPairConvertStringView : public CompositeEvent<EventObsolete, Event>
{
template<class T>
T&& convertStringView(T&& value) const noexcept
{
return std::forward<T>(value);
}
template<class T>
std::basic_string<T> convertStringView(std::basic_string_view<T> value) const noexcept
{
return std::string{value};
}
public:
using CompositeEvent<EventObsolete, Event>::operator=;
using CompositeEvent<EventObsolete, Event>::m_eventObsolete;
using CompositeEvent<EventObsolete, Event>::m_event;
template<typename... Args>
void operator()(Args&&... args) const
{
if (!m_eventObsolete.empty())
m_eventObsolete(convertStringView(args)...);
m_event(args...);
}
};
#endif
} // namespace MyGUI
#endif // MYGUI_EVENT_PAIR_H_
MYGUI_OBSOLETE
#define MYGUI_OBSOLETE(text)
Definition MyGUI_Diagnostic.h:68
MyGUI_Prerequest.h
MyGUI::CompositeEvent
Definition MyGUI_EventPair.h:17
MyGUI::CompositeEvent::operator+=
void operator+=(IDelegate *_delegate)
Definition MyGUI_EventPair.h:59
MyGUI::CompositeEvent::operator+=
void operator+=(T *)=delete
MyGUI::CompositeEvent::operator-=
void operator-=(T *)=delete
MyGUI::CompositeEvent::operator=
CompositeEvent & operator=(const T &_delegate)
Definition MyGUI_EventPair.h:32
MyGUI::CompositeEvent::m_eventObsolete
EventObsolete m_eventObsolete
Definition MyGUI_EventPair.h:89
MyGUI::CompositeEvent::operator-=
void operator-=(IDelegate *_delegate)
Definition MyGUI_EventPair.h:72
MyGUI::CompositeEvent::empty
bool empty() const
Definition MyGUI_EventPair.h:84
MyGUI::CompositeEvent::IDelegate
typename Event::IDelegate IDelegate
Definition MyGUI_EventPair.h:21
MyGUI::CompositeEvent::operator=
CompositeEvent & operator=(T *_delegate)
Definition MyGUI_EventPair.h:24
MyGUI::CompositeEvent::clear
void clear()
Definition MyGUI_EventPair.h:78
MyGUI::CompositeEvent::m_event
Event m_event
Definition MyGUI_EventPair.h:90
MyGUI::EventPairAddParameter
Definition MyGUI_EventPair.h:176
MyGUI::EventPairAddParameter::operator()
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4)
Definition MyGUI_EventPair.h:200
MyGUI::EventPairAddParameter::operator()
void operator()(TP1 p1, TP2 p2, TP3 p3)
Definition MyGUI_EventPair.h:192
MyGUI::EventPairAddParameter::operator()
void operator()(TP1 p1, TP2 p2)
Definition MyGUI_EventPair.h:184
MyGUI::EventPairConvertStringView
Definition MyGUI_EventPair.h:213
MyGUI::EventPairConvertStringView::operator()
void operator()(Args &&... args) const
Definition MyGUI_EventPair.h:232
MyGUI::EventPair
Definition MyGUI_EventPair.h:99
MyGUI::EventPair::operator()
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6, TP7 p7, TP8 p8) const
Definition MyGUI_EventPair.h:163
MyGUI::EventPair::operator()
void operator()(TP1 p1, TP2 p2, TP3 p3) const
Definition MyGUI_EventPair.h:120
MyGUI::EventPair::operator()
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4) const
Definition MyGUI_EventPair.h:127
MyGUI::EventPair::operator()
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6) const
Definition MyGUI_EventPair.h:141
MyGUI::EventPair::operator()
void operator()(TP1 p1, TP2 p2) const
Definition MyGUI_EventPair.h:113
MyGUI::EventPair::operator()
void operator()(TP1 p1) const
Definition MyGUI_EventPair.h:106
MyGUI::EventPair::operator()
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5) const
Definition MyGUI_EventPair.h:134
MyGUI::EventPair::operator()
void operator()(TP1 p1, TP2 p2, TP3 p3, TP4 p4, TP5 p5, TP6 p6, TP7 p7) const
Definition MyGUI_EventPair.h:148
MyGUI
Definition MyGUI_ActionController.h:15