View.hx 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package cpp.marshal;
  2. import cpp.SizeT;
  3. import haxe.Int64;
  4. import haxe.ds.Vector;
  5. import haxe.exceptions.ArgumentException;
  6. @:semantics(value)
  7. @:cpp.ValueType({ namespace:['cpp', 'marshal'], flags: [ StackOnly ] })
  8. extern final class View<T> implements ArrayAccess<T> {
  9. final length : SizeT;
  10. final ptr : Pointer<T>;
  11. function new(ptr:Pointer<T>, length:SizeT):Void;
  12. /**
  13. * Attempts to copy the data from the current view to the destination view.
  14. * If the destination is smaller than the current view this function returns false and no data is written to the destination.
  15. * @param destination Target of the copy operation.
  16. */
  17. function tryCopyTo(destination:View<T>):Bool;
  18. /**
  19. * Copies the the from the current view to the destination view.
  20. * @param destination Target of the copy operation
  21. * @throws ArgumentException If the destination is smaller than the current view.
  22. */
  23. inline function copyTo(destination:View<T>) {
  24. if (tryCopyTo(destination) == false) {
  25. throw new ArgumentException("destination", "Not enough space in the destination view");
  26. }
  27. }
  28. /**
  29. * Sets all items in the current view to their default value.
  30. */
  31. function clear():Void;
  32. /**
  33. * Sets all items in the current view to the specified value.
  34. * @param value The value assigned to each item in the view.
  35. */
  36. function fill(value:T):Void;
  37. /**
  38. * Create a slice of the current view which starts at the specified index.
  39. * @param start Zero based index to start the slice at.
  40. */
  41. overload function slice(start:Int64):View<T>;
  42. /**
  43. * Create a slice of the current view which starts at the specified index and runs for the specified length.
  44. * @param start Zero based index to start the slice at.
  45. * @param length Length of the slice.
  46. */
  47. overload function slice(start:Int64, length:Int64):View<T>;
  48. /**
  49. * Returns if the current view is empty.
  50. */
  51. function isEmpty():Bool;
  52. /**
  53. * Return a view interpreting this views content as a different type.
  54. */
  55. function reinterpret<K>():View<K>;
  56. function compare(rhs:View<T>):Int;
  57. }