gravatar
deba@inf.elte.hu
deba@inf.elte.hu
Bug fixes and improvements in LGF IO
0 2 0
default
2 files changed with 33 insertions and 23 deletions:
↑ Collapse diff ↑
Ignore white space 6 line context
... ...
@@ -462,17 +462,17 @@
462 462
    /// \brief Copy constructor
463 463
    ///
464 464
    /// The copy constructor transfers all data from the other reader,
465 465
    /// therefore the copied reader will not be usable more. 
466 466
    DigraphReader(DigraphReader& other) 
467 467
      : _is(other._is), local_is(other.local_is), _digraph(other._digraph),
468 468
	_use_nodes(other._use_nodes), _use_arcs(other._use_arcs) {
469 469

	
470
      other.is = 0;
470
      other._is = 0;
471 471
      other.local_is = false;
472 472
      
473 473
      _node_index.swap(other._node_index);
474 474
      _arc_index.swap(other._arc_index);
475 475

	
476 476
      _node_maps.swap(other._node_maps);
477 477
      _arc_maps.swap(other._arc_maps);
478 478
      _attributes.swap(other._attributes);
... ...
@@ -1073,18 +1073,20 @@
1073 1073

	
1074 1074
    /// \name Execution of the reader    
1075 1075
    /// @{
1076 1076

	
1077 1077
    /// \brief Start the batch processing
1078 1078
    ///
1079 1079
    /// This function starts the batch processing
1080 1080
    void run() {
1081
      
1082 1081
      LEMON_ASSERT(_is != 0, "This reader assigned to an other reader");
1082
      if (!*_is) {
1083
	throw DataFormatError("Cannot find file");
1084
      }
1083 1085
      
1084 1086
      bool nodes_done = false;
1085 1087
      bool arcs_done = false;
1086 1088
      bool attributes_done = false;
1087 1089
      std::set<std::string> extra_sections;
1088 1090

	
1089 1091
      line_num = 0;      
1090 1092
      readLine();
... ...
@@ -1155,26 +1157,29 @@
1155 1157

	
1156 1158
    /// @}
1157 1159
    
1158 1160
  };
1159 1161

	
1160 1162
  /// \relates DigraphReader
1161 1163
  template <typename Digraph>
1162 1164
  DigraphReader<Digraph> digraphReader(std::istream& is, Digraph& digraph) {
1163
    return DigraphReader<Digraph>(is, digraph);
1165
    DigraphReader<Digraph> tmp(is, digraph);
1166
    return tmp;
1164 1167
  }
1165 1168

	
1166 1169
  /// \relates DigraphReader
1167 1170
  template <typename Digraph>
1168 1171
  DigraphReader<Digraph> digraphReader(const std::string& fn, 
1169 1172
				       Digraph& digraph) {
1170
    return DigraphReader<Digraph>(fn, digraph);
1173
    DigraphReader<Digraph> tmp(fn, digraph);
1174
    return tmp;
1171 1175
  }
1172 1176

	
1173 1177
  /// \relates DigraphReader
1174 1178
  template <typename Digraph>
1175 1179
  DigraphReader<Digraph> digraphReader(const char* fn, Digraph& digraph) {
1176
    return DigraphReader<Digraph>(fn, digraph);
1180
    DigraphReader<Digraph> tmp(fn, digraph);
1181
    return tmp;
1177 1182
  }
1178 1183
}
1179 1184

	
1180 1185
#endif
Ignore white space 16 line context
... ...
@@ -190,17 +190,19 @@
190 190
      case '\t':
191 191
	os << "\\t";
192 192
	return;
193 193
      case '\v':
194 194
	os << "\\v";
195 195
	return;
196 196
      default:
197 197
	if (c < 0x20) {
198
	  std::ios::fmtflags flags = os.flags();
198 199
	  os << '\\' << std::oct << static_cast<int>(c);
200
	  os.flags(flags);
199 201
	} else {
200 202
	  os << c;
201 203
	}
202 204
	return;
203 205
      }     
204 206
    }
