0
11
0
11
28
10
28
10
17
199
341
120
93
... | ... |
@@ -48,9 +48,9 @@ |
48 | 48 |
arcMap("capacity", cap). // read the 'capacity' arc map into cap |
49 | 49 |
node("source", s). // read 'source' node to s |
50 | 50 |
node("target", t). // read 'target' node to t |
51 | 51 |
run(); |
52 |
} catch ( |
|
52 |
} catch (Exception& error) { // check if there was any error |
|
53 | 53 |
std::cerr << "Error: " << error.what() << std::endl; |
54 | 54 |
return -1; |
55 | 55 |
} |
56 | 56 |
... | ... |
@@ -309,10 +309,11 @@ |
309 | 309 |
///Magic type for operator[] |
310 | 310 |
|
311 | 311 |
///This is the type of the return value of ArgParser::operator[](). |
312 | 312 |
///It automatically converts to \c int, \c double, \c bool or |
313 |
///\c std::string if the type of the option matches, otherwise it |
|
314 |
///throws an exception (i.e. it performs runtime type checking). |
|
313 |
///\c std::string if the type of the option matches, which is checked |
|
314 |
///with an \ref LEMON_ASSERT "assertion" (i.e. it performs runtime |
|
315 |
///type checking). |
|
315 | 316 |
class RefType |
316 | 317 |
{ |
317 | 318 |
const ArgParser &_parser; |
318 | 319 |
std::string _name; |
... | ... |
@@ -134,18 +134,8 @@ |
134 | 134 |
typename TR=BfsDefaultTraits<GR> > |
135 | 135 |
#endif |
136 | 136 |
class Bfs { |
137 | 137 |
public: |
138 |
///\ref Exception for uninitialized parameters. |
|
139 |
|
|
140 |
///This error represents problems in the initialization of the |
|
141 |
///parameters of the algorithm. |
|
142 |
class UninitializedParameter : public lemon::UninitializedParameter { |
|
143 |
public: |
|
144 |
virtual const char* what() const throw() { |
|
145 |
return "lemon::Bfs::UninitializedParameter"; |
|
146 |
} |
|
147 |
}; |
|
148 | 138 |
|
149 | 139 |
///The type of the digraph the algorithm runs on. |
150 | 140 |
typedef typename TR::Digraph Digraph; |
151 | 141 |
|
... | ... |
@@ -231,9 +221,10 @@ |
231 | 221 |
struct SetPredMapTraits : public Traits { |
232 | 222 |
typedef T PredMap; |
233 | 223 |
static PredMap *createPredMap(const Digraph &) |
234 | 224 |
{ |
235 |
|
|
225 |
LEMON_ASSERT(false, "PredMap is not initialized"); |
|
226 |
return 0; // ignore warnings |
|
236 | 227 |
} |
237 | 228 |
}; |
238 | 229 |
///\brief \ref named-templ-param "Named parameter" for setting |
239 | 230 |
///\ref PredMap type. |
... | ... |
@@ -249,9 +240,10 @@ |
249 | 240 |
struct SetDistMapTraits : public Traits { |
250 | 241 |
typedef T DistMap; |
251 | 242 |
static DistMap *createDistMap(const Digraph &) |
252 | 243 |
{ |
253 |
|
|
244 |
LEMON_ASSERT(false, "DistMap is not initialized"); |
|
245 |
return 0; // ignore warnings |
|
254 | 246 |
} |
255 | 247 |
}; |
256 | 248 |
///\brief \ref named-templ-param "Named parameter" for setting |
257 | 249 |
///\ref DistMap type. |
... | ... |
@@ -267,9 +259,10 @@ |
267 | 259 |
struct SetReachedMapTraits : public Traits { |
268 | 260 |
typedef T ReachedMap; |
269 | 261 |
static ReachedMap *createReachedMap(const Digraph &) |
270 | 262 |
{ |
271 |
|
|
263 |
LEMON_ASSERT(false, "ReachedMap is not initialized"); |
|
264 |
return 0; // ignore warnings |
|
272 | 265 |
} |
273 | 266 |
}; |
274 | 267 |
///\brief \ref named-templ-param "Named parameter" for setting |
275 | 268 |
///\ref ReachedMap type. |
... | ... |
@@ -285,9 +278,10 @@ |
285 | 278 |
struct SetProcessedMapTraits : public Traits { |
286 | 279 |
typedef T ProcessedMap; |
287 | 280 |
static ProcessedMap *createProcessedMap(const Digraph &) |
288 | 281 |
{ |
289 |
|
|
282 |
LEMON_ASSERT(false, "ProcessedMap is not initialized"); |
|
283 |
return 0; // ignore warnings |
|
290 | 284 |
} |
291 | 285 |
}; |
292 | 286 |
///\brief \ref named-templ-param "Named parameter" for setting |
293 | 287 |
///\ref ProcessedMap type. |
... | ... |
@@ -303,8 +297,9 @@ |
303 | 297 |
typedef typename Digraph::template NodeMap<bool> ProcessedMap; |
304 | 298 |
static ProcessedMap *createProcessedMap(const Digraph &g) |
305 | 299 |
{ |
306 | 300 |
return new ProcessedMap(g); |
301 |
return 0; // ignore warnings |
|
307 | 302 |
} |
308 | 303 |
}; |
309 | 304 |
///\brief \ref named-templ-param "Named parameter" for setting |
310 | 305 |
///\ref ProcessedMap type to be <tt>Digraph::NodeMap<bool></tt>. |
... | ... |
@@ -1039,9 +1034,8 @@ |
1039 | 1034 |
/// |
1040 | 1035 |
///\return \c true if \c t is reachable form \c s. |
1041 | 1036 |
bool run(Node s, Node t) |
1042 | 1037 |
{ |
1043 |
if (s==INVALID || t==INVALID) throw UninitializedParameter(); |
|
1044 | 1038 |
Bfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g)); |
1045 | 1039 |
if (Base::_pred) |
1046 | 1040 |
alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); |
1047 | 1041 |
if (Base::_dist) |
... | ... |
@@ -1322,20 +1316,8 @@ |
1322 | 1316 |
#endif |
1323 | 1317 |
class BfsVisit { |
1324 | 1318 |
public: |
1325 | 1319 |
|
1326 |
/// \brief \ref Exception for uninitialized parameters. |
|
1327 |
/// |
|
1328 |
/// This error represents problems in the initialization |
|
1329 |
/// of the parameters of the algorithm. |
|
1330 |
class UninitializedParameter : public lemon::UninitializedParameter { |
|
1331 |
public: |
|
1332 |
virtual const char* what() const throw() |
|
1333 |
{ |
|
1334 |
return "lemon::BfsVisit::UninitializedParameter"; |
|
1335 |
} |
|
1336 |
}; |
|
1337 |
|
|
1338 | 1320 |
///The traits class. |
1339 | 1321 |
typedef _Traits Traits; |
1340 | 1322 |
|
1341 | 1323 |
///The type of the digraph the algorithm runs on. |
... | ... |
@@ -1388,9 +1370,10 @@ |
1388 | 1370 |
template <class T> |
1389 | 1371 |
struct SetReachedMapTraits : public Traits { |
1390 | 1372 |
typedef T ReachedMap; |
1391 | 1373 |
static ReachedMap *createReachedMap(const Digraph &digraph) { |
1392 |
|
|
1374 |
LEMON_ASSERT(false, "ReachedMap is not initialized"); |
|
1375 |
return 0; // ignore warnings |
|
1393 | 1376 |
} |
1394 | 1377 |
}; |
1395 | 1378 |
/// \brief \ref named-templ-param "Named parameter" for setting |
1396 | 1379 |
/// ReachedMap type. |
... | ... |
@@ -128,9 +128,8 @@ |
128 | 128 |
/// This method sets the priority of the given item if it is |
129 | 129 |
/// already stored in the heap. |
130 | 130 |
/// Otherwise it inserts the given item with the given priority. |
131 | 131 |
/// |
132 |
/// It may throw an \ref UnderflowPriorityException. |
|
133 | 132 |
/// \param i The item. |
134 | 133 |
/// \param p The priority. |
135 | 134 |
void set(const Item &i, const Prio &p) {} |
136 | 135 |
... | ... |
@@ -135,18 +135,8 @@ |
135 | 135 |
typename TR=DfsDefaultTraits<GR> > |
136 | 136 |
#endif |
137 | 137 |
class Dfs { |
138 | 138 |
public: |
139 |
///\ref Exception for uninitialized parameters. |
|
140 |
|
|
141 |
///This error represents problems in the initialization of the |
|
142 |
///parameters of the algorithm. |
|
143 |
class UninitializedParameter : public lemon::UninitializedParameter { |
|
144 |
public: |
|
145 |
virtual const char* what() const throw() { |
|
146 |
return "lemon::Dfs::UninitializedParameter"; |
|
147 |
} |
|
148 |
}; |
|
149 | 139 |
|
150 | 140 |
///The type of the digraph the algorithm runs on. |
151 | 141 |
typedef typename TR::Digraph Digraph; |
152 | 142 |
|
... | ... |
@@ -231,9 +221,10 @@ |
231 | 221 |
struct SetPredMapTraits : public Traits { |
232 | 222 |
typedef T PredMap; |
233 | 223 |
static PredMap *createPredMap(const Digraph &) |
234 | 224 |
{ |
235 |
|
|
225 |
LEMON_ASSERT(false, "PredMap is not initialized"); |
|
226 |
return 0; // ignore warnings |
|
236 | 227 |
} |
237 | 228 |
}; |
238 | 229 |
///\brief \ref named-templ-param "Named parameter" for setting |
239 | 230 |
///\ref PredMap type. |
... | ... |
@@ -249,9 +240,10 @@ |
249 | 240 |
struct SetDistMapTraits : public Traits { |
250 | 241 |
typedef T DistMap; |
251 | 242 |
static DistMap *createDistMap(const Digraph &) |
252 | 243 |
{ |
253 |
|
|
244 |
LEMON_ASSERT(false, "DistMap is not initialized"); |
|
245 |
return 0; // ignore warnings |
|
254 | 246 |
} |
255 | 247 |
}; |
256 | 248 |
///\brief \ref named-templ-param "Named parameter" for setting |
257 | 249 |
///\ref DistMap type. |
... | ... |
@@ -267,9 +259,10 @@ |
267 | 259 |
struct SetReachedMapTraits : public Traits { |
268 | 260 |
typedef T ReachedMap; |
269 | 261 |
static ReachedMap *createReachedMap(const Digraph &) |
270 | 262 |
{ |
271 |
|
|
263 |
LEMON_ASSERT(false, "ReachedMap is not initialized"); |
|
264 |
return 0; // ignore warnings |
|
272 | 265 |
} |
273 | 266 |
}; |
274 | 267 |
///\brief \ref named-templ-param "Named parameter" for setting |
275 | 268 |
///\ref ReachedMap type. |
... | ... |
@@ -285,9 +278,10 @@ |
285 | 278 |
struct SetProcessedMapTraits : public Traits { |
286 | 279 |
typedef T ProcessedMap; |
287 | 280 |
static ProcessedMap *createProcessedMap(const Digraph &) |
288 | 281 |
{ |
289 |
|
|
282 |
LEMON_ASSERT(false, "ProcessedMap is not initialized"); |
|
283 |
return 0; // ignore warnings |
|
290 | 284 |
} |
291 | 285 |
}; |
292 | 286 |
///\brief \ref named-templ-param "Named parameter" for setting |
293 | 287 |
///\ref ProcessedMap type. |
... | ... |
@@ -973,9 +967,8 @@ |
973 | 967 |
/// |
974 | 968 |
///\return \c true if \c t is reachable form \c s. |
975 | 969 |
bool run(Node s, Node t) |
976 | 970 |
{ |
977 |
if (s==INVALID || t==INVALID) throw UninitializedParameter(); |
|
978 | 971 |
Dfs<Digraph,TR> alg(*reinterpret_cast<const Digraph*>(Base::_g)); |
979 | 972 |
if (Base::_pred) |
980 | 973 |
alg.predMap(*reinterpret_cast<PredMap*>(Base::_pred)); |
981 | 974 |
if (Base::_dist) |
... | ... |
@@ -1269,20 +1262,8 @@ |
1269 | 1262 |
#endif |
1270 | 1263 |
class DfsVisit { |
1271 | 1264 |
public: |
1272 | 1265 |
|
1273 |
/// \brief \ref Exception for uninitialized parameters. |
|
1274 |
/// |
|
1275 |
/// This error represents problems in the initialization |
|
1276 |
/// of the parameters of the algorithm. |
|
1277 |
class UninitializedParameter : public lemon::UninitializedParameter { |
|
1278 |
public: |
|
1279 |
virtual const char* what() const throw() |
|
1280 |
{ |
|
1281 |
return "lemon::DfsVisit::UninitializedParameter"; |
|
1282 |
} |
|
1283 |
}; |
|
1284 |
|
|
1285 | 1266 |
///The traits class. |
1286 | 1267 |
typedef _Traits Traits; |
1287 | 1268 |
|
1288 | 1269 |
///The type of the digraph the algorithm runs on. |
... | ... |
@@ -1335,9 +1316,10 @@ |
1335 | 1316 |
template <class T> |
1336 | 1317 |
struct SetReachedMapTraits : public Traits { |
1337 | 1318 |
typedef T ReachedMap; |
1338 | 1319 |
static ReachedMap *createReachedMap(const Digraph &digraph) { |
1339 |
|
|
1320 |
LEMON_ASSERT(false, "ReachedMap is not initialized"); |
|
1321 |
return 0; // ignore warnings |
|
1340 | 1322 |
} |
1341 | 1323 |
}; |
1342 | 1324 |
/// \brief \ref named-templ-param "Named parameter" for setting |
1343 | 1325 |
/// ReachedMap type. |
... | ... |
@@ -224,18 +224,8 @@ |
224 | 224 |
typename TR=DijkstraDefaultTraits<GR,LM> > |
225 | 225 |
#endif |
226 | 226 |
class Dijkstra { |
227 | 227 |
public: |
228 |
///\ref Exception for uninitialized parameters. |
|
229 |
|
|
230 |
///This error represents problems in the initialization of the |
|
231 |
///parameters of the algorithm. |
|
232 |
class UninitializedParameter : public lemon::UninitializedParameter { |
|
233 |
public: |
|
234 |
virtual const char* what() const throw() { |
|
235 |
return "lemon::Dijkstra::UninitializedParameter"; |
|
236 |
} |
|
237 |
}; |
|
238 | 228 |
|
239 | 229 |
///The type of the digraph the algorithm runs on. |
240 | 230 |
typedef typename TR::Digraph Digraph; |
241 | 231 |
|
... | ... |
@@ -331,9 +321,10 @@ |
331 | 321 |
struct SetPredMapTraits : public Traits { |
332 | 322 |
typedef T PredMap; |
333 | 323 |
static PredMap *createPredMap(const Digraph &) |
334 | 324 |
{ |
335 |
|
|
325 |
LEMON_ASSERT(false, "PredMap is not initialized"); |
|
326 |
return 0; // ignore warnings |
|
336 | 327 |
} |
337 | 328 |
}; |
338 | 329 |
///\brief \ref named-templ-param "Named parameter" for setting |
339 | 330 |
///\ref PredMap type. |
... | ... |
@@ -350,9 +341,10 @@ |
350 | 341 |
struct SetDistMapTraits : public Traits { |
351 | 342 |
typedef T DistMap; |
352 | 343 |
static DistMap *createDistMap(const Digraph &) |
353 | 344 |
{ |
354 |
|
|
345 |
LEMON_ASSERT(false, "DistMap is not initialized"); |
|
346 |
return 0; // ignore warnings |
|
355 | 347 |
} |
356 | 348 |
}; |
357 | 349 |
///\brief \ref named-templ-param "Named parameter" for setting |
358 | 350 |
///\ref DistMap type. |
... | ... |
@@ -369,9 +361,10 @@ |
369 | 361 |
struct SetProcessedMapTraits : public Traits { |
370 | 362 |
typedef T ProcessedMap; |
371 | 363 |
static ProcessedMap *createProcessedMap(const Digraph &) |
372 | 364 |
{ |
373 |
|
|
365 |
LEMON_ASSERT(false, "ProcessedMap is not initialized"); |
|
366 |
return 0; // ignore warnings |
|
374 | 367 |
} |
375 | 368 |
}; |
376 | 369 |
///\brief \ref named-templ-param "Named parameter" for setting |
377 | 370 |
///\ref ProcessedMap type. |
... | ... |
@@ -407,13 +400,15 @@ |
407 | 400 |
struct SetHeapTraits : public Traits { |
408 | 401 |
typedef CR HeapCrossRef; |
409 | 402 |
typedef H Heap; |
410 | 403 |
static HeapCrossRef *createHeapCrossRef(const Digraph &) { |
411 |
|
|
404 |
LEMON_ASSERT(false, "HeapCrossRef is not initialized"); |
|
405 |
return 0; // ignore warnings |
|
412 | 406 |
} |
413 | 407 |
static Heap *createHeap(HeapCrossRef &) |
414 | 408 |
{ |
415 |
|
|
409 |
LEMON_ASSERT(false, "Heap is not initialized"); |
|
410 |
return 0; // ignore warnings |
|
416 | 411 |
} |
417 | 412 |
}; |
418 | 413 |
///\brief \ref named-templ-param "Named parameter" for setting |
419 | 414 |
///heap and cross reference type |
... | ... |
@@ -1157,9 +1152,8 @@ |
1157 | 1152 |
///This method runs %Dijkstra algorithm from the given source node |
1158 | 1153 |
///in order to compute the shortest path to each node. |
1159 | 1154 |
void run(Node s) |
1160 | 1155 |
{ |
1161 |
if (s==INVALID) throw UninitializedParameter(); |
|
1162 | 1156 |
Dijkstra<Digraph,LengthMap,TR> |
1163 | 1157 |
dijk(*reinterpret_cast<const Digraph*>(Base::_g), |
1164 | 1158 |
*reinterpret_cast<const LengthMap*>(Base::_length)); |
1165 | 1159 |
if (Base::_pred) |
... | ... |
@@ -1179,9 +1173,8 @@ |
1179 | 1173 |
/// |
1180 | 1174 |
///\return \c true if \c t is reachable form \c s. |
1181 | 1175 |
bool run(Node s, Node t) |
1182 | 1176 |
{ |
1183 |
if (s==INVALID || t==INVALID) throw UninitializedParameter(); |
|
1184 | 1177 |
Dijkstra<Digraph,LengthMap,TR> |
1185 | 1178 |
dijk(*reinterpret_cast<const Digraph*>(Base::_g), |
1186 | 1179 |
*reinterpret_cast<const LengthMap*>(Base::_length)); |
1187 | 1180 |
if (Base::_pred) |
... | ... |
@@ -34,382 +34,240 @@ |
34 | 34 |
|
35 | 35 |
/// \addtogroup exceptions |
36 | 36 |
/// @{ |
37 | 37 |
|
38 |
/// \brief |
|
38 |
/// \brief Generic exception class. |
|
39 | 39 |
/// |
40 |
/// Exception safe wrapper class to implement the members of exceptions. |
|
41 |
template <typename _Type> |
|
42 |
class ExceptionMember { |
|
43 |
public: |
|
44 |
typedef _Type Type; |
|
45 |
|
|
46 |
ExceptionMember() throw() { |
|
47 |
try { |
|
48 |
ptr.reset(new Type()); |
|
49 |
} catch (...) {} |
|
50 |
} |
|
51 |
|
|
52 |
ExceptionMember(const Type& type) throw() { |
|
53 |
try { |
|
54 |
ptr.reset(new Type()); |
|
55 |
if (ptr.get() == 0) return; |
|
56 |
*ptr = type; |
|
57 |
} catch (...) {} |
|
58 |
} |
|
59 |
|
|
60 |
ExceptionMember(const ExceptionMember& copy) throw() { |
|
61 |
try { |
|
62 |
if (!copy.valid()) return; |
|
63 |
ptr.reset(new Type()); |
|
64 |
if (ptr.get() == 0) return; |
|
65 |
*ptr = copy.get(); |
|
66 |
} catch (...) {} |
|
67 |
} |
|
68 |
|
|
69 |
ExceptionMember& operator=(const ExceptionMember& copy) throw() { |
|
70 |
if (ptr.get() == 0) return; |
|
71 |
try { |
|
72 |
if (!copy.valid()) return; |
|
73 |
*ptr = copy.get(); |
|
74 |
} catch (...) {} |
|
75 |
} |
|
76 |
|
|
77 |
void set(const Type& type) throw() { |
|
78 |
if (ptr.get() == 0) return; |
|
79 |
try { |
|
80 |
*ptr = type; |
|
81 |
} catch (...) {} |
|
82 |
} |
|
83 |
|
|
84 |
const Type& get() const { |
|
85 |
return *ptr; |
|
86 |
} |
|
87 |
|
|
88 |
bool valid() const throw() { |
|
89 |
return ptr.get() != 0; |
|
90 |
} |
|
91 |
|
|
92 |
private: |
|
93 |
std::auto_ptr<_Type> ptr; |
|
94 |
}; |
|
95 |
|
|
96 |
/// Exception-safe convenient error message builder class. |
|
97 |
|
|
98 |
/// Helper class which provides a convenient ostream-like (operator << |
|
99 |
/// based) interface to create a string message. Mostly useful in |
|
100 |
/// exception classes (therefore the name). |
|
101 |
class ErrorMessage { |
|
102 |
protected: |
|
103 |
///\e |
|
104 |
|
|
105 |
mutable std::auto_ptr<std::ostringstream> buf; |
|
106 |
|
|
107 |
///\e |
|
108 |
bool init() throw() { |
|
109 |
try { |
|
110 |
buf.reset(new std::ostringstream); |
|
111 |
} |
|
112 |
catch(...) { |
|
113 |
buf.reset(); |
|
114 |
} |
|
115 |
return buf.get(); |
|
116 |
} |
|
117 |
|
|
118 |
public: |
|
119 |
|
|
120 |
///\e |
|
121 |
ErrorMessage() throw() { init(); } |
|
122 |
|
|
123 |
ErrorMessage(const ErrorMessage& em) throw() : buf(em.buf) { } |
|
124 |
|
|
125 |
///\e |
|
126 |
ErrorMessage(const char *msg) throw() { |
|
127 |
init(); |
|
128 |
*this << msg; |
|
129 |
} |
|
130 |
|
|
131 |
///\e |
|
132 |
ErrorMessage(const std::string &msg) throw() { |
|
133 |
init(); |
|
134 |
*this << msg; |
|
135 |
} |
|
136 |
|
|
137 |
///\e |
|
138 |
template <typename T> |
|
139 |
ErrorMessage& operator<<(const T &t) throw() { |
|
140 |
if( ! buf.get() ) return *this; |
|
141 |
|
|
142 |
try { |
|
143 |
*buf << t; |
|
144 |
} |
|
145 |
catch(...) { |
|
146 |
buf.reset(); |
|
147 |
} |
|
148 |
return *this; |
|
149 |
} |
|
150 |
|
|
151 |
///\e |
|
152 |
const char* message() throw() { |
|
153 |
if( ! buf.get() ) return 0; |
|
154 |
|
|
155 |
const char* mes = 0; |
|
156 |
try { |
|
157 |
mes = buf->str().c_str(); |
|
158 |
} |
|
159 |
catch(...) {} |
|
160 |
return mes; |
|
161 |
} |
|
162 |
|
|
163 |
}; |
|
164 |
|
|
165 |
/// Generic exception class. |
|
166 |
|
|
167 | 40 |
/// Base class for exceptions used in LEMON. |
168 | 41 |
/// |
169 | 42 |
class Exception : public std::exception { |
170 | 43 |
public: |
171 |
///\e |
|
172 |
Exception() {} |
|
173 |
/// |
|
44 |
///Constructor |
|
45 |
Exception() throw() {} |
|
46 |
///Virtual destructor |
|
174 | 47 |
virtual ~Exception() throw() {} |
175 |
/// |
|
48 |
///A short description of the exception |
|
176 | 49 |
virtual const char* what() const throw() { |
177 | 50 |
return "lemon::Exception"; |
178 | 51 |
} |
179 | 52 |
}; |
180 | 53 |
|
181 |
/// |
|
54 |
/// \brief Input-Output error |
|
55 |
/// |
|
56 |
/// This exception is thrown when a file operation cannot be |
|
57 |
/// succeeded. |
|
58 |
class IoError : public Exception { |
|
59 |
protected: |
|
60 |
std::string _message; |
|
61 |
std::string _file; |
|
182 | 62 |
|
183 |
/// Logic errors represent problems in the internal logic of a program; |
|
184 |
/// in theory, these are preventable, and even detectable before the |
|
185 |
|
|
63 |
mutable std::string _what; |
|
64 |
public: |
|
65 |
|
|
66 |
/// Copy constructor |
|
67 |
IoError(const IoError &error) throw() : Exception() { |
|
68 |
message(error._message); |
|
69 |
file(error._file); |
|
70 |
} |
|
71 |
|
|
72 |
/// Constructor |
|
73 |
explicit IoError(const char *message) throw() { |
|
74 |
IoError::message(message); |
|
75 |
} |
|
76 |
|
|
77 |
/// Constructor |
|
78 |
explicit IoError(const std::string &message) throw() { |
|
79 |
IoError::message(message); |
|
80 |
} |
|
81 |
|
|
82 |
/// Constructor |
|
83 |
explicit IoError(const char *message, |
|
84 |
const std::string &file) throw() { |
|
85 |
IoError::message(message); |
|
86 |
IoError::file(file); |
|
87 |
} |
|
88 |
|
|
89 |
/// Constructor |
|
90 |
explicit IoError(const std::string &message, |
|
91 |
const std::string &file) throw() { |
|
92 |
IoError::message(message); |
|
93 |
IoError::file(file); |
|
94 |
} |
|
95 |
|
|
96 |
/// Virtual destructor |
|
97 |
virtual ~IoError() throw() {} |
|
98 |
|
|
99 |
/// Set the error message |
|
100 |
void message(const char *message) throw() { |
|
101 |
try { |
|
102 |
_message = message; |
|
103 |
} catch (...) {} |
|
104 |
} |
|
105 |
|
|
106 |
/// Set the error message |
|
107 |
void message(const std::string& message) throw() { |
|
108 |
try { |
|
109 |
_message = message; |
|
110 |
} catch (...) {} |
|
111 |
} |
|
112 |
|
|
113 |
/// Set the file name |
|
114 |
void file(const std::string &file) throw() { |
|
115 |
try { |
|
116 |
_file = file; |
|
117 |
} catch (...) {} |
|
118 |
} |
|
119 |
|
|
120 |
/// Returns the error message |
|
121 |
const std::string& message() const throw() { |
|
122 |
return _message; |
|
123 |
} |
|
124 |
|
|
125 |
/// \brief Returns the filename |
|
186 | 126 |
/// |
187 |
/// A typical example for this is \ref UninitializedParameter. |
|
188 |
class LogicError : public Exception { |
|
189 |
|
|
127 |
/// Returns the filename or an empty string if it was not specified. |
|
128 |
const std::string& file() const throw() { |
|
129 |
return _file; |
|
130 |
} |
|
131 |
|
|
132 |
/// \brief Returns a short error message |
|
133 |
/// |
|
134 |
/// Returns a short error message which contains the message and the |
|
135 |
/// file name. |
|
190 | 136 |
virtual const char* what() const throw() { |
191 |
|
|
137 |
try { |
|
138 |
_what.clear(); |
|
139 |
std::ostringstream oss; |
|
140 |
oss << "lemon:IoError" << ": "; |
|
141 |
oss << _message; |
|
142 |
if (!_file.empty()) { |
|
143 |
oss << " ('" << _file << "')"; |
|
192 | 144 |
} |
145 |
_what = oss.str(); |
|
146 |
} |
|
147 |
catch (...) {} |
|
148 |
if (!_what.empty()) return _what.c_str(); |
|
149 |
else return "lemon:IoError"; |
|
150 |
} |
|
151 |
|
|
193 | 152 |
}; |
194 | 153 |
|
195 |
/// \ref Exception for uninitialized parameters. |
|
196 |
|
|
197 |
/// This error represents problems in the initialization |
|
198 |
/// of the parameters of the algorithms. |
|
199 |
class UninitializedParameter : public LogicError { |
|
200 |
public: |
|
201 |
virtual const char* what() const throw() { |
|
202 |
return "lemon::UninitializedParameter"; |
|
203 |
} |
|
204 |
}; |
|
205 |
|
|
206 |
|
|
207 |
/// One of the two main subclasses of \ref Exception. |
|
208 |
|
|
209 |
/// Runtime errors represent problems outside the scope of a program; |
|
210 |
/// they cannot be easily predicted and can generally only be caught |
|
211 |
/// as the program executes. |
|
212 |
class RuntimeError : public Exception { |
|
213 |
public: |
|
214 |
virtual const char* what() const throw() { |
|
215 |
return "lemon::RuntimeError"; |
|
216 |
} |
|
217 |
}; |
|
218 |
|
|
219 |
///\e |
|
220 |
class RangeError : public RuntimeError { |
|
221 |
public: |
|
222 |
virtual const char* what() const throw() { |
|
223 |
return "lemon::RangeError"; |
|
224 |
} |
|
225 |
}; |
|
226 |
|
|
227 |
///\e |
|
228 |
class IoError : public RuntimeError { |
|
229 |
public: |
|
230 |
virtual const char* what() const throw() { |
|
231 |
return "lemon::IoError"; |
|
232 |
} |
|
233 |
}; |
|
234 |
|
|
235 |
///\e |
|
236 |
class DataFormatError : public IoError { |
|
154 |
/// \brief Format error |
|
155 |
/// |
|
156 |
/// This exception is thrown when an input file has wrong |
|
157 |
/// format or a data representation is not legal. |
|
158 |
class FormatError : public Exception { |
|
237 | 159 |
protected: |
238 |
ExceptionMember<std::string> _message; |
|
239 |
ExceptionMember<std::string> _file; |
|
160 |
std::string _message; |
|
161 |
std::string _file; |
|
240 | 162 |
int _line; |
241 | 163 |
|
242 |
mutable |
|
164 |
mutable std::string _what; |
|
243 | 165 |
public: |
244 | 166 |
|
245 |
DataFormatError(const DataFormatError &dfe) : |
|
246 |
IoError(dfe), _message(dfe._message), _file(dfe._file), |
|
247 |
_line(dfe._line) {} |
|
248 |
|
|
249 |
///\e |
|
250 |
explicit DataFormatError(const char *the_message) |
|
251 |
: _message(the_message), _line(0) {} |
|
252 |
|
|
253 |
///\e |
|
254 |
DataFormatError(const std::string &file_name, int line_num, |
|
255 |
const char *the_message) |
|
256 |
: _message(the_message), _line(line_num) { file(file_name); } |
|
257 |
|
|
258 |
///\e |
|
259 |
void line(int ln) { _line = ln; } |
|
260 |
///\e |
|
261 |
void message(const std::string& msg) { _message.set(msg); } |
|
262 |
///\e |
|
263 |
void file(const std::string &fl) { _file.set(fl); } |
|
264 |
|
|
265 |
///\e |
|
266 |
int line() const { return _line; } |
|
267 |
///\e |
|
268 |
const char* message() const { |
|
269 |
if (_message.valid() && !_message.get().empty()) { |
|
270 |
return _message.get().c_str(); |
|
271 |
} else { |
|
272 |
return 0; |
|
273 |
|
|
167 |
/// Copy constructor |
|
168 |
FormatError(const FormatError &error) throw() : Exception() { |
|
169 |
message(error._message); |
|
170 |
file(error._file); |
|
171 |
line(error._line); |
|
274 | 172 |
} |
275 | 173 |
|
276 |
/// \brief Returns the filename. |
|
277 |
/// |
|
278 |
/// Returns \e null if the filename was not specified. |
|
279 |
const char* file() const { |
|
280 |
if (_file.valid() && !_file.get().empty()) { |
|
281 |
return _file.get().c_str(); |
|
282 |
} else { |
|
283 |
return 0; |
|
284 |
|
|
174 |
/// Constructor |
|
175 |
explicit FormatError(const char *message) throw() { |
|
176 |
FormatError::message(message); |
|
177 |
_line = 0; |
|
285 | 178 |
} |
286 | 179 |
|
287 |
/// |
|
180 |
/// Constructor |
|
181 |
explicit FormatError(const std::string &message) throw() { |
|
182 |
FormatError::message(message); |
|
183 |
_line = 0; |
|
184 |
} |
|
185 |
|
|
186 |
/// Constructor |
|
187 |
explicit FormatError(const char *message, |
|
188 |
const std::string &file, int line = 0) throw() { |
|
189 |
FormatError::message(message); |
|
190 |
FormatError::file(file); |
|
191 |
FormatError::line(line); |
|
192 |
} |
|
193 |
|
|
194 |
/// Constructor |
|
195 |
explicit FormatError(const std::string &message, |
|
196 |
const std::string &file, int line = 0) throw() { |
|
197 |
FormatError::message(message); |
|
198 |
FormatError::file(file); |
|
199 |
FormatError::line(line); |
|
200 |
} |
|
201 |
|
|
202 |
/// Virtual destructor |
|
203 |
virtual ~FormatError() throw() {} |
|
204 |
|
|
205 |
/// Set the line number |
|
206 |
void line(int line) throw() { _line = line; } |
|
207 |
|
|
208 |
/// Set the error message |
|
209 |
void message(const char *message) throw() { |
|
210 |
try { |
|
211 |
_message = message; |
|
212 |
} catch (...) {} |
|
213 |
} |
|
214 |
|
|
215 |
/// Set the error message |
|
216 |
void message(const std::string& message) throw() { |
|
217 |
try { |
|
218 |
_message = message; |
|
219 |
} catch (...) {} |
|
220 |
} |
|
221 |
|
|
222 |
/// Set the file name |
|
223 |
void file(const std::string &file) throw() { |
|
224 |
try { |
|
225 |
_file = file; |
|
226 |
} catch (...) {} |
|
227 |
} |
|
228 |
|
|
229 |
/// \brief Returns the line number |
|
230 |
/// |
|
231 |
/// Returns the line number or zero if it was not specified. |
|
232 |
int line() const throw() { return _line; } |
|
233 |
|
|
234 |
/// Returns the error message |
|
235 |
const std::string& message() const throw() { |
|
236 |
return _message; |
|
237 |
} |
|
238 |
|
|
239 |
/// \brief Returns the filename |
|
240 |
/// |
|
241 |
/// Returns the filename or an empty string if it was not specified. |
|
242 |
const std::string& file() const throw() { |
|
243 |
return _file; |
|
244 |
} |
|
245 |
|
|
246 |
/// \brief Returns a short error message |
|
247 |
/// |
|
248 |
/// Returns a short error message which contains the message, the |
|
249 |
/// file name and the line number. |
|
288 | 250 |
virtual const char* what() const throw() { |
289 | 251 |
try { |
290 |
std::ostringstream ostr; |
|
291 |
ostr << "lemon:DataFormatError" << ": "; |
|
292 |
if (message()) ostr << message(); |
|
293 |
if( file() || line() != 0 ) { |
|
294 |
ostr << " ("; |
|
295 |
if( file() ) ostr << "in file '" << file() << "'"; |
|
296 |
if( file() && line() != 0 ) ostr << " "; |
|
297 |
if( line() != 0 ) ostr << "at line " << line(); |
|
298 |
|
|
252 |
_what.clear(); |
|
253 |
std::ostringstream oss; |
|
254 |
oss << "lemon:FormatError" << ": "; |
|
255 |
oss << _message; |
|
256 |
if (!_file.empty() || _line != 0) { |
|
257 |
oss << " ("; |
|
258 |
if (!_file.empty()) oss << "in file '" << _file << "'"; |
|
259 |
if (!_file.empty() && _line != 0) oss << " "; |
|
260 |
if (_line != 0) oss << "at line " << _line; |
|
261 |
oss << ")"; |
|
299 | 262 |
} |
300 |
|
|
263 |
_what = oss.str(); |
|
301 | 264 |
} |
302 | 265 |
catch (...) {} |
303 |
if( _message_holder.valid()) return _message_holder.get().c_str(); |
|
304 |
return "lemon:DataFormatError"; |
|
266 |
if (!_what.empty()) return _what.c_str(); |
|
267 |
else return "lemon:FormatError"; |
|
305 | 268 |
} |
306 | 269 |
|
307 |
virtual ~DataFormatError() throw() {} |
|
308 |
}; |
|
309 |
|
|
310 |
///\e |
|
311 |
class FileOpenError : public IoError { |
|
312 |
protected: |
|
313 |
ExceptionMember<std::string> _file; |
|
314 |
|
|
315 |
mutable ExceptionMember<std::string> _message_holder; |
|
316 |
public: |
|
317 |
|
|
318 |
FileOpenError(const FileOpenError &foe) : |
|
319 |
IoError(foe), _file(foe._file) {} |
|
320 |
|
|
321 |
///\e |
|
322 |
explicit FileOpenError(const std::string& fl) |
|
323 |
: _file(fl) {} |
|
324 |
|
|
325 |
|
|
326 |
///\e |
|
327 |
void file(const std::string &fl) { _file.set(fl); } |
|
328 |
|
|
329 |
/// \brief Returns the filename. |
|
330 |
/// |
|
331 |
/// Returns \e null if the filename was not specified. |
|
332 |
const char* file() const { |
|
333 |
if (_file.valid() && !_file.get().empty()) { |
|
334 |
return _file.get().c_str(); |
|
335 |
} else { |
|
336 |
return 0; |
|
337 |
} |
|
338 |
} |
|
339 |
|
|
340 |
///\e |
|
341 |
virtual const char* what() const throw() { |
|
342 |
try { |
|
343 |
std::ostringstream ostr; |
|
344 |
ostr << "lemon::FileOpenError" << ": "; |
|
345 |
ostr << "Cannot open file - " << file(); |
|
346 |
_message_holder.set(ostr.str()); |
|
347 |
} |
|
348 |
catch (...) {} |
|
349 |
if( _message_holder.valid()) return _message_holder.get().c_str(); |
|
350 |
return "lemon::FileOpenError"; |
|
351 |
} |
|
352 |
virtual ~FileOpenError() throw() {} |
|
353 |
}; |
|
354 |
|
|
355 |
class IoParameterError : public IoError { |
|
356 |
protected: |
|
357 |
ExceptionMember<std::string> _message; |
|
358 |
ExceptionMember<std::string> _file; |
|
359 |
|
|
360 |
mutable ExceptionMember<std::string> _message_holder; |
|
361 |
public: |
|
362 |
|
|
363 |
IoParameterError(const IoParameterError &ile) : |
|
364 |
IoError(ile), _message(ile._message), _file(ile._file) {} |
|
365 |
|
|
366 |
///\e |
|
367 |
explicit IoParameterError(const char *the_message) |
|
368 |
: _message(the_message) {} |
|
369 |
|
|
370 |
///\e |
|
371 |
IoParameterError(const char *file_name, const char *the_message) |
|
372 |
: _message(the_message), _file(file_name) {} |
|
373 |
|
|
374 |
///\e |
|
375 |
void message(const std::string& msg) { _message.set(msg); } |
|
376 |
///\e |
|
377 |
void file(const std::string &fl) { _file.set(fl); } |
|
378 |
|
|
379 |
///\e |
|
380 |
const char* message() const { |
|
381 |
if (_message.valid()) { |
|
382 |
return _message.get().c_str(); |
|
383 |
} else { |
|
384 |
return 0; |
|
385 |
} |
|
386 |
} |
|
387 |
|
|
388 |
/// \brief Returns the filename. |
|
389 |
/// |
|
390 |
/// Returns \c 0 if the filename was not specified. |
|
391 |
const char* file() const { |
|
392 |
if (_file.valid()) { |
|
393 |
return _file.get().c_str(); |
|
394 |
} else { |
|
395 |
return 0; |
|
396 |
} |
|
397 |
} |
|
398 |
|
|
399 |
///\e |
|
400 |
virtual const char* what() const throw() { |
|
401 |
try { |
|
402 |
std::ostringstream ostr; |
|
403 |
if (message()) ostr << message(); |
|
404 |
if (file()) ostr << "(when reading file '" << file() << "')"; |
|
405 |
_message_holder.set(ostr.str()); |
|
406 |
} |
|
407 |
catch (...) {} |
|
408 |
if( _message_holder.valid() ) return _message_holder.get().c_str(); |
|
409 |
return "lemon:IoParameterError"; |
|
410 |
} |
|
411 |
virtual ~IoParameterError() throw() {} |
|
412 | 270 |
}; |
413 | 271 |
|
414 | 272 |
/// @} |
415 | 273 |
... | ... |
@@ -39,8 +39,9 @@ |
39 | 39 |
#include<lemon/dim2.h> |
40 | 40 |
#include<lemon/maps.h> |
41 | 41 |
#include<lemon/color.h> |
42 | 42 |
#include<lemon/bits/bezier.h> |
43 |
#include<lemon/error.h> |
|
43 | 44 |
|
44 | 45 |
|
45 | 46 |
///\ingroup eps_io |
46 | 47 |
///\file |
... | ... |
@@ -1165,10 +1166,15 @@ |
1165 | 1166 |
template<class G> |
1166 | 1167 |
GraphToEps<DefaultGraphToEpsTraits<G> > |
1167 | 1168 |
graphToEps(G &g,const char *file_name) |
1168 | 1169 |
{ |
1170 |
std::ostream* os = new std::ofstream(file_name); |
|
1171 |
if (!(*os)) { |
|
1172 |
delete os; |
|
1173 |
throw IoError("Cannot write file", file_name); |
|
1174 |
} |
|
1169 | 1175 |
return GraphToEps<DefaultGraphToEpsTraits<G> > |
1170 |
(DefaultGraphToEpsTraits<G>(g,* |
|
1176 |
(DefaultGraphToEpsTraits<G>(g,*os,true)); |
|
1171 | 1177 |
} |
1172 | 1178 |
|
1173 | 1179 |
///Generates an EPS file from a graph |
1174 | 1180 |
|
... | ... |
@@ -1181,10 +1187,15 @@ |
1181 | 1187 |
template<class G> |
1182 | 1188 |
GraphToEps<DefaultGraphToEpsTraits<G> > |
1183 | 1189 |
graphToEps(G &g,const std::string& file_name) |
1184 | 1190 |
{ |
1191 |
std::ostream* os = new std::ofstream(file_name.c_str()); |
|
1192 |
if (!(*os)) { |
|
1193 |
delete os; |
|
1194 |
throw IoError("Cannot write file", file_name); |
|
1195 |
} |
|
1185 | 1196 |
return GraphToEps<DefaultGraphToEpsTraits<G> > |
1186 |
(DefaultGraphToEpsTraits<G>(g,* |
|
1197 |
(DefaultGraphToEpsTraits<G>(g,*os,true)); |
|
1187 | 1198 |
} |
1188 | 1199 |
|
1189 | 1200 |
} //END OF NAMESPACE LEMON |
1190 | 1201 |
... | ... |
@@ -47,13 +47,15 @@ |
47 | 47 |
struct DefaultConverter { |
48 | 48 |
Value operator()(const std::string& str) { |
49 | 49 |
std::istringstream is(str); |
50 | 50 |
Value value; |
51 |
is >> value |
|
51 |
if (!(is >> value)) { |
|
52 |
throw FormatError("Cannot read token"); |
|
53 |
} |
|
52 | 54 |
|
53 | 55 |
char c; |
54 | 56 |
if (is >> std::ws >> c) { |
55 |
throw |
|
57 |
throw FormatError("Remaining characters in token"); |
|
56 | 58 |
} |
57 | 59 |
return value; |
58 | 60 |
} |
59 | 61 |
}; |
... | ... |
@@ -165,9 +167,9 @@ |
165 | 167 |
_map.find(str); |
166 | 168 |
if (it == _map.end()) { |
167 | 169 |
std::ostringstream msg; |
168 | 170 |
msg << "Item not found: " << str; |
169 |
throw |
|
171 |
throw FormatError(msg.str()); |
|
170 | 172 |
} |
171 | 173 |
return it->second; |
172 | 174 |
} |
173 | 175 |
}; |
... | ... |
@@ -183,14 +185,14 @@ |
183 | 185 |
: _graph(graph), _map(map) {} |
184 | 186 |
|
185 | 187 |
typename Graph::Arc operator()(const std::string& str) { |
186 | 188 |
if (str.empty() || (str[0] != '+' && str[0] != '-')) { |
187 |
throw |
|
189 |
throw FormatError("Item must start with '+' or '-'"); |
|
188 | 190 |
} |
189 | 191 |
typename std::map<std::string, typename Graph::Edge> |
190 | 192 |
::const_iterator it = _map.find(str.substr(1)); |
191 | 193 |
if (it == _map.end()) { |
192 |
throw |
|
194 |
throw FormatError("Item not found"); |
|
193 | 195 |
} |
194 | 196 |
return _graph.direct(it->second, str[0] == '+'); |
195 | 197 |
} |
196 | 198 |
}; |
... | ... |
@@ -234,9 +236,9 @@ |
234 | 236 |
|
235 | 237 |
inline char readEscape(std::istream& is) { |
236 | 238 |
char c; |
237 | 239 |
if (!is.get(c)) |
238 |
throw |
|
240 |
throw FormatError("Escape format error"); |
|
239 | 241 |
|
240 | 242 |
switch (c) { |
241 | 243 |
case '\\': |
242 | 244 |
return '\\'; |
... | ... |
@@ -263,18 +265,18 @@ |
263 | 265 |
case 'x': |
264 | 266 |
{ |
265 | 267 |
int code; |
266 | 268 |
if (!is.get(c) || !isHex(c)) |
267 |
throw |
|
269 |
throw FormatError("Escape format error"); |
|
268 | 270 |
else if (code = valueHex(c), !is.get(c) || !isHex(c)) is.putback(c); |
269 | 271 |
else code = code * 16 + valueHex(c); |
270 | 272 |
return code; |
271 | 273 |
} |
272 | 274 |
default: |
273 | 275 |
{ |
274 | 276 |
int code; |
275 | 277 |
if (!isOct(c)) |
276 |
throw |
|
278 |
throw FormatError("Escape format error"); |
|
277 | 279 |
else if (code = valueOct(c), !is.get(c) || !isOct(c)) |
278 | 280 |
is.putback(c); |
279 | 281 |
else if (code = code * 8 + valueOct(c), !is.get(c) || !isOct(c)) |
280 | 282 |
is.putback(c); |
... | ... |
@@ -299,9 +301,9 @@ |
299 | 301 |
c = readEscape(is); |
300 | 302 |
os << c; |
301 | 303 |
} |
302 | 304 |
if (!is) |
303 |
throw |
|
305 |
throw FormatError("Quoted format error"); |
|
304 | 306 |
} else { |
305 | 307 |
is.putback(c); |
306 | 308 |
while (is.get(c) && !isWhiteSpace(c)) { |
307 | 309 |
if (c == '\\') |
... | ... |
@@ -460,8 +462,9 @@ |
460 | 462 |
|
461 | 463 |
|
462 | 464 |
std::istream* _is; |
463 | 465 |
bool local_is; |
466 |
std::string _filename; |
|
464 | 467 |
|
465 | 468 |
Digraph& _digraph; |
466 | 469 |
|
467 | 470 |
std::string _nodes_caption; |
... | ... |
@@ -509,20 +512,26 @@ |
509 | 512 |
/// |
510 | 513 |
/// Construct a directed graph reader, which reads from the given |
511 | 514 |
/// file. |
512 | 515 |
DigraphReader(Digraph& digraph, const std::string& fn) |
513 |
: _is(new std::ifstream(fn.c_str())), local_is(true), |
|
516 |
: _is(new std::ifstream(fn.c_str())), local_is(true), |
|
517 |
_filename(fn), _digraph(digraph), |
|
514 | 518 |
_use_nodes(false), _use_arcs(false), |
515 |
_skip_nodes(false), _skip_arcs(false) { |
|
519 |
_skip_nodes(false), _skip_arcs(false) { |
|
520 |
if (!(*_is)) throw IoError("Cannot open file", fn); |
|
521 |
} |
|
516 | 522 |
|
517 | 523 |
/// \brief Constructor |
518 | 524 |
/// |
519 | 525 |
/// Construct a directed graph reader, which reads from the given |
520 | 526 |
/// file. |
521 | 527 |
DigraphReader(Digraph& digraph, const char* fn) |
522 |
: _is(new std::ifstream(fn)), local_is(true), |
|
528 |
: _is(new std::ifstream(fn)), local_is(true), |
|
529 |
_filename(fn), _digraph(digraph), |
|
523 | 530 |
_use_nodes(false), _use_arcs(false), |
524 |
_skip_nodes(false), _skip_arcs(false) { |
|
531 |
_skip_nodes(false), _skip_arcs(false) { |
|
532 |
if (!(*_is)) throw IoError("Cannot open file", fn); |
|
533 |
} |
|
525 | 534 |
|
526 | 535 |
/// \brief Destructor |
527 | 536 |
~DigraphReader() { |
528 | 537 |
for (typename NodeMaps::iterator it = _node_maps.begin(); |
... | ... |
@@ -845,9 +854,9 @@ |
845 | 854 |
char c; |
846 | 855 |
if (!readLine() || !(line >> c) || c == '@') { |
847 | 856 |
if (readSuccess() && line) line.putback(c); |
848 | 857 |
if (!_node_maps.empty()) |
849 |
throw |
|
858 |
throw FormatError("Cannot find map names"); |
|
850 | 859 |
return; |
851 | 860 |
} |
852 | 861 |
line.putback(c); |
853 | 862 |
|
... | ... |
@@ -859,9 +868,9 @@ |
859 | 868 |
while (_reader_bits::readToken(line, map)) { |
860 | 869 |
if (maps.find(map) != maps.end()) { |
861 | 870 |
std::ostringstream msg; |
862 | 871 |
msg << "Multiple occurence of node map: " << map; |
863 |
throw |
|
872 |
throw FormatError(msg.str()); |
|
864 | 873 |
} |
865 | 874 |
maps.insert(std::make_pair(map, index)); |
866 | 875 |
++index; |
867 | 876 |
} |
... | ... |
@@ -870,10 +879,10 @@ |
870 | 879 |
std::map<std::string, int>::iterator jt = |
871 | 880 |
maps.find(_node_maps[i].first); |
872 | 881 |
if (jt == maps.end()) { |
873 | 882 |
std::ostringstream msg; |
874 |
msg << "Map not found in file: " << _node_maps[i].first; |
|
875 |
throw DataFormatError(msg.str().c_str()); |
|
883 |
msg << "Map not found: " << _node_maps[i].first; |
|
884 |
throw FormatError(msg.str()); |
|
876 | 885 |
} |
877 | 886 |
map_index[i] = jt->second; |
878 | 887 |
} |
879 | 888 |
|
... | ... |
@@ -895,28 +904,28 @@ |
895 | 904 |
for (int i = 0; i < map_num; ++i) { |
896 | 905 |
if (!_reader_bits::readToken(line, tokens[i])) { |
897 | 906 |
std::ostringstream msg; |
898 | 907 |
msg << "Column not found (" << i + 1 << ")"; |
899 |
throw |
|
908 |
throw FormatError(msg.str()); |
|
900 | 909 |
} |
901 | 910 |
} |
902 | 911 |
if (line >> std::ws >> c) |
903 |
throw |
|
912 |
throw FormatError("Extra character at the end of line"); |
|
904 | 913 |
|
905 | 914 |
Node n; |
906 | 915 |
if (!_use_nodes) { |
907 | 916 |
n = _digraph.addNode(); |
908 | 917 |
if (label_index != -1) |
909 | 918 |
_node_index.insert(std::make_pair(tokens[label_index], n)); |
910 | 919 |
} else { |
911 | 920 |
if (label_index == -1) |
912 |
throw |
|
921 |
throw FormatError("Label map not found"); |
|
913 | 922 |
typename std::map<std::string, Node>::iterator it = |
914 | 923 |
_node_index.find(tokens[label_index]); |
915 | 924 |
if (it == _node_index.end()) { |
916 | 925 |
std::ostringstream msg; |
917 | 926 |
msg << "Node with label not found: " << tokens[label_index]; |
918 |
throw |
|
927 |
throw FormatError(msg.str()); |
|
919 | 928 |
} |
920 | 929 |
n = it->second; |
921 | 930 |
} |
922 | 931 |
|
... | ... |
@@ -938,9 +947,9 @@ |
938 | 947 |
char c; |
939 | 948 |
if (!readLine() || !(line >> c) || c == '@') { |
940 | 949 |
if (readSuccess() && line) line.putback(c); |
941 | 950 |
if (!_arc_maps.empty()) |
942 |
throw |
|
951 |
throw FormatError("Cannot find map names"); |
|
943 | 952 |
return; |
944 | 953 |
} |
945 | 954 |
line.putback(c); |
946 | 955 |
|
... | ... |
@@ -952,9 +961,9 @@ |
952 | 961 |
while (_reader_bits::readToken(line, map)) { |
953 | 962 |
if (maps.find(map) != maps.end()) { |
954 | 963 |
std::ostringstream msg; |
955 | 964 |
msg << "Multiple occurence of arc map: " << map; |
956 |
throw |
|
965 |
throw FormatError(msg.str()); |
|
957 | 966 |
} |
958 | 967 |
maps.insert(std::make_pair(map, index)); |
959 | 968 |
++index; |
960 | 969 |
} |
... | ... |
@@ -963,10 +972,10 @@ |
963 | 972 |
std::map<std::string, int>::iterator jt = |
964 | 973 |
maps.find(_arc_maps[i].first); |
965 | 974 |
if (jt == maps.end()) { |
966 | 975 |
std::ostringstream msg; |
967 |
msg << "Map not found in file: " << _arc_maps[i].first; |
|
968 |
throw DataFormatError(msg.str().c_str()); |
|
976 |
msg << "Map not found: " << _arc_maps[i].first; |
|
977 |
throw FormatError(msg.str()); |
|
969 | 978 |
} |
970 | 979 |
map_index[i] = jt->second; |
971 | 980 |
} |
972 | 981 |
|
... | ... |
@@ -987,23 +996,23 @@ |
987 | 996 |
std::string source_token; |
988 | 997 |
std::string target_token; |
989 | 998 |
|
990 | 999 |
if (!_reader_bits::readToken(line, source_token)) |
991 |
throw |
|
1000 |
throw FormatError("Source not found"); |
|
992 | 1001 |
|
993 | 1002 |
if (!_reader_bits::readToken(line, target_token)) |
994 |
throw |
|
1003 |
throw FormatError("Target not found"); |
|
995 | 1004 |
|
996 | 1005 |
std::vector<std::string> tokens(map_num); |
997 | 1006 |
for (int i = 0; i < map_num; ++i) { |
998 | 1007 |
if (!_reader_bits::readToken(line, tokens[i])) { |
999 | 1008 |
std::ostringstream msg; |
1000 | 1009 |
msg << "Column not found (" << i + 1 << ")"; |
1001 |
throw |
|
1010 |
throw FormatError(msg.str()); |
|
1002 | 1011 |
} |
1003 | 1012 |
} |
1004 | 1013 |
if (line >> std::ws >> c) |
1005 |
throw |
|
1014 |
throw FormatError("Extra character at the end of line"); |
|
1006 | 1015 |
|
1007 | 1016 |
Arc a; |
1008 | 1017 |
if (!_use_arcs) { |
1009 | 1018 |
|
... | ... |
@@ -1012,32 +1021,32 @@ |
1012 | 1021 |
it = _node_index.find(source_token); |
1013 | 1022 |
if (it == _node_index.end()) { |
1014 | 1023 |
std::ostringstream msg; |
1015 | 1024 |
msg << "Item not found: " << source_token; |
1016 |
throw |
|
1025 |
throw FormatError(msg.str()); |
|
1017 | 1026 |
} |
1018 | 1027 |
Node source = it->second; |
1019 | 1028 |
|
1020 | 1029 |
it = _node_index.find(target_token); |
1021 | 1030 |
if (it == _node_index.end()) { |
1022 | 1031 |
std::ostringstream msg; |
1023 | 1032 |
msg << "Item not found: " << target_token; |
1024 |
throw |
|
1033 |
throw FormatError(msg.str()); |
|
1025 | 1034 |
} |
1026 | 1035 |
Node target = it->second; |
1027 | 1036 |
|
1028 | 1037 |
a = _digraph.addArc(source, target); |
1029 | 1038 |
if (label_index != -1) |
1030 | 1039 |
_arc_index.insert(std::make_pair(tokens[label_index], a)); |
1031 | 1040 |
} else { |
1032 | 1041 |
if (label_index == -1) |
1033 |
throw |
|
1042 |
throw FormatError("Label map not found"); |
|
1034 | 1043 |
typename std::map<std::string, Arc>::iterator it = |
1035 | 1044 |
_arc_index.find(tokens[label_index]); |
1036 | 1045 |
if (it == _arc_index.end()) { |
1037 | 1046 |
std::ostringstream msg; |
1038 | 1047 |
msg << "Arc with label not found: " << tokens[label_index]; |
1039 |
throw |
|
1048 |
throw FormatError(msg.str()); |
|
1040 | 1049 |
} |
1041 | 1050 |
a = it->second; |
1042 | 1051 |
} |
1043 | 1052 |
|
... | ... |
@@ -1060,20 +1069,20 @@ |
1060 | 1069 |
line.putback(c); |
1061 | 1070 |
|
1062 | 1071 |
std::string attr, token; |
1063 | 1072 |
if (!_reader_bits::readToken(line, attr)) |
1064 |
throw |
|
1073 |
throw FormatError("Attribute name not found"); |
|
1065 | 1074 |
if (!_reader_bits::readToken(line, token)) |
1066 |
throw |
|
1075 |
throw FormatError("Attribute value not found"); |
|
1067 | 1076 |
if (line >> c) |
1068 |
throw |
|
1077 |
throw FormatError("Extra character at the end of line"); |
|
1069 | 1078 |
|
1070 | 1079 |
{ |
1071 | 1080 |
std::set<std::string>::iterator it = read_attr.find(attr); |
1072 | 1081 |
if (it != read_attr.end()) { |
1073 | 1082 |
std::ostringstream msg; |
1074 |
msg << "Multiple occurence of attribute " << attr; |
|
1075 |
throw DataFormatError(msg.str().c_str()); |
|
1083 |
msg << "Multiple occurence of attribute: " << attr; |
|
1084 |
throw FormatError(msg.str()); |
|
1076 | 1085 |
} |
1077 | 1086 |
read_attr.insert(attr); |
1078 | 1087 |
} |
1079 | 1088 |
|
... | ... |
@@ -1092,10 +1101,10 @@ |
1092 | 1101 |
for (typename Attributes::iterator it = _attributes.begin(); |
1093 | 1102 |
it != _attributes.end(); ++it) { |
1094 | 1103 |
if (read_attr.find(it->first) == read_attr.end()) { |
1095 | 1104 |
std::ostringstream msg; |
1096 |
msg << "Attribute not found in file: " << it->first; |
|
1097 |
throw DataFormatError(msg.str().c_str()); |
|
1105 |
msg << "Attribute not found: " << it->first; |
|
1106 |
throw FormatError(msg.str()); |
|
1098 | 1107 |
} |
1099 | 1108 |
} |
1100 | 1109 |
} |
1101 | 1110 |
|
... | ... |
@@ -1108,11 +1117,8 @@ |
1108 | 1117 |
/// |
1109 | 1118 |
/// This function starts the batch processing |
1110 | 1119 |
void run() { |
1111 | 1120 |
LEMON_ASSERT(_is != 0, "This reader assigned to an other reader"); |
1112 |
if (!*_is) { |
|
1113 |
throw DataFormatError("Cannot find file"); |
|
1114 |
} |
|
1115 | 1121 |
|
1116 | 1122 |
bool nodes_done = _skip_nodes; |
1117 | 1123 |
bool arcs_done = _skip_arcs; |
1118 | 1124 |
bool attributes_done = false; |
... | ... |
@@ -1129,9 +1135,9 @@ |
1129 | 1135 |
_reader_bits::readToken(line, section); |
1130 | 1136 |
_reader_bits::readToken(line, caption); |
1131 | 1137 |
|
1132 | 1138 |
if (line >> c) |
1133 |
throw |
|
1139 |
throw FormatError("Extra character at the end of line"); |
|
1134 | 1140 |
|
1135 | 1141 |
if (section == "nodes" && !nodes_done) { |
1136 | 1142 |
if (_nodes_caption.empty() || _nodes_caption == caption) { |
1137 | 1143 |
readNodes(); |
... | ... |
@@ -1151,24 +1157,25 @@ |
1151 | 1157 |
} else { |
1152 | 1158 |
readLine(); |
1153 | 1159 |
skipSection(); |
1154 | 1160 |
} |
1155 |
} catch ( |
|
1161 |
} catch (FormatError& error) { |
|
1156 | 1162 |
error.line(line_num); |
1163 |
error.file(_filename); |
|
1157 | 1164 |
throw; |
1158 | 1165 |
} |
1159 | 1166 |
} |
1160 | 1167 |
|
1161 | 1168 |
if (!nodes_done) { |
1162 |
throw |
|
1169 |
throw FormatError("Section @nodes not found"); |
|
1163 | 1170 |
} |
1164 | 1171 |
|
1165 | 1172 |
if (!arcs_done) { |
1166 |
throw |
|
1173 |
throw FormatError("Section @arcs not found"); |
|
1167 | 1174 |
} |
1168 | 1175 |
|
1169 | 1176 |
if (!attributes_done && !_attributes.empty()) { |
1170 |
throw |
|
1177 |
throw FormatError("Section @attributes not found"); |
|
1171 | 1178 |
} |
1172 | 1179 |
|
1173 | 1180 |
} |
1174 | 1181 |
|
... | ... |
@@ -1246,8 +1253,9 @@ |
1246 | 1253 |
private: |
1247 | 1254 |
|
1248 | 1255 |
std::istream* _is; |
1249 | 1256 |
bool local_is; |
1257 |
std::string _filename; |
|
1250 | 1258 |
|
1251 | 1259 |
Graph& _graph; |
1252 | 1260 |
|
1253 | 1261 |
std::string _nodes_caption; |
... | ... |
@@ -1295,20 +1303,26 @@ |
1295 | 1303 |
/// |
1296 | 1304 |
/// Construct an undirected graph reader, which reads from the given |
1297 | 1305 |
/// file. |
1298 | 1306 |
GraphReader(Graph& graph, const std::string& fn) |
1299 |
: _is(new std::ifstream(fn.c_str())), local_is(true), |
|
1307 |
: _is(new std::ifstream(fn.c_str())), local_is(true), |
|
1308 |
_filename(fn), _graph(graph), |
|
1300 | 1309 |
_use_nodes(false), _use_edges(false), |
1301 |
_skip_nodes(false), _skip_edges(false) { |
|
1310 |
_skip_nodes(false), _skip_edges(false) { |
|
1311 |
if (!(*_is)) throw IoError("Cannot open file", fn); |
|
1312 |
} |
|
1302 | 1313 |
|
1303 | 1314 |
/// \brief Constructor |
1304 | 1315 |
/// |
1305 | 1316 |
/// Construct an undirected graph reader, which reads from the given |
1306 | 1317 |
/// file. |
1307 | 1318 |
GraphReader(Graph& graph, const char* fn) |
1308 |
: _is(new std::ifstream(fn)), local_is(true), |
|
1319 |
: _is(new std::ifstream(fn)), local_is(true), |
|
1320 |
_filename(fn), _graph(graph), |
|
1309 | 1321 |
_use_nodes(false), _use_edges(false), |
1310 |
_skip_nodes(false), _skip_edges(false) { |
|
1322 |
_skip_nodes(false), _skip_edges(false) { |
|
1323 |
if (!(*_is)) throw IoError("Cannot open file", fn); |
|
1324 |
} |
|
1311 | 1325 |
|
1312 | 1326 |
/// \brief Destructor |
1313 | 1327 |
~GraphReader() { |
1314 | 1328 |
for (typename NodeMaps::iterator it = _node_maps.begin(); |
... | ... |
@@ -1675,9 +1689,9 @@ |
1675 | 1689 |
char c; |
1676 | 1690 |
if (!readLine() || !(line >> c) || c == '@') { |
1677 | 1691 |
if (readSuccess() && line) line.putback(c); |
1678 | 1692 |
if (!_node_maps.empty()) |
1679 |
throw |
|
1693 |
throw FormatError("Cannot find map names"); |
|
1680 | 1694 |
return; |
1681 | 1695 |
} |
1682 | 1696 |
line.putback(c); |
1683 | 1697 |
|
... | ... |
@@ -1689,9 +1703,9 @@ |
1689 | 1703 |
while (_reader_bits::readToken(line, map)) { |
1690 | 1704 |
if (maps.find(map) != maps.end()) { |
1691 | 1705 |
std::ostringstream msg; |
1692 | 1706 |
msg << "Multiple occurence of node map: " << map; |
1693 |
throw |
|
1707 |
throw FormatError(msg.str()); |
|
1694 | 1708 |
} |
1695 | 1709 |
maps.insert(std::make_pair(map, index)); |
1696 | 1710 |
++index; |
1697 | 1711 |
} |
... | ... |
@@ -1700,10 +1714,10 @@ |
1700 | 1714 |
std::map<std::string, int>::iterator jt = |
1701 | 1715 |
maps.find(_node_maps[i].first); |
1702 | 1716 |
if (jt == maps.end()) { |
1703 | 1717 |
std::ostringstream msg; |
1704 |
msg << "Map not found in file: " << _node_maps[i].first; |
|
1705 |
throw DataFormatError(msg.str().c_str()); |
|
1718 |
msg << "Map not found: " << _node_maps[i].first; |
|
1719 |
throw FormatError(msg.str()); |
|
1706 | 1720 |
} |
1707 | 1721 |
map_index[i] = jt->second; |
1708 | 1722 |
} |
1709 | 1723 |
|
... | ... |
@@ -1725,28 +1739,28 @@ |
1725 | 1739 |
for (int i = 0; i < map_num; ++i) { |
1726 | 1740 |
if (!_reader_bits::readToken(line, tokens[i])) { |
1727 | 1741 |
std::ostringstream msg; |
1728 | 1742 |
msg << "Column not found (" << i + 1 << ")"; |
1729 |
throw |
|
1743 |
throw FormatError(msg.str()); |
|
1730 | 1744 |
} |
1731 | 1745 |
} |
1732 | 1746 |
if (line >> std::ws >> c) |
1733 |
throw |
|
1747 |
throw FormatError("Extra character at the end of line"); |
|
1734 | 1748 |
|
1735 | 1749 |
Node n; |
1736 | 1750 |
if (!_use_nodes) { |
1737 | 1751 |
n = _graph.addNode(); |
1738 | 1752 |
if (label_index != -1) |
1739 | 1753 |
_node_index.insert(std::make_pair(tokens[label_index], n)); |
1740 | 1754 |
} else { |
1741 | 1755 |
if (label_index == -1) |
1742 |
throw |
|
1756 |
throw FormatError("Label map not found"); |
|
1743 | 1757 |
typename std::map<std::string, Node>::iterator it = |
1744 | 1758 |
_node_index.find(tokens[label_index]); |
1745 | 1759 |
if (it == _node_index.end()) { |
1746 | 1760 |
std::ostringstream msg; |
1747 | 1761 |
msg << "Node with label not found: " << tokens[label_index]; |
1748 |
throw |
|
1762 |
throw FormatError(msg.str()); |
|
1749 | 1763 |
} |
1750 | 1764 |
n = it->second; |
1751 | 1765 |
} |
1752 | 1766 |
|
... | ... |
@@ -1768,9 +1782,9 @@ |
1768 | 1782 |
char c; |
1769 | 1783 |
if (!readLine() || !(line >> c) || c == '@') { |
1770 | 1784 |
if (readSuccess() && line) line.putback(c); |
1771 | 1785 |
if (!_edge_maps.empty()) |
1772 |
throw |
|
1786 |
throw FormatError("Cannot find map names"); |
|
1773 | 1787 |
return; |
1774 | 1788 |
} |
1775 | 1789 |
line.putback(c); |
1776 | 1790 |
|
... | ... |
@@ -1782,9 +1796,9 @@ |
1782 | 1796 |
while (_reader_bits::readToken(line, map)) { |
1783 | 1797 |
if (maps.find(map) != maps.end()) { |
1784 | 1798 |
std::ostringstream msg; |
1785 | 1799 |
msg << "Multiple occurence of edge map: " << map; |
1786 |
throw |
|
1800 |
throw FormatError(msg.str()); |
|
1787 | 1801 |
} |
1788 | 1802 |
maps.insert(std::make_pair(map, index)); |
1789 | 1803 |
++index; |
1790 | 1804 |
} |
... | ... |
@@ -1793,10 +1807,10 @@ |
1793 | 1807 |
std::map<std::string, int>::iterator jt = |
1794 | 1808 |
maps.find(_edge_maps[i].first); |
1795 | 1809 |
if (jt == maps.end()) { |
1796 | 1810 |
std::ostringstream msg; |
1797 |
msg << "Map not found in file: " << _edge_maps[i].first; |
|
1798 |
throw DataFormatError(msg.str().c_str()); |
|
1811 |
msg << "Map not found: " << _edge_maps[i].first; |
|
1812 |
throw FormatError(msg.str()); |
|
1799 | 1813 |
} |
1800 | 1814 |
map_index[i] = jt->second; |
1801 | 1815 |
} |
1802 | 1816 |
|
... | ... |
@@ -1817,23 +1831,23 @@ |
1817 | 1831 |
std::string source_token; |
1818 | 1832 |
std::string target_token; |
1819 | 1833 |
|
1820 | 1834 |
if (!_reader_bits::readToken(line, source_token)) |
1821 |
throw |
|
1835 |
throw FormatError("Node u not found"); |
|
1822 | 1836 |
|
1823 | 1837 |
if (!_reader_bits::readToken(line, target_token)) |
1824 |
throw |
|
1838 |
throw FormatError("Node v not found"); |
|
1825 | 1839 |
|
1826 | 1840 |
std::vector<std::string> tokens(map_num); |
1827 | 1841 |
for (int i = 0; i < map_num; ++i) { |
1828 | 1842 |
if (!_reader_bits::readToken(line, tokens[i])) { |
1829 | 1843 |
std::ostringstream msg; |
1830 | 1844 |
msg << "Column not found (" << i + 1 << ")"; |
1831 |
throw |
|
1845 |
throw FormatError(msg.str()); |
|
1832 | 1846 |
} |
1833 | 1847 |
} |
1834 | 1848 |
if (line >> std::ws >> c) |
1835 |
throw |
|
1849 |
throw FormatError("Extra character at the end of line"); |
|
1836 | 1850 |
|
1837 | 1851 |
Edge e; |
1838 | 1852 |
if (!_use_edges) { |
1839 | 1853 |
|
... | ... |
@@ -1842,32 +1856,32 @@ |
1842 | 1856 |
it = _node_index.find(source_token); |
1843 | 1857 |
if (it == _node_index.end()) { |
1844 | 1858 |
std::ostringstream msg; |
1845 | 1859 |
msg << "Item not found: " << source_token; |
1846 |
throw |
|
1860 |
throw FormatError(msg.str()); |
|
1847 | 1861 |
} |
1848 | 1862 |
Node source = it->second; |
1849 | 1863 |
|
1850 | 1864 |
it = _node_index.find(target_token); |
1851 | 1865 |
if (it == _node_index.end()) { |
1852 | 1866 |
std::ostringstream msg; |
1853 | 1867 |
msg << "Item not found: " << target_token; |
1854 |
throw |
|
1868 |
throw FormatError(msg.str()); |
|
1855 | 1869 |
} |
1856 | 1870 |
Node target = it->second; |
1857 | 1871 |
|
1858 | 1872 |
e = _graph.addEdge(source, target); |
1859 | 1873 |
if (label_index != -1) |
1860 | 1874 |
_edge_index.insert(std::make_pair(tokens[label_index], e)); |
1861 | 1875 |
} else { |
1862 | 1876 |
if (label_index == -1) |
1863 |
throw |
|
1877 |
throw FormatError("Label map not found"); |
|
1864 | 1878 |
typename std::map<std::string, Edge>::iterator it = |
1865 | 1879 |
_edge_index.find(tokens[label_index]); |
1866 | 1880 |
if (it == _edge_index.end()) { |
1867 | 1881 |
std::ostringstream msg; |
1868 | 1882 |
msg << "Edge with label not found: " << tokens[label_index]; |
1869 |
throw |
|
1883 |
throw FormatError(msg.str()); |
|
1870 | 1884 |
} |
1871 | 1885 |
e = it->second; |
1872 | 1886 |
} |
1873 | 1887 |
|
... | ... |
@@ -1890,20 +1904,20 @@ |
1890 | 1904 |
line.putback(c); |
1891 | 1905 |
|
1892 | 1906 |
std::string attr, token; |
1893 | 1907 |
if (!_reader_bits::readToken(line, attr)) |
1894 |
throw |
|
1908 |
throw FormatError("Attribute name not found"); |
|
1895 | 1909 |
if (!_reader_bits::readToken(line, token)) |
1896 |
throw |
|
1910 |
throw FormatError("Attribute value not found"); |
|
1897 | 1911 |
if (line >> c) |
1898 |
throw |
|
1912 |
throw FormatError("Extra character at the end of line"); |
|
1899 | 1913 |
|
1900 | 1914 |
{ |
1901 | 1915 |
std::set<std::string>::iterator it = read_attr.find(attr); |
1902 | 1916 |
if (it != read_attr.end()) { |
1903 | 1917 |
std::ostringstream msg; |
1904 |
msg << "Multiple occurence of attribute " << attr; |
|
1905 |
throw DataFormatError(msg.str().c_str()); |
|
1918 |
msg << "Multiple occurence of attribute: " << attr; |
|
1919 |
throw FormatError(msg.str()); |
|
1906 | 1920 |
} |
1907 | 1921 |
read_attr.insert(attr); |
1908 | 1922 |
} |
1909 | 1923 |
|
... | ... |
@@ -1922,10 +1936,10 @@ |
1922 | 1936 |
for (typename Attributes::iterator it = _attributes.begin(); |
1923 | 1937 |
it != _attributes.end(); ++it) { |
1924 | 1938 |
if (read_attr.find(it->first) == read_attr.end()) { |
1925 | 1939 |
std::ostringstream msg; |
1926 |
msg << "Attribute not found in file: " << it->first; |
|
1927 |
throw DataFormatError(msg.str().c_str()); |
|
1940 |
msg << "Attribute not found: " << it->first; |
|
1941 |
throw FormatError(msg.str()); |
|
1928 | 1942 |
} |
1929 | 1943 |
} |
1930 | 1944 |
} |
1931 | 1945 |
|
... | ... |
@@ -1957,9 +1971,9 @@ |
1957 | 1971 |
_reader_bits::readToken(line, section); |
1958 | 1972 |
_reader_bits::readToken(line, caption); |
1959 | 1973 |
|
1960 | 1974 |
if (line >> c) |
1961 |
throw |
|
1975 |
throw FormatError("Extra character at the end of line"); |
|
1962 | 1976 |
|
1963 | 1977 |
if (section == "nodes" && !nodes_done) { |
1964 | 1978 |
if (_nodes_caption.empty() || _nodes_caption == caption) { |
1965 | 1979 |
readNodes(); |
... | ... |
@@ -1979,24 +1993,25 @@ |
1979 | 1993 |
} else { |
1980 | 1994 |
readLine(); |
1981 | 1995 |
skipSection(); |
1982 | 1996 |
} |
1983 |
} catch ( |
|
1997 |
} catch (FormatError& error) { |
|
1984 | 1998 |
error.line(line_num); |
1999 |
error.file(_filename); |
|
1985 | 2000 |
throw; |
1986 | 2001 |
} |
1987 | 2002 |
} |
1988 | 2003 |
|
1989 | 2004 |
if (!nodes_done) { |
1990 |
throw |
|
2005 |
throw FormatError("Section @nodes not found"); |
|
1991 | 2006 |
} |
1992 | 2007 |
|
1993 | 2008 |
if (!edges_done) { |
1994 |
throw |
|
2009 |
throw FormatError("Section @edges not found"); |
|
1995 | 2010 |
} |
1996 | 2011 |
|
1997 | 2012 |
if (!attributes_done && !_attributes.empty()) { |
1998 |
throw |
|
2013 |
throw FormatError("Section @attributes not found"); |
|
1999 | 2014 |
} |
2000 | 2015 |
|
2001 | 2016 |
} |
2002 | 2017 |
|
... | ... |
@@ -2055,8 +2070,9 @@ |
2055 | 2070 |
private: |
2056 | 2071 |
|
2057 | 2072 |
std::istream* _is; |
2058 | 2073 |
bool local_is; |
2074 |
std::string _filename; |
|
2059 | 2075 |
|
2060 | 2076 |
typedef std::map<std::string, _reader_bits::Section*> Sections; |
2061 | 2077 |
Sections _sections; |
2062 | 2078 |
|
... | ... |
@@ -2075,15 +2091,21 @@ |
2075 | 2091 |
/// \brief Constructor |
2076 | 2092 |
/// |
2077 | 2093 |
/// Construct a section reader, which reads from the given file. |
2078 | 2094 |
SectionReader(const std::string& fn) |
2079 |
: _is(new std::ifstream(fn.c_str())), local_is(true) |
|
2095 |
: _is(new std::ifstream(fn.c_str())), local_is(true), |
|
2096 |
_filename(fn) { |
|
2097 |
if (!(*_is)) throw IoError("Cannot open file", fn); |
|
2098 |
} |
|
2080 | 2099 |
|
2081 | 2100 |
/// \brief Constructor |
2082 | 2101 |
/// |
2083 | 2102 |
/// Construct a section reader, which reads from the given file. |
2084 | 2103 |
SectionReader(const char* fn) |
2085 |
: _is(new std::ifstream(fn)), local_is(true) |
|
2104 |
: _is(new std::ifstream(fn)), local_is(true), |
|
2105 |
_filename(fn) { |
|
2106 |
if (!(*_is)) throw IoError("Cannot open file", fn); |
|
2107 |
} |
|
2086 | 2108 |
|
2087 | 2109 |
/// \brief Destructor |
2088 | 2110 |
~SectionReader() { |
2089 | 2111 |
for (Sections::iterator it = _sections.begin(); |
... | ... |
@@ -2237,33 +2259,34 @@ |
2237 | 2259 |
_reader_bits::readToken(line, section); |
2238 | 2260 |
_reader_bits::readToken(line, caption); |
2239 | 2261 |
|
2240 | 2262 |
if (line >> c) |
2241 |
throw |
|
2263 |
throw FormatError("Extra character at the end of line"); |
|
2242 | 2264 |
|
2243 | 2265 |
if (extra_sections.find(section) != extra_sections.end()) { |
2244 | 2266 |
std::ostringstream msg; |
2245 |
msg << "Multiple occurence of section " << section; |
|
2246 |
throw DataFormatError(msg.str().c_str()); |
|
2267 |
msg << "Multiple occurence of section: " << section; |
|
2268 |
throw FormatError(msg.str()); |
|
2247 | 2269 |
} |
2248 | 2270 |
Sections::iterator it = _sections.find(section); |
2249 | 2271 |
if (it != _sections.end()) { |
2250 | 2272 |
extra_sections.insert(section); |
2251 | 2273 |
it->second->process(*_is, line_num); |
2252 | 2274 |
} |
2253 | 2275 |
readLine(); |
2254 | 2276 |
skipSection(); |
2255 |
} catch ( |
|
2277 |
} catch (FormatError& error) { |
|
2256 | 2278 |
error.line(line_num); |
2279 |
error.file(_filename); |
|
2257 | 2280 |
throw; |
2258 | 2281 |
} |
2259 | 2282 |
} |
2260 | 2283 |
for (Sections::iterator it = _sections.begin(); |
2261 | 2284 |
it != _sections.end(); ++it) { |
2262 | 2285 |
if (extra_sections.find(it->first) == extra_sections.end()) { |
2263 | 2286 |
std::ostringstream os; |
2264 | 2287 |
os << "Cannot find section: " << it->first; |
2265 |
throw |
|
2288 |
throw FormatError(os.str()); |
|
2266 | 2289 |
} |
2267 | 2290 |
} |
2268 | 2291 |
} |
2269 | 2292 |
|
... | ... |
@@ -2361,16 +2384,20 @@ |
2361 | 2384 |
/// |
2362 | 2385 |
/// Construct an \e LGF contents reader, which reads from the given |
2363 | 2386 |
/// file. |
2364 | 2387 |
LgfContents(const std::string& fn) |
2365 |
: _is(new std::ifstream(fn.c_str())), local_is(true) { |
|
2388 |
: _is(new std::ifstream(fn.c_str())), local_is(true) { |
|
2389 |
if (!(*_is)) throw IoError("Cannot open file", fn); |
|
2390 |
} |
|
2366 | 2391 |
|
2367 | 2392 |
/// \brief Constructor |
2368 | 2393 |
/// |
2369 | 2394 |
/// Construct an \e LGF contents reader, which reads from the given |
2370 | 2395 |
/// file. |
2371 | 2396 |
LgfContents(const char* fn) |
2372 |
: _is(new std::ifstream(fn)), local_is(true) { |
|
2397 |
: _is(new std::ifstream(fn)), local_is(true) { |
|
2398 |
if (!(*_is)) throw IoError("Cannot open file", fn); |
|
2399 |
} |
|
2373 | 2400 |
|
2374 | 2401 |
/// \brief Destructor |
2375 | 2402 |
~LgfContents() { |
2376 | 2403 |
if (local_is) delete _is; |
... | ... |
@@ -54,9 +54,9 @@ |
54 | 54 |
}; |
55 | 55 |
|
56 | 56 |
template <typename T> |
57 | 57 |
bool operator<(const T&, const T&) { |
58 |
throw |
|
58 |
throw FormatError("Label map is not comparable"); |
|
59 | 59 |
} |
60 | 60 |
|
61 | 61 |
template <typename _Map> |
62 | 62 |
class MapLess { |
... | ... |
@@ -202,9 +202,9 @@ |
202 | 202 |
std::string operator()(const Value& str) { |
203 | 203 |
typename std::map<Value, std::string>::const_iterator it = |
204 | 204 |
_map.find(str); |
205 | 205 |
if (it == _map.end()) { |
206 |
throw |
|
206 |
throw FormatError("Item not found"); |
|
207 | 207 |
} |
208 | 208 |
return it->second; |
209 | 209 |
} |
210 | 210 |
}; |
... | ... |
@@ -222,9 +222,9 @@ |
222 | 222 |
std::string operator()(const typename Graph::Arc& val) { |
223 | 223 |
typename std::map<typename Graph::Edge, std::string> |
224 | 224 |
::const_iterator it = _map.find(val); |
225 | 225 |
if (it == _map.end()) { |
226 |
throw |
|
226 |
throw FormatError("Item not found"); |
|
227 | 227 |
} |
228 | 228 |
return (_graph.direction(val) ? '+' : '-') + it->second; |
229 | 229 |
} |
230 | 230 |
}; |
... | ... |
@@ -461,17 +461,21 @@ |
461 | 461 |
/// Construct a directed graph writer, which writes to the given |
462 | 462 |
/// output file. |
463 | 463 |
DigraphWriter(const Digraph& digraph, const std::string& fn) |
464 | 464 |
: _os(new std::ofstream(fn.c_str())), local_os(true), _digraph(digraph), |
465 |
_skip_nodes(false), _skip_arcs(false) { |
|
465 |
_skip_nodes(false), _skip_arcs(false) { |
|
466 |
if (!(*_os)) throw IoError("Cannot write file", fn); |
|
467 |
} |
|
466 | 468 |
|
467 | 469 |
/// \brief Constructor |
468 | 470 |
/// |
469 | 471 |
/// Construct a directed graph writer, which writes to the given |
470 | 472 |
/// output file. |
471 | 473 |
DigraphWriter(const Digraph& digraph, const char* fn) |
472 | 474 |
: _os(new std::ofstream(fn)), local_os(true), _digraph(digraph), |
473 |
_skip_nodes(false), _skip_arcs(false) { |
|
475 |
_skip_nodes(false), _skip_arcs(false) { |
|
476 |
if (!(*_os)) throw IoError("Cannot write file", fn); |
|
477 |
} |
|
474 | 478 |
|
475 | 479 |
/// \brief Destructor |
476 | 480 |
~DigraphWriter() { |
477 | 481 |
for (typename NodeMaps::iterator it = _node_maps.begin(); |
... | ... |
@@ -1018,17 +1022,21 @@ |
1018 | 1022 |
/// Construct a directed graph writer, which writes to the given |
1019 | 1023 |
/// output file. |
1020 | 1024 |
GraphWriter(const Graph& graph, const std::string& fn) |
1021 | 1025 |
: _os(new std::ofstream(fn.c_str())), local_os(true), _graph(graph), |
1022 |
_skip_nodes(false), _skip_edges(false) { |
|
1026 |
_skip_nodes(false), _skip_edges(false) { |
|
1027 |
if (!(*_os)) throw IoError("Cannot write file", fn); |
|
1028 |
} |
|
1023 | 1029 |
|
1024 | 1030 |
/// \brief Constructor |
1025 | 1031 |
/// |
1026 | 1032 |
/// Construct a directed graph writer, which writes to the given |
1027 | 1033 |
/// output file. |
1028 | 1034 |
GraphWriter(const Graph& graph, const char* fn) |
1029 | 1035 |
: _os(new std::ofstream(fn)), local_os(true), _graph(graph), |
1030 |
_skip_nodes(false), _skip_edges(false) { |
|
1036 |
_skip_nodes(false), _skip_edges(false) { |
|
1037 |
if (!(*_os)) throw IoError("Cannot write file", fn); |
|
1038 |
} |
|
1031 | 1039 |
|
1032 | 1040 |
/// \brief Destructor |
1033 | 1041 |
~GraphWriter() { |
1034 | 1042 |
for (typename NodeMaps::iterator it = _node_maps.begin(); |
... | ... |
@@ -1577,15 +1585,19 @@ |
1577 | 1585 |
/// \brief Constructor |
1578 | 1586 |
/// |
1579 | 1587 |
/// Construct a section writer, which writes into the given file. |
1580 | 1588 |
SectionWriter(const std::string& fn) |
1581 |
: _os(new std::ofstream(fn.c_str())), local_os(true) { |
|
1589 |
: _os(new std::ofstream(fn.c_str())), local_os(true) { |
|
1590 |
if (!(*_os)) throw IoError("Cannot write file", fn); |
|
1591 |
} |
|
1582 | 1592 |
|
1583 | 1593 |
/// \brief Constructor |
1584 | 1594 |
/// |
1585 | 1595 |
/// Construct a section writer, which writes into the given file. |
1586 | 1596 |
SectionWriter(const char* fn) |
1587 |
: _os(new std::ofstream(fn)), local_os(true) { |
|
1597 |
: _os(new std::ofstream(fn)), local_os(true) { |
|
1598 |
if (!(*_os)) throw IoError("Cannot write file", fn); |
|
1599 |
} |
|
1588 | 1600 |
|
1589 | 1601 |
/// \brief Destructor |
1590 | 1602 |
~SectionWriter() { |
1591 | 1603 |
for (Sections::iterator it = _sections.begin(); |
0 comments (0 inline)