MIRA
|
Class that allows to maintain type-safety when passing void pointers. More...
#include <utils/TypedVoidPtr.h>
Public Member Functions | |
TypedVoidPtr () | |
Creates nullptr. More... | |
template<typename T > | |
TypedVoidPtr (T *ptr) | |
Creates a typed void pointer from the given pointer. More... | |
bool | isNull () const |
Return if underlying pointer is NULL. More... | |
template<typename T > | |
operator T* () | |
Safely casts to T*. More... | |
template<typename T > | |
operator const T * () const | |
Safely casts to const T*. More... | |
template<typename T > | |
T * | cast () |
Safely casts the object pointer that is stored to T*. More... | |
template<typename T > | |
const T * | cast () const |
Safely casts the object pointer that is stored to const T*. More... | |
Class that allows to maintain type-safety when passing void pointers.
Sometimes, it is necessary to pass a void* pointer through an interface, while maintaining type safety. This can be achieved using this class. Assume you want to pass different objects of different types through the following single interface, which must be the same for all types and objects (e.g. when you cannot use templates)
Now assume, you have different classes that implement this interface for different types, then you can use the TypeVoidPtr class as follows:
|
inline |
Creates nullptr.
|
inline |
Creates a typed void pointer from the given pointer.
|
inline |
Return if underlying pointer is NULL.
|
inline |
Safely casts to T*.
XBadCast,if | the stored void pointer is not of type T. |
|
inline |
Safely casts to const T*.
XBadCast,if | the stored void pointer is not of type T. |
|
inline |
Safely casts the object pointer that is stored to T*.
XBadCast,if | the stored void pointer is not of type T. |
|
inline |
Safely casts the object pointer that is stored to const T*.
XBadCast,if | the stored void pointer is not of type T. |