1
0

cmConstStack.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. /* Distributed under the OSI-approved BSD 3-Clause License. See accompanying
  2. file Copyright.txt or https://cmake.org/licensing for details. */
  3. #pragma once
  4. #include "cmConfigure.h" // IWYU pragma: keep
  5. #include <memory>
  6. /** Base class template for CRTP to represent a stack of constant values.
  7. Provide value semantics, but use efficient reference-counting underneath
  8. to avoid copies. */
  9. template <typename T, typename Stack>
  10. class cmConstStack
  11. {
  12. struct Entry;
  13. std::shared_ptr<Entry const> TopEntry;
  14. public:
  15. /** Default-construct an empty stack. */
  16. cmConstStack();
  17. /** Get a stack with the given call context added to the top. */
  18. Stack Push(T value) const;
  19. /** Get a stack with the top level removed.
  20. May not be called until after a matching Push. */
  21. Stack Pop() const;
  22. /** Get the value at the top of the stack.
  23. This may be called only if Empty() would return false. */
  24. T const& Top() const;
  25. /** Return true if this stack is empty. */
  26. bool Empty() const;
  27. protected:
  28. cmConstStack(std::shared_ptr<Entry const> parent, T value);
  29. cmConstStack(std::shared_ptr<Entry const> top);
  30. };