COIN-OR::LEMON - Graph Library

Changeset 209:765619b7cbb2 in lemon-1.2 for lemon/lgf_writer.h


Ignore:
Timestamp:
07/13/08 20:51:02 (16 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Phase:
public
Message:

Apply unify-sources.sh to the source tree

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/lgf_writer.h

    r201 r209  
    1 /* -*- C++ -*-
     1/* -*- mode: C++; indent-tabs-mode: nil; -*-
    22 *
    3  * This file is a part of LEMON, a generic C++ optimization library
     3 * This file is a part of LEMON, a generic C++ optimization library.
    44 *
    55 * Copyright (C) 2003-2008
     
    4444    struct DefaultConverter {
    4545      std::string operator()(const Value& value) {
    46         std::ostringstream os;
    47         os << value;
    48         return os.str();
     46        std::ostringstream os;
     47        os << value;
     48        return os.str();
    4949      }
    5050    };
     
    6363    private:
    6464      const Map& _map;
    65      
     65
    6666    public:
    6767      MapLess(const Map& map) : _map(map) {}
    6868
    6969      bool operator()(const Item& left, const Item& right) {
    70         return _map[left] < _map[right];
     70        return _map[left] < _map[right];
    7171      }
    7272    };
     
    8282      const Graph& _graph;
    8383      const Map& _map;
    84      
     84
    8585    public:
    86       GraphArcMapLess(const Graph& graph, const Map& map) 
    87         : _graph(graph), _map(map) {}
     86      GraphArcMapLess(const Graph& graph, const Map& map)
     87        : _graph(graph), _map(map) {}
    8888
    8989      bool operator()(const Item& left, const Item& right) {
    90         return _map[_graph.direct(left, _dir)] <
    91           _map[_graph.direct(right, _dir)];
     90        return _map[_graph.direct(left, _dir)] <
     91          _map[_graph.direct(right, _dir)];
    9292      }
    9393    };
    9494
    95     template <typename _Item>   
     95    template <typename _Item>
    9696    class MapStorageBase {
    9797    public:
     
    106106    };
    107107
    108     template <typename _Item, typename _Map, 
    109               typename _Converter = DefaultConverter<typename _Map::Value> >
     108    template <typename _Item, typename _Map,
     109              typename _Converter = DefaultConverter<typename _Map::Value> >
    110110    class MapStorage : public MapStorageBase<_Item> {
    111111    public:
     
    113113      typedef _Converter Converter;
    114114      typedef _Item Item;
    115      
     115
    116116    private:
    117117      const Map& _map;
     
    119119
    120120    public:
    121       MapStorage(const Map& map, const Converter& converter = Converter()) 
    122         : _map(map), _converter(converter) {}
     121      MapStorage(const Map& map, const Converter& converter = Converter())
     122        : _map(map), _converter(converter) {}
    123123      virtual ~MapStorage() {}
    124124
    125125      virtual std::string get(const Item& item) {
    126         return _converter(_map[item]);
     126        return _converter(_map[item]);
    127127      }
    128128      virtual void sort(std::vector<Item>& items) {
    129         MapLess<Map> less(_map);
    130         std::sort(items.begin(), items.end(), less);
     129        MapLess<Map> less(_map);
     130        std::sort(items.begin(), items.end(), less);
    131131      }
    132132    };
    133133
    134     template <typename _Graph, bool _dir, typename _Map, 
    135               typename _Converter = DefaultConverter<typename _Map::Value> >
     134    template <typename _Graph, bool _dir, typename _Map,
     135              typename _Converter = DefaultConverter<typename _Map::Value> >
    136136    class GraphArcMapStorage : public MapStorageBase<typename _Graph::Edge> {
    137137    public:
     
    141141      typedef typename Graph::Edge Item;
    142142      static const bool dir = _dir;
    143      
     143
    144144    private:
    145145      const Graph& _graph;
     
    148148
    149149    public:
    150       GraphArcMapStorage(const Graph& graph, const Map& map, 
    151                          const Converter& converter = Converter())
    152         : _graph(graph), _map(map), _converter(converter) {}
     150      GraphArcMapStorage(const Graph& graph, const Map& map,
     151                         const Converter& converter = Converter())
     152        : _graph(graph), _map(map), _converter(converter) {}
    153153      virtual ~GraphArcMapStorage() {}
    154154
    155155      virtual std::string get(const Item& item) {
    156         return _converter(_map[_graph.direct(item, dir)]);
     156        return _converter(_map[_graph.direct(item, dir)]);
    157157      }
    158158      virtual void sort(std::vector<Item>& items) {
    159         GraphArcMapLess<Graph, dir, Map> less(_graph, _map);
    160         std::sort(items.begin(), items.end(), less);
     159        GraphArcMapLess<Graph, dir, Map> less(_graph, _map);
     160        std::sort(items.begin(), items.end(), less);
    161161      }
    162162    };
     
    167167      virtual ~ValueStorageBase() {}
    168168
    169       virtual std::string get() = 0;     
     169      virtual std::string get() = 0;
    170170    };
    171171
     
    182182    public:
    183183      ValueStorage(const Value& value, const Converter& converter = Converter())
    184         : _value(value), _converter(converter) {}
     184         : _value(value), _converter(converter) {}
    185185
    186186      virtual std::string get() {
    187         return _converter(_value);
     187        return _converter(_value);
    188188      }
    189189    };
     
    192192    struct MapLookUpConverter {
    193193      const std::map<Value, std::string>& _map;
    194      
    195       MapLookUpConverter(const std::map<Value, std::string>& map) 
    196         : _map(map) {}
    197      
     194
     195      MapLookUpConverter(const std::map<Value, std::string>& map)
     196        : _map(map) {}
     197
    198198      std::string operator()(const Value& str) {
    199         typename std::map<Value, std::string>::const_iterator it =
    200           _map.find(str);
    201         if (it == _map.end()) {
    202           throw DataFormatError("Item not found");
    203         }
    204         return it->second;
     199        typename std::map<Value, std::string>::const_iterator it =
     200          _map.find(str);
     201        if (it == _map.end()) {
     202          throw DataFormatError("Item not found");
     203        }
     204        return it->second;
    205205      }
    206206    };
     
    210210      const Graph& _graph;
    211211      const std::map<typename Graph::Edge, std::string>& _map;
    212      
    213       GraphArcLookUpConverter(const Graph& graph, 
    214                               const std::map<typename Graph::Edge,
    215                                              std::string>& map)
    216         : _graph(graph), _map(map) {}
    217      
     212
     213      GraphArcLookUpConverter(const Graph& graph,
     214                              const std::map<typename Graph::Edge,
     215                                             std::string>& map)
     216        : _graph(graph), _map(map) {}
     217
    218218      std::string operator()(const typename Graph::Arc& val) {
    219         typename std::map<typename Graph::Edge, std::string>
    220           ::const_iterator it = _map.find(val);
    221         if (it == _map.end()) {
    222           throw DataFormatError("Item not found");
    223         }
    224         return (_graph.direction(val) ? '+' : '-') + it->second;
     219        typename std::map<typename Graph::Edge, std::string>
     220          ::const_iterator it = _map.find(val);
     221        if (it == _map.end()) {
     222          throw DataFormatError("Item not found");
     223        }
     224        return (_graph.direction(val) ? '+' : '-') + it->second;
    225225      }
    226226    };
    227227
    228228    inline bool isWhiteSpace(char c) {
    229       return c == ' ' || c == '\t' || c == '\v' || 
    230         c == '\n' || c == '\r' || c == '\f'; 
     229      return c == ' ' || c == '\t' || c == '\v' ||
     230        c == '\n' || c == '\r' || c == '\f';
    231231    }
    232232
    233233    inline bool isEscaped(char c) {
    234       return c == '\\' || c == '\"' || c == '\'' || 
    235         c == '\a' || c == '\b';
     234      return c == '\\' || c == '\"' || c == '\'' ||
     235        c == '\a' || c == '\b';
    236236    }
    237237
     
    239239      switch (c) {
    240240      case '\\':
    241         os << "\\\\";
    242         return;
     241        os << "\\\\";
     242        return;
    243243      case '\"':
    244         os << "\\\"";
    245         return;
     244        os << "\\\"";
     245        return;
    246246      case '\a':
    247         os << "\\a";
    248         return;
     247        os << "\\a";
     248        return;
    249249      case '\b':
    250         os << "\\b";
    251         return;
     250        os << "\\b";
     251        return;
    252252      case '\f':
    253         os << "\\f";
    254         return;
     253        os << "\\f";
     254        return;
    255255      case '\r':
    256         os << "\\r";
    257         return;
     256        os << "\\r";
     257        return;
    258258      case '\n':
    259         os << "\\n";
    260         return;
     259        os << "\\n";
     260        return;
    261261      case '\t':
    262         os << "\\t";
    263         return;
     262        os << "\\t";
     263        return;
    264264      case '\v':
    265         os << "\\v";
    266         return;
     265        os << "\\v";
     266        return;
    267267      default:
    268         if (c < 0x20) {
    269           std::ios::fmtflags flags = os.flags();
    270           os << '\\' << std::oct << static_cast<int>(c);
    271           os.flags(flags);
    272         } else {
    273           os << c;
    274         }
    275         return;
    276       }     
     268        if (c < 0x20) {
     269          std::ios::fmtflags flags = os.flags();
     270          os << '\\' << std::oct << static_cast<int>(c);
     271          os.flags(flags);
     272        } else {
     273          os << c;
     274        }
     275        return;
     276      }
    277277    }
    278278
     
    282282      char c;
    283283      while (is.get(c)) {
    284         if (isWhiteSpace(c) || isEscaped(c)) {
    285           return true;
    286         }
     284        if (isWhiteSpace(c) || isEscaped(c)) {
     285          return true;
     286        }
    287287      }
    288288      return false;
    289289    }
    290    
     290
    291291    inline std::ostream& writeToken(std::ostream& os, const std::string& str) {
    292292
    293293      if (requireEscape(str)) {
    294         os << '\"';
    295         for (std::string::const_iterator it = str.begin();
    296              it != str.end(); ++it) {
    297           writeEscape(os, *it);
    298         }       
    299         os << '\"';
     294        os << '\"';
     295        for (std::string::const_iterator it = str.begin();
     296             it != str.end(); ++it) {
     297          writeEscape(os, *it);
     298        }
     299        os << '\"';
    300300      } else {
    301         os << str;
     301        os << str;
    302302      }
    303303      return os;
     
    310310
    311311  template <typename Digraph>
    312   DigraphWriter<Digraph> digraphWriter(std::ostream& os, 
    313                                        const Digraph& digraph);
     312  DigraphWriter<Digraph> digraphWriter(std::ostream& os,
     313                                       const Digraph& digraph);
    314314
    315315  template <typename Digraph>
    316   DigraphWriter<Digraph> digraphWriter(const std::string& fn, 
    317                                        const Digraph& digraph);
     316  DigraphWriter<Digraph> digraphWriter(const std::string& fn,
     317                                       const Digraph& digraph);
    318318
    319319  template <typename Digraph>
    320   DigraphWriter<Digraph> digraphWriter(const char *fn, 
    321                                        const Digraph& digraph);
    322  
     320  DigraphWriter<Digraph> digraphWriter(const char *fn,
     321                                       const Digraph& digraph);
     322
    323323  /// \ingroup lemon_io
    324   /// 
     324  ///
    325325  /// \brief \ref lgf-format "LGF" writer for directed graphs
    326326  ///
     
    371371    typedef _Digraph Digraph;
    372372    TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    373    
     373
    374374  private:
    375375
     
    383383    std::string _arcs_caption;
    384384    std::string _attributes_caption;
    385    
     385
    386386    typedef std::map<Node, std::string> NodeIndex;
    387387    NodeIndex _node_index;
     
    389389    ArcIndex _arc_index;
    390390
    391     typedef std::vector<std::pair<std::string, 
    392       _writer_bits::MapStorageBase<Node>* > > NodeMaps;   
    393     NodeMaps _node_maps; 
    394 
    395     typedef std::vector<std::pair<std::string, 
     391    typedef std::vector<std::pair<std::string,
     392      _writer_bits::MapStorageBase<Node>* > > NodeMaps;
     393    NodeMaps _node_maps;
     394
     395    typedef std::vector<std::pair<std::string,
    396396      _writer_bits::MapStorageBase<Arc>* > >ArcMaps;
    397397    ArcMaps _arc_maps;
    398398
    399     typedef std::vector<std::pair<std::string, 
     399    typedef std::vector<std::pair<std::string,
    400400      _writer_bits::ValueStorageBase*> > Attributes;
    401401    Attributes _attributes;
     
    410410    /// Construct a directed graph writer, which writes to the given
    411411    /// output stream.
    412     DigraphWriter(std::ostream& is, const Digraph& digraph) 
     412    DigraphWriter(std::ostream& is, const Digraph& digraph)
    413413      : _os(&is), local_os(false), _digraph(digraph),
    414         _skip_nodes(false), _skip_arcs(false) {}
     414        _skip_nodes(false), _skip_arcs(false) {}
    415415
    416416    /// \brief Constructor
     
    418418    /// Construct a directed graph writer, which writes to the given
    419419    /// output file.
    420     DigraphWriter(const std::string& fn, const Digraph& digraph) 
     420    DigraphWriter(const std::string& fn, const Digraph& digraph)
    421421      : _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph),
    422         _skip_nodes(false), _skip_arcs(false) {}
     422        _skip_nodes(false), _skip_arcs(false) {}
    423423
    424424    /// \brief Constructor
     
    426426    /// Construct a directed graph writer, which writes to the given
    427427    /// output file.
    428     DigraphWriter(const char* fn, const Digraph& digraph) 
     428    DigraphWriter(const char* fn, const Digraph& digraph)
    429429      : _os(new std::ofstream(fn)), local_os(true), _digraph(digraph),
    430         _skip_nodes(false), _skip_arcs(false) {}
     430        _skip_nodes(false), _skip_arcs(false) {}
    431431
    432432    /// \brief Destructor
    433433    ~DigraphWriter() {
    434       for (typename NodeMaps::iterator it = _node_maps.begin(); 
    435            it != _node_maps.end(); ++it) {
    436         delete it->second;
    437       }
    438 
    439       for (typename ArcMaps::iterator it = _arc_maps.begin(); 
    440            it != _arc_maps.end(); ++it) {
    441         delete it->second;
    442       }
    443 
    444       for (typename Attributes::iterator it = _attributes.begin(); 
    445            it != _attributes.end(); ++it) {
    446         delete it->second;
     434      for (typename NodeMaps::iterator it = _node_maps.begin();
     435           it != _node_maps.end(); ++it) {
     436        delete it->second;
     437      }
     438
     439      for (typename ArcMaps::iterator it = _arc_maps.begin();
     440           it != _arc_maps.end(); ++it) {
     441        delete it->second;
     442      }
     443
     444      for (typename Attributes::iterator it = _attributes.begin();
     445           it != _attributes.end(); ++it) {
     446        delete it->second;
    447447      }
    448448
    449449      if (local_os) {
    450         delete _os;
     450        delete _os;
    451451      }
    452452    }
     
    454454  private:
    455455
    456     friend DigraphWriter<Digraph> digraphWriter<>(std::ostream& os, 
    457                                                   const Digraph& digraph);
    458     friend DigraphWriter<Digraph> digraphWriter<>(const std::string& fn, 
    459                                                   const Digraph& digraph);   
    460     friend DigraphWriter<Digraph> digraphWriter<>(const char *fn, 
    461                                                   const Digraph& digraph);
    462 
    463     DigraphWriter(DigraphWriter& other) 
     456    friend DigraphWriter<Digraph> digraphWriter<>(std::ostream& os,
     457                                                  const Digraph& digraph);
     458    friend DigraphWriter<Digraph> digraphWriter<>(const std::string& fn,
     459                                                  const Digraph& digraph);
     460    friend DigraphWriter<Digraph> digraphWriter<>(const char *fn,
     461                                                  const Digraph& digraph);
     462
     463    DigraphWriter(DigraphWriter& other)
    464464      : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
    465         _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
     465        _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
    466466
    467467      other._os = 0;
     
    479479      _attributes_caption = other._attributes_caption;
    480480    }
    481    
     481
    482482    DigraphWriter& operator=(const DigraphWriter&);
    483483
     
    486486    /// \name Writing rules
    487487    /// @{
    488    
     488
    489489    /// \brief Node map writing rule
    490490    ///
     
    493493    DigraphWriter& nodeMap(const std::string& caption, const Map& map) {
    494494      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
    495       _writer_bits::MapStorageBase<Node>* storage = 
    496         new _writer_bits::MapStorage<Node, Map>(map);
     495      _writer_bits::MapStorageBase<Node>* storage =
     496        new _writer_bits::MapStorage<Node, Map>(map);
    497497      _node_maps.push_back(std::make_pair(caption, storage));
    498498      return *this;
     
    504504    /// writer.
    505505    template <typename Map, typename Converter>
    506     DigraphWriter& nodeMap(const std::string& caption, const Map& map, 
    507                            const Converter& converter = Converter()) {
     506    DigraphWriter& nodeMap(const std::string& caption, const Map& map,
     507                           const Converter& converter = Converter()) {
    508508      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
    509       _writer_bits::MapStorageBase<Node>* storage = 
    510         new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
     509      _writer_bits::MapStorageBase<Node>* storage =
     510        new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
    511511      _node_maps.push_back(std::make_pair(caption, storage));
    512512      return *this;
     
    519519    DigraphWriter& arcMap(const std::string& caption, const Map& map) {
    520520      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
    521       _writer_bits::MapStorageBase<Arc>* storage = 
    522         new _writer_bits::MapStorage<Arc, Map>(map);
     521      _writer_bits::MapStorageBase<Arc>* storage =
     522        new _writer_bits::MapStorage<Arc, Map>(map);
    523523      _arc_maps.push_back(std::make_pair(caption, storage));
    524524      return *this;
     
    530530    /// writer.
    531531    template <typename Map, typename Converter>
    532     DigraphWriter& arcMap(const std::string& caption, const Map& map, 
    533                           const Converter& converter = Converter()) {
     532    DigraphWriter& arcMap(const std::string& caption, const Map& map,
     533                          const Converter& converter = Converter()) {
    534534      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
    535       _writer_bits::MapStorageBase<Arc>* storage = 
    536         new _writer_bits::MapStorage<Arc, Map, Converter>(map, converter);
     535      _writer_bits::MapStorageBase<Arc>* storage =
     536        new _writer_bits::MapStorage<Arc, Map, Converter>(map, converter);
    537537      _arc_maps.push_back(std::make_pair(caption, storage));
    538538      return *this;
     
    544544    template <typename Value>
    545545    DigraphWriter& attribute(const std::string& caption, const Value& value) {
    546       _writer_bits::ValueStorageBase* storage = 
    547         new _writer_bits::ValueStorage<Value>(value);
     546      _writer_bits::ValueStorageBase* storage =
     547        new _writer_bits::ValueStorage<Value>(value);
    548548      _attributes.push_back(std::make_pair(caption, storage));
    549549      return *this;
     
    555555    /// writer.
    556556    template <typename Value, typename Converter>
    557     DigraphWriter& attribute(const std::string& caption, const Value& value, 
    558                              const Converter& converter = Converter()) {
    559       _writer_bits::ValueStorageBase* storage = 
    560         new _writer_bits::ValueStorage<Value, Converter>(value, converter);
     557    DigraphWriter& attribute(const std::string& caption, const Value& value,
     558                             const Converter& converter = Converter()) {
     559      _writer_bits::ValueStorageBase* storage =
     560        new _writer_bits::ValueStorage<Value, Converter>(value, converter);
    561561      _attributes.push_back(std::make_pair(caption, storage));
    562562      return *this;
     
    569569      typedef _writer_bits::MapLookUpConverter<Node> Converter;
    570570      Converter converter(_node_index);
    571       _writer_bits::ValueStorageBase* storage = 
    572         new _writer_bits::ValueStorage<Node, Converter>(node, converter);
     571      _writer_bits::ValueStorageBase* storage =
     572        new _writer_bits::ValueStorage<Node, Converter>(node, converter);
    573573      _attributes.push_back(std::make_pair(caption, storage));
    574574      return *this;
     
    581581      typedef _writer_bits::MapLookUpConverter<Arc> Converter;
    582582      Converter converter(_arc_index);
    583       _writer_bits::ValueStorageBase* storage = 
    584         new _writer_bits::ValueStorage<Arc, Converter>(arc, converter);
     583      _writer_bits::ValueStorageBase* storage =
     584        new _writer_bits::ValueStorage<Arc, Converter>(arc, converter);
    585585      _attributes.push_back(std::make_pair(caption, storage));
    586586      return *this;
     
    642642      _writer_bits::MapStorageBase<Node>* label = 0;
    643643      for (typename NodeMaps::iterator it = _node_maps.begin();
    644            it != _node_maps.end(); ++it) {
     644           it != _node_maps.end(); ++it) {
    645645        if (it->first == "label") {
    646           label = it->second;
    647           break;
    648         }
     646          label = it->second;
     647          break;
     648        }
    649649      }
    650650
    651651      *_os << "@nodes";
    652652      if (!_nodes_caption.empty()) {
    653         _writer_bits::writeToken(*_os << ' ', _nodes_caption);
     653        _writer_bits::writeToken(*_os << ' ', _nodes_caption);
    654654      }
    655655      *_os << std::endl;
    656656
    657657      if (label == 0) {
    658         *_os << "label" << '\t';
     658        *_os << "label" << '\t';
    659659      }
    660660      for (typename NodeMaps::iterator it = _node_maps.begin();
    661            it != _node_maps.end(); ++it) {
    662         _writer_bits::writeToken(*_os, it->first) << '\t';
     661           it != _node_maps.end(); ++it) {
     662        _writer_bits::writeToken(*_os, it->first) << '\t';
    663663      }
    664664      *_os << std::endl;
     
    666666      std::vector<Node> nodes;
    667667      for (NodeIt n(_digraph); n != INVALID; ++n) {
    668         nodes.push_back(n);
    669       }
    670      
     668        nodes.push_back(n);
     669      }
     670
    671671      if (label == 0) {
    672         IdMap<Digraph, Node> id_map(_digraph);
    673         _writer_bits::MapLess<IdMap<Digraph, Node> > id_less(id_map);
    674         std::sort(nodes.begin(), nodes.end(), id_less);
     672        IdMap<Digraph, Node> id_map(_digraph);
     673        _writer_bits::MapLess<IdMap<Digraph, Node> > id_less(id_map);
     674        std::sort(nodes.begin(), nodes.end(), id_less);
    675675      } else {
    676         label->sort(nodes);
     676        label->sort(nodes);
    677677      }
    678678
    679679      for (int i = 0; i < static_cast<int>(nodes.size()); ++i) {
    680         Node n = nodes[i];
    681         if (label == 0) {
    682           std::ostringstream os;
    683           os << _digraph.id(n);
    684           _writer_bits::writeToken(*_os, os.str());
    685           *_os << '\t';
    686           _node_index.insert(std::make_pair(n, os.str()));
    687         }
    688         for (typename NodeMaps::iterator it = _node_maps.begin();
    689              it != _node_maps.end(); ++it) {
    690           std::string value = it->second->get(n);
    691           _writer_bits::writeToken(*_os, value);
    692           if (it->first == "label") {
    693             _node_index.insert(std::make_pair(n, value));
    694           }
    695           *_os << '\t';
    696         }
    697         *_os << std::endl;
     680        Node n = nodes[i];
     681        if (label == 0) {
     682          std::ostringstream os;
     683          os << _digraph.id(n);
     684          _writer_bits::writeToken(*_os, os.str());
     685          *_os << '\t';
     686          _node_index.insert(std::make_pair(n, os.str()));
     687        }
     688        for (typename NodeMaps::iterator it = _node_maps.begin();
     689             it != _node_maps.end(); ++it) {
     690          std::string value = it->second->get(n);
     691          _writer_bits::writeToken(*_os, value);
     692          if (it->first == "label") {
     693            _node_index.insert(std::make_pair(n, value));
     694          }
     695          *_os << '\t';
     696        }
     697        *_os << std::endl;
    698698      }
    699699    }
     
    702702      _writer_bits::MapStorageBase<Node>* label = 0;
    703703      for (typename NodeMaps::iterator it = _node_maps.begin();
    704            it != _node_maps.end(); ++it) {
     704           it != _node_maps.end(); ++it) {
    705705        if (it->first == "label") {
    706           label = it->second;
    707           break;
    708         }
     706          label = it->second;
     707          break;
     708        }
    709709      }
    710710
    711711      if (label == 0) {
    712         for (NodeIt n(_digraph); n != INVALID; ++n) {
    713           std::ostringstream os;
    714           os << _digraph.id(n);
    715           _node_index.insert(std::make_pair(n, os.str()));       
    716         }       
     712        for (NodeIt n(_digraph); n != INVALID; ++n) {
     713          std::ostringstream os;
     714          os << _digraph.id(n);
     715          _node_index.insert(std::make_pair(n, os.str()));
     716        }
    717717      } else {
    718         for (NodeIt n(_digraph); n != INVALID; ++n) {
    719           std::string value = label->get(n);     
    720           _node_index.insert(std::make_pair(n, value));
    721         }
     718        for (NodeIt n(_digraph); n != INVALID; ++n) {
     719          std::string value = label->get(n);
     720          _node_index.insert(std::make_pair(n, value));
     721        }
    722722      }
    723723    }
     
    726726      _writer_bits::MapStorageBase<Arc>* label = 0;
    727727      for (typename ArcMaps::iterator it = _arc_maps.begin();
    728            it != _arc_maps.end(); ++it) {
     728           it != _arc_maps.end(); ++it) {
    729729        if (it->first == "label") {
    730           label = it->second;
    731           break;
    732         }
     730          label = it->second;
     731          break;
     732        }
    733733      }
    734734
    735735      *_os << "@arcs";
    736736      if (!_arcs_caption.empty()) {
    737         _writer_bits::writeToken(*_os << ' ', _arcs_caption);
     737        _writer_bits::writeToken(*_os << ' ', _arcs_caption);
    738738      }
    739739      *_os << std::endl;
     
    741741      *_os << '\t' << '\t';
    742742      if (label == 0) {
    743         *_os << "label" << '\t';
     743        *_os << "label" << '\t';
    744744      }
    745745      for (typename ArcMaps::iterator it = _arc_maps.begin();
    746            it != _arc_maps.end(); ++it) {
    747         _writer_bits::writeToken(*_os, it->first) << '\t';
     746           it != _arc_maps.end(); ++it) {
     747        _writer_bits::writeToken(*_os, it->first) << '\t';
    748748      }
    749749      *_os << std::endl;
     
    751751      std::vector<Arc> arcs;
    752752      for (ArcIt n(_digraph); n != INVALID; ++n) {
    753         arcs.push_back(n);
    754       }
    755      
     753        arcs.push_back(n);
     754      }
     755
    756756      if (label == 0) {
    757         IdMap<Digraph, Arc> id_map(_digraph);
    758         _writer_bits::MapLess<IdMap<Digraph, Arc> > id_less(id_map);
    759         std::sort(arcs.begin(), arcs.end(), id_less);
     757        IdMap<Digraph, Arc> id_map(_digraph);
     758        _writer_bits::MapLess<IdMap<Digraph, Arc> > id_less(id_map);
     759        std::sort(arcs.begin(), arcs.end(), id_less);
    760760      } else {
    761         label->sort(arcs);
     761        label->sort(arcs);
    762762      }
    763763
    764764      for (int i = 0; i < static_cast<int>(arcs.size()); ++i) {
    765         Arc a = arcs[i];
    766         _writer_bits::writeToken(*_os, _node_index.
    767                                 find(_digraph.source(a))->second);
    768         *_os << '\t';
    769         _writer_bits::writeToken(*_os, _node_index.
    770                                 find(_digraph.target(a))->second);
    771         *_os << '\t';
    772         if (label == 0) {
    773           std::ostringstream os;
    774           os << _digraph.id(a);
    775           _writer_bits::writeToken(*_os, os.str());
    776           *_os << '\t';
    777           _arc_index.insert(std::make_pair(a, os.str()));
    778         }
    779         for (typename ArcMaps::iterator it = _arc_maps.begin();
    780              it != _arc_maps.end(); ++it) {
    781           std::string value = it->second->get(a);
    782           _writer_bits::writeToken(*_os, value);
    783           if (it->first == "label") {
    784             _arc_index.insert(std::make_pair(a, value));
    785           }
    786           *_os << '\t';
    787         }
    788         *_os << std::endl;
     765        Arc a = arcs[i];
     766        _writer_bits::writeToken(*_os, _node_index.
     767                                find(_digraph.source(a))->second);
     768        *_os << '\t';
     769        _writer_bits::writeToken(*_os, _node_index.
     770                                find(_digraph.target(a))->second);
     771        *_os << '\t';
     772        if (label == 0) {
     773          std::ostringstream os;
     774          os << _digraph.id(a);
     775          _writer_bits::writeToken(*_os, os.str());
     776          *_os << '\t';
     777          _arc_index.insert(std::make_pair(a, os.str()));
     778        }
     779        for (typename ArcMaps::iterator it = _arc_maps.begin();
     780             it != _arc_maps.end(); ++it) {
     781          std::string value = it->second->get(a);
     782          _writer_bits::writeToken(*_os, value);
     783          if (it->first == "label") {
     784            _arc_index.insert(std::make_pair(a, value));
     785          }
     786          *_os << '\t';
     787        }
     788        *_os << std::endl;
    789789      }
    790790    }
     
    793793      _writer_bits::MapStorageBase<Arc>* label = 0;
    794794      for (typename ArcMaps::iterator it = _arc_maps.begin();
    795            it != _arc_maps.end(); ++it) {
     795           it != _arc_maps.end(); ++it) {
    796796        if (it->first == "label") {
    797           label = it->second;
    798           break;
    799         }
     797          label = it->second;
     798          break;
     799        }
    800800      }
    801801
    802802      if (label == 0) {
    803         for (ArcIt a(_digraph); a != INVALID; ++a) {
    804           std::ostringstream os;
    805           os << _digraph.id(a);
    806           _arc_index.insert(std::make_pair(a, os.str()));         
    807         }       
     803        for (ArcIt a(_digraph); a != INVALID; ++a) {
     804          std::ostringstream os;
     805          os << _digraph.id(a);
     806          _arc_index.insert(std::make_pair(a, os.str()));
     807        }
    808808      } else {
    809         for (ArcIt a(_digraph); a != INVALID; ++a) {
    810           std::string value = label->get(a);     
    811           _arc_index.insert(std::make_pair(a, value));
    812         }
     809        for (ArcIt a(_digraph); a != INVALID; ++a) {
     810          std::string value = label->get(a);
     811          _arc_index.insert(std::make_pair(a, value));
     812        }
    813813      }
    814814    }
     
    818818      *_os << "@attributes";
    819819      if (!_attributes_caption.empty()) {
    820         _writer_bits::writeToken(*_os << ' ', _attributes_caption);
     820        _writer_bits::writeToken(*_os << ' ', _attributes_caption);
    821821      }
    822822      *_os << std::endl;
    823823      for (typename Attributes::iterator it = _attributes.begin();
    824            it != _attributes.end(); ++it) {
    825         _writer_bits::writeToken(*_os, it->first) << ' ';
    826         _writer_bits::writeToken(*_os, it->second->get());
    827         *_os << std::endl;
    828       }
    829     }
    830    
     824           it != _attributes.end(); ++it) {
     825        _writer_bits::writeToken(*_os, it->first) << ' ';
     826        _writer_bits::writeToken(*_os, it->second->get());
     827        *_os << std::endl;
     828      }
     829    }
     830
    831831  public:
    832    
    833     /// \name Execution of the writer   
     832
     833    /// \name Execution of the writer
    834834    /// @{
    835835
     
    839839    void run() {
    840840      if (!_skip_nodes) {
    841         writeNodes();
     841        writeNodes();
    842842      } else {
    843         createNodeIndex();
    844       }
    845       if (!_skip_arcs) {     
    846         writeArcs();
     843        createNodeIndex();
     844      }
     845      if (!_skip_arcs) {
     846        writeArcs();
    847847      } else {
    848         createArcIndex();
     848        createArcIndex();
    849849      }
    850850      writeAttributes();
     
    862862
    863863  /// \brief Return a \ref DigraphWriter class
    864   /// 
     864  ///
    865865  /// This function just returns a \ref DigraphWriter class.
    866866  /// \relates DigraphWriter
    867867  template <typename Digraph>
    868   DigraphWriter<Digraph> digraphWriter(std::ostream& os, 
    869                                        const Digraph& digraph) {
     868  DigraphWriter<Digraph> digraphWriter(std::ostream& os,
     869                                       const Digraph& digraph) {
    870870    DigraphWriter<Digraph> tmp(os, digraph);
    871871    return tmp;
     
    873873
    874874  /// \brief Return a \ref DigraphWriter class
    875   /// 
     875  ///
    876876  /// This function just returns a \ref DigraphWriter class.
    877877  /// \relates DigraphWriter
    878878  template <typename Digraph>
    879   DigraphWriter<Digraph> digraphWriter(const std::string& fn, 
    880                                        const Digraph& digraph) {
     879  DigraphWriter<Digraph> digraphWriter(const std::string& fn,
     880                                       const Digraph& digraph) {
    881881    DigraphWriter<Digraph> tmp(fn, digraph);
    882882    return tmp;
     
    884884
    885885  /// \brief Return a \ref DigraphWriter class
    886   /// 
     886  ///
    887887  /// This function just returns a \ref DigraphWriter class.
    888888  /// \relates DigraphWriter
    889889  template <typename Digraph>
    890   DigraphWriter<Digraph> digraphWriter(const char* fn, 
    891                                        const Digraph& digraph) {
     890  DigraphWriter<Digraph> digraphWriter(const char* fn,
     891                                       const Digraph& digraph) {
    892892    DigraphWriter<Digraph> tmp(fn, digraph);
    893893    return tmp;
     
    898898
    899899  template <typename Graph>
    900   GraphWriter<Graph> graphWriter(std::ostream& os, const Graph& graph);   
     900  GraphWriter<Graph> graphWriter(std::ostream& os, const Graph& graph);
    901901
    902902  template <typename Graph>
    903   GraphWriter<Graph> graphWriter(const std::string& fn, const Graph& graph);   
     903  GraphWriter<Graph> graphWriter(const std::string& fn, const Graph& graph);
    904904
    905905  template <typename Graph>
    906   GraphWriter<Graph> graphWriter(const char *fn, const Graph& graph);   
     906  GraphWriter<Graph> graphWriter(const char *fn, const Graph& graph);
    907907
    908908  /// \ingroup lemon_io
    909   /// 
     909  ///
    910910  /// \brief \ref lgf-format "LGF" writer for directed graphs
    911911  ///
     
    927927    typedef _Graph Graph;
    928928    TEMPLATE_GRAPH_TYPEDEFS(Graph);
    929    
     929
    930930  private:
    931931
     
    939939    std::string _edges_caption;
    940940    std::string _attributes_caption;
    941    
     941
    942942    typedef std::map<Node, std::string> NodeIndex;
    943943    NodeIndex _node_index;
     
    945945    EdgeIndex _edge_index;
    946946
    947     typedef std::vector<std::pair<std::string, 
    948       _writer_bits::MapStorageBase<Node>* > > NodeMaps;   
    949     NodeMaps _node_maps; 
    950 
    951     typedef std::vector<std::pair<std::string, 
     947    typedef std::vector<std::pair<std::string,
     948      _writer_bits::MapStorageBase<Node>* > > NodeMaps;
     949    NodeMaps _node_maps;
     950
     951    typedef std::vector<std::pair<std::string,
    952952      _writer_bits::MapStorageBase<Edge>* > >EdgeMaps;
    953953    EdgeMaps _edge_maps;
    954954
    955     typedef std::vector<std::pair<std::string, 
     955    typedef std::vector<std::pair<std::string,
    956956      _writer_bits::ValueStorageBase*> > Attributes;
    957957    Attributes _attributes;
     
    966966    /// Construct a directed graph writer, which writes to the given
    967967    /// output stream.
    968     GraphWriter(std::ostream& is, const Graph& graph) 
     968    GraphWriter(std::ostream& is, const Graph& graph)
    969969      : _os(&is), local_os(false), _graph(graph),
    970         _skip_nodes(false), _skip_edges(false) {}
     970        _skip_nodes(false), _skip_edges(false) {}
    971971
    972972    /// \brief Constructor
     
    974974    /// Construct a directed graph writer, which writes to the given
    975975    /// output file.
    976     GraphWriter(const std::string& fn, const Graph& graph) 
     976    GraphWriter(const std::string& fn, const Graph& graph)
    977977      : _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph),
    978         _skip_nodes(false), _skip_edges(false) {}
     978        _skip_nodes(false), _skip_edges(false) {}
    979979
    980980    /// \brief Constructor
     
    982982    /// Construct a directed graph writer, which writes to the given
    983983    /// output file.
    984     GraphWriter(const char* fn, const Graph& graph) 
     984    GraphWriter(const char* fn, const Graph& graph)
    985985      : _os(new std::ofstream(fn)), local_os(true), _graph(graph),
    986         _skip_nodes(false), _skip_edges(false) {}
     986        _skip_nodes(false), _skip_edges(false) {}
    987987
    988988    /// \brief Destructor
    989989    ~GraphWriter() {
    990       for (typename NodeMaps::iterator it = _node_maps.begin(); 
    991            it != _node_maps.end(); ++it) {
    992         delete it->second;
    993       }
    994 
    995       for (typename EdgeMaps::iterator it = _edge_maps.begin(); 
    996            it != _edge_maps.end(); ++it) {
    997         delete it->second;
    998       }
    999 
    1000       for (typename Attributes::iterator it = _attributes.begin(); 
    1001            it != _attributes.end(); ++it) {
    1002         delete it->second;
     990      for (typename NodeMaps::iterator it = _node_maps.begin();
     991           it != _node_maps.end(); ++it) {
     992        delete it->second;
     993      }
     994
     995      for (typename EdgeMaps::iterator it = _edge_maps.begin();
     996           it != _edge_maps.end(); ++it) {
     997        delete it->second;
     998      }
     999
     1000      for (typename Attributes::iterator it = _attributes.begin();
     1001           it != _attributes.end(); ++it) {
     1002        delete it->second;
    10031003      }
    10041004
    10051005      if (local_os) {
    1006         delete _os;
    1007       }
    1008     }
    1009    
     1006        delete _os;
     1007      }
     1008    }
     1009
    10101010  private:
    10111011
    1012     friend GraphWriter<Graph> graphWriter<>(std::ostream& os, 
    1013                                             const Graph& graph);   
    1014     friend GraphWriter<Graph> graphWriter<>(const std::string& fn, 
    1015                                             const Graph& graph);   
    1016     friend GraphWriter<Graph> graphWriter<>(const char *fn, 
    1017                                             const Graph& graph);   
    1018 
    1019     GraphWriter(GraphWriter& other) 
     1012    friend GraphWriter<Graph> graphWriter<>(std::ostream& os,
     1013                                            const Graph& graph);
     1014    friend GraphWriter<Graph> graphWriter<>(const std::string& fn,
     1015                                            const Graph& graph);
     1016    friend GraphWriter<Graph> graphWriter<>(const char *fn,
     1017                                            const Graph& graph);
     1018
     1019    GraphWriter(GraphWriter& other)
    10201020      : _os(other._os), local_os(other.local_os), _graph(other._graph),
    1021         _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
     1021        _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
    10221022
    10231023      other._os = 0;
     
    10421042    /// \name Writing rules
    10431043    /// @{
    1044    
     1044
    10451045    /// \brief Node map writing rule
    10461046    ///
     
    10491049    GraphWriter& nodeMap(const std::string& caption, const Map& map) {
    10501050      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
    1051       _writer_bits::MapStorageBase<Node>* storage = 
    1052         new _writer_bits::MapStorage<Node, Map>(map);
     1051      _writer_bits::MapStorageBase<Node>* storage =
     1052        new _writer_bits::MapStorage<Node, Map>(map);
    10531053      _node_maps.push_back(std::make_pair(caption, storage));
    10541054      return *this;
     
    10601060    /// writer.
    10611061    template <typename Map, typename Converter>
    1062     GraphWriter& nodeMap(const std::string& caption, const Map& map, 
    1063                            const Converter& converter = Converter()) {
     1062    GraphWriter& nodeMap(const std::string& caption, const Map& map,
     1063                           const Converter& converter = Converter()) {
    10641064      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
    1065       _writer_bits::MapStorageBase<Node>* storage = 
    1066         new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
     1065      _writer_bits::MapStorageBase<Node>* storage =
     1066        new _writer_bits::MapStorage<Node, Map, Converter>(map, converter);
    10671067      _node_maps.push_back(std::make_pair(caption, storage));
    10681068      return *this;
     
    10751075    GraphWriter& edgeMap(const std::string& caption, const Map& map) {
    10761076      checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>();
    1077       _writer_bits::MapStorageBase<Edge>* storage = 
    1078         new _writer_bits::MapStorage<Edge, Map>(map);
     1077      _writer_bits::MapStorageBase<Edge>* storage =
     1078        new _writer_bits::MapStorage<Edge, Map>(map);
    10791079      _edge_maps.push_back(std::make_pair(caption, storage));
    10801080      return *this;
     
    10861086    /// writer.
    10871087    template <typename Map, typename Converter>
    1088     GraphWriter& edgeMap(const std::string& caption, const Map& map, 
    1089                           const Converter& converter = Converter()) {
     1088    GraphWriter& edgeMap(const std::string& caption, const Map& map,
     1089                          const Converter& converter = Converter()) {
    10901090      checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>();
    1091       _writer_bits::MapStorageBase<Edge>* storage = 
    1092         new _writer_bits::MapStorage<Edge, Map, Converter>(map, converter);
     1091      _writer_bits::MapStorageBase<Edge>* storage =
     1092        new _writer_bits::MapStorage<Edge, Map, Converter>(map, converter);
    10931093      _edge_maps.push_back(std::make_pair(caption, storage));
    10941094      return *this;
     
    11011101    GraphWriter& arcMap(const std::string& caption, const Map& map) {
    11021102      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
    1103       _writer_bits::MapStorageBase<Edge>* forward_storage = 
    1104         new _writer_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map);
     1103      _writer_bits::MapStorageBase<Edge>* forward_storage =
     1104        new _writer_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map);
    11051105      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
    1106       _writer_bits::MapStorageBase<Edge>* backward_storage = 
    1107         new _writer_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map);
     1106      _writer_bits::MapStorageBase<Edge>* backward_storage =
     1107        new _writer_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map);
    11081108      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
    11091109      return *this;
     
    11151115    /// writer.
    11161116    template <typename Map, typename Converter>
    1117     GraphWriter& arcMap(const std::string& caption, const Map& map, 
    1118                           const Converter& converter = Converter()) {
     1117    GraphWriter& arcMap(const std::string& caption, const Map& map,
     1118                          const Converter& converter = Converter()) {
    11191119      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
    1120       _writer_bits::MapStorageBase<Edge>* forward_storage = 
    1121         new _writer_bits::GraphArcMapStorage<Graph, true, Map, Converter>
    1122         (_graph, map, converter);
     1120      _writer_bits::MapStorageBase<Edge>* forward_storage =
     1121        new _writer_bits::GraphArcMapStorage<Graph, true, Map, Converter>
     1122        (_graph, map, converter);
    11231123      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
    1124       _writer_bits::MapStorageBase<Edge>* backward_storage = 
    1125         new _writer_bits::GraphArcMapStorage<Graph, false, Map, Converter>
    1126         (_graph, map, converter);
     1124      _writer_bits::MapStorageBase<Edge>* backward_storage =
     1125        new _writer_bits::GraphArcMapStorage<Graph, false, Map, Converter>
     1126        (_graph, map, converter);
    11271127      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
    11281128      return *this;
     
    11341134    template <typename Value>
    11351135    GraphWriter& attribute(const std::string& caption, const Value& value) {
    1136       _writer_bits::ValueStorageBase* storage = 
    1137         new _writer_bits::ValueStorage<Value>(value);
     1136      _writer_bits::ValueStorageBase* storage =
     1137        new _writer_bits::ValueStorage<Value>(value);
    11381138      _attributes.push_back(std::make_pair(caption, storage));
    11391139      return *this;
     
    11451145    /// writer.
    11461146    template <typename Value, typename Converter>
    1147     GraphWriter& attribute(const std::string& caption, const Value& value, 
    1148                              const Converter& converter = Converter()) {
    1149       _writer_bits::ValueStorageBase* storage = 
    1150         new _writer_bits::ValueStorage<Value, Converter>(value, converter);
     1147    GraphWriter& attribute(const std::string& caption, const Value& value,
     1148                             const Converter& converter = Converter()) {
     1149      _writer_bits::ValueStorageBase* storage =
     1150        new _writer_bits::ValueStorage<Value, Converter>(value, converter);
    11511151      _attributes.push_back(std::make_pair(caption, storage));
    11521152      return *this;
     
    11591159      typedef _writer_bits::MapLookUpConverter<Node> Converter;
    11601160      Converter converter(_node_index);
    1161       _writer_bits::ValueStorageBase* storage = 
    1162         new _writer_bits::ValueStorage<Node, Converter>(node, converter);
     1161      _writer_bits::ValueStorageBase* storage =
     1162        new _writer_bits::ValueStorage<Node, Converter>(node, converter);
    11631163      _attributes.push_back(std::make_pair(caption, storage));
    11641164      return *this;
     
    11711171      typedef _writer_bits::MapLookUpConverter<Edge> Converter;
    11721172      Converter converter(_edge_index);
    1173       _writer_bits::ValueStorageBase* storage = 
    1174         new _writer_bits::ValueStorage<Edge, Converter>(edge, converter);
     1173      _writer_bits::ValueStorageBase* storage =
     1174        new _writer_bits::ValueStorage<Edge, Converter>(edge, converter);
    11751175      _attributes.push_back(std::make_pair(caption, storage));
    11761176      return *this;
     
    11831183      typedef _writer_bits::GraphArcLookUpConverter<Graph> Converter;
    11841184      Converter converter(_graph, _edge_index);
    1185       _writer_bits::ValueStorageBase* storage = 
    1186         new _writer_bits::ValueStorage<Arc, Converter>(arc, converter);
     1185      _writer_bits::ValueStorageBase* storage =
     1186        new _writer_bits::ValueStorage<Arc, Converter>(arc, converter);
    11871187      _attributes.push_back(std::make_pair(caption, storage));
    11881188      return *this;
     
    12441244      _writer_bits::MapStorageBase<Node>* label = 0;
    12451245      for (typename NodeMaps::iterator it = _node_maps.begin();
    1246            it != _node_maps.end(); ++it) {
     1246           it != _node_maps.end(); ++it) {
    12471247        if (it->first == "label") {
    1248           label = it->second;
    1249           break;
    1250         }
     1248          label = it->second;
     1249          break;
     1250        }
    12511251      }
    12521252
    12531253      *_os << "@nodes";
    12541254      if (!_nodes_caption.empty()) {
    1255         _writer_bits::writeToken(*_os << ' ', _nodes_caption);
     1255        _writer_bits::writeToken(*_os << ' ', _nodes_caption);
    12561256      }
    12571257      *_os << std::endl;
    12581258
    12591259      if (label == 0) {
    1260         *_os << "label" << '\t';
     1260        *_os << "label" << '\t';
    12611261      }
    12621262      for (typename NodeMaps::iterator it = _node_maps.begin();
    1263            it != _node_maps.end(); ++it) {
    1264         _writer_bits::writeToken(*_os, it->first) << '\t';
     1263           it != _node_maps.end(); ++it) {
     1264        _writer_bits::writeToken(*_os, it->first) << '\t';
    12651265      }
    12661266      *_os << std::endl;
     
    12681268      std::vector<Node> nodes;
    12691269      for (NodeIt n(_graph); n != INVALID; ++n) {
    1270         nodes.push_back(n);
    1271       }
    1272      
     1270        nodes.push_back(n);
     1271      }
     1272
    12731273      if (label == 0) {
    1274         IdMap<Graph, Node> id_map(_graph);
    1275         _writer_bits::MapLess<IdMap<Graph, Node> > id_less(id_map);
    1276         std::sort(nodes.begin(), nodes.end(), id_less);
     1274        IdMap<Graph, Node> id_map(_graph);
     1275        _writer_bits::MapLess<IdMap<Graph, Node> > id_less(id_map);
     1276        std::sort(nodes.begin(), nodes.end(), id_less);
    12771277      } else {
    1278         label->sort(nodes);
     1278        label->sort(nodes);
    12791279      }
    12801280
    12811281      for (int i = 0; i < static_cast<int>(nodes.size()); ++i) {
    1282         Node n = nodes[i];
    1283         if (label == 0) {
    1284           std::ostringstream os;
    1285           os << _graph.id(n);
    1286           _writer_bits::writeToken(*_os, os.str());
    1287           *_os << '\t';
    1288           _node_index.insert(std::make_pair(n, os.str()));
    1289         }
    1290         for (typename NodeMaps::iterator it = _node_maps.begin();
    1291              it != _node_maps.end(); ++it) {
    1292           std::string value = it->second->get(n);
    1293           _writer_bits::writeToken(*_os, value);
    1294           if (it->first == "label") {
    1295             _node_index.insert(std::make_pair(n, value));
    1296           }
    1297           *_os << '\t';
    1298         }
    1299         *_os << std::endl;
     1282        Node n = nodes[i];
     1283        if (label == 0) {
     1284          std::ostringstream os;
     1285          os << _graph.id(n);
     1286          _writer_bits::writeToken(*_os, os.str());
     1287          *_os << '\t';
     1288          _node_index.insert(std::make_pair(n, os.str()));
     1289        }
     1290        for (typename NodeMaps::iterator it = _node_maps.begin();
     1291             it != _node_maps.end(); ++it) {
     1292          std::string value = it->second->get(n);
     1293          _writer_bits::writeToken(*_os, value);
     1294          if (it->first == "label") {
     1295            _node_index.insert(std::make_pair(n, value));
     1296          }
     1297          *_os << '\t';
     1298        }
     1299        *_os << std::endl;
    13001300      }
    13011301    }
     
    13041304      _writer_bits::MapStorageBase<Node>* label = 0;
    13051305      for (typename NodeMaps::iterator it = _node_maps.begin();
    1306            it != _node_maps.end(); ++it) {
     1306           it != _node_maps.end(); ++it) {
    13071307        if (it->first == "label") {
    1308           label = it->second;
    1309           break;
    1310         }
     1308          label = it->second;
     1309          break;
     1310        }
    13111311      }
    13121312
    13131313      if (label == 0) {
    1314         for (NodeIt n(_graph); n != INVALID; ++n) {
    1315           std::ostringstream os;
    1316           os << _graph.id(n);
    1317           _node_index.insert(std::make_pair(n, os.str()));       
    1318         }       
     1314        for (NodeIt n(_graph); n != INVALID; ++n) {
     1315          std::ostringstream os;
     1316          os << _graph.id(n);
     1317          _node_index.insert(std::make_pair(n, os.str()));
     1318        }
    13191319      } else {
    1320         for (NodeIt n(_graph); n != INVALID; ++n) {
    1321           std::string value = label->get(n);     
    1322           _node_index.insert(std::make_pair(n, value));
    1323         }
     1320        for (NodeIt n(_graph); n != INVALID; ++n) {
     1321          std::string value = label->get(n);
     1322          _node_index.insert(std::make_pair(n, value));
     1323        }
    13241324      }
    13251325    }
     
    13281328      _writer_bits::MapStorageBase<Edge>* label = 0;
    13291329      for (typename EdgeMaps::iterator it = _edge_maps.begin();
    1330            it != _edge_maps.end(); ++it) {
     1330           it != _edge_maps.end(); ++it) {
    13311331        if (it->first == "label") {
    1332           label = it->second;
    1333           break;
    1334         }
     1332          label = it->second;
     1333          break;
     1334        }
    13351335      }
    13361336
    13371337      *_os << "@edges";
    13381338      if (!_edges_caption.empty()) {
    1339         _writer_bits::writeToken(*_os << ' ', _edges_caption);
     1339        _writer_bits::writeToken(*_os << ' ', _edges_caption);
    13401340      }
    13411341      *_os << std::endl;
     
    13431343      *_os << '\t' << '\t';
    13441344      if (label == 0) {
    1345         *_os << "label" << '\t';
     1345        *_os << "label" << '\t';
    13461346      }
    13471347      for (typename EdgeMaps::iterator it = _edge_maps.begin();
    1348            it != _edge_maps.end(); ++it) {
    1349         _writer_bits::writeToken(*_os, it->first) << '\t';
     1348           it != _edge_maps.end(); ++it) {
     1349        _writer_bits::writeToken(*_os, it->first) << '\t';
    13501350      }
    13511351      *_os << std::endl;
     
    13531353      std::vector<Edge> edges;
    13541354      for (EdgeIt n(_graph); n != INVALID; ++n) {
    1355         edges.push_back(n);
    1356       }
    1357      
     1355        edges.push_back(n);
     1356      }
     1357
    13581358      if (label == 0) {
    1359         IdMap<Graph, Edge> id_map(_graph);
    1360         _writer_bits::MapLess<IdMap<Graph, Edge> > id_less(id_map);
    1361         std::sort(edges.begin(), edges.end(), id_less);
     1359        IdMap<Graph, Edge> id_map(_graph);
     1360        _writer_bits::MapLess<IdMap<Graph, Edge> > id_less(id_map);
     1361        std::sort(edges.begin(), edges.end(), id_less);
    13621362      } else {
    1363         label->sort(edges);
     1363        label->sort(edges);
    13641364      }
    13651365
    13661366      for (int i = 0; i < static_cast<int>(edges.size()); ++i) {
    1367         Edge e = edges[i];
    1368         _writer_bits::writeToken(*_os, _node_index.
    1369                                 find(_graph.u(e))->second);
    1370         *_os << '\t';
    1371         _writer_bits::writeToken(*_os, _node_index.
    1372                                 find(_graph.v(e))->second);
    1373         *_os << '\t';
    1374         if (label == 0) {
    1375           std::ostringstream os;
    1376           os << _graph.id(e);
    1377           _writer_bits::writeToken(*_os, os.str());
    1378           *_os << '\t';
    1379           _edge_index.insert(std::make_pair(e, os.str()));
    1380         }
    1381         for (typename EdgeMaps::iterator it = _edge_maps.begin();
    1382              it != _edge_maps.end(); ++it) {
    1383           std::string value = it->second->get(e);
    1384           _writer_bits::writeToken(*_os, value);
    1385           if (it->first == "label") {
    1386             _edge_index.insert(std::make_pair(e, value));
    1387           }
    1388           *_os << '\t';
    1389         }
    1390         *_os << std::endl;
     1367        Edge e = edges[i];
     1368        _writer_bits::writeToken(*_os, _node_index.
     1369                                find(_graph.u(e))->second);
     1370        *_os << '\t';
     1371        _writer_bits::writeToken(*_os, _node_index.
     1372                                find(_graph.v(e))->second);
     1373        *_os << '\t';
     1374        if (label == 0) {
     1375          std::ostringstream os;
     1376          os << _graph.id(e);
     1377          _writer_bits::writeToken(*_os, os.str());
     1378          *_os << '\t';
     1379          _edge_index.insert(std::make_pair(e, os.str()));
     1380        }
     1381        for (typename EdgeMaps::iterator it = _edge_maps.begin();
     1382             it != _edge_maps.end(); ++it) {
     1383          std::string value = it->second->get(e);
     1384          _writer_bits::writeToken(*_os, value);
     1385          if (it->first == "label") {
     1386            _edge_index.insert(std::make_pair(e, value));
     1387          }
     1388          *_os << '\t';
     1389        }
     1390        *_os << std::endl;
    13911391      }
    13921392    }
     
    13951395      _writer_bits::MapStorageBase<Edge>* label = 0;
    13961396      for (typename EdgeMaps::iterator it = _edge_maps.begin();
    1397            it != _edge_maps.end(); ++it) {
     1397           it != _edge_maps.end(); ++it) {
    13981398        if (it->first == "label") {
    1399           label = it->second;
    1400           break;
    1401         }
     1399          label = it->second;
     1400          break;
     1401        }
    14021402      }
    14031403
    14041404      if (label == 0) {
    1405         for (EdgeIt e(_graph); e != INVALID; ++e) {
    1406           std::ostringstream os;
    1407           os << _graph.id(e);
    1408           _edge_index.insert(std::make_pair(e, os.str()));       
    1409         }       
     1405        for (EdgeIt e(_graph); e != INVALID; ++e) {
     1406          std::ostringstream os;
     1407          os << _graph.id(e);
     1408          _edge_index.insert(std::make_pair(e, os.str()));
     1409        }
    14101410      } else {
    1411         for (EdgeIt e(_graph); e != INVALID; ++e) {
    1412           std::string value = label->get(e);     
    1413           _edge_index.insert(std::make_pair(e, value));
    1414         }
     1411        for (EdgeIt e(_graph); e != INVALID; ++e) {
     1412          std::string value = label->get(e);
     1413          _edge_index.insert(std::make_pair(e, value));
     1414        }
    14151415      }
    14161416    }
     
    14201420      *_os << "@attributes";
    14211421      if (!_attributes_caption.empty()) {
    1422         _writer_bits::writeToken(*_os << ' ', _attributes_caption);
     1422        _writer_bits::writeToken(*_os << ' ', _attributes_caption);
    14231423      }
    14241424      *_os << std::endl;
    14251425      for (typename Attributes::iterator it = _attributes.begin();
    1426            it != _attributes.end(); ++it) {
    1427         _writer_bits::writeToken(*_os, it->first) << ' ';
    1428         _writer_bits::writeToken(*_os, it->second->get());
    1429         *_os << std::endl;
    1430       }
    1431     }
    1432    
     1426           it != _attributes.end(); ++it) {
     1427        _writer_bits::writeToken(*_os, it->first) << ' ';
     1428        _writer_bits::writeToken(*_os, it->second->get());
     1429        *_os << std::endl;
     1430      }
     1431    }
     1432
    14331433  public:
    1434    
    1435     /// \name Execution of the writer   
     1434
     1435    /// \name Execution of the writer
    14361436    /// @{
    14371437
     
    14411441    void run() {
    14421442      if (!_skip_nodes) {
    1443         writeNodes();
     1443        writeNodes();
    14441444      } else {
    1445         createNodeIndex();
    1446       }
    1447       if (!_skip_edges) {     
    1448         writeEdges();
     1445        createNodeIndex();
     1446      }
     1447      if (!_skip_edges) {
     1448        writeEdges();
    14491449      } else {
    1450         createEdgeIndex();
     1450        createEdgeIndex();
    14511451      }
    14521452      writeAttributes();
     
    14641464
    14651465  /// \brief Return a \ref GraphWriter class
    1466   /// 
     1466  ///
    14671467  /// This function just returns a \ref GraphWriter class.
    14681468  /// \relates GraphWriter
     
    14741474
    14751475  /// \brief Return a \ref GraphWriter class
    1476   /// 
     1476  ///
    14771477  /// This function just returns a \ref GraphWriter class.
    14781478  /// \relates GraphWriter
     
    14841484
    14851485  /// \brief Return a \ref GraphWriter class
    1486   /// 
     1486  ///
    14871487  /// This function just returns a \ref GraphWriter class.
    14881488  /// \relates GraphWriter
Note: See TracChangeset for help on using the changeset viewer.