COIN-OR::LEMON - Graph Library

Changeset 1901:723b2b81d900 in lemon-0.x for lemon/lemon_writer.h


Ignore:
Timestamp:
01/24/06 17:07:38 (14 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2476
Message:

Lemon Graph Format uses label instead of id named map.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/lemon_writer.h

    r1875 r1901  
    4747   
    4848    template <typename Item>
    49     class ItemIdWriter {
     49    class ItemLabelWriter {
    5050    public:
    5151
    52       bool isIdWriter() { return true; }
    53 
    54       void writeId(std::ostream&, const Item&) {}
     52      bool isLabelWriter() { return true; }
     53
     54      void writeLabel(std::ostream&, const Item&) {}
    5555     
    56       template <class _ItemIdWriter>
     56      template <class _ItemLabelWriter>
    5757      struct Constraints {
    5858        void constraints() {
    59           bool b = writer.isIdWriter();
     59          bool b = writer.isLabelWriter();
    6060          ignore_unused_variable_warning(b);
    61           writer.writeId(os, item);
     61          writer.writeLabel(os, item);
    6262        }
    63         _ItemIdWriter& writer;
     63        _ItemLabelWriter& writer;
    6464        std::ostream& os;
    6565        const Item& item;
     
    226226
    227227    template <typename _Item>
    228     class IdWriterBase {
     228    class LabelWriterBase {
    229229    public:
    230230      typedef _Item Item;
    231       virtual ~IdWriterBase() {}
     231      virtual ~LabelWriterBase() {}
    232232      virtual void write(std::ostream&, const Item&) const = 0;
    233       virtual bool isIdWriter() const = 0;
    234     };
    235 
    236     template <typename _Item, typename _BoxedIdWriter>
    237     class IdWriter : public IdWriterBase<_Item> {
     233      virtual bool isLabelWriter() const = 0;
     234    };
     235
     236    template <typename _Item, typename _BoxedLabelWriter>
     237    class LabelWriter : public LabelWriterBase<_Item> {
    238238    public:
    239239      typedef _Item Item;
    240       typedef _BoxedIdWriter BoxedIdWriter;
    241 
    242       const BoxedIdWriter& idWriter;
    243 
    244       IdWriter(const BoxedIdWriter& _idWriter)
    245         : idWriter(_idWriter) {}
     240      typedef _BoxedLabelWriter BoxedLabelWriter;
     241
     242      const BoxedLabelWriter& labelWriter;
     243
     244      LabelWriter(const BoxedLabelWriter& _labelWriter)
     245        : labelWriter(_labelWriter) {}
    246246
    247247      virtual void write(std::ostream& os, const Item& item) const {
    248         idWriter.writeId(os, item);
    249       }
    250 
    251       virtual bool isIdWriter() const {
    252         return idWriter.isIdWriter();
     248        labelWriter.writeLabel(os, item);
     249      }
     250
     251      virtual bool isLabelWriter() const {
     252        return labelWriter.isLabelWriter();
    253253      }
    254254    };
     
    375375  ///
    376376  /// The lemon format can store multiple graph nodesets with several maps.
    377   /// The nodeset section's header line is \c \@nodeset \c nodeset_id, but the
    378   /// \c nodeset_id may be empty.
     377  /// The nodeset section's header line is \c \@nodeset \c nodeset_name, but
     378  /// the \c nodeset_name may be empty.
    379379  ///
    380380  /// The first line of the section contains the names of the maps separated
     
    382382  /// contains the mapped values for each map.
    383383  ///
    384   /// If the nodeset contains an \c "id" named map then it will be regarded
    385   /// as id map. This map should contain only unique values and when the
    386   /// \c writeId() member will be called with a node it will write it's id.
    387   /// Otherwise if the \c _forceIdMap constructor parameter is true then
    388   /// the id map will be the id in the graph.
     384  /// If the nodeset contains an \c "label" named map then it will be regarded
     385  /// as label map. This map should contain only unique values and when the
     386  /// \c writeLabel() member will be called with a node it will write it's
     387  /// label. Otherwise if the \c _forceLabelMap constructor parameter is true
     388  /// then the label map will be the id in the graph.
    389389  ///
    390390  /// \relates LemonWriter
     
    401401    ///
    402402    /// Constructor for NodeSetWriter. It creates the NodeSetWriter and
    403     /// attach it into the given LemonWriter. If the \c _forceIdMap
    404     /// parameter is true then the writer will write own id map when
    405     /// the user does not give "id" named map.
     403    /// attach it into the given LemonWriter. If the \c _forceLabelMap
     404    /// parameter is true then the writer will write own label map when
     405    /// the user does not give "label" named map.
    406406    NodeSetWriter(LemonWriter& _writer, const Graph& _graph,
    407                   const std::string& _id = std::string(),
    408                   bool _forceIdMap = true)
    409       : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
    410         graph(_graph), id(_id) {}
     407                  const std::string& _name = std::string(),
     408                  bool _forceLabelMap = true)
     409      : Parent(_writer), labelMap(0), forceLabelMap(_forceLabelMap),
     410        graph(_graph), name(_name) {}
    411411
    412412    /// \brief Destructor.
     
    455455    /// It gives back the header of the section.
    456456    virtual std::string header() {
    457       return "@nodeset " + id;
     457      return "@nodeset " + name;
    458458    }
    459459
     
    463463    virtual void write(std::ostream& os) {
    464464      for (int i = 0; i < (int)writers.size(); ++i) {
    465         if (writers[i].first == "id") {
    466           idMap = writers[i].second;
    467           forceIdMap = false;
     465        if (writers[i].first == "label" || (writers[i].first == "id" && labelMap == 0)) {
     466          labelMap = writers[i].second;
     467          forceLabelMap = false;
    468468          break;
    469469        }
    470470      }
    471       if (forceIdMap) {
    472         os << "id\t";
     471      if (forceLabelMap) {
     472        os << "label\t";
    473473      }
    474474      for (int i = 0; i < (int)writers.size(); ++i) {
     
    477477      os << std::endl;
    478478      for (typename Graph::NodeIt it(graph); it != INVALID; ++it) {
    479         if (forceIdMap) {
     479        if (forceLabelMap) {
    480480          os << graph.id(it) << '\t';
    481481        }
     
    490490  public:
    491491
    492     /// \brief Returns true if the nodeset can write the ids of the nodes.
    493     ///
    494     /// Returns true if the nodeset can write the ids of the nodes.
    495     /// It is possible only if an "id" named map was written or the
    496     /// \c _forceIdMap constructor parameter was true.
    497     bool isIdWriter() const {
    498       return idMap != 0 || forceIdMap;
    499     }
    500 
    501     /// \brief Write the id of the given node.
    502     ///
    503     /// It writes the id of the given node. If there was written an "id"
     492    /// \brief Returns true if the nodeset can write the labels of the nodes.
     493    ///
     494    /// Returns true if the nodeset can write the labels of the nodes.
     495    /// It is possible only if an "label" named map was written or the
     496    /// \c _forceLabelMap constructor parameter was true.
     497    bool isLabelWriter() const {
     498      return labelMap != 0 || forceLabelMap;
     499    }
     500
     501    /// \brief Write the label of the given node.
     502    ///
     503    /// It writes the label of the given node. If there was written an "label"
    504504    /// named map then it will write the map value belongs to the node.
    505     /// Otherwise if the \c forceId parameter was true it will write
    506     /// its id in the graph.
    507     void writeId(std::ostream& os, const Node& item) const {
    508       if (forceIdMap) {
     505    /// Otherwise if the \c forceLabel parameter was true it will write
     506    /// its label in the graph.
     507    void writeLabel(std::ostream& os, const Node& item) const {
     508      if (forceLabelMap) {
    509509        os << graph.id(item);
    510510      } else {
    511         idMap->write(os, item);
     511        labelMap->write(os, item);
    512512      }
    513513    }
     
    519519    MapWriters writers;
    520520
    521     _writer_bits::MapWriterBase<Node>* idMap;
    522     bool forceIdMap;
     521    _writer_bits::MapWriterBase<Node>* labelMap;
     522    bool forceLabelMap;
    523523   
    524524    const Graph& graph;   
    525     std::string id;
     525    std::string name;
    526526
    527527  };
     
    531531  ///
    532532  /// The lemon format can store multiple graph edgesets with several maps.
    533   /// The edgeset section's header line is \c \@edgeset \c edgeset_id, but the
    534   /// \c edgeset_id may be empty.
     533  /// The edgeset section's header line is \c \@edgeset \c edgeset_name, but
     534  /// the \c edgeset_name may be empty.
    535535  ///
    536536  /// The first line of the section contains the names of the maps separated
    537537  /// with white spaces. Each next lines describes a edge in the edgeset. The
    538   /// line contains the source and the target nodes' id and the mapped
     538  /// line contains the source and the target nodes' label and the mapped
    539539  /// values for each map.
    540540  ///
    541   /// If the edgeset contains an \c "id" named map then it will be regarded
    542   /// as id map. This map should contain only unique values and when the
    543   /// \c writeId() member will be called with an edge it will write it's id.
    544   /// Otherwise if the \c _forceIdMap constructor parameter is true then
    545   /// the id map will be the id in the graph.
    546   ///
    547   /// The edgeset writer needs a node id writer to identify which nodes
    548   /// have to be connected. If a NodeSetWriter can write the nodes' id,
     541  /// If the edgeset contains an \c "label" named map then it will be regarded
     542  /// as label map. This map should contain only unique values and when the
     543  /// \c writeLabel() member will be called with an edge it will write it's
     544  /// label. Otherwise if the \c _forceLabelMap constructor parameter is true
     545  /// then the label map will be the id in the graph.
     546  ///
     547  /// The edgeset writer needs a node label writer to identify which nodes
     548  /// have to be connected. If a NodeSetWriter can write the nodes' label,
    549549  /// it will be able to use with this class.
    550550  ///
     
    563563    ///
    564564    /// Constructor for EdgeSetWriter. It creates the EdgeSetWriter and
    565     /// attach it into the given LemonWriter. It will write node ids by
    566     /// the \c _nodeIdWriter. If the \c _forceIdMap parameter is true
    567     /// then the writer will write own id map if the user does not give
    568     /// "id" named map.
    569     template <typename NodeIdWriter>
     565    /// attach it into the given LemonWriter. It will write node labels by
     566    /// the \c _nodeLabelWriter. If the \c _forceLabelMap parameter is true
     567    /// then the writer will write own label map if the user does not give
     568    /// "label" named map.
     569    template <typename NodeLabelWriter>
    570570    EdgeSetWriter(LemonWriter& _writer, const Graph& _graph,
    571                   const NodeIdWriter& _nodeIdWriter,
    572                   const std::string& _id = std::string(),
    573                   bool _forceIdMap = true)
    574       : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
    575         graph(_graph), id(_id) {
    576       checkConcept<_writer_bits::ItemIdWriter<Node>, NodeIdWriter>();
    577       nodeIdWriter.reset(new _writer_bits::
    578                          IdWriter<Node, NodeIdWriter>(_nodeIdWriter));
     571                  const NodeLabelWriter& _nodeLabelWriter,
     572                  const std::string& _name = std::string(),
     573                  bool _forceLabelMap = true)
     574      : Parent(_writer), labelMap(0), forceLabelMap(_forceLabelMap),
     575        graph(_graph), name(_name) {
     576      checkConcept<_writer_bits::ItemLabelWriter<Node>, NodeLabelWriter>();
     577      nodeLabelWriter.reset(new _writer_bits::
     578                         LabelWriter<Node, NodeLabelWriter>(_nodeLabelWriter));
    579579    }
    580580
     
    624624    /// It gives back the header of the section.
    625625    virtual std::string header() {
    626       return "@edgeset " + id;
     626      return "@edgeset " + name;
    627627    }
    628628
     
    631631    /// Write the content of the section.
    632632    virtual void write(std::ostream& os) {
    633       if (!nodeIdWriter->isIdWriter()) {
    634         throw DataFormatError("Cannot find nodeset or ID map");
     633      if (!nodeLabelWriter->isLabelWriter()) {
     634        throw DataFormatError("Cannot find nodeset or label map");
    635635      }
    636636      for (int i = 0; i < (int)writers.size(); ++i) {
    637         if (writers[i].first == "id") {
    638           idMap = writers[i].second;
    639           forceIdMap = false;
     637        if (writers[i].first == "label" || (writers[i].first == "id" && labelMap == 0)) {
     638          labelMap = writers[i].second;
     639          forceLabelMap = false;
    640640          break;
    641641        }
    642642      }
    643643      os << "\t\t";
    644       if (forceIdMap) {
    645         os << "id\t";
     644      if (forceLabelMap) {
     645        os << "label\t";
    646646      }
    647647      for (int i = 0; i < (int)writers.size(); ++i) {
     
    650650      os << std::endl;
    651651      for (typename Graph::EdgeIt it(graph); it != INVALID; ++it) {
    652         nodeIdWriter->write(os, graph.source(it));
     652        nodeLabelWriter->write(os, graph.source(it));
    653653        os << '\t';
    654         nodeIdWriter->write(os, graph.target(it));
     654        nodeLabelWriter->write(os, graph.target(it));
    655655        os << '\t';
    656         if (forceIdMap) {
     656        if (forceLabelMap) {
    657657          os << graph.id(it) << '\t';
    658658        }
     
    667667  public:
    668668
    669     /// \brief Returns true if the edgeset can write the ids of the edges.
    670     ///
    671     /// Returns true if the edgeset can write the ids of the edges.
    672     /// It is possible only if an "id" named map was written or the
    673     /// \c _forceIdMap constructor parameter was true.
    674     bool isIdWriter() const {
    675       return forceIdMap || idMap != 0;
    676     }
    677 
    678     /// \brief Write the id of the given edge.
    679     ///
    680     /// It writes the id of the given edge. If there was written an "id"
     669    /// \brief Returns true if the edgeset can write the labels of the edges.
     670    ///
     671    /// Returns true if the edgeset can write the labels of the edges.
     672    /// It is possible only if an "label" named map was written or the
     673    /// \c _forceLabelMap constructor parameter was true.
     674    bool isLabelWriter() const {
     675      return forceLabelMap || labelMap != 0;
     676    }
     677
     678    /// \brief Write the label of the given edge.
     679    ///
     680    /// It writes the label of the given edge. If there was written an "label"
    681681    /// named map then it will write the map value belongs to the edge.
    682     /// Otherwise if the \c forceId parameter was true it will write
    683     /// its id in the graph.
    684     void writeId(std::ostream& os, const Edge& item) const {
    685       if (forceIdMap) {
     682    /// Otherwise if the \c forceLabel parameter was true it will write
     683    /// its label in the graph.
     684    void writeLabel(std::ostream& os, const Edge& item) const {
     685      if (forceLabelMap) {
    686686        os << graph.id(item);
    687687      } else {
    688         idMap->write(os, item);
     688        labelMap->write(os, item);
    689689      }
    690690    }
     
    696696    MapWriters writers;
    697697
    698     _writer_bits::MapWriterBase<Edge>* idMap;
    699     bool forceIdMap;
     698    _writer_bits::MapWriterBase<Edge>* labelMap;
     699    bool forceLabelMap;
    700700   
    701701    const Graph& graph;   
    702     std::string id;
    703 
    704     std::auto_ptr<_writer_bits::IdWriterBase<Node> > nodeIdWriter;
     702    std::string name;
     703
     704    std::auto_ptr<_writer_bits::LabelWriterBase<Node> > nodeLabelWriter;
    705705  };
    706706
     
    710710  /// The lemon format can store multiple undirected edgesets with several
    711711  /// maps. The undirected edgeset section's header line is \c \@undiredgeset
    712   /// \c undiredgeset_id, but the \c undiredgeset_id may be empty.
     712  /// \c undiredgeset_name, but the \c undiredgeset_name may be empty.
    713713  ///
    714714  /// The first line of the section contains the names of the maps separated
    715715  /// with white spaces. Each next lines describes an undirected edge in the
    716   /// edgeset. The line contains the two connected nodes' id and the mapped
     716  /// edgeset. The line contains the two connected nodes' label and the mapped
    717717  /// values for each undirected map.
    718718  ///
     
    723723  /// difference.
    724724  ///
    725   /// If the edgeset contains an \c "id" named map then it will be regarded
    726   /// as id map. This map should contain only unique values and when the
    727   /// \c writeId() member will be called with an undirected edge it will
    728   /// write it's id. Otherwise if the \c _forceIdMap constructor parameter
    729   /// is true then the id map will be the id in the graph.
    730   ///
    731   /// The undirected edgeset writer needs a node id writer to identify
     725  /// If the edgeset contains an \c "label" named map then it will be regarded
     726  /// as label map. This map should contain only unique values and when the
     727  /// \c writeLabel() member will be called with an undirected edge it will
     728  /// write it's label. Otherwise if the \c _forceLabelMap constructor
     729  /// parameter is true then the label map will be the id in the graph.
     730  ///
     731  /// The undirected edgeset writer needs a node label writer to identify
    732732  /// which nodes have to be connected. If a NodeSetWriter can write the
    733   /// nodes' id, it will be able to use with this class.
     733  /// nodes' label, it will be able to use with this class.
    734734  ///
    735735  /// \relates LemonWriter
     
    748748    ///
    749749    /// Constructor for UndirEdgeSetWriter. It creates the UndirEdgeSetWriter
    750     /// and attach it into the given LemonWriter. It will write node ids by
    751     /// the \c _nodeIdWriter. If the \c _forceIdMap parameter is true
    752     /// then the writer will write own id map if the user does not give
    753     /// "id" named map.
    754     template <typename NodeIdWriter>
     750    /// and attach it into the given LemonWriter. It will write node labels by
     751    /// the \c _nodeLabelWriter. If the \c _forceLabelMap parameter is true
     752    /// then the writer will write own label map if the user does not give
     753    /// "label" named map.
     754    template <typename NodeLabelWriter>
    755755    UndirEdgeSetWriter(LemonWriter& _writer, const Graph& _graph,
    756                        const NodeIdWriter& _nodeIdWriter,
    757                        const std::string& _id = std::string(),
    758                        bool _forceIdMap = true)
    759       : Parent(_writer), idMap(0), forceIdMap(_forceIdMap),
    760         graph(_graph), id(_id) {
    761       checkConcept<_writer_bits::ItemIdWriter<Node>, NodeIdWriter>();
    762       nodeIdWriter.reset(new _writer_bits::
    763                          IdWriter<Node, NodeIdWriter>(_nodeIdWriter));
     756                       const NodeLabelWriter& _nodeLabelWriter,
     757                       const std::string& _name = std::string(),
     758                       bool _forceLabelMap = true)
     759      : Parent(_writer), labelMap(0), forceLabelMap(_forceLabelMap),
     760        graph(_graph), name(_name) {
     761      checkConcept<_writer_bits::ItemLabelWriter<Node>, NodeLabelWriter>();
     762      nodeLabelWriter.reset(new _writer_bits::
     763                         LabelWriter<Node, NodeLabelWriter>(_nodeLabelWriter));
    764764    }
    765765
     
    833833    /// It gives back the header of the section.
    834834    virtual std::string header() {
    835       return "@undiredgeset " + id;
     835      return "@undiredgeset " + name;
    836836    }
    837837
     
    840840    /// Write the content of the section.
    841841    virtual void write(std::ostream& os) {
    842       if (!nodeIdWriter->isIdWriter()) {
    843         throw DataFormatError("Cannot find nodeset or ID map");
     842      if (!nodeLabelWriter->isLabelWriter()) {
     843        throw DataFormatError("Cannot find nodeset or label map");
    844844      }
    845845      for (int i = 0; i < (int)writers.size(); ++i) {
    846         if (writers[i].first == "id") {
    847           idMap = writers[i].second;
    848           forceIdMap = false;
     846        if (writers[i].first == "label") {
     847          labelMap = writers[i].second;
     848          forceLabelMap = false;
    849849          break;
    850850        }
    851851      }
    852852      os << "\t\t";
    853       if (forceIdMap) {
    854         os << "id\t";
     853      if (forceLabelMap) {
     854        os << "label\t";
    855855      }
    856856      for (int i = 0; i < (int)writers.size(); ++i) {
     
    859859      os << std::endl;
    860860      for (typename Graph::UndirEdgeIt it(graph); it != INVALID; ++it) {
    861         nodeIdWriter->write(os, graph.source(it));
     861        nodeLabelWriter->write(os, graph.source(it));
    862862        os << '\t';
    863         nodeIdWriter->write(os, graph.target(it));
     863        nodeLabelWriter->write(os, graph.target(it));
    864864        os << '\t';
    865         if (forceIdMap) {
     865        if (forceLabelMap) {
    866866          os << graph.id(it) << '\t';
    867867        }
     
    876876  public:
    877877
    878     /// \brief Returns true if the undirected edgeset can write the ids of
     878    /// \brief Returns true if the undirected edgeset can write the labels of
    879879    /// the edges.
    880880    ///
    881     /// Returns true if the undirected edgeset can write the ids of the
    882     /// undirected edges. It is possible only if an "id" named map was
    883     /// written or the \c _forceIdMap constructor parameter was true.
    884     bool isIdWriter() const {
    885       return forceIdMap || idMap != 0;
    886     }
    887 
    888     /// \brief Write the id of the given undirected edge.
    889     ///
    890     /// It writes the id of the given undirected edge. If there was written
    891     /// an "id" named map then it will write the map value belongs to the
    892     /// undirected edge. Otherwise if the \c forceId parameter was true it
     881    /// Returns true if the undirected edgeset can write the labels of the
     882    /// undirected edges. It is possible only if an "label" named map was
     883    /// written or the \c _forceLabelMap constructor parameter was true.
     884    bool isLabelWriter() const {
     885      return forceLabelMap || labelMap != 0;
     886    }
     887
     888    /// \brief Write the label of the given undirected edge.
     889    ///
     890    /// It writes the label of the given undirected edge. If there was written
     891    /// an "label" named map then it will write the map value belongs to the
     892    /// undirected edge. Otherwise if the \c forceLabel parameter was true it
    893893    /// will write its id in the graph.
    894     void writeId(std::ostream& os, const UndirEdge& item) const {
    895       if (forceIdMap) {
     894    void writeLabel(std::ostream& os, const UndirEdge& item) const {
     895      if (forceLabelMap) {
    896896        os << graph.id(item);
    897897      } else {
    898         idMap->write(os, item);
     898        labelMap->write(os, item);
    899899      }
    900900    }
    901901
    902     /// \brief Write the id of the given edge.
    903     ///
    904     /// It writes the id of the given edge. If there was written
    905     /// an "id" named map then it will write the map value belongs to the
    906     /// edge. Otherwise if the \c forceId parameter was true it
     902    /// \brief Write the label of the given edge.
     903    ///
     904    /// It writes the label of the given edge. If there was written
     905    /// an "label" named map then it will write the map value belongs to the
     906    /// edge. Otherwise if the \c forceLabel parameter was true it
    907907    /// will write its id in the graph. If the edge is forward map
    908908    /// then its prefix character is \c '+' elsewhere \c '-'.
    909     void writeId(std::ostream& os, const Edge& item) const {
     909    void writeLabel(std::ostream& os, const Edge& item) const {
    910910      if (graph.direction(item)) {
    911911        os << "+ ";
     
    913913        os << "- ";
    914914      }
    915       if (forceIdMap) {
     915      if (forceLabelMap) {
    916916        os << graph.id(item);
    917917      } else {
    918         idMap->write(os, item);
     918        labelMap->write(os, item);
    919919      }
    920920    }
     
    926926    MapWriters writers;
    927927
    928     _writer_bits::MapWriterBase<UndirEdge>* idMap;
    929     bool forceIdMap;
     928    _writer_bits::MapWriterBase<UndirEdge>* labelMap;
     929    bool forceLabelMap;
    930930   
    931931    const Graph& graph;   
    932     std::string id;
    933 
    934     std::auto_ptr<_writer_bits::IdWriterBase<Node> > nodeIdWriter;
     932    std::string name;
     933
     934    std::auto_ptr<_writer_bits::LabelWriterBase<Node> > nodeLabelWriter;
    935935  };
    936936
    937937  /// \ingroup io_group
    938   /// \brief SectionWriter for writing labeled nodes.
    939   ///
    940   /// The nodes section's header line is \c \@nodes \c nodes_id, but the
    941   /// \c nodes_id may be empty.
    942   ///
    943   /// Each line in the section contains the label of the node and
    944   /// then the node id.
     938  /// \brief SectionWriter for writing named nodes.
     939  ///
     940  /// The nodes section's header line is \c \@nodes \c nodes_name, but the
     941  /// \c nodes_name may be empty.
     942  ///
     943  /// Each line in the section contains the name of the node and
     944  /// then the node label.
    945945  ///
    946946  /// \relates LemonWriter
     
    955955    ///
    956956    /// Constructor for NodeWriter. It creates the NodeWriter and
    957     /// attach it into the given LemonWriter. The given \c _IdWriter
    958     /// will write the nodes' id what can be a nodeset writer.
    959     template <typename _IdWriter>
    960     NodeWriter(LemonWriter& _writer, const _IdWriter& _idWriter,
    961                const std::string& _id = std::string())
    962       : Parent(_writer), id(_id) {
    963       checkConcept<_writer_bits::ItemIdWriter<Node>, _IdWriter>();
    964       idWriter.reset(new _writer_bits::IdWriter<Node, _IdWriter>(_idWriter));
     957    /// attach it into the given LemonWriter. The given \c _LabelWriter
     958    /// will write the nodes' label what can be a nodeset writer.
     959    template <typename _LabelWriter>
     960    NodeWriter(LemonWriter& _writer, const _LabelWriter& _labelWriter,
     961               const std::string& _name = std::string())
     962      : Parent(_writer), name(_name) {
     963      checkConcept<_writer_bits::ItemLabelWriter<Node>, _LabelWriter>();
     964      labelWriter.reset(new _writer_bits::LabelWriter<Node, _LabelWriter>
     965                        (_labelWriter));
    965966    }
    966967
     
    986987  protected:
    987988
    988     /// \brief Header checking function.
    989     ///
    990     /// It gives back true when the header line start with \c \@nodes,
    991     /// and the header line's id and the writer's id are the same.
     989    /// \brief The header of the section.
     990    ///
     991    /// It gives back the header of the section.
    992992    virtual std::string header() {
    993       return "@nodes " + id;
     993      return "@nodes " + name;
    994994    }
    995995
     
    998998    /// Write the content of the section.
    999999    virtual void write(std::ostream& os) {
    1000       if (!idWriter->isIdWriter()) {
    1001         throw DataFormatError("Cannot find nodeset or ID map");
     1000      if (!labelWriter->isLabelWriter()) {
     1001        throw DataFormatError("Cannot find nodeset or label map");
    10021002      }
    10031003      for (int i = 0; i < (int)writers.size(); ++i) {
    10041004        os << writers[i].first << ' ';
    1005         idWriter->write(os, *(writers[i].second));
     1005        labelWriter->write(os, *(writers[i].second));
    10061006        os << std::endl;
    10071007      }
     
    10101010  private:
    10111011
    1012     std::string id;
     1012    std::string name;
    10131013
    10141014    typedef std::vector<std::pair<std::string, const Node*> > NodeWriters;
    10151015    NodeWriters writers;
    1016     std::auto_ptr<_writer_bits::IdWriterBase<Node> > idWriter;
     1016    std::auto_ptr<_writer_bits::LabelWriterBase<Node> > labelWriter;
    10171017  };
    10181018
    10191019  /// \ingroup io_group
    1020   /// \brief SectionWriter for writing labeled edges.
    1021   ///
    1022   /// The edges section's header line is \c \@edges \c edges_id, but the
    1023   /// \c edges_id may be empty.
    1024   ///
    1025   /// Each line in the section contains the label of the edge and
    1026   /// then the edge id.
     1020  /// \brief SectionWriter for writing named edges.
     1021  ///
     1022  /// The edges section's header line is \c \@edges \c edges_name, but the
     1023  /// \c edges_name may be empty.
     1024  ///
     1025  /// Each line in the section contains the name of the edge and
     1026  /// then the edge label.
    10271027  ///
    10281028  /// \relates LemonWriter
     
    10371037    ///
    10381038    /// Constructor for EdgeWriter. It creates the EdgeWriter and
    1039     /// attach it into the given LemonWriter. The given \c _IdWriter
    1040     /// will write the edges' id what can be a edgeset writer.
    1041     template <typename _IdWriter>
    1042     EdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter,
    1043                const std::string& _id = std::string())
    1044       : Parent(_writer), id(_id) {
    1045       checkConcept<_writer_bits::ItemIdWriter<Edge>, _IdWriter>();
    1046       idWriter.reset(new _writer_bits::IdWriter<Edge, _IdWriter>(_idWriter));
     1039    /// attach it into the given LemonWriter. The given \c _LabelWriter
     1040    /// will write the edges' label what can be a edgeset writer.
     1041    template <typename _LabelWriter>
     1042    EdgeWriter(LemonWriter& _writer, const _LabelWriter& _labelWriter,
     1043               const std::string& _name = std::string())
     1044      : Parent(_writer), name(_name) {
     1045      checkConcept<_writer_bits::ItemLabelWriter<Edge>, _LabelWriter>();
     1046      labelWriter.reset(new _writer_bits::LabelWriter<Edge, _LabelWriter>(_labelWriter));
    10471047    }
    10481048
     
    10661066  protected:
    10671067
    1068     /// \brief Header checking function.
    1069     ///
    1070     /// It gives back true when the header line start with \c \@edges,
    1071     /// and the header line's id and the writer's id are the same.
     1068    /// \brief The header of the section.
     1069    ///
     1070    /// It gives back the header of the section.
    10721071    virtual std::string header() {
    1073       return "@edges " + id;
     1072      return "@edges " + name;
    10741073    }
    10751074
     
    10781077    /// Write the content of the section.
    10791078    virtual void write(std::ostream& os) {
    1080       if (!idWriter->isIdWriter()) {
    1081         throw DataFormatError("Cannot find edgeset or ID map");
     1079      if (!labelWriter->isLabelWriter()) {
     1080        throw DataFormatError("Cannot find edgeset or label map");
    10821081      }
    10831082      for (int i = 0; i < (int)writers.size(); ++i) {
    10841083        os << writers[i].first << ' ';
    1085         idWriter->write(os, *(writers[i].second));
     1084        labelWriter->write(os, *(writers[i].second));
    10861085        os << std::endl;
    10871086      }
     
    10901089  private:
    10911090
    1092     std::string id;
     1091    std::string name;
    10931092
    10941093    typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters;
    10951094    EdgeWriters writers;
    10961095
    1097     std::auto_ptr<_writer_bits::IdWriterBase<Edge> > idWriter;
     1096    std::auto_ptr<_writer_bits::LabelWriterBase<Edge> > labelWriter;
    10981097  };
    10991098
    11001099  /// \ingroup io_group
    1101   /// \brief SectionWriter for writing labeled undirected edges.
     1100  /// \brief SectionWriter for writing named undirected edges.
    11021101  ///
    11031102  /// The undirected edges section's header line is \c \@undiredges
    1104   /// \c undiredges_id, but the \c undiredges_id may be empty.
    1105   ///
    1106   /// Each line in the section contains the label of the undirected edge and
    1107   /// then the undirected edge id.
     1103  /// \c undiredges_name, but the \c undiredges_name may be empty.
     1104  ///
     1105  /// Each line in the section contains the name of the undirected edge and
     1106  /// then the undirected edge label.
    11081107  ///
    11091108  /// \relates LemonWriter
     
    11201119    ///
    11211120    /// Constructor for UndirEdgeWriter. It creates the UndirEdgeWriter and
    1122     /// attach it into the given LemonWriter. The given \c _IdWriter
    1123     /// will write the undirected edges' id what can be an undirected
     1121    /// attach it into the given LemonWriter. The given \c _LabelWriter
     1122    /// will write the undirected edges' label what can be an undirected
    11241123    /// edgeset writer.
    1125     template <typename _IdWriter>
    1126     UndirEdgeWriter(LemonWriter& _writer, const _IdWriter& _idWriter,
    1127                const std::string& _id = std::string())
    1128       : Parent(_writer), id(_id) {
    1129       checkConcept<_writer_bits::ItemIdWriter<Edge>, _IdWriter>();
    1130       checkConcept<_writer_bits::ItemIdWriter<UndirEdge>, _IdWriter>();
    1131       undirEdgeIdWriter.reset(new _writer_bits::
    1132                               IdWriter<UndirEdge, _IdWriter>(_idWriter));
    1133       edgeIdWriter.reset(new _writer_bits::
    1134                          IdWriter<Edge, _IdWriter>(_idWriter));
     1124    template <typename _LabelWriter>
     1125    UndirEdgeWriter(LemonWriter& _writer, const _LabelWriter& _labelWriter,
     1126               const std::string& _name = std::string())
     1127      : Parent(_writer), name(_name) {
     1128      checkConcept<_writer_bits::ItemLabelWriter<Edge>, _LabelWriter>();
     1129      checkConcept<_writer_bits::ItemLabelWriter<UndirEdge>, _LabelWriter>();
     1130      undirEdgeLabelWriter.reset(new _writer_bits::
     1131                              LabelWriter<UndirEdge, _LabelWriter>(_labelWriter));
     1132      edgeLabelWriter.reset(new _writer_bits::
     1133                         LabelWriter<Edge, _LabelWriter>(_labelWriter));
    11351134    }
    11361135
     
    11611160  protected:
    11621161
    1163     /// \brief Header checking function.
    1164     ///
    1165     /// It gives back true when the header line start with \c \@undiredges,
    1166     /// and the header line's id and the writer's id are the same.
     1162    /// \brief The header of the section.
     1163    ///
     1164    /// It gives back the header of the section.
    11671165    virtual std::string header() {
    1168       return "@undiredges " + id;
     1166      return "@undiredges " + name;
    11691167    }
    11701168
     
    11731171    /// Write the content of the section.
    11741172    virtual void write(std::ostream& os) {
    1175       if (!edgeIdWriter->isIdWriter()) {
    1176         throw DataFormatError("Cannot find undirected edgeset or ID map");
    1177       }
    1178       if (!undirEdgeIdWriter->isIdWriter()) {
    1179         throw DataFormatError("Cannot find undirected edgeset or ID map");
     1173      if (!edgeLabelWriter->isLabelWriter()) {
     1174        throw DataFormatError("Cannot find undirected edgeset or label map");
     1175      }
     1176      if (!undirEdgeLabelWriter->isLabelWriter()) {
     1177        throw DataFormatError("Cannot find undirected edgeset or label map");
    11801178      }
    11811179      for (int i = 0; i < (int)undirEdgeWriters.size(); ++i) {
    11821180        os << undirEdgeWriters[i].first << ' ';
    1183         undirEdgeIdWriter->write(os, *(undirEdgeWriters[i].second));
     1181        undirEdgeLabelWriter->write(os, *(undirEdgeWriters[i].second));
    11841182        os << std::endl;
    11851183      }
    11861184      for (int i = 0; i < (int)edgeWriters.size(); ++i) {
    11871185        os << edgeWriters[i].first << ' ';
    1188         edgeIdWriter->write(os, *(edgeWriters[i].second));
     1186        edgeLabelWriter->write(os, *(edgeWriters[i].second));
    11891187        os << std::endl;
    11901188      }
     
    11931191  private:
    11941192
    1195     std::string id;
     1193    std::string name;
    11961194
    11971195    typedef std::vector<std::pair<std::string,
    11981196                                  const UndirEdge*> > UndirEdgeWriters;
    11991197    UndirEdgeWriters undirEdgeWriters;
    1200     std::auto_ptr<_writer_bits::IdWriterBase<UndirEdge> > undirEdgeIdWriter;
     1198    std::auto_ptr<_writer_bits::LabelWriterBase<UndirEdge> > undirEdgeLabelWriter;
    12011199
    12021200    typedef std::vector<std::pair<std::string, const Edge*> > EdgeWriters;
    12031201    EdgeWriters edgeWriters;
    1204     std::auto_ptr<_writer_bits::IdWriterBase<Edge> > edgeIdWriter;
     1202    std::auto_ptr<_writer_bits::LabelWriterBase<Edge> > edgeLabelWriter;
    12051203
    12061204  };
     
    12101208  ///
    12111209  /// The lemon format can store multiple attribute set. Each set has
    1212   /// the header line \c \@attributes \c attributeset_id, but the
    1213   /// attributeset_id may be empty.
     1210  /// the header line \c \@attributes \c attributes_name, but the
     1211  /// attributeset_name may be empty.
    12141212  ///
    12151213  /// The attributeset section contains several lines. Each of them starts
     
    12271225    /// attach it into the given LemonWriter.
    12281226    AttributeWriter(LemonWriter& _writer,
    1229                     const std::string& _id = std::string())
    1230       : Parent(_writer), id(_id) {}
     1227                    const std::string& _name = std::string())
     1228      : Parent(_writer), name(_name) {}
    12311229
    12321230    /// \brief Destructor.
     
    12491247    /// Add an attribute writer command for the writer.
    12501248    template <typename Value>
    1251     AttributeWriter& writeAttribute(const std::string& id,
     1249    AttributeWriter& writeAttribute(const std::string& name,
    12521250                                    const Value& value) {
    12531251      return
    1254         writeAttribute<typename Traits::template Writer<Value> >(id, value);
     1252        writeAttribute<typename Traits::template Writer<Value> >(name, value);
    12551253    }
    12561254
     
    12741272    /// It gives back the header of the section.
    12751273    std::string header() {
    1276       return "@attributes " + id;
     1274      return "@attributes " + name;
    12771275    }
    12781276
     
    12901288
    12911289  private:
    1292     std::string id;
     1290    std::string name;
    12931291
    12941292    typedef std::vector<std::pair<std::string,
Note: See TracChangeset for help on using the changeset viewer.