add TraceContext::IsSimilar
authorMathieu Lacage <mathieu.lacage@sophia.inria.fr>
Mon, 27 Aug 2007 20:45:49 +0200
changeset 1369 ca4667a61c57
parent 1368 e75dc1a2a5fb
child 1370 d5339e1c95df
add TraceContext::IsSimilar
src/core/trace-context.cc
src/core/trace-context.h
--- a/src/core/trace-context.cc	Mon Aug 27 20:25:15 2007 +0200
+++ b/src/core/trace-context.cc	Mon Aug 27 20:45:49 2007 +0200
@@ -256,6 +256,42 @@
   } while (true);
 }
 
+bool 
+TraceContext::IsSimilar (const TraceContext &o) const
+{
+  if (m_data == 0 && o.m_data == 0)
+    {
+      return true;
+    }
+  if ((m_data != 0 && o.m_data == 0) || 
+      (m_data == 0 && o.m_data != 0))
+    {
+      return false;
+    }
+  uint8_t myCurrentUid;
+  uint16_t myI = 0;
+  uint8_t otherCurrentUid;
+  uint16_t otherI = 0;
+  do {
+    myCurrentUid = m_data->data[myI];
+    otherCurrentUid = o.m_data->data[otherI];
+    uint8_t mySize = ElementRegistry::GetSize (myCurrentUid);
+    uint8_t otherSize = ElementRegistry::GetSize (otherCurrentUid);
+    myI += 1 + mySize;
+    otherI += 1 + otherSize;
+  } while (myCurrentUid == otherCurrentUid && 
+           myCurrentUid != 0 && 
+           otherCurrentUid != 0);
+  if (myCurrentUid == 0 && otherCurrentUid == 0)
+    {
+      return true;
+    }
+  else
+    {
+      return false;
+    }
+}
+
 std::ostream& operator<< (std::ostream& os, const TraceContext &context)
 {
   context.Print (os);
--- a/src/core/trace-context.h	Mon Aug 27 20:25:15 2007 +0200
+++ b/src/core/trace-context.h	Mon Aug 27 20:45:49 2007 +0200
@@ -81,6 +81,7 @@
 
   void Print (std::ostream &os) const;
   void PrintAvailable (std::ostream &os, std::string separator) const;
+  bool IsSimilar (const TraceContext &o) const;
 private:
   friend class TraceContextTest;
   // used exclusively for testing code.