# Path: src/zugbruecke/core/const.py
# GROUP_VOID = 1
# 
# Path: src/zugbruecke/core/data/memory.py
# def generate_pointer_from_bytes(in_bytes):
# 
# 	return ctypes.cast(ctypes.pointer((ctypes.c_ubyte * len(in_bytes)).from_buffer_copy(in_bytes)), ctypes.c_void_p)
# 
# def is_null_pointer(ctypes_pointer):
# 
# 	try:
# 		return ctypes.cast(ctypes_pointer, ctypes.c_void_p).value is None
# 	except ctypes.ArgumentError: # catch non-pointer arguments
# 		return False
# 
# def overwrite_pointer_with_bytes(ctypes_pointer, in_bytes):
# 
# 	ctypes.memmove(ctypes_pointer, ctypes.pointer((ctypes.c_ubyte * len(in_bytes)).from_buffer_copy(in_bytes)), len(in_bytes))
# 
# def serialize_pointer_into_bytes(ctypes_pointer, size_bytes):
# 
# 	return bytes(ctypes.cast(ctypes_pointer, ctypes.POINTER(ctypes.c_ubyte * size_bytes)).contents)


import ctypes
from pprint import pformat as pf
from ..const import GROUP_VOID
from .memory import (
	generate_pointer_from_bytes,
	is_null_pointer,
	overwrite_pointer_with_bytes,
	serialize_pointer_into_bytes
	)

"""


# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# IMPORT
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#import traceback


WCHAR_BYTES = ctypes.sizeof(ctypes.c_wchar)


# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# CLASS: Memory content packing and unpacking
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

class memory_contents_class():


	def apply_memsync_to_argtypes_and_restype_definition(self, memsync_d_list, argtypes_d, restype_d):

		# Iterate over memory segments, which must be kept in sync
		for memsync_d in memsync_d_list:

			# Get type of pointer argument
			arg_type = self.__get_argument_type_by_memsync_path__(memsync_d['p'], argtypes_d, restype_d)

			# HACK make memory sync pointers type agnostic

# Path: src/zugbruecke/core/const.py
# GROUP_VOID = 1
# 
# Path: src/zugbruecke/core/data/memory.py
# def generate_pointer_from_bytes(in_bytes):
# 
# 	return ctypes.cast(ctypes.pointer((ctypes.c_ubyte * len(in_bytes)).from_buffer_copy(in_bytes)), ctypes.c_void_p)
# 
# def is_null_pointer(ctypes_pointer):
# 
# 	try:
# 		return ctypes.cast(ctypes_pointer, ctypes.c_void_p).value is None
# 	except ctypes.ArgumentError: # catch non-pointer arguments
# 		return False
# 
# def overwrite_pointer_with_bytes(ctypes_pointer, in_bytes):
# 
# 	ctypes.memmove(ctypes_pointer, ctypes.pointer((ctypes.c_ubyte * len(in_bytes)).from_buffer_copy(in_bytes)), len(in_bytes))
# 
# def serialize_pointer_into_bytes(ctypes_pointer, size_bytes):
# 
# 	return bytes(ctypes.cast(ctypes_pointer, ctypes.POINTER(ctypes.c_ubyte * size_bytes)).contents)


# Path: src/zugbruecke/core/data/mem_contents.py
import ctypes
from pprint import pformat as pf
from ..const import GROUP_VOID
from .memory import (
	generate_pointer_from_bytes,
	is_null_pointer,
	overwrite_pointer_with_bytes,
	serialize_pointer_into_bytes
	)


"""


# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# IMPORT
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

#import traceback


WCHAR_BYTES = ctypes.sizeof(ctypes.c_wchar)


# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
# CLASS: Memory content packing and unpacking
# +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

class memory_contents_class():


	def apply_memsync_to_argtypes_and_restype_definition(self, memsync_d_list, argtypes_d, restype_d):

		# Iterate over memory segments, which must be kept in sync
		for memsync_d in memsync_d_list:

			# Get type of pointer argument
			arg_type = self.__get_argument_type_by_memsync_path__(memsync_d['p'], argtypes_d, restype_d)

			# HACK make memory sync pointers type agnostic

			arg_type['g'] = GROUP_VOID