COIN-OR::LEMON - Graph Library

Changeset 1492:0d58f0301923 in lemon-0.x


Ignore:
Timestamp:
06/15/05 12:10:59 (14 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1973
Message:

Correcting concept checks.

Location:
lemon
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • lemon/lemon_reader.h

    r1477 r1492  
    5050      bool isIdReader() { return true; }
    5151
    52       Item readId(std::istream&, Item) { return Item();}
     52      void readId(std::istream&, Item&) {}
    5353     
    5454      template <class _ItemIdReader>
     
    5757          bool b = reader.isIdReader();
    5858          ignore_unused_variable_warning(b);
    59           Item item = reader.readId(is, Item());
     59          Item item;
     60          reader.readId(is, item);
    6061        }
    6162        _ItemIdReader& reader;
     63        std::istream& is;
     64      };
     65
     66    };
     67
     68    template <typename Item>
     69    class ItemReader {
     70    public:
     71      void read(std::istream&, Item&) {}
     72     
     73      template <class _ItemReader>
     74      struct Constraints {
     75        void constraints() {
     76          Item item;
     77          reader.read(is, item);
     78        }
     79        _ItemReader& reader;
    6280        std::istream& is;
    6381      };
     
    570588
    571589      virtual Item read(std::istream& is) const {
    572         return boxedIdReader.readId(is, Item());
     590        Item item;
     591        boxedIdReader.readId(is, item);
     592        return item;
    573593      }
    574594
     
    697717    NodeSetReader& _readMap(std::string name, MapParameter map,
    698718                            const Reader& reader = Reader()) {
     719      checkConcept<concept::WriteMap<Node, typename Map::Value>, Map>();
     720      checkConcept<_reader_bits::ItemReader<typename Map::Value>, Reader>();
    699721      if (readers.find(name) != readers.end()) {
    700722        ErrorMessage msg;
     
    783805    /// It reads an id from the stream and gives back which node belongs to
    784806    /// it. It is possible only if there was read an "id" named map.
    785     Node readId(std::istream& is, Node = Node()) const {
    786       return inverter->read(is);
     807    void readId(std::istream& is, Node& node) const {
     808      node = inverter->read(is);
    787809    }
    788810
     
    905927    EdgeSetReader& _readMap(std::string name, MapParameter map,
    906928                            const Reader& reader = Reader()) {
     929      checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
     930      checkConcept<_reader_bits::ItemReader<typename Map::Value>, Reader>();
    907931      if (readers.find(name) != readers.end()) {
    908932        ErrorMessage msg;
     
    9961020    /// It reads an id from the stream and gives back which edge belongs to
    9971021    /// it. It is possible only if there was read an "id" named map.
    998     Edge readId(std::istream& is, Edge = Edge()) const {
    999       return inverter->read(is);
     1022    void readId(std::istream& is, Edge& edge) const {
     1023      edge = inverter->read(is);
    10001024    }
    10011025
     
    11251149    UndirEdgeSetReader& _readMap(std::string name, MapParameter map,
    11261150                                 const Reader& reader = Reader()) {
     1151      checkConcept<concept::WriteMap<UndirEdge, typename Map::Value>, Map>();
     1152      checkConcept<_reader_bits::ItemReader<typename Map::Value>, Reader>();
    11271153      if (readers.find(name) != readers.end()) {
    11281154        ErrorMessage msg;
     
    11911217    template <typename Reader, typename Map, typename MapParameter>
    11921218    UndirEdgeSetReader& _readDirMap(std::string name, MapParameter map,
    1193                                     const Reader& reader = Reader()) {
     1219                                    const Reader& reader = Reader()) {
     1220      checkConcept<_reader_bits::ItemReader<typename Map::Value>, Reader>();
     1221      checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
    11941222      readMap("+" + name,
    11951223              _reader_bits::writeComposeMap(map, forwardMap(graph)), reader);
     
    12761304    /// It reads an id from the stream and gives back which undirected edge
    12771305    /// belongs to it. It is possible only if there was read an "id" named map.
    1278     UndirEdge readId(std::istream& is, UndirEdge = UndirEdge()) const {
    1279       return inverter->read(is);
     1306    void readId(std::istream& is, UndirEdge& undirEdge) const {
     1307      undirEdge = inverter->read(is);
    12801308    }
    12811309
     
    12861314    /// and the undirected edge id. It is possible only if there was read
    12871315    /// an "id" named map.
    1288     Edge readId(std::istream& is, Edge = Edge()) const {
     1316    void readId(std::istream& is, Edge& edge) const {
    12891317      char c;
    12901318      is >> c;
    12911319      UndirEdge undirEdge = inverter->read(is);
    12921320      if (c == '+') {
    1293         return graph.edgeWithSource(undirEdge, graph.source(undirEdge));
     1321        edge = graph.edgeWithSource(undirEdge, graph.source(undirEdge));
    12941322      } else if (c == '-') {
    1295         return graph.edgeWithSource(undirEdge, graph.target(undirEdge));
     1323        edge = graph.edgeWithSource(undirEdge, graph.target(undirEdge));
    12961324      } else {
    12971325        throw DataFormatError("Wrong id format for edge "
     
    13411369      : Parent(_reader), id(_id) {
    13421370      checkConcept<_reader_bits::ItemIdReader<Node>, _IdReader>();
    1343       idReader.reset(new IdReader<Node, _IdReader>(_idReader));
     1371      nodeIdReader.reset(new IdReader<Node, _IdReader>(_idReader));
    13441372    }
    13451373
     
    13861414    /// It reads the content of the section.
    13871415    virtual void read(std::istream& is) {
    1388       if (!idReader->isIdReader()) {
     1416      if (!nodeIdReader->isIdReader()) {
    13891417        throw DataFormatError("Cannot find nodeset or ID map");
    13901418      }
     
    13961424        typename NodeReaders::iterator it = readers.find(id);
    13971425        if (it != readers.end()) {
    1398           *(it->second) = idReader->read(ls);
     1426          *(it->second) = nodeIdReader->read(ls);
    13991427        }       
    14001428      }
     
    14071435    typedef std::map<std::string, Node*> NodeReaders;
    14081436    NodeReaders readers;
    1409     std::auto_ptr<IdReaderBase<Node> > idReader;
     1437    std::auto_ptr<IdReaderBase<Node> > nodeIdReader;
    14101438  };
    14111439
     
    14381466      : Parent(_reader), id(_id) {
    14391467      checkConcept<_reader_bits::ItemIdReader<Edge>, _IdReader>();
    1440       idReader.reset(new IdReader<Edge, _IdReader>(_idReader));
     1468      edgeIdReader.reset(new IdReader<Edge, _IdReader>(_idReader));
    14411469    }
    14421470
     
    14821510    /// It reads the content of the section.
    14831511    virtual void read(std::istream& is) {
    1484       if (!idReader->isIdReader()) {
     1512      if (!edgeIdReader->isIdReader()) {
    14851513        throw DataFormatError("Cannot find edgeset or ID map");
    14861514      }
     
    14921520        typename EdgeReaders::iterator it = readers.find(id);
    14931521        if (it != readers.end()) {
    1494           *(it->second) = idReader->read(ls);
     1522          *(it->second) = edgeIdReader->read(ls);
    14951523        }       
    14961524      }
     
    15031531    typedef std::map<std::string, Edge*> EdgeReaders;
    15041532    EdgeReaders readers;
    1505     std::auto_ptr<IdReaderBase<Edge> > idReader;
     1533    std::auto_ptr<IdReaderBase<Edge> > edgeIdReader;
    15061534  };
    15071535
     
    16891717    AttributeReader& readAttribute(const std::string& name, Value& value,
    16901718                                   const Reader& reader = Reader()) {
     1719      checkConcept<_reader_bits::ItemReader<Value>, Reader>();
    16911720      if (readers.find(name) != readers.end()) {
    16921721        ErrorMessage msg;
  • lemon/lemon_writer.h

    r1476 r1492  
    5656      struct Constraints {
    5757        void constraints() {
    58           const Item item;
    5958          bool b = writer.isIdWriter();
    6059          ignore_unused_variable_warning(b);
     
    6362        _ItemIdWriter& writer;
    6463        std::ostream& os;
     64        const Item& item;
     65      };
     66
     67    };
     68
     69    template <typename Item>
     70    class ItemWriter {
     71    public:
     72
     73      void write(std::ostream&, const Item&) {}
     74     
     75      template <class _ItemWriter>
     76      struct Constraints {
     77        void constraints() {
     78          writer.write(os, item);
     79        }
     80        _ItemWriter& writer;
     81        std::ostream& os;
     82        const Item& item;
    6583      };
    6684
     
    353371    NodeSetWriter& writeNodeMap(std::string name, const Map& map,
    354372                            const Writer& writer = Writer()) {
    355       checkConcept<concept::WriteMap<Node, typename Map::Value>, Map>();
     373      checkConcept<concept::ReadMap<Node, typename Map::Value>, Map>();
     374      checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
    356375      writers.push_back(
    357376        make_pair(name, new MapWriter<Node, Map, Writer>(map, writer)));
     
    518537    EdgeSetWriter& writeEdgeMap(std::string name, const Map& map,
    519538                            const Writer& writer = Writer()) {
    520       checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
     539      checkConcept<concept::ReadMap<Edge, typename Map::Value>, Map>();
     540      checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
    521541      writers.push_back(
    522542        make_pair(name, new MapWriter<Edge, Map, Writer>(map, writer)));
     
    699719    UndirEdgeSetWriter& writeUndirEdgeMap(std::string name, const Map& map,
    700720                                          const Writer& writer = Writer()) {
    701       checkConcept<concept::WriteMap<UndirEdge, typename Map::Value>, Map>();
     721      checkConcept<concept::ReadMap<UndirEdge, typename Map::Value>, Map>();
     722      checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
    702723      writers.push_back(
    703724        make_pair(name, new MapWriter<UndirEdge, Map, Writer>(map, writer)));
     
    710731    template <typename Map>
    711732    UndirEdgeSetWriter& writeEdgeMap(std::string name, const Map& map) {
    712       checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
    713       writeUndirEdgeMap("+" + name, composeMap(forwardMap(graph), map));
    714       writeUndirEdgeMap("-" + name, composeMap(backwardMap(graph), map));
    715       return *this;
     733      return writeEdgeMap<typename Traits::
     734        template Writer<typename Map::Value>, Map>(name, map);
    716735    }
    717736
     
    722741    UndirEdgeSetWriter& writeEdgeMap(std::string name, const Map& map,
    723742                                     const Writer& writer = Writer()) {
    724       checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
     743      checkConcept<concept::ReadMap<Edge, typename Map::Value>, Map>();
     744      checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
    725745      writeUndirEdge("+" + name, composeMap(forwardMap(graph), map), writer);
    726746      writeUndirEdge("-" + name, composeMap(backwardMap(graph), map), writer);
     
    11611181                                    const Value& value,
    11621182                                    const Writer& writer = Writer()) {
     1183      checkConcept<_writer_bits::ItemWriter<Value>, Writer>();
    11631184      writers.push_back(make_pair(name, new ValueWriter<Value, Writer>
    11641185                               (value, writer)));
Note: See TracChangeset for help on using the changeset viewer.