
""" Generated by OTF2 Template Engine """

import ctypes

from .Config import conf, StrParam
from .ErrorCodes import ErrorCode, HandleErrorCode
from .GeneralDefinitions import *
from .Definitions import *
from .Events import *


class AttributeValue(ctypes.Union):
    """
    ctypes does not support unions as (non-pointer) arguments
    _arg_value / _arg_type is a crude and evil hack to guess
    the right argument type. This type must be correct in terms of
    size (maximum of the union) and
    calling convention (architecture specific, but for AMD64 int usually wins).
    Whenever used as a direct function argument (also applies to callbacks)
    this type should be used instead of the union. Otherwise you get undefined
    behavior.
    """
    _arg_type = ctypes.c_uint64
    _fields_ = [
@otf2 for entry in Type.entries if entry.type:
        ("@@entry.type.lower@@", @@entry.type.py_ctype@@),
@otf2 endfor
@otf2 for entry in MappingType.entries:
        ("@@entry.def.ref_lname@@Ref", @@entry.def.self_attr.type.py_ctype@@),
@otf2 endfor
        ("_arg_value", ctypes.c_uint64),
    ]

@otf2 for enum in enums:
def AttributeValue_Set@@enum.name@@(enumValue, type_=Type(), value=AttributeValue()):
    c_Set@@enum.name@@ = conf.lib.OTF2_AttributeValue_Set@@enum.name@@
    c_Set@@enum.name@@.argtypes = [ @@enum.type.py_argtype@@, ctypes.POINTER(Type), ctypes.POINTER(AttributeValue) ]
    c_Set@@enum.name@@.restype = ErrorCode
    c_Set@@enum.name@@.errcheck = HandleErrorCode
    c_Set@@enum.name@@(enumValue, ctypes.byref(type_), ctypes.byref(value))
    return (type_, value)

@otf2 endfor
@otf2 for enum in enums:
def AttributeValue_Get@@enum.name@@(type, enum_value=@@enum.type.py_ctype@@()):
    c_Get@@enum.name@@ = conf.lib.OTF2_AttributeValue_Get@@enum.name@@
    c_Get@@enum.name@@.argtypes = [ Type, AttributeValue._arg_type, ctypes.POINTER(@@enum.type.py_ctype@@) ]
    c_Get@@enum.name@@.restype = ErrorCode
    c_Get@@enum.name@@.errcheck = HandleErrorCode
    c_Get@@enum.name@@(type, value._arg_value, ctypes.byref(enum_value))
    return enum_value

@otf2 endfor
__all__ = [
    'AttributeValue',
    @otf2 for enum in enums:
    'AttributeValue_Set@@enum.name@@',
    'AttributeValue_Get@@enum.name@@',
    @otf2 endfor
]
