2081
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
2081
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #ifdef HAVE_CONFIG_H |
|
24 #include <config.h> |
|
25 #endif |
|
26 |
|
27 #include <cstdio> |
|
28 |
|
29 #include "oct-stdstrm.h" |
|
30 |
|
31 octave_base_stdiostream::~octave_base_stdiostream (void) |
|
32 { |
|
33 if (fp) |
|
34 { |
|
35 fclose (fp); |
|
36 fp = 0; |
|
37 } |
|
38 } |
|
39 |
|
40 // Position a stream at OFFSET relative to ORIGIN. |
|
41 |
|
42 int |
2610
|
43 octave_base_stdiostream::seek (streamoff offset, ios::seek_dir origin) |
2081
|
44 { |
|
45 int retval = -1; |
|
46 |
|
47 if (! bad ()) |
|
48 { |
|
49 stdiobuf *sb = rdbuf (); |
|
50 |
|
51 if (sb) |
|
52 { |
|
53 clear (); |
|
54 |
|
55 sb->seekoff (offset, origin); |
|
56 retval = bad () ? -1 : 0; |
|
57 } |
|
58 } |
|
59 |
|
60 return retval; |
|
61 } |
|
62 |
|
63 // Return current stream position. |
|
64 |
|
65 long |
|
66 octave_base_stdiostream::tell (void) const |
|
67 { |
|
68 long retval = -1; |
|
69 |
|
70 if (! bad ()) |
|
71 { |
|
72 stdiobuf *sb = rdbuf (); |
|
73 |
|
74 if (sb) |
|
75 { |
2800
|
76 retval = static_cast<long> (sb->seekoff (0, ios::cur)); |
2081
|
77 |
|
78 if (bad ()) |
|
79 retval = -1; |
|
80 } |
|
81 } |
|
82 |
|
83 return retval; |
|
84 } |
|
85 |
|
86 octave_istdiostream::octave_istdiostream (const string& n, FILE *f, |
|
87 ios::openmode arg_md, |
2317
|
88 oct_mach_info::float_format flt_fmt) |
|
89 : octave_base_stdiostream (n, f, arg_md, flt_fmt), is (0) |
2081
|
90 { |
|
91 if (f) |
|
92 is = new istdiostream (f); |
|
93 } |
|
94 |
|
95 octave_istdiostream::~octave_istdiostream (void) |
|
96 { |
|
97 delete is; |
|
98 } |
|
99 |
|
100 octave_ostdiostream::octave_ostdiostream (const string& n, FILE *f, |
|
101 ios::openmode arg_md, |
2317
|
102 oct_mach_info::float_format flt_fmt) |
|
103 : octave_base_stdiostream (n, f, arg_md, flt_fmt), os (0) |
2081
|
104 { |
|
105 if (f) |
|
106 os = new ostdiostream (f); |
|
107 } |
|
108 |
|
109 octave_ostdiostream::~octave_ostdiostream (void) |
|
110 { |
|
111 delete os; |
|
112 } |
|
113 |
|
114 /* |
|
115 ;;; Local Variables: *** |
|
116 ;;; mode: C++ *** |
|
117 ;;; End: *** |
|
118 */ |