+
+//
+// wxVariant <-> wxAny conversion code
+//
+#if wxUSE_ANY
+
+#include "wx/any.h"
+
+// In order to convert wxAny to wxVariant, we need to be able to associate
+// wxAnyValueType with a wxVariantData factory function.
+typedef wxVariantData* (*wxVariantDataFactory)(const wxAny& any);
+
+// Actual Any-to-Variant registration must be postponed to a time when all
+// global variables have been initialized. Hence this arrangement.
+// wxAnyToVariantRegistration instances are kept in global scope and
+// wxAnyValueTypeGlobals in any.cpp will use their data when the time is
+// right.
+class WXDLLIMPEXP_BASE wxAnyToVariantRegistration
+{
+public:
+ wxAnyToVariantRegistration(wxVariantDataFactory factory);
+ virtual ~wxAnyToVariantRegistration();
+
+ virtual wxAnyValueType* GetAssociatedType() = 0;
+ wxVariantDataFactory GetFactory() const { return m_factory; }
+private:
+ wxVariantDataFactory m_factory;
+};
+
+template<typename T>
+class wxAnyToVariantRegistrationImpl : public wxAnyToVariantRegistration
+{
+public:
+ wxAnyToVariantRegistrationImpl(wxVariantDataFactory factory)
+ : wxAnyToVariantRegistration(factory)
+ {
+ }
+
+ virtual wxAnyValueType* GetAssociatedType()
+ {
+ return wxAnyValueTypeImpl<T>::GetInstance();
+ }
+private:
+};
+
+#define DECLARE_WXANY_CONVERSION() \
+virtual bool GetAsAny(wxAny* any) const; \
+static wxVariantData* VariantDataFactory(const wxAny& any);
+
+#define _REGISTER_WXANY_CONVERSION(T, CLASSNAME, FUNC) \
+static wxAnyToVariantRegistrationImpl<T> \
+ gs_##CLASSNAME##AnyToVariantRegistration = \
+ wxAnyToVariantRegistrationImpl<T>(&FUNC);
+
+#define REGISTER_WXANY_CONVERSION(T, CLASSNAME) \
+_REGISTER_WXANY_CONVERSION(T, CLASSNAME, CLASSNAME::VariantDataFactory)
+
+#define IMPLEMENT_TRIVIAL_WXANY_CONVERSION(T, CLASSNAME) \
+bool CLASSNAME::GetAsAny(wxAny* any) const \
+{ \
+ *any = m_value; \
+ return true; \
+} \
+wxVariantData* CLASSNAME::VariantDataFactory(const wxAny& any) \
+{ \
+ return new CLASSNAME(wxANY_AS(any, T)); \
+} \
+REGISTER_WXANY_CONVERSION(T, CLASSNAME)
+
+// This is needed for wxVariantList conversion
+WX_DECLARE_LIST_WITH_DECL(wxAny, wxAnyList, class WXDLLIMPEXP_BASE);
+
+#else // if !wxUSE_ANY
+
+#define DECLARE_WXANY_CONVERSION()
+#define REGISTER_WXANY_CONVERSION(T, CLASSNAME)
+#define IMPLEMENT_TRIVIAL_WXANY_CONVERSION(T, CLASSNAME)
+
+#endif // wxUSE_ANY/!wxUSE_ANY
+