Panda3D
pandaFileStream.I
Go to the documentation of this file.
1 /**
2  * PANDA 3D SOFTWARE
3  * Copyright (c) Carnegie Mellon University. All rights reserved.
4  *
5  * All use of this software is subject to the terms of the revised BSD
6  * license. You should have received a copy of this license along
7  * with this source code in a file named "LICENSE."
8  *
9  * @file pandaFileStream.I
10  * @author drose
11  * @date 2008-09-08
12  */
13 
14 /**
15  *
16  */
17 INLINE IFileStream::
18 IFileStream() : std::istream(&_buf) {
19 }
20 
21 /**
22  *
23  */
24 INLINE IFileStream::
25 IFileStream(const char *filename, std::ios::openmode mode) : std::istream(&_buf) {
26  open(filename, mode);
27 }
28 
29 /**
30  *
31  */
32 INLINE IFileStream::
33 ~IFileStream() {
34  close();
35 }
36 
37 /**
38  *
39  */
40 INLINE void IFileStream::
41 open(const char *filename, std::ios::openmode mode) {
42  clear((ios_iostate)0);
43  _buf.open(filename, mode);
44  if (!_buf.is_open()) {
45  clear(std::ios::failbit);
46  }
47 }
48 
49 #ifdef _WIN32
50 /**
51  * Connects the file stream to the existing OS-defined stream, presumably
52  * opened via a low-level OS call. The filename is for reporting only. When
53  * the file stream is closed, it will also close the underlying OS handle.
54  *
55  * This function is the Windows-specific variant.
56  */
57 void IFileStream::
58 attach(const char *filename, HANDLE handle, std::ios::openmode mode) {
59  clear((ios_iostate)0);
60  _buf.attach(filename, handle, mode);
61  if (!_buf.is_open()) {
62  clear(std::ios::failbit);
63  }
64 }
65 #endif // _WIN32
66 
67 #ifndef _WIN32
68 /**
69  * Connects the file stream to the existing OS-defined stream, presumably
70  * opened via a low-level OS call. The filename is for reporting only. When
71  * the file stream is closed, it will also close the underlying OS handle.
72  *
73  * This function is the Posix-specific variant.
74  */
75 void IFileStream::
76 attach(const char *filename, int fd, std::ios::openmode mode) {
77  clear((ios_iostate)0);
78  _buf.attach(filename, fd, mode);
79  if (!_buf.is_open()) {
80  clear(std::ios::failbit);
81  }
82 }
83 #endif // _WIN32
84 
85 /**
86  *
87  */
88 INLINE void IFileStream::
89 close() {
90  _buf.close();
91 }
92 
93 /**
94  *
95  */
96 INLINE OFileStream::
97 OFileStream() : std::ostream(&_buf) {
98 }
99 
100 /**
101  *
102  */
103 INLINE OFileStream::
104 OFileStream(const char *filename, std::ios::openmode mode) : std::ostream(&_buf) {
105  open(filename, mode);
106 }
107 
108 /**
109  *
110  */
111 INLINE OFileStream::
112 ~OFileStream() {
113  close();
114 }
115 
116 /**
117  *
118  */
119 INLINE void OFileStream::
120 open(const char *filename, std::ios::openmode mode) {
121  clear((ios_iostate)0);
122  _buf.open(filename, mode);
123  if (!_buf.is_open()) {
124  clear(std::ios::failbit);
125  }
126 }
127 
128 #ifdef _WIN32
129 /**
130  * Connects the file stream to the existing OS-defined stream, presumably
131  * opened via a low-level OS call. The filename is for reporting only. When
132  * the file stream is closed, it will also close the underlying OS handle.
133  *
134  * This function is the Windows-specific variant.
135  */
136 void OFileStream::
137 attach(const char *filename, HANDLE handle, std::ios::openmode mode) {
138  clear((ios_iostate)0);
139  _buf.attach(filename, handle, mode);
140  if (!_buf.is_open()) {
141  clear(std::ios::failbit);
142  }
143 }
144 #endif // _WIN32
145 
146 #ifndef _WIN32
147 /**
148  * Connects the file stream to the existing OS-defined stream, presumably
149  * opened via a low-level OS call. The filename is for reporting only. When
150  * the file stream is closed, it will also close the underlying OS handle.
151  *
152  * This function is the Posix-specific variant.
153  */
154 void OFileStream::
155 attach(const char *filename, int fd, std::ios::openmode mode) {
156  clear((ios_iostate)0);
157  _buf.attach(filename, fd, mode);
158  if (!_buf.is_open()) {
159  clear(std::ios::failbit);
160  }
161 }
162 #endif // _WIN32
163 
164 /**
165  *
166  */
167 INLINE void OFileStream::
168 close() {
169  _buf.close();
170 }
171 
172 /**
173  *
174  */
175 INLINE FileStream::
176 FileStream() : std::iostream(&_buf) {
177 }
178 
179 /**
180  *
181  */
182 INLINE FileStream::
183 FileStream(const char *filename, std::ios::openmode mode) : std::iostream(&_buf) {
184  open(filename, mode);
185 }
186 
187 /**
188  *
189  */
190 INLINE FileStream::
191 ~FileStream() {
192  close();
193 }
194 
195 /**
196  *
197  */
198 INLINE void FileStream::
199 open(const char *filename, std::ios::openmode mode) {
200  clear((ios_iostate)0);
201  _buf.open(filename, mode);
202  if (!_buf.is_open()) {
203  clear(std::ios::failbit);
204  }
205 }
206 
207 #ifdef _WIN32
208 /**
209  * Connects the file stream to the existing OS-defined stream, presumably
210  * opened via a low-level OS call. The filename is for reporting only. When
211  * the file stream is closed, it will also close the underlying OS handle.
212  *
213  * This function is the Windows-specific variant.
214  */
215 void FileStream::
216 attach(const char *filename, HANDLE handle, std::ios::openmode mode) {
217  clear((ios_iostate)0);
218  _buf.attach(filename, handle, mode);
219  if (!_buf.is_open()) {
220  clear(std::ios::failbit);
221  }
222 }
223 #endif // _WIN32
224 
225 #ifndef _WIN32
226 /**
227  * Connects the file stream to the existing OS-defined stream, presumably
228  * opened via a low-level OS call. The filename is for reporting only. When
229  * the file stream is closed, it will also close the underlying OS handle.
230  *
231  * This function is the Posix-specific variant.
232  */
233 void FileStream::
234 attach(const char *filename, int fd, std::ios::openmode mode) {
235  clear((ios_iostate)0);
236  _buf.attach(filename, fd, mode);
237  if (!_buf.is_open()) {
238  clear(std::ios::failbit);
239  }
240 }
241 #endif // _WIN32
242 
243 /**
244  *
245  */
246 INLINE void FileStream::
247 close() {
248  _buf.close();
249 }