ExceptionSupportStack.h 1.1 KB

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