COIN-OR::LEMON - Graph Library

Changeset 1429:4283998fb2be in lemon-0.x


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

Able to read edge from undirected edgeset
Graph reader and graph writer can resolve items by id.

It makes possible:

GraphReader?<Graph> reader(std::cin, graph);

reader.readNodeMap....

NewEdgeSetAdaptor?<Graph> edgeset(graph);
UndirEdgeSetReader?<Graph> unir_edgeset_reader(reader, edgeset, reader);

reader.run();

It reads the graph and an additional edgeset in to the edgeset.

Location:
src/lemon
Files:
6 edited

Legend:

Unmodified
Added
Removed
  • src/lemon/bits/item_reader.h

    r1427 r1429  
    349349    void read(std::istream& is, Value& value) const {
    350350      char c;
    351       if (!(is >> c)) return;
     351      if (!(is >> std::ws >> c)) return;
    352352      is.putback(c);
    353353      switch (c) {
  • src/lemon/bits/item_writer.h

    r1415 r1429  
    178178  };
    179179
     180  template <>
     181  class DefaultWriter<std::string>
     182    : public QuotedStringWriter<std::string> {};
     183
    180184  template <typename Item>
    181185  class DefaultWriter<std::vector<Item> >
  • src/lemon/graph_reader.h

    r1421 r1429  
    299299      reader->run();
    300300    }
     301
     302    /// \brief Gives back the node by its id.
     303    ///
     304    /// It reads an id from the stream and gives back which node belongs to
     305    /// it. It is possible only if there was read an "id" named node map.
     306    Node readId(std::istream& is, Node) const {
     307      return nodeset_reader.readId(is, Node());
     308    }
     309
     310    /// \brief Gives back the edge by its id.
     311    ///
     312    /// It reads an id from the stream and gives back which edge belongs to
     313    /// it. It is possible only if there was read an "id" named edge map.
     314    Edge readId(std::istream& is, Edge) const {
     315      return edgeset_reader.readId(is, Edge());
     316    }
    301317
    302318  private:
     
    674690    ///
    675691    /// Add a new labeled edge reader for the reader.
     692    UndirGraphReader& readEdge(std::string name, Edge& edge) {
     693      undir_edge_reader.readEdge(name, edge);
     694    }
     695
     696    /// \brief Add a new labeled undirected edge reader for the reader.
     697    ///
     698    /// Add a new labeled undirected edge reader for the reader.
    676699    UndirGraphReader& readUndirEdge(std::string name, UndirEdge& edge) {
    677700      undir_edge_reader.readUndirEdge(name, edge);
     
    713736      reader->run();
    714737    }
     738
     739    /// \brief Gives back the node by its id.
     740    ///
     741    /// It reads an id from the stream and gives back which node belongs to
     742    /// it. It is possible only if there was read an "id" named node map.
     743    Node readId(std::istream& is, Node) const {
     744      return nodeset_reader.readId(is, Node());
     745    }
     746
     747    /// \brief Gives back the edge by its id.
     748    ///
     749    /// It reads an id from the stream and gives back which edge belongs to
     750    /// it. It is possible only if there was read an "id" named edge map.
     751    Edge readId(std::istream& is, Edge) const {
     752      return undir_edgeset_reader.readId(is, Edge());
     753    }
     754
     755    /// \brief Gives back the undirected edge by its id.
     756    ///
     757    /// It reads an id from the stream and gives back which undirected edge
     758    /// belongs to it. It is possible only if there was read an "id" named
     759    /// edge map.
     760    UndirEdge readId(std::istream& is, UndirEdge) const {
     761      return undir_edgeset_reader.readId(is, UndirEdge());
     762    }
     763   
    715764
    716765  private:
  • src/lemon/graph_writer.h

    r1421 r1429  
    238238      writer->run();
    239239    }
     240
     241    /// \brief Write the id of the given node.
     242    ///
     243    /// It writes the id of the given node. If there was written an "id"
     244    /// named node map then it will write the map value belongs to the node.
     245    void writeId(std::ostream& os, const Node& item) const {
     246      nodeset_writer.writeId(os, item);
     247    }
     248
     249    /// \brief Write the id of the given edge.
     250    ///
     251    /// It writes the id of the given edge. If there was written an "id"
     252    /// named edge map then it will write the map value belongs to the edge.
     253    void writeId(std::ostream& os, const Edge& item) const {
     254      edgeset_writer.writeId(os, item);
     255    }
    240256
    241257  private:
     
    548564    ///
    549565    /// Add a new labeled edge writer for the writer.
     566    UndirGraphWriter& writeEdge(std::string name, const Edge& edge) {
     567      undir_edge_writer.writeEdge(name, edge);
     568    }
     569
     570    /// \brief Add a new labeled undirected edge writer for the writer.
     571    ///
     572    /// Add a new labeled undirected edge writer for the writer.
    550573    UndirGraphWriter& writeUndirEdge(std::string name, const UndirEdge& edge) {
    551574      undir_edge_writer.writeUndirEdge(name, edge);
     
    587610      writer->run();
    588611    }
     612
     613    /// \brief Write the id of the given node.
     614    ///
     615    /// It writes the id of the given node. If there was written an "id"
     616    /// named node map then it will write the map value belongs to the node.
     617    void writeId(std::ostream& os, const Node& item) const {
     618      nodeset_writer.writeId(os, item);
     619    }
     620
     621    /// \brief Write the id of the given edge.
     622    ///
     623    /// It writes the id of the given edge. If there was written an "id"
     624    /// named edge map then it will write the map value belongs to the edge.
     625    void writeId(std::ostream& os, const Edge& item) const {
     626      undir_edgeset_writer.writeId(os, item);
     627    }
     628
     629    /// \brief Write the id of the given undirected edge.
     630    ///
     631    /// It writes the id of the given undirected edge. If there was written
     632    /// an "id" named edge map then it will write the map value belongs to
     633    /// the edge.
     634    void writeId(std::ostream& os, const UndirEdge& item) const {
     635      undir_edgeset_writer.writeId(os, item);
     636    }
     637
    589638
    590639  private:
  • src/lemon/lemon_reader.h

    r1427 r1429  
    546546
    547547      virtual Item read(std::istream& is) const {
    548         return boxedIdReader.readId(is);
     548        return boxedIdReader.readId(is, Item());
    549549      }
    550550    };
     
    598598    typedef _Graph Graph;
    599599    typedef _Traits Traits;
    600     typedef typename Graph::Node Item;
     600    typedef typename Graph::Node Node;
    601601    typedef typename Traits::Skipper DefaultSkipper;
    602602
     
    653653    NodeSetReader& readNodeMap(std::string name, Map& map,
    654654                               const Reader& reader = Reader()) {
    655       return _readMap<
    656         typename Traits::template Reader<typename Map::Value>, Map,
    657         typename SmartParameter<Map>::Type>(name, map, reader);
     655      return _readMap<Reader, Map, typename SmartParameter<Map>::Type>
     656        (name, map, reader);
    658657    }
    659658
     
    661660    NodeSetReader& readNodeMap(std::string name, const Map& map,
    662661                               const Reader& reader = Reader()) {
    663       return _readMap<
    664         typename Traits::template Reader<typename Map::Value>, Map,
    665         typename SmartParameter<Map>::Type>(name, map, reader);
     662      return _readMap<Reader, Map, typename SmartParameter<Map>::Type>
     663        (name, map, reader);
    666664    }
    667665
     
    677675      }
    678676      readers.insert(
    679         make_pair(name, new MapReader<Item, Map, Reader>(map, reader)));
     677        make_pair(name, new MapReader<Node, Map, Reader>(map, reader)));
    680678      return *this;
    681679    }
     
    694692        throw IOParameterError(msg.message());
    695693      }
    696       readers.insert(make_pair(name, new SkipReader<Item, Reader>(reader)));
     694      readers.insert(make_pair(name, new SkipReader<Node, Reader>(reader)));
    697695      return *this;
    698696    }
     
    717715    /// It reads the content of the section.
    718716    virtual void read(std::istream& is) {
    719       std::vector<ReaderBase<Item>* > index;
     717      std::vector<ReaderBase<Node>* > index;
    720718      std::string line;
    721719
     
    735733      }
    736734      while (getline(is, line)) {       
    737         typename Graph::Node node = graph.addNode();
     735        Node node = graph.addNode();
    738736        std::istringstream ls(line);
    739737        for (int i = 0; i < (int)index.size(); ++i) {
     
    757755    /// It reads an id from the stream and gives back which node belongs to
    758756    /// it. It is possible only if there was read an "id" named map.
    759     Item readId(std::istream& is) const {
     757    Node readId(std::istream& is, Node = Node()) const {
    760758      return inverter->read(is);
    761759    }
     
    763761  private:
    764762
    765     typedef std::map<std::string, ReaderBase<Item>*> MapReaders;
     763    typedef std::map<std::string, ReaderBase<Node>*> MapReaders;
    766764    MapReaders readers;
    767765   
    768766    typename SmartReference<Graph>::Type graph;   
    769767    std::string id;
    770     SkipReader<Item, DefaultSkipper> skipper;
    771 
    772     std::auto_ptr<InverterBase<Item> > inverter;
     768    SkipReader<Node, DefaultSkipper> skipper;
     769
     770    std::auto_ptr<InverterBase<Node> > inverter;
    773771  };
    774772
     
    802800    typedef _Graph Graph;
    803801    typedef _Traits Traits;
    804     typedef typename Graph::Edge Item;
     802    typedef typename Graph::Node Node;
     803    typedef typename Graph::Edge Edge;
    805804    typedef typename Traits::Skipper DefaultSkipper;
    806805
     
    820819                  const DefaultSkipper& _skipper = DefaultSkipper())
    821820      : Parent(_reader), graph(_graph), id(_id), skipper(_skipper),
    822         nodeIdReader(new IdReader<typename Graph::Node, NodeIdReader>
    823                      (_nodeIdReader)) {}
     821        nodeIdReader(new IdReader<Node, NodeIdReader>(_nodeIdReader)) {}
    824822
    825823    /// \brief Destructor.
     
    862860    EdgeSetReader& readEdgeMap(std::string name, Map& map,
    863861                           const Reader& reader = Reader()) {
    864       return _readMap<
    865         typename Traits::template Reader<typename Map::Value>, Map,
     862      return _readMap<Reader, Map,
    866863        typename SmartParameter<Map>::Type>(name, map, reader);
    867864    }
     
    870867    EdgeSetReader& readEdgeMap(std::string name, const Map& map,
    871868                               const Reader& reader = Reader()) {
    872       return _readMap<
    873         typename Traits::template Reader<typename Map::Value>, Map,
     869      return _readMap<Reader, Map,
    874870        typename SmartParameter<Map>::Type>(name, map, reader);
    875871    }
     
    886882      }
    887883      readers.insert(
    888         make_pair(name, new MapReader<Item, Map, Reader>(map, reader)));
     884        make_pair(name, new MapReader<Edge, Map, Reader>(map, reader)));
    889885      return *this;
    890886    }
     
    903899        throw IOParameterError(msg.message());
    904900      }
    905       readers.insert(make_pair(name, new SkipReader<Item, Reader>(reader)));
     901      readers.insert(make_pair(name, new SkipReader<Edge, Reader>(reader)));
    906902      return *this;
    907903    }
     
    926922    /// It reads the content of the section.
    927923    virtual void read(std::istream& is) {
    928       std::vector<ReaderBase<Item>* > index;
     924      std::vector<ReaderBase<Edge>* > index;
    929925      std::string line;
    930926
     
    945941      while (getline(is, line)) {       
    946942        std::istringstream ls(line);
    947         typename Graph::Node from = nodeIdReader->read(ls);
    948         typename Graph::Node to = nodeIdReader->read(ls);
    949         typename Graph::Edge edge = graph.addEdge(from, to);
     943        Node from = nodeIdReader->read(ls);
     944        Node to = nodeIdReader->read(ls);
     945        Edge edge = graph.addEdge(from, to);
    950946        for (int i = 0; i < (int)index.size(); ++i) {
    951947          index[i]->read(ls, edge);
     
    968964    /// It reads an id from the stream and gives back which edge belongs to
    969965    /// it. It is possible only if there was read an "id" named map.
    970     Item readId(std::istream& is) const {
     966    Edge readId(std::istream& is, Edge = Edge()) const {
    971967      return inverter->read(is);
    972968    }
     
    974970  private:
    975971
    976     typedef std::map<std::string, ReaderBase<Item>*> MapReaders;
     972    typedef std::map<std::string, ReaderBase<Edge>*> MapReaders;
    977973    MapReaders readers;
    978974   
    979975    typename SmartReference<Graph>::Type graph;   
    980976    std::string id;
    981     SkipReader<Item, DefaultSkipper> skipper;
    982 
    983     std::auto_ptr<InverterBase<Item> > inverter;
    984     std::auto_ptr<IdReaderBase<typename Graph::Node> > nodeIdReader;
     977    SkipReader<Edge, DefaultSkipper> skipper;
     978
     979    std::auto_ptr<InverterBase<Edge> > inverter;
     980    std::auto_ptr<IdReaderBase<Node> > nodeIdReader;
    985981  };
    986982
     
    10191015    typedef _Graph Graph;
    10201016    typedef _Traits Traits;
    1021     typedef typename Graph::UndirEdge Item;
     1017    typedef typename Graph::Node Node;
     1018    typedef typename Graph::Edge Edge;
     1019    typedef typename Graph::UndirEdge UndirEdge;
    10221020    typedef typename Traits::Skipper DefaultSkipper;
    10231021
     
    10371035                       const DefaultSkipper& _skipper = DefaultSkipper())
    10381036      : Parent(_reader), graph(_graph), id(_id), skipper(_skipper),
    1039         nodeIdReader(new IdReader<typename Graph::Node, NodeIdReader>
    1040                      (_nodeIdReader)) {}
     1037        nodeIdReader(new IdReader<Node, NodeIdReader>(_nodeIdReader)) {}
    10411038
    10421039    /// \brief Destructor.
     
    11011098      }
    11021099      readers.insert(
    1103         make_pair(name, new MapReader<Item, Map, Reader>(map, reader)));
     1100        make_pair(name, new MapReader<UndirEdge, Map, Reader>(map, reader)));
    11041101      return *this;
    11051102    }
     
    11181115        throw IOParameterError(msg.message());
    11191116      }
    1120       readers.insert(make_pair(name, new SkipReader<Item, Reader>(reader)));
     1117      readers.insert(make_pair(name,
     1118                               new SkipReader<UndirEdge, Reader>(reader)));
    11211119      return *this;
    11221120    }
     
    12001198    /// It reads the content of the section.
    12011199    virtual void read(std::istream& is) {
    1202       std::vector<ReaderBase<Item>* > index;
     1200      std::vector<ReaderBase<UndirEdge>* > index;
    12031201      std::string line;
    12041202
     
    12191217      while (getline(is, line)) {       
    12201218        std::istringstream ls(line);
    1221         typename Graph::Node from = nodeIdReader->read(ls);
    1222         typename Graph::Node to = nodeIdReader->read(ls);
    1223         typename Graph::UndirEdge edge = graph.addEdge(from, to);
     1219        Node from = nodeIdReader->read(ls);
     1220        Node to = nodeIdReader->read(ls);
     1221        UndirEdge edge = graph.addEdge(from, to);
    12241222        for (int i = 0; i < (int)index.size(); ++i) {
    12251223          index[i]->read(ls, edge);
     
    12421240    /// It reads an id from the stream and gives back which undirected edge
    12431241    /// belongs to it. It is possible only if there was read an "id" named map.
    1244     Item readId(std::istream& is) const {
     1242    UndirEdge readId(std::istream& is, UndirEdge = UndirEdge()) const {
    12451243      return inverter->read(is);
    12461244    }
    12471245
    1248   private:
    1249 
    1250     typedef std::map<std::string, ReaderBase<Item>*> MapReaders;
     1246    /// \brief Gives back the directed edge by its id.
     1247    ///
     1248    /// It reads an id from the stream and gives back which directed edge
     1249    /// belongs to it. The directed edge id is the \c '+' or \c '-' character
     1250    /// and the undirected edge id. It is possible only if there was read
     1251    /// an "id" named map.
     1252    Edge readId(std::istream& is, Edge = Edge()) const {
     1253      char c;
     1254      is >> c;
     1255      UndirEdge undirEdge = inverter->read(is);
     1256      if (c == '+') {
     1257        return graph.edgeWithSource(undirEdge, graph.source(undirEdge));
     1258      } else if (c == '-') {
     1259        return graph.edgeWithSource(undirEdge, graph.target(undirEdge));
     1260      } else {
     1261        throw DataFormatError("Wrong id format for edge "
     1262                              "in undirected edgeset");
     1263      }
     1264    }
     1265
     1266  private:
     1267
     1268    typedef std::map<std::string, ReaderBase<UndirEdge>*> MapReaders;
    12511269    MapReaders readers;
    12521270   
    12531271    typename SmartReference<Graph>::Type graph;   
    12541272    std::string id;
    1255     SkipReader<Item, DefaultSkipper> skipper;
    1256 
    1257     std::auto_ptr<InverterBase<Item> > inverter;
    1258     std::auto_ptr<IdReaderBase<typename Graph::Node> > nodeIdReader;
     1273    SkipReader<UndirEdge, DefaultSkipper> skipper;
     1274
     1275    std::auto_ptr<InverterBase<UndirEdge> > inverter;
     1276    std::auto_ptr<IdReaderBase<Node> > nodeIdReader;
    12591277  };
    12601278
     
    12731291    typedef CommonSectionReaderBase Parent;
    12741292    typedef _Graph Graph;
    1275     typedef typename Graph::Node Item;
     1293    typedef typename Graph::Node Node;
    12761294  public:
    12771295   
     
    13021320    ///
    13031321    /// Add a node reader command for the NodeReader.
    1304     void readNode(const std::string& name, Item& item) {
     1322    void readNode(const std::string& name, Node& item) {
    13051323      if (readers.find(name) != readers.end()) {
    13061324        ErrorMessage msg;
     
    13351353        std::string id;
    13361354        ls >> id;
    1337         typename ItemReaders::iterator it = readers.find(id);
     1355        typename NodeReaders::iterator it = readers.find(id);
    13381356        if (it != readers.end()) {
    13391357          *(it->second) = idReader->read(ls);
     
    13461364    std::string id;
    13471365
    1348     typedef std::map<std::string, Item*> ItemReaders;
    1349     ItemReaders readers;
    1350     std::auto_ptr<IdReaderBase<Item> > idReader;
     1366    typedef std::map<std::string, Node*> NodeReaders;
     1367    NodeReaders readers;
     1368    std::auto_ptr<IdReaderBase<Node> > idReader;
    13511369  };
    13521370
     
    13651383    typedef CommonSectionReaderBase Parent;
    13661384    typedef _Graph Graph;
    1367     typedef typename Graph::Edge Item;
     1385    typedef typename Graph::Edge Edge;
    13681386  public:
    13691387   
     
    13931411    ///
    13941412    /// Add an edge reader command for the EdgeReader.
    1395     void readEdge(const std::string& name, Item& item) {
     1413    void readEdge(const std::string& name, Edge& item) {
    13961414      if (readers.find(name) != readers.end()) {
    13971415        ErrorMessage msg;
     
    14261444        std::string id;
    14271445        ls >> id;
    1428         typename ItemReaders::iterator it = readers.find(id);
     1446        typename EdgeReaders::iterator it = readers.find(id);
    14291447        if (it != readers.end()) {
    14301448          *(it->second) = idReader->read(ls);
     
    14371455    std::string id;
    14381456
    1439     typedef std::map<std::string, Item*> ItemReaders;
    1440     ItemReaders readers;
    1441     std::auto_ptr<IdReaderBase<Item> > idReader;
     1457    typedef std::map<std::string, Edge*> EdgeReaders;
     1458    EdgeReaders readers;
     1459    std::auto_ptr<IdReaderBase<Edge> > idReader;
    14421460  };
    14431461
     
    14561474    typedef CommonSectionReaderBase Parent;
    14571475    typedef _Graph Graph;
    1458     typedef typename Graph::UndirEdge Item;
     1476    typedef typename Graph::Edge Edge;
     1477    typedef typename Graph::UndirEdge UndirEdge;
    14591478  public:
    14601479   
     
    14701489               const std::string& _id = std::string())
    14711490      : Parent(_reader), id(_id),
    1472         idReader(new IdReader<typename Graph::UndirEdge, _IdReader>(_idReader))
     1491        undirEdgeIdReader(new IdReader<UndirEdge, _IdReader>(_idReader)),
     1492        edgeIdReader(new IdReader<Edge, _IdReader>(_idReader))
    14731493    {}
    14741494
     
    14861506    ///
    14871507    /// Add an undirected edge reader command for the UndirEdgeReader.
    1488     void readUndirEdge(const std::string& name, Item& item) {
    1489       if (readers.find(name) != readers.end()) {
     1508    void readUndirEdge(const std::string& name, UndirEdge& item) {
     1509      if (undirEdgeReaders.find(name) != undirEdgeReaders.end()) {
     1510        ErrorMessage msg;
     1511        msg << "Multiple read rule for undirected edge: " << name;
     1512        throw IOParameterError(msg.message());
     1513      }
     1514      undirEdgeReaders.insert(make_pair(name, &item));
     1515    }
     1516
     1517    /// \brief Add an edge reader command for the UndirEdgeReader.
     1518    ///
     1519    /// Add an edge reader command for the UndirEdgeReader.
     1520    void readEdge(const std::string& name, Edge& item) {
     1521      if (edgeReaders.find(name) != edgeReaders.end()) {
    14901522        ErrorMessage msg;
    14911523        msg << "Multiple read rule for edge: " << name;
    14921524        throw IOParameterError(msg.message());
    14931525      }
    1494       readers.insert(make_pair(name, &item));
     1526      edgeReaders.insert(make_pair(name, &item));
    14951527    }
    14961528
     
    15071539      std::string name;
    15081540      ls >> command >> name;
    1509       return command == "@edges" && name == id;
     1541      return command == "@undiredges" && name == id;
    15101542    }
    15111543
     
    15191551        std::string id;
    15201552        ls >> id;
    1521         typename ItemReaders::iterator it = readers.find(id);
    1522         if (it != readers.end()) {
    1523           *(it->second) = idReader->read(ls);
    1524         }       
     1553        {
     1554          typename UndirEdgeReaders::iterator it = undirEdgeReaders.find(id);
     1555          if (it != undirEdgeReaders.end()) {
     1556            *(it->second) = undirEdgeIdReader->read(ls);
     1557            break;
     1558          }     
     1559        } {
     1560          typename EdgeReaders::iterator it = edgeReaders.find(id);
     1561          if (it != edgeReaders.end()) {
     1562            *(it->second) = edgeIdReader->read(ls);
     1563            break;
     1564          }     
     1565        }
    15251566      }
    15261567    }
     
    15301571    std::string id;
    15311572
    1532     typedef std::map<std::string, Item*> ItemReaders;
    1533     ItemReaders readers;
    1534     std::auto_ptr<IdReaderBase<Item> > idReader;
     1573    typedef std::map<std::string, UndirEdge*> UndirEdgeReaders;
     1574    UndirEdgeReaders undirEdgeReaders;
     1575    std::auto_ptr<IdReaderBase<UndirEdge> > undirEdgeIdReader;
     1576
     1577    typedef std::map<std::string, Edge*> EdgeReaders;
     1578    EdgeReaders edgeReaders;
     1579    std::auto_ptr<IdReaderBase<Edge> > edgeIdReader;
    15351580  };
    15361581
  • src/lemon/lemon_writer.h

    r1421 r1429  
    244244
    245245      virtual void write(std::ostream& os, const Item& item) const {
    246         return idWriter.writeId(os, item);
     246        idWriter.writeId(os, item);
    247247      }
    248248    };
     
    274274    typedef _Graph Graph;
    275275    typedef _Traits Traits;
    276     typedef typename Graph::Node Item;
     276    typedef typename Graph::Node Node;
    277277
    278278    /// \brief Constructor.
     
    320320                            const Writer& writer = Writer()) {
    321321      writers.push_back(
    322         make_pair(name, new MapWriter<Item, Map, Writer>(map, writer)));
     322        make_pair(name, new MapWriter<Node, Map, Writer>(map, writer)));
    323323      return *this;
    324324    }
     
    380380    /// Otherwise if the \c forceId parameter was true it will write
    381381    /// its id in the graph.
    382     void writeId(std::ostream& os, const Item& item) const {
     382    void writeId(std::ostream& os, const Node& item) const {
    383383      if (forceIdMap) {
    384384        os << graph.id(item);
     
    390390  private:
    391391
    392     typedef std::vector<std::pair<std::string, WriterBase<Item>*> > MapWriters;
     392    typedef std::vector<std::pair<std::string, WriterBase<Node>*> > MapWriters;
    393393    MapWriters writers;
    394394
    395     WriterBase<Item>* idMap;
     395    WriterBase<Node>* idMap;
    396396    bool forceIdMap;
    397397   
     
    431431    typedef _Graph Graph;
    432432    typedef _Traits Traits;
    433     typedef typename Graph::Edge Item;
     433    typedef typename Graph::Node Node;
     434    typedef typename Graph::Edge Edge;
    434435
    435436    /// \brief Constructor.
     
    447448      : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
    448449        graph(_graph), id(_id),
    449         nodeIdWriter(new IdWriter<typename Graph::Node, NodeIdWriter>
    450                      (_nodeIdWriter)) {}
     450        nodeIdWriter(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter)) {}
    451451
    452452    /// \brief Destructor.
     
    482482                            const Writer& writer = Writer()) {
    483483      writers.push_back(
    484         make_pair(name, new MapWriter<Item, Map, Writer>(map, writer)));
     484        make_pair(name, new MapWriter<Edge, Map, Writer>(map, writer)));
    485485      return *this;
    486486    }
     
    547547    /// Otherwise if the \c forceId parameter was true it will write
    548548    /// its id in the graph.
    549     void writeId(std::ostream& os, const Item& item) const {
     549    void writeId(std::ostream& os, const Edge& item) const {
    550550      if (forceIdMap) {
    551551        os << graph.id(item);
     
    557557  private:
    558558
    559     typedef std::vector<std::pair<std::string, WriterBase<Item>*> > MapWriters;
     559    typedef std::vector<std::pair<std::string, WriterBase<Edge>*> > MapWriters;
    560560    MapWriters writers;
    561561
    562     WriterBase<Item>* idMap;
     562    WriterBase<Edge>* idMap;
    563563    bool forceIdMap;
    564564   
     
    566566    std::string id;
    567567
    568     std::auto_ptr<IdWriterBase<typename Graph::Node> > nodeIdWriter;
     568    std::auto_ptr<IdWriterBase<Node> > nodeIdWriter;
    569569  };
    570570
     
    605605    typedef _Graph Graph;
    606606    typedef _Traits Traits;
    607     typedef typename Graph::UndirEdge Item;
     607    typedef typename Graph::Node Node;
     608    typedef typename Graph::Edge Edge;
     609    typedef typename Graph::UndirEdge UndirEdge;
    608610
    609611    /// \brief Constructor.
     
    621623      : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
    622624        graph(_graph), id(_id),
    623         nodeIdWriter(new IdWriter<typename Graph::Node, NodeIdWriter>
    624                      (_nodeIdWriter)) {}
     625        nodeIdWriter(new IdWriter<Node, NodeIdWriter>(_nodeIdWriter)) {}
    625626
    626627    /// \brief Destructor.
     
    656657                                          const Writer& writer = Writer()) {
    657658      writers.push_back(
    658         make_pair(name, new MapWriter<Item, Map, Writer>(map, writer)));
     659        make_pair(name, new MapWriter<UndirEdge, Map, Writer>(map, writer)));
    659660      return *this;
    660661    }
     
    743744    /// undirected edge. Otherwise if the \c forceId parameter was true it
    744745    /// will write its id in the graph.
    745     void writeId(std::ostream& os, const Item& item) const {
     746    void writeId(std::ostream& os, const UndirEdge& item) const {
    746747      if (forceIdMap) {
    747748        os << graph.id(item);
     
    751752    }
    752753
    753   private:
    754 
    755     typedef std::vector<std::pair<std::string, WriterBase<Item>*> > MapWriters;
     754    /// \brief Write the id of the given edge.
     755    ///
     756    /// It writes the id of the given edge. If there was written
     757    /// an "id" named map then it will write the map value belongs to the
     758    /// edge. Otherwise if the \c forceId parameter was true it
     759    /// will write its id in the graph. If the edge is forward map
     760    /// then its prefix character is \c '+' elsewhere \c '-'.
     761    void writeId(std::ostream& os, const Edge& item) const {
     762      if (graph.forward(item)) {
     763        os << "+ ";
     764      } else {
     765        os << "- ";
     766      }
     767      if (forceIdMap) {
     768        os << graph.id(item);
     769      } else {
     770        idMap->write(os, item);
     771      }
     772    }
     773
     774  private:
     775
     776    typedef std::vector<std::pair<std::string,
     777                                  WriterBase<UndirEdge>*> > MapWriters;
    756778    MapWriters writers;
    757779
    758     WriterBase<Item>* idMap;
     780    WriterBase<UndirEdge>* idMap;
    759781    bool forceIdMap;
    760782   
     
    762784    std::string id;
    763785
    764     std::auto_ptr<IdWriterBase<typename Graph::Node> > nodeIdWriter;
     786    std::auto_ptr<IdWriterBase<Node> > nodeIdWriter;
    765787  };
    766788
     
    779801    typedef CommonSectionWriterBase Parent;
    780802    typedef _Graph Graph;
    781     typedef typename Graph::Node Item;
     803    typedef typename Graph::Node Node;
    782804  public:
    783805   
     
    807829    ///
    808830    /// Add a node writer command for the NodeWriter.
    809     void writeNode(const std::string& name, const Item& item) {
     831    void writeNode(const std::string& name, const Node& item) {
    810832      writers.push_back(make_pair(name, &item));
    811833    }
     
    836858    std::string id;
    837859
    838     typedef std::vector<std::pair<std::string, const Item*> > ItemWriters;
    839     ItemWriters writers;
    840     std::auto_ptr<IdWriterBase<Item> > idWriter;
     860    typedef std::vector<std::pair<std::string, const Node*> > NodeWriters;
     861    NodeWriters writers;
     862    std::auto_ptr<IdWriterBase<Node> > idWriter;
    841863  };
    842864
     
    855877    typedef CommonSectionWriterBase Parent;
    856878    typedef _Graph Graph;
    857     typedef typename Graph::Edge Item;
     879    typedef typename Graph::Edge Edge;
    858880  public:
    859881   
     
    882904    ///
    883905    /// Add an edge writer command for the EdgeWriter.
    884     void writeEdge(const std::string& name, const Item& item) {
     906    void writeEdge(const std::string& name, const Edge& item) {
    885907      writers.push_back(make_pair(name, &item));
    886908    }
     
    911933    std::string id;
    912934
    913     typedef std::vector<std::pair<std::string, const Item*> > ItemWriters;
    914     ItemWriters writers;
    915 
    916     std::auto_ptr<IdWriterBase<Item> > idWriter;
     935    typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters;
     936    EdgeWriters writers;
     937
     938    std::auto_ptr<IdWriterBase<Edge> > idWriter;
    917939  };
    918940
     
    931953    typedef CommonSectionWriterBase Parent;
    932954    typedef _Graph Graph;
    933     typedef typename Graph::UndirEdge Item;
     955    typedef typename Graph::Node Node;
     956    typedef typename Graph::Edge Edge;
     957    typedef typename Graph::UndirEdge UndirEdge;
    934958  public:
    935959   
     
    944968               const std::string& _id = std::string())
    945969      : Parent(_writer), id(_id),
    946         idWriter(new IdWriter<typename Graph::UndirEdge, _IdWriter>
    947                  (_idWriter)) {}
     970        undirEdgeIdWriter(new IdWriter<UndirEdge, _IdWriter>(_idWriter)),
     971        edgeIdWriter(new IdWriter<Edge, _IdWriter>(_idWriter)) {}
    948972
    949973    /// \brief Destructor.
     
    957981  public:
    958982
     983    /// \brief Add an edge writer command for the UndirEdgeWriter.
     984    ///
     985    /// Add an edge writer command for the UndirEdgeWriter.
     986    void writeEdge(const std::string& name, const Edge& item) {
     987      edgeWriters.push_back(make_pair(name, &item));
     988    }
     989
    959990    /// \brief Add an undirected edge writer command for the UndirEdgeWriter.
    960991    ///
    961     /// Add an edge writer command for the UndirEdgeWriter.
    962     void writeUndirEdge(const std::string& name, const Item& item) {
    963       writers.push_back(make_pair(name, &item));
     992    /// Add an undirected edge writer command for the UndirEdgeWriter.
     993    void writeUndirEdge(const std::string& name, const UndirEdge& item) {
     994      undirEdgeWriters.push_back(make_pair(name, &item));
    964995    }
    965996
     
    9711002    /// and the header line's id and the writer's id are the same.
    9721003    virtual std::string header() {
    973       return "@edges " + id;
     1004      return "@undiredges " + id;
    9741005    }
    9751006
     
    9781009    /// Write the content of the section.
    9791010    virtual void write(std::ostream& os) {
    980       for (int i = 0; i < (int)writers.size(); ++i) {
    981         os << writers[i].first << ' ';
    982         idWriter->write(os, *(writers[i].second));
     1011      for (int i = 0; i < (int)undirEdgeWriters.size(); ++i) {
     1012        os << undirEdgeWriters[i].first << ' ';
     1013        undirEdgeIdWriter->write(os, *(undirEdgeWriters[i].second));
    9831014        os << std::endl;
    9841015      }
     1016      for (int i = 0; i < (int)edgeWriters.size(); ++i) {
     1017        os << edgeWriters[i].first << ' ';
     1018        edgeIdWriter->write(os, *(edgeWriters[i].second));
     1019        os << std::endl;
     1020      }
    9851021    }
    9861022   
     
    9891025    std::string id;
    9901026
    991     typedef std::vector<std::pair<std::string, const Item*> > ItemWriters;
    992     ItemWriters writers;
    993 
    994     std::auto_ptr<IdWriterBase<Item> > idWriter;
     1027    typedef std::vector<std::pair<std::string,
     1028                                  const UndirEdge*> > UndirEdgeWriters;
     1029    UndirEdgeWriters undirEdgeWriters;
     1030    std::auto_ptr<IdWriterBase<UndirEdge> > undirEdgeIdWriter;
     1031
     1032    typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters;
     1033    EdgeWriters edgeWriters;
     1034    std::auto_ptr<IdWriterBase<Edge> > edgeIdWriter;
     1035
    9951036  };
    9961037
Note: See TracChangeset for help on using the changeset viewer.