FixedArray.cs 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Box2D.XNA port of Box2D:
  3. * Copyright (c) 2009 Brandon Furtwangler, Nathan Furtwangler
  4. *
  5. * Original source Box2D:
  6. * Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
  7. *
  8. * This software is provided 'as-is', without any express or implied
  9. * warranty. In no event will the authors be held liable for any damages
  10. * arising from the use of this software.
  11. * Permission is granted to anyone to use this software for any purpose,
  12. * including commercial applications, and to alter it and redistribute it
  13. * freely, subject to the following restrictions:
  14. * 1. The origin of this software must not be misrepresented; you must not
  15. * claim that you wrote the original software. If you use this software
  16. * in a product, an acknowledgment in the product documentation would be
  17. * appreciated but is not required.
  18. * 2. Altered source versions must be plainly marked as such, and must not be
  19. * misrepresented as being the original software.
  20. * 3. This notice may not be removed or altered from any source distribution.
  21. */
  22. using System;
  23. namespace Box2D.XNA
  24. {
  25. public struct FixedArray2<T>
  26. {
  27. public T this[int index]
  28. {
  29. get
  30. {
  31. switch (index)
  32. {
  33. case 0:
  34. return _value0;
  35. case 1:
  36. return _value1;
  37. default:
  38. throw new IndexOutOfRangeException();
  39. }
  40. }
  41. set
  42. {
  43. switch (index)
  44. {
  45. case 0:
  46. _value0 = value;
  47. break;
  48. case 1:
  49. _value1 = value;
  50. break;
  51. default:
  52. throw new IndexOutOfRangeException();
  53. }
  54. }
  55. }
  56. T _value0;
  57. T _value1;
  58. }
  59. public struct FixedArray3<T>
  60. {
  61. public T this[int index]
  62. {
  63. get
  64. {
  65. switch (index)
  66. {
  67. case 0:
  68. return _value0;
  69. case 1:
  70. return _value1;
  71. case 2:
  72. return _value2;
  73. default:
  74. throw new IndexOutOfRangeException();
  75. }
  76. }
  77. set
  78. {
  79. switch (index)
  80. {
  81. case 0:
  82. _value0 = value;
  83. break;
  84. case 1:
  85. _value1 = value;
  86. break;
  87. case 2:
  88. _value2 = value;
  89. break;
  90. default:
  91. throw new IndexOutOfRangeException();
  92. }
  93. }
  94. }
  95. T _value0;
  96. T _value1;
  97. T _value2;
  98. }
  99. public struct FixedArray4<T>
  100. {
  101. public T this[int index]
  102. {
  103. get
  104. {
  105. switch (index)
  106. {
  107. case 0:
  108. return _value0;
  109. case 1:
  110. return _value1;
  111. case 2:
  112. return _value2;
  113. case 3:
  114. return _value3;
  115. default:
  116. throw new IndexOutOfRangeException();
  117. }
  118. }
  119. set
  120. {
  121. switch (index)
  122. {
  123. case 0:
  124. _value0 = value;
  125. break;
  126. case 1:
  127. _value1 = value;
  128. break;
  129. case 2:
  130. _value2 = value;
  131. break;
  132. case 3:
  133. _value3 = value;
  134. break;
  135. default:
  136. throw new IndexOutOfRangeException();
  137. }
  138. }
  139. }
  140. T _value0;
  141. T _value1;
  142. T _value2;
  143. T _value3;
  144. }
  145. public struct FixedArray8<T>
  146. {
  147. public T this[int index]
  148. {
  149. get
  150. {
  151. switch (index)
  152. {
  153. case 0:
  154. return _value0;
  155. case 1:
  156. return _value1;
  157. case 2:
  158. return _value2;
  159. case 3:
  160. return _value3;
  161. case 4:
  162. return _value4;
  163. case 5:
  164. return _value5;
  165. case 6:
  166. return _value6;
  167. case 7:
  168. return _value7;
  169. default:
  170. throw new IndexOutOfRangeException();
  171. }
  172. }
  173. set
  174. {
  175. switch (index)
  176. {
  177. case 0:
  178. _value0 = value;
  179. break;
  180. case 1:
  181. _value1 = value;
  182. break;
  183. case 2:
  184. _value2 = value;
  185. break;
  186. case 3:
  187. _value3 = value;
  188. break;
  189. case 4:
  190. _value4 = value;
  191. break;
  192. case 5:
  193. _value5 = value;
  194. break;
  195. case 6:
  196. _value6 = value;
  197. break;
  198. case 7:
  199. _value7 = value;
  200. break;
  201. default:
  202. throw new IndexOutOfRangeException();
  203. }
  204. }
  205. }
  206. T _value0;
  207. T _value1;
  208. T _value2;
  209. T _value3;
  210. T _value4;
  211. T _value5;
  212. T _value6;
  213. T _value7;
  214. }
  215. }