1.1 --- a/lemon/bits/traits.h Tue Apr 04 17:45:35 2006 +0000
1.2 +++ b/lemon/bits/traits.h Thu Apr 06 09:33:29 2006 +0000
1.3 @@ -239,6 +239,36 @@
1.4 typedef typename Map::Reference Reference;
1.5 };
1.6
1.7 + template <typename MatrixMap, typename Enable = void>
1.8 + struct MatrixMapTraits {
1.9 + typedef False ReferenceMapTag;
1.10 +
1.11 + typedef typename MatrixMap::FirstKey FirstKey;
1.12 + typedef typename MatrixMap::SecondKey SecondKey;
1.13 + typedef typename MatrixMap::Value Value;
1.14 +
1.15 + typedef const Value ConstReturnValue;
1.16 + typedef const Value ReturnValue;
1.17 + };
1.18 +
1.19 + template <typename MatrixMap>
1.20 + struct MatrixMapTraits<
1.21 + MatrixMap, typename enable_if<typename MatrixMap::ReferenceMapTag,
1.22 + void>::type >
1.23 + {
1.24 + typedef True ReferenceMapTag;
1.25 +
1.26 + typedef typename MatrixMap::FirstKey FirstKey;
1.27 + typedef typename MatrixMap::SecondKey SecondKey;
1.28 + typedef typename MatrixMap::Value Value;
1.29 +
1.30 + typedef typename MatrixMap::ConstReference ConstReturnValue;
1.31 + typedef typename MatrixMap::Reference ReturnValue;
1.32 +
1.33 + typedef typename MatrixMap::ConstReference ConstReference;
1.34 + typedef typename MatrixMap::Reference Reference;
1.35 + };
1.36 +
1.37 // Indicators for the tags
1.38
1.39 template <typename Graph, typename Enable = void>
2.1 Binary file lemon/matrix_maps.h has changed
3.1 --- a/test/matrix_maps_test.cc Tue Apr 04 17:45:35 2006 +0000
3.2 +++ b/test/matrix_maps_test.cc Thu Apr 06 09:33:29 2006 +0000
3.3 @@ -40,6 +40,7 @@
3.4 int main() {
3.5 typedef SmartGraph Graph;
3.6 typedef Graph::Node Node;
3.7 + typedef Graph::Edge Edge;
3.8
3.9 { // checking MatrixMap for int
3.10 typedef DynamicMatrixMap<Graph, Node, int> IntMatrixMap;
3.11 @@ -124,6 +125,95 @@
3.12 }
3.13 }
3.14
3.15 + { // checking MatrixMap for int
3.16 + typedef DynamicAsymMatrixMap<Graph, Node, Graph, Edge, int> IntMatrixMap;
3.17 + checkConcept<ReferenceMatrixMap<Node, Edge, int,
3.18 + IntMatrixMap::Reference, IntMatrixMap::ConstReference>,
3.19 + IntMatrixMap>();
3.20 +
3.21 + }
3.22 +
3.23 + { // checking MatrixMap for bool
3.24 + typedef DynamicAsymMatrixMap<Graph, Node, Graph, Edge, bool> BoolMatrixMap;
3.25 + checkConcept<ReferenceMatrixMap<Node, Edge, bool,
3.26 + BoolMatrixMap::Reference, BoolMatrixMap::ConstReference>,
3.27 + BoolMatrixMap>();
3.28 +
3.29 + }
3.30 +
3.31 + {
3.32 + Graph graph1, graph2;
3.33 + typedef DynamicAsymMatrixMap<Graph, Node, Graph, Edge, int> IntMatrixMap;
3.34 + IntMatrixMap matrix(graph1, graph2);
3.35 + for (int i = 0; i < 10; ++i) {
3.36 + graph1.addNode();
3.37 + }
3.38 + graph2.addNode();
3.39 + for (int i = 0; i < 20; ++i) {
3.40 + graph2.addEdge(Graph::NodeIt(graph2), Graph::NodeIt(graph2));
3.41 + }
3.42 + for (Graph::NodeIt it(graph1); it != INVALID; ++it) {
3.43 + for (Graph::EdgeIt jt(graph2); jt != INVALID; ++jt) {
3.44 + int val = urandom(100);
3.45 + matrix.set(it, jt, val);
3.46 + check(matrix(it, jt) == val, "Wrong assign");
3.47 + check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap");
3.48 + check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap");
3.49 + }
3.50 + }
3.51 + const IntMatrixMap& cm = matrix;
3.52 + for (Graph::NodeIt it(graph1); it != INVALID; ++it) {
3.53 + for (Graph::EdgeIt jt(graph2); jt != INVALID; ++jt) {
3.54 + check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap");
3.55 + check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap");
3.56 + }
3.57 + }
3.58 + }
3.59 +
3.60 + { // checking MatrixMap for int
3.61 + typedef DynamicAsymMatrixMap<Graph, Node, Graph, Node, int> IntMatrixMap;
3.62 + checkConcept<ReferenceMatrixMap<Node, Node, int,
3.63 + IntMatrixMap::Reference, IntMatrixMap::ConstReference>,
3.64 + IntMatrixMap>();
3.65 +
3.66 + }
3.67 +
3.68 + { // checking MatrixMap for bool
3.69 + typedef DynamicAsymMatrixMap<Graph, Node, Graph, Node, bool> BoolMatrixMap;
3.70 + checkConcept<ReferenceMatrixMap<Node, Node, bool,
3.71 + BoolMatrixMap::Reference, BoolMatrixMap::ConstReference>,
3.72 + BoolMatrixMap>();
3.73 +
3.74 + }
3.75 +
3.76 + {
3.77 + Graph graph;
3.78 + typedef DynamicAsymMatrixMap<Graph, Node, Graph, Node, int> IntMatrixMap;
3.79 + IntMatrixMap matrix(graph, graph);
3.80 + for (int i = 0; i < 10; ++i) {
3.81 + graph.addNode();
3.82 + }
3.83 + for (int i = 0; i < 20; ++i) {
3.84 + graph.addEdge(Graph::NodeIt(graph), Graph::NodeIt(graph));
3.85 + }
3.86 + for (Graph::NodeIt it(graph); it != INVALID; ++it) {
3.87 + for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
3.88 + int val = urandom(100);
3.89 + matrix.set(it, jt, val);
3.90 + check(matrix(it, jt) == val, "Wrong assign");
3.91 + check(matrix(it, jt) == matrixRowMap(matrix, it)[jt], "Wrong rowMap");
3.92 + check(matrix(it, jt) == matrixColMap(matrix, jt)[it], "Wrong colMap");
3.93 + }
3.94 + }
3.95 + const IntMatrixMap& cm = matrix;
3.96 + for (Graph::NodeIt it(graph); it != INVALID; ++it) {
3.97 + for (Graph::NodeIt jt(graph); jt != INVALID; ++jt) {
3.98 + check(cm(it, jt) == matrixRowMap(cm, it)[jt], "Wrong rowMap");
3.99 + check(cm(it, jt) == matrixColMap(cm, jt)[it], "Wrong colMap");
3.100 + }
3.101 + }
3.102 + }
3.103 +
3.104 std::cout << __FILE__ ": All tests passed.\n";
3.105
3.106 return 0;