COIN-OR::LEMON - Graph Library

Changeset 294:cbe3ec2d59d2 in lemon-1.2 for lemon/lgf_reader.h


Ignore:
Timestamp:
10/01/08 13:56:40 (16 years ago)
Author:
Alpar Juttner <alpar@…>
Branch:
default
Children:
295:7c796c1cf1b0, 296:9768e60aa4e1
Parents:
293:47fbc814aa31 (diff), 292:e7af73f1805e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Phase:
public
Message:

Merge

Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lemon/lgf_reader.h

    r291 r294  
    393393
    394394  template <typename Digraph>
    395   DigraphReader<Digraph> digraphReader(std::istream& is, Digraph& digraph);
     395  DigraphReader<Digraph> digraphReader(Digraph& digraph,
     396                                       std::istream& is = std::cin);
    396397
    397398  template <typename Digraph>
    398   DigraphReader<Digraph> digraphReader(const std::string& fn, Digraph& digraph);
     399  DigraphReader<Digraph> digraphReader(Digraph& digraph, const std::string& fn);
    399400
    400401  template <typename Digraph>
    401   DigraphReader<Digraph> digraphReader(const char *fn, Digraph& digraph);
     402  DigraphReader<Digraph> digraphReader(Digraph& digraph, const char *fn);
    402403
    403404  /// \ingroup lemon_io
     
    422423  ///
    423424  ///\code
    424   /// DigraphReader<Digraph>(std::cin, digraph).
     425  /// DigraphReader<Digraph>(digraph, std::cin).
    425426  ///   nodeMap("coordinates", coord_map).
    426427  ///   arcMap("capacity", cap_map).
     
    503504    /// Construct a directed graph reader, which reads from the given
    504505    /// input stream.
    505     DigraphReader(std::istream& is, Digraph& digraph)
     506    DigraphReader(Digraph& digraph, std::istream& is = std::cin)
    506507      : _is(&is), local_is(false), _digraph(digraph),
    507508        _use_nodes(false), _use_arcs(false),
     
    512513    /// Construct a directed graph reader, which reads from the given
    513514    /// file.
    514     DigraphReader(const std::string& fn, Digraph& digraph)
     515    DigraphReader(Digraph& digraph, const std::string& fn)
    515516      : _is(new std::ifstream(fn.c_str())), local_is(true),
    516517        _filename(fn), _digraph(digraph),
     
    524525    /// Construct a directed graph reader, which reads from the given
    525526    /// file.
    526     DigraphReader(const char* fn, Digraph& digraph)
     527    DigraphReader(Digraph& digraph, const char* fn)
    527528      : _is(new std::ifstream(fn)), local_is(true),
    528529        _filename(fn), _digraph(digraph),
     
    557558  private:
    558559
    559     friend DigraphReader<Digraph> digraphReader<>(std::istream& is,
    560                                                   Digraph& digraph);
    561     friend DigraphReader<Digraph> digraphReader<>(const std::string& fn,
    562                                                   Digraph& digraph);
    563     friend DigraphReader<Digraph> digraphReader<>(const char *fn,
    564                                                   Digraph& digraph);
     560    friend DigraphReader<Digraph> digraphReader<>(Digraph& digraph,
     561                                                  std::istream& is);
     562    friend DigraphReader<Digraph> digraphReader<>(Digraph& digraph,
     563                                                  const std::string& fn);
     564    friend DigraphReader<Digraph> digraphReader<>(Digraph& digraph,
     565                                                  const char *fn);
    565566
    566567    DigraphReader(DigraphReader& other)
     
    11881189  /// \relates DigraphReader
    11891190  template <typename Digraph>
    1190   DigraphReader<Digraph> digraphReader(std::istream& is, Digraph& digraph) {
    1191     DigraphReader<Digraph> tmp(is, digraph);
     1191  DigraphReader<Digraph> digraphReader(Digraph& digraph,
     1192                                       std::istream& is = std::cin) {
     1193    DigraphReader<Digraph> tmp(digraph, is);
    11921194    return tmp;
    11931195  }
     
    11981200  /// \relates DigraphReader
    11991201  template <typename Digraph>
    1200   DigraphReader<Digraph> digraphReader(const std::string& fn,
    1201                                        Digraph& digraph) {
    1202     DigraphReader<Digraph> tmp(fn, digraph);
     1202  DigraphReader<Digraph> digraphReader(Digraph& digraph,
     1203                                       const std::string& fn) {
     1204    DigraphReader<Digraph> tmp(digraph, fn);
    12031205    return tmp;
    12041206  }
     
    12091211  /// \relates DigraphReader
    12101212  template <typename Digraph>
    1211   DigraphReader<Digraph> digraphReader(const char* fn, Digraph& digraph) {
    1212     DigraphReader<Digraph> tmp(fn, digraph);
     1213  DigraphReader<Digraph> digraphReader(Digraph& digraph, const char* fn) {
     1214    DigraphReader<Digraph> tmp(digraph, fn);
    12131215    return tmp;
    12141216  }
     
    12181220
    12191221  template <typename Graph>
    1220   GraphReader<Graph> graphReader(std::istream& is, Graph& graph);
     1222  GraphReader<Graph> graphReader(Graph& graph,
     1223                                 std::istream& is = std::cin);
    12211224
    12221225  template <typename Graph>
    1223   GraphReader<Graph> graphReader(const std::string& fn, Graph& graph);
     1226  GraphReader<Graph> graphReader(Graph& graph, const std::string& fn);
    12241227
    12251228  template <typename Graph>
    1226   GraphReader<Graph> graphReader(const char *fn, Graph& graph);
     1229  GraphReader<Graph> graphReader(Graph& graph, const char *fn);
    12271230
    12281231  /// \ingroup lemon_io
     
    12921295    /// Construct an undirected graph reader, which reads from the given
    12931296    /// input stream.
    1294     GraphReader(std::istream& is, Graph& graph)
     1297    GraphReader(Graph& graph, std::istream& is = std::cin)
    12951298      : _is(&is), local_is(false), _graph(graph),
    12961299        _use_nodes(false), _use_edges(false),
     
    13011304    /// Construct an undirected graph reader, which reads from the given
    13021305    /// file.
    1303     GraphReader(const std::string& fn, Graph& graph)
     1306    GraphReader(Graph& graph, const std::string& fn)
    13041307      : _is(new std::ifstream(fn.c_str())), local_is(true),
    13051308        _filename(fn), _graph(graph),
     
    13131316    /// Construct an undirected graph reader, which reads from the given
    13141317    /// file.
    1315     GraphReader(const char* fn, Graph& graph)
     1318    GraphReader(Graph& graph, const char* fn)
    13161319      : _is(new std::ifstream(fn)), local_is(true),
    13171320        _filename(fn), _graph(graph),
     
    13451348
    13461349  private:
    1347     friend GraphReader<Graph> graphReader<>(std::istream& is, Graph& graph);
    1348     friend GraphReader<Graph> graphReader<>(const std::string& fn,
    1349                                             Graph& graph);
    1350     friend GraphReader<Graph> graphReader<>(const char *fn, Graph& graph);
     1350    friend GraphReader<Graph> graphReader<>(Graph& graph, std::istream& is);
     1351    friend GraphReader<Graph> graphReader<>(Graph& graph,
     1352                                            const std::string& fn);
     1353    friend GraphReader<Graph> graphReader<>(Graph& graph, const char *fn);
    13511354
    13521355    GraphReader(GraphReader& other)
     
    20222025  /// \relates GraphReader
    20232026  template <typename Graph>
    2024   GraphReader<Graph> graphReader(std::istream& is, Graph& graph) {
    2025     GraphReader<Graph> tmp(is, graph);
     2027  GraphReader<Graph> graphReader(Graph& graph, std::istream& is = std::cin) {
     2028    GraphReader<Graph> tmp(graph, is);
    20262029    return tmp;
    20272030  }
     
    20322035  /// \relates GraphReader
    20332036  template <typename Graph>
    2034   GraphReader<Graph> graphReader(const std::string& fn,
    2035                                        Graph& graph) {
    2036     GraphReader<Graph> tmp(fn, graph);
     2037  GraphReader<Graph> graphReader(Graph& graph, const std::string& fn) {
     2038    GraphReader<Graph> tmp(graph, fn);
    20372039    return tmp;
    20382040  }
     
    20432045  /// \relates GraphReader
    20442046  template <typename Graph>
    2045   GraphReader<Graph> graphReader(const char* fn, Graph& graph) {
    2046     GraphReader<Graph> tmp(fn, graph);
     2047  GraphReader<Graph> graphReader(Graph& graph, const char* fn) {
     2048    GraphReader<Graph> tmp(graph, fn);
    20472049    return tmp;
    20482050  }
  • lemon/lgf_reader.h

    r293 r294  
    4949        std::istringstream is(str);
    5050        Value value;
    51         is >> value;
     51        if (!(is >> value)) {
     52          throw FormatError("Cannot read token");
     53        }
    5254
    5355        char c;
    5456        if (is >> std::ws >> c) {
    55           throw DataFormatError("Remaining characters in token");
     57          throw FormatError("Remaining characters in token");
    5658        }
    5759        return value;
     
    167169          std::ostringstream msg;
    168170          msg << "Item not found: " << str;
    169           throw DataFormatError(msg.str().c_str());
     171          throw FormatError(msg.str());
    170172        }
    171173        return it->second;
     
    185187      typename Graph::Arc operator()(const std::string& str) {
    186188        if (str.empty() || (str[0] != '+' && str[0] != '-')) {
    187           throw DataFormatError("Item must start with '+' or '-'");
     189          throw FormatError("Item must start with '+' or '-'");
    188190        }
    189191        typename std::map<std::string, typename Graph::Edge>
    190192          ::const_iterator it = _map.find(str.substr(1));
    191193        if (it == _map.end()) {
    192           throw DataFormatError("Item not found");
     194          throw FormatError("Item not found");
    193195        }
    194196        return _graph.direct(it->second, str[0] == '+');
     
    236238      char c;
    237239      if (!is.get(c))
    238         throw DataFormatError("Escape format error");
     240        throw FormatError("Escape format error");
    239241
    240242      switch (c) {
     
    265267          int code;
    266268          if (!is.get(c) || !isHex(c))
    267             throw DataFormatError("Escape format error");
     269            throw FormatError("Escape format error");
    268270          else if (code = valueHex(c), !is.get(c) || !isHex(c)) is.putback(c);
    269271          else code = code * 16 + valueHex(c);
     
    274276          int code;
    275277          if (!isOct(c))
    276             throw DataFormatError("Escape format error");
     278            throw FormatError("Escape format error");
    277279          else if (code = valueOct(c), !is.get(c) || !isOct(c))
    278280            is.putback(c);
     
    301303        }
    302304        if (!is)
    303           throw DataFormatError("Quoted format error");
     305          throw FormatError("Quoted format error");
    304306      } else {
    305307        is.putback(c);
     
    462464    std::istream* _is;
    463465    bool local_is;
     466    std::string _filename;
    464467
    465468    Digraph& _digraph;
     
    511514    /// file.
    512515    DigraphReader(Digraph& digraph, const std::string& fn)
    513       : _is(new std::ifstream(fn.c_str())), local_is(true), _digraph(digraph),
     516      : _is(new std::ifstream(fn.c_str())), local_is(true),
     517        _filename(fn), _digraph(digraph),
    514518        _use_nodes(false), _use_arcs(false),
    515         _skip_nodes(false), _skip_arcs(false) {}
     519        _skip_nodes(false), _skip_arcs(false) {
     520      if (!(*_is)) throw IoError("Cannot open file", fn);
     521    }
    516522
    517523    /// \brief Constructor
     
    520526    /// file.
    521527    DigraphReader(Digraph& digraph, const char* fn)
    522       : _is(new std::ifstream(fn)), local_is(true), _digraph(digraph),
     528      : _is(new std::ifstream(fn)), local_is(true),
     529        _filename(fn), _digraph(digraph),
    523530        _use_nodes(false), _use_arcs(false),
    524         _skip_nodes(false), _skip_arcs(false) {}
     531        _skip_nodes(false), _skip_arcs(false) {
     532      if (!(*_is)) throw IoError("Cannot open file", fn);
     533    }
    525534
    526535    /// \brief Destructor
     
    847856        if (readSuccess() && line) line.putback(c);
    848857        if (!_node_maps.empty())
    849           throw DataFormatError("Cannot find map names");
     858          throw FormatError("Cannot find map names");
    850859        return;
    851860      }
     
    861870            std::ostringstream msg;
    862871            msg << "Multiple occurence of node map: " << map;
    863             throw DataFormatError(msg.str().c_str());
     872            throw FormatError(msg.str());
    864873          }
    865874          maps.insert(std::make_pair(map, index));
     
    872881          if (jt == maps.end()) {
    873882            std::ostringstream msg;
    874             msg << "Map not found in file: " << _node_maps[i].first;
    875             throw DataFormatError(msg.str().c_str());
     883            msg << "Map not found: " << _node_maps[i].first;
     884            throw FormatError(msg.str());
    876885          }
    877886          map_index[i] = jt->second;
     
    897906            std::ostringstream msg;
    898907            msg << "Column not found (" << i + 1 << ")";
    899             throw DataFormatError(msg.str().c_str());
     908            throw FormatError(msg.str());
    900909          }
    901910        }
    902911        if (line >> std::ws >> c)
    903           throw DataFormatError("Extra character on the end of line");
     912          throw FormatError("Extra character at the end of line");
    904913
    905914        Node n;
     
    910919        } else {
    911920          if (label_index == -1)
    912             throw DataFormatError("Label map not found in file");
     921            throw FormatError("Label map not found");
    913922          typename std::map<std::string, Node>::iterator it =
    914923            _node_index.find(tokens[label_index]);
     
    916925            std::ostringstream msg;
    917926            msg << "Node with label not found: " << tokens[label_index];
    918             throw DataFormatError(msg.str().c_str());
     927            throw FormatError(msg.str());
    919928          }
    920929          n = it->second;
     
    940949        if (readSuccess() && line) line.putback(c);
    941950        if (!_arc_maps.empty())
    942           throw DataFormatError("Cannot find map names");
     951          throw FormatError("Cannot find map names");
    943952        return;
    944953      }
     
    954963            std::ostringstream msg;
    955964            msg << "Multiple occurence of arc map: " << map;
    956             throw DataFormatError(msg.str().c_str());
     965            throw FormatError(msg.str());
    957966          }
    958967          maps.insert(std::make_pair(map, index));
     
    965974          if (jt == maps.end()) {
    966975            std::ostringstream msg;
    967             msg << "Map not found in file: " << _arc_maps[i].first;
    968             throw DataFormatError(msg.str().c_str());
     976            msg << "Map not found: " << _arc_maps[i].first;
     977            throw FormatError(msg.str());
    969978          }
    970979          map_index[i] = jt->second;
     
    989998
    990999        if (!_reader_bits::readToken(line, source_token))
    991           throw DataFormatError("Source not found");
     1000          throw FormatError("Source not found");
    9921001
    9931002        if (!_reader_bits::readToken(line, target_token))
    994           throw DataFormatError("Target not found");
     1003          throw FormatError("Target not found");
    9951004
    9961005        std::vector<std::string> tokens(map_num);
     
    9991008            std::ostringstream msg;
    10001009            msg << "Column not found (" << i + 1 << ")";
    1001             throw DataFormatError(msg.str().c_str());
     1010            throw FormatError(msg.str());
    10021011          }
    10031012        }
    10041013        if (line >> std::ws >> c)
    1005           throw DataFormatError("Extra character on the end of line");
     1014          throw FormatError("Extra character at the end of line");
    10061015
    10071016        Arc a;
     
    10141023            std::ostringstream msg;
    10151024            msg << "Item not found: " << source_token;
    1016             throw DataFormatError(msg.str().c_str());
     1025            throw FormatError(msg.str());
    10171026          }
    10181027          Node source = it->second;
     
    10221031            std::ostringstream msg;
    10231032            msg << "Item not found: " << target_token;
    1024             throw DataFormatError(msg.str().c_str());
     1033            throw FormatError(msg.str());
    10251034          }
    10261035          Node target = it->second;
     
    10311040        } else {
    10321041          if (label_index == -1)
    1033             throw DataFormatError("Label map not found in file");
     1042            throw FormatError("Label map not found");
    10341043          typename std::map<std::string, Arc>::iterator it =
    10351044            _arc_index.find(tokens[label_index]);
     
    10371046            std::ostringstream msg;
    10381047            msg << "Arc with label not found: " << tokens[label_index];
    1039             throw DataFormatError(msg.str().c_str());
     1048            throw FormatError(msg.str());
    10401049          }
    10411050          a = it->second;
     
    10621071        std::string attr, token;
    10631072        if (!_reader_bits::readToken(line, attr))
    1064           throw DataFormatError("Attribute name not found");
     1073          throw FormatError("Attribute name not found");
    10651074        if (!_reader_bits::readToken(line, token))
    1066           throw DataFormatError("Attribute value not found");
     1075          throw FormatError("Attribute value not found");
    10671076        if (line >> c)
    1068           throw DataFormatError("Extra character on the end of line");
     1077          throw FormatError("Extra character at the end of line");
    10691078
    10701079        {
     
    10721081          if (it != read_attr.end()) {
    10731082            std::ostringstream msg;
    1074             msg << "Multiple occurence of attribute " << attr;
    1075             throw DataFormatError(msg.str().c_str());
     1083            msg << "Multiple occurence of attribute: " << attr;
     1084            throw FormatError(msg.str());
    10761085          }
    10771086          read_attr.insert(attr);
     
    10941103        if (read_attr.find(it->first) == read_attr.end()) {
    10951104          std::ostringstream msg;
    1096           msg << "Attribute not found in file: " << it->first;
    1097           throw DataFormatError(msg.str().c_str());
     1105          msg << "Attribute not found: " << it->first;
     1106          throw FormatError(msg.str());
    10981107        }
    10991108      }
     
    11101119    void run() {
    11111120      LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
    1112       if (!*_is) {
    1113         throw DataFormatError("Cannot find file");
    1114       }
    11151121
    11161122      bool nodes_done = _skip_nodes;
     
    11311137
    11321138          if (line >> c)
    1133             throw DataFormatError("Extra character on the end of line");
     1139            throw FormatError("Extra character at the end of line");
    11341140
    11351141          if (section == "nodes" && !nodes_done) {
     
    11531159            skipSection();
    11541160          }
    1155         } catch (DataFormatError& error) {
     1161        } catch (FormatError& error) {
    11561162          error.line(line_num);
     1163          error.file(_filename);
    11571164          throw;
    11581165        }
     
    11601167
    11611168      if (!nodes_done) {
    1162         throw DataFormatError("Section @nodes not found");
     1169        throw FormatError("Section @nodes not found");
    11631170      }
    11641171
    11651172      if (!arcs_done) {
    1166         throw DataFormatError("Section @arcs not found");
     1173        throw FormatError("Section @arcs not found");
    11671174      }
    11681175
    11691176      if (!attributes_done && !_attributes.empty()) {
    1170         throw DataFormatError("Section @attributes not found");
     1177        throw FormatError("Section @attributes not found");
    11711178      }
    11721179
     
    12481255    std::istream* _is;
    12491256    bool local_is;
     1257    std::string _filename;
    12501258
    12511259    Graph& _graph;
     
    12971305    /// file.
    12981306    GraphReader(Graph& graph, const std::string& fn)
    1299       : _is(new std::ifstream(fn.c_str())), local_is(true), _graph(graph),
     1307      : _is(new std::ifstream(fn.c_str())), local_is(true),
     1308        _filename(fn), _graph(graph),
    13001309        _use_nodes(false), _use_edges(false),
    1301         _skip_nodes(false), _skip_edges(false) {}
     1310        _skip_nodes(false), _skip_edges(false) {
     1311      if (!(*_is)) throw IoError("Cannot open file", fn);
     1312    }
    13021313
    13031314    /// \brief Constructor
     
    13061317    /// file.
    13071318    GraphReader(Graph& graph, const char* fn)
    1308       : _is(new std::ifstream(fn)), local_is(true), _graph(graph),
     1319      : _is(new std::ifstream(fn)), local_is(true),
     1320        _filename(fn), _graph(graph),
    13091321        _use_nodes(false), _use_edges(false),
    1310         _skip_nodes(false), _skip_edges(false) {}
     1322        _skip_nodes(false), _skip_edges(false) {
     1323      if (!(*_is)) throw IoError("Cannot open file", fn);
     1324    }
    13111325
    13121326    /// \brief Destructor
     
    16771691        if (readSuccess() && line) line.putback(c);
    16781692        if (!_node_maps.empty())
    1679           throw DataFormatError("Cannot find map names");
     1693          throw FormatError("Cannot find map names");
    16801694        return;
    16811695      }
     
    16911705            std::ostringstream msg;
    16921706            msg << "Multiple occurence of node map: " << map;
    1693             throw DataFormatError(msg.str().c_str());
     1707            throw FormatError(msg.str());
    16941708          }
    16951709          maps.insert(std::make_pair(map, index));
     
    17021716          if (jt == maps.end()) {
    17031717            std::ostringstream msg;
    1704             msg << "Map not found in file: " << _node_maps[i].first;
    1705             throw DataFormatError(msg.str().c_str());
     1718            msg << "Map not found: " << _node_maps[i].first;
     1719            throw FormatError(msg.str());
    17061720          }
    17071721          map_index[i] = jt->second;
     
    17271741            std::ostringstream msg;
    17281742            msg << "Column not found (" << i + 1 << ")";
    1729             throw DataFormatError(msg.str().c_str());
     1743            throw FormatError(msg.str());
    17301744          }
    17311745        }
    17321746        if (line >> std::ws >> c)
    1733           throw DataFormatError("Extra character on the end of line");
     1747          throw FormatError("Extra character at the end of line");
    17341748
    17351749        Node n;
     
    17401754        } else {
    17411755          if (label_index == -1)
    1742             throw DataFormatError("Label map not found in file");
     1756            throw FormatError("Label map not found");
    17431757          typename std::map<std::string, Node>::iterator it =
    17441758            _node_index.find(tokens[label_index]);
     
    17461760            std::ostringstream msg;
    17471761            msg << "Node with label not found: " << tokens[label_index];
    1748             throw DataFormatError(msg.str().c_str());
     1762            throw FormatError(msg.str());
    17491763          }
    17501764          n = it->second;
     
    17701784        if (readSuccess() && line) line.putback(c);
    17711785        if (!_edge_maps.empty())
    1772           throw DataFormatError("Cannot find map names");
     1786          throw FormatError("Cannot find map names");
    17731787        return;
    17741788      }
     
    17841798            std::ostringstream msg;
    17851799            msg << "Multiple occurence of edge map: " << map;
    1786             throw DataFormatError(msg.str().c_str());
     1800            throw FormatError(msg.str());
    17871801          }
    17881802          maps.insert(std::make_pair(map, index));
     
    17951809          if (jt == maps.end()) {
    17961810            std::ostringstream msg;
    1797             msg << "Map not found in file: " << _edge_maps[i].first;
    1798             throw DataFormatError(msg.str().c_str());
     1811            msg << "Map not found: " << _edge_maps[i].first;
     1812            throw FormatError(msg.str());
    17991813          }
    18001814          map_index[i] = jt->second;
     
    18191833
    18201834        if (!_reader_bits::readToken(line, source_token))
    1821           throw DataFormatError("Node u not found");
     1835          throw FormatError("Node u not found");
    18221836
    18231837        if (!_reader_bits::readToken(line, target_token))
    1824           throw DataFormatError("Node v not found");
     1838          throw FormatError("Node v not found");
    18251839
    18261840        std::vector<std::string> tokens(map_num);
     
    18291843            std::ostringstream msg;
    18301844            msg << "Column not found (" << i + 1 << ")";
    1831             throw DataFormatError(msg.str().c_str());
     1845            throw FormatError(msg.str());
    18321846          }
    18331847        }
    18341848        if (line >> std::ws >> c)
    1835           throw DataFormatError("Extra character on the end of line");
     1849          throw FormatError("Extra character at the end of line");
    18361850
    18371851        Edge e;
     
    18441858            std::ostringstream msg;
    18451859            msg << "Item not found: " << source_token;
    1846             throw DataFormatError(msg.str().c_str());
     1860            throw FormatError(msg.str());
    18471861          }
    18481862          Node source = it->second;
     
    18521866            std::ostringstream msg;
    18531867            msg << "Item not found: " << target_token;
    1854             throw DataFormatError(msg.str().c_str());
     1868            throw FormatError(msg.str());
    18551869          }
    18561870          Node target = it->second;
     
    18611875        } else {
    18621876          if (label_index == -1)
    1863             throw DataFormatError("Label map not found in file");
     1877            throw FormatError("Label map not found");
    18641878          typename std::map<std::string, Edge>::iterator it =
    18651879            _edge_index.find(tokens[label_index]);
     
    18671881            std::ostringstream msg;
    18681882            msg << "Edge with label not found: " << tokens[label_index];
    1869             throw DataFormatError(msg.str().c_str());
     1883            throw FormatError(msg.str());
    18701884          }
    18711885          e = it->second;
     
    18921906        std::string attr, token;
    18931907        if (!_reader_bits::readToken(line, attr))
    1894           throw DataFormatError("Attribute name not found");
     1908          throw FormatError("Attribute name not found");
    18951909        if (!_reader_bits::readToken(line, token))
    1896           throw DataFormatError("Attribute value not found");
     1910          throw FormatError("Attribute value not found");
    18971911        if (line >> c)
    1898           throw DataFormatError("Extra character on the end of line");
     1912          throw FormatError("Extra character at the end of line");
    18991913
    19001914        {
     
    19021916          if (it != read_attr.end()) {
    19031917            std::ostringstream msg;
    1904             msg << "Multiple occurence of attribute " << attr;
    1905             throw DataFormatError(msg.str().c_str());
     1918            msg << "Multiple occurence of attribute: " << attr;
     1919            throw FormatError(msg.str());
    19061920          }
    19071921          read_attr.insert(attr);
     
    19241938        if (read_attr.find(it->first) == read_attr.end()) {
    19251939          std::ostringstream msg;
    1926           msg << "Attribute not found in file: " << it->first;
    1927           throw DataFormatError(msg.str().c_str());
     1940          msg << "Attribute not found: " << it->first;
     1941          throw FormatError(msg.str());
    19281942        }
    19291943      }
     
    19591973
    19601974          if (line >> c)
    1961             throw DataFormatError("Extra character on the end of line");
     1975            throw FormatError("Extra character at the end of line");
    19621976
    19631977          if (section == "nodes" && !nodes_done) {
     
    19811995            skipSection();
    19821996          }
    1983         } catch (DataFormatError& error) {
     1997        } catch (FormatError& error) {
    19841998          error.line(line_num);
     1999          error.file(_filename);
    19852000          throw;
    19862001        }
     
    19882003
    19892004      if (!nodes_done) {
    1990         throw DataFormatError("Section @nodes not found");
     2005        throw FormatError("Section @nodes not found");
    19912006      }
    19922007
    19932008      if (!edges_done) {
    1994         throw DataFormatError("Section @edges not found");
     2009        throw FormatError("Section @edges not found");
    19952010      }
    19962011
    19972012      if (!attributes_done && !_attributes.empty()) {
    1998         throw DataFormatError("Section @attributes not found");
     2013        throw FormatError("Section @attributes not found");
    19992014      }
    20002015
     
    20572072    std::istream* _is;
    20582073    bool local_is;
     2074    std::string _filename;
    20592075
    20602076    typedef std::map<std::string, _reader_bits::Section*> Sections;
     
    20772093    /// Construct a section reader, which reads from the given file.
    20782094    SectionReader(const std::string& fn)
    2079       : _is(new std::ifstream(fn.c_str())), local_is(true) {}
     2095      : _is(new std::ifstream(fn.c_str())), local_is(true),
     2096        _filename(fn) {
     2097      if (!(*_is)) throw IoError("Cannot open file", fn);
     2098    }
    20802099
    20812100    /// \brief Constructor
     
    20832102    /// Construct a section reader, which reads from the given file.
    20842103    SectionReader(const char* fn)
    2085       : _is(new std::ifstream(fn)), local_is(true) {}
     2104      : _is(new std::ifstream(fn)), local_is(true),
     2105        _filename(fn) {
     2106      if (!(*_is)) throw IoError("Cannot open file", fn);
     2107    }
    20862108
    20872109    /// \brief Destructor
     
    22392261
    22402262          if (line >> c)
    2241             throw DataFormatError("Extra character on the end of line");
     2263            throw FormatError("Extra character at the end of line");
    22422264
    22432265          if (extra_sections.find(section) != extra_sections.end()) {
    22442266            std::ostringstream msg;
    2245             msg << "Multiple occurence of section " << section;
    2246             throw DataFormatError(msg.str().c_str());
     2267            msg << "Multiple occurence of section: " << section;
     2268            throw FormatError(msg.str());
    22472269          }
    22482270          Sections::iterator it = _sections.find(section);
     
    22532275          readLine();
    22542276          skipSection();
    2255         } catch (DataFormatError& error) {
     2277        } catch (FormatError& error) {
    22562278          error.line(line_num);
     2279          error.file(_filename);
    22572280          throw;
    22582281        }
     
    22632286          std::ostringstream os;
    22642287          os << "Cannot find section: " << it->first;
    2265           throw DataFormatError(os.str().c_str());
     2288          throw FormatError(os.str());
    22662289        }
    22672290      }
     
    23632386    /// file.
    23642387    LgfContents(const std::string& fn)
    2365       : _is(new std::ifstream(fn.c_str())), local_is(true) {}
     2388      : _is(new std::ifstream(fn.c_str())), local_is(true) {
     2389      if (!(*_is)) throw IoError("Cannot open file", fn);
     2390    }
    23662391
    23672392    /// \brief Constructor
     
    23702395    /// file.
    23712396    LgfContents(const char* fn)
    2372       : _is(new std::ifstream(fn)), local_is(true) {}
     2397      : _is(new std::ifstream(fn)), local_is(true) {
     2398      if (!(*_is)) throw IoError("Cannot open file", fn);
     2399    }
    23732400
    23742401    /// \brief Destructor
Note: See TracChangeset for help on using the changeset viewer.