Codechange: add concept of ConvertibleThroughBase for strong types
This makes it possible to write templated alternatives for ConvertibleThroughBase which are then available for any (strong) type that implements a base() function In the end making adding new ConvertibleThroughBase types less awkward.
This commit is contained in:
@@ -12,16 +12,15 @@
|
||||
|
||||
#include "window_type.h"
|
||||
#include "company_type.h"
|
||||
#include "core/convertible_through_base.hpp"
|
||||
#include "core/geometry_type.hpp"
|
||||
#include "core/strong_typedef_type.hpp"
|
||||
|
||||
Window *FindWindowById(WindowClass cls, WindowNumber number);
|
||||
Window *FindWindowByClass(WindowClass cls);
|
||||
Window *GetMainWindow();
|
||||
void ChangeWindowOwner(Owner old_owner, Owner new_owner);
|
||||
|
||||
template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
|
||||
Window *FindWindowById(WindowClass cls, T number)
|
||||
Window *FindWindowById(WindowClass cls, ConvertibleThroughBase auto number)
|
||||
{
|
||||
return FindWindowById(cls, number.base());
|
||||
}
|
||||
@@ -44,8 +43,7 @@ void InputLoop();
|
||||
void InvalidateWindowData(WindowClass cls, WindowNumber number, int data = 0, bool gui_scope = false);
|
||||
void InvalidateWindowClassesData(WindowClass cls, int data = 0, bool gui_scope = false);
|
||||
|
||||
template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
|
||||
void InvalidateWindowData(WindowClass cls, T number, int data = 0, bool gui_scope = false)
|
||||
void InvalidateWindowData(WindowClass cls, ConvertibleThroughBase auto number, int data = 0, bool gui_scope = false)
|
||||
{
|
||||
InvalidateWindowData(cls, number.base(), data, gui_scope);
|
||||
}
|
||||
@@ -67,8 +65,7 @@ void SetWindowWidgetDirty(WindowClass cls, WindowNumber number, WidgetID widget_
|
||||
void SetWindowDirty(WindowClass cls, WindowNumber number);
|
||||
void SetWindowClassesDirty(WindowClass cls);
|
||||
|
||||
template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
|
||||
void SetWindowDirty(WindowClass cls, T number)
|
||||
void SetWindowDirty(WindowClass cls, ConvertibleThroughBase auto number)
|
||||
{
|
||||
SetWindowDirty(cls, number.base());
|
||||
}
|
||||
@@ -76,8 +73,7 @@ void SetWindowDirty(WindowClass cls, T number)
|
||||
void CloseWindowById(WindowClass cls, WindowNumber number, bool force = true, int data = 0);
|
||||
void CloseWindowByClass(WindowClass cls, int data = 0);
|
||||
|
||||
template <typename T, std::enable_if_t<std::is_base_of<StrongTypedefBase, T>::value, int> = 0>
|
||||
void CloseWindowById(WindowClass cls, T number, bool force = true, int data = 0)
|
||||
void CloseWindowById(WindowClass cls, ConvertibleThroughBase auto number, bool force = true, int data = 0)
|
||||
{
|
||||
CloseWindowById(cls, number.base(), force, data);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user