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 |
3546
|
43 octave_base_stdiostream::seek (std::streamoff offset, std::ios::seek_dir origin) |
2081
|
44 { |
|
45 int retval = -1; |
|
46 |
|
47 if (! bad ()) |
|
48 { |
3611
|
49 c_file_ptr_buf *sb = rdbuf (); |
2081
|
50 |
|
51 if (sb) |
|
52 { |
|
53 clear (); |
|
54 |
3611
|
55 sb->pubseekoff (offset, origin); |
2081
|
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 { |
3611
|
72 c_file_ptr_buf *sb = rdbuf (); |
2081
|
73 |
|
74 if (sb) |
|
75 { |
3611
|
76 retval = static_cast<long> (sb->pubseekoff (0, std::ios::cur)); |
2081
|
77 |
|
78 if (bad ()) |
|
79 retval = -1; |
|
80 } |
|
81 } |
|
82 |
|
83 return retval; |
|
84 } |
|
85 |
3340
|
86 octave_stream |
3523
|
87 octave_istdiostream::create (const std::string& n, FILE *f, |
3626
|
88 std::ios::openmode arg_md, |
3340
|
89 oct_mach_info::float_format flt_fmt) |
|
90 { |
|
91 return octave_stream (new octave_istdiostream (n, f, arg_md, flt_fmt)); |
|
92 } |
|
93 |
3523
|
94 octave_istdiostream::octave_istdiostream (const std::string& n, FILE *f, |
3626
|
95 std::ios::openmode arg_md, |
2317
|
96 oct_mach_info::float_format flt_fmt) |
|
97 : octave_base_stdiostream (n, f, arg_md, flt_fmt), is (0) |
2081
|
98 { |
|
99 if (f) |
3611
|
100 is = new i_c_file_ptr_stream (f); |
2081
|
101 } |
|
102 |
|
103 octave_istdiostream::~octave_istdiostream (void) |
|
104 { |
|
105 delete is; |
|
106 } |
|
107 |
3340
|
108 octave_stream |
3523
|
109 octave_ostdiostream::create (const std::string& n, FILE *f, |
3626
|
110 std::ios::openmode arg_md, |
3340
|
111 oct_mach_info::float_format flt_fmt) |
|
112 { |
|
113 return octave_stream (new octave_ostdiostream (n, f, arg_md, flt_fmt)); |
|
114 } |
|
115 |
3523
|
116 octave_ostdiostream::octave_ostdiostream (const std::string& n, FILE *f, |
3626
|
117 std::ios::openmode arg_md, |
2317
|
118 oct_mach_info::float_format flt_fmt) |
|
119 : octave_base_stdiostream (n, f, arg_md, flt_fmt), os (0) |
2081
|
120 { |
|
121 if (f) |
3611
|
122 os = new o_c_file_ptr_stream (f); |
2081
|
123 } |
|
124 |
|
125 octave_ostdiostream::~octave_ostdiostream (void) |
|
126 { |
|
127 delete os; |
|
128 } |
|
129 |
|
130 /* |
|
131 ;;; Local Variables: *** |
|
132 ;;; mode: C++ *** |
|
133 ;;; End: *** |
|
134 */ |