Browse Source

cmListFileCache: Add wrapper template for values with a backtrace

Brad King 7 years ago
parent
commit
f1dd0eeaaf
2 changed files with 35 additions and 1 deletions
  1. 6 1
      Source/cmListFileCache.cxx
  2. 29 0
      Source/cmListFileCache.h

+ 6 - 1
Source/cmListFileCache.cxx

@@ -9,10 +9,10 @@
 #include "cmSystemTools.h"
 #include "cmSystemTools.h"
 #include "cmake.h"
 #include "cmake.h"
 
 
-#include <algorithm>
 #include <assert.h>
 #include <assert.h>
 #include <memory>
 #include <memory>
 #include <sstream>
 #include <sstream>
+#include <utility>
 
 
 cmCommandContext::cmCommandName& cmCommandContext::cmCommandName::operator=(
 cmCommandContext::cmCommandName& cmCommandContext::cmCommandName::operator=(
   std::string const& name)
   std::string const& name)
@@ -474,3 +474,8 @@ bool operator!=(const cmListFileContext& lhs, const cmListFileContext& rhs)
 {
 {
   return !(lhs == rhs);
   return !(lhs == rhs);
 }
 }
+
+std::ostream& operator<<(std::ostream& os, BT<std::string> const& s)
+{
+  return os << s.Value;
+}

+ 29 - 0
Source/cmListFileCache.h

@@ -9,6 +9,7 @@
 #include <memory> // IWYU pragma: keep
 #include <memory> // IWYU pragma: keep
 #include <stddef.h>
 #include <stddef.h>
 #include <string>
 #include <string>
+#include <utility>
 #include <vector>
 #include <vector>
 
 
 #include "cmStateSnapshot.h"
 #include "cmStateSnapshot.h"
@@ -169,6 +170,34 @@ private:
   cmListFileBacktrace(std::shared_ptr<Entry const> top);
   cmListFileBacktrace(std::shared_ptr<Entry const> top);
 };
 };
 
 
+// Wrap type T as a value with a backtrace.  For purposes of
+// ordering and equality comparison, only the original value is
+// used.  The backtrace is considered incidental.
+template <typename T>
+class BT
+{
+public:
+  BT(T v = T(), cmListFileBacktrace bt = cmListFileBacktrace())
+    : Value(std::move(v))
+    , Backtrace(std::move(bt))
+  {
+  }
+  T Value;
+  cmListFileBacktrace Backtrace;
+  friend bool operator==(BT<T> const& l, BT<T> const& r)
+  {
+    return l.Value == r.Value;
+  }
+  friend bool operator<(BT<T> const& l, BT<T> const& r)
+  {
+    return l.Value < r.Value;
+  }
+  friend bool operator==(BT<T> const& l, T const& r) { return l.Value == r; }
+  friend bool operator==(T const& l, BT<T> const& r) { return l == r.Value; }
+};
+
+std::ostream& operator<<(std::ostream& os, BT<std::string> const& s);
+
 struct cmListFile
 struct cmListFile
 {
 {
   bool ParseFile(const char* path, cmMessenger* messenger,
   bool ParseFile(const char* path, cmMessenger* messenger,