COIN-OR::LEMON - Graph Library

Changeset 1115:444f69240539 in lemon-0.x for src/work/deba


Ignore:
Timestamp:
02/01/05 16:56:37 (20 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1514
Message:

Some changes in the IO and map utilities.

Location:
src/work/deba
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • src/work/deba/graph_io_test.cc

    r1037 r1115  
    1919
    2020  SmartGraph::NodeMap<int> id(graph);
    21   reader.readNodeMap("id", id);
     21  reader.addNodeMap("id", id);
    2222
    2323  SmartGraph::NodeMap<int> cost(graph);
    24   reader.readNodeMap("cost", cost);
     24  reader.addNodeMap("cost", cost);
    2525 
    2626  SmartGraph::NodeMap<string> color(graph);
    27   reader.readNodeMap("color", color);
     27  reader.addNodeMap("color", color);
    2828
    2929  SmartGraph::NodeMap<string> description(graph);
    30   reader.readNodeMap<QuotedStringReader>("description", description);
     30  reader.addNodeMap<QuotedStringReader>("description", description);
    3131
    3232  SmartGraph::EdgeMap<char> mmap(graph);
    33   reader.readEdgeMap("mmap", mmap);
     33  reader.addEdgeMap("mmap", mmap);
    3434
    3535  reader.skipEdgeMap<QuotedStringReader>("description");
    3636
    3737  SmartGraph::Node source;
    38   reader.readNode("source", source);
     38  reader.addNode("source", source);
    3939 
    4040  SmartGraph::Edge newedge;
    41   reader.readEdge("newedge", newedge);
     41  reader.addEdge("newedge", newedge);
    4242
    4343  try {
     
    4848    cerr << e.what() << endl;
    4949  }
     50
    5051  for (SmartGraph::NodeIt it(graph); it != INVALID; ++it) {
    5152    cout << cost[it] << ' ' << color[it] << ' ' << description[it] << endl;
     
    5354
    5455  for (SmartGraph::EdgeIt it(graph); it != INVALID; ++it) {
    55     cout << mmap[it] << ' ' << id[graph.source(it)] << ' ' << id[graph.target(it)]  << endl;
     56    cout << mmap[it] << ' ' << id[graph.source(it)] << ' ' <<
     57      id[graph.target(it)]  << endl;
    5658  }
    5759
    58   cout << id[source] << ' ' << cost[source] << ' ' << color[source] << ' ' << description[source] << endl;
    59   cout << mmap[newedge] << ' ' << id[graph.source(newedge)] << ' ' << id[graph.target(newedge)]  << endl;
     60  cout << id[source] << ' ' << cost[source] << ' ' <<
     61    color[source] << ' ' << description[source] << endl;
     62  cout << mmap[newedge] << ' ' << id[graph.source(newedge)] <<
     63    ' ' << id[graph.target(newedge)]  << endl;
    6064
    6165  ofstream output("copy.lgf");
    6266  GraphWriter<SmartGraph> writer(output, graph);
    6367 
    64   DescriptorMap<SmartGraph, SmartGraph::Node, SmartGraph::NodeIt, SmartGraph::NodeMap<int> > node_ids(graph);
     68  DescriptorMap<SmartGraph, SmartGraph::Node, SmartGraph::NodeMap<int> >
     69    node_ids(graph);
    6570 
    66   writer.writeNodeMap("id", node_ids);
    67   writer.writeNodeMap<QuotedStringWriter>("format", description);
     71  writer.addNodeMap("id", node_ids);
     72  writer.addNodeMap<QuotedStringWriter>("format", description);
    6873
    69   DescriptorMap<SmartGraph, SmartGraph::Edge, SmartGraph::EdgeIt, SmartGraph::EdgeMap<int> > edge_ids(graph);
     74  IdMap<SmartGraph, SmartGraph::Edge > edge_ids(graph);
    7075
    71   writer.writeEdgeMap("id", edge_ids);
    72   writer.writeEdgeMap("chars", mmap);
     76  writer.addEdgeMap("id", edge_ids);
     77  writer.addEdgeMap("chars", mmap);
    7378 
    74   writer.writeNode("source", node_ids.inverse()[3]);
    75   writer.writeEdge("elek", edge_ids.inverse()[6]);
     79  writer.addNode("source", node_ids.inverse()[3]);
     80  //  writer.addEdge("elek", edge_ids.inverse()[6]);
    7681  writer.write();
    7782 
  • src/work/deba/graph_reader.h

    r1037 r1115  
    3838  class IOException {
    3939  public:
     40    virtual ~IOException() {}
    4041    virtual string what() const = 0;
    4142  };
     
    5657    typedef _Exception Exception;
    5758    StreamException(int _line, Exception _exception)
    58       : line_num(_line), Exception(_exception) {}
     59      : Exception(_exception), line_num(_line) {}
    5960    virtual int line() const {
    6061      return line_num;
    6162    }
     63
     64    virtual ~StreamException() {}
     65
    6266    virtual std::string what() const {
    6367      ostringstream os;
     
    7175
    7276  // Readers and ReaderTraits
    73  
     77  /// \brief Standard ReaderTraits for the GraphReader class.
     78  ///
     79  ///
     80 
    7481  struct DefaultReaderTraits {
    7582
     
    97104      value.clear();
    98105      is >> ws;
    99       if (!is.get(c) || c != '\"') throw DataFormatException("Quoted string format");
     106      if (!is.get(c) || c != '\"')
     107        throw DataFormatException("Quoted string format");
    100108      while (is.get(c) && c != '\"') {
    101109        if (escaped && c == '\\') {
     
    193201    typedef typename ReaderTraits::DefaultReader DefaultReader;
    194202
    195     GraphReader(std::istream& _is, Graph& _graph, const DefaultReader& _reader = DefaultReader())
     203    GraphReader(std::istream& _is, Graph& _graph,
     204                const DefaultReader& _reader = DefaultReader())
    196205      : is(_is), graph(_graph), nodeSkipper(_reader), edgeSkipper(_reader) {}
    197206
     
    199208    ~GraphReader() {
    200209
    201       for (typename NodeMapReaders::iterator it = node_map_readers.begin(); it != node_map_readers.end(); ++it) {
     210      for (typename NodeMapReaders::iterator it = node_map_readers.begin();
     211           it != node_map_readers.end(); ++it) {
    202212        delete it->second;
    203213      }
    204214
    205       for (typename EdgeMapReaders::iterator it = edge_map_readers.begin(); it != edge_map_readers.end(); ++it) {
     215      for (typename EdgeMapReaders::iterator it = edge_map_readers.begin();
     216           it != edge_map_readers.end(); ++it) {
    206217        delete it->second;
    207218      }
     
    212223
    213224    template <typename Map>
    214     GraphReader& readNodeMap(std::string name, Map& map) {
    215       return readNodeMap<typename ReaderTraits::template Reader<typename Map::Value>, Map>(name, map);
     225    GraphReader& addNodeMap(std::string name, Map& map) {
     226      return addNodeMap<typename ReaderTraits::template
     227        Reader<typename Map::Value>, Map>(name, map);
    216228    }
    217229
    218230    template <typename Reader, typename Map>
    219     GraphReader& readNodeMap(std::string name, Map& map, const Reader& reader = Reader()) {
     231    GraphReader& addNodeMap(std::string name, Map& map,
     232                             const Reader& reader = Reader()) {
    220233      if (node_map_readers.find(name) != node_map_readers.end()) {
    221234        throw Exception() << "Multiple read rule for node map: " << name;
    222235      }
    223       node_map_readers.insert(make_pair(name, new MapReader<Node, Map, Reader>(map, reader)));
     236      node_map_readers.insert(
     237        make_pair(name, new MapReader<Node, Map, Reader>(map, reader)));
    224238      return *this;
    225239    }
    226240
    227241    template <typename Reader>
    228     GraphReader& skipNodeMap(std::string name, const Reader& reader = Reader()) {
     242    GraphReader& skipNodeMap(std::string name,
     243                             const Reader& reader = Reader()) {
    229244      if (node_map_readers.find(name) != node_map_readers.end()) {
    230245        throw Exception() << "Multiple read rule for node map: " << name;
    231246      }
    232       node_map_readers.insert(make_pair(name, new SkipReader<Node, Reader>(reader)));
     247      node_map_readers.insert(
     248        make_pair(name, new SkipReader<Node, Reader>(reader)));
    233249      return *this;
    234250    }
     
    237253
    238254    template <typename Map>
    239     GraphReader& readEdgeMap(std::string name, Map& map) {
    240       return readEdgeMap<typename ReaderTraits::template Reader<typename Map::Value>, Map>(name, map);
     255    GraphReader& addEdgeMap(std::string name, Map& map) {
     256      return addEdgeMap<typename ReaderTraits::template
     257        Reader<typename Map::Value>, Map>(name, map);
    241258    }
    242259
    243260
    244261    template <typename Reader, typename Map>
    245     GraphReader& readEdgeMap(std::string name, Map& map, const Reader& reader = Reader()) {
     262    GraphReader& addEdgeMap(std::string name, Map& map,
     263                             const Reader& reader = Reader()) {
    246264      if (edge_map_readers.find(name) != edge_map_readers.end()) {
    247265        throw Exception() << "Multiple read rule for edge map: " << name;
    248266      }
    249       edge_map_readers.insert(make_pair(name, new MapReader<Edge, Map, Reader>(map, reader)));
     267      edge_map_readers.insert(
     268        make_pair(name, new MapReader<Edge, Map, Reader>(map, reader)));
    250269      return *this;
    251270    }
    252271
    253272    template <typename Reader>
    254     GraphReader& skipEdgeMap(std::string name, const Reader& reader = Reader()) {
     273    GraphReader& skipEdgeMap(std::string name,
     274                             const Reader& reader = Reader()) {
    255275      if (edge_map_readers.find(name) != edge_map_readers.end()) {
    256276        throw Exception() << "Multiple read rule for edge map: " << name;
    257277      }
    258       edge_map_readers.insert(make_pair(name, new SkipReader<Edge, Reader>(reader)));
     278      edge_map_readers.insert(
     279        make_pair(name, new SkipReader<Edge, Reader>(reader)));
    259280      return *this;
    260281    }
    261282
    262283    // Node rules
    263     GraphReader& readNode(std::string name, Node& node) {
     284    GraphReader& addNode(std::string name, Node& node) {
    264285      if (node_readers.find(name) != node_readers.end()) {
    265286        throw Exception() << "Multiple read rule for node";
    266287      }
    267288      node_readers.insert(make_pair(name, &node));
     289      return *this;
    268290    }
    269291
    270292    // Edge rules
    271293
    272     GraphReader& readEdge(std::string name, Edge& edge) {
     294    GraphReader& addEdge(std::string name, Edge& edge) {
    273295      if (edge_readers.find(name) != edge_readers.end()) {
    274296        throw Exception() << "Multiple read rule for edge";
    275297      }
    276298      edge_readers.insert(make_pair(name, &edge));
     299      return *this;
    277300    }
    278301
     
    307330    template <typename Item> class InverterBase;
    308331
    309     std::string readNodeSet(int& line_num, auto_ptr<InverterBase<Node> > & nodeInverter) {
     332    std::string readNodeSet(int& line_num,
     333                            auto_ptr<InverterBase<Node> > & nodeInverter) {
    310334      std::vector<ReaderBase<Node>* > index;
    311335      {
     
    335359        std::istringstream ls(line);
    336360        nodeInverter->read(ls, node);
    337         for (int i = 1; i < index.size(); ++i) {
     361        for (int i = 1; i < (int)index.size(); ++i) {
    338362          index[i]->read(ls, node);
    339363        }
     
    343367
    344368    std::string readEdgeSet(int& line_num,
    345                      auto_ptr<InverterBase<Edge> > & edgeInverter, auto_ptr<InverterBase<Node> > & nodeInverter) {
     369                            auto_ptr<InverterBase<Edge> > & edgeInverter,
     370                            auto_ptr<InverterBase<Node> > & nodeInverter) {
    346371      std::vector<ReaderBase<Edge>*> index;
    347372      {
     
    373398        Edge edge = graph.addEdge(source, target);
    374399        edgeInverter->read(ls, edge);
    375         for (int i = 1; i < index.size(); ++i) {
     400        for (int i = 1; i < (int)index.size(); ++i) {
    376401          index[i]->read(ls, edge);
    377402        }
     
    380405    }
    381406
    382     std::string readNodes(int& line_num, auto_ptr<InverterBase<Node> >& nodeInverter) {
     407    std::string readNodes(int& line_num,
     408                          auto_ptr<InverterBase<Node> >& nodeInverter) {
    383409      std::string line;
    384410      while (line = readNotEmptyLine(is, line_num), line[0] != '@') {
     
    394420    }
    395421
    396     std::string readEdges(int& line_num, auto_ptr<InverterBase<Edge> >& edgeInverter) {
     422    std::string readEdges(int& line_num,
     423                          auto_ptr<InverterBase<Edge> >& edgeInverter) {
    397424      std::string line;
    398425      while (line = readNotEmptyLine(is, line_num), line[0] != '@') {
     
    412439      while (++line_num, getline(is, line)) {   
    413440        int vi = line.find_first_not_of(" \t");
    414         if (vi != string::npos && line[vi] != '#') {
     441        if (vi != (int)string::npos && line[vi] != '#') {
    415442          return line.substr(vi);
    416443        }
     
    446473        : map(_map), reader(_reader) {}
    447474
     475      virtual ~MapReaderInverter() {}
     476
    448477      virtual void read(std::istream& is, const Item& item) {
    449478        Value value;
     
    483512        : reader(_reader) {}
    484513
     514      virtual ~SkipReaderInverter() {}
     515
    485516      virtual void read(std::istream& is, const Item& item) {
    486517        Value value;
     
    514545    public:
    515546      typedef _Item Item;
     547
     548      //      virtual ~ReaderBase() {}
    516549
    517550      virtual void read(std::istream& is, const Item& item) = 0;
     
    533566        : map(_map), reader(_reader) {}
    534567
     568      virtual ~MapReader() {}
    535569
    536570      virtual void read(std::istream& is, const Item& item) {
     
    556590      SkipReader(const Reader& _reader) : reader(_reader) {}
    557591
     592      virtual ~SkipReader() {}
     593
    558594      virtual void read(std::istream& is, const Item& item) {
    559595        Value value;
  • src/work/deba/graph_writer.h

    r1037 r1115  
    5555
    5656    void write(std::ostream& os, const std::string& value) {
    57       char c;
    5857      os << "\"";
    5958      if (escaped) {
    6059        ostringstream ls;
    61         for (int i = 0; i < value.size(); ++i) {
     60        for (int i = 0; i < (int)value.size(); ++i) {
    6261          writeEscape(ls, value[i]);
    6362        }
     
    137136
    138137    ~GraphWriter() {
    139 
    140       for (typename NodeMapWriters::iterator it = node_map_writers.begin(); it != node_map_writers.end(); ++it) {
     138      for (typename NodeMapWriters::iterator it = node_map_writers.begin();
     139          it != node_map_writers.end(); ++it) {
    141140        delete it->second;
    142141      }
    143142
    144       for (typename EdgeMapWriters::iterator it = edge_map_writers.begin(); it != edge_map_writers.end(); ++it) {
     143      for (typename EdgeMapWriters::iterator it = edge_map_writers.begin();
     144           it != edge_map_writers.end(); ++it) {
    145145        delete it->second;
    146146      }
     
    151151
    152152    template <typename Map>
    153     GraphWriter& writeNodeMap(std::string name, const Map& map) {
    154       return writeNodeMap<typename WriterTraits::template Writer<typename Map::Value>, Map>(name, map);
     153    GraphWriter& addNodeMap(std::string name, const Map& map) {
     154      return addNodeMap<typename WriterTraits::template Writer<
     155        typename Map::Value>, Map>(name, map);
    155156    }
    156157
    157158    template <typename Writer, typename Map>
    158     GraphWriter& writeNodeMap(std::string name, const Map& map, const Writer& writer = Writer()) {
     159    GraphWriter& addNodeMap(std::string name, const Map& map,
     160                              const Writer& writer = Writer()) {
    159161      //      if (node_map_writers.find(name) != node_map_writers.end()) {
    160       //        throw Exception() << "Multiple write rule for node map: " << name;
     162      //        throw Exception() << "Multiple write rule for node map: "
     163      //        << name;
    161164      //      }
    162       node_map_writers.push_back(make_pair(name, new MapWriter<Node, Map, Writer>(map, writer)));
     165      node_map_writers.push_back(
     166        make_pair(name, new MapWriter<Node, Map, Writer>(map, writer)));
    163167      return *this;
    164168    }
     
    167171
    168172    template <typename Map>
    169     GraphWriter& writeEdgeMap(std::string name, const Map& map) {
    170       return writeEdgeMap<typename WriterTraits::template Writer<typename Map::Value>, Map>(name, map);
     173    GraphWriter& addEdgeMap(std::string name, const Map& map) {
     174      return addEdgeMap<typename WriterTraits::template Writer<typename Map::Value>, Map>(name, map);
    171175    }
    172176
    173177
    174178    template <typename Writer, typename Map>
    175     GraphWriter& writeEdgeMap(std::string name, const Map& map, const Writer& writer = Writer()) {
     179    GraphWriter& addEdgeMap(std::string name, const Map& map, const Writer& writer = Writer()) {
    176180      //      if (edge_map_writers.find(name) != edge_map_writers.end()) {
    177181      //        throw Exception() << "Multiple write rule for edge map: " << name;
     
    182186
    183187    // Node rules
    184     GraphWriter& writeNode(std::string name, const Node& node) {
     188    GraphWriter& addNode(std::string name, const Node& node) {
    185189      //      if (node_writers.find(name) != node_writers.end()) {
    186190      //        throw Exception() << "Multiple write rule for node";
    187191      //      }
    188192      node_writers.push_back(make_pair(name, node));
     193      return *this;
    189194    }
    190195
    191196    // Edge rules
    192197
    193     GraphWriter& writeEdge(std::string name, const Edge& edge) {
     198    GraphWriter& addEdge(std::string name, const Edge& edge) {
    194199      //      if (edge_writers.find(name) != edge_writers.end()) {
    195200      //        throw Exception() << "Multiple write rule for edge";
    196201      //      }
    197202      edge_writers.push_back(make_pair(name, edge));
     203      return *this;
    198204    }
    199205
     
    211217      if (node_map_writers.size() == 0) return;
    212218      os << "@nodeset" << std::endl;
    213       for (int i = 0; i < node_map_writers.size(); ++i) {
     219      for (int i = 0; i < (int)node_map_writers.size(); ++i) {
    214220        os << node_map_writers[i].first << '\t';
    215221      }
    216222      os << std::endl;
    217223      for (NodeIt it(graph); it != INVALID; ++it) {
    218         for (int i = 0; i < node_map_writers.size(); ++i) {
     224        for (int i = 0; i < (int)node_map_writers.size(); ++i) {
    219225          node_map_writers[i].second->write(os, it);
    220226        }
     
    231237      os << "@edgeset" << std::endl;
    232238      os << "\t\t";
    233       for (int i = 0; i < edge_map_writers.size(); ++i) {
     239      for (int i = 0; i < (int)edge_map_writers.size(); ++i) {
    234240        os << edge_map_writers[i].first << '\t';
    235241      }
     
    238244        node_map_writers[0].second->write(os, graph.source(it));
    239245        node_map_writers[0].second->write(os, graph.target(it));
    240         for (int i = 0; i < edge_map_writers.size(); ++i) {
     246        for (int i = 0; i < (int)edge_map_writers.size(); ++i) {
    241247          edge_map_writers[i].second->write(os, it);
    242248        }
     
    251257      }
    252258      os << "@nodes" << std::endl;
    253       for (int i = 0; i < node_writers.size(); ++i) {
     259      for (int i = 0; i < (int)node_writers.size(); ++i) {
    254260        os << node_writers[i].first << '\t';
    255261        node_map_writers[0].second->write(os, node_writers[i].second);
     
    264270      }
    265271      os << "@edges" << std::endl;
    266       for (int i = 0; i < edge_writers.size(); ++i) {
     272      for (int i = 0; i < (int)edge_writers.size(); ++i) {
    267273        os << edge_writers[i].first << '\t';
    268274        edge_map_writers[0].second->write(os, edge_writers[i].second);
     
    296302
    297303      virtual void write(std::ostream& os, const Item& item) {
    298         Value value;
    299304        writer.write(os, map[item]);
    300305      }
     
    304309
    305310
    306     typedef std::vector< std::pair<std::string, WriterBase<Node>*> > NodeMapWriters;
     311    typedef std::vector< std::pair<std::string, WriterBase<Node>*> >
     312      NodeMapWriters;
    307313    NodeMapWriters node_map_writers;
    308314
    309     typedef std::vector< std::pair<std::string, WriterBase<Edge>*> > EdgeMapWriters;
     315    typedef std::vector< std::pair<std::string, WriterBase<Edge>*> >
     316      EdgeMapWriters;
    310317    EdgeMapWriters edge_map_writers;
    311318
  • src/work/deba/map_utils.h

    r1037 r1115  
    1515 */
    1616
    17 ///\ingroup gutils
     17///\ingroup mutils
    1818///\file
    1919///\brief Map utilities.
     
    5050    typedef typename _Map::ConstReference ConstReference;
    5151
    52     /// Constructor.
    53 
     52    /// \brief Constructor.
     53    ///
    5454    /// Construct a new InversableMap for the graph.
    5555    ///
    5656    InversableMap(const Graph& graph) : Map(graph) {}
    5757   
    58     /// The setter function of the map.
    59 
    60     /// It sets the map and the inverse map
     58    /// \brief The setter function of the map.
     59    ///
     60    /// It sets the map and the inverse map to given key-value pair.
    6161    void set(const Key& key, const Value& val) {
    6262      Value oldval = Map::operator[](key);
     
    9696
    9797
    98   // unique, continous, mutable
     98 
     99  /// \brief Provides a mutable, continous and unique descriptor for each
     100  /// item in the graph.
     101  ///
     102  /// The DescriptorMap class provides a mutable, continous and immutable
     103  /// mapping for each item in the graph.
     104  ///
     105  /// \param _Graph The graph class the \c DescriptorMap belongs to.
     106  /// \param _Item The Item is the Key of the Map. It may be Node, Edge or
     107  /// UndirEdge.
     108  /// \param _Map A ReadWriteMap mapping from the item type to integer.
    99109
    100110  template <
    101111    typename _Graph,   
    102112    typename _Item,
    103     typename _ItemIt,
    104113    typename _Map
    105114  >
    106115  class DescriptorMap : protected _Map {
     116
     117    typedef _Item Item;
     118    typedef _Map Map;
     119
    107120  public:
     121    /// The graph class of DescriptorMap.
    108122    typedef _Graph Graph;
    109     typedef _Item Item;
    110     typedef _ItemIt ItemIt;
    111     typedef _Map Map;
    112 
    113 
     123
     124    /// The key type of DescriptorMap (Node, Edge, UndirEdge).
    114125    typedef typename _Map::Key Key;
     126    /// The value type of DescriptorMap.
    115127    typedef typename _Map::Value Value;
    116128
    117     typedef vector<Item> InverseMap;
    118 
     129    typedef std::vector<Item> InverseMap;
     130
     131    /// \brief Constructor.
     132    ///
     133    /// Constructor for creating descriptor map.
    119134    DescriptorMap(const Graph& _graph) : Map(_graph) {
    120135      build();
     
    135150    virtual void build() {
    136151      Map::build();
    137       for (ItemIt it(*Map::getGraph()); it != INVALID; ++it) {
     152      Item it;
     153      for (getGraph()->first(it); it != INVALID; getGraph()->next(it)) {
    138154        Map::set(it, inv_map.size());
    139155        inv_map.push_back(it); 
     
    146162    }
    147163
     164    /// \brief Gives back the \e descriptor of the item.
     165    ///
     166    /// Gives back the mutable and unique \e descriptor of the map.
    148167    int operator[](const Item& item) const {
    149168      return Map::operator[](item);
    150169    }
    151 
    152    
     170   
     171    /// \brief Gives back the inverse of the map.
     172    ///
     173    /// Gives back the inverse of the map.
    153174    const InverseMap inverse() const {
    154175      return inv_map;
     
    158179    vector<Item> inv_map;
    159180  };
    160 
    161   // unique, immutable => IDMap
    162181 
    163  
     182  /// Provides an immutable and unique id for each item in the graph.
     183
     184  /// The IdMap class provides an unique and immutable mapping for each item
     185  /// in the graph.
     186  ///
     187  template <typename _Graph, typename _Item>
     188  class IdMap {
     189  public:
     190    typedef _Graph Graph;
     191    typedef int Value;
     192    typedef _Item Item;
     193
     194    /// \brief The class represents the inverse of the map.
     195    ///
     196    /// The class represents the inverse of the map.
     197    /// \see inverse()
     198    class InverseMap {
     199    protected:
     200      InverseMap(const Graph& _graph) : graph(_graph) {}
     201    public:
     202      /// \brief Gives back the given item by its id.
     203      ///
     204      /// Gives back the given item by its id.
     205      ///
     206      Item operator[](int id) const { return graph->fromId(id, Item());}
     207    private:
     208      Graph* graph;
     209    };
     210
     211    /// \brief Constructor.
     212    ///
     213    /// Constructor for creating id map.
     214    IdMap(const Graph& _graph) : graph(&_graph) {}
     215
     216    /// \brief Gives back the \e id of the item.
     217    ///
     218    /// Gives back the immutable and unique \e id of the map.
     219    int operator[](const Item& item) const { return graph->id(item);}
     220
     221    /// \brief Gives back the inverse of the map.
     222    ///
     223    /// Gives back the inverse of the map.
     224    InverseMap inverse() const { return InverseMap(*graph);}
     225
     226  private:
     227    const Graph* graph;
     228
     229  };
     230
     231
    164232
    165233}
Note: See TracChangeset for help on using the changeset viewer.