Cast

Contains functions to help casting pointers to Tokens using dynamic_cast. Helpful for dealing with different overloads in Registrables. For example, suppose we have the following Registrable that is supposed to take up to three integers.

ZHETAPI_REGISTRABLE(my_registrable)
{
    OpZ o1, o2, o3;

    // Performing overload switching with zhetapi_cast (should be used for very
    // specific or seemingly random overloads)
    if (zhetapi_cast(inputs, o1, o2, o3)) {
        // do the function for three integers (o1, o2, o3)
    } else if (zhetapi_cast(inputs, o1, o2)) {
        // do the function for two integers (o1, o2)
    } else if (zhetapi_cast(inputs, o1)) {
        // do the function for two integers (o1)
    } else {
        // Terminating branch...
    }

    // ...or use zhetapi_cc_cast (should be used for sequences of partial
    // overloads)
    switch (zhetapi_cc_cast(inputs, o1, o2, o3)) {
    case 3:
        // do the function for three integers (o1, o2, o3)
    case 2:
        // do the function for two integers (o1, o2)
    case 1:
        // do the function for one integer (o1)
    default:
        break;
    }

    // As the terminating action either
    return nullptr;

    // ...or throw
    throw my_exception();
}

namespace zhetapi

Functions

template<class T>
bool zhetapi_cast_process(const std::vector<Token*> &tokens, size_t i, T &tptr)
template<class T>
void zhetapi_cast_cc_process(const std::vector<Token*> &tokens, size_t &i, T &tptr)