Example #1
0
File: core.cpp Project: alurin/kiwi
KiwiObject kiwi_up_cast(KiwiObject obj, KiwiType type) {
    TypePtr current = kiwi_icast(obj->Data->Type);
    TypePtr derived = kiwi_icast(type);

    // check requirement of a upper cast
    if (current == derived) {
        return obj;
    }

    // allocate new object handler and store pointers
    KiwiObject parent = (KiwiObject) kiwi_malloc(sizeof(KiwiOpaqueObject));
    parent->VTable    = reinterpret_cast<KiwiVTable*>(current->getVTablePointer(derived));
    parent->AMap      = reinterpret_cast<KiwiAMap*>(current->getAMapPointer(derived));
    parent->Data      = obj->Data;
    return parent;
}