comparison src/oct-stream.h @ 3523:b80bbb43a1a9

[project @ 2000-02-02 10:25:52 by jwe]
author jwe
date Wed, 02 Feb 2000 10:26:25 +0000
parents d14c483b3c12
children 71bd2d124119
comparison
equal deleted inserted replaced
3522:bd422cf62f0c 3523:b80bbb43a1a9
45 literal_conversion = 2 45 literal_conversion = 2
46 }; 46 };
47 47
48 scanf_format_elt (const char *txt = 0, int w = 0, bool d = false, 48 scanf_format_elt (const char *txt = 0, int w = 0, bool d = false,
49 char typ = '\0', char mod = '\0', 49 char typ = '\0', char mod = '\0',
50 const string& ch_class = string ()) 50 const std::string& ch_class = std::string ())
51 : text (txt), width (w), discard (d), type (typ), modifier (mod), 51 : text (txt), width (w), discard (d), type (typ), modifier (mod),
52 char_class (ch_class) { } 52 char_class (ch_class) { }
53 53
54 ~scanf_format_elt (void) { delete text; } 54 ~scanf_format_elt (void) { delete text; }
55 55
56 const char *text; 56 const char *text;
57 int width; 57 int width;
58 bool discard; 58 bool discard;
59 char type; 59 char type;
60 char modifier; 60 char modifier;
61 string char_class; 61 std::string char_class;
62 }; 62 };
63 63
64 class 64 class
65 scanf_format_list 65 scanf_format_list
66 { 66 {
67 public: 67 public:
68 68
69 scanf_format_list (const string& fmt = string ()); 69 scanf_format_list (const std::string& fmt = std::string ());
70 70
71 ~scanf_format_list (void); 71 ~scanf_format_list (void);
72 72
73 int num_conversions (void) { return nconv; } 73 int num_conversions (void) { return nconv; }
74 74
106 106
107 bool all_numeric_conversions (void); 107 bool all_numeric_conversions (void);
108 108
109 private: 109 private:
110 110
111 // Number of conversions specified by this format string, or -1 if 111 // Number of conversions specified by this format std::string, or -1 if
112 // invalid conversions have been found. 112 // invalid conversions have been found.
113 int nconv; 113 int nconv;
114 114
115 // Index to current element; 115 // Index to current element;
116 int curr_idx; 116 int curr_idx;
117 117
118 // List of format elements. 118 // List of format elements.
119 Array<scanf_format_elt*> list; 119 Array<scanf_format_elt*> list;
120 120
121 // Temporary buffer. 121 // Temporary buffer.
122 ostrstream *buf; 122 std::ostrstream *buf;
123 123
124 void add_elt_to_list (int width, bool discard, char type, char modifier, 124 void add_elt_to_list (int width, bool discard, char type, char modifier,
125 int& num_elts, const string& char_class = string ()); 125 int& num_elts, const std::string& char_class = std::string ());
126 126
127 void process_conversion (const string& s, int& i, int n, int& width, 127 void process_conversion (const std::string& s, int& i, int n, int& width,
128 bool& discard, char& type, char& modifier, 128 bool& discard, char& type, char& modifier,
129 int& num_elts); 129 int& num_elts);
130 130
131 int finish_conversion (const string& s, int& i, int n, int& width, 131 int finish_conversion (const std::string& s, int& i, int n, int& width,
132 bool discard, char& type, char modifier, 132 bool discard, char& type, char modifier,
133 int& num_elts); 133 int& num_elts);
134 // No copying! 134 // No copying!
135 135
136 scanf_format_list (const scanf_format_list&); 136 scanf_format_list (const scanf_format_list&);
156 class 156 class
157 printf_format_list 157 printf_format_list
158 { 158 {
159 public: 159 public:
160 160
161 printf_format_list (const string& fmt = string ()); 161 printf_format_list (const std::string& fmt = std::string ());
162 162
163 ~printf_format_list (void); 163 ~printf_format_list (void);
164 164
165 int num_conversions (void) { return nconv; } 165 int num_conversions (void) { return nconv; }
166 166
187 187
188 operator bool () const { return ok (); } 188 operator bool () const { return ok (); }
189 189
190 private: 190 private:
191 191
192 // Number of conversions specified by this format string, or -1 if 192 // Number of conversions specified by this format std::string, or -1 if
193 // invalid conversions have been found. 193 // invalid conversions have been found.
194 int nconv; 194 int nconv;
195 195
196 // Index to current element; 196 // Index to current element;
197 int curr_idx; 197 int curr_idx;
198 198
199 // List of format elements. 199 // List of format elements.
200 Array<printf_format_elt*> list; 200 Array<printf_format_elt*> list;
201 201
202 // Temporary buffer. 202 // Temporary buffer.
203 ostrstream *buf; 203 std::ostrstream *buf;
204 204
205 void add_elt_to_list (int args, char type, char modifier, 205 void add_elt_to_list (int args, char type, char modifier,
206 int& num_elts); 206 int& num_elts);
207 207
208 void process_conversion (const string& s, int& i, int n, int& args, 208 void process_conversion (const std::string& s, int& i, int n, int& args,
209 char& modifier, char& type, int& num_elts); 209 char& modifier, char& type, int& num_elts);
210 210
211 void finish_conversion (const string& s, int& i, int args, 211 void finish_conversion (const std::string& s, int& i, int args,
212 char modifier, char& type, int& num_elts); 212 char modifier, char& type, int& num_elts);
213 213
214 // No copying! 214 // No copying!
215 215
216 printf_format_list (const printf_format_list&); 216 printf_format_list (const printf_format_list&);
249 249
250 virtual bool eof (void) const = 0; 250 virtual bool eof (void) const = 0;
251 251
252 // The name of the file. 252 // The name of the file.
253 253
254 virtual string name (void) const = 0; 254 virtual std::string name (void) const = 0;
255 255
256 // If the derived class provides this function and it returns a 256 // If the derived class provides this function and it returns a
257 // pointer to a valid istream, scanf(), read(), getl(), and gets() 257 // pointer to a valid istream, scanf(), read(), getl(), and gets()
258 // will automatically work for this stream. 258 // will automatically work for this stream.
259 259
260 virtual istream *input_stream (void) { return 0; } 260 virtual std::istream *input_stream (void) { return 0; }
261 261
262 // If the derived class provides this function and it returns a 262 // If the derived class provides this function and it returns a
263 // pointer to a valid ostream, flush(), write(), and printf() will 263 // pointer to a valid ostream, flush(), write(), and printf() will
264 // automatically work for this stream. 264 // automatically work for this stream.
265 265
266 virtual ostream *output_stream (void) { return 0; } 266 virtual std::ostream *output_stream (void) { return 0; }
267 267
268 // Return TRUE if this stream is open. 268 // Return TRUE if this stream is open.
269 269
270 bool is_open (void) const { return open_state; } 270 bool is_open (void) const { return open_state; }
271 271
275 275
276 bool ok (void) const { return ! fail; } 276 bool ok (void) const { return ! fail; }
277 277
278 // Return current error message for this stream. 278 // Return current error message for this stream.
279 279
280 string error (bool clear, int& err_num); 280 std::string error (bool clear, int& err_num);
281 281
282 protected: 282 protected:
283 283
284 int mode (void) const { return md; } 284 int mode (void) const { return md; }
285 285
286 oct_mach_info::float_format float_format (void) const { return flt_fmt; } 286 oct_mach_info::float_format float_format (void) const { return flt_fmt; }
287 287
288 // Set current error state and set fail to TRUE. 288 // Set current error state and set fail to TRUE.
289 289
290 void error (const string& msg); 290 void error (const std::string& msg);
291 291
292 // Clear any error message and set fail to FALSE. 292 // Clear any error message and set fail to FALSE.
293 293
294 void clear (void); 294 void clear (void);
295 295
310 310
311 // TRUE if this stream is open. 311 // TRUE if this stream is open.
312 bool open_state; 312 bool open_state;
313 313
314 // Should contain error message if fail is TRUE. 314 // Should contain error message if fail is TRUE.
315 string errmsg; 315 std::string errmsg;
316 316
317 // Functions that are defined for all input streams (input streams 317 // Functions that are defined for all input streams (input streams
318 // are those that define is). 318 // are those that define is).
319 319
320 string do_gets (int max_len, bool& err, bool strip_newline, 320 std::string do_gets (int max_len, bool& err, bool strip_newline,
321 const char *fcn); 321 const char *fcn);
322 322
323 string getl (int max_len, bool& err); 323 std::string getl (int max_len, bool& err);
324 string gets (int max_len, bool& err); 324 std::string gets (int max_len, bool& err);
325 325
326 octave_value do_read (int nr, int nc, oct_data_conv::data_type dt, 326 octave_value do_read (int nr, int nc, oct_data_conv::data_type dt,
327 int skip, oct_mach_info::float_format flt_fmt, 327 int skip, oct_mach_info::float_format flt_fmt,
328 int& count); 328 int& count);
329 329
338 int nr, int nc, int& count); 338 int nr, int nc, int& count);
339 339
340 octave_value do_scanf (scanf_format_list& fmt_list, int nr, int nc, 340 octave_value do_scanf (scanf_format_list& fmt_list, int nr, int nc,
341 bool one_elt_size_spec, int& count); 341 bool one_elt_size_spec, int& count);
342 342
343 octave_value scanf (const string& fmt, const Matrix& size, int& count); 343 octave_value scanf (const std::string& fmt, const Matrix& size, int& count);
344 344
345 bool do_oscanf (const scanf_format_elt *elt, octave_value&); 345 bool do_oscanf (const scanf_format_elt *elt, octave_value&);
346 346
347 octave_value_list oscanf (const string& fmt); 347 octave_value_list oscanf (const std::string& fmt);
348 348
349 // Functions that are defined for all output streams (output streams 349 // Functions that are defined for all output streams (output streams
350 // are those that define os). 350 // are those that define os).
351 351
352 int flush (void); 352 int flush (void);
357 int write (const octave_value& data, oct_data_conv::data_type dt, 357 int write (const octave_value& data, oct_data_conv::data_type dt,
358 int skip, oct_mach_info::float_format flt_fmt); 358 int skip, oct_mach_info::float_format flt_fmt);
359 359
360 int do_printf (printf_format_list& fmt_list, const octave_value_list& args); 360 int do_printf (printf_format_list& fmt_list, const octave_value_list& args);
361 361
362 int printf (const string& fmt, const octave_value_list& args); 362 int printf (const std::string& fmt, const octave_value_list& args);
363 363
364 int puts (const string& s); 364 int puts (const std::string& s);
365 365
366 // We can always do this in terms of seek(), so the derived class 366 // We can always do this in terms of seek(), so the derived class
367 // only has to provide that. 367 // only has to provide that.
368 368
369 int rewind (void); 369 int rewind (void);
390 390
391 octave_stream& operator = (const octave_stream&); 391 octave_stream& operator = (const octave_stream&);
392 392
393 int flush (void); 393 int flush (void);
394 394
395 string getl (int max_len, bool& err); 395 std::string getl (int max_len, bool& err);
396 string getl (const octave_value& max_len, bool& err); 396 std::string getl (const octave_value& max_len, bool& err);
397 397
398 string gets (int max_len, bool& err); 398 std::string gets (int max_len, bool& err);
399 string gets (const octave_value& max_len, bool& err); 399 std::string gets (const octave_value& max_len, bool& err);
400 400
401 int seek (streamoff offset, ios::seek_dir origin); 401 int seek (streamoff offset, ios::seek_dir origin);
402 int seek (const octave_value& offset, const octave_value& origin); 402 int seek (const octave_value& offset, const octave_value& origin);
403 403
404 long tell (void) const; 404 long tell (void) const;
414 int& count); 414 int& count);
415 415
416 int write (const octave_value& data, oct_data_conv::data_type dt, 416 int write (const octave_value& data, oct_data_conv::data_type dt,
417 int skip, oct_mach_info::float_format flt_fmt); 417 int skip, oct_mach_info::float_format flt_fmt);
418 418
419 octave_value scanf (const string& fmt, const Matrix& size, int& count); 419 octave_value scanf (const std::string& fmt, const Matrix& size, int& count);
420 420
421 octave_value_list oscanf (const string& fmt); 421 octave_value_list oscanf (const std::string& fmt);
422 422
423 int printf (const string& fmt, const octave_value_list& args); 423 int printf (const std::string& fmt, const octave_value_list& args);
424 424
425 int puts (const string& s); 425 int puts (const std::string& s);
426 int puts (const octave_value& s); 426 int puts (const octave_value& s);
427 427
428 bool eof (void) const; 428 bool eof (void) const;
429 429
430 string error (bool clear, int& err_num); 430 std::string error (bool clear, int& err_num);
431 431
432 string error (bool clear = false) 432 std::string error (bool clear = false)
433 { 433 {
434 int err_num; 434 int err_num;
435 return error (clear, err_num); 435 return error (clear, err_num);
436 } 436 }
437 437
441 441
442 bool ok (void) const { return rep && rep->ok (); } 442 bool ok (void) const { return rep && rep->ok (); }
443 443
444 operator bool () const { return ok (); } 444 operator bool () const { return ok (); }
445 445
446 string name (void) const; 446 std::string name (void) const;
447 447
448 int mode (void) const; 448 int mode (void) const;
449 449
450 oct_mach_info::float_format float_format (void) const; 450 oct_mach_info::float_format float_format (void) const;
451 451
452 static string mode_as_string (int mode); 452 static std::string mode_as_string (int mode);
453 453
454 istream *input_stream (void) { return rep ? rep->input_stream () : 0; } 454 std::istream *input_stream (void) { return rep ? rep->input_stream () : 0; }
455 455
456 ostream *output_stream (void) { return rep ? rep->output_stream () : 0; } 456 std::ostream *output_stream (void) { return rep ? rep->output_stream () : 0; }
457 457
458 private: 458 private:
459 459
460 // The actual representation of this stream. 460 // The actual representation of this stream.
461 octave_base_stream *rep; 461 octave_base_stream *rep;
478 } 478 }
479 479
480 return retval; 480 return retval;
481 } 481 }
482 482
483 void error (const string& msg) 483 void error (const std::string& msg)
484 { 484 {
485 if (rep) 485 if (rep)
486 rep->error (msg); 486 rep->error (msg);
487 } 487 }
488 }; 488 };
500 500
501 static bool instance_ok (void); 501 static bool instance_ok (void);
502 502
503 static octave_value insert (const octave_stream& os); 503 static octave_value insert (const octave_stream& os);
504 504
505 static octave_stream lookup (int fid, const string& who = string ()); 505 static octave_stream lookup (int fid, const std::string& who = std::string ());
506 static octave_stream lookup (const octave_value& fid, 506 static octave_stream lookup (const octave_value& fid,
507 const string& who = string ()); 507 const std::string& who = std::string ());
508 508
509 static int remove (int fid, const string& who = string ()); 509 static int remove (int fid, const std::string& who = std::string ());
510 static int remove (const octave_value& fid, 510 static int remove (const octave_value& fid,
511 const string& who = string ()); 511 const std::string& who = std::string ());
512 512
513 static void clear (void); 513 static void clear (void);
514 514
515 static string_vector get_info (int fid); 515 static string_vector get_info (int fid);
516 static string_vector get_info (const octave_value& fid); 516 static string_vector get_info (const octave_value& fid);
517 517
518 static string list_open_files (void); 518 static std::string list_open_files (void);
519 519
520 static octave_value open_file_numbers (void); 520 static octave_value open_file_numbers (void);
521 521
522 static int get_file_number (const octave_value& fid); 522 static int get_file_number (const octave_value& fid);
523 523
529 529
530 static octave_stream_list *instance; 530 static octave_stream_list *instance;
531 531
532 octave_value do_insert (const octave_stream& os); 532 octave_value do_insert (const octave_stream& os);
533 533
534 octave_stream do_lookup (int fid, const string& who = string ()) const; 534 octave_stream do_lookup (int fid, const std::string& who = std::string ()) const;
535 octave_stream do_lookup (const octave_value& fid, 535 octave_stream do_lookup (const octave_value& fid,
536 const string& who = string ()) const; 536 const std::string& who = std::string ()) const;
537 537
538 int do_remove (int fid, const string& who = string ()); 538 int do_remove (int fid, const std::string& who = std::string ());
539 int do_remove (const octave_value& fid, const string& who = string ()); 539 int do_remove (const octave_value& fid, const std::string& who = std::string ());
540 540
541 void do_clear (void); 541 void do_clear (void);
542 542
543 string_vector do_get_info (int fid) const; 543 string_vector do_get_info (int fid) const;
544 string_vector do_get_info (const octave_value& fid) const; 544 string_vector do_get_info (const octave_value& fid) const;
545 545
546 string do_list_open_files (void) const; 546 std::string do_list_open_files (void) const;
547 547
548 octave_value do_open_file_numbers (void) const; 548 octave_value do_open_file_numbers (void) const;
549 549
550 int do_get_file_number (const octave_value& fid) const; 550 int do_get_file_number (const octave_value& fid) const;
551 }; 551 };