Vector.cs 873 B

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Runtime.InteropServices;
  4. namespace AtomicEngine
  5. {
  6. // Type safe wrapper around ScriptVector
  7. public class Vector<T> where T : RefCounted
  8. {
  9. public uint Size
  10. {
  11. get
  12. {
  13. return scriptVector.GetSize();
  14. }
  15. }
  16. public void Push(T refCounted)
  17. {
  18. scriptVector.Push(refCounted);
  19. }
  20. public T At(uint index)
  21. {
  22. return (T)scriptVector.At(index);
  23. }
  24. public T this[int key]
  25. {
  26. get
  27. {
  28. return At((uint)key);
  29. }
  30. }
  31. public T this[uint key]
  32. {
  33. get
  34. {
  35. return At(key);
  36. }
  37. }
  38. public static implicit operator IntPtr(Vector<T> vector)
  39. {
  40. if (vector == null)
  41. return IntPtr.Zero;
  42. return vector.scriptVector.nativeInstance;
  43. }
  44. public ScriptVector GetScriptVector() { return scriptVector; }
  45. ScriptVector scriptVector = new ScriptVector();
  46. }
  47. }