Add wxIMPLEMENT_DYNAMIC_TEMPLATE_SPECIALIZATION()

This will be used in the upcoming commit.
This commit is contained in:
Vadim Zeitlin
2026-01-28 01:10:33 +01:00
parent 56b18f643e
commit 9b312abc75
2 changed files with 49 additions and 0 deletions
+19
View File
@@ -226,6 +226,25 @@ WXDLLIMPEXP_BASE wxObject *wxCreateDynamicObject(const wxString& name);
wxObject* name::wxCreateObject() \
{ return new name; }
// Template specialization with one base class.
#define wxIMPLEMENT_DYNAMIC_TEMPLATE_SPECIALIZATION(name, arg, basename) \
template <> \
wxObject* name<arg>::wxCreateObject() { return new name<arg>; } \
template <> \
wxClassInfo \
name<arg>::ms_classInfo \
( \
wxT(#name) L"<" wxT(#arg) L">", \
&basename::ms_classInfo, \
nullptr, \
static_cast<int>(sizeof(name<arg>)), \
name<arg>::wxCreateObject \
); \
template <> \
wxClassInfo* name<arg>::GetClassInfo() const { return &ms_classInfo; }
// -----------------------------------
// for abstract classes
// -----------------------------------
+30
View File
@@ -797,6 +797,36 @@ public:
*/
#define wxIMPLEMENT_DYNAMIC_CLASS2( className, baseClassName1, baseClassName2 )
/**
Used in a C++ implementation file to complete the declaration of a class
that has run-time type information, and whose instances can be created
dynamically. Use this for template specializations.
Please note that @a arg must be the template parameter the primary template
@a templateName is being specialized for, e.g.
@code
template <typename T>
class MyWindow : public wxWindow
{
public:
MyWindow() = default; // Must have a default ctor for dynamic creation.
private:
T m_value;
wxDECLARE_DYNAMIC_CLASS(MyWindow);
};
wxIMPLEMENT_DYNAMIC_TEMPLATE_SPECIALIZATION(MyWindow, int, wxWindow);
@endcode
@header{wx/object.h}
@since 3.3.2
*/
#define wxIMPLEMENT_DYNAMIC_TEMPLATE_SPECIALIZATION( templateName, arg, baseClassName )
/**
Synonym for wxIMPLEMENT_ABSTRACT_CLASS().