diff options
author | Brad King <brad.king@kitware.com> | 2022-03-30 20:35:23 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2022-04-02 09:55:31 (GMT) |
commit | 11cc728e75d2c215abdb2e402aa50f415060fef3 (patch) | |
tree | e28ef8c26c79fd7eb4fc42e7d0e6990beb952f0b /Source/cmListFileCache.h | |
parent | 912319375823ddd2b8ccf4f5e344cafeca73eb29 (diff) | |
download | CMake-11cc728e75d2c215abdb2e402aa50f415060fef3.zip CMake-11cc728e75d2c215abdb2e402aa50f415060fef3.tar.gz CMake-11cc728e75d2c215abdb2e402aa50f415060fef3.tar.bz2 |
cmConstStack: Factor out of cmListFileBacktrace
This presents value semantics for a stack of constant values.
Internally it shares ownership to avoid copies. Previously
this was implemented by `cmListFileBacktrace` explicitly,
but the approach can be re-used for other kinds of stacks.
Diffstat (limited to 'Source/cmListFileCache.h')
-rw-r--r-- | Source/cmListFileCache.h | 34 |
1 files changed, 8 insertions, 26 deletions
diff --git a/Source/cmListFileCache.h b/Source/cmListFileCache.h index 7c19f24..f7c2509 100644 --- a/Source/cmListFileCache.h +++ b/Source/cmListFileCache.h @@ -12,6 +12,7 @@ #include <cm/optional> +#include "cmConstStack.h" #include "cmSystemTools.h" /** \class cmListFileCache @@ -157,35 +158,16 @@ bool operator<(const cmListFileContext& lhs, const cmListFileContext& rhs); bool operator==(cmListFileContext const& lhs, cmListFileContext const& rhs); bool operator!=(cmListFileContext const& lhs, cmListFileContext const& rhs); -// Represent a backtrace (call stack). Provide value semantics -// but use efficient reference-counting underneath to avoid copies. +// Represent a backtrace (call stack) with efficient value semantics. class cmListFileBacktrace + : public cmConstStack<cmListFileContext, cmListFileBacktrace> { -public: - // Default-constructed backtrace is empty. - cmListFileBacktrace() = default; - - // Get a backtrace with the given call context added to the top. - cmListFileBacktrace Push(cmListFileContext const& lfc) const; - - // Get a backtrace with the top level removed. - // May not be called until after a matching Push. - cmListFileBacktrace Pop() const; - - // Get the context at the top of the backtrace. - // This may be called only if Empty() would return false. - cmListFileContext const& Top() const; - - // Return true if this backtrace is empty. - bool Empty() const; - -private: - struct Entry; - std::shared_ptr<Entry const> TopEntry; - cmListFileBacktrace(std::shared_ptr<Entry const> parent, - cmListFileContext const& lfc); - cmListFileBacktrace(std::shared_ptr<Entry const> top); + using cmConstStack::cmConstStack; + friend class cmConstStack<cmListFileContext, cmListFileBacktrace>; }; +#ifndef cmListFileCache_cxx +extern template class cmConstStack<cmListFileContext, cmListFileBacktrace>; +#endif // Wrap type T as a value with a backtrace. For purposes of // ordering and equality comparison, only the original value is |