ExceptionSupportStack.h 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #include <stdint.h>
  3. namespace il2cpp
  4. {
  5. namespace utils
  6. {
  7. template<typename T, int Size>
  8. class ExceptionSupportStack
  9. {
  10. public:
  11. ExceptionSupportStack() : m_count(0)
  12. {
  13. }
  14. void push(T value)
  15. {
  16. // This function is rather unsafe. We don't track the size of storage,
  17. // and assume the caller will not push more values than it has allocated.
  18. // This function should only be used from generated code, where
  19. // we control the calls to this function.
  20. IL2CPP_ASSERT(m_count < Size);
  21. m_Storage[m_count] = value;
  22. m_count++;
  23. }
  24. #if HYBRIDCLR_UNITY_VERSION >= 20210331
  25. T pop()
  26. {
  27. IL2CPP_ASSERT(!empty());
  28. m_count--;
  29. return m_Storage[m_count];
  30. }
  31. #else
  32. void pop()
  33. {
  34. IL2CPP_ASSERT(!empty());
  35. m_count--;
  36. }
  37. #endif
  38. T top() const
  39. {
  40. IL2CPP_ASSERT(!empty());
  41. return m_Storage[m_count - 1];
  42. }
  43. bool empty() const
  44. {
  45. return m_count == 0;
  46. }
  47. private:
  48. T m_Storage[Size];
  49. int m_count;
  50. };
  51. }
  52. }