lemon/lgf_reader.h
changeset 1026 699c7eac2c6d
parent 1024 b84e68af8248
child 1029 374a9519986b
equal deleted inserted replaced
49:62eb1816b738 50:749faaf425e8
  2146   ///
  2146   ///
  2147   /// It can be used almost the same way as \c GraphReader, but it
  2147   /// It can be used almost the same way as \c GraphReader, but it
  2148   /// reads the red and blue nodes from separate sections, and these
  2148   /// reads the red and blue nodes from separate sections, and these
  2149   /// sections can contain different set of maps.
  2149   /// sections can contain different set of maps.
  2150   ///
  2150   ///
  2151   /// The red and blue maps are read from the corresponding
  2151   /// The red and blue node maps are read from the corresponding
  2152   /// sections. If a map is defined with the same name in both of
  2152   /// sections. If a map is defined with the same name in both of
  2153   /// these sections, then it can be read as a node map.
  2153   /// these sections, then it can be read as a node map.
  2154   template <typename BGR>
  2154   template <typename BGR>
  2155   class BpGraphReader {
  2155   class BpGraphReader {
  2156   public:
  2156   public:
  2335         new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
  2335         new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
  2336       _blue_maps.push_back(std::make_pair(caption, blue_storage));
  2336       _blue_maps.push_back(std::make_pair(caption, blue_storage));
  2337       return *this;
  2337       return *this;
  2338     }
  2338     }
  2339 
  2339 
  2340     /// Add a red map reading rule to the reader.
  2340     /// Add a red node map reading rule to the reader.
  2341     template <typename Map>
  2341     template <typename Map>
  2342     BpGraphReader& redMap(const std::string& caption, Map& map) {
  2342     BpGraphReader& redNodeMap(const std::string& caption, Map& map) {
  2343       checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
  2343       checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
  2344       _reader_bits::MapStorageBase<Node>* storage =
  2344       _reader_bits::MapStorageBase<Node>* storage =
  2345         new _reader_bits::MapStorage<Node, Map>(map);
  2345         new _reader_bits::MapStorage<Node, Map>(map);
  2346       _red_maps.push_back(std::make_pair(caption, storage));
  2346       _red_maps.push_back(std::make_pair(caption, storage));
  2347       return *this;
  2347       return *this;
  2348     }
  2348     }
  2349 
  2349 
  2350     /// \brief Red map reading rule
  2350     /// \brief Red node map reading rule
  2351     ///
  2351     ///
  2352     /// Add a red map reading rule with specialized converter to the
  2352     /// Add a red node map node reading rule with specialized converter to
  2353     /// reader.
  2353     /// the reader.
  2354     template <typename Map, typename Converter>
  2354     template <typename Map, typename Converter>
  2355     BpGraphReader& redMap(const std::string& caption, Map& map,
  2355     BpGraphReader& redNodeMap(const std::string& caption, Map& map,
  2356                           const Converter& converter = Converter()) {
  2356                               const Converter& converter = Converter()) {
  2357       checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
  2357       checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
  2358       _reader_bits::MapStorageBase<Node>* storage =
  2358       _reader_bits::MapStorageBase<Node>* storage =
  2359         new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
  2359         new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
  2360       _red_maps.push_back(std::make_pair(caption, storage));
  2360       _red_maps.push_back(std::make_pair(caption, storage));
  2361       return *this;
  2361       return *this;
  2362     }
  2362     }
  2363 
  2363 
  2364     /// Add a blue map reading rule to the reader.
  2364     /// Add a blue node map reading rule to the reader.
  2365     template <typename Map>
  2365     template <typename Map>
  2366     BpGraphReader& blueMap(const std::string& caption, Map& map) {
  2366     BpGraphReader& blueNodeMap(const std::string& caption, Map& map) {
  2367       checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
  2367       checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
  2368       _reader_bits::MapStorageBase<Node>* storage =
  2368       _reader_bits::MapStorageBase<Node>* storage =
  2369         new _reader_bits::MapStorage<Node, Map>(map);
  2369         new _reader_bits::MapStorage<Node, Map>(map);
  2370       _blue_maps.push_back(std::make_pair(caption, storage));
  2370       _blue_maps.push_back(std::make_pair(caption, storage));
  2371       return *this;
  2371       return *this;
  2372     }
  2372     }
  2373 
  2373 
  2374     /// \brief Blue map reading rule
  2374     /// \brief Blue node map reading rule
  2375     ///
  2375     ///
  2376     /// Add a blue map reading rule with specialized converter to the
  2376     /// Add a blue node map reading rule with specialized converter to
  2377     /// reader.
  2377     /// the reader.
  2378     template <typename Map, typename Converter>
  2378     template <typename Map, typename Converter>
  2379     BpGraphReader& blueMap(const std::string& caption, Map& map,
  2379     BpGraphReader& blueNodeMap(const std::string& caption, Map& map,
  2380                            const Converter& converter = Converter()) {
  2380                                const Converter& converter = Converter()) {
  2381       checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
  2381       checkConcept<concepts::WriteMap<Node, typename Map::Value>, Map>();
  2382       _reader_bits::MapStorageBase<Node>* storage =
  2382       _reader_bits::MapStorageBase<Node>* storage =
  2383         new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
  2383         new _reader_bits::MapStorage<Node, Map, Converter>(map, converter);
  2384       _blue_maps.push_back(std::make_pair(caption, storage));
  2384       _blue_maps.push_back(std::make_pair(caption, storage));
  2385       return *this;
  2385       return *this;
  2682         std::string map;
  2682         std::string map;
  2683         int index = 0;
  2683         int index = 0;
  2684         while (_reader_bits::readToken(line, map)) {
  2684         while (_reader_bits::readToken(line, map)) {
  2685           if (maps.find(map) != maps.end()) {
  2685           if (maps.find(map) != maps.end()) {
  2686             std::ostringstream msg;
  2686             std::ostringstream msg;
  2687             msg << "Multiple occurence of red map: " << map;
  2687             msg << "Multiple occurence of red node map: " << map;
  2688             throw FormatError(msg.str());
  2688             throw FormatError(msg.str());
  2689           }
  2689           }
  2690           maps.insert(std::make_pair(map, index));
  2690           maps.insert(std::make_pair(map, index));
  2691           ++index;
  2691           ++index;
  2692         }
  2692         }
  2775         std::string map;
  2775         std::string map;
  2776         int index = 0;
  2776         int index = 0;
  2777         while (_reader_bits::readToken(line, map)) {
  2777         while (_reader_bits::readToken(line, map)) {
  2778           if (maps.find(map) != maps.end()) {
  2778           if (maps.find(map) != maps.end()) {
  2779             std::ostringstream msg;
  2779             std::ostringstream msg;
  2780             msg << "Multiple occurence of blue map: " << map;
  2780             msg << "Multiple occurence of blue node map: " << map;
  2781             throw FormatError(msg.str());
  2781             throw FormatError(msg.str());
  2782           }
  2782           }
  2783           maps.insert(std::make_pair(map, index));
  2783           maps.insert(std::make_pair(map, index));
  2784           ++index;
  2784           ++index;
  2785         }
  2785         }