Mercurial > octave
annotate libinterp/corefcn/oct-fstrm.cc @ 27172:b0abae0bd94b
style fixes
* oct-fstrm.cc, oct-fstrm.h, oct-iostrm.cc, oct-iostrm.h,
oct-stream.cc, oct-stream.h, oct-strstrm.h, procstream.cc,
procstream.h: Use m_ prefix for member variable names and other minor
style fixes.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 11 Jun 2019 12:53:55 -0500 |
parents | 00f796120a6d |
children | b442ec6dda5c |
rev | line source |
---|---|
2081 | 1 /* |
2 | |
26376
00f796120a6d
maint: Update copyright dates in all source files.
John W. Eaton <jwe@octave.org>
parents:
25054
diff
changeset
|
3 Copyright (C) 1996-2019 John W. Eaton |
2081 | 4 |
5 This file is part of Octave. | |
6 | |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
7 Octave is free software: you can redistribute it and/or modify it |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
8 under the terms of the GNU General Public License as published by |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
9 the Free Software Foundation, either version 3 of the License, or |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
10 (at your option) any later version. |
2081 | 11 |
22755
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
12 Octave is distributed in the hope that it will be useful, but |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
13 WITHOUT ANY WARRANTY; without even the implied warranty of |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
3a2b891d0b33
maint: Standardize Copyright formatting.
Rik <rik@octave.org>
parents:
22407
diff
changeset
|
15 GNU General Public License for more details. |
2081 | 16 |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
24534
194eb4bd202b
maint: Update punctuation for GPL v3 license text.
Rik <rik@octave.org>
parents:
23457
diff
changeset
|
19 <https://www.gnu.org/licenses/>. |
2081 | 20 |
21 */ | |
22 | |
21724
aba2e6293dd8
use "#if ..." consistently instead of "#ifdef" and "#ifndef"
John W. Eaton <jwe@octave.org>
parents:
21301
diff
changeset
|
23 #if defined (HAVE_CONFIG_H) |
21301
40de9f8f23a6
Use '#include "config.h"' rather than <config.h>.
Rik <rik@octave.org>
parents:
21200
diff
changeset
|
24 # include "config.h" |
2081 | 25 #endif |
26 | |
27 #include <cerrno> | |
10463
bbe99b2a5ba7
undo recent gnulib-related changes
John W. Eaton <jwe@octave.org>
parents:
10447
diff
changeset
|
28 #include <cstring> |
2081 | 29 |
30 #include "error.h" | |
31 #include "oct-fstrm.h" | |
32 | |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
33 octave::stream |
3570 | 34 octave_fstream::create (const std::string& nm_arg, std::ios::openmode arg_md, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
35 octave::mach_info::float_format ff) |
3340 | 36 { |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
37 return octave::stream (new octave_fstream (nm_arg, arg_md, ff)); |
3340 | 38 } |
39 | |
3552 | 40 octave_fstream::octave_fstream (const std::string& nm_arg, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
41 std::ios::openmode arg_md, |
21739
c4ab2e54f100
use namespace for oct_mach_info class
John W. Eaton <jwe@octave.org>
parents:
21724
diff
changeset
|
42 octave::mach_info::float_format ff) |
27172 | 43 : octave::base_stream (arg_md, ff), m_name (nm_arg) |
2081 | 44 { |
27172 | 45 m_fstream.open (m_name.c_str (), arg_md); |
3775 | 46 |
27172 | 47 if (! m_fstream) |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
48 // Note: error is inherited from octave::base_stream, not ::error. |
21942
aab79a1885cc
limit gnulib headers to liboctave/wrappers directory
John W. Eaton <jwe@octave.org>
parents:
21739
diff
changeset
|
49 error (std::strerror (errno)); |
2081 | 50 } |
51 | |
52 // Position a stream at OFFSET relative to ORIGIN. | |
53 | |
54 int | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
55 octave_fstream::seek (off_t, int) |
2081 | 56 { |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
57 // Note: error is inherited from octave::base_stream, not ::error. |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20916
diff
changeset
|
58 // This error function does not halt execution so "return ..." must exist. |
4797 | 59 error ("fseek: invalid_operation"); |
20916
8ddb11c0b1f8
restore return statements after calls to octave_base_stream::error
John W. Eaton <jwe@octave.org>
parents:
20893
diff
changeset
|
60 return -1; |
2081 | 61 } |
62 | |
63 // Return current stream position. | |
64 | |
16011
8122286c69a9
initial large file support for 32-bit systems
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
65 off_t |
4797 | 66 octave_fstream::tell (void) |
2081 | 67 { |
23059
b98ebcd7f11c
move some octave stream classes into octave namespace
John W. Eaton <jwe@octave.org>
parents:
22755
diff
changeset
|
68 // Note: error is inherited from octave::base_stream, not ::error. |
20931
69dcb58b9ada
Clean up use of error() versus ::error() in stream-based code.
Rik <rik@octave.org>
parents:
20916
diff
changeset
|
69 // This error function does not halt execution so "return ..." must exist. |
4797 | 70 error ("ftell: invalid_operation"); |
20916
8ddb11c0b1f8
restore return statements after calls to octave_base_stream::error
John W. Eaton <jwe@octave.org>
parents:
20893
diff
changeset
|
71 return -1; |
2081 | 72 } |
73 | |
18812
9ac2357f19bc
doc: Replace "non-zero" with "nonzero" to match existing usage.
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
74 // Return nonzero if EOF has been reached on this stream. |
2081 | 75 |
76 bool | |
77 octave_fstream::eof (void) const | |
78 { | |
27172 | 79 return m_fstream.eof (); |
2081 | 80 } |
81 | |
3652 | 82 void |
83 octave_fstream::do_close (void) | |
84 { | |
27172 | 85 m_fstream.close (); |
3652 | 86 } |
87 | |
3523 | 88 std::istream * |
2081 | 89 octave_fstream::input_stream (void) |
90 { | |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
91 std::istream *retval = nullptr; |
2081 | 92 |
3544 | 93 if (mode () & std::ios::in) |
27172 | 94 retval = &m_fstream; |
2081 | 95 |
96 return retval; | |
97 } | |
98 | |
3523 | 99 std::ostream * |
2081 | 100 octave_fstream::output_stream (void) |
101 { | |
23457
21baad6b35c4
maint: Use C++11 nullptr rather than 0 or NULL when possible.
Rik <rik@octave.org>
parents:
23220
diff
changeset
|
102 std::ostream *retval = nullptr; |
2081 | 103 |
3544 | 104 if (mode () & std::ios::out) |
27172 | 105 retval = &m_fstream; |
2081 | 106 |
107 return retval; | |
108 } |