comparison libinterp/corefcn/oct-fstrm.cc @ 29991:3988112c7116

move i/o stream classes inside octave namespace * c-file-ptr-stream.h, c-file-ptr-stream.cc, file-io.cc, oct-fstrm.cc, oct-fstrm.h, oct-iostrm.cc, oct-iostrm.h, oct-prcstrm.cc, oct-prcstrm.h, oct-procbuf.cc, oct-procbuf.h, oct-stdstrm.h, oct-stream.cc, oct-strstrm.cc, oct-strstrm.h, procstream.cc, procstream.h: Move classes inside octave namespace. Change all uses. Provide deprecated typedefs to preserve old names where possible.
author John W. Eaton <jwe@octave.org>
date Tue, 17 Aug 2021 11:17:36 -0400
parents 0a5b15007766
children 796f54d4ddbf
comparison
equal deleted inserted replaced
29990:b839c36fd106 29991:3988112c7116
31 #include <cstring> 31 #include <cstring>
32 32
33 #include "error.h" 33 #include "error.h"
34 #include "oct-fstrm.h" 34 #include "oct-fstrm.h"
35 35
36 octave::stream 36 OCTAVE_NAMESPACE_BEGIN
37 octave_fstream::create (const std::string& nm_arg, std::ios::openmode arg_md, 37
38 octave::mach_info::float_format ff) 38 stream
39 fstream::create (const std::string& nm_arg, std::ios::openmode arg_md,
40 mach_info::float_format ff)
39 { 41 {
40 return octave::stream (new octave_fstream (nm_arg, arg_md, ff)); 42 return stream (new fstream (nm_arg, arg_md, ff));
41 } 43 }
42 44
43 octave_fstream::octave_fstream (const std::string& nm_arg, 45 fstream::fstream (const std::string& nm_arg, std::ios::openmode arg_md,
44 std::ios::openmode arg_md, 46 mach_info::float_format ff)
45 octave::mach_info::float_format ff) 47 : base_stream (arg_md, ff), m_name (nm_arg)
46 : octave::base_stream (arg_md, ff), m_name (nm_arg)
47 { 48 {
48 m_fstream.open (m_name.c_str (), arg_md); 49 m_fstream.open (m_name.c_str (), arg_md);
49 50
50 if (! m_fstream) 51 if (! m_fstream)
51 // Note: error is inherited from octave::base_stream, not ::error. 52 // Note: error is inherited from base_stream, not ::error.
52 error (std::strerror (errno)); 53 error (std::strerror (errno));
53 } 54 }
54 55
55 // Position a stream at OFFSET relative to ORIGIN. 56 // Position a stream at OFFSET relative to ORIGIN.
56 57
57 int 58 int
58 octave_fstream::seek (off_t, int) 59 fstream::seek (off_t, int)
59 { 60 {
60 // Note: error is inherited from octave::base_stream, not ::error. 61 // Note: error is inherited from base_stream, not ::error.
61 // This error function does not halt execution so "return ..." must exist. 62 // This error function does not halt execution so "return ..." must exist.
62 error ("fseek: invalid_operation"); 63 error ("fseek: invalid_operation");
63 return -1; 64 return -1;
64 } 65 }
65 66
66 // Return current stream position. 67 // Return current stream position.
67 68
68 off_t 69 off_t
69 octave_fstream::tell (void) 70 fstream::tell (void)
70 { 71 {
71 // Note: error is inherited from octave::base_stream, not ::error. 72 // Note: error is inherited from base_stream, not ::error.
72 // This error function does not halt execution so "return ..." must exist. 73 // This error function does not halt execution so "return ..." must exist.
73 error ("ftell: invalid_operation"); 74 error ("ftell: invalid_operation");
74 return -1; 75 return -1;
75 } 76 }
76 77
77 // Return nonzero if EOF has been reached on this stream. 78 // Return nonzero if EOF has been reached on this stream.
78 79
79 bool 80 bool
80 octave_fstream::eof (void) const 81 fstream::eof (void) const
81 { 82 {
82 return m_fstream.eof (); 83 return m_fstream.eof ();
83 } 84 }
84 85
85 void 86 void
86 octave_fstream::do_close (void) 87 fstream::do_close (void)
87 { 88 {
88 m_fstream.close (); 89 m_fstream.close ();
89 } 90 }
90 91
91 std::istream * 92 std::istream *
92 octave_fstream::input_stream (void) 93 fstream::input_stream (void)
93 { 94 {
94 std::istream *retval = nullptr; 95 std::istream *retval = nullptr;
95 96
96 if (mode () & std::ios::in) 97 if (mode () & std::ios::in)
97 retval = &m_fstream; 98 retval = &m_fstream;
98 99
99 return retval; 100 return retval;
100 } 101 }
101 102
102 std::ostream * 103 std::ostream *
103 octave_fstream::output_stream (void) 104 fstream::output_stream (void)
104 { 105 {
105 std::ostream *retval = nullptr; 106 std::ostream *retval = nullptr;
106 107
107 if (mode () & std::ios::out) 108 if (mode () & std::ios::out)
108 retval = &m_fstream; 109 retval = &m_fstream;
109 110
110 return retval; 111 return retval;
111 } 112 }
113
114 OCTAVE_NAMESPACE_END