Changeset 1030:4936be66d2f5 in lemon-main
- Timestamp:
- 02/12/13 07:15:52 (12 years ago)
- Branch:
- default
- Phase:
- public
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
lemon/lgf_reader.h
r1029 r1030 155 155 }; 156 156 157 template <typename Value> 157 template <typename Value, 158 typename Map = std::map<std::string, Value> > 158 159 struct MapLookUpConverter { 159 const std::map<std::string, Value>& _map;160 161 MapLookUpConverter(const std::map<std::string, Value>& map)160 const Map& _map; 161 162 MapLookUpConverter(const Map& map) 162 163 : _map(map) {} 163 164 164 165 Value operator()(const std::string& str) { 165 typename std::map<std::string, Value>::const_iterator it = 166 _map.find(str); 166 typename Map::const_iterator it = _map.find(str); 167 167 if (it == _map.end()) { 168 168 std::ostringstream msg; … … 171 171 } 172 172 return it->second; 173 } 174 }; 175 176 template <typename Value, 177 typename Map1 = std::map<std::string, Value>, 178 typename Map2 = std::map<std::string, Value> > 179 struct DoubleMapLookUpConverter { 180 const Map1& _map1; 181 const Map2& _map2; 182 183 DoubleMapLookUpConverter(const Map1& map1, const Map2& map2) 184 : _map1(map1), _map2(map2) {} 185 186 Value operator()(const std::string& str) { 187 typename Map1::const_iterator it1 = _map1.find(str); 188 typename Map2::const_iterator it2 = _map2.find(str); 189 if (it1 == _map1.end()) { 190 if (it2 == _map2.end()) { 191 std::ostringstream msg; 192 msg << "Item not found: " << str; 193 throw FormatError(msg.str()); 194 } else { 195 return it2->second; 196 } 197 } else { 198 if (it2 == _map2.end()) { 199 return it1->second; 200 } else { 201 std::ostringstream msg; 202 msg << "Item is ambigous: " << str; 203 throw FormatError(msg.str()); 204 } 205 } 173 206 } 174 207 }; … … 2172 2205 std::string _attributes_caption; 2173 2206 2174 typedef std::map<std::string, Node> NodeIndex; 2175 NodeIndex _node_index; 2207 typedef std::map<std::string, RedNode> RedNodeIndex; 2208 RedNodeIndex _red_node_index; 2209 typedef std::map<std::string, BlueNode> BlueNodeIndex; 2210 BlueNodeIndex _blue_node_index; 2176 2211 typedef std::map<std::string, Edge> EdgeIndex; 2177 2212 EdgeIndex _edge_index; 2178 2213 2179 2214 typedef std::vector<std::pair<std::string, 2180 _reader_bits::MapStorageBase<Node>*> > NodeMaps; 2181 NodeMaps _red_maps; 2182 NodeMaps _blue_maps; 2215 _reader_bits::MapStorageBase<RedNode>*> > RedNodeMaps; 2216 RedNodeMaps _red_node_maps; 2217 typedef std::vector<std::pair<std::string, 2218 _reader_bits::MapStorageBase<BlueNode>*> > BlueNodeMaps; 2219 BlueNodeMaps _blue_node_maps; 2183 2220 2184 2221 typedef std::vector<std::pair<std::string, … … 2242 2279 /// \brief Destructor 2243 2280 ~BpGraphReader() { 2244 for (typename NodeMaps::iterator it = _red_maps.begin();2245 it != _red_ maps.end(); ++it) {2281 for (typename RedNodeMaps::iterator it = _red_node_maps.begin(); 2282 it != _red_node_maps.end(); ++it) { 2246 2283 delete it->second; 2247 2284 } 2248 2285 2249 for (typename NodeMaps::iterator it = _blue_maps.begin();2250 it != _blue_ maps.end(); ++it) {2286 for (typename BlueNodeMaps::iterator it = _blue_node_maps.begin(); 2287 it != _blue_node_maps.end(); ++it) { 2251 2288 delete it->second; 2252 2289 } … … 2285 2322 other.local_is = false; 2286 2323 2287 _node_index.swap(other._node_index); 2324 _red_node_index.swap(other._red_node_index); 2325 _blue_node_index.swap(other._blue_node_index); 2288 2326 _edge_index.swap(other._edge_index); 2289 2327 2290 _red_ maps.swap(other._red_maps);2291 _blue_ maps.swap(other._blue_maps);2328 _red_node_maps.swap(other._red_node_maps); 2329 _blue_node_maps.swap(other._blue_node_maps); 2292 2330 _edge_maps.swap(other._edge_maps); 2293 2331 _attributes.swap(other._attributes); … … 2312 2350 BpGraphReader& nodeMap(const std::string& caption, Map& map) { 2313 2351 checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>(); 2314 _reader_bits::MapStorageBase< Node>* red_storage =2315 new _reader_bits::MapStorage< Node, Map>(map);2316 _red_ maps.push_back(std::make_pair(caption, red_storage));2317 _reader_bits::MapStorageBase< Node>* blue_storage =2318 new _reader_bits::MapStorage< Node, Map>(map);2319 _blue_ maps.push_back(std::make_pair(caption, blue_storage));2352 _reader_bits::MapStorageBase<RedNode>* red_storage = 2353 new _reader_bits::MapStorage<RedNode, Map>(map); 2354 _red_node_maps.push_back(std::make_pair(caption, red_storage)); 2355 _reader_bits::MapStorageBase<BlueNode>* blue_storage = 2356 new _reader_bits::MapStorage<BlueNode, Map>(map); 2357 _blue_node_maps.push_back(std::make_pair(caption, blue_storage)); 2320 2358 return *this; 2321 2359 } … … 2329 2367 const Converter& converter = Converter()) { 2330 2368 checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>(); 2331 _reader_bits::MapStorageBase< Node>* red_storage =2332 new _reader_bits::MapStorage< Node, Map, Converter>(map, converter);2333 _red_ maps.push_back(std::make_pair(caption, red_storage));2334 _reader_bits::MapStorageBase< Node>* blue_storage =2335 new _reader_bits::MapStorage< Node, Map, Converter>(map, converter);2336 _blue_ maps.push_back(std::make_pair(caption, blue_storage));2369 _reader_bits::MapStorageBase<RedNode>* red_storage = 2370 new _reader_bits::MapStorage<RedNode, Map, Converter>(map, converter); 2371 _red_node_maps.push_back(std::make_pair(caption, red_storage)); 2372 _reader_bits::MapStorageBase<BlueNode>* blue_storage = 2373 new _reader_bits::MapStorage<BlueNode, Map, Converter>(map, converter); 2374 _blue_node_maps.push_back(std::make_pair(caption, blue_storage)); 2337 2375 return *this; 2338 2376 } … … 2341 2379 template <typename Map> 2342 2380 BpGraphReader& redNodeMap(const std::string& caption, Map& map) { 2343 checkConcept<concepts::WriteMap< Node, typename Map::Value>, Map>();2344 _reader_bits::MapStorageBase< Node>* storage =2345 new _reader_bits::MapStorage< Node, Map>(map);2346 _red_ maps.push_back(std::make_pair(caption, storage));2381 checkConcept<concepts::WriteMap<RedNode, typename Map::Value>, Map>(); 2382 _reader_bits::MapStorageBase<RedNode>* storage = 2383 new _reader_bits::MapStorage<RedNode, Map>(map); 2384 _red_node_maps.push_back(std::make_pair(caption, storage)); 2347 2385 return *this; 2348 2386 } … … 2355 2393 BpGraphReader& redNodeMap(const std::string& caption, Map& map, 2356 2394 const Converter& converter = Converter()) { 2357 checkConcept<concepts::WriteMap< Node, typename Map::Value>, Map>();2358 _reader_bits::MapStorageBase< Node>* storage =2359 new _reader_bits::MapStorage< Node, Map, Converter>(map, converter);2360 _red_ maps.push_back(std::make_pair(caption, storage));2395 checkConcept<concepts::WriteMap<RedNode, typename Map::Value>, Map>(); 2396 _reader_bits::MapStorageBase<RedNode>* storage = 2397 new _reader_bits::MapStorage<RedNode, Map, Converter>(map, converter); 2398 _red_node_maps.push_back(std::make_pair(caption, storage)); 2361 2399 return *this; 2362 2400 } … … 2365 2403 template <typename Map> 2366 2404 BpGraphReader& blueNodeMap(const std::string& caption, Map& map) { 2367 checkConcept<concepts::WriteMap< Node, typename Map::Value>, Map>();2368 _reader_bits::MapStorageBase< Node>* storage =2369 new _reader_bits::MapStorage< Node, Map>(map);2370 _blue_ maps.push_back(std::make_pair(caption, storage));2405 checkConcept<concepts::WriteMap<BlueNode, typename Map::Value>, Map>(); 2406 _reader_bits::MapStorageBase<BlueNode>* storage = 2407 new _reader_bits::MapStorage<BlueNode, Map>(map); 2408 _blue_node_maps.push_back(std::make_pair(caption, storage)); 2371 2409 return *this; 2372 2410 } … … 2379 2417 BpGraphReader& blueNodeMap(const std::string& caption, Map& map, 2380 2418 const Converter& converter = Converter()) { 2381 checkConcept<concepts::WriteMap< Node, typename Map::Value>, Map>();2382 _reader_bits::MapStorageBase< Node>* storage =2383 new _reader_bits::MapStorage< Node, Map, Converter>(map, converter);2384 _blue_ maps.push_back(std::make_pair(caption, storage));2419 checkConcept<concepts::WriteMap<BlueNode, typename Map::Value>, Map>(); 2420 _reader_bits::MapStorageBase<BlueNode>* storage = 2421 new _reader_bits::MapStorage<BlueNode, Map, Converter>(map, converter); 2422 _blue_node_maps.push_back(std::make_pair(caption, storage)); 2385 2423 return *this; 2386 2424 } … … 2474 2512 /// Add a node reading rule to reader. 2475 2513 BpGraphReader& node(const std::string& caption, Node& node) { 2476 typedef _reader_bits::MapLookUpConverter<Node> Converter; 2477 Converter converter(_node_index); 2514 typedef _reader_bits::DoubleMapLookUpConverter< 2515 Node, RedNodeIndex, BlueNodeIndex> Converter; 2516 Converter converter(_red_node_index, _blue_node_index); 2478 2517 _reader_bits::ValueStorageBase* storage = 2479 2518 new _reader_bits::ValueStorage<Node, Converter>(node, converter); 2519 _attributes.insert(std::make_pair(caption, storage)); 2520 return *this; 2521 } 2522 2523 /// \brief Red node reading rule 2524 /// 2525 /// Add a red node reading rule to reader. 2526 BpGraphReader& redNode(const std::string& caption, RedNode& node) { 2527 typedef _reader_bits::MapLookUpConverter<RedNode> Converter; 2528 Converter converter(_red_node_index); 2529 _reader_bits::ValueStorageBase* storage = 2530 new _reader_bits::ValueStorage<RedNode, Converter>(node, converter); 2531 _attributes.insert(std::make_pair(caption, storage)); 2532 return *this; 2533 } 2534 2535 /// \brief Blue node reading rule 2536 /// 2537 /// Add a blue node reading rule to reader. 2538 BpGraphReader& blueNode(const std::string& caption, BlueNode& node) { 2539 typedef _reader_bits::MapLookUpConverter<BlueNode> Converter; 2540 Converter converter(_blue_node_index); 2541 _reader_bits::ValueStorageBase* storage = 2542 new _reader_bits::ValueStorage<BlueNode, Converter>(node, converter); 2480 2543 _attributes.insert(std::make_pair(caption, storage)); 2481 2544 return *this; … … 2550 2613 _use_nodes = true; 2551 2614 _writer_bits::DefaultConverter<typename Map::Value> converter; 2552 for (NodeIt n(_graph); n != INVALID; ++n) { 2553 _node_index.insert(std::make_pair(converter(map[n]), n)); 2615 for (RedNodeIt n(_graph); n != INVALID; ++n) { 2616 _red_node_index.insert(std::make_pair(converter(map[n]), n)); 2617 } 2618 for (BlueNodeIt n(_graph); n != INVALID; ++n) { 2619 _blue_node_index.insert(std::make_pair(converter(map[n]), n)); 2554 2620 } 2555 2621 return *this; … … 2567 2633 LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); 2568 2634 _use_nodes = true; 2569 for (NodeIt n(_graph); n != INVALID; ++n) { 2570 _node_index.insert(std::make_pair(converter(map[n]), n)); 2635 for (RedNodeIt n(_graph); n != INVALID; ++n) { 2636 _red_node_index.insert(std::make_pair(converter(map[n]), n)); 2637 } 2638 for (BlueNodeIt n(_graph); n != INVALID; ++n) { 2639 _blue_node_index.insert(std::make_pair(converter(map[n]), n)); 2571 2640 } 2572 2641 return *this; … … 2665 2734 void readRedNodes() { 2666 2735 2667 std::vector<int> map_index(_red_ maps.size());2736 std::vector<int> map_index(_red_node_maps.size()); 2668 2737 int map_num, label_index; 2669 2738 … … 2671 2740 if (!readLine() || !(line >> c) || c == '@') { 2672 2741 if (readSuccess() && line) line.putback(c); 2673 if (!_red_ maps.empty())2742 if (!_red_node_maps.empty()) 2674 2743 throw FormatError("Cannot find map names"); 2675 2744 return; … … 2692 2761 } 2693 2762 2694 for (int i = 0; i < static_cast<int>(_red_ maps.size()); ++i) {2763 for (int i = 0; i < static_cast<int>(_red_node_maps.size()); ++i) { 2695 2764 std::map<std::string, int>::iterator jt = 2696 maps.find(_red_ maps[i].first);2765 maps.find(_red_node_maps[i].first); 2697 2766 if (jt == maps.end()) { 2698 2767 std::ostringstream msg; 2699 msg << "Map not found: " << _red_ maps[i].first;2768 msg << "Map not found: " << _red_node_maps[i].first; 2700 2769 throw FormatError(msg.str()); 2701 2770 } … … 2728 2797 throw FormatError("Extra character at the end of line"); 2729 2798 2730 Node n;2799 RedNode n; 2731 2800 if (!_use_nodes) { 2732 2801 n = _graph.addRedNode(); 2733 2802 if (label_index != -1) 2734 _ node_index.insert(std::make_pair(tokens[label_index], n));2803 _red_node_index.insert(std::make_pair(tokens[label_index], n)); 2735 2804 } else { 2736 2805 if (label_index == -1) 2737 2806 throw FormatError("Label map not found"); 2738 typename std::map<std::string, Node>::iterator it =2739 _ node_index.find(tokens[label_index]);2740 if (it == _ node_index.end()) {2807 typename std::map<std::string, RedNode>::iterator it = 2808 _red_node_index.find(tokens[label_index]); 2809 if (it == _red_node_index.end()) { 2741 2810 std::ostringstream msg; 2742 2811 msg << "Node with label not found: " << tokens[label_index]; … … 2746 2815 } 2747 2816 2748 for (int i = 0; i < static_cast<int>(_red_ maps.size()); ++i) {2749 _red_ maps[i].second->set(n, tokens[map_index[i]]);2817 for (int i = 0; i < static_cast<int>(_red_node_maps.size()); ++i) { 2818 _red_node_maps[i].second->set(n, tokens[map_index[i]]); 2750 2819 } 2751 2820 … … 2758 2827 void readBlueNodes() { 2759 2828 2760 std::vector<int> map_index(_blue_ maps.size());2829 std::vector<int> map_index(_blue_node_maps.size()); 2761 2830 int map_num, label_index; 2762 2831 … … 2764 2833 if (!readLine() || !(line >> c) || c == '@') { 2765 2834 if (readSuccess() && line) line.putback(c); 2766 if (!_blue_ maps.empty())2835 if (!_blue_node_maps.empty()) 2767 2836 throw FormatError("Cannot find map names"); 2768 2837 return; … … 2785 2854 } 2786 2855 2787 for (int i = 0; i < static_cast<int>(_blue_ maps.size()); ++i) {2856 for (int i = 0; i < static_cast<int>(_blue_node_maps.size()); ++i) { 2788 2857 std::map<std::string, int>::iterator jt = 2789 maps.find(_blue_ maps[i].first);2858 maps.find(_blue_node_maps[i].first); 2790 2859 if (jt == maps.end()) { 2791 2860 std::ostringstream msg; 2792 msg << "Map not found: " << _blue_ maps[i].first;2861 msg << "Map not found: " << _blue_node_maps[i].first; 2793 2862 throw FormatError(msg.str()); 2794 2863 } … … 2821 2890 throw FormatError("Extra character at the end of line"); 2822 2891 2823 Node n;2892 BlueNode n; 2824 2893 if (!_use_nodes) { 2825 2894 n = _graph.addBlueNode(); 2826 2895 if (label_index != -1) 2827 _ node_index.insert(std::make_pair(tokens[label_index], n));2896 _blue_node_index.insert(std::make_pair(tokens[label_index], n)); 2828 2897 } else { 2829 2898 if (label_index == -1) 2830 2899 throw FormatError("Label map not found"); 2831 typename std::map<std::string, Node>::iterator it =2832 _ node_index.find(tokens[label_index]);2833 if (it == _ node_index.end()) {2900 typename std::map<std::string, BlueNode>::iterator it = 2901 _blue_node_index.find(tokens[label_index]); 2902 if (it == _blue_node_index.end()) { 2834 2903 std::ostringstream msg; 2835 2904 msg << "Node with label not found: " << tokens[label_index]; … … 2839 2908 } 2840 2909 2841 for (int i = 0; i < static_cast<int>(_blue_ maps.size()); ++i) {2842 _blue_ maps[i].second->set(n, tokens[map_index[i]]);2910 for (int i = 0; i < static_cast<int>(_blue_node_maps.size()); ++i) { 2911 _blue_node_maps[i].second->set(n, tokens[map_index[i]]); 2843 2912 } 2844 2913 … … 2925 2994 Edge e; 2926 2995 if (!_use_edges) { 2927 2928 typename NodeIndex::iterator it; 2929 2930 it = _node_index.find(source_token); 2931 if (it == _node_index.end()) { 2996 typename RedNodeIndex::iterator rit = 2997 _red_node_index.find(source_token); 2998 if (rit == _red_node_index.end()) { 2932 2999 std::ostringstream msg; 2933 3000 msg << "Item not found: " << source_token; 2934 3001 throw FormatError(msg.str()); 2935 3002 } 2936 Node source = it->second; 2937 if (!_graph.red(source)) { 2938 std::ostringstream msg; 2939 msg << "Item is not red node: " << source_token; 2940 throw FormatError(msg.str()); 2941 } 2942 2943 it = _node_index.find(target_token); 2944 if (it == _node_index.end()) { 3003 RedNode source = rit->second; 3004 typename BlueNodeIndex::iterator it = 3005 _blue_node_index.find(target_token); 3006 if (it == _blue_node_index.end()) { 2945 3007 std::ostringstream msg; 2946 3008 msg << "Item not found: " << target_token; 2947 3009 throw FormatError(msg.str()); 2948 3010 } 2949 Node target = it->second; 2950 if (!_graph.blue(target)) { 2951 std::ostringstream msg; 2952 msg << "Item is not red node: " << source_token; 2953 throw FormatError(msg.str()); 2954 } 3011 BlueNode target = it->second; 2955 3012 2956 3013 // It is checked that source is red and 2957 3014 // target is blue, so this should be safe: 2958 e = _graph.addEdge(_graph.asRedNodeUnsafe(source), 2959 _graph.asBlueNodeUnsafe(target)); 3015 e = _graph.addEdge(source, target); 2960 3016 if (label_index != -1) 2961 3017 _edge_index.insert(std::make_pair(tokens[label_index], e)); -
lemon/lgf_writer.h
r1026 r1030 186 186 ValueStorage(const Value& value, const Converter& converter = Converter()) 187 187 : _value(value), _converter(converter) {} 188 188 189 189 virtual std::string get() { 190 190 return _converter(_value); … … 192 192 }; 193 193 194 template <typename Value> 194 template <typename Value, 195 typename Map = std::map<Value, std::string> > 195 196 struct MapLookUpConverter { 196 const std::map<Value, std::string>& _map;197 198 MapLookUpConverter(const std::map<Value, std::string>& map)197 const Map& _map; 198 199 MapLookUpConverter(const Map& map) 199 200 : _map(map) {} 200 201 201 std::string operator()(const Value& str) { 202 typename std::map<Value, std::string>::const_iterator it = 203 _map.find(str); 202 std::string operator()(const Value& value) { 203 typename Map::const_iterator it = _map.find(value); 204 204 if (it == _map.end()) { 205 205 throw FormatError("Item not found"); 206 206 } 207 207 return it->second; 208 } 209 }; 210 211 template <typename Value, 212 typename Map1 = std::map<Value, std::string>, 213 typename Map2 = std::map<Value, std::string> > 214 struct DoubleMapLookUpConverter { 215 const Map1& _map1; 216 const Map2& _map2; 217 218 DoubleMapLookUpConverter(const Map1& map1, const Map2& map2) 219 : _map1(map1), _map2(map2) {} 220 221 std::string operator()(const Value& value) { 222 typename Map1::const_iterator it1 = _map1.find(value); 223 typename Map1::const_iterator it2 = _map2.find(value); 224 if (it1 == _map1.end()) { 225 if (it2 == _map2.end()) { 226 throw FormatError("Item not found"); 227 } else { 228 return it2->second; 229 } 230 } else { 231 if (it2 == _map2.end()) { 232 return it1->second; 233 } else { 234 throw FormatError("Item is ambigous"); 235 } 236 } 208 237 } 209 238 }; … … 1652 1681 std::string _attributes_caption; 1653 1682 1654 typedef std::map<Node, std::string> NodeIndex; 1655 NodeIndex _node_index; 1683 typedef std::map<Node, std::string> RedNodeIndex; 1684 RedNodeIndex _red_node_index; 1685 typedef std::map<Node, std::string> BlueNodeIndex; 1686 BlueNodeIndex _blue_node_index; 1656 1687 typedef std::map<Edge, std::string> EdgeIndex; 1657 1688 EdgeIndex _edge_index; 1658 1689 1659 1690 typedef std::vector<std::pair<std::string, 1660 _writer_bits::MapStorageBase<Node>* > > NodeMaps; 1661 NodeMaps _red_maps; 1662 NodeMaps _blue_maps; 1691 _writer_bits::MapStorageBase<RedNode>* > > RedNodeMaps; 1692 RedNodeMaps _red_node_maps; 1693 typedef std::vector<std::pair<std::string, 1694 _writer_bits::MapStorageBase<BlueNode>* > > BlueNodeMaps; 1695 BlueNodeMaps _blue_node_maps; 1663 1696 1664 1697 typedef std::vector<std::pair<std::string, … … 1711 1744 /// \brief Destructor 1712 1745 ~BpGraphWriter() { 1713 for (typename NodeMaps::iterator it = _red_maps.begin();1714 it != _red_ maps.end(); ++it) {1746 for (typename RedNodeMaps::iterator it = _red_node_maps.begin(); 1747 it != _red_node_maps.end(); ++it) { 1715 1748 delete it->second; 1716 1749 } 1717 1750 1718 for (typename NodeMaps::iterator it = _blue_maps.begin();1719 it != _blue_ maps.end(); ++it) {1751 for (typename BlueNodeMaps::iterator it = _blue_node_maps.begin(); 1752 it != _blue_node_maps.end(); ++it) { 1720 1753 delete it->second; 1721 1754 } … … 1754 1787 other.local_os = false; 1755 1788 1756 _node_index.swap(other._node_index); 1789 _red_node_index.swap(other._red_node_index); 1790 _blue_node_index.swap(other._blue_node_index); 1757 1791 _edge_index.swap(other._edge_index); 1758 1792 1759 _red_ maps.swap(other._red_maps);1760 _blue_ maps.swap(other._blue_maps);1793 _red_node_maps.swap(other._red_node_maps); 1794 _blue_node_maps.swap(other._blue_node_maps); 1761 1795 _edge_maps.swap(other._edge_maps); 1762 1796 _attributes.swap(other._attributes); … … 1780 1814 BpGraphWriter& nodeMap(const std::string& caption, const Map& map) { 1781 1815 checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>(); 1782 _writer_bits::MapStorageBase< Node>* red_storage =1783 new _writer_bits::MapStorage< Node, Map>(map);1784 _red_ maps.push_back(std::make_pair(caption, red_storage));1785 _writer_bits::MapStorageBase< Node>* blue_storage =1786 new _writer_bits::MapStorage< Node, Map>(map);1787 _blue_ maps.push_back(std::make_pair(caption, blue_storage));1816 _writer_bits::MapStorageBase<RedNode>* red_storage = 1817 new _writer_bits::MapStorage<RedNode, Map>(map); 1818 _red_node_maps.push_back(std::make_pair(caption, red_storage)); 1819 _writer_bits::MapStorageBase<BlueNode>* blue_storage = 1820 new _writer_bits::MapStorage<BlueNode, Map>(map); 1821 _blue_node_maps.push_back(std::make_pair(caption, blue_storage)); 1788 1822 return *this; 1789 1823 } … … 1797 1831 const Converter& converter = Converter()) { 1798 1832 checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>(); 1799 _writer_bits::MapStorageBase< Node>* red_storage =1800 new _writer_bits::MapStorage< Node, Map, Converter>(map, converter);1801 _red_ maps.push_back(std::make_pair(caption, red_storage));1802 _writer_bits::MapStorageBase< Node>* blue_storage =1803 new _writer_bits::MapStorage< Node, Map, Converter>(map, converter);1804 _blue_ maps.push_back(std::make_pair(caption, blue_storage));1833 _writer_bits::MapStorageBase<RedNode>* red_storage = 1834 new _writer_bits::MapStorage<RedNode, Map, Converter>(map, converter); 1835 _red_node_maps.push_back(std::make_pair(caption, red_storage)); 1836 _writer_bits::MapStorageBase<BlueNode>* blue_storage = 1837 new _writer_bits::MapStorage<BlueNode, Map, Converter>(map, converter); 1838 _blue_node_maps.push_back(std::make_pair(caption, blue_storage)); 1805 1839 return *this; 1806 1840 } … … 1811 1845 template <typename Map> 1812 1846 BpGraphWriter& redNodeMap(const std::string& caption, const Map& map) { 1813 checkConcept<concepts::ReadMap< Node, typename Map::Value>, Map>();1814 _writer_bits::MapStorageBase< Node>* storage =1815 new _writer_bits::MapStorage< Node, Map>(map);1816 _red_ maps.push_back(std::make_pair(caption, storage));1847 checkConcept<concepts::ReadMap<RedNode, typename Map::Value>, Map>(); 1848 _writer_bits::MapStorageBase<RedNode>* storage = 1849 new _writer_bits::MapStorage<RedNode, Map>(map); 1850 _red_node_maps.push_back(std::make_pair(caption, storage)); 1817 1851 return *this; 1818 1852 } … … 1825 1859 BpGraphWriter& redNodeMap(const std::string& caption, const Map& map, 1826 1860 const Converter& converter = Converter()) { 1827 checkConcept<concepts::ReadMap< Node, typename Map::Value>, Map>();1828 _writer_bits::MapStorageBase< Node>* storage =1829 new _writer_bits::MapStorage< Node, Map, Converter>(map, converter);1830 _red_ maps.push_back(std::make_pair(caption, storage));1861 checkConcept<concepts::ReadMap<RedNode, typename Map::Value>, Map>(); 1862 _writer_bits::MapStorageBase<RedNode>* storage = 1863 new _writer_bits::MapStorage<RedNode, Map, Converter>(map, converter); 1864 _red_node_maps.push_back(std::make_pair(caption, storage)); 1831 1865 return *this; 1832 1866 } … … 1837 1871 template <typename Map> 1838 1872 BpGraphWriter& blueNodeMap(const std::string& caption, const Map& map) { 1839 checkConcept<concepts::ReadMap< Node, typename Map::Value>, Map>();1840 _writer_bits::MapStorageBase< Node>* storage =1841 new _writer_bits::MapStorage< Node, Map>(map);1842 _blue_ maps.push_back(std::make_pair(caption, storage));1873 checkConcept<concepts::ReadMap<BlueNode, typename Map::Value>, Map>(); 1874 _writer_bits::MapStorageBase<BlueNode>* storage = 1875 new _writer_bits::MapStorage<BlueNode, Map>(map); 1876 _blue_node_maps.push_back(std::make_pair(caption, storage)); 1843 1877 return *this; 1844 1878 } … … 1851 1885 BpGraphWriter& blueNodeMap(const std::string& caption, const Map& map, 1852 1886 const Converter& converter = Converter()) { 1853 checkConcept<concepts::ReadMap< Node, typename Map::Value>, Map>();1854 _writer_bits::MapStorageBase< Node>* storage =1855 new _writer_bits::MapStorage< Node, Map, Converter>(map, converter);1856 _blue_ maps.push_back(std::make_pair(caption, storage));1887 checkConcept<concepts::ReadMap<BlueNode, typename Map::Value>, Map>(); 1888 _writer_bits::MapStorageBase<BlueNode>* storage = 1889 new _writer_bits::MapStorage<BlueNode, Map, Converter>(map, converter); 1890 _blue_node_maps.push_back(std::make_pair(caption, storage)); 1857 1891 return *this; 1858 1892 } … … 1946 1980 /// Add a node writing rule to the writer. 1947 1981 BpGraphWriter& node(const std::string& caption, const Node& node) { 1982 typedef _writer_bits::DoubleMapLookUpConverter< 1983 Node, RedNodeIndex, BlueNodeIndex> Converter; 1984 Converter converter(_red_node_index, _blue_node_index); 1985 _writer_bits::ValueStorageBase* storage = 1986 new _writer_bits::ValueStorage<Node, Converter>(node, converter); 1987 _attributes.push_back(std::make_pair(caption, storage)); 1988 return *this; 1989 } 1990 1991 /// \brief Red node writing rule 1992 /// 1993 /// Add a red node writing rule to the writer. 1994 BpGraphWriter& redNode(const std::string& caption, const RedNode& node) { 1948 1995 typedef _writer_bits::MapLookUpConverter<Node> Converter; 1949 Converter converter(_node_index); 1996 Converter converter(_red_node_index); 1997 _writer_bits::ValueStorageBase* storage = 1998 new _writer_bits::ValueStorage<Node, Converter>(node, converter); 1999 _attributes.push_back(std::make_pair(caption, storage)); 2000 return *this; 2001 } 2002 2003 /// \brief Blue node writing rule 2004 /// 2005 /// Add a blue node writing rule to the writer. 2006 BpGraphWriter& blueNode(const std::string& caption, const BlueNode& node) { 2007 typedef _writer_bits::MapLookUpConverter<Node> Converter; 2008 Converter converter(_blue_node_index); 1950 2009 _writer_bits::ValueStorageBase* storage = 1951 2010 new _writer_bits::ValueStorage<Node, Converter>(node, converter); … … 2034 2093 2035 2094 void writeRedNodes() { 2036 _writer_bits::MapStorageBase< Node>* label = 0;2037 for (typename NodeMaps::iterator it = _red_maps.begin();2038 it != _red_ maps.end(); ++it) {2095 _writer_bits::MapStorageBase<RedNode>* label = 0; 2096 for (typename RedNodeMaps::iterator it = _red_node_maps.begin(); 2097 it != _red_node_maps.end(); ++it) { 2039 2098 if (it->first == "label") { 2040 2099 label = it->second; … … 2052 2111 *_os << "label" << '\t'; 2053 2112 } 2054 for (typename NodeMaps::iterator it = _red_maps.begin();2055 it != _red_ maps.end(); ++it) {2113 for (typename RedNodeMaps::iterator it = _red_node_maps.begin(); 2114 it != _red_node_maps.end(); ++it) { 2056 2115 _writer_bits::writeToken(*_os, it->first) << '\t'; 2057 2116 } 2058 2117 *_os << std::endl; 2059 2118 2060 std::vector< Node> nodes;2119 std::vector<RedNode> nodes; 2061 2120 for (RedNodeIt n(_graph); n != INVALID; ++n) { 2062 2121 nodes.push_back(n); … … 2072 2131 2073 2132 for (int i = 0; i < static_cast<int>(nodes.size()); ++i) { 2074 Node n = nodes[i];2133 RedNode n = nodes[i]; 2075 2134 if (label == 0) { 2076 2135 std::ostringstream os; 2077 os << _graph.id( n);2136 os << _graph.id(static_cast<Node>(n)); 2078 2137 _writer_bits::writeToken(*_os, os.str()); 2079 2138 *_os << '\t'; 2080 _ node_index.insert(std::make_pair(n, os.str()));2081 } 2082 for (typename NodeMaps::iterator it = _red_maps.begin();2083 it != _red_ maps.end(); ++it) {2139 _red_node_index.insert(std::make_pair(n, os.str())); 2140 } 2141 for (typename RedNodeMaps::iterator it = _red_node_maps.begin(); 2142 it != _red_node_maps.end(); ++it) { 2084 2143 std::string value = it->second->get(n); 2085 2144 _writer_bits::writeToken(*_os, value); 2086 2145 if (it->first == "label") { 2087 _ node_index.insert(std::make_pair(n, value));2146 _red_node_index.insert(std::make_pair(n, value)); 2088 2147 } 2089 2148 *_os << '\t'; … … 2094 2153 2095 2154 void writeBlueNodes() { 2096 _writer_bits::MapStorageBase< Node>* label = 0;2097 for (typename NodeMaps::iterator it = _blue_maps.begin();2098 it != _blue_ maps.end(); ++it) {2155 _writer_bits::MapStorageBase<BlueNode>* label = 0; 2156 for (typename BlueNodeMaps::iterator it = _blue_node_maps.begin(); 2157 it != _blue_node_maps.end(); ++it) { 2099 2158 if (it->first == "label") { 2100 2159 label = it->second; … … 2112 2171 *_os << "label" << '\t'; 2113 2172 } 2114 for (typename NodeMaps::iterator it = _blue_maps.begin();2115 it != _blue_ maps.end(); ++it) {2173 for (typename BlueNodeMaps::iterator it = _blue_node_maps.begin(); 2174 it != _blue_node_maps.end(); ++it) { 2116 2175 _writer_bits::writeToken(*_os, it->first) << '\t'; 2117 2176 } 2118 2177 *_os << std::endl; 2119 2178 2120 std::vector< Node> nodes;2179 std::vector<BlueNode> nodes; 2121 2180 for (BlueNodeIt n(_graph); n != INVALID; ++n) { 2122 2181 nodes.push_back(n); … … 2132 2191 2133 2192 for (int i = 0; i < static_cast<int>(nodes.size()); ++i) { 2134 Node n = nodes[i];2193 BlueNode n = nodes[i]; 2135 2194 if (label == 0) { 2136 2195 std::ostringstream os; 2137 os << _graph.id( n);2196 os << _graph.id(static_cast<Node>(n)); 2138 2197 _writer_bits::writeToken(*_os, os.str()); 2139 2198 *_os << '\t'; 2140 _ node_index.insert(std::make_pair(n, os.str()));2141 } 2142 for (typename NodeMaps::iterator it = _blue_maps.begin();2143 it != _blue_ maps.end(); ++it) {2199 _blue_node_index.insert(std::make_pair(n, os.str())); 2200 } 2201 for (typename BlueNodeMaps::iterator it = _blue_node_maps.begin(); 2202 it != _blue_node_maps.end(); ++it) { 2144 2203 std::string value = it->second->get(n); 2145 2204 _writer_bits::writeToken(*_os, value); 2146 2205 if (it->first == "label") { 2147 _ node_index.insert(std::make_pair(n, value));2206 _blue_node_index.insert(std::make_pair(n, value)); 2148 2207 } 2149 2208 *_os << '\t'; … … 2154 2213 2155 2214 void createRedNodeIndex() { 2156 _writer_bits::MapStorageBase< Node>* label = 0;2157 for (typename NodeMaps::iterator it = _red_maps.begin();2158 it != _red_ maps.end(); ++it) {2215 _writer_bits::MapStorageBase<RedNode>* label = 0; 2216 for (typename RedNodeMaps::iterator it = _red_node_maps.begin(); 2217 it != _red_node_maps.end(); ++it) { 2159 2218 if (it->first == "label") { 2160 2219 label = it->second; … … 2164 2223 2165 2224 if (label == 0) { 2166 for ( NodeIt n(_graph); n != INVALID; ++n) {2225 for (RedNodeIt n(_graph); n != INVALID; ++n) { 2167 2226 std::ostringstream os; 2168 2227 os << _graph.id(n); 2169 _ node_index.insert(std::make_pair(n, os.str()));2228 _red_node_index.insert(std::make_pair(n, os.str())); 2170 2229 } 2171 2230 } else { 2172 for ( NodeIt n(_graph); n != INVALID; ++n) {2231 for (RedNodeIt n(_graph); n != INVALID; ++n) { 2173 2232 std::string value = label->get(n); 2174 _ node_index.insert(std::make_pair(n, value));2233 _red_node_index.insert(std::make_pair(n, value)); 2175 2234 } 2176 2235 } … … 2178 2237 2179 2238 void createBlueNodeIndex() { 2180 _writer_bits::MapStorageBase< Node>* label = 0;2181 for (typename NodeMaps::iterator it = _blue_maps.begin();2182 it != _blue_ maps.end(); ++it) {2239 _writer_bits::MapStorageBase<BlueNode>* label = 0; 2240 for (typename BlueNodeMaps::iterator it = _blue_node_maps.begin(); 2241 it != _blue_node_maps.end(); ++it) { 2183 2242 if (it->first == "label") { 2184 2243 label = it->second; … … 2188 2247 2189 2248 if (label == 0) { 2190 for ( NodeIt n(_graph); n != INVALID; ++n) {2249 for (BlueNodeIt n(_graph); n != INVALID; ++n) { 2191 2250 std::ostringstream os; 2192 2251 os << _graph.id(n); 2193 _ node_index.insert(std::make_pair(n, os.str()));2252 _blue_node_index.insert(std::make_pair(n, os.str())); 2194 2253 } 2195 2254 } else { 2196 for ( NodeIt n(_graph); n != INVALID; ++n) {2255 for (BlueNodeIt n(_graph); n != INVALID; ++n) { 2197 2256 std::string value = label->get(n); 2198 _ node_index.insert(std::make_pair(n, value));2257 _blue_node_index.insert(std::make_pair(n, value)); 2199 2258 } 2200 2259 } … … 2242 2301 for (int i = 0; i < static_cast<int>(edges.size()); ++i) { 2243 2302 Edge e = edges[i]; 2244 _writer_bits::writeToken(*_os, _ node_index.2303 _writer_bits::writeToken(*_os, _red_node_index. 2245 2304 find(_graph.redNode(e))->second); 2246 2305 *_os << '\t'; 2247 _writer_bits::writeToken(*_os, _ node_index.2306 _writer_bits::writeToken(*_os, _blue_node_index. 2248 2307 find(_graph.blueNode(e))->second); 2249 2308 *_os << '\t'; -
test/CMakeLists.txt
r1018 r1030 36 36 heap_test 37 37 kruskal_test 38 lgf_reader_writer_test 38 39 lgf_test 39 40 maps_test
Note: See TracChangeset
for help on using the changeset viewer.