resolve cyclic dependency with zstd
[platform/upstream/cmake.git] / Source / cmConstStack.h
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
5 #include "cmConfigure.h" // IWYU pragma: keep
6
7 #include <memory>
8
9 /** Base class template for CRTP to represent a stack of constant values.
10     Provide value semantics, but use efficient reference-counting underneath
11     to avoid copies.  */
12 template <typename T, typename Stack>
13 class cmConstStack
14 {
15   struct Entry;
16   std::shared_ptr<Entry const> TopEntry;
17
18 public:
19   /** Default-construct an empty stack.  */
20   cmConstStack();
21
22   /** Get a stack with the given call context added to the top.  */
23   Stack Push(T value) const;
24
25   /** Get a stack with the top level removed.
26       May not be called until after a matching Push.  */
27   Stack Pop() const;
28
29   /** Get the value at the top of the stack.
30       This may be called only if Empty() would return false.  */
31   T const& Top() const;
32
33   /** Return true if this stack is empty.  */
34   bool Empty() const;
35
36 protected:
37   cmConstStack(std::shared_ptr<Entry const> parent, T value);
38   cmConstStack(std::shared_ptr<Entry const> top);
39 };