Implicit Conversion and Wrappers - acidrainstudios/TrueReality GitHub Wiki

Implicit Conversion and Wrappers

TR will be wrapping most of the SDKs it uses, but also wants to maintain ease of conversion and interoperability between it and the SDKs original classes. We don't want to completely hide the wrapped class from the users, they might want to access it directly, but we also want to have a common look and feel and coding style through out the engine. For this to be achievable all of the wrappers must contain a way to implicitly convert themselves to their base class.

For standardization the same implicit conversion operators need to be created in all wrappers. If we have class ClassA that wraps class ClassB we would have the following operators:

//////////////////////////////////////////////////////////////////////////
ClassA::operator ClassB  () const
{
    return mClassB;
}

//////////////////////////////////////////////////////////////////////////
ClassA::operator ClassB & ()
{
    return mClassB;
}

//////////////////////////////////////////////////////////////////////////
ClassA::operator const ClassB & () const
{
    return mClassB;
}

//////////////////////////////////////////////////////////////////////////
ClassA::operator ClassB * ()
{
    return &mClassB;
}