summaryrefslogtreecommitdiff
path: root/src/bindings/mono/eina_mono/eina_binbuf.cs
diff options
context:
space:
mode:
authorLauro Moura <lauromoura@expertisesolutions.com.br>2017-11-23 21:49:22 -0300
committerLauro Moura <lauromoura@expertisesolutions.com.br>2017-12-04 15:47:49 -0300
commit9391407319424c503a78479b407737ccead945b7 (patch)
treeedc4d5bab7b79667c9853d3c9d9ed2956e498394 /src/bindings/mono/eina_mono/eina_binbuf.cs
parente6dd831f7ea57bc4717f364141be1bf197da3cc8 (diff)
efl_mono: Adding support code for the C# binding
This is the C# manual code for the binding. Buildsystem integration will come in a future commit.
Diffstat (limited to 'src/bindings/mono/eina_mono/eina_binbuf.cs')
-rw-r--r--src/bindings/mono/eina_mono/eina_binbuf.cs210
1 files changed, 210 insertions, 0 deletions
diff --git a/src/bindings/mono/eina_mono/eina_binbuf.cs b/src/bindings/mono/eina_mono/eina_binbuf.cs
new file mode 100644
index 0000000..dd30ab1
--- /dev/null
+++ b/src/bindings/mono/eina_mono/eina_binbuf.cs
@@ -0,0 +1,210 @@
1using System;
2using System.Runtime.InteropServices;
3
4namespace eina {
5
6public class Binbuf : IDisposable
7{
8 [DllImport(efl.Libs.Eina)] public static extern IntPtr
9 eina_binbuf_new();
10 [DllImport(efl.Libs.Eina)] public static extern void
11 eina_binbuf_free(IntPtr buf);
12 [DllImport(efl.Libs.Eina)] public static extern void
13 eina_binbuf_reset(IntPtr buf);
14 [DllImport(efl.Libs.Eina)] public static extern byte
15 eina_binbuf_append_length(IntPtr buf, byte[] str, UIntPtr length);
16 [DllImport(efl.Libs.Eina)] public static extern byte
17 eina_binbuf_append_slice(IntPtr buf, eina.Slice slice);
18 [DllImport(efl.Libs.Eina)] public static extern byte
19 eina_binbuf_append_buffer(IntPtr buf, IntPtr data);
20 [DllImport(efl.Libs.Eina)] public static extern byte
21 eina_binbuf_append_char(IntPtr buf, byte c);
22 [DllImport(efl.Libs.Eina)] public static extern byte
23 eina_binbuf_insert_length(IntPtr buf, byte[] str, UIntPtr length, UIntPtr pos);
24 [DllImport(efl.Libs.Eina)] public static extern byte
25 eina_binbuf_insert_slice(IntPtr buf, eina.Slice slice, UIntPtr pos);
26 [DllImport(efl.Libs.Eina)] public static extern byte
27 eina_binbuf_insert_char(IntPtr buf, byte c, UIntPtr pos);
28 [DllImport(efl.Libs.Eina)] public static extern byte
29 eina_binbuf_remove(IntPtr buf, UIntPtr start, UIntPtr end);
30 [DllImport(efl.Libs.Eina)] public static extern IntPtr
31 eina_binbuf_string_get(IntPtr buf);
32 [DllImport(efl.Libs.Eina)] public static extern void
33 eina_binbuf_string_free(IntPtr buf);
34 [DllImport(efl.Libs.Eina)] public static extern UIntPtr
35 eina_binbuf_length_get(IntPtr buf);
36 [DllImport(efl.Libs.Eina)] public static extern eina.Slice
37 eina_binbuf_slice_get(IntPtr buf);
38
39 public IntPtr Handle {get;set;} = IntPtr.Zero;
40 public bool Own {get;set;}
41
42 public int Length
43 {
44 get { return (int) GetLength(); }
45 }
46
47 private void InitNew()
48 {
49 Handle = eina_binbuf_new();
50 Own = true;
51 if (Handle == IntPtr.Zero)
52 throw new SEHException("Could not alloc binbuf");
53 }
54
55 public Binbuf()
56 {
57 InitNew();
58 }
59
60 public Binbuf(byte[] str, uint? length = null)
61 {
62 InitNew();
63
64 if (str != null)
65 {
66 if (!Append(str, (length != null ? length.Value : (uint)(str.Length))))
67 {
68 Dispose();
69 throw new SEHException("Could not append on binbuf");
70 }
71 }
72 }
73
74 public Binbuf(Binbuf bb)
75 {
76 InitNew();
77
78 if (bb != null)
79 {
80 Append(bb);
81 }
82 }
83
84 public Binbuf(IntPtr handle, bool own)
85 {
86 Handle = handle;
87 Own = own;
88 }
89
90 ~Binbuf()
91 {
92 Dispose(false);
93 }
94
95 protected virtual void Dispose(bool disposing)
96 {
97 IntPtr h = Handle;
98 Handle = IntPtr.Zero;
99 if (Own && h != IntPtr.Zero) {
100 eina_binbuf_free(Handle);
101 }
102 }
103
104 public void Dispose()
105 {
106 Dispose(true);
107 GC.SuppressFinalize(this);
108 }
109
110 public void Free()
111 {
112 Dispose();
113 }
114
115 public IntPtr Release()
116 {
117 IntPtr h = Handle;
118 Handle = IntPtr.Zero;
119 return h;
120 }
121
122 public void Reset()
123 {
124 eina_binbuf_reset(Handle);
125 }
126
127 public bool Append(byte[] str)
128 {
129 return 0 != eina_binbuf_append_length(Handle, str, (UIntPtr)(str.Length));
130 }
131
132 public bool Append(byte[] str, uint length)
133 {
134 return 0 != eina_binbuf_append_length(Handle, str, (UIntPtr)length);
135 }
136
137 public bool Append(Binbuf bb)
138 {
139 return 0 != eina_binbuf_append_buffer(Handle, bb.Handle);
140 }
141
142 public bool Append(byte c)
143 {
144 return 0 != eina_binbuf_append_char(Handle, c);
145 }
146
147 public bool Append(eina.Slice slice)
148 {
149 return 0 != eina_binbuf_append_slice(Handle, slice);
150 }
151
152 public bool Insert(byte[] str, uint pos)
153 {
154 return 0 != eina_binbuf_insert_length(Handle, str, (UIntPtr)(str.Length), (UIntPtr)pos);
155 }
156
157 public bool Insert(byte[] str, uint length, uint pos)
158 {
159 return 0 != eina_binbuf_insert_length(Handle, str, (UIntPtr)length, (UIntPtr)pos);
160 }
161
162 public bool Insert(byte c, uint pos)
163 {
164 return 0 != eina_binbuf_insert_char(Handle, c, (UIntPtr)pos);
165 }
166
167 public bool Insert(eina.Slice slice, uint pos)
168 {
169 return 0 != eina_binbuf_insert_slice(Handle, slice, (UIntPtr)pos);
170 }
171
172 public bool Remove(uint start, uint end)
173 {
174 return 0 != eina_binbuf_remove(Handle, (UIntPtr)start, (UIntPtr)end);
175 }
176
177 public byte[] GetBytes()
178 {
179 var ptr = eina_binbuf_string_get(Handle);
180 if (ptr == IntPtr.Zero)
181 return null;
182
183 var size = (int)(this.GetLength());
184 byte[] mArray = new byte[size];
185 Marshal.Copy(ptr, mArray, 0, size);
186 return mArray;
187 }
188
189 public IntPtr GetStringNative()
190 {
191 return eina_binbuf_string_get(Handle);
192 }
193
194 public void FreeString()
195 {
196 eina_binbuf_string_free(Handle);
197 }
198
199 public UIntPtr GetLength()
200 {
201 return eina_binbuf_length_get(Handle);
202 }
203
204 eina.Slice GetSlice()
205 {
206 return eina_binbuf_slice_get(Handle);
207 }
208}
209
210}