-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourceVector.cs
More file actions
52 lines (45 loc) · 1.93 KB
/
Copy pathSourceVector.cs
File metadata and controls
52 lines (45 loc) · 1.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
using System;
using System.Collections.Generic;
using System.Runtime.ConstrainedExecution;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.Win32.SafeHandles;
namespace AlureWrapper
{
[SecurityPermission(SecurityAction.InheritanceDemand, UnmanagedCode = true)]
[SecurityPermission(SecurityAction.Demand, UnmanagedCode = true)]
internal class SourceVector : SafeHandleZeroOrMinusOneIsInvalid
{
#region Extern
[DllImport("alure-c-interface", CallingConvention = CallingConvention.Cdecl)]
private static extern void sourceVector_destroyPointer(IntPtr dm);
[DllImport("alure-c-interface", CallingConvention = CallingConvention.Cdecl)]
private static extern UInt64 sourceVector_getSize(IntPtr dm, ref IntPtr exceptionPointer);
[DllImport("alure-c-interface", CallingConvention = CallingConvention.Cdecl)]
private static extern IntPtr sourceVector_getAt(IntPtr dm, UInt64 position, ref IntPtr exceptionPointer);
#endregion Extern
public SourceVector() : base(true) { }
public SourceVector(IntPtr dm, bool ownsHandle = false) : base(ownsHandle)
{
SetHandle(dm);
}
public Source[] ToSources()
{
var list = new List<Source>();
UInt64 size = WrapException.CheckForException((ref IntPtr e) => sourceVector_getSize(handle, ref e));
for (UInt64 i = 0; i < size; ++i)
{
list.Add(new Source(WrapException.CheckForException((ref IntPtr e) => sourceVector_getAt(handle, i, ref e)), true));
}
return list.ToArray();
}
[ReliabilityContract(Consistency.WillNotCorruptState, Cer.Success)]
protected override bool ReleaseHandle()
{
sourceVector_destroyPointer(handle);
SetHandleAsInvalid();
handle = IntPtr.Zero;
return true;
}
}
}