1.1 --- a/src/work/deba/graph_reader.h Tue Feb 01 15:51:22 2005 +0000
1.2 +++ b/src/work/deba/graph_reader.h Tue Feb 01 15:56:37 2005 +0000
1.3 @@ -37,6 +37,7 @@
1.4
1.5 class IOException {
1.6 public:
1.7 + virtual ~IOException() {}
1.8 virtual string what() const = 0;
1.9 };
1.10
1.11 @@ -55,10 +56,13 @@
1.12 public:
1.13 typedef _Exception Exception;
1.14 StreamException(int _line, Exception _exception)
1.15 - : line_num(_line), Exception(_exception) {}
1.16 + : Exception(_exception), line_num(_line) {}
1.17 virtual int line() const {
1.18 return line_num;
1.19 }
1.20 +
1.21 + virtual ~StreamException() {}
1.22 +
1.23 virtual std::string what() const {
1.24 ostringstream os;
1.25 os << Exception::what() << " in line " << line();
1.26 @@ -70,7 +74,10 @@
1.27
1.28
1.29 // Readers and ReaderTraits
1.30 -
1.31 + /// \brief Standard ReaderTraits for the GraphReader class.
1.32 + ///
1.33 + ///
1.34 +
1.35 struct DefaultReaderTraits {
1.36
1.37 template <typename _Value>
1.38 @@ -96,7 +103,8 @@
1.39 char c;
1.40 value.clear();
1.41 is >> ws;
1.42 - if (!is.get(c) || c != '\"') throw DataFormatException("Quoted string format");
1.43 + if (!is.get(c) || c != '\"')
1.44 + throw DataFormatException("Quoted string format");
1.45 while (is.get(c) && c != '\"') {
1.46 if (escaped && c == '\\') {
1.47 value += readEscape(is);
1.48 @@ -192,17 +200,20 @@
1.49 typedef _ReaderTraits ReaderTraits;
1.50 typedef typename ReaderTraits::DefaultReader DefaultReader;
1.51
1.52 - GraphReader(std::istream& _is, Graph& _graph, const DefaultReader& _reader = DefaultReader())
1.53 + GraphReader(std::istream& _is, Graph& _graph,
1.54 + const DefaultReader& _reader = DefaultReader())
1.55 : is(_is), graph(_graph), nodeSkipper(_reader), edgeSkipper(_reader) {}
1.56
1.57
1.58 ~GraphReader() {
1.59
1.60 - for (typename NodeMapReaders::iterator it = node_map_readers.begin(); it != node_map_readers.end(); ++it) {
1.61 + for (typename NodeMapReaders::iterator it = node_map_readers.begin();
1.62 + it != node_map_readers.end(); ++it) {
1.63 delete it->second;
1.64 }
1.65
1.66 - for (typename EdgeMapReaders::iterator it = edge_map_readers.begin(); it != edge_map_readers.end(); ++it) {
1.67 + for (typename EdgeMapReaders::iterator it = edge_map_readers.begin();
1.68 + it != edge_map_readers.end(); ++it) {
1.69 delete it->second;
1.70 }
1.71
1.72 @@ -211,69 +222,81 @@
1.73 // Node map rules
1.74
1.75 template <typename Map>
1.76 - GraphReader& readNodeMap(std::string name, Map& map) {
1.77 - return readNodeMap<typename ReaderTraits::template Reader<typename Map::Value>, Map>(name, map);
1.78 + GraphReader& addNodeMap(std::string name, Map& map) {
1.79 + return addNodeMap<typename ReaderTraits::template
1.80 + Reader<typename Map::Value>, Map>(name, map);
1.81 }
1.82
1.83 template <typename Reader, typename Map>
1.84 - GraphReader& readNodeMap(std::string name, Map& map, const Reader& reader = Reader()) {
1.85 + GraphReader& addNodeMap(std::string name, Map& map,
1.86 + const Reader& reader = Reader()) {
1.87 if (node_map_readers.find(name) != node_map_readers.end()) {
1.88 throw Exception() << "Multiple read rule for node map: " << name;
1.89 }
1.90 - node_map_readers.insert(make_pair(name, new MapReader<Node, Map, Reader>(map, reader)));
1.91 + node_map_readers.insert(
1.92 + make_pair(name, new MapReader<Node, Map, Reader>(map, reader)));
1.93 return *this;
1.94 }
1.95
1.96 template <typename Reader>
1.97 - GraphReader& skipNodeMap(std::string name, const Reader& reader = Reader()) {
1.98 + GraphReader& skipNodeMap(std::string name,
1.99 + const Reader& reader = Reader()) {
1.100 if (node_map_readers.find(name) != node_map_readers.end()) {
1.101 throw Exception() << "Multiple read rule for node map: " << name;
1.102 }
1.103 - node_map_readers.insert(make_pair(name, new SkipReader<Node, Reader>(reader)));
1.104 + node_map_readers.insert(
1.105 + make_pair(name, new SkipReader<Node, Reader>(reader)));
1.106 return *this;
1.107 }
1.108
1.109 // Edge map rules
1.110
1.111 template <typename Map>
1.112 - GraphReader& readEdgeMap(std::string name, Map& map) {
1.113 - return readEdgeMap<typename ReaderTraits::template Reader<typename Map::Value>, Map>(name, map);
1.114 + GraphReader& addEdgeMap(std::string name, Map& map) {
1.115 + return addEdgeMap<typename ReaderTraits::template
1.116 + Reader<typename Map::Value>, Map>(name, map);
1.117 }
1.118
1.119
1.120 template <typename Reader, typename Map>
1.121 - GraphReader& readEdgeMap(std::string name, Map& map, const Reader& reader = Reader()) {
1.122 + GraphReader& addEdgeMap(std::string name, Map& map,
1.123 + const Reader& reader = Reader()) {
1.124 if (edge_map_readers.find(name) != edge_map_readers.end()) {
1.125 throw Exception() << "Multiple read rule for edge map: " << name;
1.126 }
1.127 - edge_map_readers.insert(make_pair(name, new MapReader<Edge, Map, Reader>(map, reader)));
1.128 + edge_map_readers.insert(
1.129 + make_pair(name, new MapReader<Edge, Map, Reader>(map, reader)));
1.130 return *this;
1.131 }
1.132
1.133 template <typename Reader>
1.134 - GraphReader& skipEdgeMap(std::string name, const Reader& reader = Reader()) {
1.135 + GraphReader& skipEdgeMap(std::string name,
1.136 + const Reader& reader = Reader()) {
1.137 if (edge_map_readers.find(name) != edge_map_readers.end()) {
1.138 throw Exception() << "Multiple read rule for edge map: " << name;
1.139 }
1.140 - edge_map_readers.insert(make_pair(name, new SkipReader<Edge, Reader>(reader)));
1.141 + edge_map_readers.insert(
1.142 + make_pair(name, new SkipReader<Edge, Reader>(reader)));
1.143 return *this;
1.144 }
1.145
1.146 // Node rules
1.147 - GraphReader& readNode(std::string name, Node& node) {
1.148 + GraphReader& addNode(std::string name, Node& node) {
1.149 if (node_readers.find(name) != node_readers.end()) {
1.150 throw Exception() << "Multiple read rule for node";
1.151 }
1.152 node_readers.insert(make_pair(name, &node));
1.153 + return *this;
1.154 }
1.155
1.156 // Edge rules
1.157
1.158 - GraphReader& readEdge(std::string name, Edge& edge) {
1.159 + GraphReader& addEdge(std::string name, Edge& edge) {
1.160 if (edge_readers.find(name) != edge_readers.end()) {
1.161 throw Exception() << "Multiple read rule for edge";
1.162 }
1.163 edge_readers.insert(make_pair(name, &edge));
1.164 + return *this;
1.165 }
1.166
1.167 void read() {
1.168 @@ -306,7 +329,8 @@
1.169
1.170 template <typename Item> class InverterBase;
1.171
1.172 - std::string readNodeSet(int& line_num, auto_ptr<InverterBase<Node> > & nodeInverter) {
1.173 + std::string readNodeSet(int& line_num,
1.174 + auto_ptr<InverterBase<Node> > & nodeInverter) {
1.175 std::vector<ReaderBase<Node>* > index;
1.176 {
1.177 std::string line = readNotEmptyLine(is, line_num);
1.178 @@ -334,7 +358,7 @@
1.179 Node node = graph.addNode();
1.180 std::istringstream ls(line);
1.181 nodeInverter->read(ls, node);
1.182 - for (int i = 1; i < index.size(); ++i) {
1.183 + for (int i = 1; i < (int)index.size(); ++i) {
1.184 index[i]->read(ls, node);
1.185 }
1.186 }
1.187 @@ -342,7 +366,8 @@
1.188 }
1.189
1.190 std::string readEdgeSet(int& line_num,
1.191 - auto_ptr<InverterBase<Edge> > & edgeInverter, auto_ptr<InverterBase<Node> > & nodeInverter) {
1.192 + auto_ptr<InverterBase<Edge> > & edgeInverter,
1.193 + auto_ptr<InverterBase<Node> > & nodeInverter) {
1.194 std::vector<ReaderBase<Edge>*> index;
1.195 {
1.196 std::string line = readNotEmptyLine(is, line_num);
1.197 @@ -372,14 +397,15 @@
1.198 Node target = nodeInverter->read(ls);
1.199 Edge edge = graph.addEdge(source, target);
1.200 edgeInverter->read(ls, edge);
1.201 - for (int i = 1; i < index.size(); ++i) {
1.202 + for (int i = 1; i < (int)index.size(); ++i) {
1.203 index[i]->read(ls, edge);
1.204 }
1.205 }
1.206 return line;
1.207 }
1.208
1.209 - std::string readNodes(int& line_num, auto_ptr<InverterBase<Node> >& nodeInverter) {
1.210 + std::string readNodes(int& line_num,
1.211 + auto_ptr<InverterBase<Node> >& nodeInverter) {
1.212 std::string line;
1.213 while (line = readNotEmptyLine(is, line_num), line[0] != '@') {
1.214 std::istringstream ls(line);
1.215 @@ -393,7 +419,8 @@
1.216 return line;
1.217 }
1.218
1.219 - std::string readEdges(int& line_num, auto_ptr<InverterBase<Edge> >& edgeInverter) {
1.220 + std::string readEdges(int& line_num,
1.221 + auto_ptr<InverterBase<Edge> >& edgeInverter) {
1.222 std::string line;
1.223 while (line = readNotEmptyLine(is, line_num), line[0] != '@') {
1.224 std::istringstream ls(line);
1.225 @@ -411,7 +438,7 @@
1.226 std::string line;
1.227 while (++line_num, getline(is, line)) {
1.228 int vi = line.find_first_not_of(" \t");
1.229 - if (vi != string::npos && line[vi] != '#') {
1.230 + if (vi != (int)string::npos && line[vi] != '#') {
1.231 return line.substr(vi);
1.232 }
1.233 }
1.234 @@ -445,6 +472,8 @@
1.235 MapReaderInverter(Map& _map, const Reader& _reader)
1.236 : map(_map), reader(_reader) {}
1.237
1.238 + virtual ~MapReaderInverter() {}
1.239 +
1.240 virtual void read(std::istream& is, const Item& item) {
1.241 Value value;
1.242 reader.read(is, value);
1.243 @@ -482,6 +511,8 @@
1.244 SkipReaderInverter(const Reader& _reader)
1.245 : reader(_reader) {}
1.246
1.247 + virtual ~SkipReaderInverter() {}
1.248 +
1.249 virtual void read(std::istream& is, const Item& item) {
1.250 Value value;
1.251 reader.read(is, value);
1.252 @@ -514,6 +545,8 @@
1.253 public:
1.254 typedef _Item Item;
1.255
1.256 + // virtual ~ReaderBase() {}
1.257 +
1.258 virtual void read(std::istream& is, const Item& item) = 0;
1.259 virtual InverterBase<_Item>* getInverter() = 0;
1.260 };
1.261 @@ -532,6 +565,7 @@
1.262 MapReader(Map& _map, const Reader& _reader)
1.263 : map(_map), reader(_reader) {}
1.264
1.265 + virtual ~MapReader() {}
1.266
1.267 virtual void read(std::istream& is, const Item& item) {
1.268 Value value;
1.269 @@ -555,6 +589,8 @@
1.270 Reader reader;
1.271 SkipReader(const Reader& _reader) : reader(_reader) {}
1.272
1.273 + virtual ~SkipReader() {}
1.274 +
1.275 virtual void read(std::istream& is, const Item& item) {
1.276 Value value;
1.277 reader.read(is, value);