1.1 --- a/src/work/deba/graph_reader.h Sun Feb 06 20:14:30 2005 +0000
1.2 +++ b/src/work/deba/graph_reader.h Mon Feb 07 10:48:14 2005 +0000
1.3 @@ -73,32 +73,50 @@
1.4 };
1.5
1.6
1.7 - // Readers and ReaderTraits
1.8 /// \brief Standard ReaderTraits for the GraphReader class.
1.9 ///
1.10 - ///
1.11 -
1.12 + /// Standard ReaderTraits for the GraphReader class.
1.13 + /// It defines standard reading method for all type of value.
1.14 struct DefaultReaderTraits {
1.15
1.16 + /// \brief Template class for reading an value.
1.17 + ///
1.18 + /// Template class for reading an value.
1.19 template <typename _Value>
1.20 struct Reader {
1.21 + /// The value type.
1.22 typedef _Value Value;
1.23 + /// \brief Reads a value from the given stream.
1.24 + ///
1.25 + /// Reads a value from the given stream.
1.26 void read(std::istream& is, Value& value) {
1.27 if (!(is >> value))
1.28 throw DataFormatException("Default Reader format exception");
1.29 }
1.30 };
1.31
1.32 + /// The reader class for the not needed maps.
1.33 typedef Reader<std::string> DefaultReader;
1.34
1.35 };
1.36
1.37 + /// \brief Reader class for quoted strings.
1.38 + ///
1.39 + /// Reader class for quoted strings. It can process the escape
1.40 + /// sequences in the string.
1.41 class QuotedStringReader {
1.42 public:
1.43 typedef std::string Value;
1.44 -
1.45 +
1.46 + /// \brief Constructor for the reader.
1.47 + ///
1.48 + /// Constructor for the reader. If the given parameter is true
1.49 + /// the reader processes the escape sequences.
1.50 QuotedStringReader(bool _escaped = true) : escaped(_escaped) {}
1.51 -
1.52 +
1.53 + /// \brief Reads a quoted string from the given stream.
1.54 + ///
1.55 + /// Reads a quoted string from the given stream.
1.56 void read(std::istream& is, std::string& value) {
1.57 char c;
1.58 value.clear();
1.59 @@ -145,7 +163,8 @@
1.60 case 'x':
1.61 {
1.62 int code;
1.63 - if (!is.get(c) || !isHex(c)) throw DataFormatException("Escape format exception");
1.64 + if (!is.get(c) || !isHex(c))
1.65 + throw DataFormatException("Escape format exception");
1.66 else if (code = valueHex(c), !is.get(c) || !isHex(c)) is.putback(c);
1.67 else code = code * 16 + valueHex(c);
1.68 return code;
1.69 @@ -153,9 +172,12 @@
1.70 default:
1.71 {
1.72 int code;
1.73 - if (!isOct(c)) throw DataFormatException("Escape format exception");
1.74 - else if (code = valueOct(c), !is.get(c) || !isOct(c)) is.putback(c);
1.75 - else if (code = code * 8 + valueOct(c), !is.get(c) || !isOct(c)) is.putback(c);
1.76 + if (!isOct(c))
1.77 + throw DataFormatException("Escape format exception");
1.78 + else if (code = valueOct(c), !is.get(c) || !isOct(c))
1.79 + is.putback(c);
1.80 + else if (code = code * 8 + valueOct(c), !is.get(c) || !isOct(c))
1.81 + is.putback(c);
1.82 else code = code * 8 + valueOct(c);
1.83 return code;
1.84 }
1.85 @@ -171,7 +193,9 @@
1.86 }
1.87
1.88 static bool isHex(char c) {
1.89 - return ('0' <= c && c <= '9') || ('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z');
1.90 + return ('0' <= c && c <= '9') ||
1.91 + ('a' <= c && c <= 'z') ||
1.92 + ('A' <= c && c <= 'Z');
1.93 }
1.94
1.95 static int valueHex(char c) {
1.96 @@ -183,12 +207,10 @@
1.97 bool escaped;
1.98 };
1.99
1.100 -
1.101 -
1.102 -
1.103 -
1.104 - // Graph reader
1.105 -
1.106 + /// \brief The graph reader class.
1.107 + ///
1.108 + /// The reader class for the graph input.
1.109 + /// \see graph-io-page
1.110 template <typename _Graph, typename _ReaderTraits = DefaultReaderTraits>
1.111 class GraphReader {
1.112 public:
1.113 @@ -200,11 +222,18 @@
1.114 typedef _ReaderTraits ReaderTraits;
1.115 typedef typename ReaderTraits::DefaultReader DefaultReader;
1.116
1.117 + /// \brief Construct a new GraphReader.
1.118 + ///
1.119 + /// Construct a new GraphReader. It reads from the given map,
1.120 + /// it constructs the given map and it use the given reader as the
1.121 + /// default skipper.
1.122 GraphReader(std::istream& _is, Graph& _graph,
1.123 const DefaultReader& _reader = DefaultReader())
1.124 : is(_is), graph(_graph), nodeSkipper(_reader), edgeSkipper(_reader) {}
1.125
1.126 -
1.127 + /// \brief Destruct the graph reader.
1.128 + ///
1.129 + /// Destruct the graph reader.
1.130 ~GraphReader() {
1.131
1.132 for (typename NodeMapReaders::iterator it = node_map_readers.begin();
1.133 @@ -219,14 +248,18 @@
1.134
1.135 }
1.136
1.137 - // Node map rules
1.138 -
1.139 + /// \brief Add a new node map reader command for the reader.
1.140 + ///
1.141 + /// Add a new node map reader command for the reader.
1.142 template <typename Map>
1.143 GraphReader& addNodeMap(std::string name, Map& map) {
1.144 return addNodeMap<typename ReaderTraits::template
1.145 Reader<typename Map::Value>, Map>(name, map);
1.146 }
1.147
1.148 + /// \brief Add a new node map reader command for the reader.
1.149 + ///
1.150 + /// Add a new node map reader command for the reader.
1.151 template <typename Reader, typename Map>
1.152 GraphReader& addNodeMap(std::string name, Map& map,
1.153 const Reader& reader = Reader()) {
1.154 @@ -238,6 +271,9 @@
1.155 return *this;
1.156 }
1.157
1.158 + /// \brief Add a new node map skipper command for the reader.
1.159 + ///
1.160 + /// Add a new node map skipper command for the reader.
1.161 template <typename Reader>
1.162 GraphReader& skipNodeMap(std::string name,
1.163 const Reader& reader = Reader()) {
1.164 @@ -249,8 +285,9 @@
1.165 return *this;
1.166 }
1.167
1.168 - // Edge map rules
1.169 -
1.170 + /// \brief Add a new edge map reader command for the reader.
1.171 + ///
1.172 + /// Add a new edge map reader command for the reader.
1.173 template <typename Map>
1.174 GraphReader& addEdgeMap(std::string name, Map& map) {
1.175 return addEdgeMap<typename ReaderTraits::template
1.176 @@ -258,6 +295,9 @@
1.177 }
1.178
1.179
1.180 + /// \brief Add a new edge map reader command for the reader.
1.181 + ///
1.182 + /// Add a new edge map reader command for the reader.
1.183 template <typename Reader, typename Map>
1.184 GraphReader& addEdgeMap(std::string name, Map& map,
1.185 const Reader& reader = Reader()) {
1.186 @@ -269,6 +309,9 @@
1.187 return *this;
1.188 }
1.189
1.190 + /// \brief Add a new edge map skipper command for the reader.
1.191 + ///
1.192 + /// Add a new edge map skipper command for the reader.
1.193 template <typename Reader>
1.194 GraphReader& skipEdgeMap(std::string name,
1.195 const Reader& reader = Reader()) {
1.196 @@ -280,7 +323,9 @@
1.197 return *this;
1.198 }
1.199
1.200 - // Node rules
1.201 + /// \brief Add a new labeled node reader for the reader.
1.202 + ///
1.203 + /// Add a new labeled node reader for the reader.
1.204 GraphReader& addNode(std::string name, Node& node) {
1.205 if (node_readers.find(name) != node_readers.end()) {
1.206 throw Exception() << "Multiple read rule for node";
1.207 @@ -289,8 +334,9 @@
1.208 return *this;
1.209 }
1.210
1.211 - // Edge rules
1.212 -
1.213 + /// \brief Add a new labeled edge reader for the reader.
1.214 + ///
1.215 + /// Add a new labeled edge reader for the reader.
1.216 GraphReader& addEdge(std::string name, Edge& edge) {
1.217 if (edge_readers.find(name) != edge_readers.end()) {
1.218 throw Exception() << "Multiple read rule for edge";
1.219 @@ -299,7 +345,10 @@
1.220 return *this;
1.221 }
1.222
1.223 - void read() {
1.224 + /// \brief Executes the reader commands.
1.225 + ///
1.226 + /// Executes the reader commands.
1.227 + void run() {
1.228 int line_num = 0;
1.229 std::auto_ptr<InverterBase<Node> > nodeInverter;
1.230 std::auto_ptr<InverterBase<Edge> > edgeInverter;
2.1 --- a/src/work/deba/graph_writer.h Sun Feb 06 20:14:30 2005 +0000
2.2 +++ b/src/work/deba/graph_writer.h Mon Feb 07 10:48:14 2005 +0000
2.3 @@ -33,12 +33,23 @@
2.4
2.5 namespace lemon {
2.6
2.7 + /// \brief Standard WriterTraits for the GraphWriter class.
2.8 + ///
2.9 + /// Standard WriterTraits for the GraphWriter class.
2.10 + /// It defines standard writing method for all type of value.
2.11 struct DefaultWriterTraits {
2.12
2.13 + /// \brief Template class for writing an value.
2.14 + ///
2.15 + /// Template class for writing an value.
2.16 template <typename _Value>
2.17 struct Writer {
2.18 + /// The value type.
2.19 typedef _Value Value;
2.20
2.21 + /// \brief Writes a value from the given stream.
2.22 + ///
2.23 + /// Writes a value from the given stream.
2.24 void write(std::ostream& os, const Value& value) {
2.25 os << value << '\t';
2.26 }
2.27 @@ -47,12 +58,23 @@
2.28 };
2.29
2.30
2.31 + /// \brief Writer class for quoted strings.
2.32 + ///
2.33 + /// Writer class for quoted strings. It can process the escape
2.34 + /// sequences in the string.
2.35 class QuotedStringWriter {
2.36 public:
2.37 typedef std::string Value;
2.38
2.39 + /// \brief Constructor for the writer.
2.40 + ///
2.41 + /// Constructor for the writer. If the given parameter is true
2.42 + /// the writer creates escape sequences from special characters.
2.43 QuotedStringWriter(bool _escaped = true) : escaped(_escaped) {}
2.44
2.45 + /// \brief Writes a quoted string from the given stream.
2.46 + ///
2.47 + /// Writes a quoted string from the given stream.
2.48 void write(std::ostream& os, const std::string& value) {
2.49 os << "\"";
2.50 if (escaped) {
2.51 @@ -117,8 +139,11 @@
2.52 bool escaped;
2.53 };
2.54
2.55 - // Graph writer
2.56
2.57 + /// \brief The graph writer class.
2.58 + ///
2.59 + /// The writer class for the graph output.
2.60 + /// \see graph-io-page
2.61 template <typename _Graph, typename _WriterTraits = DefaultWriterTraits>
2.62 class GraphWriter {
2.63 public:
2.64 @@ -130,10 +155,18 @@
2.65 typedef typename Graph::EdgeIt EdgeIt;
2.66
2.67 typedef _WriterTraits WriterTraits;
2.68 -
2.69 +
2.70 + /// \brief Construct a new GraphWriter.
2.71 + ///
2.72 + /// Construct a new GraphWriter. It writes from the given map,
2.73 + /// it constructs the given map and it use the given writer as the
2.74 + /// default skipper.
2.75 GraphWriter(std::ostream& _os, Graph& _graph) : os(_os), graph(_graph) {}
2.76
2.77
2.78 + /// \brief Destruct the graph writer.
2.79 + ///
2.80 + /// Destruct the graph writer.
2.81 ~GraphWriter() {
2.82 for (typename NodeMapWriters::iterator it = node_map_writers.begin();
2.83 it != node_map_writers.end(); ++it) {
2.84 @@ -149,19 +182,21 @@
2.85
2.86 // Node map rules
2.87
2.88 + /// \brief Add a new node map writer command for the writer.
2.89 + ///
2.90 + /// Add a new node map writer command for the writer.
2.91 template <typename Map>
2.92 GraphWriter& addNodeMap(std::string name, const Map& map) {
2.93 return addNodeMap<typename WriterTraits::template Writer<
2.94 typename Map::Value>, Map>(name, map);
2.95 }
2.96
2.97 + /// \brief Add a new node map writer command for the writer.
2.98 + ///
2.99 + /// Add a new node map writer command for the writer.
2.100 template <typename Writer, typename Map>
2.101 GraphWriter& addNodeMap(std::string name, const Map& map,
2.102 const Writer& writer = Writer()) {
2.103 - // if (node_map_writers.find(name) != node_map_writers.end()) {
2.104 - // throw Exception() << "Multiple write rule for node map: "
2.105 - // << name;
2.106 - // }
2.107 node_map_writers.push_back(
2.108 make_pair(name, new MapWriter<Node, Map, Writer>(map, writer)));
2.109 return *this;
2.110 @@ -169,41 +204,47 @@
2.111
2.112 // Edge map rules
2.113
2.114 + /// \brief Add a new edge map writer command for the writer.
2.115 + ///
2.116 + /// Add a new edge map writer command for the writer.
2.117 template <typename Map>
2.118 GraphWriter& addEdgeMap(std::string name, const Map& map) {
2.119 - return addEdgeMap<typename WriterTraits::template Writer<typename Map::Value>, Map>(name, map);
2.120 + return addEdgeMap<typename WriterTraits::template Writer<
2.121 + typename Map::Value>, Map>(name, map);
2.122 }
2.123
2.124
2.125 + /// \brief Add a new edge map writer command for the writer.
2.126 + ///
2.127 + /// Add a new edge map writer command for the writer.
2.128 template <typename Writer, typename Map>
2.129 - GraphWriter& addEdgeMap(std::string name, const Map& map, const Writer& writer = Writer()) {
2.130 - // if (edge_map_writers.find(name) != edge_map_writers.end()) {
2.131 - // throw Exception() << "Multiple write rule for edge map: " << name;
2.132 - // }
2.133 - edge_map_writers.push_back(make_pair(name, new MapWriter<Edge, Map, Writer>(map, writer)));
2.134 + GraphWriter& addEdgeMap(std::string name,
2.135 + const Map& map, const Writer& writer = Writer()) {
2.136 + edge_map_writers.push_back(make_pair(name,
2.137 + new MapWriter<Edge, Map, Writer>(map, writer)));
2.138 return *this;
2.139 }
2.140
2.141 - // Node rules
2.142 + /// \brief Add a new labeled node writer for the writer.
2.143 + ///
2.144 + /// Add a new labeled node writer for the writer.
2.145 GraphWriter& addNode(std::string name, const Node& node) {
2.146 - // if (node_writers.find(name) != node_writers.end()) {
2.147 - // throw Exception() << "Multiple write rule for node";
2.148 - // }
2.149 node_writers.push_back(make_pair(name, node));
2.150 return *this;
2.151 }
2.152
2.153 - // Edge rules
2.154 -
2.155 + /// \brief Add a new labeled edge writer for the writer.
2.156 + ///
2.157 + /// Add a new labeled edge writer for the writer.
2.158 GraphWriter& addEdge(std::string name, const Edge& edge) {
2.159 - // if (edge_writers.find(name) != edge_writers.end()) {
2.160 - // throw Exception() << "Multiple write rule for edge";
2.161 - // }
2.162 edge_writers.push_back(make_pair(name, edge));
2.163 return *this;
2.164 }
2.165
2.166 - void write() {
2.167 + /// \brief Executes the writer commands.
2.168 + ///
2.169 + /// Executes the writer commands.
2.170 + void run() {
2.171 writeNodeSet();
2.172 writeEdgeSet();
2.173 writeNodes();
3.1 --- a/src/work/deba/map_utils.h Sun Feb 06 20:14:30 2005 +0000
3.2 +++ b/src/work/deba/map_utils.h Mon Feb 07 10:48:14 2005 +0000
3.3 @@ -23,16 +23,17 @@
3.4
3.5 namespace lemon {
3.6
3.7 - /// \addtogroup gutils
3.8 + /// \addtogroup mutils
3.9 /// @{
3.10
3.11 -
3.12 /// \brief General inversable map type.
3.13
3.14 /// This type provides simple inversable map functions.
3.15 /// The InversableMap wraps an arbitrary ReadWriteMap
3.16 /// and if a key is setted to a new value then store it
3.17 /// in the inverse map.
3.18 + /// \param _Graph The graph type.
3.19 + /// \param _Map The map to extend with inversable functionality.
3.20 template <
3.21 typename _Graph,
3.22 typename _Map
3.23 @@ -43,7 +44,9 @@
3.24 typedef _Graph Graph;
3.25
3.26 typedef _Map Map;
3.27 + /// The key type of InversableMap (Node, Edge, UndirEdge).
3.28 typedef typename _Map::Key Key;
3.29 + /// The value type of the InversableMap.
3.30 typedef typename _Map::Value Value;
3.31 typedef std::map<Value, Key> InverseMap;
3.32
3.33 @@ -60,38 +63,61 @@
3.34 /// It sets the map and the inverse map to given key-value pair.
3.35 void set(const Key& key, const Value& val) {
3.36 Value oldval = Map::operator[](key);
3.37 - typename InverseMap::iterator it = inv_map.find(oldval);
3.38 - if (it != inv_map.end() && it->second == key) {
3.39 - inv_map.erase(it);
3.40 + typename InverseMap::iterator it = invMap.find(oldval);
3.41 + if (it != invMap.end() && it->second == key) {
3.42 + invMap.erase(it);
3.43 }
3.44 - inv_map.insert(make_pair(val, key));
3.45 + invMap.insert(make_pair(val, key));
3.46 Map::set(key, val);
3.47 }
3.48
3.49 - ConstReference operator[](const Key&) const {
3.50 + /// \brief The getter function of the map.
3.51 + ///
3.52 + /// It gives back the value associated with the key.
3.53 + ConstReference operator[](const Key& key) const {
3.54 return Map::operator[](key);
3.55 }
3.56
3.57 - virtual void add(const Key&) {
3.58 + /// \brief Add a new key to the map.
3.59 + ///
3.60 + /// Add a new key to the map. It is called by the
3.61 + /// \c AlterationNotifier.
3.62 + virtual void add(const Key& key) {
3.63 Map::add(key);
3.64 }
3.65
3.66 - virtual void erase(const Key&) {
3.67 + /// \brief Erase the key from the map.
3.68 + ///
3.69 + /// Erase the key to the map. It is called by the
3.70 + /// \c AlterationNotifier.
3.71 + virtual void erase(const Key& key) {
3.72 Value val = Map::operator[](key);
3.73 - typename InverseMap::iterator it = inv_map.find(val);
3.74 - if (it != inv_map.end() && it->second == key) {
3.75 + typename InverseMap::iterator it = invMap.find(val);
3.76 + if (it != invMap.end() && it->second == key) {
3.77 invMap.erase(it);
3.78 }
3.79 Map::erase(key);
3.80 }
3.81
3.82 + /// \brief Clear the keys from the map and inverse map.
3.83 + ///
3.84 + /// Clear the keys from the map and inverse map. It is called by the
3.85 + /// \c AlterationNotifier.
3.86 + virtual void clear() {
3.87 + invMap.clear();
3.88 + Map::clear();
3.89 + }
3.90 +
3.91 + /// \brief It gives back the just readeable inverse map.
3.92 + ///
3.93 + /// It gives back the just readeable inverse map.
3.94 const InverseMap& inverse() const {
3.95 - return inv_map;
3.96 + return invMap;
3.97 }
3.98
3.99
3.100 private:
3.101 - InverseMap inv_map;
3.102 + InverseMap invMap;
3.103 };
3.104
3.105
3.106 @@ -135,29 +161,45 @@
3.107 build();
3.108 }
3.109
3.110 + /// \brief Add a new key to the map.
3.111 + ///
3.112 + /// Add a new key to the map. It is called by the
3.113 + /// \c AlterationNotifier.
3.114 virtual void add(const Item& item) {
3.115 Map::add(item);
3.116 - Map::set(item, inv_map.size());
3.117 - inv_map.push_back(item);
3.118 + Map::set(item, invMap.size());
3.119 + invMap.push_back(item);
3.120 }
3.121
3.122 + /// \brief Erase the key from the map.
3.123 + ///
3.124 + /// Erase the key to the map. It is called by the
3.125 + /// \c AlterationNotifier.
3.126 virtual void erase(const Item& item) {
3.127 - Map::set(inv_map.back(), Map::operator[](item));
3.128 - inv_map[Map::operator[](item)] = inv_map.back();
3.129 + Map::set(invMap.back(), Map::operator[](item));
3.130 + invMap[Map::operator[](item)] = invMap.back();
3.131 Map::erase(item);
3.132 }
3.133
3.134 + /// \brief Build the unique map.
3.135 + ///
3.136 + /// Build the unique map. It is called by the
3.137 + /// \c AlterationNotifier.
3.138 virtual void build() {
3.139 Map::build();
3.140 Item it;
3.141 for (getGraph()->first(it); it != INVALID; getGraph()->next(it)) {
3.142 - Map::set(it, inv_map.size());
3.143 - inv_map.push_back(it);
3.144 + Map::set(it, invMap.size());
3.145 + invMap.push_back(it);
3.146 }
3.147 }
3.148
3.149 + /// \brief Clear the keys from the map.
3.150 + ///
3.151 + /// Clear the keys from the map. It is called by the
3.152 + /// \c AlterationNotifier.
3.153 virtual void clear() {
3.154 - inv_map.clear();
3.155 + invMap.clear();
3.156 Map::clear();
3.157 }
3.158
3.159 @@ -172,11 +214,11 @@
3.160 ///
3.161 /// Gives back the inverse of the map.
3.162 const InverseMap inverse() const {
3.163 - return inv_map;
3.164 + return invMap;
3.165 }
3.166
3.167 private:
3.168 - vector<Item> inv_map;
3.169 + vector<Item> invMap;
3.170 };
3.171
3.172 /// Provides an immutable and unique id for each item in the graph.