COIN-OR::LEMON - Graph Library

Changeset 1133:9fd485470fee in lemon-0.x


Ignore:
Timestamp:
02/07/05 11:48:14 (20 years ago)
Author:
Balazs Dezso
Branch:
default
Phase:
public
Convert:
svn:c9d7d8f5-90d6-0310-b91f-818b3a526b0e/lemon/trunk@1532
Message:

Documentation

Location:
src/work/deba
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • src/work/deba/graph_reader.h

    r1115 r1133  
    7474
    7575
    76   // Readers and ReaderTraits
    7776  /// \brief Standard ReaderTraits for the GraphReader class.
    7877  ///
    79   ///
    80  
     78  /// Standard ReaderTraits for the GraphReader class.
     79  /// It defines standard reading method for all type of value.
    8180  struct DefaultReaderTraits {
    8281
     82    /// \brief Template class for reading an value.
     83    ///
     84    /// Template class for reading an value.
    8385    template <typename _Value>
    8486    struct Reader {
     87      /// The value type.
    8588      typedef _Value Value;
     89      /// \brief Reads a value from the given stream.
     90      ///
     91      /// Reads a value from the given stream.
    8692      void read(std::istream& is, Value& value) {
    8793        if (!(is >> value))
     
    9096    };
    9197
     98    /// The reader class for the not needed maps.
    9299    typedef Reader<std::string> DefaultReader;
    93100
    94101  };
    95102
     103  /// \brief Reader class for quoted strings.
     104  ///
     105  /// Reader class for quoted strings. It can process the escape
     106  /// sequences in the string.
    96107  class QuotedStringReader {
    97108  public:
    98109    typedef std::string Value;
    99 
     110   
     111    /// \brief Constructor for the reader.
     112    ///
     113    /// Constructor for the reader. If the given parameter is true
     114    /// the reader processes the escape sequences.
    100115    QuotedStringReader(bool _escaped = true) : escaped(_escaped) {}
    101 
     116   
     117    /// \brief Reads a quoted string from the given stream.
     118    ///
     119    /// Reads a quoted string from the given stream.
    102120    void read(std::istream& is, std::string& value) {
    103121      char c;
     
    146164        {
    147165          int code;
    148           if (!is.get(c) || !isHex(c)) throw DataFormatException("Escape format exception");
     166          if (!is.get(c) || !isHex(c))
     167            throw DataFormatException("Escape format exception");
    149168          else if (code = valueHex(c), !is.get(c) || !isHex(c)) is.putback(c);
    150169          else code = code * 16 + valueHex(c);
     
    154173        {
    155174          int code;
    156           if (!isOct(c)) throw DataFormatException("Escape format exception");
    157           else if (code = valueOct(c), !is.get(c) || !isOct(c)) is.putback(c);
    158           else if (code = code * 8 + valueOct(c), !is.get(c) || !isOct(c)) is.putback(c);
     175          if (!isOct(c))
     176            throw DataFormatException("Escape format exception");
     177          else if (code = valueOct(c), !is.get(c) || !isOct(c))
     178            is.putback(c);
     179          else if (code = code * 8 + valueOct(c), !is.get(c) || !isOct(c))
     180            is.putback(c);
    159181          else code = code * 8 + valueOct(c);
    160182          return code;
     
    172194
    173195   static bool isHex(char c) {
    174       return ('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
     196      return ('0' <= c && c <= '9') ||
     197        ('a' <= c && c <= 'z') ||
     198        ('A' <= c && c <= 'Z');
    175199    }
    176200   
     
    184208  };
    185209
    186 
    187 
    188 
    189 
    190   // Graph reader
    191  
     210  /// \brief The graph reader class.
     211  ///
     212  /// The reader class for the graph input.
     213  /// \see graph-io-page
    192214  template <typename _Graph, typename _ReaderTraits = DefaultReaderTraits>
    193215  class GraphReader {
     
    201223    typedef typename ReaderTraits::DefaultReader DefaultReader;
    202224
     225    /// \brief Construct a new GraphReader.
     226    ///
     227    /// Construct a new GraphReader. It reads from the given map,
     228    /// it constructs the given map and it use the given reader as the
     229    /// default skipper.
    203230    GraphReader(std::istream& _is, Graph& _graph,
    204231                const DefaultReader& _reader = DefaultReader())
    205232      : is(_is), graph(_graph), nodeSkipper(_reader), edgeSkipper(_reader) {}
    206233
    207 
     234    /// \brief Destruct the graph reader.
     235    ///
     236    /// Destruct the graph reader.
    208237    ~GraphReader() {
    209238
     
    220249    }
    221250
    222     // Node map rules
    223 
     251    /// \brief Add a new node map reader command for the reader.
     252    ///
     253    /// Add a new node map reader command for the reader.
    224254    template <typename Map>
    225255    GraphReader& addNodeMap(std::string name, Map& map) {
     
    228258    }
    229259
     260    /// \brief Add a new node map reader command for the reader.
     261    ///
     262    /// Add a new node map reader command for the reader.
    230263    template <typename Reader, typename Map>
    231264    GraphReader& addNodeMap(std::string name, Map& map,
     
    239272    }
    240273
     274    /// \brief Add a new node map skipper command for the reader.
     275    ///
     276    /// Add a new node map skipper command for the reader.
    241277    template <typename Reader>
    242278    GraphReader& skipNodeMap(std::string name,
     
    250286    }
    251287
    252     // Edge map rules
    253 
     288    /// \brief Add a new edge map reader command for the reader.
     289    ///
     290    /// Add a new edge map reader command for the reader.
    254291    template <typename Map>
    255292    GraphReader& addEdgeMap(std::string name, Map& map) {
     
    259296
    260297
     298    /// \brief Add a new edge map reader command for the reader.
     299    ///
     300    /// Add a new edge map reader command for the reader.
    261301    template <typename Reader, typename Map>
    262302    GraphReader& addEdgeMap(std::string name, Map& map,
     
    270310    }
    271311
     312    /// \brief Add a new edge map skipper command for the reader.
     313    ///
     314    /// Add a new edge map skipper command for the reader.
    272315    template <typename Reader>
    273316    GraphReader& skipEdgeMap(std::string name,
     
    281324    }
    282325
    283     // Node rules
     326    /// \brief Add a new labeled node reader for the reader.
     327    ///
     328    /// Add a new labeled node reader for the reader.
    284329    GraphReader& addNode(std::string name, Node& node) {
    285330      if (node_readers.find(name) != node_readers.end()) {
     
    290335    }
    291336
    292     // Edge rules
    293 
     337    /// \brief Add a new labeled edge reader for the reader.
     338    ///
     339    /// Add a new labeled edge reader for the reader.
    294340    GraphReader& addEdge(std::string name, Edge& edge) {
    295341      if (edge_readers.find(name) != edge_readers.end()) {
     
    300346    }
    301347
    302     void read() {
     348    /// \brief Executes the reader commands.
     349    ///
     350    /// Executes the reader commands.
     351    void run() {
    303352      int line_num = 0;
    304353      std::auto_ptr<InverterBase<Node> > nodeInverter;
  • src/work/deba/graph_writer.h

    r1115 r1133  
    3434namespace lemon {
    3535
     36  /// \brief Standard WriterTraits for the GraphWriter class.
     37  ///
     38  /// Standard WriterTraits for the GraphWriter class.
     39  /// It defines standard writing method for all type of value.
    3640  struct DefaultWriterTraits {
    3741
     42    /// \brief Template class for writing an value.
     43    ///
     44    /// Template class for writing an value.
    3845    template <typename _Value>
    3946    struct Writer {
     47      /// The value type.
    4048      typedef _Value Value;
    4149
     50      /// \brief Writes a value from the given stream.
     51      ///
     52      /// Writes a value from the given stream.
    4253      void write(std::ostream& os, const Value& value) {
    4354        os << value << '\t';
     
    4859
    4960
     61  /// \brief Writer class for quoted strings.
     62  ///
     63  /// Writer class for quoted strings. It can process the escape
     64  /// sequences in the string.
    5065  class QuotedStringWriter {
    5166  public:
    5267    typedef std::string Value;
    5368
     69    /// \brief Constructor for the writer.
     70    ///
     71    /// Constructor for the writer. If the given parameter is true
     72    /// the writer creates escape sequences from special characters.
    5473    QuotedStringWriter(bool _escaped = true) : escaped(_escaped) {}
    5574
     75    /// \brief Writes a quoted string from the given stream.
     76    ///
     77    /// Writes a quoted string from the given stream.
    5678    void write(std::ostream& os, const std::string& value) {
    5779      os << "\"";
     
    118140  };
    119141
    120   // Graph writer
    121142 
     143  /// \brief The graph writer class.
     144  ///
     145  /// The writer class for the graph output.
     146  /// \see graph-io-page
    122147  template <typename _Graph, typename _WriterTraits = DefaultWriterTraits>
    123148  class GraphWriter {
     
    131156
    132157    typedef _WriterTraits WriterTraits;
    133 
     158 
     159    /// \brief Construct a new GraphWriter.
     160    ///
     161    /// Construct a new GraphWriter. It writes from the given map,
     162    /// it constructs the given map and it use the given writer as the
     163    /// default skipper.
    134164    GraphWriter(std::ostream& _os, Graph& _graph) : os(_os), graph(_graph) {}
    135165
    136166
     167    /// \brief Destruct the graph writer.
     168    ///
     169    /// Destruct the graph writer.
    137170    ~GraphWriter() {
    138171      for (typename NodeMapWriters::iterator it = node_map_writers.begin();
     
    150183    // Node map rules
    151184
     185    /// \brief Add a new node map writer command for the writer.
     186    ///
     187    /// Add a new node map writer command for the writer.
    152188    template <typename Map>
    153189    GraphWriter& addNodeMap(std::string name, const Map& map) {
     
    156192    }
    157193
     194    /// \brief Add a new node map writer command for the writer.
     195    ///
     196    /// Add a new node map writer command for the writer.
    158197    template <typename Writer, typename Map>
    159198    GraphWriter& addNodeMap(std::string name, const Map& map,
    160199                              const Writer& writer = Writer()) {
    161       //      if (node_map_writers.find(name) != node_map_writers.end()) {
    162       //        throw Exception() << "Multiple write rule for node map: "
    163       //        << name;
    164       //      }
    165200      node_map_writers.push_back(
    166201        make_pair(name, new MapWriter<Node, Map, Writer>(map, writer)));
     
    170205    // Edge map rules
    171206
     207    /// \brief Add a new edge map writer command for the writer.
     208    ///
     209    /// Add a new edge map writer command for the writer.
    172210    template <typename Map>
    173211    GraphWriter& addEdgeMap(std::string name, const Map& map) {
    174       return addEdgeMap<typename WriterTraits::template Writer<typename Map::Value>, Map>(name, map);
    175     }
    176 
    177 
     212      return addEdgeMap<typename WriterTraits::template Writer<
     213        typename Map::Value>, Map>(name, map);
     214    }
     215
     216
     217    /// \brief Add a new edge map writer command for the writer.
     218    ///
     219    /// Add a new edge map writer command for the writer.
    178220    template <typename Writer, typename Map>
    179     GraphWriter& addEdgeMap(std::string name, const Map& map, const Writer& writer = Writer()) {
    180       //      if (edge_map_writers.find(name) != edge_map_writers.end()) {
    181       //        throw Exception() << "Multiple write rule for edge map: " << name;
    182       //      }
    183       edge_map_writers.push_back(make_pair(name, new MapWriter<Edge, Map, Writer>(map, writer)));
     221    GraphWriter& addEdgeMap(std::string name,
     222                            const Map& map, const Writer& writer = Writer()) {
     223      edge_map_writers.push_back(make_pair(name,
     224        new MapWriter<Edge, Map, Writer>(map, writer)));
    184225      return *this;
    185226    }
    186227
    187     // Node rules
     228    /// \brief Add a new labeled node writer for the writer.
     229    ///
     230    /// Add a new labeled node writer for the writer.
    188231    GraphWriter& addNode(std::string name, const Node& node) {
    189       //      if (node_writers.find(name) != node_writers.end()) {
    190       //        throw Exception() << "Multiple write rule for node";
    191       //      }
    192232      node_writers.push_back(make_pair(name, node));
    193233      return *this;
    194234    }
    195235
    196     // Edge rules
    197 
     236    /// \brief Add a new labeled edge writer for the writer.
     237    ///
     238    /// Add a new labeled edge writer for the writer.
    198239    GraphWriter& addEdge(std::string name, const Edge& edge) {
    199       //      if (edge_writers.find(name) != edge_writers.end()) {
    200       //        throw Exception() << "Multiple write rule for edge";
    201       //      }
    202240      edge_writers.push_back(make_pair(name, edge));
    203241      return *this;
    204242    }
    205243
    206     void write() {   
     244    /// \brief Executes the writer commands.
     245    ///
     246    /// Executes the writer commands.
     247    void run() {   
    207248      writeNodeSet();
    208249      writeEdgeSet();
  • src/work/deba/map_utils.h

    r1115 r1133  
    2424namespace lemon {
    2525
    26   /// \addtogroup gutils
     26  /// \addtogroup mutils
    2727  /// @{
    28 
    2928
    3029  /// \brief General inversable map type.
     
    3433  /// and if a key is setted to a new value then store it
    3534  /// in the inverse map.
     35  /// \param _Graph The graph type.
     36  /// \param _Map The map to extend with inversable functionality.
    3637  template <
    3738    typename _Graph,
     
    4445
    4546    typedef _Map Map;
     47    /// The key type of InversableMap (Node, Edge, UndirEdge).
    4648    typedef typename _Map::Key Key;
     49    /// The value type of the InversableMap.
    4750    typedef typename _Map::Value Value;
    4851    typedef std::map<Value, Key> InverseMap;
     
    6164    void set(const Key& key, const Value& val) {
    6265      Value oldval = Map::operator[](key);
    63       typename InverseMap::iterator it = inv_map.find(oldval);
    64       if (it != inv_map.end() && it->second == key) {
    65         inv_map.erase(it);
     66      typename InverseMap::iterator it = invMap.find(oldval);
     67      if (it != invMap.end() && it->second == key) {
     68        invMap.erase(it);
    6669      }     
    67       inv_map.insert(make_pair(val, key));
     70      invMap.insert(make_pair(val, key));
    6871      Map::set(key, val);
    6972    }
    7073
    71     ConstReference operator[](const Key&) const {
     74    /// \brief The getter function of the map.
     75    ///
     76    /// It gives back the value associated with the key.
     77    ConstReference operator[](const Key& key) const {
    7278      return Map::operator[](key);
    7379    }
    7480
    75     virtual void add(const Key&) {
     81    /// \brief Add a new key to the map.
     82    ///
     83    /// Add a new key to the map. It is called by the
     84    /// \c AlterationNotifier.
     85    virtual void add(const Key& key) {
    7686      Map::add(key);
    7787    }
    7888
    79     virtual void erase(const Key&) {
     89    /// \brief Erase the key from the map.
     90    ///
     91    /// Erase the key to the map. It is called by the
     92    /// \c AlterationNotifier.
     93    virtual void erase(const Key& key) {
    8094      Value val = Map::operator[](key);
    81       typename InverseMap::iterator it = inv_map.find(val);
    82       if (it != inv_map.end() && it->second == key) {
     95      typename InverseMap::iterator it = invMap.find(val);
     96      if (it != invMap.end() && it->second == key) {
    8397        invMap.erase(it);
    8498      }
     
    86100    }
    87101
     102    /// \brief Clear the keys from the map and inverse map.
     103    ///
     104    /// Clear the keys from the map and inverse map. It is called by the
     105    /// \c AlterationNotifier.
     106    virtual void clear() {
     107      invMap.clear();
     108      Map::clear();
     109    }
     110
     111    /// \brief It gives back the just readeable inverse map.
     112    ///
     113    /// It gives back the just readeable inverse map.
    88114    const InverseMap& inverse() const {
    89       return inv_map;
     115      return invMap;
    90116    }
    91117
    92118
    93119  private:
    94     InverseMap inv_map;   
     120    InverseMap invMap;   
    95121  };
    96122
     
    136162    }
    137163
     164    /// \brief Add a new key to the map.
     165    ///
     166    /// Add a new key to the map. It is called by the
     167    /// \c AlterationNotifier.
    138168    virtual void add(const Item& item) {
    139169      Map::add(item);
    140       Map::set(item, inv_map.size());
    141       inv_map.push_back(item);
    142     }
    143 
     170      Map::set(item, invMap.size());
     171      invMap.push_back(item);
     172    }
     173
     174    /// \brief Erase the key from the map.
     175    ///
     176    /// Erase the key to the map. It is called by the
     177    /// \c AlterationNotifier.
    144178    virtual void erase(const Item& item) {
    145       Map::set(inv_map.back(), Map::operator[](item));
    146       inv_map[Map::operator[](item)] = inv_map.back();
     179      Map::set(invMap.back(), Map::operator[](item));
     180      invMap[Map::operator[](item)] = invMap.back();
    147181      Map::erase(item);
    148182    }
    149183
     184    /// \brief Build the unique map.
     185    ///
     186    /// Build the unique map. It is called by the
     187    /// \c AlterationNotifier.
    150188    virtual void build() {
    151189      Map::build();
    152190      Item it;
    153191      for (getGraph()->first(it); it != INVALID; getGraph()->next(it)) {
    154         Map::set(it, inv_map.size());
    155         inv_map.push_back(it); 
     192        Map::set(it, invMap.size());
     193        invMap.push_back(it);   
    156194      }     
    157195    }
    158196   
     197    /// \brief Clear the keys from the map.
     198    ///
     199    /// Clear the keys from the map. It is called by the
     200    /// \c AlterationNotifier.
    159201    virtual void clear() {
    160       inv_map.clear();
     202      invMap.clear();
    161203      Map::clear();
    162204    }
     
    173215    /// Gives back the inverse of the map.
    174216    const InverseMap inverse() const {
    175       return inv_map;
     217      return invMap;
    176218    }
    177219
    178220  private:
    179     vector<Item> inv_map;
     221    vector<Item> invMap;
    180222  };
    181223 
Note: See TracChangeset for help on using the changeset viewer.