COIN-OR::LEMON - Graph Library

Changeset 1909:2d806130e700 in lemon-0.x for lemon/lemon_reader.h


Ignore:
Timestamp:
01/26/06 16:42:13 (14 years ago)
Author:
Mihaly Barasz
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@2484
Message:

Undir -> U transition

File:
1 edited

Legend:

Unmodified
Added
Removed
  • lemon/lemon_reader.h

    r1901 r1909  
    105105    class ForwardComposeMap {
    106106    public:
    107       typedef typename Graph::UndirEdge Key;
     107      typedef typename Graph::UEdge Key;
    108108      typedef typename Map::Value Value;
    109109
     
    135135    class BackwardComposeMap {
    136136    public:
    137       typedef typename Graph::UndirEdge Key;
     137      typedef typename Graph::UEdge Key;
    138138      typedef typename Map::Value Value;
    139139
     
    11681168  ///
    11691169  /// The lemon format can store multiple undirected edgesets with several
    1170   /// maps. The undirected edgeset section's header line is \c \@undiredgeset
    1171   /// \c undiredgeset_name, but the \c undiredgeset_name may be empty.
     1170  /// maps. The undirected edgeset section's header line is \c \@uedgeset
     1171  /// \c uedgeset_name, but the \c uedgeset_name may be empty.
    11721172  ///
    11731173  /// The first line of the section contains the names of the maps separated
     
    11841184  /// as id map. This map should contain only unique values and when the
    11851185  /// \c readLabel() member will read a value from the given stream it will
    1186   /// give back that undiricted edge which is mapped to this value.
     1186  /// give back that uicted edge which is mapped to this value.
    11871187  ///
    11881188  /// The undirected edgeset reader needs a node id reader to identify which
     
    11921192  /// \relates LemonReader
    11931193  template <typename _Graph, typename _Traits = DefaultReaderTraits>
    1194   class UndirEdgeSetReader : public LemonReader::SectionReader {
     1194  class UEdgeSetReader : public LemonReader::SectionReader {
    11951195    typedef LemonReader::SectionReader Parent;
    11961196  public:
     
    12001200    typedef typename Graph::Node Node;
    12011201    typedef typename Graph::Edge Edge;
    1202     typedef typename Graph::UndirEdge UndirEdge;
     1202    typedef typename Graph::UEdge UEdge;
    12031203    typedef typename Traits::Skipper DefaultSkipper;
    12041204
    12051205    /// \brief Constructor.
    12061206    ///
    1207     /// Constructor for UndirEdgeSetReader. It creates the UndirEdgeSetReader
     1207    /// Constructor for UEdgeSetReader. It creates the UEdgeSetReader
    12081208    /// and attach it into the given LemonReader. The undirected edgeset
    12091209    /// reader will add the readed undirected edges to the given Graph. It
    12101210    /// will use the given node id reader to read the source and target
    12111211    /// nodes of the edges. The reader will read the section only if the
    1212     /// \c _name and the \c undiredgset_name are the same.
     1212    /// \c _name and the \c uedgset_name are the same.
    12131213    template <typename NodeLabelReader>
    1214     UndirEdgeSetReader(LemonReader& _reader,
     1214    UEdgeSetReader(LemonReader& _reader,
    12151215                       Graph& _graph,
    12161216                       const NodeLabelReader& _nodeLabelReader,
     
    12241224    /// \brief Destructor.
    12251225    ///
    1226     /// Destructor for UndirEdgeSetReader.
    1227     virtual ~UndirEdgeSetReader() {
     1226    /// Destructor for UEdgeSetReader.
     1227    virtual ~UEdgeSetReader() {
    12281228      for (typename MapReaders::iterator it = readers.begin();
    12291229           it != readers.end(); ++it) {
     
    12331233
    12341234  private:
    1235     UndirEdgeSetReader(const UndirEdgeSetReader&);
    1236     void operator=(const UndirEdgeSetReader&);
     1235    UEdgeSetReader(const UEdgeSetReader&);
     1236    void operator=(const UEdgeSetReader&);
    12371237
    12381238  public:
     
    12421242    /// Add a new edge undirected map reader command for the reader.
    12431243    template <typename Map>
    1244     UndirEdgeSetReader& readUndirEdgeMap(std::string name, Map& map) {
     1244    UEdgeSetReader& readUEdgeMap(std::string name, Map& map) {
    12451245      return _readMap<
    12461246        typename Traits::template Reader<typename Map::Value>, Map,
     
    12491249
    12501250    template <typename Map>
    1251     UndirEdgeSetReader& readUndirEdgeMap(std::string name, const Map& map) {
     1251    UEdgeSetReader& readUEdgeMap(std::string name, const Map& map) {
    12521252      return _readMap<
    12531253        typename Traits::template Reader<typename Map::Value>, Map,
     
    12591259    /// Add a new edge undirected map reader command for the reader.
    12601260    template <typename Reader, typename Map>
    1261     UndirEdgeSetReader& readUndirEdgeMap(std::string name, Map& map,
     1261    UEdgeSetReader& readUEdgeMap(std::string name, Map& map,
    12621262                                         const Reader& reader = Reader()) {
    12631263      return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
     
    12661266
    12671267    template <typename Reader, typename Map>
    1268     UndirEdgeSetReader& readUndirEdgeMap(std::string name, const Map& map,
     1268    UEdgeSetReader& readUEdgeMap(std::string name, const Map& map,
    12691269                                         const Reader& reader = Reader()) {
    12701270      return _readMap<Reader, Map, typename _reader_bits::Arg<Map>::Type >
     
    12751275
    12761276    template <typename Reader, typename Map, typename MapParameter>
    1277     UndirEdgeSetReader& _readMap(std::string name, MapParameter map,
     1277    UEdgeSetReader& _readMap(std::string name, MapParameter map,
    12781278                                 const Reader& reader = Reader()) {
    1279       checkConcept<concept::WriteMap<UndirEdge, typename Map::Value>, Map>();
     1279      checkConcept<concept::WriteMap<UEdge, typename Map::Value>, Map>();
    12801280      checkConcept<_reader_bits::ItemReader<typename Map::Value>, Reader>();
    12811281      if (readers.find(name) != readers.end()) {
     
    12861286      readers.insert(
    12871287        make_pair(name, new _reader_bits::
    1288                   MapReader<UndirEdge, Map, Reader>(map, reader)));
     1288                  MapReader<UEdge, Map, Reader>(map, reader)));
    12891289      return *this;
    12901290    }
     
    12961296    /// Add a new undirected edge map skipper command for the reader.
    12971297    template <typename Reader>
    1298     UndirEdgeSetReader& skipUndirEdgeMap(std::string name,
     1298    UEdgeSetReader& skipUEdgeMap(std::string name,
    12991299                                         const Reader& reader = Reader()) {
    13001300      if (readers.find(name) != readers.end()) {
     
    13041304      }
    13051305      readers.insert(make_pair(name, new _reader_bits::
    1306                                SkipReader<UndirEdge, Reader>(reader)));
     1306                               SkipReader<UEdge, Reader>(reader)));
    13071307      return *this;
    13081308    }
     
    13121312    /// Add a new directed edge map reader command for the reader.
    13131313    template <typename Map>
    1314     UndirEdgeSetReader& readEdgeMap(std::string name, Map& map) {
     1314    UEdgeSetReader& readEdgeMap(std::string name, Map& map) {
    13151315      return _readDirMap<
    13161316        typename Traits::template Reader<typename Map::Value>, Map,
     
    13191319
    13201320    template <typename Map>
    1321     UndirEdgeSetReader& readEdgeMap(std::string name, const Map& map) {
     1321    UEdgeSetReader& readEdgeMap(std::string name, const Map& map) {
    13221322      return _readDirMap<
    13231323        typename Traits::template Reader<typename Map::Value>, Map,
     
    13291329    /// Add a new directed edge map reader command for the reader.
    13301330    template <typename Reader, typename Map>
    1331     UndirEdgeSetReader& readEdgeMap(std::string name, Map& map,
     1331    UEdgeSetReader& readEdgeMap(std::string name, Map& map,
    13321332                                    const Reader& reader = Reader()) {
    13331333      return _readDirMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
     
    13361336
    13371337    template <typename Reader, typename Map>
    1338     UndirEdgeSetReader& readEdgeMap(std::string name, const Map& map,
     1338    UEdgeSetReader& readEdgeMap(std::string name, const Map& map,
    13391339                                    const Reader& reader = Reader()) {
    13401340      return _readDirMap<Reader, Map, typename _reader_bits::Arg<Map>::Type>
     
    13451345
    13461346    template <typename Reader, typename Map, typename MapParameter>
    1347     UndirEdgeSetReader& _readDirMap(std::string name, MapParameter map,
     1347    UEdgeSetReader& _readDirMap(std::string name, MapParameter map,
    13481348                                    const Reader& reader = Reader()) {
    13491349      checkConcept<_reader_bits::ItemReader<typename Map::Value>, Reader>();
     
    13621362    /// Add a new directed edge map skipper command for the reader.
    13631363    template <typename Reader>
    1364     UndirEdgeSetReader& skipEdgeMap(std::string name,
     1364    UEdgeSetReader& skipEdgeMap(std::string name,
    13651365                                    const Reader& reader = Reader()) {
    13661366      skipMap("+" + name, reader);
     
    13741374    /// the section with the given header line.
    13751375    ///
    1376     /// It gives back true when the header line starts with \c \@undiredgeset,
     1376    /// It gives back true when the header line starts with \c \@uedgeset,
    13771377    /// and the header line's name and the edgeset's name are the same.
    13781378    virtual bool header(const std::string& line) {
     
    13811381      std::string id;
    13821382      ls >> command >> name;
    1383       return command == "@undiredgeset" && name == id;
     1383      return command == "@uedgeset" && name == id;
    13841384    }
    13851385
     
    13911391        throw DataFormatError("Cannot find nodeset or label map");
    13921392      }
    1393       std::vector<_reader_bits::MapReaderBase<UndirEdge>* > index;
     1393      std::vector<_reader_bits::MapReaderBase<UEdge>* > index;
    13941394      std::string line;
    13951395
     
    14221422        Node from = nodeLabelReader->read(ls);
    14231423        Node to = nodeLabelReader->read(ls);
    1424         UndirEdge edge = graph.addEdge(from, to);
     1424        UEdge edge = graph.addEdge(from, to);
    14251425        for (int i = 0; i < (int)index.size(); ++i) {
    14261426          index[i]->read(ls, edge);
     
    14431443    /// It reads an id from the stream and gives back which undirected edge
    14441444    /// belongs to it. It is possible only if there was read an "label" named map.
    1445     void readLabel(std::istream& is, UndirEdge& undirEdge) const {
    1446       undirEdge = inverter->read(is);
     1445    void readLabel(std::istream& is, UEdge& uEdge) const {
     1446      uEdge = inverter->read(is);
    14471447    }
    14481448
     
    14561456      char c;
    14571457      is >> c;
    1458       UndirEdge undirEdge = inverter->read(is);
     1458      UEdge uEdge = inverter->read(is);
    14591459      if (c == '+') {
    1460         edge = graph.direct(undirEdge, true);
     1460        edge = graph.direct(uEdge, true);
    14611461      } else if (c == '-') {
    1462         edge = graph.direct(undirEdge, false);
     1462        edge = graph.direct(uEdge, false);
    14631463      } else {
    14641464        throw DataFormatError("Wrong id format for edge "
     
    14701470
    14711471    typedef std::map<std::string,
    1472                      _reader_bits::MapReaderBase<UndirEdge>*> MapReaders;
     1472                     _reader_bits::MapReaderBase<UEdge>*> MapReaders;
    14731473    MapReaders readers;
    14741474   
    14751475    Graph& graph;   
    14761476    std::string name;
    1477     _reader_bits::SkipReader<UndirEdge, DefaultSkipper> skipper;
    1478 
    1479     std::auto_ptr<_reader_bits::MapInverterBase<UndirEdge> > inverter;
     1477    _reader_bits::SkipReader<UEdge, DefaultSkipper> skipper;
     1478
     1479    std::auto_ptr<_reader_bits::MapInverterBase<UEdge> > inverter;
    14801480    std::auto_ptr<_reader_bits::LabelReaderBase<Node> > nodeLabelReader;
    14811481  };
     
    16971697  /// \brief SectionReader for reading labeled undirected edges.
    16981698  ///
    1699   /// The undirected edges section's header line is \c \@undiredges
    1700   /// \c undiredges_name, but the \c undiredges_name may be empty.
     1699  /// The undirected edges section's header line is \c \@uedges
     1700  /// \c uedges_name, but the \c uedges_name may be empty.
    17011701  ///
    17021702  /// Each line in the section contains the name of the undirected edge
     
    17051705  /// \relates LemonReader
    17061706  template <typename _Graph>
    1707   class UndirEdgeReader : public LemonReader::SectionReader {
     1707  class UEdgeReader : public LemonReader::SectionReader {
    17081708    typedef LemonReader::SectionReader Parent;
    17091709    typedef _Graph Graph;
    17101710    typedef typename Graph::Edge Edge;
    1711     typedef typename Graph::UndirEdge UndirEdge;
     1711    typedef typename Graph::UEdge UEdge;
    17121712  public:
    17131713   
    17141714    /// \brief Constructor.
    17151715    ///
    1716     /// Constructor for UndirEdgeReader. It creates the UndirEdgeReader and
     1716    /// Constructor for UEdgeReader. It creates the UEdgeReader and
    17171717    /// attach it into the given LemonReader. It will use the given
    17181718    /// undirected edge id reader to give back the edges. The reader will
    1719     /// read the section only if the \c _name and the \c undiredges_name are
     1719    /// read the section only if the \c _name and the \c uedges_name are
    17201720    /// the same.
    17211721    template <typename _LabelReader>
    1722     UndirEdgeReader(LemonReader& _reader, const _LabelReader& _labelReader,
     1722    UEdgeReader(LemonReader& _reader, const _LabelReader& _labelReader,
    17231723               const std::string& _name = std::string())
    17241724      : Parent(_reader), name(_name) {
    1725       checkConcept<_reader_bits::ItemLabelReader<UndirEdge>, _LabelReader>();
     1725      checkConcept<_reader_bits::ItemLabelReader<UEdge>, _LabelReader>();
    17261726      checkConcept<_reader_bits::ItemLabelReader<Edge>, _LabelReader>();
    1727       undirEdgeLabelReader.reset(new _reader_bits::
    1728                               LabelReader<UndirEdge, _LabelReader>(_labelReader));
     1727      uEdgeLabelReader.reset(new _reader_bits::
     1728                              LabelReader<UEdge, _LabelReader>(_labelReader));
    17291729      edgeLabelReader.reset(new _reader_bits::
    17301730                         LabelReader<Edge, _LabelReader>(_labelReader));
     
    17331733    /// \brief Destructor.
    17341734    ///
    1735     /// Destructor for UndirEdgeReader.
    1736     virtual ~UndirEdgeReader() {}
     1735    /// Destructor for UEdgeReader.
     1736    virtual ~UEdgeReader() {}
    17371737  private:
    1738     UndirEdgeReader(const UndirEdgeReader&);
    1739     void operator=(const UndirEdgeReader&);
    1740 
    1741   public:
    1742 
    1743     /// \brief Add an undirected edge reader command for the UndirEdgeReader.
    1744     ///
    1745     /// Add an undirected edge reader command for the UndirEdgeReader.
    1746     void readUndirEdge(const std::string& name, UndirEdge& item) {
    1747       if (undirEdgeReaders.find(name) != undirEdgeReaders.end()) {
     1738    UEdgeReader(const UEdgeReader&);
     1739    void operator=(const UEdgeReader&);
     1740
     1741  public:
     1742
     1743    /// \brief Add an undirected edge reader command for the UEdgeReader.
     1744    ///
     1745    /// Add an undirected edge reader command for the UEdgeReader.
     1746    void readUEdge(const std::string& name, UEdge& item) {
     1747      if (uEdgeReaders.find(name) != uEdgeReaders.end()) {
    17481748        ErrorMessage msg;
    17491749        msg << "Multiple read rule for undirected edge: " << name;
    17501750        throw IOParameterError(msg.message());
    17511751      }
    1752       undirEdgeReaders.insert(make_pair(name, _reader_bits::
    1753                                         ItemStore<UndirEdge>(item)));
    1754     }
    1755 
    1756     /// \brief Add an edge reader command for the UndirEdgeReader.
    1757     ///
    1758     /// Add an edge reader command for the UndirEdgeReader.
     1752      uEdgeReaders.insert(make_pair(name, _reader_bits::
     1753                                        ItemStore<UEdge>(item)));
     1754    }
     1755
     1756    /// \brief Add an edge reader command for the UEdgeReader.
     1757    ///
     1758    /// Add an edge reader command for the UEdgeReader.
    17591759    void readEdge(const std::string& name, Edge& item) {
    17601760      if (edgeReaders.find(name) != edgeReaders.end()) {
     
    17781778      std::string id;
    17791779      ls >> command >> name;
    1780       return command == "@undiredges" && name == id;
     1780      return command == "@uedges" && name == id;
    17811781    }
    17821782
     
    17881788        throw DataFormatError("Cannot find undirected edgeset or label map");
    17891789      }
    1790       if (!undirEdgeLabelReader->isLabelReader()) {
     1790      if (!uEdgeLabelReader->isLabelReader()) {
    17911791        throw DataFormatError("Cannot find undirected edgeset or label map");
    17921792      }
     
    17971797        ls >> id;
    17981798        {
    1799           typename UndirEdgeReaders::iterator it = undirEdgeReaders.find(id);
    1800           if (it != undirEdgeReaders.end()) {
    1801             it->second.read(undirEdgeLabelReader->read(ls));
     1799          typename UEdgeReaders::iterator it = uEdgeReaders.find(id);
     1800          if (it != uEdgeReaders.end()) {
     1801            it->second.read(uEdgeLabelReader->read(ls));
    18021802            it->second.touch();
    18031803            continue;
     
    18201820        }
    18211821      }
    1822       for (typename UndirEdgeReaders::iterator it = undirEdgeReaders.begin();
    1823            it != undirEdgeReaders.end(); ++it) {
     1822      for (typename UEdgeReaders::iterator it = uEdgeReaders.begin();
     1823           it != uEdgeReaders.end(); ++it) {
    18241824        if (!it->second.touched()) {
    18251825          ErrorMessage msg;
    1826           msg << "UndirEdge not found in file: " << it->first;
     1826          msg << "UEdge not found in file: " << it->first;
    18271827          throw IOParameterError(msg.message());
    18281828        }
     
    18351835
    18361836    typedef std::map<std::string,
    1837                      _reader_bits::ItemStore<UndirEdge> > UndirEdgeReaders;
    1838     UndirEdgeReaders undirEdgeReaders;
    1839     std::auto_ptr<_reader_bits::LabelReaderBase<UndirEdge> > undirEdgeLabelReader;
     1837                     _reader_bits::ItemStore<UEdge> > UEdgeReaders;
     1838    UEdgeReaders uEdgeReaders;
     1839    std::auto_ptr<_reader_bits::LabelReaderBase<UEdge> > uEdgeLabelReader;
    18401840
    18411841    typedef std::map<std::string, _reader_bits::ItemStore<Edge> > EdgeReaders;
     
    20262026    ///
    20272027    /// Gives back how many undirected edgesets are in the file.
    2028     int undirEdgeSetNum() const {
    2029       return undiredgesets.size();
     2028    int uEdgeSetNum() const {
     2029      return uedgesets.size();
    20302030    }
    20312031
     
    20342034    ///
    20352035    /// Gives back the name of undirected edgeset on the indiced position.
    2036     std::string undirEdgeSetName(int index) const {
    2037       return undiredgesets[index].name;
     2036    std::string uEdgeSetName(int index) const {
     2037      return uedgesets[index].name;
    20382038    }
    20392039
     
    20422042    ///
    20432043    /// Gives back the map names of undirected edgeset on the indiced position.
    2044     const std::vector<std::string>& undirEdgeSetMaps(int index) const {
    2045       return undiredgesets[index].items;
     2044    const std::vector<std::string>& uEdgeSetMaps(int index) const {
     2045      return uedgesets[index].items;
    20462046    }
    20472047
     
    20962096    ///
    20972097    /// Gives back how many labeled undirected edges section are in the file.
    2098     int undirEdgesNum() const {
    2099       return undiredges.size();
     2098    int uEdgesNum() const {
     2099      return uedges.size();
    21002100    }
    21012101
     
    21052105    /// Gives back the name of labeled undirected edges section on the
    21062106    /// indiced position.
    2107     std::string undirEdgesName(int index) const {
    2108       return undiredges[index].name;
     2107    std::string uEdgesName(int index) const {
     2108      return uedges[index].name;
    21092109    }
    21102110
     
    21142114    /// Gives back the names of the labeled undirected edges in the
    21152115    /// indiced section.
    2116     const std::vector<std::string>& undirEdgesItems(int index) const {
    2117       return undiredges[index].items;
     2116    const std::vector<std::string>& uEdgesItems(int index) const {
     2117      return uedges[index].items;
    21182118    }
    21192119
     
    21612161        current = command;
    21622162        edgesets.push_back(SectionInfo(name));
    2163       } else if (command == "@undiredgeset") {
     2163      } else if (command == "@uedgeset") {
    21642164        current = command;
    2165         undiredgesets.push_back(SectionInfo(name));
     2165        uedgesets.push_back(SectionInfo(name));
    21662166      } else if (command == "@nodes") {
    21672167        current = command;
     
    21702170        current = command;
    21712171        edges.push_back(SectionInfo(name));
    2172       } else if (command == "@undiredges") {
     2172      } else if (command == "@uedges") {
    21732173        current = command;
    2174         undiredges.push_back(SectionInfo(name));
     2174        uedges.push_back(SectionInfo(name));
    21752175      } else if (command == "@attributes") {
    21762176        current = command;
     
    21912191      } else if (current == "@edgeset") {
    21922192        readMapNames(is, edgesets.back().items);
    2193       } else if (current == "@undiredgeset") {
    2194         readMapNames(is, undiredgesets.back().items);
     2193      } else if (current == "@uedgeset") {
     2194        readMapNames(is, uedgesets.back().items);
    21952195      } else if (current == "@nodes") {
    21962196        readItemNames(is, nodes.back().items);
    21972197      } else if (current == "@edges") {
    21982198        readItemNames(is, edges.back().items);
    2199       } else if (current == "@undiredges") {
    2200         readItemNames(is, undiredges.back().items);
     2199      } else if (current == "@uedges") {
     2200        readItemNames(is, uedges.back().items);
    22012201      } else if (current == "@attributes") {
    22022202        readItemNames(is, attributes.back().items);
     
    22342234    std::vector<SectionInfo> nodesets;
    22352235    std::vector<SectionInfo> edgesets;
    2236     std::vector<SectionInfo> undiredgesets;
     2236    std::vector<SectionInfo> uedgesets;
    22372237
    22382238    std::vector<SectionInfo> nodes;
    22392239    std::vector<SectionInfo> edges;
    2240     std::vector<SectionInfo> undiredges;
     2240    std::vector<SectionInfo> uedges;
    22412241
    22422242    std::vector<SectionInfo> attributes;
Note: See TracChangeset for help on using the changeset viewer.