COIN-OR::LEMON - Graph Library

Changeset 1476:182da222fceb in lemon-0.x for lemon/lemon_reader.h


Ignore:
Timestamp:
06/13/05 19:13:56 (15 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1956
Message:

Some bug fix.

Added: Concept check for maps and IdReader/Writer? classes

Some runtime check

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/lemon_reader.h

    r1435 r1476  
    3737#include <lemon/bits/item_reader.h>
    3838
     39#include <lemon/concept_check.h>
     40#include <lemon/concept/maps.h>
    3941
    4042namespace lemon {
    4143
    4244  namespace _reader_bits {
     45
     46    template <typename Item>
     47    class ItemIdReader {
     48    public:
     49
     50      bool isIdReader() { return true; }
     51
     52      Item readId(std::istream&, Item) { return Item();}
     53     
     54      template <class _ItemIdReader>
     55      struct Constraints {
     56        void constraints() {
     57          bool b = reader.isIdReader();
     58          ignore_unused_variable_warning(b);
     59          Item item = reader.readId(is, Item());
     60        }
     61        _ItemIdReader& reader;
     62        std::istream& is;
     63      };
     64
     65    };
    4366 
    4467    template <typename T>
     
    532555      typedef _Item Item;
    533556      virtual Item read(std::istream& is) const = 0;
     557      virtual bool isIdReader() const = 0;
    534558    };
    535559
     
    547571      virtual Item read(std::istream& is) const {
    548572        return boxedIdReader.readId(is, Item());
     573      }
     574
     575      virtual bool isIdReader() const {
     576        return boxedIdReader.isIdReader();
    549577      }
    550578    };
     
    818846                  const std::string& _id = std::string(),
    819847                  const DefaultSkipper& _skipper = DefaultSkipper())
    820       : Parent(_reader), graph(_graph), id(_id), skipper(_skipper),
    821         nodeIdReader(new IdReader<Node, NodeIdReader>(_nodeIdReader)) {}
    822 
     848      : Parent(_reader), graph(_graph), id(_id), skipper(_skipper) {
     849      checkConcept<_reader_bits::ItemIdReader<Node>, NodeIdReader>();
     850      nodeIdReader.reset(new IdReader<Node, NodeIdReader>(_nodeIdReader));
     851    }
    823852    /// \brief Destructor.
    824853    ///
     
    922951    /// It reads the content of the section.
    923952    virtual void read(std::istream& is) {
     953      if (!nodeIdReader->isIdReader()) {
     954        throw DataFormatError("Cannot find nodeset or ID map");
     955      }
    924956      std::vector<ReaderBase<Edge>* > index;
    925957      std::string line;
     
    10341066                       const std::string& _id = std::string(),
    10351067                       const DefaultSkipper& _skipper = DefaultSkipper())
    1036       : Parent(_reader), graph(_graph), id(_id), skipper(_skipper),
    1037         nodeIdReader(new IdReader<Node, NodeIdReader>(_nodeIdReader)) {}
    1038 
     1068      : Parent(_reader), graph(_graph), id(_id), skipper(_skipper) {
     1069      checkConcept<_reader_bits::ItemIdReader<Node>, NodeIdReader>();
     1070      nodeIdReader.reset(new IdReader<Node, NodeIdReader>(_nodeIdReader));
     1071    }
    10391072    /// \brief Destructor.
    10401073    ///
     
    11981231    /// It reads the content of the section.
    11991232    virtual void read(std::istream& is) {
     1233      if (!nodeIdReader->isIdReader()) {
     1234        throw DataFormatError("Cannot find nodeset or ID map");
     1235      }
    12001236      std::vector<ReaderBase<UndirEdge>* > index;
    12011237      std::string line;
     
    13031339    NodeReader(LemonReader& _reader, const _IdReader& _idReader,
    13041340               const std::string& _id = std::string())
    1305       : Parent(_reader), id(_id),
    1306         idReader(new IdReader<typename Graph::Node, _IdReader>(_idReader)) {}
     1341      : Parent(_reader), id(_id) {
     1342      checkConcept<_reader_bits::ItemIdReader<Node>, _IdReader>();
     1343      idReader.reset(new IdReader<Node, _IdReader>(_idReader));
     1344    }
    13071345
    13081346    /// \brief Destructor.
     
    13481386    /// It reads the content of the section.
    13491387    virtual void read(std::istream& is) {
     1388      if (!idReader->isIdReader()) {
     1389        throw DataFormatError("Cannot find nodeset or ID map");
     1390      }
    13501391      std::string line;
    13511392      while (getline(is, line)) {
     
    13951436    EdgeReader(LemonReader& _reader, const _IdReader& _idReader,
    13961437               const std::string& _id = std::string())
    1397       : Parent(_reader), id(_id),
    1398         idReader(new IdReader<typename Graph::Edge, _IdReader>(_idReader)) {}
     1438      : Parent(_reader), id(_id) {
     1439      checkConcept<_reader_bits::ItemIdReader<Edge>, _IdReader>();
     1440      idReader.reset(new IdReader<Edge, _IdReader>(_idReader));
     1441    }
    13991442
    14001443    /// \brief Destructor.
     
    14391482    /// It reads the content of the section.
    14401483    virtual void read(std::istream& is) {
     1484      if (!idReader->isIdReader()) {
     1485        throw DataFormatError("Cannot find edgeset or ID map");
     1486      }
    14411487      std::string line;
    14421488      while (getline(is, line)) {
     
    14881534    UndirEdgeReader(LemonReader& _reader, const _IdReader& _idReader,
    14891535               const std::string& _id = std::string())
    1490       : Parent(_reader), id(_id),
    1491         undirEdgeIdReader(new IdReader<UndirEdge, _IdReader>(_idReader)),
    1492         edgeIdReader(new IdReader<Edge, _IdReader>(_idReader))
    1493     {}
     1536      : Parent(_reader), id(_id) {
     1537      checkConcept<_reader_bits::ItemIdReader<UndirEdge>, _IdReader>();
     1538      checkConcept<_reader_bits::ItemIdReader<Edge>, _IdReader>();
     1539      undirEdgeIdReader.reset(new IdReader<UndirEdge, _IdReader>(_idReader));
     1540      egdeIdReader.reset(new IdReader<Edge, _IdReader>(_idReader));
     1541    }
    14941542
    14951543    /// \brief Destructor.
     
    15461594    /// It reads the content of the section.
    15471595    virtual void read(std::istream& is) {
     1596      if (!edgeIdReader->isIdReader()) {
     1597        throw DataFormatError("Cannot find undirected edgeset or ID map");
     1598      }
     1599      if (!undirEdgeIdReader->isIdReader()) {
     1600        throw DataFormatError("Cannot find undirected edgeset or ID map");
     1601      }
    15481602      std::string line;
    15491603      while (getline(is, line)) {
Note: See TracChangeset for help on using the changeset viewer.