Panda3D
pandaFileStream.h
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.h
10  * @author drose
11  * @date 2008-09-08
12  */
13 
14 #ifndef PANDAFILESTREAM_H
15 #define PANDAFILESTREAM_H
16 
17 #include "dtoolbase.h"
18 
19 #ifdef USE_PANDAFILESTREAM
20 
21 #include "pandaFileStreamBuf.h"
22 
23 /**
24  * Implements a C++ stream object suitable for reading from files on disk.
25  * This is similar to ifstream, but it provides low-level support for Panda's
26  * simple-threading implementation (using this interface will block only the
27  * current thread, rather than the entire process, on I/O waits).
28  */
29 class EXPCL_DTOOL_DTOOLUTIL IFileStream : public std::istream {
30 PUBLISHED:
31  INLINE IFileStream();
32  INLINE explicit IFileStream(const char *filename, std::ios::openmode mode = std::ios::in);
33  INLINE ~IFileStream();
34 
35  INLINE void open(const char *filename, std::ios::openmode mode = std::ios::in);
36 
37 public:
38 #ifdef _WIN32
39  INLINE void attach(const char *filename, HANDLE handle, std::ios::openmode mode = std::ios::in);
40 #else
41  INLINE void attach(const char *filename, int fd, std::ios::openmode mode = std::ios::in);
42 #endif
43 
44 PUBLISHED:
45  INLINE void close();
46 
47 private:
48  PandaFileStreamBuf _buf;
49 };
50 
51 /**
52  * Implements a C++ stream object suitable for writing to files on disk. This
53  * is similar to ofstream, but it provides low-level support for Panda's
54  * simple-threading implementation (using this interface will block only the
55  * current thread, rather than the entire process, on I/O waits).
56  */
57 class EXPCL_DTOOL_DTOOLUTIL OFileStream : public std::ostream {
58 PUBLISHED:
59  INLINE OFileStream();
60  INLINE explicit OFileStream(const char *filename, std::ios::openmode mode = std::ios::out);
61  INLINE ~OFileStream();
62 
63  INLINE void open(const char *filename, std::ios::openmode mode = std::ios::out);
64 
65 public:
66 #ifdef _WIN32
67  INLINE void attach(const char *filename, HANDLE handle, std::ios::openmode mode = std::ios::out);
68 #else
69  INLINE void attach(const char *filename, int fd, std::ios::openmode mode = std::ios::out);
70 #endif
71 
72 PUBLISHED:
73  INLINE void close();
74 
75 private:
76  PandaFileStreamBuf _buf;
77 };
78 
79 /**
80  * Implements a C++ stream object suitable for reading from and/or writing to
81  * files on disk. This is similar to fstream, but it provides low-level
82  * support for Panda's simple-threading implementation (using this interface
83  * will block only the current thread, rather than the entire process, on I/O
84  * waits).
85  */
86 class EXPCL_DTOOL_DTOOLUTIL FileStream : public std::iostream {
87 PUBLISHED:
88  INLINE FileStream();
89  INLINE explicit FileStream(const char *filename, std::ios::openmode mode = std::ios::in);
90  INLINE ~FileStream();
91 
92  INLINE void open(const char *filename, std::ios::openmode mode = std::ios::in);
93 
94 public:
95 #ifdef _WIN32
96  INLINE void attach(const char *filename, HANDLE handle, std::ios::openmode mode);
97 #else
98  INLINE void attach(const char *filename, int fd, std::ios::openmode mode);
99 #endif
100 
101 PUBLISHED:
102  INLINE void close();
103 
104 private:
105  PandaFileStreamBuf _buf;
106 };
107 
108 #include "pandaFileStream.I"
109 
110 typedef IFileStream pifstream;
111 typedef OFileStream pofstream;
112 typedef FileStream pfstream;
113 
114 #else // USE_PANDAFILESTREAM
115 
116 typedef ifstream pifstream;
117 typedef ofstream pofstream;
118 typedef fstream pfstream;
119 
120 #endif // USE_PANDAFILESTREAM
121 
122 #endif
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.