You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

LLamaPos.cs 1.4 kB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. using System.Runtime.InteropServices;
  2. namespace LLama.Native;
  3. /// <summary>
  4. /// Indicates position in a sequence
  5. /// </summary>
  6. [StructLayout(LayoutKind.Sequential)]
  7. public record struct LLamaPos
  8. {
  9. /// <summary>
  10. /// The raw value
  11. /// </summary>
  12. public int Value;
  13. /// <summary>
  14. /// Create a new LLamaPos
  15. /// </summary>
  16. /// <param name="value"></param>
  17. private LLamaPos(int value)
  18. {
  19. Value = value;
  20. }
  21. /// <summary>
  22. /// Convert a LLamaPos into an integer (extract the raw value)
  23. /// </summary>
  24. /// <param name="pos"></param>
  25. /// <returns></returns>
  26. public static explicit operator int(LLamaPos pos) => pos.Value;
  27. /// <summary>
  28. /// Convert an integer into a LLamaPos
  29. /// </summary>
  30. /// <param name="value"></param>
  31. /// <returns></returns>
  32. public static implicit operator LLamaPos(int value) => new(value);
  33. /// <summary>
  34. /// Increment this position
  35. /// </summary>
  36. /// <param name="pos"></param>
  37. /// <returns></returns>
  38. public static LLamaPos operator ++(LLamaPos pos)
  39. {
  40. return new LLamaPos(pos.Value + 1);
  41. }
  42. /// <summary>
  43. /// Increment this position
  44. /// </summary>
  45. /// <param name="pos"></param>
  46. /// <returns></returns>
  47. public static LLamaPos operator --(LLamaPos pos)
  48. {
  49. return new LLamaPos(pos.Value - 1);
  50. }
  51. }