COIN-OR::LEMON - Graph Library

Changeset 209:765619b7cbb2 in lemon-main for lemon/lgf_reader.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_reader.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
     
    4747    struct DefaultConverter {
    4848      Value operator()(const std::string& str) {
    49         std::istringstream is(str);
    50         Value value;
    51         is >> value;
    52 
    53         char c;
    54         if (is >> std::ws >> c) {
    55           throw DataFormatError("Remaining characters in token");
    56         }
    57         return value;
     49        std::istringstream is(str);
     50        Value value;
     51        is >> value;
     52
     53        char c;
     54        if (is >> std::ws >> c) {
     55          throw DataFormatError("Remaining characters in token");
     56        }
     57        return value;
    5858      }
    5959    };
     
    6262    struct DefaultConverter<std::string> {
    6363      std::string operator()(const std::string& str) {
    64         return str;
     64        return str;
    6565      }
    6666    };
    6767
    68     template <typename _Item>   
     68    template <typename _Item>
    6969    class MapStorageBase {
    7070    public:
     
    7979    };
    8080
    81     template <typename _Item, typename _Map, 
    82               typename _Converter = DefaultConverter<typename _Map::Value> >
     81    template <typename _Item, typename _Map,
     82              typename _Converter = DefaultConverter<typename _Map::Value> >
    8383    class MapStorage : public MapStorageBase<_Item> {
    8484    public:
     
    8686      typedef _Converter Converter;
    8787      typedef _Item Item;
    88      
     88
    8989    private:
    9090      Map& _map;
     
    9292
    9393    public:
    94       MapStorage(Map& map, const Converter& converter = Converter()) 
    95         : _map(map), _converter(converter) {}
     94      MapStorage(Map& map, const Converter& converter = Converter())
     95        : _map(map), _converter(converter) {}
    9696      virtual ~MapStorage() {}
    9797
    9898      virtual void set(const Item& item ,const std::string& value) {
    99         _map.set(item, _converter(value));
     99        _map.set(item, _converter(value));
    100100      }
    101101    };
    102102
    103     template <typename _Graph, bool _dir, typename _Map, 
    104               typename _Converter = DefaultConverter<typename _Map::Value> >
     103    template <typename _Graph, bool _dir, typename _Map,
     104              typename _Converter = DefaultConverter<typename _Map::Value> >
    105105    class GraphArcMapStorage : public MapStorageBase<typename _Graph::Edge> {
    106106    public:
     
    110110      typedef typename Graph::Edge Item;
    111111      static const bool dir = _dir;
    112      
     112
    113113    private:
    114114      const Graph& _graph;
     
    117117
    118118    public:
    119       GraphArcMapStorage(const Graph& graph, Map& map, 
    120                          const Converter& converter = Converter())
    121         : _graph(graph), _map(map), _converter(converter) {}
     119      GraphArcMapStorage(const Graph& graph, Map& map,
     120                         const Converter& converter = Converter())
     121        : _graph(graph), _map(map), _converter(converter) {}
    122122      virtual ~GraphArcMapStorage() {}
    123123
    124124      virtual void set(const Item& item ,const std::string& value) {
    125         _map.set(_graph.direct(item, dir), _converter(value));
     125        _map.set(_graph.direct(item, dir), _converter(value));
    126126      }
    127127    };
     
    147147    public:
    148148      ValueStorage(Value& value, const Converter& converter = Converter())
    149         : _value(value), _converter(converter) {}
     149         : _value(value), _converter(converter) {}
    150150
    151151      virtual void set(const std::string& value) {
    152         _value = _converter(value);
     152        _value = _converter(value);
    153153      }
    154154    };
     
    177177      const Graph& _graph;
    178178      const std::map<std::string, typename Graph::Edge>& _map;
    179      
    180       GraphArcLookUpConverter(const Graph& graph, 
    181                               const std::map<std::string,
    182                                              typename Graph::Edge>& map)
    183         : _graph(graph), _map(map) {}
    184      
     179
     180      GraphArcLookUpConverter(const Graph& graph,
     181                              const std::map<std::string,
     182                                             typename Graph::Edge>& map)
     183        : _graph(graph), _map(map) {}
     184
    185185      typename Graph::Arc operator()(const std::string& str) {
    186         if (str.empty() || (str[0] != '+' && str[0] != '-')) {
    187           throw DataFormatError("Item must start with '+' or '-'");
    188         }
    189         typename std::map<std::string, typename Graph::Edge>
    190           ::const_iterator it = _map.find(str.substr(1));
    191         if (it == _map.end()) {
    192           throw DataFormatError("Item not found");
    193         }
    194         return _graph.direct(it->second, str[0] == '+');
     186        if (str.empty() || (str[0] != '+' && str[0] != '-')) {
     187          throw DataFormatError("Item must start with '+' or '-'");
     188        }
     189        typename std::map<std::string, typename Graph::Edge>
     190          ::const_iterator it = _map.find(str.substr(1));
     191        if (it == _map.end()) {
     192          throw DataFormatError("Item not found");
     193        }
     194        return _graph.direct(it->second, str[0] == '+');
    195195      }
    196196    };
    197197
    198198    inline bool isWhiteSpace(char c) {
    199       return c == ' ' || c == '\t' || c == '\v' || 
    200         c == '\n' || c == '\r' || c == '\f'; 
    201     }
    202    
     199      return c == ' ' || c == '\t' || c == '\v' ||
     200        c == '\n' || c == '\r' || c == '\f';
     201    }
     202
    203203    inline bool isOct(char c) {
    204       return '0' <= c && c <='7'; 
    205     }
    206    
     204      return '0' <= c && c <='7';
     205    }
     206
    207207    inline int valueOct(char c) {
    208208      LEMON_ASSERT(isOct(c), "The character is not octal.");
     
    211211
    212212    inline bool isHex(char c) {
    213       return ('0' <= c && c <= '9') || 
    214         ('a' <= c && c <= 'z') ||
    215         ('A' <= c && c <= 'Z');
    216     }
    217    
     213      return ('0' <= c && c <= '9') ||
     214        ('a' <= c && c <= 'z') ||
     215        ('A' <= c && c <= 'Z');
     216    }
     217
    218218    inline int valueHex(char c) {
    219219      LEMON_ASSERT(isHex(c), "The character is not hexadecimal.");
     
    225225    inline bool isIdentifierFirstChar(char c) {
    226226      return ('a' <= c && c <= 'z') ||
    227         ('A' <= c && c <= 'Z') || c == '_';
     227        ('A' <= c && c <= 'Z') || c == '_';
    228228    }
    229229
    230230    inline bool isIdentifierChar(char c) {
    231231      return isIdentifierFirstChar(c) ||
    232         ('0' <= c && c <= '9');
     232        ('0' <= c && c <= '9');
    233233    }
    234234
     
    236236      char c;
    237237      if (!is.get(c))
    238         throw DataFormatError("Escape format error");
     238        throw DataFormatError("Escape format error");
    239239
    240240      switch (c) {
    241241      case '\\':
    242         return '\\';
     242        return '\\';
    243243      case '\"':
    244         return '\"';
     244        return '\"';
    245245      case '\'':
    246         return '\'';
     246        return '\'';
    247247      case '\?':
    248         return '\?';
     248        return '\?';
    249249      case 'a':
    250         return '\a';
     250        return '\a';
    251251      case 'b':
    252         return '\b';
     252        return '\b';
    253253      case 'f':
    254         return '\f';
     254        return '\f';
    255255      case 'n':
    256         return '\n';
     256        return '\n';
    257257      case 'r':
    258         return '\r';
     258        return '\r';
    259259      case 't':
    260         return '\t';
     260        return '\t';
    261261      case 'v':
    262         return '\v';
     262        return '\v';
    263263      case 'x':
    264         {
    265           int code;
    266           if (!is.get(c) || !isHex(c))
    267             throw DataFormatError("Escape format error");
    268           else if (code = valueHex(c), !is.get(c) || !isHex(c)) is.putback(c);
    269           else code = code * 16 + valueHex(c);
    270           return code;
    271         }
     264        {
     265          int code;
     266          if (!is.get(c) || !isHex(c))
     267            throw DataFormatError("Escape format error");
     268          else if (code = valueHex(c), !is.get(c) || !isHex(c)) is.putback(c);
     269          else code = code * 16 + valueHex(c);
     270          return code;
     271        }
    272272      default:
    273         {
    274           int code;
    275           if (!isOct(c))
    276             throw DataFormatError("Escape format error");
    277           else if (code = valueOct(c), !is.get(c) || !isOct(c))
    278             is.putback(c);
    279           else if (code = code * 8 + valueOct(c), !is.get(c) || !isOct(c))
    280             is.putback(c);
    281           else code = code * 8 + valueOct(c);
    282           return code;
    283         }             
    284       } 
    285     }
    286    
     273        {
     274          int code;
     275          if (!isOct(c))
     276            throw DataFormatError("Escape format error");
     277          else if (code = valueOct(c), !is.get(c) || !isOct(c))
     278            is.putback(c);
     279          else if (code = code * 8 + valueOct(c), !is.get(c) || !isOct(c))
     280            is.putback(c);
     281          else code = code * 8 + valueOct(c);
     282          return code;
     283        }
     284      }
     285    }
     286
    287287    inline std::istream& readToken(std::istream& is, std::string& str) {
    288288      std::ostringstream os;
     
    290290      char c;
    291291      is >> std::ws;
    292      
    293       if (!is.get(c)) 
    294         return is;
     292
     293      if (!is.get(c))
     294        return is;
    295295
    296296      if (c == '\"') {
    297         while (is.get(c) && c != '\"') {
    298           if (c == '\\')
    299             c = readEscape(is);
    300           os << c;
    301         }
    302         if (!is)
    303           throw DataFormatError("Quoted format error");
     297        while (is.get(c) && c != '\"') {
     298          if (c == '\\')
     299            c = readEscape(is);
     300          os << c;
     301        }
     302        if (!is)
     303          throw DataFormatError("Quoted format error");
    304304      } else {
    305         is.putback(c);
    306         while (is.get(c) && !isWhiteSpace(c)) {
    307           if (c == '\\')
    308             c = readEscape(is);
    309           os << c;
    310         }
    311         if (!is) {
    312           is.clear();
    313         } else {
    314           is.putback(c);
    315         }
     305        is.putback(c);
     306        while (is.get(c) && !isWhiteSpace(c)) {
     307          if (c == '\\')
     308            c = readEscape(is);
     309          os << c;
     310        }
     311        if (!is) {
     312          is.clear();
     313        } else {
     314          is.putback(c);
     315        }
    316316      }
    317317      str = os.str();
     
    332332
    333333    public:
    334      
     334
    335335      LineSection(const Functor& functor) : _functor(functor) {}
    336336      virtual ~LineSection() {}
    337337
    338338      virtual void process(std::istream& is, int& line_num) {
    339         char c;
    340         std::string line;
    341         while (is.get(c) && c != '@') {
    342           if (c == '\n') {
    343             ++line_num;
    344           } else if (c == '#') {
    345             getline(is, line);
    346             ++line_num;
    347           } else if (!isWhiteSpace(c)) {
    348             is.putback(c);
    349             getline(is, line);
    350             _functor(line);
    351             ++line_num;
    352           }
    353         }
    354         if (is) is.putback(c);
    355         else if (is.eof()) is.clear();
     339        char c;
     340        std::string line;
     341        while (is.get(c) && c != '@') {
     342          if (c == '\n') {
     343            ++line_num;
     344          } else if (c == '#') {
     345            getline(is, line);
     346            ++line_num;
     347          } else if (!isWhiteSpace(c)) {
     348            is.putback(c);
     349            getline(is, line);
     350            _functor(line);
     351            ++line_num;
     352          }
     353        }
     354        if (is) is.putback(c);
     355        else if (is.eof()) is.clear();
    356356      }
    357357    };
     
    364364
    365365    public:
    366      
     366
    367367      StreamSection(const Functor& functor) : _functor(functor) {}
    368       virtual ~StreamSection() {} 
     368      virtual ~StreamSection() {}
    369369
    370370      virtual void process(std::istream& is, int& line_num) {
    371         _functor(is, line_num);
    372         char c;
    373         std::string line;
    374         while (is.get(c) && c != '@') {
    375           if (c == '\n') {
    376             ++line_num;
    377           } else if (!isWhiteSpace(c)) {
    378             getline(is, line);
    379             ++line_num;
    380           }
    381         }
    382         if (is) is.putback(c);
    383         else if (is.eof()) is.clear(); 
     371        _functor(is, line_num);
     372        char c;
     373        std::string line;
     374        while (is.get(c) && c != '@') {
     375          if (c == '\n') {
     376            ++line_num;
     377          } else if (!isWhiteSpace(c)) {
     378            getline(is, line);
     379            ++line_num;
     380          }
     381        }
     382        if (is) is.putback(c);
     383        else if (is.eof()) is.clear();
    384384      }
    385385    };
    386    
     386
    387387  }
    388388
     
    400400
    401401  /// \ingroup lemon_io
    402   /// 
     402  ///
    403403  /// \brief \ref lgf-format "LGF" reader for directed graphs
    404404  ///
     
    454454    typedef _Digraph Digraph;
    455455    TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
    456    
     456
    457457  private:
    458458
     
    471471    typedef std::map<std::string, Arc> ArcIndex;
    472472    ArcIndex _arc_index;
    473    
    474     typedef std::vector<std::pair<std::string, 
    475       _reader_bits::MapStorageBase<Node>*> > NodeMaps;   
    476     NodeMaps _node_maps; 
     473
     474    typedef std::vector<std::pair<std::string,
     475      _reader_bits::MapStorageBase<Node>*> > NodeMaps;
     476    NodeMaps _node_maps;
    477477
    478478    typedef std::vector<std::pair<std::string,
     
    480480    ArcMaps _arc_maps;
    481481
    482     typedef std::multimap<std::string, _reader_bits::ValueStorageBase*> 
     482    typedef std::multimap<std::string, _reader_bits::ValueStorageBase*>
    483483      Attributes;
    484484    Attributes _attributes;
     
    499499    /// Construct a directed graph reader, which reads from the given
    500500    /// input stream.
    501     DigraphReader(std::istream& is, Digraph& digraph) 
     501    DigraphReader(std::istream& is, Digraph& digraph)
    502502      : _is(&is), local_is(false), _digraph(digraph),
    503         _use_nodes(false), _use_arcs(false),
    504         _skip_nodes(false), _skip_arcs(false) {}
     503        _use_nodes(false), _use_arcs(false),
     504        _skip_nodes(false), _skip_arcs(false) {}
    505505
    506506    /// \brief Constructor
     
    508508    /// Construct a directed graph reader, which reads from the given
    509509    /// file.
    510     DigraphReader(const std::string& fn, Digraph& digraph) 
     510    DigraphReader(const std::string& fn, Digraph& digraph)
    511511      : _is(new std::ifstream(fn.c_str())), local_is(true), _digraph(digraph),
    512         _use_nodes(false), _use_arcs(false),
    513         _skip_nodes(false), _skip_arcs(false) {}
    514    
     512            _use_nodes(false), _use_arcs(false),
     513        _skip_nodes(false), _skip_arcs(false) {}
     514
    515515    /// \brief Constructor
    516516    ///
    517517    /// Construct a directed graph reader, which reads from the given
    518518    /// file.
    519     DigraphReader(const char* fn, Digraph& digraph) 
     519    DigraphReader(const char* fn, Digraph& digraph)
    520520      : _is(new std::ifstream(fn)), local_is(true), _digraph(digraph),
    521         _use_nodes(false), _use_arcs(false),
    522         _skip_nodes(false), _skip_arcs(false) {}
     521            _use_nodes(false), _use_arcs(false),
     522        _skip_nodes(false), _skip_arcs(false) {}
    523523
    524524    /// \brief Destructor
    525525    ~DigraphReader() {
    526       for (typename NodeMaps::iterator it = _node_maps.begin(); 
    527            it != _node_maps.end(); ++it) {
    528         delete it->second;
    529       }
    530 
    531       for (typename ArcMaps::iterator it = _arc_maps.begin(); 
    532            it != _arc_maps.end(); ++it) {
    533         delete it->second;
    534       }
    535 
    536       for (typename Attributes::iterator it = _attributes.begin(); 
    537            it != _attributes.end(); ++it) {
    538         delete it->second;
     526      for (typename NodeMaps::iterator it = _node_maps.begin();
     527           it != _node_maps.end(); ++it) {
     528        delete it->second;
     529      }
     530
     531      for (typename ArcMaps::iterator it = _arc_maps.begin();
     532           it != _arc_maps.end(); ++it) {
     533        delete it->second;
     534      }
     535
     536      for (typename Attributes::iterator it = _attributes.begin();
     537           it != _attributes.end(); ++it) {
     538        delete it->second;
    539539      }
    540540
    541541      if (local_is) {
    542         delete _is;
     542        delete _is;
    543543      }
    544544
     
    547547  private:
    548548
    549     friend DigraphReader<Digraph> digraphReader<>(std::istream& is, 
    550                                                   Digraph& digraph);   
    551     friend DigraphReader<Digraph> digraphReader<>(const std::string& fn, 
    552                                                   Digraph& digraph);   
    553     friend DigraphReader<Digraph> digraphReader<>(const char *fn, 
    554                                                   Digraph& digraph);   
    555 
    556     DigraphReader(DigraphReader& other) 
     549    friend DigraphReader<Digraph> digraphReader<>(std::istream& is,
     550                                                  Digraph& digraph);
     551    friend DigraphReader<Digraph> digraphReader<>(const std::string& fn,
     552                                                  Digraph& digraph);
     553    friend DigraphReader<Digraph> digraphReader<>(const char *fn,
     554                                                  Digraph& digraph);
     555
     556    DigraphReader(DigraphReader& other)
    557557      : _is(other._is), local_is(other.local_is), _digraph(other._digraph),
    558         _use_nodes(other._use_nodes), _use_arcs(other._use_arcs),
    559         _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
     558        _use_nodes(other._use_nodes), _use_arcs(other._use_arcs),
     559        _skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
    560560
    561561      other._is = 0;
    562562      other.local_is = false;
    563      
     563
    564564      _node_index.swap(other._node_index);
    565565      _arc_index.swap(other._arc_index);
     
    581581    /// \name Reading rules
    582582    /// @{
    583    
     583
    584584    /// \brief Node map reading rule
    585585    ///
     
    588588    DigraphReader& nodeMap(const std::string& caption, Map& map) {
    589589      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
    590       _reader_bits::MapStorageBase<Node>* storage = 
    591         new _reader_bits::MapStorage<Node, Map>(map);
     590      _reader_bits::MapStorageBase<Node>* storage =
     591        new _reader_bits::MapStorage<Node, Map>(map);
    592592      _node_maps.push_back(std::make_pair(caption, storage));
    593593      return *this;
     
    599599    /// reader.
    600600    template <typename Map, typename Converter>
    601     DigraphReader& nodeMap(const std::string& caption, Map& map, 
    602                            const Converter& converter = Converter()) {
     601    DigraphReader& nodeMap(const std::string& caption, Map& map,
     602                           const Converter& converter = Converter()) {
    603603      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
    604       _reader_bits::MapStorageBase<Node>* storage = 
    605         new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
     604      _reader_bits::MapStorageBase<Node>* storage =
     605        new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
    606606      _node_maps.push_back(std::make_pair(caption, storage));
    607607      return *this;
     
    614614    DigraphReader& arcMap(const std::string& caption, Map& map) {
    615615      checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>();
    616       _reader_bits::MapStorageBase<Arc>* storage = 
    617         new _reader_bits::MapStorage<Arc, Map>(map);
     616      _reader_bits::MapStorageBase<Arc>* storage =
     617        new _reader_bits::MapStorage<Arc, Map>(map);
    618618      _arc_maps.push_back(std::make_pair(caption, storage));
    619619      return *this;
     
    625625    /// reader.
    626626    template <typename Map, typename Converter>
    627     DigraphReader& arcMap(const std::string& caption, Map& map, 
    628                           const Converter& converter = Converter()) {
     627    DigraphReader& arcMap(const std::string& caption, Map& map,
     628                          const Converter& converter = Converter()) {
    629629      checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>();
    630       _reader_bits::MapStorageBase<Arc>* storage = 
    631         new _reader_bits::MapStorage<Arc, Map, Converter>(map, converter);
     630      _reader_bits::MapStorageBase<Arc>* storage =
     631        new _reader_bits::MapStorage<Arc, Map, Converter>(map, converter);
    632632      _arc_maps.push_back(std::make_pair(caption, storage));
    633633      return *this;
     
    639639    template <typename Value>
    640640    DigraphReader& attribute(const std::string& caption, Value& value) {
    641       _reader_bits::ValueStorageBase* storage = 
    642         new _reader_bits::ValueStorage<Value>(value);
     641      _reader_bits::ValueStorageBase* storage =
     642        new _reader_bits::ValueStorage<Value>(value);
    643643      _attributes.insert(std::make_pair(caption, storage));
    644644      return *this;
     
    650650    /// reader.
    651651    template <typename Value, typename Converter>
    652     DigraphReader& attribute(const std::string& caption, Value& value, 
    653                              const Converter& converter = Converter()) {
    654       _reader_bits::ValueStorageBase* storage = 
    655         new _reader_bits::ValueStorage<Value, Converter>(value, converter);
     652    DigraphReader& attribute(const std::string& caption, Value& value,
     653                             const Converter& converter = Converter()) {
     654      _reader_bits::ValueStorageBase* storage =
     655        new _reader_bits::ValueStorage<Value, Converter>(value, converter);
    656656      _attributes.insert(std::make_pair(caption, storage));
    657657      return *this;
     
    664664      typedef _reader_bits::MapLookUpConverter<Node> Converter;
    665665      Converter converter(_node_index);
    666       _reader_bits::ValueStorageBase* storage = 
    667         new _reader_bits::ValueStorage<Node, Converter>(node, converter);
     666      _reader_bits::ValueStorageBase* storage =
     667        new _reader_bits::ValueStorage<Node, Converter>(node, converter);
    668668      _attributes.insert(std::make_pair(caption, storage));
    669669      return *this;
     
    676676      typedef _reader_bits::MapLookUpConverter<Arc> Converter;
    677677      Converter converter(_arc_index);
    678       _reader_bits::ValueStorageBase* storage = 
    679         new _reader_bits::ValueStorage<Arc, Converter>(arc, converter);
     678      _reader_bits::ValueStorageBase* storage =
     679        new _reader_bits::ValueStorage<Arc, Converter>(arc, converter);
    680680      _attributes.insert(std::make_pair(caption, storage));
    681681      return *this;
     
    723723    DigraphReader& useNodes(const Map& map) {
    724724      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
    725       LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); 
     725      LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member");
    726726      _use_nodes = true;
    727727      _writer_bits::DefaultConverter<typename Map::Value> converter;
    728728      for (NodeIt n(_digraph); n != INVALID; ++n) {
    729         _node_index.insert(std::make_pair(converter(map[n]), n));
     729        _node_index.insert(std::make_pair(converter(map[n]), n));
    730730      }
    731731      return *this;
     
    738738    /// \c std::string.
    739739    template <typename Map, typename Converter>
    740     DigraphReader& useNodes(const Map& map, 
    741                             const Converter& converter = Converter()) {
     740    DigraphReader& useNodes(const Map& map,
     741                            const Converter& converter = Converter()) {
    742742      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
    743       LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); 
     743      LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member");
    744744      _use_nodes = true;
    745745      for (NodeIt n(_digraph); n != INVALID; ++n) {
    746         _node_index.insert(std::make_pair(converter(map[n]), n));
     746        _node_index.insert(std::make_pair(converter(map[n]), n));
    747747      }
    748748      return *this;
     
    760760      _writer_bits::DefaultConverter<typename Map::Value> converter;
    761761      for (ArcIt a(_digraph); a != INVALID; ++a) {
    762         _arc_index.insert(std::make_pair(converter(map[a]), a));
     762        _arc_index.insert(std::make_pair(converter(map[a]), a));
    763763      }
    764764      return *this;
     
    771771    /// \c std::string.
    772772    template <typename Map, typename Converter>
    773     DigraphReader& useArcs(const Map& map, 
    774                            const Converter& converter = Converter()) {
     773    DigraphReader& useArcs(const Map& map,
     774                           const Converter& converter = Converter()) {
    775775      checkConcept<concepts::ReadMap<Arc, typename Map::Value>, Map>();
    776       LEMON_ASSERT(!_use_arcs, "Multiple usage of useArcs() member"); 
     776      LEMON_ASSERT(!_use_arcs, "Multiple usage of useArcs() member");
    777777      _use_arcs = true;
    778778      for (ArcIt a(_digraph); a != INVALID; ++a) {
    779         _arc_index.insert(std::make_pair(converter(map[a]), a));
     779        _arc_index.insert(std::make_pair(converter(map[a]), a));
    780780      }
    781781      return *this;
     
    791791    /// \c useNodes() should be used to specify the label of the nodes.
    792792    DigraphReader& skipNodes() {
    793       LEMON_ASSERT(!_skip_nodes, "Skip nodes already set"); 
     793      LEMON_ASSERT(!_skip_nodes, "Skip nodes already set");
    794794      _skip_nodes = true;
    795795      return *this;
     
    802802    /// will not be constructed.
    803803    DigraphReader& skipArcs() {
    804       LEMON_ASSERT(!_skip_arcs, "Skip arcs already set"); 
     804      LEMON_ASSERT(!_skip_arcs, "Skip arcs already set");
    805805      _skip_arcs = true;
    806806      return *this;
     
    814814      std::string str;
    815815      while(++line_num, std::getline(*_is, str)) {
    816         line.clear(); line.str(str);
    817         char c;
    818         if (line >> std::ws >> c && c != '#') {
    819           line.putback(c);
    820           return true;
    821         }
     816        line.clear(); line.str(str);
     817        char c;
     818        if (line >> std::ws >> c && c != '#') {
     819          line.putback(c);
     820          return true;
     821        }
    822822      }
    823823      return false;
     
    827827      return static_cast<bool>(*_is);
    828828    }
    829    
     829
    830830    void skipSection() {
    831831      char c;
    832832      while (readSuccess() && line >> c && c != '@') {
    833         readLine();
     833        readLine();
    834834      }
    835835      line.putback(c);
     
    843843      char c;
    844844      if (!readLine() || !(line >> c) || c == '@') {
    845         if (readSuccess() && line) line.putback(c);
    846         if (!_node_maps.empty())
    847           throw DataFormatError("Cannot find map names");
    848         return;
     845        if (readSuccess() && line) line.putback(c);
     846        if (!_node_maps.empty())
     847          throw DataFormatError("Cannot find map names");
     848        return;
    849849      }
    850850      line.putback(c);
    851851
    852852      {
    853         std::map<std::string, int> maps;
    854        
    855         std::string map;
    856         int index = 0;
    857         while (_reader_bits::readToken(line, map)) {
    858           if (maps.find(map) != maps.end()) {
    859             std::ostringstream msg;
    860             msg << "Multiple occurence of node map: " << map;
    861             throw DataFormatError(msg.str().c_str());
    862           }
    863           maps.insert(std::make_pair(map, index));
    864           ++index;
    865         }
    866        
    867         for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) {
    868           std::map<std::string, int>::iterator jt =
    869             maps.find(_node_maps[i].first);
    870           if (jt == maps.end()) {
    871             std::ostringstream msg;
    872             msg << "Map not found in file: " << _node_maps[i].first;
    873             throw DataFormatError(msg.str().c_str());
    874           }
    875           map_index[i] = jt->second;
    876         }
    877 
    878         {
    879           std::map<std::string, int>::iterator jt = maps.find("label");
    880           if (jt != maps.end()) {
    881             label_index = jt->second;
    882           } else {
    883             label_index = -1;
    884           }
    885         }
    886         map_num = maps.size();
     853        std::map<std::string, int> maps;
     854
     855        std::string map;
     856        int index = 0;
     857        while (_reader_bits::readToken(line, map)) {
     858          if (maps.find(map) != maps.end()) {
     859            std::ostringstream msg;
     860            msg << "Multiple occurence of node map: " << map;
     861            throw DataFormatError(msg.str().c_str());
     862          }
     863          maps.insert(std::make_pair(map, index));
     864          ++index;
     865        }
     866
     867        for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) {
     868          std::map<std::string, int>::iterator jt =
     869            maps.find(_node_maps[i].first);
     870          if (jt == maps.end()) {
     871            std::ostringstream msg;
     872            msg << "Map not found in file: " << _node_maps[i].first;
     873            throw DataFormatError(msg.str().c_str());
     874          }
     875          map_index[i] = jt->second;
     876        }
     877
     878        {
     879          std::map<std::string, int>::iterator jt = maps.find("label");
     880          if (jt != maps.end()) {
     881            label_index = jt->second;
     882          } else {
     883            label_index = -1;
     884          }
     885        }
     886        map_num = maps.size();
    887887      }
    888888
    889889      while (readLine() && line >> c && c != '@') {
    890         line.putback(c);
    891 
    892         std::vector<std::string> tokens(map_num);
    893         for (int i = 0; i < map_num; ++i) {
    894           if (!_reader_bits::readToken(line, tokens[i])) {
    895             std::ostringstream msg;
    896             msg << "Column not found (" << i + 1 << ")";
    897             throw DataFormatError(msg.str().c_str());
    898           }
    899         }
    900         if (line >> std::ws >> c)
    901           throw DataFormatError("Extra character on the end of line");
    902        
    903         Node n;
    904         if (!_use_nodes) {
    905           n = _digraph.addNode();
    906           if (label_index != -1)
    907             _node_index.insert(std::make_pair(tokens[label_index], n));
    908         } else {
    909           if (label_index == -1)
    910             throw DataFormatError("Label map not found in file");
    911           typename std::map<std::string, Node>::iterator it =
    912             _node_index.find(tokens[label_index]);
    913           if (it == _node_index.end()) {
    914             std::ostringstream msg;
    915             msg << "Node with label not found: " << tokens[label_index];
    916             throw DataFormatError(msg.str().c_str());       
    917           }
    918           n = it->second;
    919         }
    920 
    921         for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) {
    922           _node_maps[i].second->set(n, tokens[map_index[i]]);
    923         }
     890        line.putback(c);
     891
     892        std::vector<std::string> tokens(map_num);
     893        for (int i = 0; i < map_num; ++i) {
     894          if (!_reader_bits::readToken(line, tokens[i])) {
     895            std::ostringstream msg;
     896            msg << "Column not found (" << i + 1 << ")";
     897            throw DataFormatError(msg.str().c_str());
     898          }
     899        }
     900        if (line >> std::ws >> c)
     901          throw DataFormatError("Extra character on the end of line");
     902
     903        Node n;
     904        if (!_use_nodes) {
     905          n = _digraph.addNode();
     906          if (label_index != -1)
     907            _node_index.insert(std::make_pair(tokens[label_index], n));
     908        } else {
     909          if (label_index == -1)
     910            throw DataFormatError("Label map not found in file");
     911          typename std::map<std::string, Node>::iterator it =
     912            _node_index.find(tokens[label_index]);
     913          if (it == _node_index.end()) {
     914            std::ostringstream msg;
     915            msg << "Node with label not found: " << tokens[label_index];
     916            throw DataFormatError(msg.str().c_str());
     917          }
     918          n = it->second;
     919        }
     920
     921        for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) {
     922          _node_maps[i].second->set(n, tokens[map_index[i]]);
     923        }
    924924
    925925      }
    926926      if (readSuccess()) {
    927         line.putback(c);
     927        line.putback(c);
    928928      }
    929929    }
     
    936936      char c;
    937937      if (!readLine() || !(line >> c) || c == '@') {
    938         if (readSuccess() && line) line.putback(c);
    939         if (!_arc_maps.empty())
    940           throw DataFormatError("Cannot find map names");
    941         return;
     938        if (readSuccess() && line) line.putback(c);
     939        if (!_arc_maps.empty())
     940          throw DataFormatError("Cannot find map names");
     941        return;
    942942      }
    943943      line.putback(c);
    944      
     944
    945945      {
    946         std::map<std::string, int> maps;
    947        
    948         std::string map;
    949         int index = 0;
    950         while (_reader_bits::readToken(line, map)) {
    951           if (maps.find(map) != maps.end()) {
    952             std::ostringstream msg;
    953             msg << "Multiple occurence of arc map: " << map;
    954             throw DataFormatError(msg.str().c_str());
    955           }
    956           maps.insert(std::make_pair(map, index));
    957           ++index;
    958         }
    959        
    960         for (int i = 0; i < static_cast<int>(_arc_maps.size()); ++i) {
    961           std::map<std::string, int>::iterator jt =
    962             maps.find(_arc_maps[i].first);
    963           if (jt == maps.end()) {
    964             std::ostringstream msg;
    965             msg << "Map not found in file: " << _arc_maps[i].first;
    966             throw DataFormatError(msg.str().c_str());
    967           }
    968           map_index[i] = jt->second;
    969         }
    970 
    971         {
    972           std::map<std::string, int>::iterator jt = maps.find("label");
    973           if (jt != maps.end()) {
    974             label_index = jt->second;
    975           } else {
    976             label_index = -1;
    977           }
    978         }
    979         map_num = maps.size();
     946        std::map<std::string, int> maps;
     947
     948        std::string map;
     949        int index = 0;
     950        while (_reader_bits::readToken(line, map)) {
     951          if (maps.find(map) != maps.end()) {
     952            std::ostringstream msg;
     953            msg << "Multiple occurence of arc map: " << map;
     954            throw DataFormatError(msg.str().c_str());
     955          }
     956          maps.insert(std::make_pair(map, index));
     957          ++index;
     958        }
     959
     960        for (int i = 0; i < static_cast<int>(_arc_maps.size()); ++i) {
     961          std::map<std::string, int>::iterator jt =
     962            maps.find(_arc_maps[i].first);
     963          if (jt == maps.end()) {
     964            std::ostringstream msg;
     965            msg << "Map not found in file: " << _arc_maps[i].first;
     966            throw DataFormatError(msg.str().c_str());
     967          }
     968          map_index[i] = jt->second;
     969        }
     970
     971        {
     972          std::map<std::string, int>::iterator jt = maps.find("label");
     973          if (jt != maps.end()) {
     974            label_index = jt->second;
     975          } else {
     976            label_index = -1;
     977          }
     978        }
     979        map_num = maps.size();
    980980      }
    981981
    982982      while (readLine() && line >> c && c != '@') {
    983         line.putback(c);
    984 
    985         std::string source_token;
    986         std::string target_token;
    987 
    988         if (!_reader_bits::readToken(line, source_token))
    989           throw DataFormatError("Source not found");
    990 
    991         if (!_reader_bits::readToken(line, target_token))
    992           throw DataFormatError("Target not found");
    993        
    994         std::vector<std::string> tokens(map_num);
    995         for (int i = 0; i < map_num; ++i) {
    996           if (!_reader_bits::readToken(line, tokens[i])) {
    997             std::ostringstream msg;
    998             msg << "Column not found (" << i + 1 << ")";
    999             throw DataFormatError(msg.str().c_str());
    1000           }
    1001         }
    1002         if (line >> std::ws >> c)
    1003           throw DataFormatError("Extra character on the end of line");
    1004        
    1005         Arc a;
    1006         if (!_use_arcs) {
     983        line.putback(c);
     984
     985        std::string source_token;
     986        std::string target_token;
     987
     988        if (!_reader_bits::readToken(line, source_token))
     989          throw DataFormatError("Source not found");
     990
     991        if (!_reader_bits::readToken(line, target_token))
     992          throw DataFormatError("Target not found");
     993
     994        std::vector<std::string> tokens(map_num);
     995        for (int i = 0; i < map_num; ++i) {
     996          if (!_reader_bits::readToken(line, tokens[i])) {
     997            std::ostringstream msg;
     998            msg << "Column not found (" << i + 1 << ")";
     999            throw DataFormatError(msg.str().c_str());
     1000          }
     1001        }
     1002        if (line >> std::ws >> c)
     1003          throw DataFormatError("Extra character on the end of line");
     1004
     1005        Arc a;
     1006        if (!_use_arcs) {
    10071007
    10081008          typename NodeIndex::iterator it;
    1009  
     1009
    10101010          it = _node_index.find(source_token);
    10111011          if (it == _node_index.end()) {
     
    10171017
    10181018          it = _node_index.find(target_token);
    1019           if (it == _node_index.end()) {       
    1020             std::ostringstream msg;           
     1019          if (it == _node_index.end()) {
     1020            std::ostringstream msg;
    10211021            msg << "Item not found: " << target_token;
    10221022            throw DataFormatError(msg.str().c_str());
    1023           }                                         
    1024           Node target = it->second;                           
    1025 
    1026           a = _digraph.addArc(source, target);
    1027           if (label_index != -1)
    1028             _arc_index.insert(std::make_pair(tokens[label_index], a));
    1029         } else {
    1030           if (label_index == -1)
    1031             throw DataFormatError("Label map not found in file");
    1032           typename std::map<std::string, Arc>::iterator it =
    1033             _arc_index.find(tokens[label_index]);
    1034           if (it == _arc_index.end()) {
    1035             std::ostringstream msg;
    1036             msg << "Arc with label not found: " << tokens[label_index];
    1037             throw DataFormatError(msg.str().c_str());       
    1038           }
    1039           a = it->second;
    1040         }
    1041 
    1042         for (int i = 0; i < static_cast<int>(_arc_maps.size()); ++i) {
    1043           _arc_maps[i].second->set(a, tokens[map_index[i]]);
    1044         }
     1023          }
     1024          Node target = it->second;
     1025
     1026          a = _digraph.addArc(source, target);
     1027          if (label_index != -1)
     1028            _arc_index.insert(std::make_pair(tokens[label_index], a));
     1029        } else {
     1030          if (label_index == -1)
     1031            throw DataFormatError("Label map not found in file");
     1032          typename std::map<std::string, Arc>::iterator it =
     1033            _arc_index.find(tokens[label_index]);
     1034          if (it == _arc_index.end()) {
     1035            std::ostringstream msg;
     1036            msg << "Arc with label not found: " << tokens[label_index];
     1037            throw DataFormatError(msg.str().c_str());
     1038          }
     1039          a = it->second;
     1040        }
     1041
     1042        for (int i = 0; i < static_cast<int>(_arc_maps.size()); ++i) {
     1043          _arc_maps[i].second->set(a, tokens[map_index[i]]);
     1044        }
    10451045
    10461046      }
    10471047      if (readSuccess()) {
    1048         line.putback(c);
     1048        line.putback(c);
    10491049      }
    10501050    }
     
    10561056      char c;
    10571057      while (readLine() && line >> c && c != '@') {
    1058         line.putback(c);
    1059        
    1060         std::string attr, token;
    1061         if (!_reader_bits::readToken(line, attr))
    1062           throw DataFormatError("Attribute name not found");
    1063         if (!_reader_bits::readToken(line, token))
    1064           throw DataFormatError("Attribute value not found");
    1065         if (line >> c)
    1066           throw DataFormatError("Extra character on the end of line");   
    1067 
    1068         {
    1069           std::set<std::string>::iterator it = read_attr.find(attr);
    1070           if (it != read_attr.end()) {
    1071             std::ostringstream msg;
    1072             msg << "Multiple occurence of attribute " << attr;
    1073             throw DataFormatError(msg.str().c_str());
    1074           }
    1075           read_attr.insert(attr);
    1076         }
    1077        
    1078         {
    1079           typename Attributes::iterator it = _attributes.lower_bound(attr);
    1080           while (it != _attributes.end() && it->first == attr) {
    1081             it->second->set(token);
    1082             ++it;
    1083           }
    1084         }
     1058        line.putback(c);
     1059
     1060        std::string attr, token;
     1061        if (!_reader_bits::readToken(line, attr))
     1062          throw DataFormatError("Attribute name not found");
     1063        if (!_reader_bits::readToken(line, token))
     1064          throw DataFormatError("Attribute value not found");
     1065        if (line >> c)
     1066          throw DataFormatError("Extra character on the end of line");
     1067
     1068        {
     1069          std::set<std::string>::iterator it = read_attr.find(attr);
     1070          if (it != read_attr.end()) {
     1071            std::ostringstream msg;
     1072            msg << "Multiple occurence of attribute " << attr;
     1073            throw DataFormatError(msg.str().c_str());
     1074          }
     1075          read_attr.insert(attr);
     1076        }
     1077
     1078        {
     1079          typename Attributes::iterator it = _attributes.lower_bound(attr);
     1080          while (it != _attributes.end() && it->first == attr) {
     1081            it->second->set(token);
     1082            ++it;
     1083          }
     1084        }
    10851085
    10861086      }
    10871087      if (readSuccess()) {
    1088         line.putback(c);
     1088        line.putback(c);
    10891089      }
    10901090      for (typename Attributes::iterator it = _attributes.begin();
    1091            it != _attributes.end(); ++it) {
    1092         if (read_attr.find(it->first) == read_attr.end()) {
    1093           std::ostringstream msg;
    1094           msg << "Attribute not found in file: " << it->first;
    1095           throw DataFormatError(msg.str().c_str());
    1096         }       
     1091           it != _attributes.end(); ++it) {
     1092        if (read_attr.find(it->first) == read_attr.end()) {
     1093          std::ostringstream msg;
     1094          msg << "Attribute not found in file: " << it->first;
     1095          throw DataFormatError(msg.str().c_str());
     1096        }
    10971097      }
    10981098    }
     
    11001100  public:
    11011101
    1102     /// \name Execution of the reader   
     1102    /// \name Execution of the reader
    11031103    /// @{
    11041104
     
    11091109      LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
    11101110      if (!*_is) {
    1111         throw DataFormatError("Cannot find file");
    1112       }
    1113      
     1111        throw DataFormatError("Cannot find file");
     1112      }
     1113
    11141114      bool nodes_done = _skip_nodes;
    11151115      bool arcs_done = _skip_arcs;
    11161116      bool attributes_done = false;
    11171117
    1118       line_num = 0;     
     1118      line_num = 0;
    11191119      readLine();
    11201120      skipSection();
    11211121
    11221122      while (readSuccess()) {
    1123         try {
    1124           char c;
    1125           std::string section, caption;
    1126           line >> c;
    1127           _reader_bits::readToken(line, section);
    1128           _reader_bits::readToken(line, caption);
    1129 
    1130           if (line >> c)
    1131             throw DataFormatError("Extra character on the end of line");
    1132 
    1133           if (section == "nodes" && !nodes_done) {
    1134             if (_nodes_caption.empty() || _nodes_caption == caption) {
    1135               readNodes();
    1136               nodes_done = true;
    1137             }
    1138           } else if ((section == "arcs" || section == "edges") &&
    1139                      !arcs_done) {
    1140             if (_arcs_caption.empty() || _arcs_caption == caption) {
    1141               readArcs();
    1142               arcs_done = true;
    1143             }
    1144           } else if (section == "attributes" && !attributes_done) {
    1145             if (_attributes_caption.empty() || _attributes_caption == caption) {
    1146               readAttributes();
    1147               attributes_done = true;
    1148             }
    1149           } else {
    1150             readLine();
    1151             skipSection();
    1152           }
    1153         } catch (DataFormatError& error) {
    1154           error.line(line_num);
    1155           throw;
    1156         }       
     1123        try {
     1124          char c;
     1125          std::string section, caption;
     1126          line >> c;
     1127          _reader_bits::readToken(line, section);
     1128          _reader_bits::readToken(line, caption);
     1129
     1130          if (line >> c)
     1131            throw DataFormatError("Extra character on the end of line");
     1132
     1133          if (section == "nodes" && !nodes_done) {
     1134            if (_nodes_caption.empty() || _nodes_caption == caption) {
     1135              readNodes();
     1136              nodes_done = true;
     1137            }
     1138          } else if ((section == "arcs" || section == "edges") &&
     1139                     !arcs_done) {
     1140            if (_arcs_caption.empty() || _arcs_caption == caption) {
     1141              readArcs();
     1142              arcs_done = true;
     1143            }
     1144          } else if (section == "attributes" && !attributes_done) {
     1145            if (_attributes_caption.empty() || _attributes_caption == caption) {
     1146              readAttributes();
     1147              attributes_done = true;
     1148            }
     1149          } else {
     1150            readLine();
     1151            skipSection();
     1152          }
     1153        } catch (DataFormatError& error) {
     1154          error.line(line_num);
     1155          throw;
     1156        }
    11571157      }
    11581158
    11591159      if (!nodes_done) {
    1160         throw DataFormatError("Section @nodes not found");
     1160        throw DataFormatError("Section @nodes not found");
    11611161      }
    11621162
    11631163      if (!arcs_done) {
    1164         throw DataFormatError("Section @arcs not found");
     1164        throw DataFormatError("Section @arcs not found");
    11651165      }
    11661166
    11671167      if (!attributes_done && !_attributes.empty()) {
    1168         throw DataFormatError("Section @attributes not found");
     1168        throw DataFormatError("Section @attributes not found");
    11691169      }
    11701170
     
    11721172
    11731173    /// @}
    1174    
     1174
    11751175  };
    11761176
    11771177  /// \brief Return a \ref DigraphReader class
    1178   /// 
     1178  ///
    11791179  /// This function just returns a \ref DigraphReader class.
    11801180  /// \relates DigraphReader
     
    11861186
    11871187  /// \brief Return a \ref DigraphReader class
    1188   /// 
     1188  ///
    11891189  /// This function just returns a \ref DigraphReader class.
    11901190  /// \relates DigraphReader
    11911191  template <typename Digraph>
    1192   DigraphReader<Digraph> digraphReader(const std::string& fn, 
    1193                                        Digraph& digraph) {
     1192  DigraphReader<Digraph> digraphReader(const std::string& fn,
     1193                                       Digraph& digraph) {
    11941194    DigraphReader<Digraph> tmp(fn, digraph);
    11951195    return tmp;
     
    11971197
    11981198  /// \brief Return a \ref DigraphReader class
    1199   /// 
     1199  ///
    12001200  /// This function just returns a \ref DigraphReader class.
    12011201  /// \relates DigraphReader
     
    12101210
    12111211  template <typename Graph>
    1212   GraphReader<Graph> graphReader(std::istream& is, Graph& graph);   
     1212  GraphReader<Graph> graphReader(std::istream& is, Graph& graph);
    12131213
    12141214  template <typename Graph>
    1215   GraphReader<Graph> graphReader(const std::string& fn, Graph& graph);   
     1215  GraphReader<Graph> graphReader(const std::string& fn, Graph& graph);
    12161216
    12171217  template <typename Graph>
    1218   GraphReader<Graph> graphReader(const char *fn, Graph& graph);   
     1218  GraphReader<Graph> graphReader(const char *fn, Graph& graph);
    12191219
    12201220  /// \ingroup lemon_io
    1221   /// 
     1221  ///
    12221222  /// \brief \ref lgf-format "LGF" reader for undirected graphs
    12231223  ///
     
    12391239    typedef _Graph Graph;
    12401240    TEMPLATE_GRAPH_TYPEDEFS(Graph);
    1241    
     1241
    12421242  private:
    12431243
     
    12551255    typedef std::map<std::string, Edge> EdgeIndex;
    12561256    EdgeIndex _edge_index;
    1257    
    1258     typedef std::vector<std::pair<std::string, 
    1259       _reader_bits::MapStorageBase<Node>*> > NodeMaps;   
    1260     NodeMaps _node_maps; 
     1257
     1258    typedef std::vector<std::pair<std::string,
     1259      _reader_bits::MapStorageBase<Node>*> > NodeMaps;
     1260    NodeMaps _node_maps;
    12611261
    12621262    typedef std::vector<std::pair<std::string,
     
    12641264    EdgeMaps _edge_maps;
    12651265
    1266     typedef std::multimap<std::string, _reader_bits::ValueStorageBase*> 
     1266    typedef std::multimap<std::string, _reader_bits::ValueStorageBase*>
    12671267      Attributes;
    12681268    Attributes _attributes;
     
    12831283    /// Construct an undirected graph reader, which reads from the given
    12841284    /// input stream.
    1285     GraphReader(std::istream& is, Graph& graph) 
     1285    GraphReader(std::istream& is, Graph& graph)
    12861286      : _is(&is), local_is(false), _graph(graph),
    1287         _use_nodes(false), _use_edges(false),
    1288         _skip_nodes(false), _skip_edges(false) {}
     1287        _use_nodes(false), _use_edges(false),
     1288        _skip_nodes(false), _skip_edges(false) {}
    12891289
    12901290    /// \brief Constructor
     
    12921292    /// Construct an undirected graph reader, which reads from the given
    12931293    /// file.
    1294     GraphReader(const std::string& fn, Graph& graph) 
     1294    GraphReader(const std::string& fn, Graph& graph)
    12951295      : _is(new std::ifstream(fn.c_str())), local_is(true), _graph(graph),
    1296         _use_nodes(false), _use_edges(false),
    1297         _skip_nodes(false), _skip_edges(false) {}
    1298    
     1296            _use_nodes(false), _use_edges(false),
     1297        _skip_nodes(false), _skip_edges(false) {}
     1298
    12991299    /// \brief Constructor
    13001300    ///
    13011301    /// Construct an undirected graph reader, which reads from the given
    13021302    /// file.
    1303     GraphReader(const char* fn, Graph& graph) 
     1303    GraphReader(const char* fn, Graph& graph)
    13041304      : _is(new std::ifstream(fn)), local_is(true), _graph(graph),
    1305         _use_nodes(false), _use_edges(false),
    1306         _skip_nodes(false), _skip_edges(false) {}
     1305            _use_nodes(false), _use_edges(false),
     1306        _skip_nodes(false), _skip_edges(false) {}
    13071307
    13081308    /// \brief Destructor
    13091309    ~GraphReader() {
    1310       for (typename NodeMaps::iterator it = _node_maps.begin(); 
    1311            it != _node_maps.end(); ++it) {
    1312         delete it->second;
    1313       }
    1314 
    1315       for (typename EdgeMaps::iterator it = _edge_maps.begin(); 
    1316            it != _edge_maps.end(); ++it) {
    1317         delete it->second;
    1318       }
    1319 
    1320       for (typename Attributes::iterator it = _attributes.begin(); 
    1321            it != _attributes.end(); ++it) {
    1322         delete it->second;
     1310      for (typename NodeMaps::iterator it = _node_maps.begin();
     1311           it != _node_maps.end(); ++it) {
     1312        delete it->second;
     1313      }
     1314
     1315      for (typename EdgeMaps::iterator it = _edge_maps.begin();
     1316           it != _edge_maps.end(); ++it) {
     1317        delete it->second;
     1318      }
     1319
     1320      for (typename Attributes::iterator it = _attributes.begin();
     1321           it != _attributes.end(); ++it) {
     1322        delete it->second;
    13231323      }
    13241324
    13251325      if (local_is) {
    1326         delete _is;
     1326        delete _is;
    13271327      }
    13281328
     
    13301330
    13311331  private:
    1332     friend GraphReader<Graph> graphReader<>(std::istream& is, Graph& graph);   
    1333     friend GraphReader<Graph> graphReader<>(const std::string& fn, 
    1334                                             Graph& graph);   
    1335     friend GraphReader<Graph> graphReader<>(const char *fn, Graph& graph);   
    1336 
    1337     GraphReader(GraphReader& other) 
     1332    friend GraphReader<Graph> graphReader<>(std::istream& is, Graph& graph);
     1333    friend GraphReader<Graph> graphReader<>(const std::string& fn,
     1334                                            Graph& graph);
     1335    friend GraphReader<Graph> graphReader<>(const char *fn, Graph& graph);
     1336
     1337    GraphReader(GraphReader& other)
    13381338      : _is(other._is), local_is(other.local_is), _graph(other._graph),
    1339         _use_nodes(other._use_nodes), _use_edges(other._use_edges),
    1340         _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
     1339        _use_nodes(other._use_nodes), _use_edges(other._use_edges),
     1340        _skip_nodes(other._skip_nodes), _skip_edges(other._skip_edges) {
    13411341
    13421342      other._is = 0;
    13431343      other.local_is = false;
    1344      
     1344
    13451345      _node_index.swap(other._node_index);
    13461346      _edge_index.swap(other._edge_index);
     
    13621362    /// \name Reading rules
    13631363    /// @{
    1364    
     1364
    13651365    /// \brief Node map reading rule
    13661366    ///
     
    13691369    GraphReader& nodeMap(const std::string& caption, Map& map) {
    13701370      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
    1371       _reader_bits::MapStorageBase<Node>* storage = 
    1372         new _reader_bits::MapStorage<Node, Map>(map);
     1371      _reader_bits::MapStorageBase<Node>* storage =
     1372        new _reader_bits::MapStorage<Node, Map>(map);
    13731373      _node_maps.push_back(std::make_pair(caption, storage));
    13741374      return *this;
     
    13801380    /// reader.
    13811381    template <typename Map, typename Converter>
    1382     GraphReader& nodeMap(const std::string& caption, Map& map, 
    1383                            const Converter& converter = Converter()) {
     1382    GraphReader& nodeMap(const std::string& caption, Map& map,
     1383                           const Converter& converter = Converter()) {
    13841384      checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
    1385       _reader_bits::MapStorageBase<Node>* storage = 
    1386         new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
     1385      _reader_bits::MapStorageBase<Node>* storage =
     1386        new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
    13871387      _node_maps.push_back(std::make_pair(caption, storage));
    13881388      return *this;
     
    13951395    GraphReader& edgeMap(const std::string& caption, Map& map) {
    13961396      checkConcept<concepts::WriteMap<Edge, typename Map::Value>, Map>();
    1397       _reader_bits::MapStorageBase<Edge>* storage = 
    1398         new _reader_bits::MapStorage<Edge, Map>(map);
     1397      _reader_bits::MapStorageBase<Edge>* storage =
     1398        new _reader_bits::MapStorage<Edge, Map>(map);
    13991399      _edge_maps.push_back(std::make_pair(caption, storage));
    14001400      return *this;
     
    14061406    /// reader.
    14071407    template <typename Map, typename Converter>
    1408     GraphReader& edgeMap(const std::string& caption, Map& map, 
    1409                           const Converter& converter = Converter()) {
     1408    GraphReader& edgeMap(const std::string& caption, Map& map,
     1409                          const Converter& converter = Converter()) {
    14101410      checkConcept<concepts::WriteMap<Edge, typename Map::Value>, Map>();
    1411       _reader_bits::MapStorageBase<Edge>* storage = 
    1412         new _reader_bits::MapStorage<Edge, Map, Converter>(map, converter);
     1411      _reader_bits::MapStorageBase<Edge>* storage =
     1412        new _reader_bits::MapStorage<Edge, Map, Converter>(map, converter);
    14131413      _edge_maps.push_back(std::make_pair(caption, storage));
    14141414      return *this;
     
    14211421    GraphReader& arcMap(const std::string& caption, Map& map) {
    14221422      checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>();
    1423       _reader_bits::MapStorageBase<Edge>* forward_storage = 
    1424         new _reader_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map);
     1423      _reader_bits::MapStorageBase<Edge>* forward_storage =
     1424        new _reader_bits::GraphArcMapStorage<Graph, true, Map>(_graph, map);
    14251425      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
    1426       _reader_bits::MapStorageBase<Edge>* backward_storage = 
    1427         new _reader_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map);
     1426      _reader_bits::MapStorageBase<Edge>* backward_storage =
     1427        new _reader_bits::GraphArcMapStorage<Graph, false, Map>(_graph, map);
    14281428      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
    14291429      return *this;
     
    14351435    /// reader.
    14361436    template <typename Map, typename Converter>
    1437     GraphReader& arcMap(const std::string& caption, Map& map, 
    1438                           const Converter& converter = Converter()) {
     1437    GraphReader& arcMap(const std::string& caption, Map& map,
     1438                          const Converter& converter = Converter()) {
    14391439      checkConcept<concepts::WriteMap<Arc, typename Map::Value>, Map>();
    1440       _reader_bits::MapStorageBase<Edge>* forward_storage = 
    1441         new _reader_bits::GraphArcMapStorage<Graph, true, Map, Converter>
    1442         (_graph, map, converter);
     1440      _reader_bits::MapStorageBase<Edge>* forward_storage =
     1441        new _reader_bits::GraphArcMapStorage<Graph, true, Map, Converter>
     1442        (_graph, map, converter);
    14431443      _edge_maps.push_back(std::make_pair('+' + caption, forward_storage));
    1444       _reader_bits::MapStorageBase<Edge>* backward_storage = 
    1445         new _reader_bits::GraphArcMapStorage<Graph, false, Map, Converter>
    1446         (_graph, map, converter);
     1444      _reader_bits::MapStorageBase<Edge>* backward_storage =
     1445        new _reader_bits::GraphArcMapStorage<Graph, false, Map, Converter>
     1446        (_graph, map, converter);
    14471447      _edge_maps.push_back(std::make_pair('-' + caption, backward_storage));
    14481448      return *this;
     
    14541454    template <typename Value>
    14551455    GraphReader& attribute(const std::string& caption, Value& value) {
    1456       _reader_bits::ValueStorageBase* storage = 
    1457         new _reader_bits::ValueStorage<Value>(value);
     1456      _reader_bits::ValueStorageBase* storage =
     1457        new _reader_bits::ValueStorage<Value>(value);
    14581458      _attributes.insert(std::make_pair(caption, storage));
    14591459      return *this;
     
    14651465    /// reader.
    14661466    template <typename Value, typename Converter>
    1467     GraphReader& attribute(const std::string& caption, Value& value, 
    1468                              const Converter& converter = Converter()) {
    1469       _reader_bits::ValueStorageBase* storage = 
    1470         new _reader_bits::ValueStorage<Value, Converter>(value, converter);
     1467    GraphReader& attribute(const std::string& caption, Value& value,
     1468                             const Converter& converter = Converter()) {
     1469      _reader_bits::ValueStorageBase* storage =
     1470        new _reader_bits::ValueStorage<Value, Converter>(value, converter);
    14711471      _attributes.insert(std::make_pair(caption, storage));
    14721472      return *this;
     
    14791479      typedef _reader_bits::MapLookUpConverter<Node> Converter;
    14801480      Converter converter(_node_index);
    1481       _reader_bits::ValueStorageBase* storage = 
    1482         new _reader_bits::ValueStorage<Node, Converter>(node, converter);
     1481      _reader_bits::ValueStorageBase* storage =
     1482        new _reader_bits::ValueStorage<Node, Converter>(node, converter);
    14831483      _attributes.insert(std::make_pair(caption, storage));
    14841484      return *this;
     
    14911491      typedef _reader_bits::MapLookUpConverter<Edge> Converter;
    14921492      Converter converter(_edge_index);
    1493       _reader_bits::ValueStorageBase* storage = 
    1494         new _reader_bits::ValueStorage<Edge, Converter>(edge, converter);
     1493      _reader_bits::ValueStorageBase* storage =
     1494        new _reader_bits::ValueStorage<Edge, Converter>(edge, converter);
    14951495      _attributes.insert(std::make_pair(caption, storage));
    14961496      return *this;
     
    15031503      typedef _reader_bits::GraphArcLookUpConverter<Graph> Converter;
    15041504      Converter converter(_graph, _edge_index);
    1505       _reader_bits::ValueStorageBase* storage = 
    1506         new _reader_bits::ValueStorage<Arc, Converter>(arc, converter);
     1505      _reader_bits::ValueStorageBase* storage =
     1506        new _reader_bits::ValueStorage<Arc, Converter>(arc, converter);
    15071507      _attributes.insert(std::make_pair(caption, storage));
    15081508      return *this;
     
    15501550    GraphReader& useNodes(const Map& map) {
    15511551      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
    1552       LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); 
     1552      LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member");
    15531553      _use_nodes = true;
    15541554      _writer_bits::DefaultConverter<typename Map::Value> converter;
    15551555      for (NodeIt n(_graph); n != INVALID; ++n) {
    1556         _node_index.insert(std::make_pair(converter(map[n]), n));
     1556        _node_index.insert(std::make_pair(converter(map[n]), n));
    15571557      }
    15581558      return *this;
     
    15651565    /// \c std::string.
    15661566    template <typename Map, typename Converter>
    1567     GraphReader& useNodes(const Map& map, 
    1568                             const Converter& converter = Converter()) {
     1567    GraphReader& useNodes(const Map& map,
     1568                            const Converter& converter = Converter()) {
    15691569      checkConcept<concepts::ReadMap<Node, typename Map::Value>, Map>();
    1570       LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member"); 
     1570      LEMON_ASSERT(!_use_nodes, "Multiple usage of useNodes() member");
    15711571      _use_nodes = true;
    15721572      for (NodeIt n(_graph); n != INVALID; ++n) {
    1573         _node_index.insert(std::make_pair(converter(map[n]), n));
     1573        _node_index.insert(std::make_pair(converter(map[n]), n));
    15741574      }
    15751575      return *this;
     
    15871587      _writer_bits::DefaultConverter<typename Map::Value> converter;
    15881588      for (EdgeIt a(_graph); a != INVALID; ++a) {
    1589         _edge_index.insert(std::make_pair(converter(map[a]), a));
     1589        _edge_index.insert(std::make_pair(converter(map[a]), a));
    15901590      }
    15911591      return *this;
     
    15981598    /// \c std::string.
    15991599    template <typename Map, typename Converter>
    1600     GraphReader& useEdges(const Map& map, 
    1601                             const Converter& converter = Converter()) {
     1600    GraphReader& useEdges(const Map& map,
     1601                            const Converter& converter = Converter()) {
    16021602      checkConcept<concepts::ReadMap<Edge, typename Map::Value>, Map>();
    1603       LEMON_ASSERT(!_use_edges, "Multiple usage of useEdges() member"); 
     1603      LEMON_ASSERT(!_use_edges, "Multiple usage of useEdges() member");
    16041604      _use_edges = true;
    16051605      for (EdgeIt a(_graph); a != INVALID; ++a) {
    1606         _edge_index.insert(std::make_pair(converter(map[a]), a));
     1606        _edge_index.insert(std::make_pair(converter(map[a]), a));
    16071607      }
    16081608      return *this;
     
    16191619    /// \c useNodes() should be used to specify the label of the nodes.
    16201620    GraphReader& skipNodes() {
    1621       LEMON_ASSERT(!_skip_nodes, "Skip nodes already set"); 
     1621      LEMON_ASSERT(!_skip_nodes, "Skip nodes already set");
    16221622      _skip_nodes = true;
    16231623      return *this;
     
    16301630    /// will not be constructed.
    16311631    GraphReader& skipEdges() {
    1632       LEMON_ASSERT(!_skip_edges, "Skip edges already set"); 
     1632      LEMON_ASSERT(!_skip_edges, "Skip edges already set");
    16331633      _skip_edges = true;
    16341634      return *this;
     
    16421642      std::string str;
    16431643      while(++line_num, std::getline(*_is, str)) {
    1644         line.clear(); line.str(str);
    1645         char c;
    1646         if (line >> std::ws >> c && c != '#') {
    1647           line.putback(c);
    1648           return true;
    1649         }
     1644        line.clear(); line.str(str);
     1645        char c;
     1646        if (line >> std::ws >> c && c != '#') {
     1647          line.putback(c);
     1648          return true;
     1649        }
    16501650      }
    16511651      return false;
     
    16551655      return static_cast<bool>(*_is);
    16561656    }
    1657    
     1657
    16581658    void skipSection() {
    16591659      char c;
    16601660      while (readSuccess() && line >> c && c != '@') {
    1661         readLine();
     1661        readLine();
    16621662      }
    16631663      line.putback(c);
     
    16711671      char c;
    16721672      if (!readLine() || !(line >> c) || c == '@') {
    1673         if (readSuccess() && line) line.putback(c);
    1674         if (!_node_maps.empty())
    1675           throw DataFormatError("Cannot find map names");
    1676         return;
     1673        if (readSuccess() && line) line.putback(c);
     1674        if (!_node_maps.empty())
     1675          throw DataFormatError("Cannot find map names");
     1676        return;
    16771677      }
    16781678      line.putback(c);
    1679      
     1679
    16801680      {
    1681         std::map<std::string, int> maps;
    1682        
    1683         std::string map;
    1684         int index = 0;
    1685         while (_reader_bits::readToken(line, map)) {
    1686           if (maps.find(map) != maps.end()) {
    1687             std::ostringstream msg;
    1688             msg << "Multiple occurence of node map: " << map;
    1689             throw DataFormatError(msg.str().c_str());
    1690           }
    1691           maps.insert(std::make_pair(map, index));
    1692           ++index;
    1693         }
    1694        
    1695         for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) {
    1696           std::map<std::string, int>::iterator jt =
    1697             maps.find(_node_maps[i].first);
    1698           if (jt == maps.end()) {
    1699             std::ostringstream msg;
    1700             msg << "Map not found in file: " << _node_maps[i].first;
    1701             throw DataFormatError(msg.str().c_str());
    1702           }
    1703           map_index[i] = jt->second;
    1704         }
    1705 
    1706         {
    1707           std::map<std::string, int>::iterator jt = maps.find("label");
    1708           if (jt != maps.end()) {
    1709             label_index = jt->second;
    1710           } else {
    1711             label_index = -1;
    1712           }
    1713         }
    1714         map_num = maps.size();
     1681        std::map<std::string, int> maps;
     1682
     1683        std::string map;
     1684        int index = 0;
     1685        while (_reader_bits::readToken(line, map)) {
     1686          if (maps.find(map) != maps.end()) {
     1687            std::ostringstream msg;
     1688            msg << "Multiple occurence of node map: " << map;
     1689            throw DataFormatError(msg.str().c_str());
     1690          }
     1691          maps.insert(std::make_pair(map, index));
     1692          ++index;
     1693        }
     1694
     1695        for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) {
     1696          std::map<std::string, int>::iterator jt =
     1697            maps.find(_node_maps[i].first);
     1698          if (jt == maps.end()) {
     1699            std::ostringstream msg;
     1700            msg << "Map not found in file: " << _node_maps[i].first;
     1701            throw DataFormatError(msg.str().c_str());
     1702          }
     1703          map_index[i] = jt->second;
     1704        }
     1705
     1706        {
     1707          std::map<std::string, int>::iterator jt = maps.find("label");
     1708          if (jt != maps.end()) {
     1709            label_index = jt->second;
     1710          } else {
     1711            label_index = -1;
     1712          }
     1713        }
     1714        map_num = maps.size();
    17151715      }
    17161716
    17171717      while (readLine() && line >> c && c != '@') {
    1718         line.putback(c);
    1719 
    1720         std::vector<std::string> tokens(map_num);
    1721         for (int i = 0; i < map_num; ++i) {
    1722           if (!_reader_bits::readToken(line, tokens[i])) {
    1723             std::ostringstream msg;
    1724             msg << "Column not found (" << i + 1 << ")";
    1725             throw DataFormatError(msg.str().c_str());
    1726           }
    1727         }
    1728         if (line >> std::ws >> c)
    1729           throw DataFormatError("Extra character on the end of line");
    1730        
    1731         Node n;
    1732         if (!_use_nodes) {
    1733           n = _graph.addNode();
    1734           if (label_index != -1)
    1735             _node_index.insert(std::make_pair(tokens[label_index], n));
    1736         } else {
    1737           if (label_index == -1)
    1738             throw DataFormatError("Label map not found in file");
    1739           typename std::map<std::string, Node>::iterator it =
    1740             _node_index.find(tokens[label_index]);
    1741           if (it == _node_index.end()) {
    1742             std::ostringstream msg;
    1743             msg << "Node with label not found: " << tokens[label_index];
    1744             throw DataFormatError(msg.str().c_str());       
    1745           }
    1746           n = it->second;
    1747         }
    1748 
    1749         for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) {
    1750           _node_maps[i].second->set(n, tokens[map_index[i]]);
    1751         }
     1718        line.putback(c);
     1719
     1720        std::vector<std::string> tokens(map_num);
     1721        for (int i = 0; i < map_num; ++i) {
     1722          if (!_reader_bits::readToken(line, tokens[i])) {
     1723            std::ostringstream msg;
     1724            msg << "Column not found (" << i + 1 << ")";
     1725            throw DataFormatError(msg.str().c_str());
     1726          }
     1727        }
     1728        if (line >> std::ws >> c)
     1729          throw DataFormatError("Extra character on the end of line");
     1730
     1731        Node n;
     1732        if (!_use_nodes) {
     1733          n = _graph.addNode();
     1734          if (label_index != -1)
     1735            _node_index.insert(std::make_pair(tokens[label_index], n));
     1736        } else {
     1737          if (label_index == -1)
     1738            throw DataFormatError("Label map not found in file");
     1739          typename std::map<std::string, Node>::iterator it =
     1740            _node_index.find(tokens[label_index]);
     1741          if (it == _node_index.end()) {
     1742            std::ostringstream msg;
     1743            msg << "Node with label not found: " << tokens[label_index];
     1744            throw DataFormatError(msg.str().c_str());
     1745          }
     1746          n = it->second;
     1747        }
     1748
     1749        for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) {
     1750          _node_maps[i].second->set(n, tokens[map_index[i]]);
     1751        }
    17521752
    17531753      }
    17541754      if (readSuccess()) {
    1755         line.putback(c);
     1755        line.putback(c);
    17561756      }
    17571757    }
     
    17641764      char c;
    17651765      if (!readLine() || !(line >> c) || c == '@') {
    1766         if (readSuccess() && line) line.putback(c);
    1767         if (!_edge_maps.empty())
    1768           throw DataFormatError("Cannot find map names");
    1769         return;
     1766        if (readSuccess() && line) line.putback(c);
     1767        if (!_edge_maps.empty())
     1768          throw DataFormatError("Cannot find map names");
     1769        return;
    17701770      }
    17711771      line.putback(c);
    1772      
     1772
    17731773      {
    1774         std::map<std::string, int> maps;
    1775        
    1776         std::string map;
    1777         int index = 0;
    1778         while (_reader_bits::readToken(line, map)) {
    1779           if (maps.find(map) != maps.end()) {
    1780             std::ostringstream msg;
    1781             msg << "Multiple occurence of edge map: " << map;
    1782             throw DataFormatError(msg.str().c_str());
    1783           }
    1784           maps.insert(std::make_pair(map, index));
    1785           ++index;
    1786         }
    1787        
    1788         for (int i = 0; i < static_cast<int>(_edge_maps.size()); ++i) {
    1789           std::map<std::string, int>::iterator jt =
    1790             maps.find(_edge_maps[i].first);
    1791           if (jt == maps.end()) {
    1792             std::ostringstream msg;
    1793             msg << "Map not found in file: " << _edge_maps[i].first;
    1794             throw DataFormatError(msg.str().c_str());
    1795           }
    1796           map_index[i] = jt->second;
    1797         }
    1798 
    1799         {
    1800           std::map<std::string, int>::iterator jt = maps.find("label");
    1801           if (jt != maps.end()) {
    1802             label_index = jt->second;
    1803           } else {
    1804             label_index = -1;
    1805           }
    1806         }
    1807         map_num = maps.size();
     1774        std::map<std::string, int> maps;
     1775
     1776        std::string map;
     1777        int index = 0;
     1778        while (_reader_bits::readToken(line, map)) {
     1779          if (maps.find(map) != maps.end()) {
     1780            std::ostringstream msg;
     1781            msg << "Multiple occurence of edge map: " << map;
     1782            throw DataFormatError(msg.str().c_str());
     1783          }
     1784          maps.insert(std::make_pair(map, index));
     1785          ++index;
     1786        }
     1787
     1788        for (int i = 0; i < static_cast<int>(_edge_maps.size()); ++i) {
     1789          std::map<std::string, int>::iterator jt =
     1790            maps.find(_edge_maps[i].first);
     1791          if (jt == maps.end()) {
     1792            std::ostringstream msg;
     1793            msg << "Map not found in file: " << _edge_maps[i].first;
     1794            throw DataFormatError(msg.str().c_str());
     1795          }
     1796          map_index[i] = jt->second;
     1797        }
     1798
     1799        {
     1800          std::map<std::string, int>::iterator jt = maps.find("label");
     1801          if (jt != maps.end()) {
     1802            label_index = jt->second;
     1803          } else {
     1804            label_index = -1;
     1805          }
     1806        }
     1807        map_num = maps.size();
    18081808      }
    18091809
    18101810      while (readLine() && line >> c && c != '@') {
    1811         line.putback(c);
    1812 
    1813         std::string source_token;
    1814         std::string target_token;
    1815 
    1816         if (!_reader_bits::readToken(line, source_token))
    1817           throw DataFormatError("Node u not found");
    1818 
    1819         if (!_reader_bits::readToken(line, target_token))
    1820           throw DataFormatError("Node v not found");
    1821        
    1822         std::vector<std::string> tokens(map_num);
    1823         for (int i = 0; i < map_num; ++i) {
    1824           if (!_reader_bits::readToken(line, tokens[i])) {
    1825             std::ostringstream msg;
    1826             msg << "Column not found (" << i + 1 << ")";
    1827             throw DataFormatError(msg.str().c_str());
    1828           }
    1829         }
    1830         if (line >> std::ws >> c)
    1831           throw DataFormatError("Extra character on the end of line");
    1832        
    1833         Edge e;
    1834         if (!_use_edges) {
     1811        line.putback(c);
     1812
     1813        std::string source_token;
     1814        std::string target_token;
     1815
     1816        if (!_reader_bits::readToken(line, source_token))
     1817          throw DataFormatError("Node u not found");
     1818
     1819        if (!_reader_bits::readToken(line, target_token))
     1820          throw DataFormatError("Node v not found");
     1821
     1822        std::vector<std::string> tokens(map_num);
     1823        for (int i = 0; i < map_num; ++i) {
     1824          if (!_reader_bits::readToken(line, tokens[i])) {
     1825            std::ostringstream msg;
     1826            msg << "Column not found (" << i + 1 << ")";
     1827            throw DataFormatError(msg.str().c_str());
     1828          }
     1829        }
     1830        if (line >> std::ws >> c)
     1831          throw DataFormatError("Extra character on the end of line");
     1832
     1833        Edge e;
     1834        if (!_use_edges) {
    18351835
    18361836          typename NodeIndex::iterator it;
    1837  
     1837
    18381838          it = _node_index.find(source_token);
    18391839          if (it == _node_index.end()) {
     
    18451845
    18461846          it = _node_index.find(target_token);
    1847           if (it == _node_index.end()) {       
    1848             std::ostringstream msg;           
     1847          if (it == _node_index.end()) {
     1848            std::ostringstream msg;
    18491849            msg << "Item not found: " << target_token;
    18501850            throw DataFormatError(msg.str().c_str());
    1851           }                                         
    1852           Node target = it->second;                           
    1853 
    1854           e = _graph.addEdge(source, target);
    1855           if (label_index != -1)
    1856             _edge_index.insert(std::make_pair(tokens[label_index], e));
    1857         } else {
    1858           if (label_index == -1)
    1859             throw DataFormatError("Label map not found in file");
    1860           typename std::map<std::string, Edge>::iterator it =
    1861             _edge_index.find(tokens[label_index]);
    1862           if (it == _edge_index.end()) {
    1863             std::ostringstream msg;
    1864             msg << "Edge with label not found: " << tokens[label_index];
    1865             throw DataFormatError(msg.str().c_str());       
    1866           }
    1867           e = it->second;
    1868         }
    1869 
    1870         for (int i = 0; i < static_cast<int>(_edge_maps.size()); ++i) {
    1871           _edge_maps[i].second->set(e, tokens[map_index[i]]);
    1872         }
     1851          }
     1852          Node target = it->second;
     1853
     1854          e = _graph.addEdge(source, target);
     1855          if (label_index != -1)
     1856            _edge_index.insert(std::make_pair(tokens[label_index], e));
     1857        } else {
     1858          if (label_index == -1)
     1859            throw DataFormatError("Label map not found in file");
     1860          typename std::map<std::string, Edge>::iterator it =
     1861            _edge_index.find(tokens[label_index]);
     1862          if (it == _edge_index.end()) {
     1863            std::ostringstream msg;
     1864            msg << "Edge with label not found: " << tokens[label_index];
     1865            throw DataFormatError(msg.str().c_str());
     1866          }
     1867          e = it->second;
     1868        }
     1869
     1870        for (int i = 0; i < static_cast<int>(_edge_maps.size()); ++i) {
     1871          _edge_maps[i].second->set(e, tokens[map_index[i]]);
     1872        }
    18731873
    18741874      }
    18751875      if (readSuccess()) {
    1876         line.putback(c);
     1876        line.putback(c);
    18771877      }
    18781878    }
     
    18841884      char c;
    18851885      while (readLine() && line >> c && c != '@') {
    1886         line.putback(c);
    1887        
    1888         std::string attr, token;
    1889         if (!_reader_bits::readToken(line, attr))
    1890           throw DataFormatError("Attribute name not found");
    1891         if (!_reader_bits::readToken(line, token))
    1892           throw DataFormatError("Attribute value not found");
    1893         if (line >> c)
    1894           throw DataFormatError("Extra character on the end of line");   
    1895 
    1896         {
    1897           std::set<std::string>::iterator it = read_attr.find(attr);
    1898           if (it != read_attr.end()) {
    1899             std::ostringstream msg;
    1900             msg << "Multiple occurence of attribute " << attr;
    1901             throw DataFormatError(msg.str().c_str());
    1902           }
    1903           read_attr.insert(attr);
    1904         }
    1905        
    1906         {
    1907           typename Attributes::iterator it = _attributes.lower_bound(attr);
    1908           while (it != _attributes.end() && it->first == attr) {
    1909             it->second->set(token);
    1910             ++it;
    1911           }
    1912         }
     1886        line.putback(c);
     1887
     1888        std::string attr, token;
     1889        if (!_reader_bits::readToken(line, attr))
     1890          throw DataFormatError("Attribute name not found");
     1891        if (!_reader_bits::readToken(line, token))
     1892          throw DataFormatError("Attribute value not found");
     1893        if (line >> c)
     1894          throw DataFormatError("Extra character on the end of line");
     1895
     1896        {
     1897          std::set<std::string>::iterator it = read_attr.find(attr);
     1898          if (it != read_attr.end()) {
     1899            std::ostringstream msg;
     1900            msg << "Multiple occurence of attribute " << attr;
     1901            throw DataFormatError(msg.str().c_str());
     1902          }
     1903          read_attr.insert(attr);
     1904        }
     1905
     1906        {
     1907          typename Attributes::iterator it = _attributes.lower_bound(attr);
     1908          while (it != _attributes.end() && it->first == attr) {
     1909            it->second->set(token);
     1910            ++it;
     1911          }
     1912        }
    19131913
    19141914      }
    19151915      if (readSuccess()) {
    1916         line.putback(c);
     1916        line.putback(c);
    19171917      }
    19181918      for (typename Attributes::iterator it = _attributes.begin();
    1919            it != _attributes.end(); ++it) {
    1920         if (read_attr.find(it->first) == read_attr.end()) {
    1921           std::ostringstream msg;
    1922           msg << "Attribute not found in file: " << it->first;
    1923           throw DataFormatError(msg.str().c_str());
    1924         }       
     1919           it != _attributes.end(); ++it) {
     1920        if (read_attr.find(it->first) == read_attr.end()) {
     1921          std::ostringstream msg;
     1922          msg << "Attribute not found in file: " << it->first;
     1923          throw DataFormatError(msg.str().c_str());
     1924        }
    19251925      }
    19261926    }
     
    19281928  public:
    19291929
    1930     /// \name Execution of the reader   
     1930    /// \name Execution of the reader
    19311931    /// @{
    19321932
     
    19351935    /// This function starts the batch processing
    19361936    void run() {
    1937      
     1937
    19381938      LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
    1939      
     1939
    19401940      bool nodes_done = _skip_nodes;
    19411941      bool edges_done = _skip_edges;
    19421942      bool attributes_done = false;
    19431943
    1944       line_num = 0;     
     1944      line_num = 0;
    19451945      readLine();
    19461946      skipSection();
    19471947
    19481948      while (readSuccess()) {
    1949         try {
    1950           char c;
    1951           std::string section, caption;
    1952           line >> c;
    1953           _reader_bits::readToken(line, section);
    1954           _reader_bits::readToken(line, caption);
    1955 
    1956           if (line >> c)
    1957             throw DataFormatError("Extra character on the end of line");
    1958 
    1959           if (section == "nodes" && !nodes_done) {
    1960             if (_nodes_caption.empty() || _nodes_caption == caption) {
    1961               readNodes();
    1962               nodes_done = true;
    1963             }
    1964           } else if ((section == "edges" || section == "arcs") &&
    1965                      !edges_done) {
    1966             if (_edges_caption.empty() || _edges_caption == caption) {
    1967               readEdges();
    1968               edges_done = true;
    1969             }
    1970           } else if (section == "attributes" && !attributes_done) {
    1971             if (_attributes_caption.empty() || _attributes_caption == caption) {
    1972               readAttributes();
    1973               attributes_done = true;
    1974             }
    1975           } else {
    1976             readLine();
    1977             skipSection();
    1978           }
    1979         } catch (DataFormatError& error) {
    1980           error.line(line_num);
    1981           throw;
    1982         }       
     1949        try {
     1950          char c;
     1951          std::string section, caption;
     1952          line >> c;
     1953          _reader_bits::readToken(line, section);
     1954          _reader_bits::readToken(line, caption);
     1955
     1956          if (line >> c)
     1957            throw DataFormatError("Extra character on the end of line");
     1958
     1959          if (section == "nodes" && !nodes_done) {
     1960            if (_nodes_caption.empty() || _nodes_caption == caption) {
     1961              readNodes();
     1962              nodes_done = true;
     1963            }
     1964          } else if ((section == "edges" || section == "arcs") &&
     1965                     !edges_done) {
     1966            if (_edges_caption.empty() || _edges_caption == caption) {
     1967              readEdges();
     1968              edges_done = true;
     1969            }
     1970          } else if (section == "attributes" && !attributes_done) {
     1971            if (_attributes_caption.empty() || _attributes_caption == caption) {
     1972              readAttributes();
     1973              attributes_done = true;
     1974            }
     1975          } else {
     1976            readLine();
     1977            skipSection();
     1978          }
     1979        } catch (DataFormatError& error) {
     1980          error.line(line_num);
     1981          throw;
     1982        }
    19831983      }
    19841984
    19851985      if (!nodes_done) {
    1986         throw DataFormatError("Section @nodes not found");
     1986        throw DataFormatError("Section @nodes not found");
    19871987      }
    19881988
    19891989      if (!edges_done) {
    1990         throw DataFormatError("Section @edges not found");
     1990        throw DataFormatError("Section @edges not found");
    19911991      }
    19921992
    19931993      if (!attributes_done && !_attributes.empty()) {
    1994         throw DataFormatError("Section @attributes not found");
     1994        throw DataFormatError("Section @attributes not found");
    19951995      }
    19961996
     
    19981998
    19991999    /// @}
    2000    
     2000
    20012001  };
    20022002
    20032003  /// \brief Return a \ref GraphReader class
    2004   /// 
     2004  ///
    20052005  /// This function just returns a \ref GraphReader class.
    20062006  /// \relates GraphReader
     
    20122012
    20132013  /// \brief Return a \ref GraphReader class
    2014   /// 
     2014  ///
    20152015  /// This function just returns a \ref GraphReader class.
    20162016  /// \relates GraphReader
    20172017  template <typename Graph>
    2018   GraphReader<Graph> graphReader(const std::string& fn, 
    2019                                        Graph& graph) {
     2018  GraphReader<Graph> graphReader(const std::string& fn,
     2019                                       Graph& graph) {
    20202020    GraphReader<Graph> tmp(fn, graph);
    20212021    return tmp;
     
    20232023
    20242024  /// \brief Return a \ref GraphReader class
    2025   /// 
     2025  ///
    20262026  /// This function just returns a \ref GraphReader class.
    20272027  /// \relates GraphReader
     
    20372037  SectionReader sectionReader(const std::string& fn);
    20382038  SectionReader sectionReader(const char* fn);
    2039  
     2039
    20402040  /// \ingroup lemon_io
    20412041  ///
    20422042  /// \brief Section reader class
    20432043  ///
    2044   /// In the \ref lgf-format "LGF" file extra sections can be placed, 
     2044  /// In the \ref lgf-format "LGF" file extra sections can be placed,
    20452045  /// which contain any data in arbitrary format. Such sections can be
    2046   /// read with this class. A reading rule can be added to the class 
     2046  /// read with this class. A reading rule can be added to the class
    20472047  /// with two different functions. With the \c sectionLines() function a
    20482048  /// functor can process the section line-by-line, while with the \c
     
    20512051  class SectionReader {
    20522052  private:
    2053    
     2053
    20542054    std::istream* _is;
    20552055    bool local_is;
     
    20672067    /// Construct a section reader, which reads from the given input
    20682068    /// stream.
    2069     SectionReader(std::istream& is) 
     2069    SectionReader(std::istream& is)
    20702070      : _is(&is), local_is(false) {}
    20712071
     
    20732073    ///
    20742074    /// Construct a section reader, which reads from the given file.
    2075     SectionReader(const std::string& fn) 
     2075    SectionReader(const std::string& fn)
    20762076      : _is(new std::ifstream(fn.c_str())), local_is(true) {}
    2077    
     2077
    20782078    /// \brief Constructor
    20792079    ///
    20802080    /// Construct a section reader, which reads from the given file.
    2081     SectionReader(const char* fn) 
     2081    SectionReader(const char* fn)
    20822082      : _is(new std::ifstream(fn)), local_is(true) {}
    20832083
    20842084    /// \brief Destructor
    20852085    ~SectionReader() {
    2086       for (Sections::iterator it = _sections.begin(); 
    2087            it != _sections.end(); ++it) {
    2088         delete it->second;
     2086      for (Sections::iterator it = _sections.begin();
     2087           it != _sections.end(); ++it) {
     2088        delete it->second;
    20892089      }
    20902090
    20912091      if (local_is) {
    2092         delete _is;
     2092        delete _is;
    20932093      }
    20942094
     
    21012101    friend SectionReader sectionReader(const char* fn);
    21022102
    2103     SectionReader(SectionReader& other) 
     2103    SectionReader(SectionReader& other)
    21042104      : _is(other._is), local_is(other.local_is) {
    21052105
    21062106      other._is = 0;
    21072107      other.local_is = false;
    2108      
     2108
    21092109      _sections.swap(other._sections);
    21102110    }
    2111    
     2111
    21122112    SectionReader& operator=(const SectionReader&);
    21132113
     
    21492149    ///  // ...
    21502150    ///
    2151     ///  reader.sectionLines("numbers", NumberSection(vec)); 
     2151    ///  reader.sectionLines("numbers", NumberSection(vec));
    21522152    ///\endcode
    21532153    template <typename Functor>
    21542154    SectionReader& sectionLines(const std::string& type, Functor functor) {
    21552155      LEMON_ASSERT(!type.empty(), "Type is empty.");
    2156       LEMON_ASSERT(_sections.find(type) == _sections.end(), 
    2157                    "Multiple reading of section.");
    2158       _sections.insert(std::make_pair(type, 
     2156      LEMON_ASSERT(_sections.find(type) == _sections.end(),
     2157                   "Multiple reading of section.");
     2158      _sections.insert(std::make_pair(type,
    21592159        new _reader_bits::LineSection<Functor>(functor)));
    21602160      return *this;
     
    21722172    SectionReader& sectionStream(const std::string& type, Functor functor) {
    21732173      LEMON_ASSERT(!type.empty(), "Type is empty.");
    2174       LEMON_ASSERT(_sections.find(type) == _sections.end(), 
    2175                    "Multiple reading of section.");
    2176       _sections.insert(std::make_pair(type, 
    2177         new _reader_bits::StreamSection<Functor>(functor)));
    2178       return *this;
    2179     }   
    2180    
     2174      LEMON_ASSERT(_sections.find(type) == _sections.end(),
     2175                   "Multiple reading of section.");
     2176      _sections.insert(std::make_pair(type,
     2177        new _reader_bits::StreamSection<Functor>(functor)));
     2178      return *this;
     2179    }
     2180
    21812181    /// @}
    21822182
     
    21862186      std::string str;
    21872187      while(++line_num, std::getline(*_is, str)) {
    2188         line.clear(); line.str(str);
    2189         char c;
    2190         if (line >> std::ws >> c && c != '#') {
    2191           line.putback(c);
    2192           return true;
    2193         }
     2188        line.clear(); line.str(str);
     2189        char c;
     2190        if (line >> std::ws >> c && c != '#') {
     2191          line.putback(c);
     2192          return true;
     2193        }
    21942194      }
    21952195      return false;
     
    21992199      return static_cast<bool>(*_is);
    22002200    }
    2201    
     2201
    22022202    void skipSection() {
    22032203      char c;
    22042204      while (readSuccess() && line >> c && c != '@') {
    2205         readLine();
     2205        readLine();
    22062206      }
    22072207      line.putback(c);
     
    22112211
    22122212
    2213     /// \name Execution of the reader   
     2213    /// \name Execution of the reader
    22142214    /// @{
    22152215
     
    22182218    /// This function starts the batch processing.
    22192219    void run() {
    2220      
     2220
    22212221      LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
    2222      
     2222
    22232223      std::set<std::string> extra_sections;
    22242224
    2225       line_num = 0;     
     2225      line_num = 0;
    22262226      readLine();
    22272227      skipSection();
    22282228
    22292229      while (readSuccess()) {
    2230         try {
    2231           char c;
    2232           std::string section, caption;
    2233           line >> c;
    2234           _reader_bits::readToken(line, section);
    2235           _reader_bits::readToken(line, caption);
    2236 
    2237           if (line >> c)
    2238             throw DataFormatError("Extra character on the end of line");
    2239 
    2240           if (extra_sections.find(section) != extra_sections.end()) {
    2241             std::ostringstream msg;
    2242             msg << "Multiple occurence of section " << section;
    2243             throw DataFormatError(msg.str().c_str());
    2244           }
    2245           Sections::iterator it = _sections.find(section);
    2246           if (it != _sections.end()) {
    2247             extra_sections.insert(section);
    2248             it->second->process(*_is, line_num);
    2249           }
    2250           readLine();
    2251           skipSection();
    2252         } catch (DataFormatError& error) {
    2253           error.line(line_num);
    2254           throw;
    2255         }       
     2230        try {
     2231          char c;
     2232          std::string section, caption;
     2233          line >> c;
     2234          _reader_bits::readToken(line, section);
     2235          _reader_bits::readToken(line, caption);
     2236
     2237          if (line >> c)
     2238            throw DataFormatError("Extra character on the end of line");
     2239
     2240          if (extra_sections.find(section) != extra_sections.end()) {
     2241            std::ostringstream msg;
     2242            msg << "Multiple occurence of section " << section;
     2243            throw DataFormatError(msg.str().c_str());
     2244          }
     2245          Sections::iterator it = _sections.find(section);
     2246          if (it != _sections.end()) {
     2247            extra_sections.insert(section);
     2248            it->second->process(*_is, line_num);
     2249          }
     2250          readLine();
     2251          skipSection();
     2252        } catch (DataFormatError& error) {
     2253          error.line(line_num);
     2254          throw;
     2255        }
    22562256      }
    22572257      for (Sections::iterator it = _sections.begin();
    2258            it != _sections.end(); ++it) {
    2259         if (extra_sections.find(it->first) == extra_sections.end()) {
    2260           std::ostringstream os;
    2261           os << "Cannot find section: " << it->first;
    2262           throw DataFormatError(os.str().c_str());
    2263         }
     2258           it != _sections.end(); ++it) {
     2259        if (extra_sections.find(it->first) == extra_sections.end()) {
     2260          std::ostringstream os;
     2261          os << "Cannot find section: " << it->first;
     2262          throw DataFormatError(os.str().c_str());
     2263        }
    22642264      }
    22652265    }
    22662266
    22672267    /// @}
    2268        
     2268
    22692269  };
    22702270
    22712271  /// \brief Return a \ref SectionReader class
    2272   /// 
     2272  ///
    22732273  /// This function just returns a \ref SectionReader class.
    22742274  /// \relates SectionReader
     
    22792279
    22802280  /// \brief Return a \ref SectionReader class
    2281   /// 
     2281  ///
    22822282  /// This function just returns a \ref SectionReader class.
    22832283  /// \relates SectionReader
     
    22882288
    22892289  /// \brief Return a \ref SectionReader class
    2290   /// 
     2290  ///
    22912291  /// This function just returns a \ref SectionReader class.
    22922292  /// \relates SectionReader
     
    22982298  /// \ingroup lemon_io
    22992299  ///
    2300   /// \brief Reader for the contents of the \ref lgf-format "LGF" file 
     2300  /// \brief Reader for the contents of the \ref lgf-format "LGF" file
    23012301  ///
    23022302  /// This class can be used to read the sections, the map names and
     
    23082308  /// reading the graph.
    23092309  ///
    2310   ///\code 
    2311   /// LgfContents contents("graph.lgf"); 
     2310  ///\code
     2311  /// LgfContents contents("graph.lgf");
    23122312  /// contents.run();
    23132313  ///
     
    23172317  ///   return -1;
    23182318  /// }
    2319   /// std::cout << "The name of the default node section: " 
     2319  /// std::cout << "The name of the default node section: "
    23202320  ///           << contents.nodeSection(0) << std::endl;
    2321   /// std::cout << "The number of the arc maps: " 
     2321  /// std::cout << "The number of the arc maps: "
    23222322  ///           << contents.arcMaps(0).size() << std::endl;
    2323   /// std::cout << "The name of second arc map: " 
     2323  /// std::cout << "The name of second arc map: "
    23242324  ///           << contents.arcMaps(0)[1] << std::endl;
    23252325  ///\endcode
    2326   class LgfContents {   
     2326  class LgfContents {
    23272327  private:
    23282328
     
    23452345    int line_num;
    23462346    std::istringstream line;
    2347    
     2347
    23482348  public:
    23492349
     
    23522352    /// Construct an \e LGF contents reader, which reads from the given
    23532353    /// input stream.
    2354     LgfContents(std::istream& is) 
     2354    LgfContents(std::istream& is)
    23552355      : _is(&is), local_is(false) {}
    23562356
     
    23592359    /// Construct an \e LGF contents reader, which reads from the given
    23602360    /// file.
    2361     LgfContents(const std::string& fn) 
     2361    LgfContents(const std::string& fn)
    23622362      : _is(new std::ifstream(fn.c_str())), local_is(true) {}
    23632363
     
    23682368    LgfContents(const char* fn)
    23692369      : _is(new std::ifstream(fn)), local_is(true) {}
    2370    
     2370
    23712371    /// \brief Destructor
    23722372    ~LgfContents() {
     
    23752375
    23762376  private:
    2377    
     2377
    23782378    LgfContents(const LgfContents&);
    23792379    LgfContents& operator=(const LgfContents&);
     
    23922392    }
    23932393
    2394     /// \brief Returns the node section name at the given position. 
    2395     ///
    2396     /// Returns the node section name at the given position. 
     2394    /// \brief Returns the node section name at the given position.
     2395    ///
     2396    /// Returns the node section name at the given position.
    23972397    const std::string& nodeSection(int i) const {
    23982398      return _node_sections[i];
     
    24082408    /// @}
    24092409
    2410     /// \name Arc/Edge sections 
     2410    /// \name Arc/Edge sections
    24112411    /// @{
    24122412
     
    24192419    }
    24202420
    2421     /// \brief Returns the arc/edge section name at the given position. 
    2422     ///
    2423     /// Returns the arc/edge section name at the given position. 
     2421    /// \brief Returns the arc/edge section name at the given position.
     2422    ///
     2423    /// Returns the arc/edge section name at the given position.
    24242424    /// \note It is synonym of \c edgeSection().
    24252425    const std::string& arcSection(int i) const {
     
    24482448    }
    24492449
    2450     /// \brief Returns the section name at the given position. 
    2451     ///
    2452     /// Returns the section name at the given position. 
     2450    /// \brief Returns the section name at the given position.
     2451    ///
     2452    /// Returns the section name at the given position.
    24532453    /// \note It is synonym of \c arcSection().
    24542454    const std::string& edgeSection(int i) const {
     
    24662466    /// @}
    24672467
    2468     /// \name Attribute sections   
     2468    /// \name Attribute sections
    24692469    /// @{
    24702470
     
    24762476    }
    24772477
    2478     /// \brief Returns the attribute section name at the given position. 
    2479     ///
    2480     /// Returns the attribute section name at the given position. 
     2478    /// \brief Returns the attribute section name at the given position.
     2479    ///
     2480    /// Returns the attribute section name at the given position.
    24812481    const std::string& attributeSectionNames(int i) const {
    24822482      return _attribute_sections[i];
     
    24922492    /// @}
    24932493
    2494     /// \name Extra sections   
     2494    /// \name Extra sections
    24952495    /// @{
    24962496
     
    25022502    }
    25032503
    2504     /// \brief Returns the extra section type at the given position. 
    2505     ///
    2506     /// Returns the section type at the given position. 
     2504    /// \brief Returns the extra section type at the given position.
     2505    ///
     2506    /// Returns the section type at the given position.
    25072507    const std::string& extraSection(int i) const {
    25082508      return _extra_sections[i];
     
    25162516      std::string str;
    25172517      while(++line_num, std::getline(*_is, str)) {
    2518         line.clear(); line.str(str);
    2519         char c;
    2520         if (line >> std::ws >> c && c != '#') {
    2521           line.putback(c);
    2522           return true;
    2523         }
     2518        line.clear(); line.str(str);
     2519        char c;
     2520        if (line >> std::ws >> c && c != '#') {
     2521          line.putback(c);
     2522          return true;
     2523        }
    25242524      }
    25252525      return false;
     
    25332533      char c;
    25342534      while (readSuccess() && line >> c && c != '@') {
    2535         readLine();
     2535        readLine();
    25362536      }
    25372537      line.putback(c);
     
    25412541      char c;
    25422542      if (!readLine() || !(line >> c) || c == '@') {
    2543         if (readSuccess() && line) line.putback(c);
    2544         return;
     2543        if (readSuccess() && line) line.putback(c);
     2544        return;
    25452545      }
    25462546      line.putback(c);
    25472547      std::string map;
    25482548      while (_reader_bits::readToken(line, map)) {
    2549         maps.push_back(map);
     2549        maps.push_back(map);
    25502550      }
    25512551    }
     
    25552555      char c;
    25562556      while (readSuccess() && line >> c && c != '@') {
    2557         line.putback(c);
    2558         std::string attr;
    2559         _reader_bits::readToken(line, attr);
    2560         attrs.push_back(attr);
    2561         readLine();
     2557        line.putback(c);
     2558        std::string attr;
     2559        _reader_bits::readToken(line, attr);
     2560        attrs.push_back(attr);
     2561        readLine();
    25622562      }
    25632563      line.putback(c);
     
    25662566  public:
    25672567
    2568     /// \name Execution of the contents reader   
     2568    /// \name Execution of the contents reader
    25692569    /// @{
    25702570
     
    25792579      while (readSuccess()) {
    25802580
    2581         char c;
    2582         line >> c;
    2583 
    2584         std::string section, caption;
    2585         _reader_bits::readToken(line, section);
    2586         _reader_bits::readToken(line, caption);
    2587 
    2588         if (section == "nodes") {
    2589           _node_sections.push_back(caption);
    2590           _node_maps.push_back(std::vector<std::string>());
    2591           readMaps(_node_maps.back());
    2592           readLine(); skipSection();
    2593         } else if (section == "arcs" || section == "edges") {
    2594           _edge_sections.push_back(caption);
    2595           _arc_sections.push_back(section == "arcs");
    2596           _edge_maps.push_back(std::vector<std::string>());
    2597           readMaps(_edge_maps.back());
    2598           readLine(); skipSection();
    2599         } else if (section == "attributes") {
    2600           _attribute_sections.push_back(caption);
    2601           _attributes.push_back(std::vector<std::string>());
    2602           readAttributes(_attributes.back());
    2603         } else {
    2604           _extra_sections.push_back(section);
    2605           readLine(); skipSection();
    2606         }
     2581        char c;
     2582        line >> c;
     2583
     2584        std::string section, caption;
     2585        _reader_bits::readToken(line, section);
     2586        _reader_bits::readToken(line, caption);
     2587
     2588        if (section == "nodes") {
     2589          _node_sections.push_back(caption);
     2590          _node_maps.push_back(std::vector<std::string>());
     2591          readMaps(_node_maps.back());
     2592          readLine(); skipSection();
     2593        } else if (section == "arcs" || section == "edges") {
     2594          _edge_sections.push_back(caption);
     2595          _arc_sections.push_back(section == "arcs");
     2596          _edge_maps.push_back(std::vector<std::string>());
     2597          readMaps(_edge_maps.back());
     2598          readLine(); skipSection();
     2599        } else if (section == "attributes") {
     2600          _attribute_sections.push_back(caption);
     2601          _attributes.push_back(std::vector<std::string>());
     2602          readAttributes(_attributes.back());
     2603        } else {
     2604          _extra_sections.push_back(section);
     2605          readLine(); skipSection();
     2606        }
    26072607      }
    26082608    }
    26092609
    26102610    /// @}
    2611    
     2611
    26122612  };
    26132613}
Note: See TracChangeset for help on using the changeset viewer.