Panda3D
 All Classes Functions Variables Enumerations
pandaFileStream.I
00001 // Filename: pandaFileStream.I
00002 // Created by:  drose (08Sep08)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) Carnegie Mellon University.  All rights reserved.
00008 //
00009 // All use of this software is subject to the terms of the revised BSD
00010 // license.  You should have received a copy of this license along
00011 // with this source code in a file named "LICENSE."
00012 //
00013 ////////////////////////////////////////////////////////////////////
00014 
00015 
00016 ////////////////////////////////////////////////////////////////////
00017 //     Function: IFileStream::Constructor
00018 //       Access: Published
00019 //  Description:
00020 ////////////////////////////////////////////////////////////////////
00021 INLINE IFileStream::
00022 IFileStream() : istream(&_buf) {
00023 }
00024 
00025 ////////////////////////////////////////////////////////////////////
00026 //     Function: IFileStream::Constructor
00027 //       Access: Published
00028 //  Description:
00029 ////////////////////////////////////////////////////////////////////
00030 INLINE IFileStream::
00031 IFileStream(const char *filename, ios::openmode mode) : istream(&_buf) {
00032   open(filename, mode);
00033 }
00034 
00035 ////////////////////////////////////////////////////////////////////
00036 //     Function: IFileStream::Destructor
00037 //       Access: Published
00038 //  Description:
00039 ////////////////////////////////////////////////////////////////////
00040 INLINE IFileStream::
00041 ~IFileStream() {
00042   close();
00043 }
00044 
00045 ////////////////////////////////////////////////////////////////////
00046 //     Function: IFileStream::open
00047 //       Access: Published
00048 //  Description: 
00049 ////////////////////////////////////////////////////////////////////
00050 INLINE void IFileStream::
00051 open(const char *filename, ios::openmode mode) {
00052   clear((ios_iostate)0);
00053   _buf.open(filename, mode);
00054   if (!_buf.is_open()) {
00055     clear(ios::failbit);
00056   }
00057 }
00058 
00059 #ifdef _WIN32
00060 ////////////////////////////////////////////////////////////////////
00061 //     Function: IFileStream::attach
00062 //       Access: Public
00063 //  Description: Connects the file stream to the existing OS-defined
00064 //               stream, presumably opened via a low-level OS call.
00065 //               The filename is for reporting only.  When the file
00066 //               stream is closed, it will also close the underlying
00067 //               OS handle.
00068 //
00069 //               This function is the Windows-specific variant.
00070 ////////////////////////////////////////////////////////////////////
00071 void IFileStream::
00072 attach(const char *filename, HANDLE handle, ios::openmode mode) {
00073   clear((ios_iostate)0);
00074   _buf.attach(filename, handle, mode);
00075   if (!_buf.is_open()) {
00076     clear(ios::failbit);
00077   }
00078 }
00079 #endif  // _WIN32
00080 
00081 #ifndef _WIN32
00082 ////////////////////////////////////////////////////////////////////
00083 //     Function: IFileStream::attach
00084 //       Access: Public
00085 //  Description: Connects the file stream to the existing OS-defined
00086 //               stream, presumably opened via a low-level OS call.
00087 //               The filename is for reporting only.  When the file
00088 //               stream is closed, it will also close the underlying
00089 //               OS handle.
00090 //
00091 //               This function is the Posix-specific variant.
00092 ////////////////////////////////////////////////////////////////////
00093 void IFileStream::
00094 attach(const char *filename, int fd, ios::openmode mode) {
00095   clear((ios_iostate)0);
00096   _buf.attach(filename, fd, mode);
00097   if (!_buf.is_open()) {
00098     clear(ios::failbit);
00099   }
00100 }
00101 #endif  // _WIN32
00102 
00103 ////////////////////////////////////////////////////////////////////
00104 //     Function: IFileStream::close
00105 //       Access: Published
00106 //  Description: 
00107 ////////////////////////////////////////////////////////////////////
00108 INLINE void IFileStream::
00109 close() {
00110   _buf.close();
00111 }
00112 
00113 ////////////////////////////////////////////////////////////////////
00114 //     Function: OFileStream::Constructor
00115 //       Access: Published
00116 //  Description:
00117 ////////////////////////////////////////////////////////////////////
00118 INLINE OFileStream::
00119 OFileStream() : ostream(&_buf) {
00120 }
00121 
00122 ////////////////////////////////////////////////////////////////////
00123 //     Function: OFileStream::Constructor
00124 //       Access: Published
00125 //  Description:
00126 ////////////////////////////////////////////////////////////////////
00127 INLINE OFileStream::
00128 OFileStream(const char *filename, ios::openmode mode) : ostream(&_buf) {
00129   open(filename, mode);
00130 }
00131 
00132 ////////////////////////////////////////////////////////////////////
00133 //     Function: OFileStream::Destructor
00134 //       Access: Published
00135 //  Description:
00136 ////////////////////////////////////////////////////////////////////
00137 INLINE OFileStream::
00138 ~OFileStream() {
00139   close();
00140 }
00141 
00142 ////////////////////////////////////////////////////////////////////
00143 //     Function: OFileStream::open
00144 //       Access: Published
00145 //  Description: 
00146 ////////////////////////////////////////////////////////////////////
00147 INLINE void OFileStream::
00148 open(const char *filename, ios::openmode mode) {
00149   clear((ios_iostate)0);
00150   _buf.open(filename, mode);
00151   if (!_buf.is_open()) {
00152     clear(ios::failbit);
00153   }
00154 }
00155 
00156 #ifdef _WIN32
00157 ////////////////////////////////////////////////////////////////////
00158 //     Function: OFileStream::attach
00159 //       Access: Public
00160 //  Description: Connects the file stream to the existing OS-defined
00161 //               stream, presumably opened via a low-level OS call.
00162 //               The filename is for reporting only.  When the file
00163 //               stream is closed, it will also close the underlying
00164 //               OS handle.
00165 //
00166 //               This function is the Windows-specific variant.
00167 ////////////////////////////////////////////////////////////////////
00168 void OFileStream::
00169 attach(const char *filename, HANDLE handle, ios::openmode mode) {
00170   clear((ios_iostate)0);
00171   _buf.attach(filename, handle, mode);
00172   if (!_buf.is_open()) {
00173     clear(ios::failbit);
00174   }
00175 }
00176 #endif  // _WIN32
00177 
00178 #ifndef _WIN32
00179 ////////////////////////////////////////////////////////////////////
00180 //     Function: OFileStream::attach
00181 //       Access: Public
00182 //  Description: Connects the file stream to the existing OS-defined
00183 //               stream, presumably opened via a low-level OS call.
00184 //               The filename is for reporting only.  When the file
00185 //               stream is closed, it will also close the underlying
00186 //               OS handle.
00187 //
00188 //               This function is the Posix-specific variant.
00189 ////////////////////////////////////////////////////////////////////
00190 void OFileStream::
00191 attach(const char *filename, int fd, ios::openmode mode) {
00192   clear((ios_iostate)0);
00193   _buf.attach(filename, fd, mode);
00194   if (!_buf.is_open()) {
00195     clear(ios::failbit);
00196   }
00197 }
00198 #endif  // _WIN32
00199 
00200 ////////////////////////////////////////////////////////////////////
00201 //     Function: OFileStream::close
00202 //       Access: Published
00203 //  Description: 
00204 ////////////////////////////////////////////////////////////////////
00205 INLINE void OFileStream::
00206 close() {
00207   _buf.close();
00208 }
00209 
00210 ////////////////////////////////////////////////////////////////////
00211 //     Function: FileStream::Constructor
00212 //       Access: Published
00213 //  Description:
00214 ////////////////////////////////////////////////////////////////////
00215 INLINE FileStream::
00216 FileStream() : iostream(&_buf) {
00217 }
00218 
00219 ////////////////////////////////////////////////////////////////////
00220 //     Function: FileStream::Constructor
00221 //       Access: Published
00222 //  Description:
00223 ////////////////////////////////////////////////////////////////////
00224 INLINE FileStream::
00225 FileStream(const char *filename, ios::openmode mode) : iostream(&_buf) {
00226   open(filename, mode);
00227 }
00228 
00229 ////////////////////////////////////////////////////////////////////
00230 //     Function: FileStream::Destructor
00231 //       Access: Published
00232 //  Description:
00233 ////////////////////////////////////////////////////////////////////
00234 INLINE FileStream::
00235 ~FileStream() {
00236   close();
00237 }
00238 
00239 ////////////////////////////////////////////////////////////////////
00240 //     Function: FileStream::open
00241 //       Access: Published
00242 //  Description: 
00243 ////////////////////////////////////////////////////////////////////
00244 INLINE void FileStream::
00245 open(const char *filename, ios::openmode mode) {
00246   clear((ios_iostate)0);
00247   _buf.open(filename, mode);
00248   if (!_buf.is_open()) {
00249     clear(ios::failbit);
00250   }
00251 }
00252 
00253 #ifdef _WIN32
00254 ////////////////////////////////////////////////////////////////////
00255 //     Function: FileStream::attach
00256 //       Access: Public
00257 //  Description: Connects the file stream to the existing OS-defined
00258 //               stream, presumably opened via a low-level OS call.
00259 //               The filename is for reporting only.  When the file
00260 //               stream is closed, it will also close the underlying
00261 //               OS handle.
00262 //
00263 //               This function is the Windows-specific variant.
00264 ////////////////////////////////////////////////////////////////////
00265 void FileStream::
00266 attach(const char *filename, HANDLE handle, ios::openmode mode) {
00267   clear((ios_iostate)0);
00268   _buf.attach(filename, handle, mode);
00269   if (!_buf.is_open()) {
00270     clear(ios::failbit);
00271   }
00272 }
00273 #endif  // _WIN32
00274 
00275 #ifndef _WIN32
00276 ////////////////////////////////////////////////////////////////////
00277 //     Function: FileStream::attach
00278 //       Access: Public
00279 //  Description: Connects the file stream to the existing OS-defined
00280 //               stream, presumably opened via a low-level OS call.
00281 //               The filename is for reporting only.  When the file
00282 //               stream is closed, it will also close the underlying
00283 //               OS handle.
00284 //
00285 //               This function is the Posix-specific variant.
00286 ////////////////////////////////////////////////////////////////////
00287 void FileStream::
00288 attach(const char *filename, int fd, ios::openmode mode) {
00289   clear((ios_iostate)0);
00290   _buf.attach(filename, fd, mode);
00291   if (!_buf.is_open()) {
00292     clear(ios::failbit);
00293   }
00294 }
00295 #endif  // _WIN32
00296 
00297 ////////////////////////////////////////////////////////////////////
00298 //     Function: FileStream::close
00299 //       Access: Published
00300 //  Description: 
00301 ////////////////////////////////////////////////////////////////////
00302 INLINE void FileStream::
00303 close() {
00304   _buf.close();
00305 }
 All Classes Functions Variables Enumerations