COIN-OR::LEMON - Graph Library

Changeset 1901:723b2b81d900 in lemon-0.x for lemon/lemon_reader.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_reader.h

    r1875 r1901  
    4848    template <typename T>
    4949    bool operator<(T, T) {
    50       throw DataFormatError("Id is not comparable");
     50      throw DataFormatError("Label is not comparable");
    5151    }
    5252
     
    5959
    6060    template <typename Item>
    61     class ItemIdReader {
     61    class ItemLabelReader {
    6262    public:
    6363
    64       bool isIdReader() { return true; }
    65 
    66       void readId(std::istream&, Item&) {}
     64      bool isLabelReader() { return true; }
     65
     66      void readLabel(std::istream&, Item&) {}
    6767     
    68       template <class _ItemIdReader>
     68      template <class _ItemLabelReader>
    6969      struct Constraints {
    7070        void constraints() {
    71           bool b = reader.isIdReader();
     71          bool b = reader.isLabelReader();
    7272          ignore_unused_variable_warning(b);
    7373          Item item;
    74           reader.readId(is, item);
    75         }
    76         _ItemIdReader& reader;
     74          reader.readLabel(is, item);
     75        }
     76        _ItemLabelReader& reader;
    7777        std::istream& is;
    7878      };
     
    242242          inverse.insert(std::make_pair(value, item));
    243243        } else {
    244           throw DataFormatError("Multiple ID occurence");
     244          throw DataFormatError("Multiple label occurence");
    245245        }
    246246      }
     
    253253          return it->second;
    254254        } else {
    255           throw DataFormatError("Invalid ID error");
     255          throw DataFormatError("Invalid label error");
    256256        }
    257257      }     
     
    280280          inverse.insert(std::make_pair(value, item));
    281281        } else {
    282           throw DataFormatError("Multiple ID occurence error");
     282          throw DataFormatError("Multiple label occurence error");
    283283        }
    284284      }
     
    291291          return it->second;
    292292        } else {
    293           throw DataFormatError("Invalid ID error");
     293          throw DataFormatError("Invalid label error");
    294294        }
    295295      }
     
    371371
    372372    template <typename _Item>
    373     class IdReaderBase {
     373    class LabelReaderBase {
    374374    public:
    375375      typedef _Item Item;
    376       virtual ~IdReaderBase() {}
     376      virtual ~LabelReaderBase() {}
    377377      virtual Item read(std::istream& is) const = 0;
    378       virtual bool isIdReader() const = 0;
    379     };
    380 
    381     template <typename _Item, typename _BoxedIdReader>
    382     class IdReader : public IdReaderBase<_Item> {
     378      virtual bool isLabelReader() const = 0;
     379    };
     380
     381    template <typename _Item, typename _BoxedLabelReader>
     382    class LabelReader : public LabelReaderBase<_Item> {
    383383    public:
    384384      typedef _Item Item;
    385       typedef _BoxedIdReader BoxedIdReader;
     385      typedef _BoxedLabelReader BoxedLabelReader;
    386386     
    387       const BoxedIdReader& boxedIdReader;
    388 
    389       IdReader(const BoxedIdReader& _boxedIdReader)
    390         : boxedIdReader(_boxedIdReader) {}
     387      const BoxedLabelReader& boxedLabelReader;
     388
     389      LabelReader(const BoxedLabelReader& _boxedLabelReader)
     390        : boxedLabelReader(_boxedLabelReader) {}
    391391
    392392      virtual Item read(std::istream& is) const {
    393393        Item item;
    394         boxedIdReader.readId(is, item);
     394        boxedLabelReader.readLabel(is, item);
    395395        return item;
    396396      }
    397397
    398       virtual bool isIdReader() const {
    399         return boxedIdReader.isIdReader();
     398      virtual bool isLabelReader() const {
     399        return boxedLabelReader.isLabelReader();
    400400      }
    401401    };
     
    728728  ///
    729729  /// The lemon format can store multiple graph nodesets with several maps.
    730   /// The nodeset section's header line is \c \@nodeset \c nodeset_id, but the
    731   /// \c nodeset_id may be empty.
     730  /// The nodeset section's header line is \c \@nodeset \c nodeset_name, but the
     731  /// \c nodeset_name may be empty.
    732732  ///
    733733  /// The first line of the section contains the names of the maps separated
     
    735735  /// contains the mapped values for each map.
    736736  ///
    737   /// If the nodeset contains an \c "id" named map then it will be regarded
     737  /// If the nodeset contains an \c "label" named map then it will be regarded
    738738  /// as id map. This map should contain only unique values and when the
    739   /// \c readId() member will read a value from the given stream it will
     739  /// \c readLabel() member will read a value from the given stream it will
    740740  /// give back that node which is mapped to this value.
    741741  ///
     
    756756    /// attach it into the given LemonReader. The nodeset reader will
    757757    /// add the readed nodes to the given Graph. The reader will read
    758     /// the section when the \c section_id and the \c _id are the same.
     758    /// the section when the \c section_name and the \c _name are the same.
    759759    NodeSetReader(LemonReader& _reader,
    760760                  Graph& _graph,
    761                   const std::string& _id = std::string(),
     761                  const std::string& _name = std::string(),
    762762                  const DefaultSkipper& _skipper = DefaultSkipper())
    763       : Parent(_reader), graph(_graph), id(_id), skipper(_skipper) {}
     763      : Parent(_reader), graph(_graph), name(_name), skipper(_skipper) {}
    764764
    765765
     
    856856    ///
    857857    /// It gives back true when the header line starts with \c \@nodeset,
    858     /// and the header line's id and the nodeset's id are the same.
     858    /// and the header line's name and the nodeset's name are the same.
    859859    virtual bool header(const std::string& line) {
    860860      std::istringstream ls(line);
    861861      std::string command;
    862       std::string name;
     862      std::string id;
    863863      ls >> command >> name;
    864864      return command == "@nodeset" && name == id;
     
    873873
    874874      getline(is, line);
    875       std::istringstream ls(line);     
     875      std::istringstream ls(line);
     876      std::string id;
    876877      while (ls >> id) {
    877878        typename MapReaders::iterator it = readers.find(id);
     
    882883          index.push_back(&skipper);
    883884        }
    884         if (id == "id" && inverter.get() == 0) {
     885        if (id == "label" || (id =="id" && inverter.get() == 0)) {
    885886          inverter.reset(index.back()->getInverter());
    886887          index.back() = inverter.get();
     
    906907  public:
    907908
    908     /// \brief Returns true if the nodeset can give back the node by its id.
    909     ///
    910     /// Returns true if the nodeset can give back the node by its id.
    911     /// It is possible only if an "id" named map was read.
    912     bool isIdReader() const {
     909    /// \brief Returns true if the nodeset can give back the node by its label.
     910    ///
     911    /// Returns true if the nodeset can give back the node by its label.
     912    /// It is possible only if an "label" named map was read.
     913    bool isLabelReader() const {
    913914      return inverter.get() != 0;
    914915    }
    915916
    916     /// \brief Gives back the node by its id.
     917    /// \brief Gives back the node by its label.
    917918    ///
    918919    /// It reads an id from the stream and gives back which node belongs to
    919     /// it. It is possible only if there was read an "id" named map.
    920     void readId(std::istream& is, Node& node) const {
     920    /// it. It is possible only if there was read an "label" named map.
     921    void readLabel(std::istream& is, Node& node) const {
    921922      node = inverter->read(is);
    922923    }
     
    928929   
    929930    Graph& graph;   
    930     std::string id;
     931    std::string name;
    931932    _reader_bits::SkipReader<Node, DefaultSkipper> skipper;
    932933
     
    938939  ///
    939940  /// The lemon format can store multiple graph edgesets with several maps.
    940   /// The edgeset section's header line is \c \@edgeset \c edgeset_id, but the
    941   /// \c edgeset_id may be empty.
     941  /// The edgeset section's header line is \c \@edgeset \c edgeset_name, but the
     942  /// \c edgeset_name may be empty.
    942943  ///
    943944  /// The first line of the section contains the names of the maps separated
     
    946947  /// values for each map.
    947948  ///
    948   /// If the edgeset contains an \c "id" named map then it will be regarded
     949  /// If the edgeset contains an \c "label" named map then it will be regarded
    949950  /// as id map. This map should contain only unique values and when the
    950   /// \c readId() member will read a value from the given stream it will
     951  /// \c readLabel() member will read a value from the given stream it will
    951952  /// give back that edge which is mapped to this value.
    952953  ///
    953954  /// The edgeset reader needs a node id reader to identify which nodes
    954   /// have to be connected. If a NodeSetReader reads an "id" named map,
     955  /// have to be connected. If a NodeSetReader reads an "label" named map,
    955956  /// it will be able to resolve the nodes by ids.
    956957  ///
     
    973974    /// add the readed edges to the given Graph. It will use the given
    974975    /// node id reader to read the source and target nodes of the edges.
    975     /// The reader will read the section only if the \c _id and the
    976     /// \c edgset_id are the same.
    977     template <typename NodeIdReader>
     976    /// The reader will read the section only if the \c _name and the
     977    /// \c edgset_name are the same.
     978    template <typename NodeLabelReader>
    978979    EdgeSetReader(LemonReader& _reader,
    979980                  Graph& _graph,
    980                   const NodeIdReader& _nodeIdReader,
    981                   const std::string& _id = std::string(),
     981                  const NodeLabelReader& _nodeLabelReader,
     982                  const std::string& _name = std::string(),
    982983                  const DefaultSkipper& _skipper = DefaultSkipper())
    983       : Parent(_reader), graph(_graph), id(_id), skipper(_skipper) {
    984       checkConcept<_reader_bits::ItemIdReader<Node>, NodeIdReader>();
    985       nodeIdReader.reset(new _reader_bits::
    986                          IdReader<Node, NodeIdReader>(_nodeIdReader));
     984      : Parent(_reader), graph(_graph), name(_name), skipper(_skipper) {
     985      checkConcept<_reader_bits::ItemLabelReader<Node>, NodeLabelReader>();
     986      nodeLabelReader.reset(new _reader_bits::
     987                         LabelReader<Node, NodeLabelReader>(_nodeLabelReader));
    987988    }
    988989    /// \brief Destructor.
     
    10781079    ///
    10791080    /// It gives back true when the header line starts with \c \@edgeset,
    1080     /// and the header line's id and the edgeset's id are the same.
     1081    /// and the header line's name and the edgeset's name are the same.
    10811082    virtual bool header(const std::string& line) {
    10821083      std::istringstream ls(line);
    10831084      std::string command;
    1084       std::string name;
     1085      std::string id;
    10851086      ls >> command >> name;
    10861087      return command == "@edgeset" && name == id;
     
    10911092    /// It reads the content of the section.
    10921093    virtual void read(std::istream& is) {
    1093       if (!nodeIdReader->isIdReader()) {
    1094         throw DataFormatError("Cannot find nodeset or ID map");
     1094      if (!nodeLabelReader->isLabelReader()) {
     1095        throw DataFormatError("Cannot find nodeset or label map");
    10951096      }
    10961097      std::vector<_reader_bits::MapReaderBase<Edge>* > index;
     
    10991100      getline(is, line);
    11001101      std::istringstream ls(line);     
     1102      std::string id;
    11011103      while (ls >> id) {
    11021104        typename MapReaders::iterator it = readers.find(id);
     
    11071109          index.push_back(&skipper);
    11081110        }
    1109         if (id == "id" && inverter.get() == 0) {
     1111        if (id == "label" || (id =="id" && inverter.get() == 0)) {
    11101112          inverter.reset(index.back()->getInverter());
    11111113          index.back() = inverter.get();
     
    11221124      while (getline(is, line)) {       
    11231125        std::istringstream ls(line);
    1124         Node from = nodeIdReader->read(ls);
    1125         Node to = nodeIdReader->read(ls);
     1126        Node from = nodeLabelReader->read(ls);
     1127        Node to = nodeLabelReader->read(ls);
    11261128        Edge edge = graph.addEdge(from, to);
    11271129        for (int i = 0; i < (int)index.size(); ++i) {
     
    11331135  public:
    11341136
    1135     /// \brief Returns true if the edgeset can give back the edge by its id.
    1136     ///
    1137     /// Returns true if the edgeset can give back the edge by its id.
    1138     /// It is possible only if an "id" named map was read.
    1139     bool isIdReader() const {
     1137    /// \brief Returns true if the edgeset can give back the edge by its label.
     1138    ///
     1139    /// Returns true if the edgeset can give back the edge by its label.
     1140    /// It is possible only if an "label" named map was read.
     1141    bool isLabelReader() const {
    11401142      return inverter.get() != 0;
    11411143    }
    11421144
    1143     /// \brief Gives back the edge by its id.
     1145    /// \brief Gives back the edge by its label.
    11441146    ///
    11451147    /// It reads an id from the stream and gives back which edge belongs to
    1146     /// it. It is possible only if there was read an "id" named map.
    1147     void readId(std::istream& is, Edge& edge) const {
     1148    /// it. It is possible only if there was read an "label" named map.
     1149    void readLabel(std::istream& is, Edge& edge) const {
    11481150      edge = inverter->read(is);
    11491151    }
     
    11551157   
    11561158    Graph& graph;   
    1157     std::string id;
     1159    std::string name;
    11581160    _reader_bits::SkipReader<Edge, DefaultSkipper> skipper;
    11591161
    11601162    std::auto_ptr<_reader_bits::MapInverterBase<Edge> > inverter;
    1161     std::auto_ptr<_reader_bits::IdReaderBase<Node> > nodeIdReader;
     1163    std::auto_ptr<_reader_bits::LabelReaderBase<Node> > nodeLabelReader;
    11621164  };
    11631165
     
    11671169  /// The lemon format can store multiple undirected edgesets with several
    11681170  /// maps. The undirected edgeset section's header line is \c \@undiredgeset
    1169   /// \c undiredgeset_id, but the \c undiredgeset_id may be empty.
     1171  /// \c undiredgeset_name, but the \c undiredgeset_name may be empty.
    11701172  ///
    11711173  /// The first line of the section contains the names of the maps separated
     
    11791181  /// difference.
    11801182  ///
    1181   /// If the edgeset contains an \c "id" named map then it will be regarded
     1183  /// If the edgeset contains an \c "label" named map then it will be regarded
    11821184  /// as id map. This map should contain only unique values and when the
    1183   /// \c readId() member will read a value from the given stream it will
     1185  /// \c readLabel() member will read a value from the given stream it will
    11841186  /// give back that undiricted edge which is mapped to this value.
    11851187  ///
    11861188  /// The undirected edgeset reader needs a node id reader to identify which
    1187   /// nodes have to be connected. If a NodeSetReader reads an "id" named map,
     1189  /// nodes have to be connected. If a NodeSetReader reads an "label" named map,
    11881190  /// it will be able to resolve the nodes by ids.
    11891191  ///
     
    12081210    /// will use the given node id reader to read the source and target
    12091211    /// nodes of the edges. The reader will read the section only if the
    1210     /// \c _id and the \c undiredgset_id are the same.
    1211     template <typename NodeIdReader>
     1212    /// \c _name and the \c undiredgset_name are the same.
     1213    template <typename NodeLabelReader>
    12121214    UndirEdgeSetReader(LemonReader& _reader,
    12131215                       Graph& _graph,
    1214                        const NodeIdReader& _nodeIdReader,
    1215                        const std::string& _id = std::string(),
     1216                       const NodeLabelReader& _nodeLabelReader,
     1217                       const std::string& _name = std::string(),
    12161218                       const DefaultSkipper& _skipper = DefaultSkipper())
    1217       : Parent(_reader), graph(_graph), id(_id), skipper(_skipper) {
    1218       checkConcept<_reader_bits::ItemIdReader<Node>, NodeIdReader>();
    1219       nodeIdReader.reset(new _reader_bits::
    1220                          IdReader<Node, NodeIdReader>(_nodeIdReader));
     1219      : Parent(_reader), graph(_graph), name(_name), skipper(_skipper) {
     1220      checkConcept<_reader_bits::ItemLabelReader<Node>, NodeLabelReader>();
     1221      nodeLabelReader.reset(new _reader_bits::
     1222                         LabelReader<Node, NodeLabelReader>(_nodeLabelReader));
    12211223    }
    12221224    /// \brief Destructor.
     
    13731375    ///
    13741376    /// It gives back true when the header line starts with \c \@undiredgeset,
    1375     /// and the header line's id and the edgeset's id are the same.
     1377    /// and the header line's name and the edgeset's name are the same.
    13761378    virtual bool header(const std::string& line) {
    13771379      std::istringstream ls(line);
    13781380      std::string command;
    1379       std::string name;
     1381      std::string id;
    13801382      ls >> command >> name;
    13811383      return command == "@undiredgeset" && name == id;
     
    13861388    /// It reads the content of the section.
    13871389    virtual void read(std::istream& is) {
    1388       if (!nodeIdReader->isIdReader()) {
    1389         throw DataFormatError("Cannot find nodeset or ID map");
     1390      if (!nodeLabelReader->isLabelReader()) {
     1391        throw DataFormatError("Cannot find nodeset or label map");
    13901392      }
    13911393      std::vector<_reader_bits::MapReaderBase<UndirEdge>* > index;
     
    13941396      getline(is, line);
    13951397      std::istringstream ls(line);     
     1398      std::string id;
    13961399      while (ls >> id) {
    13971400        typename MapReaders::iterator it = readers.find(id);
     
    14021405          index.push_back(&skipper);
    14031406        }
    1404         if (id == "id" && inverter.get() == 0) {
     1407        if (id == "label" || (id =="id" && inverter.get() == 0)) {
    14051408          inverter.reset(index.back()->getInverter());
    14061409          index.back() = inverter.get();
     
    14171420      while (getline(is, line)) {       
    14181421        std::istringstream ls(line);
    1419         Node from = nodeIdReader->read(ls);
    1420         Node to = nodeIdReader->read(ls);
     1422        Node from = nodeLabelReader->read(ls);
     1423        Node to = nodeLabelReader->read(ls);
    14211424        UndirEdge edge = graph.addEdge(from, to);
    14221425        for (int i = 0; i < (int)index.size(); ++i) {
     
    14281431  public:
    14291432
    1430     /// \brief Returns true if the edgeset can give back the edge by its id.
     1433    /// \brief Returns true if the edgeset can give back the edge by its label.
    14311434    ///
    14321435    /// Returns true if the edgeset can give back the undirected edge by its
    1433     /// id. It is possible only if an "id" named map was read.
    1434     bool isIdReader() const {
     1436    /// id. It is possible only if an "label" named map was read.
     1437    bool isLabelReader() const {
    14351438      return inverter.get() != 0;
    14361439    }
    14371440
    1438     /// \brief Gives back the undirected edge by its id.
     1441    /// \brief Gives back the undirected edge by its label.
    14391442    ///
    14401443    /// It reads an id from the stream and gives back which undirected edge
    1441     /// belongs to it. It is possible only if there was read an "id" named map.
    1442     void readId(std::istream& is, UndirEdge& undirEdge) const {
     1444    /// belongs to it. It is possible only if there was read an "label" named map.
     1445    void readLabel(std::istream& is, UndirEdge& undirEdge) const {
    14431446      undirEdge = inverter->read(is);
    14441447    }
    14451448
    1446     /// \brief Gives back the directed edge by its id.
     1449    /// \brief Gives back the directed edge by its label.
    14471450    ///
    14481451    /// It reads an id from the stream and gives back which directed edge
    14491452    /// belongs to it. The directed edge id is the \c '+' or \c '-' character
    14501453    /// and the undirected edge id. It is possible only if there was read
    1451     /// an "id" named map.
    1452     void readId(std::istream& is, Edge& edge) const {
     1454    /// an "label" named map.
     1455    void readLabel(std::istream& is, Edge& edge) const {
    14531456      char c;
    14541457      is >> c;
     
    14711474   
    14721475    Graph& graph;   
    1473     std::string id;
     1476    std::string name;
    14741477    _reader_bits::SkipReader<UndirEdge, DefaultSkipper> skipper;
    14751478
    14761479    std::auto_ptr<_reader_bits::MapInverterBase<UndirEdge> > inverter;
    1477     std::auto_ptr<_reader_bits::IdReaderBase<Node> > nodeIdReader;
     1480    std::auto_ptr<_reader_bits::LabelReaderBase<Node> > nodeLabelReader;
    14781481  };
    14791482
     
    14811484  /// \brief SectionReader for reading labeled nodes.
    14821485  ///
    1483   /// The nodes section's header line is \c \@nodes \c nodes_id, but the
    1484   /// \c nodes_id may be empty.
     1486  /// The nodes section's header line is \c \@nodes \c nodes_name, but the
     1487  /// \c nodes_name may be empty.
    14851488  ///
    14861489  /// Each line in the section contains the name of the node
     
    15001503    /// attach it into the given LemonReader. It will use the given
    15011504    /// node id reader to give back the nodes. The reader will read the
    1502     /// section only if the \c _id and the \c nodes_id are the same.
    1503     template <typename _IdReader>
    1504     NodeReader(LemonReader& _reader, const _IdReader& _idReader,
    1505                const std::string& _id = std::string())
    1506       : Parent(_reader), id(_id) {
    1507       checkConcept<_reader_bits::ItemIdReader<Node>, _IdReader>();
    1508       nodeIdReader.reset(new _reader_bits::
    1509                          IdReader<Node, _IdReader>(_idReader));
     1505    /// section only if the \c _name and the \c nodes_name are the same.
     1506    template <typename _LabelReader>
     1507    NodeReader(LemonReader& _reader, const _LabelReader& _labelReader,
     1508               const std::string& _name = std::string())
     1509      : Parent(_reader), name(_name) {
     1510      checkConcept<_reader_bits::ItemLabelReader<Node>, _LabelReader>();
     1511      nodeLabelReader.reset(new _reader_bits::
     1512                         LabelReader<Node, _LabelReader>(_labelReader));
    15101513    }
    15111514
     
    15391542    ///
    15401543    /// It gives back true when the header line start with \c \@nodes,
    1541     /// and the header line's id and the reader's id are the same.
     1544    /// and the header line's name and the reader's name are the same.
    15421545    virtual bool header(const std::string& line) {
    15431546      std::istringstream ls(line);
    15441547      std::string command;
    1545       std::string name;
     1548      std::string id;
    15461549      ls >> command >> name;
    15471550      return command == "@nodes" && name == id;
     
    15521555    /// It reads the content of the section.
    15531556    virtual void read(std::istream& is) {
    1554       if (!nodeIdReader->isIdReader()) {
    1555         throw DataFormatError("Cannot find nodeset or ID map");
     1557      if (!nodeLabelReader->isLabelReader()) {
     1558        throw DataFormatError("Cannot find nodeset or label map");
    15561559      }
    15571560      std::string line;
     
    15621565        typename NodeReaders::iterator it = readers.find(id);
    15631566        if (it != readers.end()) {
    1564           it->second.read(nodeIdReader->read(ls));
     1567          it->second.read(nodeLabelReader->read(ls));
    15651568          it->second.touch();
    15661569        }       
     
    15781581  private:
    15791582
    1580     std::string id;
     1583    std::string name;
    15811584
    15821585    typedef std::map<std::string, _reader_bits::ItemStore<Node> > NodeReaders;
    15831586    NodeReaders readers;
    1584     std::auto_ptr<_reader_bits::IdReaderBase<Node> > nodeIdReader;
     1587    std::auto_ptr<_reader_bits::LabelReaderBase<Node> > nodeLabelReader;
    15851588  };
    15861589
     
    15881591  /// \brief SectionReader for reading labeled edges.
    15891592  ///
    1590   /// The edges section's header line is \c \@edges \c edges_id, but the
    1591   /// \c edges_id may be empty.
     1593  /// The edges section's header line is \c \@edges \c edges_name, but the
     1594  /// \c edges_name may be empty.
    15921595  ///
    15931596  /// Each line in the section contains the name of the edge
     
    16071610    /// attach it into the given LemonReader. It will use the given
    16081611    /// edge id reader to give back the edges. The reader will read the
    1609     /// section only if the \c _id and the \c edges_id are the same.
    1610     template <typename _IdReader>
    1611     EdgeReader(LemonReader& _reader, const _IdReader& _idReader,
    1612                const std::string& _id = std::string())
    1613       : Parent(_reader), id(_id) {
    1614       checkConcept<_reader_bits::ItemIdReader<Edge>, _IdReader>();
    1615       edgeIdReader.reset(new _reader_bits::
    1616                          IdReader<Edge, _IdReader>(_idReader));
     1612    /// section only if the \c _name and the \c edges_name are the same.
     1613    template <typename _LabelReader>
     1614    EdgeReader(LemonReader& _reader, const _LabelReader& _labelReader,
     1615               const std::string& _name = std::string())
     1616      : Parent(_reader), name(_name) {
     1617      checkConcept<_reader_bits::ItemLabelReader<Edge>, _LabelReader>();
     1618      edgeLabelReader.reset(new _reader_bits::
     1619                         LabelReader<Edge, _LabelReader>(_labelReader));
    16171620    }
    16181621
     
    16451648    ///
    16461649    /// It gives back true when the header line start with \c \@edges,
    1647     /// and the header line's id and the reader's id are the same.
     1650    /// and the header line's name and the reader's name are the same.
    16481651    virtual bool header(const std::string& line) {
    16491652      std::istringstream ls(line);
    16501653      std::string command;
    1651       std::string name;
     1654      std::string id;
    16521655      ls >> command >> name;
    16531656      return command == "@edges" && name == id;
     
    16581661    /// It reads the content of the section.
    16591662    virtual void read(std::istream& is) {
    1660       if (!edgeIdReader->isIdReader()) {
    1661         throw DataFormatError("Cannot find edgeset or ID map");
     1663      if (!edgeLabelReader->isLabelReader()) {
     1664        throw DataFormatError("Cannot find edgeset or label map");
    16621665      }
    16631666      std::string line;
     
    16681671        typename EdgeReaders::iterator it = readers.find(id);
    16691672        if (it != readers.end()) {
    1670           it->second.read(edgeIdReader->read(ls));
     1673          it->second.read(edgeLabelReader->read(ls));
    16711674          it->second.touch();
    16721675        }       
     
    16841687  private:
    16851688
    1686     std::string id;
     1689    std::string name;
    16871690
    16881691    typedef std::map<std::string, _reader_bits::ItemStore<Edge> > EdgeReaders;
    16891692    EdgeReaders readers;
    1690     std::auto_ptr<_reader_bits::IdReaderBase<Edge> > edgeIdReader;
     1693    std::auto_ptr<_reader_bits::LabelReaderBase<Edge> > edgeLabelReader;
    16911694  };
    16921695
     
    16951698  ///
    16961699  /// The undirected edges section's header line is \c \@undiredges
    1697   /// \c undiredges_id, but the \c undiredges_id may be empty.
     1700  /// \c undiredges_name, but the \c undiredges_name may be empty.
    16981701  ///
    16991702  /// Each line in the section contains the name of the undirected edge
     
    17141717    /// attach it into the given LemonReader. It will use the given
    17151718    /// undirected edge id reader to give back the edges. The reader will
    1716     /// read the section only if the \c _id and the \c undiredges_id are
     1719    /// read the section only if the \c _name and the \c undiredges_name are
    17171720    /// the same.
    1718     template <typename _IdReader>
    1719     UndirEdgeReader(LemonReader& _reader, const _IdReader& _idReader,
    1720                const std::string& _id = std::string())
    1721       : Parent(_reader), id(_id) {
    1722       checkConcept<_reader_bits::ItemIdReader<UndirEdge>, _IdReader>();
    1723       checkConcept<_reader_bits::ItemIdReader<Edge>, _IdReader>();
    1724       undirEdgeIdReader.reset(new _reader_bits::
    1725                               IdReader<UndirEdge, _IdReader>(_idReader));
    1726       edgeIdReader.reset(new _reader_bits::
    1727                          IdReader<Edge, _IdReader>(_idReader));
     1721    template <typename _LabelReader>
     1722    UndirEdgeReader(LemonReader& _reader, const _LabelReader& _labelReader,
     1723               const std::string& _name = std::string())
     1724      : Parent(_reader), name(_name) {
     1725      checkConcept<_reader_bits::ItemLabelReader<UndirEdge>, _LabelReader>();
     1726      checkConcept<_reader_bits::ItemLabelReader<Edge>, _LabelReader>();
     1727      undirEdgeLabelReader.reset(new _reader_bits::
     1728                              LabelReader<UndirEdge, _LabelReader>(_labelReader));
     1729      edgeLabelReader.reset(new _reader_bits::
     1730                         LabelReader<Edge, _LabelReader>(_labelReader));
    17281731    }
    17291732
     
    17691772    ///
    17701773    /// It gives back true when the header line start with \c \@edges,
    1771     /// and the header line's id and the reader's id are the same.
     1774    /// and the header line's name and the reader's name are the same.
    17721775    virtual bool header(const std::string& line) {
    17731776      std::istringstream ls(line);
    17741777      std::string command;
    1775       std::string name;
     1778      std::string id;
    17761779      ls >> command >> name;
    17771780      return command == "@undiredges" && name == id;
     
    17821785    /// It reads the content of the section.
    17831786    virtual void read(std::istream& is) {
    1784       if (!edgeIdReader->isIdReader()) {
    1785         throw DataFormatError("Cannot find undirected edgeset or ID map");
    1786       }
    1787       if (!undirEdgeIdReader->isIdReader()) {
    1788         throw DataFormatError("Cannot find undirected edgeset or ID map");
     1787      if (!edgeLabelReader->isLabelReader()) {
     1788        throw DataFormatError("Cannot find undirected edgeset or label map");
     1789      }
     1790      if (!undirEdgeLabelReader->isLabelReader()) {
     1791        throw DataFormatError("Cannot find undirected edgeset or label map");
    17891792      }
    17901793      std::string line;
     
    17961799          typename UndirEdgeReaders::iterator it = undirEdgeReaders.find(id);
    17971800          if (it != undirEdgeReaders.end()) {
    1798             it->second.read(undirEdgeIdReader->read(ls));
     1801            it->second.read(undirEdgeLabelReader->read(ls));
    17991802            it->second.touch();
    18001803            continue;
     
    18031806          typename EdgeReaders::iterator it = edgeReaders.find(id);
    18041807          if (it != edgeReaders.end()) {
    1805             it->second.read(edgeIdReader->read(ls));
     1808            it->second.read(edgeLabelReader->read(ls));
    18061809            it->second.touch();
    18071810            continue;
     
    18291832  private:
    18301833
    1831     std::string id;
     1834    std::string name;
    18321835
    18331836    typedef std::map<std::string,
    18341837                     _reader_bits::ItemStore<UndirEdge> > UndirEdgeReaders;
    18351838    UndirEdgeReaders undirEdgeReaders;
    1836     std::auto_ptr<_reader_bits::IdReaderBase<UndirEdge> > undirEdgeIdReader;
     1839    std::auto_ptr<_reader_bits::LabelReaderBase<UndirEdge> > undirEdgeLabelReader;
    18371840
    18381841    typedef std::map<std::string, _reader_bits::ItemStore<Edge> > EdgeReaders;
    18391842    EdgeReaders edgeReaders;
    1840     std::auto_ptr<_reader_bits::IdReaderBase<Edge> > edgeIdReader;
     1843    std::auto_ptr<_reader_bits::LabelReaderBase<Edge> > edgeLabelReader;
    18411844  };
    18421845
     
    18451848  ///
    18461849  /// The lemon format can store multiple attribute set. Each set has
    1847   /// the header line \c \@attributes \c attributeset_id, but the
    1848   /// attributeset_id may be empty.
     1850  /// the header line \c \@attributes \c attributeset_name, but the
     1851  /// attributeset_name may be empty.
    18491852  ///
    18501853  /// The attributeset section contains several lines. Each of them starts
     
    18611864    /// Constructor for AttributeReader. It creates the AttributeReader and
    18621865    /// attach it into the given LemonReader. The reader process a section
    1863     /// only if the \c section_id and the \c _id are the same.
     1866    /// only if the \c section_name and the \c _name are the same.
    18641867    AttributeReader(LemonReader& _reader,
    1865                     const std::string& _id = std::string())
    1866       : Parent(_reader), id(_id) {}
     1868                    const std::string& _name = std::string())
     1869      : Parent(_reader), name(_name) {}
    18671870
    18681871    /// \brief Destructor.
     
    19171920      std::istringstream ls(line);
    19181921      std::string command;
    1919       std::string name;
     1922      std::string id;
    19201923      ls >> command >> name;
    19211924      return command == "@attributes" && name == id;
     
    19341937        if (it != readers.end()) {
    19351938          it->second->read(ls);
    1936           it->second->touch();
     1939          it->second->touch();
    19371940        }
    19381941      }
     
    19481951
    19491952  private:
    1950     std::string id;
     1953    std::string name;
    19511954
    19521955    typedef std::map<std::string, _reader_bits::ValueReaderBase*> Readers;
     
    22042207
    22052208    void readMapNames(std::istream& is, std::vector<std::string>& maps) {
    2206       std::string line, id;
     2209      std::string line, name;
    22072210      std::getline(is, line);
    22082211      std::istringstream ls(line);
    2209       while (ls >> id) {
    2210         maps.push_back(id);
     2212      while (ls >> name) {
     2213        maps.push_back(name);
    22112214      }
    22122215      while (getline(is, line));
     
    22142217
    22152218    void readItemNames(std::istream& is, std::vector<std::string>& maps) {
    2216       std::string line, id;
     2219      std::string line, name;
    22172220      while (std::getline(is, line)) {
    22182221        std::istringstream ls(line);
    2219         ls >> id;
    2220         maps.push_back(id);
     2222        ls >> name;
     2223        maps.push_back(name);
    22212224      }
    22222225    }
Note: See TracChangeset for help on using the changeset viewer.