00001 #ifndef wali_nwa_CONFIGURATION_HPP 00002 #define wali_nwa_CONFIGURATION_HPP 00003 00004 #include "opennwa/NwaFwd.hpp" 00005 00006 #include <ios> 00007 #include <vector> 00008 00009 namespace opennwa 00010 { 00011 namespace details 00012 { 00013 00014 struct Configuration { 00015 State state; 00016 std::vector<State> callPredecessors; 00017 00018 Configuration(State s) : state(s) {} 00019 Configuration(Configuration const & c) 00020 : state(c.state) 00021 , callPredecessors(c.callPredecessors) {} 00022 00023 bool operator< (Configuration const & other) const { 00024 if (state < other.state) return true; 00025 if (state > other.state) return false; 00026 if (callPredecessors.size() < other.callPredecessors.size()) return true; 00027 if (callPredecessors.size() > other.callPredecessors.size()) return false; 00028 00029 // Iterate in parallel over the two callPredecessors 00030 for (std::vector<State>::const_iterator i = callPredecessors.begin(), j = other.callPredecessors.begin(); 00031 i!=callPredecessors.end(); ++i, ++j) 00032 { 00033 assert (j!=other.callPredecessors.end()); 00034 if (*i < *j) return true; 00035 if (*i > *j) return false; 00036 } 00037 00038 return false; 00039 } 00040 00041 bool operator== (Configuration const & other) const { 00042 // If neither A < B nor B < A, then A == B 00043 return !(*this < other || other < *this); 00044 } 00045 }; 00046 00047 00048 inline 00049 std::ostream & 00050 operator << (std::ostream & os, Configuration const & configuration) 00051 { 00052 os << wali::key2str(configuration.state) << " ["; 00053 for (size_t i=0; i<configuration.callPredecessors.size(); ++i) { 00054 os << wali::key2str(configuration.callPredecessors[i]) << " "; 00055 } 00056 os << "]"; 00057 return os; 00058 } 00059 00060 } 00061 } 00062 00063 #endif