Correcting concept checks.
authordeba
Wed, 15 Jun 2005 10:10:59 +0000
changeset 14920d58f0301923
parent 1491 340514805e40
child 1493 94535d1833b5
Correcting concept checks.
lemon/lemon_reader.h
lemon/lemon_writer.h
     1.1 --- a/lemon/lemon_reader.h	Tue Jun 14 23:21:31 2005 +0000
     1.2 +++ b/lemon/lemon_reader.h	Wed Jun 15 10:10:59 2005 +0000
     1.3 @@ -49,20 +49,38 @@
     1.4  
     1.5        bool isIdReader() { return true; }
     1.6  
     1.7 -      Item readId(std::istream&, Item) { return Item();}
     1.8 +      void readId(std::istream&, Item&) {}
     1.9        
    1.10        template <class _ItemIdReader>
    1.11        struct Constraints {
    1.12  	void constraints() {
    1.13  	  bool b = reader.isIdReader();
    1.14  	  ignore_unused_variable_warning(b);
    1.15 -	  Item item = reader.readId(is, Item());
    1.16 +	  Item item;
    1.17 +	  reader.readId(is, item);
    1.18  	}
    1.19  	_ItemIdReader& reader;
    1.20  	std::istream& is;
    1.21        };
    1.22  
    1.23      };
    1.24 +
    1.25 +    template <typename Item>
    1.26 +    class ItemReader {
    1.27 +    public:
    1.28 +      void read(std::istream&, Item&) {}
    1.29 +      
    1.30 +      template <class _ItemReader>
    1.31 +      struct Constraints {
    1.32 +	void constraints() {
    1.33 +	  Item item;
    1.34 +	  reader.read(is, item);
    1.35 +	}
    1.36 +	_ItemReader& reader;
    1.37 +	std::istream& is;
    1.38 +      };
    1.39 +
    1.40 +    };
    1.41    
    1.42      template <typename T>
    1.43      bool operator<(T, T) {
    1.44 @@ -569,7 +587,9 @@
    1.45  	: boxedIdReader(_boxedIdReader) {}
    1.46  
    1.47        virtual Item read(std::istream& is) const {
    1.48 -	return boxedIdReader.readId(is, Item());
    1.49 +	Item item;
    1.50 +	boxedIdReader.readId(is, item);
    1.51 +	return item;
    1.52        }
    1.53  
    1.54        virtual bool isIdReader() const {
    1.55 @@ -696,6 +716,8 @@
    1.56      template <typename Reader, typename Map, typename MapParameter>
    1.57      NodeSetReader& _readMap(std::string name, MapParameter map, 
    1.58  			    const Reader& reader = Reader()) {
    1.59 +      checkConcept<concept::WriteMap<Node, typename Map::Value>, Map>();
    1.60 +      checkConcept<_reader_bits::ItemReader<typename Map::Value>, Reader>();
    1.61        if (readers.find(name) != readers.end()) {
    1.62  	ErrorMessage msg;
    1.63  	msg << "Multiple read rule for node map: " << name;
    1.64 @@ -782,8 +804,8 @@
    1.65      ///
    1.66      /// It reads an id from the stream and gives back which node belongs to
    1.67      /// it. It is possible only if there was read an "id" named map.
    1.68 -    Node readId(std::istream& is, Node = Node()) const {
    1.69 -      return inverter->read(is);
    1.70 +    void readId(std::istream& is, Node& node) const {
    1.71 +      node = inverter->read(is);
    1.72      } 
    1.73  
    1.74    private:
    1.75 @@ -904,6 +926,8 @@
    1.76      template <typename Reader, typename Map, typename MapParameter>
    1.77      EdgeSetReader& _readMap(std::string name, MapParameter map, 
    1.78  			    const Reader& reader = Reader()) {
    1.79 +      checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
    1.80 +      checkConcept<_reader_bits::ItemReader<typename Map::Value>, Reader>();
    1.81        if (readers.find(name) != readers.end()) {
    1.82  	ErrorMessage msg;
    1.83  	msg << "Multiple read rule for edge map: " << name;
    1.84 @@ -995,8 +1019,8 @@
    1.85      ///
    1.86      /// It reads an id from the stream and gives back which edge belongs to
    1.87      /// it. It is possible only if there was read an "id" named map.
    1.88 -    Edge readId(std::istream& is, Edge = Edge()) const {
    1.89 -      return inverter->read(is);
    1.90 +    void readId(std::istream& is, Edge& edge) const {
    1.91 +      edge = inverter->read(is);
    1.92      } 
    1.93  
    1.94    private:
    1.95 @@ -1124,6 +1148,8 @@
    1.96      template <typename Reader, typename Map, typename MapParameter>
    1.97      UndirEdgeSetReader& _readMap(std::string name, MapParameter map,
    1.98  				 const Reader& reader = Reader()) {
    1.99 +      checkConcept<concept::WriteMap<UndirEdge, typename Map::Value>, Map>();
   1.100 +      checkConcept<_reader_bits::ItemReader<typename Map::Value>, Reader>();
   1.101        if (readers.find(name) != readers.end()) {
   1.102  	ErrorMessage msg;
   1.103  	msg << "Multiple read rule for edge map: " << name;
   1.104 @@ -1190,7 +1216,9 @@
   1.105  
   1.106      template <typename Reader, typename Map, typename MapParameter>
   1.107      UndirEdgeSetReader& _readDirMap(std::string name, MapParameter map,
   1.108 -				    const Reader& reader = Reader()) {
   1.109 +				    const Reader& reader = Reader()) { 
   1.110 +      checkConcept<_reader_bits::ItemReader<typename Map::Value>, Reader>();
   1.111 +      checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
   1.112        readMap("+" + name, 
   1.113  	      _reader_bits::writeComposeMap(map, forwardMap(graph)), reader);
   1.114        readMap("-" + name, 
   1.115 @@ -1275,8 +1303,8 @@
   1.116      ///
   1.117      /// It reads an id from the stream and gives back which undirected edge 
   1.118      /// belongs to it. It is possible only if there was read an "id" named map.
   1.119 -    UndirEdge readId(std::istream& is, UndirEdge = UndirEdge()) const {
   1.120 -      return inverter->read(is);
   1.121 +    void readId(std::istream& is, UndirEdge& undirEdge) const {
   1.122 +      undirEdge = inverter->read(is);
   1.123      } 
   1.124  
   1.125      /// \brief Gives back the directed edge by its id.
   1.126 @@ -1285,14 +1313,14 @@
   1.127      /// belongs to it. The directed edge id is the \c '+' or \c '-' character
   1.128      /// and the undirected edge id. It is possible only if there was read 
   1.129      /// an "id" named map.
   1.130 -    Edge readId(std::istream& is, Edge = Edge()) const {
   1.131 +    void readId(std::istream& is, Edge& edge) const {
   1.132        char c;
   1.133        is >> c;
   1.134        UndirEdge undirEdge = inverter->read(is);
   1.135        if (c == '+') {
   1.136 -	return graph.edgeWithSource(undirEdge, graph.source(undirEdge));
   1.137 +	edge = graph.edgeWithSource(undirEdge, graph.source(undirEdge));
   1.138        } else if (c == '-') {
   1.139 -	return graph.edgeWithSource(undirEdge, graph.target(undirEdge));
   1.140 +        edge = graph.edgeWithSource(undirEdge, graph.target(undirEdge));
   1.141        } else {
   1.142  	throw DataFormatError("Wrong id format for edge "
   1.143  			      "in undirected edgeset");
   1.144 @@ -1340,7 +1368,7 @@
   1.145  	       const std::string& _id = std::string()) 
   1.146        : Parent(_reader), id(_id) {
   1.147        checkConcept<_reader_bits::ItemIdReader<Node>, _IdReader>();
   1.148 -      idReader.reset(new IdReader<Node, _IdReader>(_idReader));
   1.149 +      nodeIdReader.reset(new IdReader<Node, _IdReader>(_idReader));
   1.150      }
   1.151  
   1.152      /// \brief Destructor.
   1.153 @@ -1385,7 +1413,7 @@
   1.154      ///
   1.155      /// It reads the content of the section.
   1.156      virtual void read(std::istream& is) {
   1.157 -      if (!idReader->isIdReader()) {
   1.158 +      if (!nodeIdReader->isIdReader()) {
   1.159  	throw DataFormatError("Cannot find nodeset or ID map");
   1.160        }
   1.161        std::string line;
   1.162 @@ -1395,7 +1423,7 @@
   1.163  	ls >> id;
   1.164  	typename NodeReaders::iterator it = readers.find(id);
   1.165  	if (it != readers.end()) {
   1.166 -	  *(it->second) = idReader->read(ls); 
   1.167 +	  *(it->second) = nodeIdReader->read(ls); 
   1.168  	}	
   1.169        }
   1.170      }
   1.171 @@ -1406,7 +1434,7 @@
   1.172  
   1.173      typedef std::map<std::string, Node*> NodeReaders;
   1.174      NodeReaders readers;
   1.175 -    std::auto_ptr<IdReaderBase<Node> > idReader;
   1.176 +    std::auto_ptr<IdReaderBase<Node> > nodeIdReader;
   1.177    };
   1.178  
   1.179    /// \ingroup io_group
   1.180 @@ -1437,7 +1465,7 @@
   1.181  	       const std::string& _id = std::string()) 
   1.182        : Parent(_reader), id(_id) {
   1.183        checkConcept<_reader_bits::ItemIdReader<Edge>, _IdReader>();
   1.184 -      idReader.reset(new IdReader<Edge, _IdReader>(_idReader));
   1.185 +      edgeIdReader.reset(new IdReader<Edge, _IdReader>(_idReader));
   1.186      }
   1.187  
   1.188      /// \brief Destructor.
   1.189 @@ -1481,7 +1509,7 @@
   1.190      ///
   1.191      /// It reads the content of the section.
   1.192      virtual void read(std::istream& is) {
   1.193 -      if (!idReader->isIdReader()) {
   1.194 +      if (!edgeIdReader->isIdReader()) {
   1.195  	throw DataFormatError("Cannot find edgeset or ID map");
   1.196        }
   1.197        std::string line;
   1.198 @@ -1491,7 +1519,7 @@
   1.199  	ls >> id;
   1.200  	typename EdgeReaders::iterator it = readers.find(id);
   1.201  	if (it != readers.end()) {
   1.202 -	  *(it->second) = idReader->read(ls); 
   1.203 +	  *(it->second) = edgeIdReader->read(ls); 
   1.204  	}	
   1.205        }
   1.206      }
   1.207 @@ -1502,7 +1530,7 @@
   1.208  
   1.209      typedef std::map<std::string, Edge*> EdgeReaders;
   1.210      EdgeReaders readers;
   1.211 -    std::auto_ptr<IdReaderBase<Edge> > idReader;
   1.212 +    std::auto_ptr<IdReaderBase<Edge> > edgeIdReader;
   1.213    };
   1.214  
   1.215    /// \ingroup io_group
   1.216 @@ -1688,6 +1716,7 @@
   1.217      template <typename Reader, typename Value>
   1.218      AttributeReader& readAttribute(const std::string& name, Value& value,
   1.219  				   const Reader& reader = Reader()) {
   1.220 +      checkConcept<_reader_bits::ItemReader<Value>, Reader>();
   1.221        if (readers.find(name) != readers.end()) {
   1.222  	ErrorMessage msg;
   1.223  	msg << "Multiple read rule for attribute: " << name;
     2.1 --- a/lemon/lemon_writer.h	Tue Jun 14 23:21:31 2005 +0000
     2.2 +++ b/lemon/lemon_writer.h	Wed Jun 15 10:10:59 2005 +0000
     2.3 @@ -55,13 +55,31 @@
     2.4        template <class _ItemIdWriter>
     2.5        struct Constraints {
     2.6  	void constraints() {
     2.7 -	  const Item item;
     2.8  	  bool b = writer.isIdWriter();
     2.9  	  ignore_unused_variable_warning(b);
    2.10  	  writer.writeId(os, item);
    2.11  	}
    2.12  	_ItemIdWriter& writer;
    2.13  	std::ostream& os;
    2.14 +	const Item& item;
    2.15 +      };
    2.16 +
    2.17 +    };
    2.18 +
    2.19 +    template <typename Item>
    2.20 +    class ItemWriter {
    2.21 +    public:
    2.22 +
    2.23 +      void write(std::ostream&, const Item&) {}
    2.24 +      
    2.25 +      template <class _ItemWriter>
    2.26 +      struct Constraints {
    2.27 +	void constraints() {
    2.28 +	  writer.write(os, item);
    2.29 +	}
    2.30 +	_ItemWriter& writer;
    2.31 +	std::ostream& os;
    2.32 +	const Item& item;
    2.33        };
    2.34  
    2.35      };
    2.36 @@ -352,7 +370,8 @@
    2.37      template <typename Writer, typename Map>
    2.38      NodeSetWriter& writeNodeMap(std::string name, const Map& map, 
    2.39  			    const Writer& writer = Writer()) {
    2.40 -      checkConcept<concept::WriteMap<Node, typename Map::Value>, Map>();
    2.41 +      checkConcept<concept::ReadMap<Node, typename Map::Value>, Map>();
    2.42 +      checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
    2.43        writers.push_back(
    2.44  	make_pair(name, new MapWriter<Node, Map, Writer>(map, writer)));
    2.45        return *this;
    2.46 @@ -517,7 +536,8 @@
    2.47      template <typename Writer, typename Map>
    2.48      EdgeSetWriter& writeEdgeMap(std::string name, const Map& map, 
    2.49  			    const Writer& writer = Writer()) {
    2.50 -      checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
    2.51 +      checkConcept<concept::ReadMap<Edge, typename Map::Value>, Map>();
    2.52 +      checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
    2.53        writers.push_back(
    2.54  	make_pair(name, new MapWriter<Edge, Map, Writer>(map, writer)));
    2.55        return *this;
    2.56 @@ -698,7 +718,8 @@
    2.57      template <typename Writer, typename Map>
    2.58      UndirEdgeSetWriter& writeUndirEdgeMap(std::string name, const Map& map, 
    2.59  					  const Writer& writer = Writer()) {
    2.60 -      checkConcept<concept::WriteMap<UndirEdge, typename Map::Value>, Map>();
    2.61 +      checkConcept<concept::ReadMap<UndirEdge, typename Map::Value>, Map>();
    2.62 +      checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
    2.63        writers.push_back(
    2.64  	make_pair(name, new MapWriter<UndirEdge, Map, Writer>(map, writer)));
    2.65        return *this;
    2.66 @@ -709,10 +730,8 @@
    2.67      /// Add a new directed map writer command for the writer.
    2.68      template <typename Map>
    2.69      UndirEdgeSetWriter& writeEdgeMap(std::string name, const Map& map) {
    2.70 -      checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
    2.71 -      writeUndirEdgeMap("+" + name, composeMap(forwardMap(graph), map));
    2.72 -      writeUndirEdgeMap("-" + name, composeMap(backwardMap(graph), map));
    2.73 -      return *this;
    2.74 +      return writeEdgeMap<typename Traits::
    2.75 +	template Writer<typename Map::Value>, Map>(name, map);
    2.76      }
    2.77  
    2.78      /// \brief Add a new directed map writer command for the writer.
    2.79 @@ -721,7 +740,8 @@
    2.80      template <typename Writer, typename Map>
    2.81      UndirEdgeSetWriter& writeEdgeMap(std::string name, const Map& map, 
    2.82  				     const Writer& writer = Writer()) {
    2.83 -      checkConcept<concept::WriteMap<Edge, typename Map::Value>, Map>();
    2.84 +      checkConcept<concept::ReadMap<Edge, typename Map::Value>, Map>();
    2.85 +      checkConcept<_writer_bits::ItemWriter<typename Map::Value>, Writer>();
    2.86        writeUndirEdge("+" + name, composeMap(forwardMap(graph), map), writer);
    2.87        writeUndirEdge("-" + name, composeMap(backwardMap(graph), map), writer);
    2.88        return *this;
    2.89 @@ -1160,6 +1180,7 @@
    2.90      AttributeWriter& writeAttribute(const std::string& name, 
    2.91  				    const Value& value,
    2.92  				    const Writer& writer = Writer()) {
    2.93 +      checkConcept<_writer_bits::ItemWriter<Value>, Writer>();
    2.94        writers.push_back(make_pair(name, new ValueWriter<Value, Writer>
    2.95        			       (value, writer)));
    2.96        return *this;