|Reported by:||jmsalli||Owned by:|
As discussed on wx-dev, wxAny is a proposed backwards-incompatible replacement for wxVariant. It is based on ideas of various variant implementations and relies heavily on C++ templates.
Attached is some working prototype code.
Some remarks about it:
- wxAny itself holds type information (wxAnyValueType* m_type) and data buffer (wxAnyValueBuffer m_buffer).
- A generic wxAnyValueTypeImpl template, which inherits from wxAnyValueType, should work for about 90% of data types (for others, a specialization of this template would need to be implemented). wxAnyValueTypeImpl uses wxIsMovable to see if type value is appropriate for simple storage in wxAny.m_buffer. If type is not "movable" or its size exceeds the buffer, then a holder object is allocated in heap (similar to existing wxVariant and boost::any behavior).
- Brunt of the wxAnyValueTypeImpl's implementation is embedded in an intermediate wxAnyValueTypeImplBase class. This is done so that this intermediate class can be sub-classed, and then those subclasses can be used as basis for specialized wxAnyValueTypeImpl. For instance, in the first draft wxAnyValueTypeImplBase is used to create wxAnyValueTypeImplInt, which is then used as basis for specialized templates of all signed integer types. This allows for much smoother type conversion between those types.
- For refined custom type conversion, you must create a specialized template and override virtual Convert() function. This is already done, for instance, in wxAnyValueTypeImplInt, to convert int to a wxString.
- wxAnyValueType instances are singletons, allocated in global scope. wxModule is used to free these instances.