Panda3D
 All Classes Functions Variables Enumerations
pandaFileStream.h
00001 // Filename: pandaFileStream.h
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 #ifndef PANDAFILESTREAM_H
00016 #define PANDAFILESTREAM_H
00017 
00018 #include "dtoolbase.h"
00019 
00020 #ifdef USE_PANDAFILESTREAM
00021 
00022 #include "pandaFileStreamBuf.h"
00023 
00024 ////////////////////////////////////////////////////////////////////
00025 //       Class : IFileStream
00026 // Description : Implements a C++ stream object suitable for reading
00027 //               from files on disk.  This is similar to ifstream, but
00028 //               it provides low-level support for Panda's
00029 //               simple-threading implementation (using this interface
00030 //               will block only the current thread, rather than the
00031 //               entire process, on I/O waits).
00032 ////////////////////////////////////////////////////////////////////
00033 class EXPCL_DTOOL IFileStream : public istream {
00034 PUBLISHED:
00035   INLINE IFileStream();
00036   INLINE IFileStream(const char *filename, ios::openmode mode = ios::in);
00037   INLINE ~IFileStream();
00038 
00039   INLINE void open(const char *filename, ios::openmode mode = ios::in);
00040 
00041 public:
00042 #ifdef _WIN32
00043   INLINE void attach(const char *filename, HANDLE handle, ios::openmode mode = ios::in);
00044 #else
00045   INLINE void attach(const char *filename, int fd, ios::openmode mode = ios::in);
00046 #endif
00047 
00048 PUBLISHED:
00049   INLINE void close();
00050 
00051 private:
00052   PandaFileStreamBuf _buf;
00053 };
00054 
00055 ////////////////////////////////////////////////////////////////////
00056 //       Class : OFileStream
00057 // Description : Implements a C++ stream object suitable for writing
00058 //               to files on disk.  This is similar to ofstream, but
00059 //               it provides low-level support for Panda's
00060 //               simple-threading implementation (using this interface
00061 //               will block only the current thread, rather than the
00062 //               entire process, on I/O waits).
00063 ////////////////////////////////////////////////////////////////////
00064 class EXPCL_DTOOL OFileStream : public ostream {
00065 PUBLISHED:
00066   INLINE OFileStream();
00067   INLINE OFileStream(const char *filename, ios::openmode mode = ios::out);
00068   INLINE ~OFileStream();
00069 
00070   INLINE void open(const char *filename, ios::openmode mode = ios::out);
00071 
00072 public:
00073 #ifdef _WIN32
00074   INLINE void attach(const char *filename, HANDLE handle, ios::openmode mode = ios::out);
00075 #else
00076   INLINE void attach(const char *filename, int fd, ios::openmode mode = ios::out);
00077 #endif
00078 
00079 PUBLISHED:
00080   INLINE void close();
00081 
00082 private:
00083   PandaFileStreamBuf _buf;
00084 };
00085 
00086 ////////////////////////////////////////////////////////////////////
00087 //       Class : FileStream
00088 // Description : Implements a C++ stream object suitable for reading
00089 //               from and/or writing to files on disk.  This is
00090 //               similar to fstream, but it provides low-level support
00091 //               for Panda's simple-threading implementation (using
00092 //               this interface will block only the current thread,
00093 //               rather than the entire process, on I/O waits).
00094 ////////////////////////////////////////////////////////////////////
00095 class EXPCL_DTOOL FileStream : public iostream {
00096 PUBLISHED:
00097   INLINE FileStream();
00098   INLINE FileStream(const char *filename, ios::openmode mode = ios::in);
00099   INLINE ~FileStream();
00100 
00101   INLINE void open(const char *filename, ios::openmode mode = ios::in);
00102 
00103 public:
00104 #ifdef _WIN32
00105   INLINE void attach(const char *filename, HANDLE handle, ios::openmode mode);
00106 #else
00107   INLINE void attach(const char *filename, int fd, ios::openmode mode);
00108 #endif
00109 
00110 PUBLISHED:
00111   INLINE void close();
00112 
00113 private:
00114   PandaFileStreamBuf _buf;
00115 };
00116 
00117 #include "pandaFileStream.I"
00118 
00119 typedef IFileStream pifstream;
00120 typedef OFileStream pofstream;
00121 typedef FileStream pfstream;
00122 
00123 #else   // USE_PANDAFILESTREAM
00124 
00125 typedef ifstream pifstream;
00126 typedef ofstream pofstream;
00127 typedef fstream pfstream;
00128 
00129 #endif  // USE_PANDAFILESTREAM
00130 
00131 #endif
 All Classes Functions Variables Enumerations