#include "mirror.h"

MirroredTypeclass* internal_mirror_get_typeclass(void* self, IMirror const* tc, const char* typeclass) {
    uintptr_t target_hash = strhash(typeclass);
    list_foreach(MirroredTypeclass*, class, tc->get_typeclasses(self)) {
        if(target_hash == class->name_hash && strcmp(typeclass, class->typeclass_name) == 0)
            return class;
    }
    return NULL;
}

const void* mirror_get_typeclass(void* data, IMirror const* tc, const char* typeclass) {
    MirroredTypeclass* class = internal_mirror_get_typeclass(data, tc, typeclass);
    if(class != NULL)
        return class->typeclass;
    else
        return NULL;
}

void* mirror_get_function(void* data, IMirror const* tc, const char* typeclass_name) {
    MirroredTypeclass* class = internal_mirror_get_typeclass(data, tc, typeclass_name);
    if(class != NULL)
        return class->function;
    else
        return NULL;
}
