0
4
0
... | ... |
@@ -36,21 +36,21 @@ |
36 | 36 |
/// @{ |
37 | 37 |
|
38 | 38 |
/// \brief Generic exception class. |
39 | 39 |
/// |
40 | 40 |
/// Base class for exceptions used in LEMON. |
41 | 41 |
/// |
42 | 42 |
class Exception : public std::exception { |
43 | 43 |
public: |
44 |
///\e Constructor |
|
45 |
Exception() {} |
|
46 |
/// |
|
44 |
///Constructor |
|
45 |
Exception() throw() {} |
|
46 |
///Virtual destructor |
|
47 | 47 |
virtual ~Exception() throw() {} |
48 |
/// |
|
48 |
///A short description of the exception |
|
49 | 49 |
virtual const char* what() const throw() { |
50 | 50 |
return "lemon::Exception"; |
51 | 51 |
} |
52 | 52 |
}; |
53 | 53 |
|
54 | 54 |
/// \brief Input-Output error |
55 | 55 |
/// |
56 | 56 |
/// This exception is thrown when a file operation cannot be |
... | ... |
@@ -59,210 +59,210 @@ |
59 | 59 |
protected: |
60 | 60 |
std::string _message; |
61 | 61 |
std::string _file; |
62 | 62 |
|
63 | 63 |
mutable std::string _what; |
64 | 64 |
public: |
65 | 65 |
|
66 | 66 |
/// Copy constructor |
67 |
IoError(const IoError &error) { |
|
67 |
IoError(const IoError &error) throw() : Exception() { |
|
68 | 68 |
message(error._message); |
69 | 69 |
file(error._file); |
70 | 70 |
} |
71 | 71 |
|
72 | 72 |
/// Constructor |
73 |
explicit IoError(const char *message) { |
|
73 |
explicit IoError(const char *message) throw() { |
|
74 | 74 |
IoError::message(message); |
75 | 75 |
} |
76 | 76 |
|
77 | 77 |
/// Constructor |
78 |
explicit IoError(const std::string &message) { |
|
78 |
explicit IoError(const std::string &message) throw() { |
|
79 | 79 |
IoError::message(message); |
80 | 80 |
} |
81 | 81 |
|
82 | 82 |
/// Constructor |
83 |
IoError( |
|
83 |
explicit IoError(const char *message, |
|
84 |
const std::string &file) throw() { |
|
84 | 85 |
IoError::message(message); |
85 | 86 |
IoError::file(file); |
86 | 87 |
} |
87 | 88 |
|
88 | 89 |
/// Constructor |
89 |
IoError(const std::string & |
|
90 |
explicit IoError(const std::string &message, |
|
91 |
const std::string &file) throw() { |
|
90 | 92 |
IoError::message(message); |
91 | 93 |
IoError::file(file); |
92 | 94 |
} |
93 | 95 |
|
94 | 96 |
/// Virtual destructor |
95 | 97 |
virtual ~IoError() throw() {} |
96 | 98 |
|
97 | 99 |
/// Set the error message |
98 |
void message(const char *message) { |
|
100 |
void message(const char *message) throw() { |
|
99 | 101 |
try { |
100 | 102 |
_message = message; |
101 | 103 |
} catch (...) {} |
102 | 104 |
} |
103 | 105 |
|
104 | 106 |
/// Set the error message |
105 |
void message(const std::string& message) { |
|
107 |
void message(const std::string& message) throw() { |
|
106 | 108 |
try { |
107 | 109 |
_message = message; |
108 | 110 |
} catch (...) {} |
109 | 111 |
} |
110 | 112 |
|
111 | 113 |
/// Set the file name |
112 |
void file(const std::string &file) { |
|
114 |
void file(const std::string &file) throw() { |
|
113 | 115 |
try { |
114 | 116 |
_file = file; |
115 | 117 |
} catch (...) {} |
116 | 118 |
} |
117 | 119 |
|
118 | 120 |
/// Returns the error message |
119 |
const std::string& message() const { |
|
121 |
const std::string& message() const throw() { |
|
120 | 122 |
return _message; |
121 | 123 |
} |
122 | 124 |
|
123 | 125 |
/// \brief Returns the filename |
124 | 126 |
/// |
125 |
/// Returns the filename or empty string if the filename was not |
|
126 |
/// specified. |
|
127 |
|
|
127 |
/// Returns the filename or an empty string if it was not specified. |
|
128 |
const std::string& file() const throw() { |
|
128 | 129 |
return _file; |
129 | 130 |
} |
130 | 131 |
|
131 | 132 |
/// \brief Returns a short error message |
132 | 133 |
/// |
133 |
/// Returns a short error message which contains the message, the |
|
134 |
/// file name and the line number. |
|
134 |
/// Returns a short error message which contains the message and the |
|
135 |
/// file name. |
|
135 | 136 |
virtual const char* what() const throw() { |
136 | 137 |
try { |
137 | 138 |
_what.clear(); |
138 | 139 |
std::ostringstream oss; |
139 | 140 |
oss << "lemon:IoError" << ": "; |
140 |
oss << message(); |
|
141 |
if (!file().empty()) { |
|
142 |
oss << " ("; |
|
143 |
if (!file().empty()) oss << "with file '" << file() << "'"; |
|
144 |
|
|
141 |
oss << _message; |
|
142 |
if (!_file.empty()) { |
|
143 |
oss << " ('" << _file << "')"; |
|
145 | 144 |
} |
146 | 145 |
_what = oss.str(); |
147 | 146 |
} |
148 | 147 |
catch (...) {} |
149 | 148 |
if (!_what.empty()) return _what.c_str(); |
150 | 149 |
else return "lemon:IoError"; |
151 | 150 |
} |
152 | 151 |
|
153 | 152 |
}; |
154 | 153 |
|
155 | 154 |
/// \brief Format error |
156 | 155 |
/// |
157 |
/// This class is used to indicate if an input file has wrong |
|
158 |
/// formatting, or a data representation is not legal. |
|
156 |
/// This exception is thrown when an input file has wrong |
|
157 |
/// format or a data representation is not legal. |
|
159 | 158 |
class FormatError : public Exception { |
160 | 159 |
protected: |
161 | 160 |
std::string _message; |
162 | 161 |
std::string _file; |
163 | 162 |
int _line; |
164 | 163 |
|
165 | 164 |
mutable std::string _what; |
166 | 165 |
public: |
167 | 166 |
|
168 | 167 |
/// Copy constructor |
169 |
FormatError(const FormatError &error) { |
|
168 |
FormatError(const FormatError &error) throw() : Exception() { |
|
170 | 169 |
message(error._message); |
171 | 170 |
file(error._file); |
172 | 171 |
line(error._line); |
173 | 172 |
} |
174 | 173 |
|
175 | 174 |
/// Constructor |
176 |
explicit FormatError(const char *message) { |
|
175 |
explicit FormatError(const char *message) throw() { |
|
177 | 176 |
FormatError::message(message); |
178 | 177 |
_line = 0; |
179 | 178 |
} |
180 | 179 |
|
181 | 180 |
/// Constructor |
182 |
explicit FormatError(const std::string &message) { |
|
181 |
explicit FormatError(const std::string &message) throw() { |
|
183 | 182 |
FormatError::message(message); |
184 | 183 |
_line = 0; |
185 | 184 |
} |
186 | 185 |
|
187 | 186 |
/// Constructor |
188 |
FormatError( |
|
187 |
explicit FormatError(const char *message, |
|
188 |
const std::string &file, int line = 0) throw() { |
|
189 | 189 |
FormatError::message(message); |
190 | 190 |
FormatError::file(file); |
191 | 191 |
FormatError::line(line); |
192 | 192 |
} |
193 | 193 |
|
194 | 194 |
/// Constructor |
195 |
FormatError(const std::string & |
|
195 |
explicit FormatError(const std::string &message, |
|
196 |
const std::string &file, int line = 0) throw() { |
|
196 | 197 |
FormatError::message(message); |
197 | 198 |
FormatError::file(file); |
198 | 199 |
FormatError::line(line); |
199 | 200 |
} |
200 | 201 |
|
201 | 202 |
/// Virtual destructor |
202 | 203 |
virtual ~FormatError() throw() {} |
203 | 204 |
|
204 | 205 |
/// Set the line number |
205 |
void line(int line) { _line = line; } |
|
206 |
void line(int line) throw() { _line = line; } |
|
206 | 207 |
|
207 | 208 |
/// Set the error message |
208 |
void message(const char *message) { |
|
209 |
void message(const char *message) throw() { |
|
209 | 210 |
try { |
210 | 211 |
_message = message; |
211 | 212 |
} catch (...) {} |
212 | 213 |
} |
213 | 214 |
|
214 | 215 |
/// Set the error message |
215 |
void message(const std::string& message) { |
|
216 |
void message(const std::string& message) throw() { |
|
216 | 217 |
try { |
217 | 218 |
_message = message; |
218 | 219 |
} catch (...) {} |
219 | 220 |
} |
220 | 221 |
|
221 | 222 |
/// Set the file name |
222 |
void file(const std::string &file) { |
|
223 |
void file(const std::string &file) throw() { |
|
223 | 224 |
try { |
224 | 225 |
_file = file; |
225 | 226 |
} catch (...) {} |
226 | 227 |
} |
227 | 228 |
|
228 | 229 |
/// \brief Returns the line number |
229 | 230 |
/// |
230 | 231 |
/// Returns the line number or zero if it was not specified. |
231 |
int line() const { return _line; } |
|
232 |
int line() const throw() { return _line; } |
|
232 | 233 |
|
233 | 234 |
/// Returns the error message |
234 |
const std::string& message() const { |
|
235 |
const std::string& message() const throw() { |
|
235 | 236 |
return _message; |
236 | 237 |
} |
237 | 238 |
|
238 | 239 |
/// \brief Returns the filename |
239 | 240 |
/// |
240 |
/// Returns the filename or empty string if the filename was not |
|
241 |
/// specified. |
|
242 |
|
|
241 |
/// Returns the filename or an empty string if it was not specified. |
|
242 |
const std::string& file() const throw() { |
|
243 | 243 |
return _file; |
244 | 244 |
} |
245 | 245 |
|
246 | 246 |
/// \brief Returns a short error message |
247 | 247 |
/// |
248 | 248 |
/// Returns a short error message which contains the message, the |
249 | 249 |
/// file name and the line number. |
250 | 250 |
virtual const char* what() const throw() { |
251 | 251 |
try { |
252 | 252 |
_what.clear(); |
253 | 253 |
std::ostringstream oss; |
254 | 254 |
oss << "lemon:FormatError" << ": "; |
255 |
oss << message(); |
|
256 |
if (!file().empty() || line() != 0) { |
|
255 |
oss << _message; |
|
256 |
if (!_file.empty() || _line != 0) { |
|
257 | 257 |
oss << " ("; |
258 |
if (!file().empty()) oss << "in file '" << file() << "'"; |
|
259 |
if (!file().empty() && line() != 0) oss << " "; |
|
260 |
if ( |
|
258 |
if (!_file.empty()) oss << "in file '" << _file << "'"; |
|
259 |
if (!_file.empty() && _line != 0) oss << " "; |
|
260 |
if (_line != 0) oss << "at line " << _line; |
|
261 | 261 |
oss << ")"; |
262 | 262 |
} |
263 | 263 |
_what = oss.str(); |
264 | 264 |
} |
265 | 265 |
catch (...) {} |
266 | 266 |
if (!_what.empty()) return _what.c_str(); |
267 | 267 |
else return "lemon:FormatError"; |
268 | 268 |
} |
... | ... |
@@ -1165,17 +1165,17 @@ |
1165 | 1165 |
///\sa graphToEps(G &g, std::ostream& os) |
1166 | 1166 |
template<class G> |
1167 | 1167 |
GraphToEps<DefaultGraphToEpsTraits<G> > |
1168 | 1168 |
graphToEps(G &g,const char *file_name) |
1169 | 1169 |
{ |
1170 | 1170 |
std::ostream* os = new std::ofstream(file_name); |
1171 | 1171 |
if (!(*os)) { |
1172 | 1172 |
delete os; |
1173 |
throw IoError( |
|
1173 |
throw IoError("Cannot write file", file_name); |
|
1174 | 1174 |
} |
1175 | 1175 |
return GraphToEps<DefaultGraphToEpsTraits<G> > |
1176 | 1176 |
(DefaultGraphToEpsTraits<G>(g,*os,true)); |
1177 | 1177 |
} |
1178 | 1178 |
|
1179 | 1179 |
///Generates an EPS file from a graph |
1180 | 1180 |
|
1181 | 1181 |
///\ingroup eps_io |
... | ... |
@@ -1186,17 +1186,17 @@ |
1186 | 1186 |
///\sa graphToEps(G &g, std::ostream& os) |
1187 | 1187 |
template<class G> |
1188 | 1188 |
GraphToEps<DefaultGraphToEpsTraits<G> > |
1189 | 1189 |
graphToEps(G &g,const std::string& file_name) |
1190 | 1190 |
{ |
1191 | 1191 |
std::ostream* os = new std::ofstream(file_name.c_str()); |
1192 | 1192 |
if (!(*os)) { |
1193 | 1193 |
delete os; |
1194 |
throw IoError( |
|
1194 |
throw IoError("Cannot write file", file_name); |
|
1195 | 1195 |
} |
1196 | 1196 |
return GraphToEps<DefaultGraphToEpsTraits<G> > |
1197 | 1197 |
(DefaultGraphToEpsTraits<G>(g,*os,true)); |
1198 | 1198 |
} |
1199 | 1199 |
|
1200 | 1200 |
} //END OF NAMESPACE LEMON |
1201 | 1201 |
|
1202 | 1202 |
#endif // LEMON_GRAPH_TO_EPS_H |
... | ... |
@@ -511,29 +511,29 @@ |
511 | 511 |
/// |
512 | 512 |
/// Construct a directed graph reader, which reads from the given |
513 | 513 |
/// file. |
514 | 514 |
DigraphReader(const std::string& fn, Digraph& digraph) |
515 | 515 |
: _is(new std::ifstream(fn.c_str())), local_is(true), |
516 | 516 |
_filename(fn), _digraph(digraph), |
517 | 517 |
_use_nodes(false), _use_arcs(false), |
518 | 518 |
_skip_nodes(false), _skip_arcs(false) { |
519 |
if (!(*_is)) throw IoError( |
|
519 |
if (!(*_is)) throw IoError("Cannot open file", fn); |
|
520 | 520 |
} |
521 | 521 |
|
522 | 522 |
/// \brief Constructor |
523 | 523 |
/// |
524 | 524 |
/// Construct a directed graph reader, which reads from the given |
525 | 525 |
/// file. |
526 | 526 |
DigraphReader(const char* fn, Digraph& digraph) |
527 | 527 |
: _is(new std::ifstream(fn)), local_is(true), |
528 | 528 |
_filename(fn), _digraph(digraph), |
529 | 529 |
_use_nodes(false), _use_arcs(false), |
530 | 530 |
_skip_nodes(false), _skip_arcs(false) { |
531 |
if (!(*_is)) throw IoError( |
|
531 |
if (!(*_is)) throw IoError("Cannot open file", fn); |
|
532 | 532 |
} |
533 | 533 |
|
534 | 534 |
/// \brief Destructor |
535 | 535 |
~DigraphReader() { |
536 | 536 |
for (typename NodeMaps::iterator it = _node_maps.begin(); |
537 | 537 |
it != _node_maps.end(); ++it) { |
538 | 538 |
delete it->second; |
539 | 539 |
} |
... | ... |
@@ -874,17 +874,17 @@ |
874 | 874 |
++index; |
875 | 875 |
} |
876 | 876 |
|
877 | 877 |
for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) { |
878 | 878 |
std::map<std::string, int>::iterator jt = |
879 | 879 |
maps.find(_node_maps[i].first); |
880 | 880 |
if (jt == maps.end()) { |
881 | 881 |
std::ostringstream msg; |
882 |
msg << "Map not found |
|
882 |
msg << "Map not found: " << _node_maps[i].first; |
|
883 | 883 |
throw FormatError(msg.str()); |
884 | 884 |
} |
885 | 885 |
map_index[i] = jt->second; |
886 | 886 |
} |
887 | 887 |
|
888 | 888 |
{ |
889 | 889 |
std::map<std::string, int>::iterator jt = maps.find("label"); |
890 | 890 |
if (jt != maps.end()) { |
... | ... |
@@ -903,26 +903,26 @@ |
903 | 903 |
for (int i = 0; i < map_num; ++i) { |
904 | 904 |
if (!_reader_bits::readToken(line, tokens[i])) { |
905 | 905 |
std::ostringstream msg; |
906 | 906 |
msg << "Column not found (" << i + 1 << ")"; |
907 | 907 |
throw FormatError(msg.str()); |
908 | 908 |
} |
909 | 909 |
} |
910 | 910 |
if (line >> std::ws >> c) |
911 |
throw FormatError("Extra character |
|
911 |
throw FormatError("Extra character at the end of line"); |
|
912 | 912 |
|
913 | 913 |
Node n; |
914 | 914 |
if (!_use_nodes) { |
915 | 915 |
n = _digraph.addNode(); |
916 | 916 |
if (label_index != -1) |
917 | 917 |
_node_index.insert(std::make_pair(tokens[label_index], n)); |
918 | 918 |
} else { |
919 | 919 |
if (label_index == -1) |
920 |
throw FormatError("Label map not found |
|
920 |
throw FormatError("Label map not found"); |
|
921 | 921 |
typename std::map<std::string, Node>::iterator it = |
922 | 922 |
_node_index.find(tokens[label_index]); |
923 | 923 |
if (it == _node_index.end()) { |
924 | 924 |
std::ostringstream msg; |
925 | 925 |
msg << "Node with label not found: " << tokens[label_index]; |
926 | 926 |
throw FormatError(msg.str()); |
927 | 927 |
} |
928 | 928 |
n = it->second; |
... | ... |
@@ -967,17 +967,17 @@ |
967 | 967 |
++index; |
968 | 968 |
} |
969 | 969 |
|
970 | 970 |
for (int i = 0; i < static_cast<int>(_arc_maps.size()); ++i) { |
971 | 971 |
std::map<std::string, int>::iterator jt = |
972 | 972 |
maps.find(_arc_maps[i].first); |
973 | 973 |
if (jt == maps.end()) { |
974 | 974 |
std::ostringstream msg; |
975 |
msg << "Map not found |
|
975 |
msg << "Map not found: " << _arc_maps[i].first; |
|
976 | 976 |
throw FormatError(msg.str()); |
977 | 977 |
} |
978 | 978 |
map_index[i] = jt->second; |
979 | 979 |
} |
980 | 980 |
|
981 | 981 |
{ |
982 | 982 |
std::map<std::string, int>::iterator jt = maps.find("label"); |
983 | 983 |
if (jt != maps.end()) { |
... | ... |
@@ -1005,17 +1005,17 @@ |
1005 | 1005 |
for (int i = 0; i < map_num; ++i) { |
1006 | 1006 |
if (!_reader_bits::readToken(line, tokens[i])) { |
1007 | 1007 |
std::ostringstream msg; |
1008 | 1008 |
msg << "Column not found (" << i + 1 << ")"; |
1009 | 1009 |
throw FormatError(msg.str()); |
1010 | 1010 |
} |
1011 | 1011 |
} |
1012 | 1012 |
if (line >> std::ws >> c) |
1013 |
throw FormatError("Extra character |
|
1013 |
throw FormatError("Extra character at the end of line"); |
|
1014 | 1014 |
|
1015 | 1015 |
Arc a; |
1016 | 1016 |
if (!_use_arcs) { |
1017 | 1017 |
|
1018 | 1018 |
typename NodeIndex::iterator it; |
1019 | 1019 |
|
1020 | 1020 |
it = _node_index.find(source_token); |
1021 | 1021 |
if (it == _node_index.end()) { |
... | ... |
@@ -1033,17 +1033,17 @@ |
1033 | 1033 |
} |
1034 | 1034 |
Node target = it->second; |
1035 | 1035 |
|
1036 | 1036 |
a = _digraph.addArc(source, target); |
1037 | 1037 |
if (label_index != -1) |
1038 | 1038 |
_arc_index.insert(std::make_pair(tokens[label_index], a)); |
1039 | 1039 |
} else { |
1040 | 1040 |
if (label_index == -1) |
1041 |
throw FormatError("Label map not found |
|
1041 |
throw FormatError("Label map not found"); |
|
1042 | 1042 |
typename std::map<std::string, Arc>::iterator it = |
1043 | 1043 |
_arc_index.find(tokens[label_index]); |
1044 | 1044 |
if (it == _arc_index.end()) { |
1045 | 1045 |
std::ostringstream msg; |
1046 | 1046 |
msg << "Arc with label not found: " << tokens[label_index]; |
1047 | 1047 |
throw FormatError(msg.str()); |
1048 | 1048 |
} |
1049 | 1049 |
a = it->second; |
... | ... |
@@ -1068,23 +1068,23 @@ |
1068 | 1068 |
line.putback(c); |
1069 | 1069 |
|
1070 | 1070 |
std::string attr, token; |
1071 | 1071 |
if (!_reader_bits::readToken(line, attr)) |
1072 | 1072 |
throw FormatError("Attribute name not found"); |
1073 | 1073 |
if (!_reader_bits::readToken(line, token)) |
1074 | 1074 |
throw FormatError("Attribute value not found"); |
1075 | 1075 |
if (line >> c) |
1076 |
throw FormatError("Extra character |
|
1076 |
throw FormatError("Extra character at the end of line"); |
|
1077 | 1077 |
|
1078 | 1078 |
{ |
1079 | 1079 |
std::set<std::string>::iterator it = read_attr.find(attr); |
1080 | 1080 |
if (it != read_attr.end()) { |
1081 | 1081 |
std::ostringstream msg; |
1082 |
msg << "Multiple occurence of attribute " << attr; |
|
1082 |
msg << "Multiple occurence of attribute: " << attr; |
|
1083 | 1083 |
throw FormatError(msg.str()); |
1084 | 1084 |
} |
1085 | 1085 |
read_attr.insert(attr); |
1086 | 1086 |
} |
1087 | 1087 |
|
1088 | 1088 |
{ |
1089 | 1089 |
typename Attributes::iterator it = _attributes.lower_bound(attr); |
1090 | 1090 |
while (it != _attributes.end() && it->first == attr) { |
... | ... |
@@ -1096,35 +1096,32 @@ |
1096 | 1096 |
} |
1097 | 1097 |
if (readSuccess()) { |
1098 | 1098 |
line.putback(c); |
1099 | 1099 |
} |
1100 | 1100 |
for (typename Attributes::iterator it = _attributes.begin(); |
1101 | 1101 |
it != _attributes.end(); ++it) { |
1102 | 1102 |
if (read_attr.find(it->first) == read_attr.end()) { |
1103 | 1103 |
std::ostringstream msg; |
1104 |
msg << "Attribute not found |
|
1104 |
msg << "Attribute not found: " << it->first; |
|
1105 | 1105 |
throw FormatError(msg.str()); |
1106 | 1106 |
} |
1107 | 1107 |
} |
1108 | 1108 |
} |
1109 | 1109 |
|
1110 | 1110 |
public: |
1111 | 1111 |
|
1112 | 1112 |
/// \name Execution of the reader |
1113 | 1113 |
/// @{ |
1114 | 1114 |
|
1115 | 1115 |
/// \brief Start the batch processing |
1116 | 1116 |
/// |
1117 | 1117 |
/// This function starts the batch processing |
1118 | 1118 |
void run() { |
1119 | 1119 |
LEMON_ASSERT(_is != 0, "This reader assigned to an other reader"); |
1120 |
if (!*_is) { |
|
1121 |
throw FormatError("Cannot find file"); |
|
1122 |
} |
|
1123 | 1120 |
|
1124 | 1121 |
bool nodes_done = _skip_nodes; |
1125 | 1122 |
bool arcs_done = _skip_arcs; |
1126 | 1123 |
bool attributes_done = false; |
1127 | 1124 |
|
1128 | 1125 |
line_num = 0; |
1129 | 1126 |
readLine(); |
1130 | 1127 |
skipSection(); |
... | ... |
@@ -1133,17 +1130,17 @@ |
1133 | 1130 |
try { |
1134 | 1131 |
char c; |
1135 | 1132 |
std::string section, caption; |
1136 | 1133 |
line >> c; |
1137 | 1134 |
_reader_bits::readToken(line, section); |
1138 | 1135 |
_reader_bits::readToken(line, caption); |
1139 | 1136 |
|
1140 | 1137 |
if (line >> c) |
1141 |
throw FormatError("Extra character |
|
1138 |
throw FormatError("Extra character at the end of line"); |
|
1142 | 1139 |
|
1143 | 1140 |
if (section == "nodes" && !nodes_done) { |
1144 | 1141 |
if (_nodes_caption.empty() || _nodes_caption == caption) { |
1145 | 1142 |
readNodes(); |
1146 | 1143 |
nodes_done = true; |
1147 | 1144 |
} |
1148 | 1145 |
} else if ((section == "arcs" || section == "edges") && |
1149 | 1146 |
!arcs_done) { |
... | ... |
@@ -1303,29 +1300,29 @@ |
1303 | 1300 |
/// |
1304 | 1301 |
/// Construct an undirected graph reader, which reads from the given |
1305 | 1302 |
/// file. |
1306 | 1303 |
GraphReader(const std::string& fn, Graph& graph) |
1307 | 1304 |
: _is(new std::ifstream(fn.c_str())), local_is(true), |
1308 | 1305 |
_filename(fn), _graph(graph), |
1309 | 1306 |
_use_nodes(false), _use_edges(false), |
1310 | 1307 |
_skip_nodes(false), _skip_edges(false) { |
1311 |
if (!(*_is)) throw IoError( |
|
1308 |
if (!(*_is)) throw IoError("Cannot open file", fn); |
|
1312 | 1309 |
} |
1313 | 1310 |
|
1314 | 1311 |
/// \brief Constructor |
1315 | 1312 |
/// |
1316 | 1313 |
/// Construct an undirected graph reader, which reads from the given |
1317 | 1314 |
/// file. |
1318 | 1315 |
GraphReader(const char* fn, Graph& graph) |
1319 | 1316 |
: _is(new std::ifstream(fn)), local_is(true), |
1320 | 1317 |
_filename(fn), _graph(graph), |
1321 | 1318 |
_use_nodes(false), _use_edges(false), |
1322 | 1319 |
_skip_nodes(false), _skip_edges(false) { |
1323 |
if (!(*_is)) throw IoError( |
|
1320 |
if (!(*_is)) throw IoError("Cannot open file", fn); |
|
1324 | 1321 |
} |
1325 | 1322 |
|
1326 | 1323 |
/// \brief Destructor |
1327 | 1324 |
~GraphReader() { |
1328 | 1325 |
for (typename NodeMaps::iterator it = _node_maps.begin(); |
1329 | 1326 |
it != _node_maps.end(); ++it) { |
1330 | 1327 |
delete it->second; |
1331 | 1328 |
} |
... | ... |
@@ -1710,17 +1707,17 @@ |
1710 | 1707 |
++index; |
1711 | 1708 |
} |
1712 | 1709 |
|
1713 | 1710 |
for (int i = 0; i < static_cast<int>(_node_maps.size()); ++i) { |
1714 | 1711 |
std::map<std::string, int>::iterator jt = |
1715 | 1712 |
maps.find(_node_maps[i].first); |
1716 | 1713 |
if (jt == maps.end()) { |
1717 | 1714 |
std::ostringstream msg; |
1718 |
msg << "Map not found |
|
1715 |
msg << "Map not found: " << _node_maps[i].first; |
|
1719 | 1716 |
throw FormatError(msg.str()); |
1720 | 1717 |
} |
1721 | 1718 |
map_index[i] = jt->second; |
1722 | 1719 |
} |
1723 | 1720 |
|
1724 | 1721 |
{ |
1725 | 1722 |
std::map<std::string, int>::iterator jt = maps.find("label"); |
1726 | 1723 |
if (jt != maps.end()) { |
... | ... |
@@ -1739,26 +1736,26 @@ |
1739 | 1736 |
for (int i = 0; i < map_num; ++i) { |
1740 | 1737 |
if (!_reader_bits::readToken(line, tokens[i])) { |
1741 | 1738 |
std::ostringstream msg; |
1742 | 1739 |
msg << "Column not found (" << i + 1 << ")"; |
1743 | 1740 |
throw FormatError(msg.str()); |
1744 | 1741 |
} |
1745 | 1742 |
} |
1746 | 1743 |
if (line >> std::ws >> c) |
1747 |
throw FormatError("Extra character |
|
1744 |
throw FormatError("Extra character at the end of line"); |
|
1748 | 1745 |
|
1749 | 1746 |
Node n; |
1750 | 1747 |
if (!_use_nodes) { |
1751 | 1748 |
n = _graph.addNode(); |
1752 | 1749 |
if (label_index != -1) |
1753 | 1750 |
_node_index.insert(std::make_pair(tokens[label_index], n)); |
1754 | 1751 |
} else { |
1755 | 1752 |
if (label_index == -1) |
1756 |
throw FormatError("Label map not found |
|
1753 |
throw FormatError("Label map not found"); |
|
1757 | 1754 |
typename std::map<std::string, Node>::iterator it = |
1758 | 1755 |
_node_index.find(tokens[label_index]); |
1759 | 1756 |
if (it == _node_index.end()) { |
1760 | 1757 |
std::ostringstream msg; |
1761 | 1758 |
msg << "Node with label not found: " << tokens[label_index]; |
1762 | 1759 |
throw FormatError(msg.str()); |
1763 | 1760 |
} |
1764 | 1761 |
n = it->second; |
... | ... |
@@ -1803,17 +1800,17 @@ |
1803 | 1800 |
++index; |
1804 | 1801 |
} |
1805 | 1802 |
|
1806 | 1803 |
for (int i = 0; i < static_cast<int>(_edge_maps.size()); ++i) { |
1807 | 1804 |
std::map<std::string, int>::iterator jt = |
1808 | 1805 |
maps.find(_edge_maps[i].first); |
1809 | 1806 |
if (jt == maps.end()) { |
1810 | 1807 |
std::ostringstream msg; |
1811 |
msg << "Map not found |
|
1808 |
msg << "Map not found: " << _edge_maps[i].first; |
|
1812 | 1809 |
throw FormatError(msg.str()); |
1813 | 1810 |
} |
1814 | 1811 |
map_index[i] = jt->second; |
1815 | 1812 |
} |
1816 | 1813 |
|
1817 | 1814 |
{ |
1818 | 1815 |
std::map<std::string, int>::iterator jt = maps.find("label"); |
1819 | 1816 |
if (jt != maps.end()) { |
... | ... |
@@ -1841,17 +1838,17 @@ |
1841 | 1838 |
for (int i = 0; i < map_num; ++i) { |
1842 | 1839 |
if (!_reader_bits::readToken(line, tokens[i])) { |
1843 | 1840 |
std::ostringstream msg; |
1844 | 1841 |
msg << "Column not found (" << i + 1 << ")"; |
1845 | 1842 |
throw FormatError(msg.str()); |
1846 | 1843 |
} |
1847 | 1844 |
} |
1848 | 1845 |
if (line >> std::ws >> c) |
1849 |
throw FormatError("Extra character |
|
1846 |
throw FormatError("Extra character at the end of line"); |
|
1850 | 1847 |
|
1851 | 1848 |
Edge e; |
1852 | 1849 |
if (!_use_edges) { |
1853 | 1850 |
|
1854 | 1851 |
typename NodeIndex::iterator it; |
1855 | 1852 |
|
1856 | 1853 |
it = _node_index.find(source_token); |
1857 | 1854 |
if (it == _node_index.end()) { |
... | ... |
@@ -1869,17 +1866,17 @@ |
1869 | 1866 |
} |
1870 | 1867 |
Node target = it->second; |
1871 | 1868 |
|
1872 | 1869 |
e = _graph.addEdge(source, target); |
1873 | 1870 |
if (label_index != -1) |
1874 | 1871 |
_edge_index.insert(std::make_pair(tokens[label_index], e)); |
1875 | 1872 |
} else { |
1876 | 1873 |
if (label_index == -1) |
1877 |
throw FormatError("Label map not found |
|
1874 |
throw FormatError("Label map not found"); |
|
1878 | 1875 |
typename std::map<std::string, Edge>::iterator it = |
1879 | 1876 |
_edge_index.find(tokens[label_index]); |
1880 | 1877 |
if (it == _edge_index.end()) { |
1881 | 1878 |
std::ostringstream msg; |
1882 | 1879 |
msg << "Edge with label not found: " << tokens[label_index]; |
1883 | 1880 |
throw FormatError(msg.str()); |
1884 | 1881 |
} |
1885 | 1882 |
e = it->second; |
... | ... |
@@ -1904,23 +1901,23 @@ |
1904 | 1901 |
line.putback(c); |
1905 | 1902 |
|
1906 | 1903 |
std::string attr, token; |
1907 | 1904 |
if (!_reader_bits::readToken(line, attr)) |
1908 | 1905 |
throw FormatError("Attribute name not found"); |
1909 | 1906 |
if (!_reader_bits::readToken(line, token)) |
1910 | 1907 |
throw FormatError("Attribute value not found"); |
1911 | 1908 |
if (line >> c) |
1912 |
throw FormatError("Extra character |
|
1909 |
throw FormatError("Extra character at the end of line"); |
|
1913 | 1910 |
|
1914 | 1911 |
{ |
1915 | 1912 |
std::set<std::string>::iterator it = read_attr.find(attr); |
1916 | 1913 |
if (it != read_attr.end()) { |
1917 | 1914 |
std::ostringstream msg; |
1918 |
msg << "Multiple occurence of attribute " << attr; |
|
1915 |
msg << "Multiple occurence of attribute: " << attr; |
|
1919 | 1916 |
throw FormatError(msg.str()); |
1920 | 1917 |
} |
1921 | 1918 |
read_attr.insert(attr); |
1922 | 1919 |
} |
1923 | 1920 |
|
1924 | 1921 |
{ |
1925 | 1922 |
typename Attributes::iterator it = _attributes.lower_bound(attr); |
1926 | 1923 |
while (it != _attributes.end() && it->first == attr) { |
... | ... |
@@ -1932,17 +1929,17 @@ |
1932 | 1929 |
} |
1933 | 1930 |
if (readSuccess()) { |
1934 | 1931 |
line.putback(c); |
1935 | 1932 |
} |
1936 | 1933 |
for (typename Attributes::iterator it = _attributes.begin(); |
1937 | 1934 |
it != _attributes.end(); ++it) { |
1938 | 1935 |
if (read_attr.find(it->first) == read_attr.end()) { |
1939 | 1936 |
std::ostringstream msg; |
1940 |
msg << "Attribute not found |
|
1937 |
msg << "Attribute not found: " << it->first; |
|
1941 | 1938 |
throw FormatError(msg.str()); |
1942 | 1939 |
} |
1943 | 1940 |
} |
1944 | 1941 |
} |
1945 | 1942 |
|
1946 | 1943 |
public: |
1947 | 1944 |
|
1948 | 1945 |
/// \name Execution of the reader |
... | ... |
@@ -1967,17 +1964,17 @@ |
1967 | 1964 |
try { |
1968 | 1965 |
char c; |
1969 | 1966 |
std::string section, caption; |
1970 | 1967 |
line >> c; |
1971 | 1968 |
_reader_bits::readToken(line, section); |
1972 | 1969 |
_reader_bits::readToken(line, caption); |
1973 | 1970 |
|
1974 | 1971 |
if (line >> c) |
1975 |
throw FormatError("Extra character |
|
1972 |
throw FormatError("Extra character at the end of line"); |
|
1976 | 1973 |
|
1977 | 1974 |
if (section == "nodes" && !nodes_done) { |
1978 | 1975 |
if (_nodes_caption.empty() || _nodes_caption == caption) { |
1979 | 1976 |
readNodes(); |
1980 | 1977 |
nodes_done = true; |
1981 | 1978 |
} |
1982 | 1979 |
} else if ((section == "edges" || section == "arcs") && |
1983 | 1980 |
!edges_done) { |
... | ... |
@@ -2090,26 +2087,26 @@ |
2090 | 2087 |
: _is(&is), local_is(false) {} |
2091 | 2088 |
|
2092 | 2089 |
/// \brief Constructor |
2093 | 2090 |
/// |
2094 | 2091 |
/// Construct a section reader, which reads from the given file. |
2095 | 2092 |
SectionReader(const std::string& fn) |
2096 | 2093 |
: _is(new std::ifstream(fn.c_str())), local_is(true), |
2097 | 2094 |
_filename(fn) { |
2098 |
if (!(*_is)) throw IoError( |
|
2095 |
if (!(*_is)) throw IoError("Cannot open file", fn); |
|
2099 | 2096 |
} |
2100 | 2097 |
|
2101 | 2098 |
/// \brief Constructor |
2102 | 2099 |
/// |
2103 | 2100 |
/// Construct a section reader, which reads from the given file. |
2104 | 2101 |
SectionReader(const char* fn) |
2105 | 2102 |
: _is(new std::ifstream(fn)), local_is(true), |
2106 | 2103 |
_filename(fn) { |
2107 |
if (!(*_is)) throw IoError( |
|
2104 |
if (!(*_is)) throw IoError("Cannot open file", fn); |
|
2108 | 2105 |
} |
2109 | 2106 |
|
2110 | 2107 |
/// \brief Destructor |
2111 | 2108 |
~SectionReader() { |
2112 | 2109 |
for (Sections::iterator it = _sections.begin(); |
2113 | 2110 |
it != _sections.end(); ++it) { |
2114 | 2111 |
delete it->second; |
2115 | 2112 |
} |
... | ... |
@@ -2256,21 +2253,21 @@ |
2256 | 2253 |
try { |
2257 | 2254 |
char c; |
2258 | 2255 |
std::string section, caption; |
2259 | 2256 |
line >> c; |
2260 | 2257 |
_reader_bits::readToken(line, section); |
2261 | 2258 |
_reader_bits::readToken(line, caption); |
2262 | 2259 |
|
2263 | 2260 |
if (line >> c) |
2264 |
throw FormatError("Extra character |
|
2261 |
throw FormatError("Extra character at the end of line"); |
|
2265 | 2262 |
|
2266 | 2263 |
if (extra_sections.find(section) != extra_sections.end()) { |
2267 | 2264 |
std::ostringstream msg; |
2268 |
msg << "Multiple occurence of section " << section; |
|
2265 |
msg << "Multiple occurence of section: " << section; |
|
2269 | 2266 |
throw FormatError(msg.str()); |
2270 | 2267 |
} |
2271 | 2268 |
Sections::iterator it = _sections.find(section); |
2272 | 2269 |
if (it != _sections.end()) { |
2273 | 2270 |
extra_sections.insert(section); |
2274 | 2271 |
it->second->process(*_is, line_num); |
2275 | 2272 |
} |
2276 | 2273 |
readLine(); |
... | ... |
@@ -2382,26 +2379,26 @@ |
2382 | 2379 |
: _is(&is), local_is(false) {} |
2383 | 2380 |
|
2384 | 2381 |
/// \brief Constructor |
2385 | 2382 |
/// |
2386 | 2383 |
/// Construct an \e LGF contents reader, which reads from the given |
2387 | 2384 |
/// file. |
2388 | 2385 |
LgfContents(const std::string& fn) |
2389 | 2386 |
: _is(new std::ifstream(fn.c_str())), local_is(true) { |
2390 |
if (!(*_is)) throw IoError( |
|
2387 |
if (!(*_is)) throw IoError("Cannot open file", fn); |
|
2391 | 2388 |
} |
2392 | 2389 |
|
2393 | 2390 |
/// \brief Constructor |
2394 | 2391 |
/// |
2395 | 2392 |
/// Construct an \e LGF contents reader, which reads from the given |
2396 | 2393 |
/// file. |
2397 | 2394 |
LgfContents(const char* fn) |
2398 | 2395 |
: _is(new std::ifstream(fn)), local_is(true) { |
2399 |
if (!(*_is)) throw IoError( |
|
2396 |
if (!(*_is)) throw IoError("Cannot open file", fn); |
|
2400 | 2397 |
} |
2401 | 2398 |
|
2402 | 2399 |
/// \brief Destructor |
2403 | 2400 |
~LgfContents() { |
2404 | 2401 |
if (local_is) delete _is; |
2405 | 2402 |
} |
2406 | 2403 |
|
2407 | 2404 |
private: |
... | ... |
@@ -458,27 +458,27 @@ |
458 | 458 |
|
459 | 459 |
/// \brief Constructor |
460 | 460 |
/// |
461 | 461 |
/// Construct a directed graph writer, which writes to the given |
462 | 462 |
/// output file. |
463 | 463 |
DigraphWriter(const std::string& fn, const Digraph& digraph) |
464 | 464 |
: _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph), |
465 | 465 |
_skip_nodes(false), _skip_arcs(false) { |
466 |
if (!(*_os)) throw IoError( |
|
466 |
if (!(*_os)) throw IoError("Cannot write file", fn); |
|
467 | 467 |
} |
468 | 468 |
|
469 | 469 |
/// \brief Constructor |
470 | 470 |
/// |
471 | 471 |
/// Construct a directed graph writer, which writes to the given |
472 | 472 |
/// output file. |
473 | 473 |
DigraphWriter(const char* fn, const Digraph& digraph) |
474 | 474 |
: _os(new std::ofstream(fn)), local_os(true), _digraph(digraph), |
475 | 475 |
_skip_nodes(false), _skip_arcs(false) { |
476 |
if (!(*_os)) throw IoError( |
|
476 |
if (!(*_os)) throw IoError("Cannot write file", fn); |
|
477 | 477 |
} |
478 | 478 |
|
479 | 479 |
/// \brief Destructor |
480 | 480 |
~DigraphWriter() { |
481 | 481 |
for (typename NodeMaps::iterator it = _node_maps.begin(); |
482 | 482 |
it != _node_maps.end(); ++it) { |
483 | 483 |
delete it->second; |
484 | 484 |
} |
... | ... |
@@ -1018,27 +1018,27 @@ |
1018 | 1018 |
|
1019 | 1019 |
/// \brief Constructor |
1020 | 1020 |
/// |
1021 | 1021 |
/// Construct a directed graph writer, which writes to the given |
1022 | 1022 |
/// output file. |
1023 | 1023 |
GraphWriter(const std::string& fn, const Graph& graph) |
1024 | 1024 |
: _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph), |
1025 | 1025 |
_skip_nodes(false), _skip_edges(false) { |
1026 |
if (!(*_os)) throw IoError( |
|
1026 |
if (!(*_os)) throw IoError("Cannot write file", fn); |
|
1027 | 1027 |
} |
1028 | 1028 |
|
1029 | 1029 |
/// \brief Constructor |
1030 | 1030 |
/// |
1031 | 1031 |
/// Construct a directed graph writer, which writes to the given |
1032 | 1032 |
/// output file. |
1033 | 1033 |
GraphWriter(const char* fn, const Graph& graph) |
1034 | 1034 |
: _os(new std::ofstream(fn)), local_os(true), _graph(graph), |
1035 | 1035 |
_skip_nodes(false), _skip_edges(false) { |
1036 |
if (!(*_os)) throw IoError( |
|
1036 |
if (!(*_os)) throw IoError("Cannot write file", fn); |
|
1037 | 1037 |
} |
1038 | 1038 |
|
1039 | 1039 |
/// \brief Destructor |
1040 | 1040 |
~GraphWriter() { |
1041 | 1041 |
for (typename NodeMaps::iterator it = _node_maps.begin(); |
1042 | 1042 |
it != _node_maps.end(); ++it) { |
1043 | 1043 |
delete it->second; |
1044 | 1044 |
} |
... | ... |
@@ -1580,25 +1580,25 @@ |
1580 | 1580 |
SectionWriter(std::ostream& os) |
1581 | 1581 |
: _os(&os), local_os(false) {} |
1582 | 1582 |
|
1583 | 1583 |
/// \brief Constructor |
1584 | 1584 |
/// |
1585 | 1585 |
/// Construct a section writer, which writes into the given file. |
1586 | 1586 |
SectionWriter(const std::string& fn) |
1587 | 1587 |
: _os(new std::ofstream(fn.c_str())), local_os(true) { |
1588 |
if (!(*_os)) throw IoError( |
|
1588 |
if (!(*_os)) throw IoError("Cannot write file", fn); |
|
1589 | 1589 |
} |
1590 | 1590 |
|
1591 | 1591 |
/// \brief Constructor |
1592 | 1592 |
/// |
1593 | 1593 |
/// Construct a section writer, which writes into the given file. |
1594 | 1594 |
SectionWriter(const char* fn) |
1595 | 1595 |
: _os(new std::ofstream(fn)), local_os(true) { |
1596 |
if (!(*_os)) throw IoError( |
|
1596 |
if (!(*_os)) throw IoError("Cannot write file", fn); |
|
1597 | 1597 |
} |
1598 | 1598 |
|
1599 | 1599 |
/// \brief Destructor |
1600 | 1600 |
~SectionWriter() { |
1601 | 1601 |
for (Sections::iterator it = _sections.begin(); |
1602 | 1602 |
it != _sections.end(); ++it) { |
1603 | 1603 |
delete it->second; |
1604 | 1604 |
} |
0 comments (0 inline)