﻿using System;
using NativeMarshal = System.Runtime.InteropServices.Marshal;

namespace REKT.DI
{
    internal class MarshalDependency : IMarshalDependency
    {
        public IntPtr AllocCoTaskMem(int cb)
        {
            return NativeMarshal.AllocCoTaskMem(cb);
        }

        public IntPtr AllocHGlobal(IntPtr cb)
        {
            return NativeMarshal.AllocHGlobal(cb);
        }

        public IntPtr AllocHGlobal(int cb)
        {
            return NativeMarshal.AllocHGlobal(cb);
        }

        public void Copy(IntPtr source, double[] destination, int startIndex, int length)
        {
            NativeMarshal.Copy(source, destination, startIndex, length);
        }

        public void Copy(IntPtr source, float[] destination, int startIndex, int length)
        {
            NativeMarshal.Copy(source, destination, startIndex, length);
        }

        public void Copy(IntPtr source, long[] destination, int startIndex, int length)
        {
            NativeMarshal.Copy(source, destination, startIndex, length);
        }

        public void Copy(IntPtr source, int[] destination, int startIndex, int length)
        {
            NativeMarshal.Copy(source, destination, startIndex, length);
        }

        public void Copy(IntPtr source, short[] destination, int startIndex, int length)
        {
            NativeMarshal.Copy(source, destination, startIndex, length);
        }

        public void Copy(IntPtr source, char[] destination, int startIndex, int length)
        {
            NativeMarshal.Copy(source, destination, startIndex, length);
        }

        public void Copy(IntPtr source, byte[] destination, int startIndex, int length)
        {
            NativeMarshal.Copy(source, destination, startIndex, length);
        }

        public void Copy(IntPtr[] source, int startIndex, IntPtr destination, int length)
        {
            NativeMarshal.Copy(source, startIndex, destination, length);
        }

        public void Copy(float[] source, int startIndex, IntPtr destination, int length)
        {
            NativeMarshal.Copy(source, startIndex, destination, length);
        }

        public void Copy(long[] source, int startIndex, IntPtr destination, int length)
        {
            NativeMarshal.Copy(source, startIndex, destination, length);
        }

        public void Copy(IntPtr source, IntPtr[] destination, int startIndex, int length)
        {
            NativeMarshal.Copy(source, destination, startIndex, length);
        }

        public void Copy(short[] source, int startIndex, IntPtr destination, int length)
        {
            NativeMarshal.Copy(source, startIndex, destination, length);
        }

        public void Copy(char[] source, int startIndex, IntPtr destination, int length)
        {
            NativeMarshal.Copy(source, startIndex, destination, length);
        }

        public void Copy(byte[] source, int startIndex, IntPtr destination, int length)
        {
            NativeMarshal.Copy(source, startIndex, destination, length);
        }

        public void Copy(double[] source, int startIndex, IntPtr destination, int length)
        {
            NativeMarshal.Copy(source, startIndex, destination, length);
        }

        public void Copy(int[] source, int startIndex, IntPtr destination, int length)
        {
            NativeMarshal.Copy(source, startIndex, destination, length);
        }

        public void FreeCoTaskMem(IntPtr ptr)
        {
            NativeMarshal.FreeCoTaskMem(ptr);
        }

        public void FreeHGlobal(IntPtr hglobal)
        {
            NativeMarshal.FreeHGlobal(hglobal);
        }

        public T PtrToStructure<T>(IntPtr handle) where T : struct
        {
            return NativeMarshal.PtrToStructure<T>(handle);
        }
    }
}