00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00036 #ifndef _depends_details_node_h
00037 #define _depends_details_node_h
00038
00039 namespace Depends
00040 {
00041 namespace Details
00042 {
00044 template <typename NodeType>
00045 struct ValueCompare
00046 {
00047 typedef typename NodeType::value_type value_type;
00048
00049 ValueCompare(const value_type & v) : val_(v) {}
00050
00051 bool operator()(const value_type & v) const { return val_ == v; }
00052 bool operator()(const NodeType & n) const { return n.value_ == val_; }
00053 bool operator()(const NodeType * n) const { return n->value_ == val_; }
00054
00055 value_type val_;
00056 };
00057
00058 template <typename NodeType>
00059 struct CompareNodesByContents
00060 {
00061 bool operator()(const NodeType & lhs, const NodeType & rhs)
00062 {
00063
00064 if (lhs < rhs)
00065 return true;
00066 else if (lhs.value_ < rhs.value_)
00067 return true;
00068 else
00069 return std::lexicographical_compare(
00070 boost::indirect_iterator< typename NodeType::targets_type::const_iterator >(lhs.targets_.begin()),
00071 boost::indirect_iterator< typename NodeType::targets_type::const_iterator >(lhs.targets_.end()),
00072 boost::indirect_iterator< typename NodeType::targets_type::const_iterator >(rhs.targets_.begin()),
00073 boost::indirect_iterator< typename NodeType::targets_type::const_iterator >(rhs.targets_.end()),
00074 *this);
00075 }
00076 };
00077
00079 template <class ValueType, typename ScoreType>
00080 struct Node
00081 {
00082 typedef ValueType value_type;
00083 typedef ScoreType score_type;
00084 typedef std::vector<Node*> targets_type;
00085
00086 enum Flag { VISITED = 1 };
00087
00088 Node(const ValueType & v)
00089 : value_(v),
00090 score_(1),
00091 flags_(0)
00092 {
00093 }
00094
00095 bool operator<(const Node & n) const
00096 {
00097 return score_ < n.score_;
00098 }
00099
00100 bool operator==(const Node & rhs) const
00101 {
00102 return
00103 (value_ == rhs.value_) &&
00104 (score_ == rhs.score_) &&
00105 targets_.size() == rhs.targets_.size() &&
00106 std::equal(
00107 boost::indirect_iterator< typename targets_type::const_iterator >(targets_.begin()),
00108 boost::indirect_iterator< typename targets_type::const_iterator >(targets_.end()),
00109 boost::indirect_iterator< typename targets_type::const_iterator >(rhs.targets_.begin())
00110 );
00111 }
00112
00113 targets_type targets_;
00114 ValueType value_;
00115 ScoreType score_;
00116 unsigned int flags_;
00117
00118 private :
00119 Node()
00120 : score_(0),
00121 flags_(0)
00122 { }
00123
00124 #if DEPENDS_SUPPORT_SERIALIZATION
00125 template < typename Archive >
00126 void serialize( Archive & ar, const unsigned int version )
00127 {
00128 ar & boost::serialization::make_nvp("targets_", targets_)
00129 & boost::serialization::make_nvp("value_", value_)
00130 & boost::serialization::make_nvp("score_", score_)
00131 & boost::serialization::make_nvp("flags_", flags_)
00132 ;
00133 }
00134
00135 friend class boost::serialization::access;
00136 #endif
00137 };
00138 }
00139 }
00140
00141 #endif
00142