ExceptionSupportStack.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. void pop()
  25. {
  26. IL2CPP_ASSERT(!empty());
  27. m_count--;
  28. }
  29. T top() const
  30. {
  31. IL2CPP_ASSERT(!empty());
  32. return m_Storage[m_count - 1];
  33. }
  34. bool empty() const
  35. {
  36. return m_count == 0;
  37. }
  38. private:
  39. T m_Storage[Size];
  40. int m_count;
  41. };
  42. }
  43. }