Update mussa to build on ubuntu 10.04 with qt 4.6.2 +boost 1.40.0.1
[mussa.git] / alg / conserved_path.cpp
index c67b4540d986b53940f52550c3e3a1c30c695ec5..1edb374065c2027d3cf1a4e37dec80b17ebea9c6 100644 (file)
@@ -1,5 +1,5 @@
 #include "alg/conserved_path.hpp"
-#include <stdexcept>
+#include "mussa_exceptions.hpp"
 
 using namespace std;
 
@@ -54,6 +54,32 @@ bool operator!=(const ConservedPath::ConservedPath& a,
   return not (a == b);
 }
 
+bool operator<(const ConservedPath& a, const ConservedPath &b)
+{
+  ConservedPath::const_iterator a_i = a.begin();
+  ConservedPath::const_iterator b_i = b.begin();
+  for(; a_i != a.end() and b_i != b.end(); ++a_i, ++b_i)
+  {
+    if (*a_i < *b_i) {
+      return true;
+    } else if (*a_i > *b_i) {
+      return false;
+    }
+    // else they're equal and we continue to loop
+  }
+  // now handle mismatched lengths
+  if (a_i == a.end() and b_i == b.end()) {
+    return false; // since the two paths are equal
+  } else if (a_i == a.end()) {
+    return true; // a is shorter than b
+  } else if (b_i == b.end()) {
+    return false; // b is shorter than a
+  } else {
+    // something went horribly wrong
+    throw std::runtime_error("ConservedPath operator< had a fatal logic error");
+  }
+}
+
 std::ostream& operator<<(std::ostream& out, const ConservedPath& path)
 {
   out << "<path win_size" << path.window_size 
@@ -119,7 +145,7 @@ ConservedPath::const_iterator ConservedPath::end() const
 bool ConservedPath::nextTo(const ConservedPath& next) const
 {
   if (size() != next.size() ) {
-    throw runtime_error("paths must be the same length");
+    throw conserved_path_size_mismatch("paths must be the same length");
   }    
   ConservedPath::const_iterator this_itor = begin();
   ConservedPath::const_iterator next_itor = next.begin();