(DISTFILES): Comment out a few missing files.
[mono-project.git] / mcs / class / Mono.PEToolkit / LEBitConverter.cs
blob2814547df754c88cb569b204b897222d777e4e7b
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining
4 // a copy of this software and associated documentation files (the
5 // "Software"), to deal in the Software without restriction, including
6 // without limitation the rights to use, copy, modify, merge, publish,
7 // distribute, sublicense, and/or sell copies of the Software, and to
8 // permit persons to whom the Software is furnished to do so, subject to
9 // the following conditions:
10 //
11 // The above copyright notice and this permission notice shall be
12 // included in all copies or substantial portions of the Software.
13 //
14 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15 // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16 // MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17 // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18 // LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19 // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
23 // Auto-generated file - DO NOT EDIT!
24 // Please edit bitconverter.xsl if you want to make changes.
26 using System;
28 namespace Mono.PEToolkit {
30 /// <summary>
31 /// Little-endian bit converter.
32 /// </summary>
33 public sealed class LEBitConverter {
35 internal interface IConverter {
37 short ToInt16(byte [] val, int idx);
38 ushort ToUInt16(byte [] val, int idx);
39 int ToInt32(byte [] val, int idx);
40 uint ToUInt32(byte [] val, int idx);
41 long ToInt64(byte [] val, int idx);
42 ulong ToUInt64(byte [] val, int idx);
46 public static readonly bool Native = System.BitConverter.IsLittleEndian;
48 private static readonly IConverter impl = System.BitConverter.IsLittleEndian
49 ? new LEConverter() as IConverter
50 : new BEConverter() as IConverter;
55 private LEBitConverter()
57 // Never instantiated.
60 ///<summary></summary>
61 unsafe public static short SwapInt16(short x)
63 short* p = stackalloc short [1];
64 *p = x;
65 byte* bp = (byte*) p;
66 byte b = bp [0];
67 bp [0] = bp [1];
68 bp [1] = b;
69 return *p;
72 ///<summary></summary>
73 unsafe public static ushort SwapUInt16(ushort x)
75 ushort* p = stackalloc ushort [1];
76 *p = x;
77 byte* bp = (byte*) p;
78 byte b = bp [0];
79 bp [0] = bp [1];
80 bp [1] = b;
81 return *p;
84 ///<summary></summary>
85 unsafe public static int SwapInt32(int x)
87 int* p = stackalloc int [1];
88 *p = x;
89 byte* bp = (byte*) p;
90 byte b = bp [0];
91 bp [0] = bp [3];
92 bp [3] = b;
93 b = bp [1];
94 bp [1] = bp [2];
95 bp [2] = b;
96 return *p;
99 ///<summary></summary>
100 unsafe public static uint SwapUInt32(uint x)
102 uint* p = stackalloc uint [1];
103 *p = x;
104 byte* bp = (byte*) p;
105 byte b = bp [0];
106 bp [0] = bp [3];
107 bp [3] = b;
108 b = bp [1];
109 bp [1] = bp [2];
110 bp [2] = b;
111 return *p;
114 ///<summary></summary>
115 unsafe public static long SwapInt64(long x)
117 long* p = stackalloc long [1];
118 *p = x;
119 byte* bp = (byte*) p;
120 byte b = bp [0];
121 bp [0] = bp [7];
122 bp [7] = b;
123 b = bp [1];
124 bp [1] = bp [6];
125 bp [6] = b;
126 b = bp [2];
127 bp [2] = bp [5];
128 bp [5] = b;
129 b = bp [3];
130 bp [3] = bp [4];
131 bp [4] = b;
132 return *p;
135 ///<summary></summary>
136 unsafe public static ulong SwapUInt64(ulong x)
138 ulong* p = stackalloc ulong [1];
139 *p = x;
140 byte* bp = (byte*) p;
141 byte b = bp [0];
142 bp [0] = bp [7];
143 bp [7] = b;
144 b = bp [1];
145 bp [1] = bp [6];
146 bp [6] = b;
147 b = bp [2];
148 bp [2] = bp [5];
149 bp [5] = b;
150 b = bp [3];
151 bp [3] = bp [4];
152 bp [4] = b;
153 return *p;
160 internal sealed class LEConverter : IConverter {
161 ///<summary></summary>
162 public short ToInt16(byte [] val, int idx)
164 return BitConverter.ToInt16(val, idx);
166 ///<summary></summary>
167 public ushort ToUInt16(byte [] val, int idx)
169 return BitConverter.ToUInt16(val, idx);
171 ///<summary></summary>
172 public int ToInt32(byte [] val, int idx)
174 return BitConverter.ToInt32(val, idx);
176 ///<summary></summary>
177 public uint ToUInt32(byte [] val, int idx)
179 return BitConverter.ToUInt32(val, idx);
181 ///<summary></summary>
182 public long ToInt64(byte [] val, int idx)
184 return BitConverter.ToInt64(val, idx);
186 ///<summary></summary>
187 public ulong ToUInt64(byte [] val, int idx)
189 return BitConverter.ToUInt64(val, idx);
194 internal sealed class BEConverter : IConverter {
195 ///<summary></summary>
196 public short ToInt16(byte [] val, int idx)
198 return SwapInt16(BitConverter.ToInt16(val, idx));
200 ///<summary></summary>
201 public ushort ToUInt16(byte [] val, int idx)
203 return SwapUInt16(BitConverter.ToUInt16(val, idx));
205 ///<summary></summary>
206 public int ToInt32(byte [] val, int idx)
208 return SwapInt32(BitConverter.ToInt32(val, idx));
210 ///<summary></summary>
211 public uint ToUInt32(byte [] val, int idx)
213 return SwapUInt32(BitConverter.ToUInt32(val, idx));
215 ///<summary></summary>
216 public long ToInt64(byte [] val, int idx)
218 return SwapInt64(BitConverter.ToInt64(val, idx));
220 ///<summary></summary>
221 public ulong ToUInt64(byte [] val, int idx)
223 return SwapUInt64(BitConverter.ToUInt64(val, idx));
231 ///<summary></summary>
232 public static short ToInt16(byte [] val, int idx)
234 return impl.ToInt16(val, idx);
237 ///<summary></summary>
238 public static ushort ToUInt16(byte [] val, int idx)
240 return impl.ToUInt16(val, idx);
243 ///<summary></summary>
244 public static int ToInt32(byte [] val, int idx)
246 return impl.ToInt32(val, idx);
249 ///<summary></summary>
250 public static uint ToUInt32(byte [] val, int idx)
252 return impl.ToUInt32(val, idx);
255 ///<summary></summary>
256 public static long ToInt64(byte [] val, int idx)
258 return impl.ToInt64(val, idx);
261 ///<summary></summary>
262 public static ulong ToUInt64(byte [] val, int idx)
264 return impl.ToUInt64(val, idx);