205 207

	
206 208
    bool requireEscape(const std::string& str) {
... ...
@@ -238,22 +240,22 @@
238 240
  ///
239 241
  /// This utility writes an \ref lgf-format "LGF" file.
240 242
  ///
241 243
  /// The writing method does a batch processing. The user creates a
242 244
  /// writer object, then various writing rules can be added to the
243 245
  /// writer, and eventually the writing is executed with the \c run()
244 246
  /// member function. A map writing rule can be added to the writer
245 247
  /// with the \c nodeMap() or \c arcMap() members. An optional
246
  /// converter parameter can also be added as a standard functor converting from
247
  /// the value type of the map to std::string. If it is set, it will
248
  /// determine how the map's value type is written to the output
249
  /// stream. If the functor is not set, then a default conversion
250
  /// will be used. The \c attribute(), \c node() and \c arc() functions
251
  /// are used to add attribute writing rules.
248
  /// converter parameter can also be added as a standard functor
249
  /// converting from the value type of the map to std::string. If it
250
  /// is set, it will determine how the map's value type is written to
251
  /// the output stream. If the functor is not set, then a default
252
  /// conversion will be used. The \c attribute(), \c node() and \c
253
  /// arc() functions are used to add attribute writing rules.
252 254
  ///
253 255
  ///\code
254 256
  ///     DigraphWriter<Digraph>(std::cout, digraph).
255 257
  ///       nodeMap("coordinates", coord_map).
256 258
  ///       nodeMap("size", size).
257 259
  ///       nodeMap("title", title).
258 260
  ///       arcMap("capacity", cap_map).
259 261
  ///       node("source", src).
... ...
@@ -264,23 +266,23 @@
264 266
  ///
265 267
  ///
266 268
  /// By default, the writer does not write additional captions to the
267 269
  /// sections, but they can be give as an optional parameter of
268 270
  /// the \c nodes(), \c arcs() or \c
269 271
  /// attributes() functions.
270 272
  ///
271 273
  /// The \c skipNodes() and \c skipArcs() functions forbid the
272
  /// writing of the sections. If two arc sections should be written to the
273
  /// output, it can be done in two passes, the first pass writes the
274
  /// node section and the first arc section, then the second pass
275
  /// skips the node section and writes just the arc section to the
276
  /// stream. The output stream can be retrieved with the \c ostream()
277
  /// function, hence the second pass can append its output to the output of the
278
  /// first pass.
274
  /// writing of the sections. If two arc sections should be written
275
  /// to the output, it can be done in two passes, the first pass
276
  /// writes the node section and the first arc section, then the
277
  /// second pass skips the node section and writes just the arc
278
  /// section to the stream. The output stream can be retrieved with
279
  /// the \c ostream() function, hence the second pass can append its
280
  /// output to the output of the first pass.
279 281
  template <typename _Digraph>
280 282
  class DigraphWriter {
281 283
  public:
282 284

	
283 285
    typedef _Digraph Digraph;
284 286
    TEMPLATE_DIGRAPH_TYPEDEFS(Digraph);
285 287
    
286 288
  private:
... ...
@@ -344,17 +346,17 @@
344 346
    /// \brief Copy constructor
345 347
    ///
346 348
    /// The copy constructor transfers all data from the other writer,
347 349
    /// therefore the copied writer will not be usable more. 
348 350
    DigraphWriter(DigraphWriter& other) 
349 351
      : _os(other._os), local_os(other.local_os), _digraph(other._digraph),
350 352
	_skip_nodes(other._skip_nodes), _skip_arcs(other._skip_arcs) {
351 353

	
352
      other.is = 0;
354
      other._os = 0;
353 355
      other.local_os = false;
354 356

	
355 357
      _node_index.swap(other._node_index);
356 358
      _arc_index.swap(other._arc_index);
357 359

	
358 360
      _node_maps.swap(other._node_maps);
359 361
      _arc_maps.swap(other._arc_maps);
360 362
      _attributes.swap(other._attributes);
... ...
@@ -712,27 +714,30 @@
712 714
      return *_os;
713 715
    }
714 716

	
715 717
    /// @}
716 718
  };
717 719

	
718 720
  /// \relates DigraphWriter
719 721
  template <typename Digraph>
720
  DigraphWriter<Digraph> digraphWriter(std::istream& is, Digraph& digraph) {
721
    return DigraphWriter<Digraph>(is, digraph);
722
  DigraphWriter<Digraph> digraphWriter(std::ostream& os, Digraph& digraph) {
723
    DigraphWriter<Digraph> tmp(os, digraph);
724
    return tmp;
722 725
  }
723 726

	
724 727
  /// \relates DigraphWriter
725 728
  template <typename Digraph>
726 729
  DigraphWriter<Digraph> digraphWriter(const std::string& fn, 
727 730
				       Digraph& digraph) {
728
    return DigraphWriter<Digraph>(fn, digraph);
731
    DigraphWriter<Digraph> tmp(fn, digraph);
732
    return tmp;
729 733
  }
730 734

	
731 735
  /// \relates DigraphWriter
732 736
  template <typename Digraph>
733 737
  DigraphWriter<Digraph> digraphWriter(const char* fn, Digraph& digraph) {
734
    return DigraphWriter<Digraph>(fn, digraph);
738
    DigraphWriter<Digraph> tmp(fn, digraph);
739
    return tmp;
735 740
  }
736 741
}
737 742

	
738 743
#endif
0 comments (0 inline)