# AUTOGENERATED FILE - DO NOT MODIFY!
# This file generated by Djinni from test.djinni

from djinni.support import MultiSet # default imported in all files
from djinni.exception import CPyException # default imported in all files
from djinni.pycffi_marshal import CPyObject, CPyObjectProxy, CPyPrimitive, CPyString
from PyCFFIlib_cffi import ffi, lib

from djinni import exception # this forces run of __init__.py which gives cpp option to call back into py to create exception

class MapStringInt64THelper:
    c_data_set = MultiSet()

    @staticmethod
    def check_c_data_set_empty():
        assert len(MapStringInt64THelper.c_data_set) == 0

    @ffi.callback("int64_t(struct DjinniObjectHandle *, struct DjinniString *)")
    def __get_value(cself, key):
        pyKey = CPyString.toPyWithoutTakingOwnership(key)
        assert pyKey is not None
        try:
            _ret = CPyPrimitive.fromPy(CPyObjectProxy.toPyObj(None, cself)[pyKey])
            return _ret
        except Exception as _djinni_py_e:
            CPyException.setExceptionFromPy(_djinni_py_e)
            return ffi.NULL

    @ffi.callback("size_t(struct DjinniObjectHandle *)")
    def __get_size(cself):
        return len(CPyObjectProxy.toPyObj(None, cself))

    @ffi.callback("struct DjinniObjectHandle *()")
    def __python_create():
        c_ptr = ffi.new_handle(MapStringInt64TProxy(dict()))
        MapStringInt64THelper.c_data_set.add(c_ptr)
        return ffi.cast("struct DjinniObjectHandle *", c_ptr)

    @ffi.callback("void(struct DjinniObjectHandle *, struct DjinniString *, int64_t)")
    def __python_add(cself, key, value):
        CPyObjectProxy.toPyObj(None, cself)[CPyString.toPy(key)] = CPyPrimitive.toPy(value)

    @ffi.callback("void(struct DjinniObjectHandle * )")
    def __delete(c_ptr):
        assert c_ptr in MapStringInt64THelper.c_data_set
        MapStringInt64THelper.c_data_set.remove(c_ptr)

    @ffi.callback("struct DjinniString *(struct DjinniObjectHandle *)")
    def __python_next(cself):
        try:
            with CPyString.fromPy(next(CPyObjectProxy.toPyIter(cself))) as py_obj:
                _ret = py_obj.release_djinni_string()
                assert _ret != ffi.NULL
                return _ret
        except Exception as _djinni_py_e:
            CPyException.setExceptionFromPy(_djinni_py_e)
            return ffi.NULL

    @staticmethod
    def _add_callbacks():
        lib.map_string_int64_t_add_callback__get_value(MapStringInt64THelper.__get_value)
        lib.map_string_int64_t_add_callback___delete(MapStringInt64THelper.__delete)
        lib.map_string_int64_t_add_callback__get_size(MapStringInt64THelper.__get_size)
        lib.map_string_int64_t_add_callback__python_create(MapStringInt64THelper.__python_create)
        lib.map_string_int64_t_add_callback__python_add(MapStringInt64THelper.__python_add)
        lib.map_string_int64_t_add_callback__python_next(MapStringInt64THelper.__python_next)

MapStringInt64THelper._add_callbacks()

class MapStringInt64TProxy:
    def iter(d):
        for k in d:
            yield k

    def __init__(self, py_obj):
        self._py_obj = py_obj
        if py_obj is not None:
            self._py_iter = iter(py_obj)
        else:
            self._py_iter = None
