1.1 --- a/lemon/lgf_writer.h Sun Jul 13 16:46:56 2008 +0100
1.2 +++ b/lemon/lgf_writer.h Sun Jul 13 19:51:02 2008 +0100
1.3 @@ -1,6 +1,6 @@
1.4 -/* -*- C++ -*-
1.5 +/* -*- mode: C++; indent-tabs-mode: nil; -*-
1.6 *
1.7 - * This file is a part of LEMON, a generic C++ optimization library
1.8 + * This file is a part of LEMON, a generic C++ optimization library.
1.9 *
1.10 * Copyright (C) 2003-2008
1.11 * Egervary Jeno Kombinatorikus Optimalizalasi Kutatocsoport
1.12 @@ -43,9 +43,9 @@
1.13 template <typename Value>
1.14 struct DefaultConverter {
1.15 std::string operator()(const Value& value) {
1.16 - std::ostringstream os;
1.17 - os << value;
1.18 - return os.str();
1.19 + std::ostringstream os;
1.20 + os << value;
1.21 + return os.str();
1.22 }
1.23 };
1.24
1.25 @@ -62,12 +62,12 @@
1.26
1.27 private:
1.28 const Map& _map;
1.29 -
1.30 +
1.31 public:
1.32 MapLess(const Map& map) : _map(map) {}
1.33
1.34 bool operator()(const Item& left, const Item& right) {
1.35 - return _map[left] < _map[right];
1.36 + return _map[left] < _map[right];
1.37 }
1.38 };
1.39
1.40 @@ -81,18 +81,18 @@
1.41 private:
1.42 const Graph& _graph;
1.43 const Map& _map;
1.44 -
1.45 +
1.46 public:
1.47 - GraphArcMapLess(const Graph& graph, const Map& map)
1.48 - : _graph(graph), _map(map) {}
1.49 + GraphArcMapLess(const Graph& graph, const Map& map)
1.50 + : _graph(graph), _map(map) {}
1.51
1.52 bool operator()(const Item& left, const Item& right) {
1.53 - return _map[_graph.direct(left, _dir)] <
1.54 - _map[_graph.direct(right, _dir)];
1.55 + return _map[_graph.direct(left, _dir)] <
1.56 + _map[_graph.direct(right, _dir)];
1.57 }
1.58 };
1.59
1.60 - template <typename _Item>
1.61 + template <typename _Item>
1.62 class MapStorageBase {
1.63 public:
1.64 typedef _Item Item;
1.65 @@ -105,34 +105,34 @@
1.66 virtual void sort(std::vector<Item>&) = 0;
1.67 };
1.68
1.69 - template <typename _Item, typename _Map,
1.70 - typename _Converter = DefaultConverter<typename _Map::Value> >
1.71 + template <typename _Item, typename _Map,
1.72 + typename _Converter = DefaultConverter<typename _Map::Value> >
1.73 class MapStorage : public MapStorageBase<_Item> {
1.74 public:
1.75 typedef _Map Map;
1.76 typedef _Converter Converter;
1.77 typedef _Item Item;
1.78 -
1.79 +
1.80 private:
1.81 const Map& _map;
1.82 Converter _converter;
1.83
1.84 public:
1.85 - MapStorage(const Map& map, const Converter& converter = Converter())
1.86 - : _map(map), _converter(converter) {}
1.87 + MapStorage(const Map& map, const Converter& converter = Converter())
1.88 + : _map(map), _converter(converter) {}
1.89 virtual ~MapStorage() {}
1.90
1.91 virtual std::string get(const Item& item) {
1.92 - return _converter(_map[item]);
1.93 + return _converter(_map[item]);
1.94 }
1.95 virtual void sort(std::vector<Item>& items) {
1.96 - MapLess<Map> less(_map);
1.97 - std::sort(items.begin(), items.end(), less);
1.98 + MapLess<Map> less(_map);
1.99 + std::sort(items.begin(), items.end(), less);
1.100 }
1.101 };
1.102
1.103 - template <typename _Graph, bool _dir, typename _Map,
1.104 - typename _Converter = DefaultConverter<typename _Map::Value> >
1.105 + template <typename _Graph, bool _dir, typename _Map,
1.106 + typename _Converter = DefaultConverter<typename _Map::Value> >
1.107 class GraphArcMapStorage : public MapStorageBase<typename _Graph::Edge> {
1.108 public:
1.109 typedef _Map Map;
1.110 @@ -140,24 +140,24 @@
1.111 typedef _Graph Graph;
1.112 typedef typename Graph::Edge Item;
1.113 static const bool dir = _dir;
1.114 -
1.115 +
1.116 private:
1.117 const Graph& _graph;
1.118 const Map& _map;
1.119 Converter _converter;
1.120
1.121 public:
1.122 - GraphArcMapStorage(const Graph& graph, const Map& map,
1.123 - const Converter& converter = Converter())
1.124 - : _graph(graph), _map(map), _converter(converter) {}
1.125 + GraphArcMapStorage(const Graph& graph, const Map& map,
1.126 + const Converter& converter = Converter())
1.127 + : _graph(graph), _map(map), _converter(converter) {}
1.128 virtual ~GraphArcMapStorage() {}
1.129
1.130 virtual std::string get(const Item& item) {
1.131 - return _converter(_map[_graph.direct(item, dir)]);
1.132 + return _converter(_map[_graph.direct(item, dir)]);
1.133 }
1.134 virtual void sort(std::vector<Item>& items) {
1.135 - GraphArcMapLess<Graph, dir, Map> less(_graph, _map);
1.136 - std::sort(items.begin(), items.end(), less);
1.137 + GraphArcMapLess<Graph, dir, Map> less(_graph, _map);
1.138 + std::sort(items.begin(), items.end(), less);
1.139 }
1.140 };
1.141
1.142 @@ -166,7 +166,7 @@
1.143 ValueStorageBase() {}
1.144 virtual ~ValueStorageBase() {}
1.145
1.146 - virtual std::string get() = 0;
1.147 + virtual std::string get() = 0;
1.148 };
1.149
1.150 template <typename _Value, typename _Converter = DefaultConverter<_Value> >
1.151 @@ -181,27 +181,27 @@
1.152
1.153 public:
1.154 ValueStorage(const Value& value, const Converter& converter = Converter())
1.155 - : _value(value), _converter(converter) {}
1.156 + : _value(value), _converter(converter) {}
1.157
1.158 virtual std::string get() {
1.159 - return _converter(_value);
1.160 + return _converter(_value);
1.161 }
1.162 };
1.163
1.164 template <typename Value>
1.165 struct MapLookUpConverter {
1.166 const std::map<Value, std::string>& _map;
1.167 -
1.168 - MapLookUpConverter(const std::map<Value, std::string>& map)
1.169 - : _map(map) {}
1.170 -
1.171 +
1.172 + MapLookUpConverter(const std::map<Value, std::string>& map)
1.173 + : _map(map) {}
1.174 +
1.175 std::string operator()(const Value& str) {
1.176 - typename std::map<Value, std::string>::const_iterator it =
1.177 - _map.find(str);
1.178 - if (it == _map.end()) {
1.179 - throw DataFormatError("Item not found");
1.180 - }
1.181 - return it->second;
1.182 + typename std::map<Value, std::string>::const_iterator it =
1.183 + _map.find(str);
1.184 + if (it == _map.end()) {
1.185 + throw DataFormatError("Item not found");
1.186 + }
1.187 + return it->second;
1.188 }
1.189 };
1.190
1.191 @@ -209,71 +209,71 @@
1.192 struct GraphArcLookUpConverter {
1.193 const Graph& _graph;
1.194 const std::map<typename Graph::Edge, std::string>& _map;
1.195 -
1.196 - GraphArcLookUpConverter(const Graph& graph,
1.197 - const std::map<typename Graph::Edge,
1.198 - std::string>& map)
1.199 - : _graph(graph), _map(map) {}
1.200 -
1.201 +
1.202 + GraphArcLookUpConverter(const Graph& graph,
1.203 + const std::map<typename Graph::Edge,
1.204 + std::string>& map)
1.205 + : _graph(graph), _map(map) {}
1.206 +
1.207 std::string operator()(const typename Graph::Arc& val) {
1.208 - typename std::map<typename Graph::Edge, std::string>
1.209 - ::const_iterator it = _map.find(val);
1.210 - if (it == _map.end()) {
1.211 - throw DataFormatError("Item not found");
1.212 - }
1.213 - return (_graph.direction(val) ? '+' : '-') + it->second;
1.214 + typename std::map<typename Graph::Edge, std::string>
1.215 + ::const_iterator it = _map.find(val);
1.216 + if (it == _map.end()) {
1.217 + throw DataFormatError("Item not found");
1.218 + }
1.219 + return (_graph.direction(val) ? '+' : '-') + it->second;
1.220 }
1.221 };
1.222
1.223 inline bool isWhiteSpace(char c) {
1.224 - return c == ' ' || c == '\t' || c == '\v' ||
1.225 - c == '\n' || c == '\r' || c == '\f';
1.226 + return c == ' ' || c == '\t' || c == '\v' ||
1.227 + c == '\n' || c == '\r' || c == '\f';
1.228 }
1.229
1.230 inline bool isEscaped(char c) {
1.231 - return c == '\\' || c == '\"' || c == '\'' ||
1.232 - c == '\a' || c == '\b';
1.233 + return c == '\\' || c == '\"' || c == '\'' ||
1.234 + c == '\a' || c == '\b';
1.235 }
1.236
1.237 inline static void writeEscape(std::ostream& os, char c) {
1.238 switch (c) {
1.239 case '\\':
1.240 - os << "\\\\";
1.241 - return;
1.242 + os << "\\\\";
1.243 + return;
1.244 case '\"':
1.245 - os << "\\\"";
1.246 - return;
1.247 + os << "\\\"";
1.248 + return;
1.249 case '\a':
1.250 - os << "\\a";
1.251 - return;
1.252 + os << "\\a";
1.253 + return;
1.254 case '\b':
1.255 - os << "\\b";
1.256 - return;
1.257 + os << "\\b";
1.258 + return;
1.259 case '\f':
1.260 - os << "\\f";
1.261 - return;
1.262 + os << "\\f";
1.263 + return;
1.264 case '\r':
1.265 - os << "\\r";
1.266 - return;
1.267 + os << "\\r";
1.268 + return;
1.269 case '\n':
1.270 - os << "\\n";
1.271 - return;
1.272 + os << "\\n";
1.273 + return;
1.274 case '\t':
1.275 - os << "\\t";
1.276 - return;
1.277 + os << "\\t";
1.278 + return;
1.279 case '\v':
1.280 - os << "\\v";
1.281 - return;
1.282 + os << "\\v";
1.283 + return;
1.284 default:
1.285 - if (c < 0x20) {
1.286 - std::ios::fmtflags flags = os.flags();
1.287 - os << '\\' << std::oct << static_cast<int>(c);
1.288 - os.flags(flags);
1.289 - } else {
1.290 - os << c;
1.291 - }
1.292 - return;
1.293 - }
1.294 + if (c < 0x20) {
1.295 + std::ios::fmtflags flags = os.flags();
1.296 + os << '\\' << std::oct << static_cast<int>(c);
1.297 + os.flags(flags);
1.298 + } else {
1.299 + os << c;
1.300 + }
1.301 + return;
1.302 + }
1.303 }
1.304
1.305 inline bool requireEscape(const std::string& str) {
1.306 @@ -281,24 +281,24 @@
1.307 std::istringstream is(str);
1.308 char c;
1.309 while (is.get(c)) {
1.310 - if (isWhiteSpace(c) || isEscaped(c)) {
1.311 - return true;
1.312 - }
1.313 + if (isWhiteSpace(c) || isEscaped(c)) {
1.314 + return true;
1.315 + }
1.316 }
1.317 return false;
1.318 }
1.319 -
1.320 +
1.321 inline std::ostream& writeToken(std::ostream& os, const std::string& str) {
1.322
1.323 if (requireEscape(str)) {
1.324 - os << '\"';
1.325 - for (std::string::const_iterator it = str.begin();
1.326 - it != str.end(); ++it) {
1.327 - writeEscape(os, *it);
1.328 - }
1.329 - os << '\"';
1.330 + os << '\"';
1.331 + for (std::string::const_iterator it = str.begin();
1.332 + it != str.end(); ++it) {
1.333 + writeEscape(os, *it);
1.334 + }
1.335 + os << '\"';
1.336 } else {
1.337 - os << str;
1.338 + os << str;
1.339 }
1.340 return os;
1.341 }
1.342 @@ -309,19 +309,19 @@
1.343 class DigraphWriter;
1.344
1.345 template <typename Digraph>
1.346 - DigraphWriter<Digraph> digraphWriter(std::ostream& os,
1.347 - const Digraph& digraph);
1.348 + DigraphWriter<Digraph> digraphWriter(std::ostream& os,
1.349 + const Digraph& digraph);
1.350
1.351 template <typename Digraph>
1.352 - DigraphWriter<Digraph> digraphWriter(const std::string& fn,
1.353 - const Digraph& digraph);
1.354 + DigraphWriter<Digraph> digraphWriter(const std::string& fn,
1.355 + const Digraph& digraph);
1.356
1.357 template <typename Digraph>
1.358 - DigraphWriter<Digraph> digraphWriter(const char *fn,
1.359 - const Digraph& digraph);
1.360 -
1.361 + DigraphWriter<Digraph> digraphWriter(const char *fn,
1.362 + const Digraph& digraph);
1.363 +
1.364 /// \ingroup lemon_io
1.365 - ///
1.366 + ///
1.367 /// \brief \ref lgf-format "LGF" writer for directed graphs
1.368 ///
1.369 /// This utility writes an \ref lgf-format "LGF" file.
1.370 @@ -370,7 +370,7 @@
1.371
1.372 typedef _Digraph Digraph;
1.373 TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
1.374 -
1.375 +
1.376 private:
1.377
1.378
1.379 @@ -382,21 +382,21 @@
1.380 std::string _nodes_caption;
1.381 std::string _arcs_caption;
1.382 std::string _attributes_caption;
1.383 -
1.384 +
1.385 typedef std::map<Node, std::string> NodeIndex;
1.386 NodeIndex _node_index;
1.387 typedef std::map<Arc, std::string> ArcIndex;
1.388 ArcIndex _arc_index;
1.389
1.390 - typedef std::vector<std::pair<std::string,
1.391 - _writer_bits::MapStorageBase<Node>* > > NodeMaps;
1.392 - NodeMaps _node_maps;
1.393 + typedef std::vector<std::pair<std::string,
1.394 + _writer_bits::MapStorageBase<Node>* > > NodeMaps;
1.395 + NodeMaps _node_maps;
1.396
1.397 - typedef std::vector<std::pair<std::string,
1.398 + typedef std::vector<std::pair<std::string,
1.399 _writer_bits::MapStorageBase<Arc>* > >ArcMaps;
1.400 ArcMaps _arc_maps;
1.401
1.402 - typedef std::vector<std::pair<std::string,
1.403 + typedef std::vector<std::pair<std::string,
1.404 _writer_bits::ValueStorageBase*> > Attributes;
1.405 Attributes _attributes;
1.406
1.407 @@ -409,60 +409,60 @@
1.408 ///
1.409 /// Construct a directed graph writer, which writes to the given
1.410 /// output stream.
1.411 - DigraphWriter(std::ostream& is, const Digraph& digraph)
1.412 + DigraphWriter(std::ostream& is, const Digraph& digraph)
1.413 : _os(&is), local_os(false), _digraph(digraph),
1.414 - _skip_nodes(false), _skip_arcs(false) {}
1.415 + _skip_nodes(false), _skip_arcs(false) {}
1.416
1.417 /// \brief Constructor
1.418 ///
1.419 /// Construct a directed graph writer, which writes to the given
1.420 /// output file.
1.421 - DigraphWriter(const std::string& fn, const Digraph& digraph)
1.422 + DigraphWriter(const std::string& fn, const Digraph& digraph)
1.423 : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph),
1.424 - _skip_nodes(false), _skip_arcs(false) {}
1.425 + _skip_nodes(false), _skip_arcs(false) {}
1.426
1.427 /// \brief Constructor
1.428 ///
1.429 /// Construct a directed graph writer, which writes to the given
1.430 /// output file.
1.431 - DigraphWriter(const char* fn, const Digraph& digraph)
1.432 + DigraphWriter(const char* fn, const Digraph& digraph)
1.433 : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph),
1.434 - _skip_nodes(false), _skip_arcs(false) {}
1.435 + _skip_nodes(false), _skip_arcs(false) {}
1.436
1.437 /// \brief Destructor
1.438 ~DigraphWriter() {
1.439 - for (typename NodeMaps::iterator it = _node_maps.begin();
1.440 - it != _node_maps.end(); ++it) {
1.441 - delete it->second;
1.442 + for (typename NodeMaps::iterator it = _node_maps.begin();
1.443 + it != _node_maps.end(); ++it) {
1.444 + delete it->second;
1.445 }
1.446
1.447 - for (typename ArcMaps::iterator it = _arc_maps.begin();
1.448 - it != _arc_maps.end(); ++it) {
1.449 - delete it->second;
1.450 + for (typename ArcMaps::iterator it = _arc_maps.begin();
1.451 + it != _arc_maps.end(); ++it) {
1.452 + delete it->second;
1.453 }
1.454
1.455 - for (typename Attributes::iterator it = _attributes.begin();
1.456 - it != _attributes.end(); ++it) {
1.457 - delete it->second;
1.458 + for (typename Attributes::iterator it = _attributes.begin();
1.459 + it != _attributes.end(); ++it) {
1.460 + delete it->second;
1.461 }
1.462
1.463 if (local_os) {
1.464 - delete _os;
1.465 + delete _os;
1.466 }
1.467 }
1.468
1.469 private:
1.470
1.471 - friend DigraphWriter<Digraph> digraphWriter<>(std::ostream& os,
1.472 - const Digraph& digraph);
1.473 - friend DigraphWriter<Digraph> digraphWriter<>(const std::string& fn,
1.474 - const Digraph& digraph);
1.475 - friend DigraphWriter<Digraph> digraphWriter<>(const char *fn,
1.476 - const Digraph& digraph);
1.477 + friend DigraphWriter<Digraph> digraphWriter<>(std::ostream& os,
1.478 + const Digraph& digraph);
1.479 + friend DigraphWriter<Digraph> digraphWriter<>(const std::string& fn,
1.480 + const Digraph& digraph);
1.481 + friend DigraphWriter<Digraph> digraphWriter<>(const char *fn,
1.482 + const Digraph& digraph);
1.483
1.484 - DigraphWriter(DigraphWriter& other)
1.485 + DigraphWriter(DigraphWriter& other)
1.486 : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
1.487 - _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
1.488 + _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
1.489
1.490 other._os = 0;
1.491 other.local_os = false;
1.492 @@ -478,22 +478,22 @@
1.493 _arcs_caption = other._arcs_caption;
1.494 _attributes_caption = other._attributes_caption;
1.495 }
1.496 -
1.497 +
1.498 DigraphWriter& operator=(const DigraphWriter&);
1.499
1.500 public:
1.501
1.502 /// \name Writing rules
1.503 /// @{
1.504 -
1.505 +
1.506 /// \brief Node map writing rule
1.507 ///
1.508 /// Add a node map writing rule to the writer.
1.509 template <typename Map>
1.510 DigraphWriter& nodeMap(const std::string& caption, const Map& map) {
1.511 checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
1.512 - _writer_bits::MapStorageBase<Node>* storage =
1.513 - new _writer_bits::MapStorage<Node, Map>(map);
1.514 + _writer_bits::MapStorageBase<Node>* storage =
1.515 + new _writer_bits::MapStorage<Node, Map>(map);
1.516 _node_maps.push_back(std::make_pair(caption, storage));
1.517 return *this;
1.518 }
1.519 @@ -503,11 +503,11 @@
1.520 /// Add a node map writing rule with specialized converter to the
1.521 /// writer.
1.522 template <typename Map, typename Converter>
1.523 - DigraphWriter& nodeMap(const std::string& caption, const Map& map,
1.524 - const Converter& converter = Converter()) {
1.525 + DigraphWriter& nodeMap(const std::string& caption, const Map& map,
1.526 + const Converter& converter = Converter()) {
1.527 checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
1.528 - _writer_bits::MapStorageBase<Node>* storage =
1.529 - new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
1.530 + _writer_bits::MapStorageBase<Node>* storage =
1.531 + new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
1.532 _node_maps.push_back(std::make_pair(caption, storage));
1.533 return *this;
1.534 }
1.535 @@ -518,8 +518,8 @@
1.536 template <typename Map>
1.537 DigraphWriter& arcMap(const std::string& caption, const Map& map) {
1.538 checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
1.539 - _writer_bits::MapStorageBase<Arc>* storage =
1.540 - new _writer_bits::MapStorage<Arc, Map>(map);
1.541 + _writer_bits::MapStorageBase<Arc>* storage =
1.542 + new _writer_bits::MapStorage<Arc, Map>(map);
1.543 _arc_maps.push_back(std::make_pair(caption, storage));
1.544 return *this;
1.545 }
1.546 @@ -529,11 +529,11 @@
1.547 /// Add an arc map writing rule with specialized converter to the
1.548 /// writer.
1.549 template <typename Map, typename Converter>
1.550 - DigraphWriter& arcMap(const std::string& caption, const Map& map,
1.551 - const Converter& converter = Converter()) {
1.552 + DigraphWriter& arcMap(const std::string& caption, const Map& map,
1.553 + const Converter& converter = Converter()) {
1.554 checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
1.555 - _writer_bits::MapStorageBase<Arc>* storage =
1.556 - new _writer_bits::MapStorage<Arc, Map, Converter>(map, converter);
1.557 + _writer_bits::MapStorageBase<Arc>* storage =
1.558 + new _writer_bits::MapStorage<Arc, Map, Converter>(map, converter);
1.559 _arc_maps.push_back(std::make_pair(caption, storage));
1.560 return *this;
1.561 }
1.562 @@ -543,8 +543,8 @@
1.563 /// Add an attribute writing rule to the writer.
1.564 template <typename Value>
1.565 DigraphWriter& attribute(const std::string& caption, const Value& value) {
1.566 - _writer_bits::ValueStorageBase* storage =
1.567 - new _writer_bits::ValueStorage<Value>(value);
1.568 + _writer_bits::ValueStorageBase* storage =
1.569 + new _writer_bits::ValueStorage<Value>(value);
1.570 _attributes.push_back(std::make_pair(caption, storage));
1.571 return *this;
1.572 }
1.573 @@ -554,10 +554,10 @@
1.574 /// Add an attribute writing rule with specialized converter to the
1.575 /// writer.
1.576 template <typename Value, typename Converter>
1.577 - DigraphWriter& attribute(const std::string& caption, const Value& value,
1.578 - const Converter& converter = Converter()) {
1.579 - _writer_bits::ValueStorageBase* storage =
1.580 - new _writer_bits::ValueStorage<Value, Converter>(value, converter);
1.581 + DigraphWriter& attribute(const std::string& caption, const Value& value,
1.582 + const Converter& converter = Converter()) {
1.583 + _writer_bits::ValueStorageBase* storage =
1.584 + new _writer_bits::ValueStorage<Value, Converter>(value, converter);
1.585 _attributes.push_back(std::make_pair(caption, storage));
1.586 return *this;
1.587 }
1.588 @@ -568,8 +568,8 @@
1.589 DigraphWriter& node(const std::string& caption, const Node& node) {
1.590 typedef _writer_bits::MapLookUpConverter<Node> Converter;
1.591 Converter converter(_node_index);
1.592 - _writer_bits::ValueStorageBase* storage =
1.593 - new _writer_bits::ValueStorage<Node, Converter>(node, converter);
1.594 + _writer_bits::ValueStorageBase* storage =
1.595 + new _writer_bits::ValueStorage<Node, Converter>(node, converter);
1.596 _attributes.push_back(std::make_pair(caption, storage));
1.597 return *this;
1.598 }
1.599 @@ -580,8 +580,8 @@
1.600 DigraphWriter& arc(const std::string& caption, const Arc& arc) {
1.601 typedef _writer_bits::MapLookUpConverter<Arc> Converter;
1.602 Converter converter(_arc_index);
1.603 - _writer_bits::ValueStorageBase* storage =
1.604 - new _writer_bits::ValueStorage<Arc, Converter>(arc, converter);
1.605 + _writer_bits::ValueStorageBase* storage =
1.606 + new _writer_bits::ValueStorage<Arc, Converter>(arc, converter);
1.607 _attributes.push_back(std::make_pair(caption, storage));
1.608 return *this;
1.609 }
1.610 @@ -641,175 +641,175 @@
1.611 void writeNodes() {
1.612 _writer_bits::MapStorageBase<Node>* label = 0;
1.613 for (typename NodeMaps::iterator it = _node_maps.begin();
1.614 - it != _node_maps.end(); ++it) {
1.615 + it != _node_maps.end(); ++it) {
1.616 if (it->first == "label") {
1.617 - label = it->second;
1.618 - break;
1.619 - }
1.620 + label = it->second;
1.621 + break;
1.622 + }
1.623 }
1.624
1.625 *_os << "@nodes";
1.626 if (!_nodes_caption.empty()) {
1.627 - _writer_bits::writeToken(*_os << ' ', _nodes_caption);
1.628 + _writer_bits::writeToken(*_os << ' ', _nodes_caption);
1.629 }
1.630 *_os << std::endl;
1.631
1.632 if (label == 0) {
1.633 - *_os << "label" << '\t';
1.634 + *_os << "label" << '\t';
1.635 }
1.636 for (typename NodeMaps::iterator it = _node_maps.begin();
1.637 - it != _node_maps.end(); ++it) {
1.638 - _writer_bits::writeToken(*_os, it->first) << '\t';
1.639 + it != _node_maps.end(); ++it) {
1.640 + _writer_bits::writeToken(*_os, it->first) << '\t';
1.641 }
1.642 *_os << std::endl;
1.643
1.644 std::vector<Node> nodes;
1.645 for (NodeIt n(_digraph); n != INVALID; ++n) {
1.646 - nodes.push_back(n);
1.647 + nodes.push_back(n);
1.648 }
1.649 -
1.650 +
1.651 if (label == 0) {
1.652 - IdMap<Digraph, Node> id_map(_digraph);
1.653 - _writer_bits::MapLess<IdMap<Digraph, Node> > id_less(id_map);
1.654 - std::sort(nodes.begin(), nodes.end(), id_less);
1.655 + IdMap<Digraph, Node> id_map(_digraph);
1.656 + _writer_bits::MapLess<IdMap<Digraph, Node> > id_less(id_map);
1.657 + std::sort(nodes.begin(), nodes.end(), id_less);
1.658 } else {
1.659 - label->sort(nodes);
1.660 + label->sort(nodes);
1.661 }
1.662
1.663 for (int i = 0; i < static_cast<int>(nodes.size()); ++i) {
1.664 - Node n = nodes[i];
1.665 - if (label == 0) {
1.666 - std::ostringstream os;
1.667 - os << _digraph.id(n);
1.668 - _writer_bits::writeToken(*_os, os.str());
1.669 - *_os << '\t';
1.670 - _node_index.insert(std::make_pair(n, os.str()));
1.671 - }
1.672 - for (typename NodeMaps::iterator it = _node_maps.begin();
1.673 - it != _node_maps.end(); ++it) {
1.674 - std::string value = it->second->get(n);
1.675 - _writer_bits::writeToken(*_os, value);
1.676 - if (it->first == "label") {
1.677 - _node_index.insert(std::make_pair(n, value));
1.678 - }
1.679 - *_os << '\t';
1.680 - }
1.681 - *_os << std::endl;
1.682 + Node n = nodes[i];
1.683 + if (label == 0) {
1.684 + std::ostringstream os;
1.685 + os << _digraph.id(n);
1.686 + _writer_bits::writeToken(*_os, os.str());
1.687 + *_os << '\t';
1.688 + _node_index.insert(std::make_pair(n, os.str()));
1.689 + }
1.690 + for (typename NodeMaps::iterator it = _node_maps.begin();
1.691 + it != _node_maps.end(); ++it) {
1.692 + std::string value = it->second->get(n);
1.693 + _writer_bits::writeToken(*_os, value);
1.694 + if (it->first == "label") {
1.695 + _node_index.insert(std::make_pair(n, value));
1.696 + }
1.697 + *_os << '\t';
1.698 + }
1.699 + *_os << std::endl;
1.700 }
1.701 }
1.702
1.703 void createNodeIndex() {
1.704 _writer_bits::MapStorageBase<Node>* label = 0;
1.705 for (typename NodeMaps::iterator it = _node_maps.begin();
1.706 - it != _node_maps.end(); ++it) {
1.707 + it != _node_maps.end(); ++it) {
1.708 if (it->first == "label") {
1.709 - label = it->second;
1.710 - break;
1.711 - }
1.712 + label = it->second;
1.713 + break;
1.714 + }
1.715 }
1.716
1.717 if (label == 0) {
1.718 - for (NodeIt n(_digraph); n != INVALID; ++n) {
1.719 - std::ostringstream os;
1.720 - os << _digraph.id(n);
1.721 - _node_index.insert(std::make_pair(n, os.str()));
1.722 - }
1.723 + for (NodeIt n(_digraph); n != INVALID; ++n) {
1.724 + std::ostringstream os;
1.725 + os << _digraph.id(n);
1.726 + _node_index.insert(std::make_pair(n, os.str()));
1.727 + }
1.728 } else {
1.729 - for (NodeIt n(_digraph); n != INVALID; ++n) {
1.730 - std::string value = label->get(n);
1.731 - _node_index.insert(std::make_pair(n, value));
1.732 - }
1.733 + for (NodeIt n(_digraph); n != INVALID; ++n) {
1.734 + std::string value = label->get(n);
1.735 + _node_index.insert(std::make_pair(n, value));
1.736 + }
1.737 }
1.738 }
1.739
1.740 void writeArcs() {
1.741 _writer_bits::MapStorageBase<Arc>* label = 0;
1.742 for (typename ArcMaps::iterator it = _arc_maps.begin();
1.743 - it != _arc_maps.end(); ++it) {
1.744 + it != _arc_maps.end(); ++it) {
1.745 if (it->first == "label") {
1.746 - label = it->second;
1.747 - break;
1.748 - }
1.749 + label = it->second;
1.750 + break;
1.751 + }
1.752 }
1.753
1.754 *_os << "@arcs";
1.755 if (!_arcs_caption.empty()) {
1.756 - _writer_bits::writeToken(*_os << ' ', _arcs_caption);
1.757 + _writer_bits::writeToken(*_os << ' ', _arcs_caption);
1.758 }
1.759 *_os << std::endl;
1.760
1.761 *_os << '\t' << '\t';
1.762 if (label == 0) {
1.763 - *_os << "label" << '\t';
1.764 + *_os << "label" << '\t';
1.765 }
1.766 for (typename ArcMaps::iterator it = _arc_maps.begin();
1.767 - it != _arc_maps.end(); ++it) {
1.768 - _writer_bits::writeToken(*_os, it->first) << '\t';
1.769 + it != _arc_maps.end(); ++it) {
1.770 + _writer_bits::writeToken(*_os, it->first) << '\t';
1.771 }
1.772 *_os << std::endl;
1.773
1.774 std::vector<Arc> arcs;
1.775 for (ArcIt n(_digraph); n != INVALID; ++n) {
1.776 - arcs.push_back(n);
1.777 + arcs.push_back(n);
1.778 }
1.779 -
1.780 +
1.781 if (label == 0) {
1.782 - IdMap<Digraph, Arc> id_map(_digraph);
1.783 - _writer_bits::MapLess<IdMap<Digraph, Arc> > id_less(id_map);
1.784 - std::sort(arcs.begin(), arcs.end(), id_less);
1.785 + IdMap<Digraph, Arc> id_map(_digraph);
1.786 + _writer_bits::MapLess<IdMap<Digraph, Arc> > id_less(id_map);
1.787 + std::sort(arcs.begin(), arcs.end(), id_less);
1.788 } else {
1.789 - label->sort(arcs);
1.790 + label->sort(arcs);
1.791 }
1.792
1.793 for (int i = 0; i < static_cast<int>(arcs.size()); ++i) {
1.794 - Arc a = arcs[i];
1.795 - _writer_bits::writeToken(*_os, _node_index.
1.796 - find(_digraph.source(a))->second);
1.797 - *_os << '\t';
1.798 - _writer_bits::writeToken(*_os, _node_index.
1.799 - find(_digraph.target(a))->second);
1.800 - *_os << '\t';
1.801 - if (label == 0) {
1.802 - std::ostringstream os;
1.803 - os << _digraph.id(a);
1.804 - _writer_bits::writeToken(*_os, os.str());
1.805 - *_os << '\t';
1.806 - _arc_index.insert(std::make_pair(a, os.str()));
1.807 - }
1.808 - for (typename ArcMaps::iterator it = _arc_maps.begin();
1.809 - it != _arc_maps.end(); ++it) {
1.810 - std::string value = it->second->get(a);
1.811 - _writer_bits::writeToken(*_os, value);
1.812 - if (it->first == "label") {
1.813 - _arc_index.insert(std::make_pair(a, value));
1.814 - }
1.815 - *_os << '\t';
1.816 - }
1.817 - *_os << std::endl;
1.818 + Arc a = arcs[i];
1.819 + _writer_bits::writeToken(*_os, _node_index.
1.820 + find(_digraph.source(a))->second);
1.821 + *_os << '\t';
1.822 + _writer_bits::writeToken(*_os, _node_index.
1.823 + find(_digraph.target(a))->second);
1.824 + *_os << '\t';
1.825 + if (label == 0) {
1.826 + std::ostringstream os;
1.827 + os << _digraph.id(a);
1.828 + _writer_bits::writeToken(*_os, os.str());
1.829 + *_os << '\t';
1.830 + _arc_index.insert(std::make_pair(a, os.str()));
1.831 + }
1.832 + for (typename ArcMaps::iterator it = _arc_maps.begin();
1.833 + it != _arc_maps.end(); ++it) {
1.834 + std::string value = it->second->get(a);
1.835 + _writer_bits::writeToken(*_os, value);
1.836 + if (it->first == "label") {
1.837 + _arc_index.insert(std::make_pair(a, value));
1.838 + }
1.839 + *_os << '\t';
1.840 + }
1.841 + *_os << std::endl;
1.842 }
1.843 }
1.844
1.845 void createArcIndex() {
1.846 _writer_bits::MapStorageBase<Arc>* label = 0;
1.847 for (typename ArcMaps::iterator it = _arc_maps.begin();
1.848 - it != _arc_maps.end(); ++it) {
1.849 + it != _arc_maps.end(); ++it) {
1.850 if (it->first == "label") {
1.851 - label = it->second;
1.852 - break;
1.853 - }
1.854 + label = it->second;
1.855 + break;
1.856 + }
1.857 }
1.858
1.859 if (label == 0) {
1.860 - for (ArcIt a(_digraph); a != INVALID; ++a) {
1.861 - std::ostringstream os;
1.862 - os << _digraph.id(a);
1.863 - _arc_index.insert(std::make_pair(a, os.str()));
1.864 - }
1.865 + for (ArcIt a(_digraph); a != INVALID; ++a) {
1.866 + std::ostringstream os;
1.867 + os << _digraph.id(a);
1.868 + _arc_index.insert(std::make_pair(a, os.str()));
1.869 + }
1.870 } else {
1.871 - for (ArcIt a(_digraph); a != INVALID; ++a) {
1.872 - std::string value = label->get(a);
1.873 - _arc_index.insert(std::make_pair(a, value));
1.874 - }
1.875 + for (ArcIt a(_digraph); a != INVALID; ++a) {
1.876 + std::string value = label->get(a);
1.877 + _arc_index.insert(std::make_pair(a, value));
1.878 + }
1.879 }
1.880 }
1.881
1.882 @@ -817,20 +817,20 @@
1.883 if (_attributes.empty()) return;
1.884 *_os << "@attributes";
1.885 if (!_attributes_caption.empty()) {
1.886 - _writer_bits::writeToken(*_os << ' ', _attributes_caption);
1.887 + _writer_bits::writeToken(*_os << ' ', _attributes_caption);
1.888 }
1.889 *_os << std::endl;
1.890 for (typename Attributes::iterator it = _attributes.begin();
1.891 - it != _attributes.end(); ++it) {
1.892 - _writer_bits::writeToken(*_os, it->first) << ' ';
1.893 - _writer_bits::writeToken(*_os, it->second->get());
1.894 - *_os << std::endl;
1.895 + it != _attributes.end(); ++it) {
1.896 + _writer_bits::writeToken(*_os, it->first) << ' ';
1.897 + _writer_bits::writeToken(*_os, it->second->get());
1.898 + *_os << std::endl;
1.899 }
1.900 }
1.901 -
1.902 +
1.903 public:
1.904 -
1.905 - /// \name Execution of the writer
1.906 +
1.907 + /// \name Execution of the writer
1.908 /// @{
1.909
1.910 /// \brief Start the batch processing
1.911 @@ -838,14 +838,14 @@
1.912 /// This function starts the batch processing.
1.913 void run() {
1.914 if (!_skip_nodes) {
1.915 - writeNodes();
1.916 + writeNodes();
1.917 } else {
1.918 - createNodeIndex();
1.919 + createNodeIndex();
1.920 }
1.921 - if (!_skip_arcs) {
1.922 - writeArcs();
1.923 + if (!_skip_arcs) {
1.924 + writeArcs();
1.925 } else {
1.926 - createArcIndex();
1.927 + createArcIndex();
1.928 }
1.929 writeAttributes();
1.930 }
1.931 @@ -861,34 +861,34 @@
1.932 };
1.933
1.934 /// \brief Return a \ref DigraphWriter class
1.935 - ///
1.936 + ///
1.937 /// This function just returns a \ref DigraphWriter class.
1.938 /// \relates DigraphWriter
1.939 template <typename Digraph>
1.940 - DigraphWriter<Digraph> digraphWriter(std::ostream& os,
1.941 - const Digraph& digraph) {
1.942 + DigraphWriter<Digraph> digraphWriter(std::ostream& os,
1.943 + const Digraph& digraph) {
1.944 DigraphWriter<Digraph> tmp(os, digraph);
1.945 return tmp;
1.946 }
1.947
1.948 /// \brief Return a \ref DigraphWriter class
1.949 - ///
1.950 + ///
1.951 /// This function just returns a \ref DigraphWriter class.
1.952 /// \relates DigraphWriter
1.953 template <typename Digraph>
1.954 - DigraphWriter<Digraph> digraphWriter(const std::string& fn,
1.955 - const Digraph& digraph) {
1.956 + DigraphWriter<Digraph> digraphWriter(const std::string& fn,
1.957 + const Digraph& digraph) {
1.958 DigraphWriter<Digraph> tmp(fn, digraph);
1.959 return tmp;
1.960 }
1.961
1.962 /// \brief Return a \ref DigraphWriter class
1.963 - ///
1.964 + ///
1.965 /// This function just returns a \ref DigraphWriter class.
1.966 /// \relates DigraphWriter
1.967 template <typename Digraph>
1.968 - DigraphWriter<Digraph> digraphWriter(const char* fn,
1.969 - const Digraph& digraph) {
1.970 + DigraphWriter<Digraph> digraphWriter(const char* fn,
1.971 + const Digraph& digraph) {
1.972 DigraphWriter<Digraph> tmp(fn, digraph);
1.973 return tmp;
1.974 }
1.975 @@ -897,16 +897,16 @@
1.976 class GraphWriter;
1.977
1.978 template <typename Graph>
1.979 - GraphWriter<Graph> graphWriter(std::ostream& os, const Graph& graph);
1.980 + GraphWriter<Graph> graphWriter(std::ostream& os, const Graph& graph);
1.981
1.982 template <typename Graph>
1.983 - GraphWriter<Graph> graphWriter(const std::string& fn, const Graph& graph);
1.984 + GraphWriter<Graph> graphWriter(const std::string& fn, const Graph& graph);
1.985
1.986 template <typename Graph>
1.987 - GraphWriter<Graph> graphWriter(const char *fn, const Graph& graph);
1.988 + GraphWriter<Graph> graphWriter(const char *fn, const Graph& graph);
1.989
1.990 /// \ingroup lemon_io
1.991 - ///
1.992 + ///
1.993 /// \brief \ref lgf-format "LGF" writer for directed graphs
1.994 ///
1.995 /// This utility writes an \ref lgf-format "LGF" file.
1.996 @@ -926,7 +926,7 @@
1.997
1.998 typedef _Graph Graph;
1.999 TEMPLATE_GRAPH_TYPEDEFS(Graph);
1.1000 -
1.1001 +
1.1002 private:
1.1003
1.1004
1.1005 @@ -938,21 +938,21 @@
1.1006 std::string _nodes_caption;
1.1007 std::string _edges_caption;
1.1008 std::string _attributes_caption;
1.1009 -
1.1010 +
1.1011 typedef std::map<Node, std::string> NodeIndex;
1.1012 NodeIndex _node_index;
1.1013 typedef std::map<Edge, std::string> EdgeIndex;
1.1014 EdgeIndex _edge_index;
1.1015
1.1016 - typedef std::vector<std::pair<std::string,
1.1017 - _writer_bits::MapStorageBase<Node>* > > NodeMaps;
1.1018 - NodeMaps _node_maps;
1.1019 + typedef std::vector<std::pair<std::string,
1.1020 + _writer_bits::MapStorageBase<Node>* > > NodeMaps;
1.1021 + NodeMaps _node_maps;
1.1022
1.1023 - typedef std::vector<std::pair<std::string,
1.1024 + typedef std::vector<std::pair<std::string,
1.1025 _writer_bits::MapStorageBase<Edge>* > >EdgeMaps;
1.1026 EdgeMaps _edge_maps;
1.1027
1.1028 - typedef std::vector<std::pair<std::string,
1.1029 + typedef std::vector<std::pair<std::string,
1.1030 _writer_bits::ValueStorageBase*> > Attributes;
1.1031 Attributes _attributes;
1.1032
1.1033 @@ -965,60 +965,60 @@
1.1034 ///
1.1035 /// Construct a directed graph writer, which writes to the given
1.1036 /// output stream.
1.1037 - GraphWriter(std::ostream& is, const Graph& graph)
1.1038 + GraphWriter(std::ostream& is, const Graph& graph)
1.1039 : _os(&is), local_os(false), _graph(graph),
1.1040 - _skip_nodes(false), _skip_edges(false) {}
1.1041 + _skip_nodes(false), _skip_edges(false) {}
1.1042
1.1043 /// \brief Constructor
1.1044 ///
1.1045 /// Construct a directed graph writer, which writes to the given
1.1046 /// output file.
1.1047 - GraphWriter(const std::string& fn, const Graph& graph)
1.1048 + GraphWriter(const std::string& fn, const Graph& graph)
1.1049 : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph),
1.1050 - _skip_nodes(false), _skip_edges(false) {}
1.1051 + _skip_nodes(false), _skip_edges(false) {}
1.1052
1.1053 /// \brief Constructor
1.1054 ///
1.1055 /// Construct a directed graph writer, which writes to the given
1.1056 /// output file.
1.1057 - GraphWriter(const char* fn, const Graph& graph)
1.1058 + GraphWriter(const char* fn, const Graph& graph)
1.1059 : _os(new std::ofstream(fn)), local_os(true), _graph(graph),
1.1060 - _skip_nodes(false), _skip_edges(false) {}
1.1061 + _skip_nodes(false), _skip_edges(false) {}
1.1062
1.1063 /// \brief Destructor
1.1064 ~GraphWriter() {
1.1065 - for (typename NodeMaps::iterator it = _node_maps.begin();
1.1066 - it != _node_maps.end(); ++it) {
1.1067 - delete it->second;
1.1068 + for (typename NodeMaps::iterator it = _node_maps.begin();
1.1069 + it != _node_maps.end(); ++it) {
1.1070 + delete it->second;
1.1071 }
1.1072
1.1073 - for (typename EdgeMaps::iterator it = _edge_maps.begin();
1.1074 - it != _edge_maps.end(); ++it) {
1.1075 - delete it->second;
1.1076 + for (typename EdgeMaps::iterator it = _edge_maps.begin();
1.1077 + it != _edge_maps.end(); ++it) {
1.1078 + delete it->second;
1.1079 }
1.1080
1.1081 - for (typename Attributes::iterator it = _attributes.begin();
1.1082 - it != _attributes.end(); ++it) {
1.1083 - delete it->second;
1.1084 + for (typename Attributes::iterator it = _attributes.begin();
1.1085 + it != _attributes.end(); ++it) {
1.1086 + delete it->second;
1.1087 }
1.1088
1.1089 if (local_os) {
1.1090 - delete _os;
1.1091 + delete _os;
1.1092 }
1.1093 }
1.1094 -
1.1095 +
1.1096 private:
1.1097
1.1098 - friend GraphWriter<Graph> graphWriter<>(std::ostream& os,
1.1099 - const Graph& graph);
1.1100 - friend GraphWriter<Graph> graphWriter<>(const std::string& fn,
1.1101 - const Graph& graph);
1.1102 - friend GraphWriter<Graph> graphWriter<>(const char *fn,
1.1103 - const Graph& graph);
1.1104 + friend GraphWriter<Graph> graphWriter<>(std::ostream& os,
1.1105 + const Graph& graph);
1.1106 + friend GraphWriter<Graph> graphWriter<>(const std::string& fn,
1.1107 + const Graph& graph);
1.1108 + friend GraphWriter<Graph> graphWriter<>(const char *fn,
1.1109 + const Graph& graph);
1.1110
1.1111 - GraphWriter(GraphWriter& other)
1.1112 + GraphWriter(GraphWriter& other)
1.1113 : _os(other._os), local_os(other.local_os), _graph(other._graph),
1.1114 - _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
1.1115 + _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
1.1116
1.1117 other._os = 0;
1.1118 other.local_os = false;
1.1119 @@ -1041,15 +1041,15 @@
1.1120
1.1121 /// \name Writing rules
1.1122 /// @{
1.1123 -
1.1124 +
1.1125 /// \brief Node map writing rule
1.1126 ///
1.1127 /// Add a node map writing rule to the writer.
1.1128 template <typename Map>
1.1129 GraphWriter& nodeMap(const std::string& caption, const Map& map) {
1.1130 checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
1.1131 - _writer_bits::MapStorageBase<Node>* storage =
1.1132 - new _writer_bits::MapStorage<Node, Map>(map);
1.1133 + _writer_bits::MapStorageBase<Node>* storage =
1.1134 + new _writer_bits::MapStorage<Node, Map>(map);
1.1135 _node_maps.push_back(std::make_pair(caption, storage));
1.1136 return *this;
1.1137 }
1.1138 @@ -1059,11 +1059,11 @@
1.1139 /// Add a node map writing rule with specialized converter to the
1.1140 /// writer.
1.1141 template <typename Map, typename Converter>
1.1142 - GraphWriter& nodeMap(const std::string& caption, const Map& map,
1.1143 - const Converter& converter = Converter()) {
1.1144 + GraphWriter& nodeMap(const std::string& caption, const Map& map,
1.1145 + const Converter& converter = Converter()) {
1.1146 checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
1.1147 - _writer_bits::MapStorageBase<Node>* storage =
1.1148 - new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
1.1149 + _writer_bits::MapStorageBase<Node>* storage =
1.1150 + new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
1.1151 _node_maps.push_back(std::make_pair(caption, storage));
1.1152 return *this;
1.1153 }
1.1154 @@ -1074,8 +1074,8 @@
1.1155 template <typename Map>
1.1156 GraphWriter& edgeMap(const std::string& caption, const Map& map) {
1.1157 checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>();
1.1158 - _writer_bits::MapStorageBase<Edge>* storage =
1.1159 - new _writer_bits::MapStorage<Edge, Map>(map);
1.1160 + _writer_bits::MapStorageBase<Edge>* storage =
1.1161 + new _writer_bits::MapStorage<Edge, Map>(map);
1.1162 _edge_maps.push_back(std::make_pair(caption, storage));
1.1163 return *this;
1.1164 }
1.1165 @@ -1085,11 +1085,11 @@
1.1166 /// Add an edge map writing rule with specialized converter to the
1.1167 /// writer.
1.1168 template <typename Map, typename Converter>
1.1169 - GraphWriter& edgeMap(const std::string& caption, const Map& map,
1.1170 - const Converter& converter = Converter()) {
1.1171 + GraphWriter& edgeMap(const std::string& caption, const Map& map,
1.1172 + const Converter& converter = Converter()) {
1.1173 checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>();
1.1174 - _writer_bits::MapStorageBase<Edge>* storage =
1.1175 - new _writer_bits::MapStorage<Edge, Map, Converter>(map, converter);
1.1176 + _writer_bits::MapStorageBase<Edge>* storage =
1.1177 + new _writer_bits::MapStorage<Edge, Map, Converter>(map, converter);
1.1178 _edge_maps.push_back(std::make_pair(caption, storage));
1.1179 return *this;
1.1180 }
1.1181 @@ -1100,11 +1100,11 @@
1.1182 template <typename Map>
1.1183 GraphWriter& arcMap(const std::string& caption, const Map& map) {
1.1184 checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
1.1185 - _writer_bits::MapStorageBase<Edge>* forward_storage =
1.1186 - new _writer_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map);
1.1187 + _writer_bits::MapStorageBase<Edge>* forward_storage =
1.1188 + new _writer_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map);
1.1189 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
1.1190 - _writer_bits::MapStorageBase<Edge>* backward_storage =
1.1191 - new _writer_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map);
1.1192 + _writer_bits::MapStorageBase<Edge>* backward_storage =
1.1193 + new _writer_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map);
1.1194 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
1.1195 return *this;
1.1196 }
1.1197 @@ -1114,16 +1114,16 @@
1.1198 /// Add an arc map writing rule with specialized converter to the
1.1199 /// writer.
1.1200 template <typename Map, typename Converter>
1.1201 - GraphWriter& arcMap(const std::string& caption, const Map& map,
1.1202 - const Converter& converter = Converter()) {
1.1203 + GraphWriter& arcMap(const std::string& caption, const Map& map,
1.1204 + const Converter& converter = Converter()) {
1.1205 checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
1.1206 - _writer_bits::MapStorageBase<Edge>* forward_storage =
1.1207 - new _writer_bits::GraphArcMapStorage<Graph, true, Map, Converter>
1.1208 - (_graph, map, converter);
1.1209 + _writer_bits::MapStorageBase<Edge>* forward_storage =
1.1210 + new _writer_bits::GraphArcMapStorage<Graph, true, Map, Converter>
1.1211 + (_graph, map, converter);
1.1212 _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
1.1213 - _writer_bits::MapStorageBase<Edge>* backward_storage =
1.1214 - new _writer_bits::GraphArcMapStorage<Graph, false, Map, Converter>
1.1215 - (_graph, map, converter);
1.1216 + _writer_bits::MapStorageBase<Edge>* backward_storage =
1.1217 + new _writer_bits::GraphArcMapStorage<Graph, false, Map, Converter>
1.1218 + (_graph, map, converter);
1.1219 _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
1.1220 return *this;
1.1221 }
1.1222 @@ -1133,8 +1133,8 @@
1.1223 /// Add an attribute writing rule to the writer.
1.1224 template <typename Value>
1.1225 GraphWriter& attribute(const std::string& caption, const Value& value) {
1.1226 - _writer_bits::ValueStorageBase* storage =
1.1227 - new _writer_bits::ValueStorage<Value>(value);
1.1228 + _writer_bits::ValueStorageBase* storage =
1.1229 + new _writer_bits::ValueStorage<Value>(value);
1.1230 _attributes.push_back(std::make_pair(caption, storage));
1.1231 return *this;
1.1232 }
1.1233 @@ -1144,10 +1144,10 @@
1.1234 /// Add an attribute writing rule with specialized converter to the
1.1235 /// writer.
1.1236 template <typename Value, typename Converter>
1.1237 - GraphWriter& attribute(const std::string& caption, const Value& value,
1.1238 - const Converter& converter = Converter()) {
1.1239 - _writer_bits::ValueStorageBase* storage =
1.1240 - new _writer_bits::ValueStorage<Value, Converter>(value, converter);
1.1241 + GraphWriter& attribute(const std::string& caption, const Value& value,
1.1242 + const Converter& converter = Converter()) {
1.1243 + _writer_bits::ValueStorageBase* storage =
1.1244 + new _writer_bits::ValueStorage<Value, Converter>(value, converter);
1.1245 _attributes.push_back(std::make_pair(caption, storage));
1.1246 return *this;
1.1247 }
1.1248 @@ -1158,8 +1158,8 @@
1.1249 GraphWriter& node(const std::string& caption, const Node& node) {
1.1250 typedef _writer_bits::MapLookUpConverter<Node> Converter;
1.1251 Converter converter(_node_index);
1.1252 - _writer_bits::ValueStorageBase* storage =
1.1253 - new _writer_bits::ValueStorage<Node, Converter>(node, converter);
1.1254 + _writer_bits::ValueStorageBase* storage =
1.1255 + new _writer_bits::ValueStorage<Node, Converter>(node, converter);
1.1256 _attributes.push_back(std::make_pair(caption, storage));
1.1257 return *this;
1.1258 }
1.1259 @@ -1170,8 +1170,8 @@
1.1260 GraphWriter& edge(const std::string& caption, const Edge& edge) {
1.1261 typedef _writer_bits::MapLookUpConverter<Edge> Converter;
1.1262 Converter converter(_edge_index);
1.1263 - _writer_bits::ValueStorageBase* storage =
1.1264 - new _writer_bits::ValueStorage<Edge, Converter>(edge, converter);
1.1265 + _writer_bits::ValueStorageBase* storage =
1.1266 + new _writer_bits::ValueStorage<Edge, Converter>(edge, converter);
1.1267 _attributes.push_back(std::make_pair(caption, storage));
1.1268 return *this;
1.1269 }
1.1270 @@ -1182,8 +1182,8 @@
1.1271 GraphWriter& arc(const std::string& caption, const Arc& arc) {
1.1272 typedef _writer_bits::GraphArcLookUpConverter<Graph> Converter;
1.1273 Converter converter(_graph, _edge_index);
1.1274 - _writer_bits::ValueStorageBase* storage =
1.1275 - new _writer_bits::ValueStorage<Arc, Converter>(arc, converter);
1.1276 + _writer_bits::ValueStorageBase* storage =
1.1277 + new _writer_bits::ValueStorage<Arc, Converter>(arc, converter);
1.1278 _attributes.push_back(std::make_pair(caption, storage));
1.1279 return *this;
1.1280 }
1.1281 @@ -1243,175 +1243,175 @@
1.1282 void writeNodes() {
1.1283 _writer_bits::MapStorageBase<Node>* label = 0;
1.1284 for (typename NodeMaps::iterator it = _node_maps.begin();
1.1285 - it != _node_maps.end(); ++it) {
1.1286 + it != _node_maps.end(); ++it) {
1.1287 if (it->first == "label") {
1.1288 - label = it->second;
1.1289 - break;
1.1290 - }
1.1291 + label = it->second;
1.1292 + break;
1.1293 + }
1.1294 }
1.1295
1.1296 *_os << "@nodes";
1.1297 if (!_nodes_caption.empty()) {
1.1298 - _writer_bits::writeToken(*_os << ' ', _nodes_caption);
1.1299 + _writer_bits::writeToken(*_os << ' ', _nodes_caption);
1.1300 }
1.1301 *_os << std::endl;
1.1302
1.1303 if (label == 0) {
1.1304 - *_os << "label" << '\t';
1.1305 + *_os << "label" << '\t';
1.1306 }
1.1307 for (typename NodeMaps::iterator it = _node_maps.begin();
1.1308 - it != _node_maps.end(); ++it) {
1.1309 - _writer_bits::writeToken(*_os, it->first) << '\t';
1.1310 + it != _node_maps.end(); ++it) {
1.1311 + _writer_bits::writeToken(*_os, it->first) << '\t';
1.1312 }
1.1313 *_os << std::endl;
1.1314
1.1315 std::vector<Node> nodes;
1.1316 for (NodeIt n(_graph); n != INVALID; ++n) {
1.1317 - nodes.push_back(n);
1.1318 + nodes.push_back(n);
1.1319 }
1.1320 -
1.1321 +
1.1322 if (label == 0) {
1.1323 - IdMap<Graph, Node> id_map(_graph);
1.1324 - _writer_bits::MapLess<IdMap<Graph, Node> > id_less(id_map);
1.1325 - std::sort(nodes.begin(), nodes.end(), id_less);
1.1326 + IdMap<Graph, Node> id_map(_graph);
1.1327 + _writer_bits::MapLess<IdMap<Graph, Node> > id_less(id_map);
1.1328 + std::sort(nodes.begin(), nodes.end(), id_less);
1.1329 } else {
1.1330 - label->sort(nodes);
1.1331 + label->sort(nodes);
1.1332 }
1.1333
1.1334 for (int i = 0; i < static_cast<int>(nodes.size()); ++i) {
1.1335 - Node n = nodes[i];
1.1336 - if (label == 0) {
1.1337 - std::ostringstream os;
1.1338 - os << _graph.id(n);
1.1339 - _writer_bits::writeToken(*_os, os.str());
1.1340 - *_os << '\t';
1.1341 - _node_index.insert(std::make_pair(n, os.str()));
1.1342 - }
1.1343 - for (typename NodeMaps::iterator it = _node_maps.begin();
1.1344 - it != _node_maps.end(); ++it) {
1.1345 - std::string value = it->second->get(n);
1.1346 - _writer_bits::writeToken(*_os, value);
1.1347 - if (it->first == "label") {
1.1348 - _node_index.insert(std::make_pair(n, value));
1.1349 - }
1.1350 - *_os << '\t';
1.1351 - }
1.1352 - *_os << std::endl;
1.1353 + Node n = nodes[i];
1.1354 + if (label == 0) {
1.1355 + std::ostringstream os;
1.1356 + os << _graph.id(n);
1.1357 + _writer_bits::writeToken(*_os, os.str());
1.1358 + *_os << '\t';
1.1359 + _node_index.insert(std::make_pair(n, os.str()));
1.1360 + }
1.1361 + for (typename NodeMaps::iterator it = _node_maps.begin();
1.1362 + it != _node_maps.end(); ++it) {
1.1363 + std::string value = it->second->get(n);
1.1364 + _writer_bits::writeToken(*_os, value);
1.1365 + if (it->first == "label") {
1.1366 + _node_index.insert(std::make_pair(n, value));
1.1367 + }
1.1368 + *_os << '\t';
1.1369 + }
1.1370 + *_os << std::endl;
1.1371 }
1.1372 }
1.1373
1.1374 void createNodeIndex() {
1.1375 _writer_bits::MapStorageBase<Node>* label = 0;
1.1376 for (typename NodeMaps::iterator it = _node_maps.begin();
1.1377 - it != _node_maps.end(); ++it) {
1.1378 + it != _node_maps.end(); ++it) {
1.1379 if (it->first == "label") {
1.1380 - label = it->second;
1.1381 - break;
1.1382 - }
1.1383 + label = it->second;
1.1384 + break;
1.1385 + }
1.1386 }
1.1387
1.1388 if (label == 0) {
1.1389 - for (NodeIt n(_graph); n != INVALID; ++n) {
1.1390 - std::ostringstream os;
1.1391 - os << _graph.id(n);
1.1392 - _node_index.insert(std::make_pair(n, os.str()));
1.1393 - }
1.1394 + for (NodeIt n(_graph); n != INVALID; ++n) {
1.1395 + std::ostringstream os;
1.1396 + os << _graph.id(n);
1.1397 + _node_index.insert(std::make_pair(n, os.str()));
1.1398 + }
1.1399 } else {
1.1400 - for (NodeIt n(_graph); n != INVALID; ++n) {
1.1401 - std::string value = label->get(n);
1.1402 - _node_index.insert(std::make_pair(n, value));
1.1403 - }
1.1404 + for (NodeIt n(_graph); n != INVALID; ++n) {
1.1405 + std::string value = label->get(n);
1.1406 + _node_index.insert(std::make_pair(n, value));
1.1407 + }
1.1408 }
1.1409 }
1.1410
1.1411 void writeEdges() {
1.1412 _writer_bits::MapStorageBase<Edge>* label = 0;
1.1413 for (typename EdgeMaps::iterator it = _edge_maps.begin();
1.1414 - it != _edge_maps.end(); ++it) {
1.1415 + it != _edge_maps.end(); ++it) {
1.1416 if (it->first == "label") {
1.1417 - label = it->second;
1.1418 - break;
1.1419 - }
1.1420 + label = it->second;
1.1421 + break;
1.1422 + }
1.1423 }
1.1424
1.1425 *_os << "@edges";
1.1426 if (!_edges_caption.empty()) {
1.1427 - _writer_bits::writeToken(*_os << ' ', _edges_caption);
1.1428 + _writer_bits::writeToken(*_os << ' ', _edges_caption);
1.1429 }
1.1430 *_os << std::endl;
1.1431
1.1432 *_os << '\t' << '\t';
1.1433 if (label == 0) {
1.1434 - *_os << "label" << '\t';
1.1435 + *_os << "label" << '\t';
1.1436 }
1.1437 for (typename EdgeMaps::iterator it = _edge_maps.begin();
1.1438 - it != _edge_maps.end(); ++it) {
1.1439 - _writer_bits::writeToken(*_os, it->first) << '\t';
1.1440 + it != _edge_maps.end(); ++it) {
1.1441 + _writer_bits::writeToken(*_os, it->first) << '\t';
1.1442 }
1.1443 *_os << std::endl;
1.1444
1.1445 std::vector<Edge> edges;
1.1446 for (EdgeIt n(_graph); n != INVALID; ++n) {
1.1447 - edges.push_back(n);
1.1448 + edges.push_back(n);
1.1449 }
1.1450 -
1.1451 +
1.1452 if (label == 0) {
1.1453 - IdMap<Graph, Edge> id_map(_graph);
1.1454 - _writer_bits::MapLess<IdMap<Graph, Edge> > id_less(id_map);
1.1455 - std::sort(edges.begin(), edges.end(), id_less);
1.1456 + IdMap<Graph, Edge> id_map(_graph);
1.1457 + _writer_bits::MapLess<IdMap<Graph, Edge> > id_less(id_map);
1.1458 + std::sort(edges.begin(), edges.end(), id_less);
1.1459 } else {
1.1460 - label->sort(edges);
1.1461 + label->sort(edges);
1.1462 }
1.1463
1.1464 for (int i = 0; i < static_cast<int>(edges.size()); ++i) {
1.1465 - Edge e = edges[i];
1.1466 - _writer_bits::writeToken(*_os, _node_index.
1.1467 - find(_graph.u(e))->second);
1.1468 - *_os << '\t';
1.1469 - _writer_bits::writeToken(*_os, _node_index.
1.1470 - find(_graph.v(e))->second);
1.1471 - *_os << '\t';
1.1472 - if (label == 0) {
1.1473 - std::ostringstream os;
1.1474 - os << _graph.id(e);
1.1475 - _writer_bits::writeToken(*_os, os.str());
1.1476 - *_os << '\t';
1.1477 - _edge_index.insert(std::make_pair(e, os.str()));
1.1478 - }
1.1479 - for (typename EdgeMaps::iterator it = _edge_maps.begin();
1.1480 - it != _edge_maps.end(); ++it) {
1.1481 - std::string value = it->second->get(e);
1.1482 - _writer_bits::writeToken(*_os, value);
1.1483 - if (it->first == "label") {
1.1484 - _edge_index.insert(std::make_pair(e, value));
1.1485 - }
1.1486 - *_os << '\t';
1.1487 - }
1.1488 - *_os << std::endl;
1.1489 + Edge e = edges[i];
1.1490 + _writer_bits::writeToken(*_os, _node_index.
1.1491 + find(_graph.u(e))->second);
1.1492 + *_os << '\t';
1.1493 + _writer_bits::writeToken(*_os, _node_index.
1.1494 + find(_graph.v(e))->second);
1.1495 + *_os << '\t';
1.1496 + if (label == 0) {
1.1497 + std::ostringstream os;
1.1498 + os << _graph.id(e);
1.1499 + _writer_bits::writeToken(*_os, os.str());
1.1500 + *_os << '\t';
1.1501 + _edge_index.insert(std::make_pair(e, os.str()));
1.1502 + }
1.1503 + for (typename EdgeMaps::iterator it = _edge_maps.begin();
1.1504 + it != _edge_maps.end(); ++it) {
1.1505 + std::string value = it->second->get(e);
1.1506 + _writer_bits::writeToken(*_os, value);
1.1507 + if (it->first == "label") {
1.1508 + _edge_index.insert(std::make_pair(e, value));
1.1509 + }
1.1510 + *_os << '\t';
1.1511 + }
1.1512 + *_os << std::endl;
1.1513 }
1.1514 }
1.1515
1.1516 void createEdgeIndex() {
1.1517 _writer_bits::MapStorageBase<Edge>* label = 0;
1.1518 for (typename EdgeMaps::iterator it = _edge_maps.begin();
1.1519 - it != _edge_maps.end(); ++it) {
1.1520 + it != _edge_maps.end(); ++it) {
1.1521 if (it->first == "label") {
1.1522 - label = it->second;
1.1523 - break;
1.1524 - }
1.1525 + label = it->second;
1.1526 + break;
1.1527 + }
1.1528 }
1.1529
1.1530 if (label == 0) {
1.1531 - for (EdgeIt e(_graph); e != INVALID; ++e) {
1.1532 - std::ostringstream os;
1.1533 - os << _graph.id(e);
1.1534 - _edge_index.insert(std::make_pair(e, os.str()));
1.1535 - }
1.1536 + for (EdgeIt e(_graph); e != INVALID; ++e) {
1.1537 + std::ostringstream os;
1.1538 + os << _graph.id(e);
1.1539 + _edge_index.insert(std::make_pair(e, os.str()));
1.1540 + }
1.1541 } else {
1.1542 - for (EdgeIt e(_graph); e != INVALID; ++e) {
1.1543 - std::string value = label->get(e);
1.1544 - _edge_index.insert(std::make_pair(e, value));
1.1545 - }
1.1546 + for (EdgeIt e(_graph); e != INVALID; ++e) {
1.1547 + std::string value = label->get(e);
1.1548 + _edge_index.insert(std::make_pair(e, value));
1.1549 + }
1.1550 }
1.1551 }
1.1552
1.1553 @@ -1419,20 +1419,20 @@
1.1554 if (_attributes.empty()) return;
1.1555 *_os << "@attributes";
1.1556 if (!_attributes_caption.empty()) {
1.1557 - _writer_bits::writeToken(*_os << ' ', _attributes_caption);
1.1558 + _writer_bits::writeToken(*_os << ' ', _attributes_caption);
1.1559 }
1.1560 *_os << std::endl;
1.1561 for (typename Attributes::iterator it = _attributes.begin();
1.1562 - it != _attributes.end(); ++it) {
1.1563 - _writer_bits::writeToken(*_os, it->first) << ' ';
1.1564 - _writer_bits::writeToken(*_os, it->second->get());
1.1565 - *_os << std::endl;
1.1566 + it != _attributes.end(); ++it) {
1.1567 + _writer_bits::writeToken(*_os, it->first) << ' ';
1.1568 + _writer_bits::writeToken(*_os, it->second->get());
1.1569 + *_os << std::endl;
1.1570 }
1.1571 }
1.1572 -
1.1573 +
1.1574 public:
1.1575 -
1.1576 - /// \name Execution of the writer
1.1577 +
1.1578 + /// \name Execution of the writer
1.1579 /// @{
1.1580
1.1581 /// \brief Start the batch processing
1.1582 @@ -1440,14 +1440,14 @@
1.1583 /// This function starts the batch processing.
1.1584 void run() {
1.1585 if (!_skip_nodes) {
1.1586 - writeNodes();
1.1587 + writeNodes();
1.1588 } else {
1.1589 - createNodeIndex();
1.1590 + createNodeIndex();
1.1591 }
1.1592 - if (!_skip_edges) {
1.1593 - writeEdges();
1.1594 + if (!_skip_edges) {
1.1595 + writeEdges();
1.1596 } else {
1.1597 - createEdgeIndex();
1.1598 + createEdgeIndex();
1.1599 }
1.1600 writeAttributes();
1.1601 }
1.1602 @@ -1463,7 +1463,7 @@
1.1603 };
1.1604
1.1605 /// \brief Return a \ref GraphWriter class
1.1606 - ///
1.1607 + ///
1.1608 /// This function just returns a \ref GraphWriter class.
1.1609 /// \relates GraphWriter
1.1610 template <typename Graph>
1.1611 @@ -1473,7 +1473,7 @@
1.1612 }
1.1613
1.1614 /// \brief Return a \ref GraphWriter class
1.1615 - ///
1.1616 + ///
1.1617 /// This function just returns a \ref GraphWriter class.
1.1618 /// \relates GraphWriter
1.1619 template <typename Graph>
1.1620 @@ -1483,7 +1483,7 @@
1.1621 }
1.1622
1.1623 /// \brief Return a \ref GraphWriter class
1.1624 - ///
1.1625 + ///
1.1626 /// This function just returns a \ref GraphWriter class.
1.1627 /// \relates GraphWriter
1.1628 template <typename Graph>