| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305 |
- // Filename: pandaFileStream.I
- // Created by: drose (08Sep08)
- //
- ////////////////////////////////////////////////////////////////////
- //
- // PANDA 3D SOFTWARE
- // Copyright (c) Carnegie Mellon University. All rights reserved.
- //
- // All use of this software is subject to the terms of the revised BSD
- // license. You should have received a copy of this license along
- // with this source code in a file named "LICENSE."
- //
- ////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////
- // Function: IFileStream::Constructor
- // Access: Published
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE IFileStream::
- IFileStream() : istream(&_buf) {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: IFileStream::Constructor
- // Access: Published
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE IFileStream::
- IFileStream(const char *filename, ios::openmode mode) : istream(&_buf) {
- open(filename, mode);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: IFileStream::Destructor
- // Access: Published
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE IFileStream::
- ~IFileStream() {
- close();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: IFileStream::open
- // Access: Published
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE void IFileStream::
- open(const char *filename, ios::openmode mode) {
- clear((ios_iostate)0);
- _buf.open(filename, mode);
- if (!_buf.is_open()) {
- clear(ios::failbit);
- }
- }
- #ifdef _WIN32
- ////////////////////////////////////////////////////////////////////
- // Function: IFileStream::attach
- // Access: Public
- // Description: Connects the file stream to the existing OS-defined
- // stream, presumably opened via a low-level OS call.
- // The filename is for reporting only. When the file
- // stream is closed, it will also close the underlying
- // OS handle.
- //
- // This function is the Windows-specific variant.
- ////////////////////////////////////////////////////////////////////
- void IFileStream::
- attach(const char *filename, HANDLE handle, ios::openmode mode) {
- clear((ios_iostate)0);
- _buf.attach(filename, handle, mode);
- if (!_buf.is_open()) {
- clear(ios::failbit);
- }
- }
- #endif // _WIN32
- #ifndef _WIN32
- ////////////////////////////////////////////////////////////////////
- // Function: IFileStream::attach
- // Access: Public
- // Description: Connects the file stream to the existing OS-defined
- // stream, presumably opened via a low-level OS call.
- // The filename is for reporting only. When the file
- // stream is closed, it will also close the underlying
- // OS handle.
- //
- // This function is the Posix-specific variant.
- ////////////////////////////////////////////////////////////////////
- void IFileStream::
- attach(const char *filename, int fd, ios::openmode mode) {
- clear((ios_iostate)0);
- _buf.attach(filename, fd, mode);
- if (!_buf.is_open()) {
- clear(ios::failbit);
- }
- }
- #endif // _WIN32
- ////////////////////////////////////////////////////////////////////
- // Function: IFileStream::close
- // Access: Published
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE void IFileStream::
- close() {
- _buf.close();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: OFileStream::Constructor
- // Access: Published
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE OFileStream::
- OFileStream() : ostream(&_buf) {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: OFileStream::Constructor
- // Access: Published
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE OFileStream::
- OFileStream(const char *filename, ios::openmode mode) : ostream(&_buf) {
- open(filename, mode);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: OFileStream::Destructor
- // Access: Published
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE OFileStream::
- ~OFileStream() {
- close();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: OFileStream::open
- // Access: Published
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE void OFileStream::
- open(const char *filename, ios::openmode mode) {
- clear((ios_iostate)0);
- _buf.open(filename, mode);
- if (!_buf.is_open()) {
- clear(ios::failbit);
- }
- }
- #ifdef _WIN32
- ////////////////////////////////////////////////////////////////////
- // Function: OFileStream::attach
- // Access: Public
- // Description: Connects the file stream to the existing OS-defined
- // stream, presumably opened via a low-level OS call.
- // The filename is for reporting only. When the file
- // stream is closed, it will also close the underlying
- // OS handle.
- //
- // This function is the Windows-specific variant.
- ////////////////////////////////////////////////////////////////////
- void OFileStream::
- attach(const char *filename, HANDLE handle, ios::openmode mode) {
- clear((ios_iostate)0);
- _buf.attach(filename, handle, mode);
- if (!_buf.is_open()) {
- clear(ios::failbit);
- }
- }
- #endif // _WIN32
- #ifndef _WIN32
- ////////////////////////////////////////////////////////////////////
- // Function: OFileStream::attach
- // Access: Public
- // Description: Connects the file stream to the existing OS-defined
- // stream, presumably opened via a low-level OS call.
- // The filename is for reporting only. When the file
- // stream is closed, it will also close the underlying
- // OS handle.
- //
- // This function is the Posix-specific variant.
- ////////////////////////////////////////////////////////////////////
- void OFileStream::
- attach(const char *filename, int fd, ios::openmode mode) {
- clear((ios_iostate)0);
- _buf.attach(filename, fd, mode);
- if (!_buf.is_open()) {
- clear(ios::failbit);
- }
- }
- #endif // _WIN32
- ////////////////////////////////////////////////////////////////////
- // Function: OFileStream::close
- // Access: Published
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE void OFileStream::
- close() {
- _buf.close();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: FileStream::Constructor
- // Access: Published
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE FileStream::
- FileStream() : iostream(&_buf) {
- }
- ////////////////////////////////////////////////////////////////////
- // Function: FileStream::Constructor
- // Access: Published
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE FileStream::
- FileStream(const char *filename, ios::openmode mode) : iostream(&_buf) {
- open(filename, mode);
- }
- ////////////////////////////////////////////////////////////////////
- // Function: FileStream::Destructor
- // Access: Published
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE FileStream::
- ~FileStream() {
- close();
- }
- ////////////////////////////////////////////////////////////////////
- // Function: FileStream::open
- // Access: Published
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE void FileStream::
- open(const char *filename, ios::openmode mode) {
- clear((ios_iostate)0);
- _buf.open(filename, mode);
- if (!_buf.is_open()) {
- clear(ios::failbit);
- }
- }
- #ifdef _WIN32
- ////////////////////////////////////////////////////////////////////
- // Function: FileStream::attach
- // Access: Public
- // Description: Connects the file stream to the existing OS-defined
- // stream, presumably opened via a low-level OS call.
- // The filename is for reporting only. When the file
- // stream is closed, it will also close the underlying
- // OS handle.
- //
- // This function is the Windows-specific variant.
- ////////////////////////////////////////////////////////////////////
- void FileStream::
- attach(const char *filename, HANDLE handle, ios::openmode mode) {
- clear((ios_iostate)0);
- _buf.attach(filename, handle, mode);
- if (!_buf.is_open()) {
- clear(ios::failbit);
- }
- }
- #endif // _WIN32
- #ifndef _WIN32
- ////////////////////////////////////////////////////////////////////
- // Function: FileStream::attach
- // Access: Public
- // Description: Connects the file stream to the existing OS-defined
- // stream, presumably opened via a low-level OS call.
- // The filename is for reporting only. When the file
- // stream is closed, it will also close the underlying
- // OS handle.
- //
- // This function is the Posix-specific variant.
- ////////////////////////////////////////////////////////////////////
- void FileStream::
- attach(const char *filename, int fd, ios::openmode mode) {
- clear((ios_iostate)0);
- _buf.attach(filename, fd, mode);
- if (!_buf.is_open()) {
- clear(ios::failbit);
- }
- }
- #endif // _WIN32
- ////////////////////////////////////////////////////////////////////
- // Function: FileStream::close
- // Access: Published
- // Description:
- ////////////////////////////////////////////////////////////////////
- INLINE void FileStream::
- close() {
- _buf.close();
- }
|