00001 #ifndef GSGL_DATA_FSTREAM_H
00002 #define GSGL_DATA_FSTREAM_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "data/data.hpp"
00038 #include "data/string.hpp"
00039 #include "data/stream.hpp"
00040
00041 namespace gsgl
00042 {
00043
00044 class string;
00045
00046 namespace io
00047 {
00048
00049
00050 enum open_mode
00051 {
00052 FILE_OPEN_READ = 1 << 0,
00053 FILE_OPEN_WRITE = 1 << 1,
00054 FILE_OPEN_APPEND = 1 << 2,
00055 FILE_OPEN_TEXT = 1 << 3,
00056 FILE_OPEN_BINARY = 1 << 4
00057 };
00058
00059
00060
00061 class DATA_API file_stream
00062 : public data_object
00063 {
00064 protected:
00065 gsgl::string fname;
00066
00067 void *fp;
00068 int mode;
00069
00070 file_stream(void *fp, gsgl::flags_t mode);
00071
00072 bool at_end() const;
00073
00074 public:
00075 file_stream(const gsgl::string & fname, gsgl::flags_t mode = FILE_OPEN_READ);
00076 virtual ~file_stream();
00077
00078 const gsgl::string & get_fname() const { return fname; }
00079 };
00080
00081
00082
00083 class DATA_API ft_stream
00084 : public file_stream, public text_stream
00085 {
00086 ft_stream(void *fp, gsgl::flags_t mode);
00087 public:
00088 ft_stream(const gsgl::string & fname, gsgl::flags_t mode = FILE_OPEN_READ);
00089 virtual ~ft_stream();
00090
00091 wchar_t peek();
00092 wchar_t get();
00093 void unget(wchar_t);
00094 bool at_end() const;
00095
00096 gsgl::index_t read(wchar_t *, const gsgl::index_t);
00097 gsgl::index_t write(const wchar_t *, const gsgl::index_t);
00098
00099 static ft_stream out;
00100 static ft_stream err;
00101 static ft_stream in;
00102 };
00103
00104
00105
00106 class DATA_API fd_stream
00107 : public file_stream, public data_stream
00108 {
00109 public:
00110 fd_stream(const gsgl::string & fname, gsgl::flags_t mode = FILE_OPEN_READ);
00111 virtual ~fd_stream();
00112
00113 bool at_end() const;
00114
00115 gsgl::index_t read(unsigned char *, const gsgl::index_t);
00116 gsgl::index_t write(const unsigned char *, const gsgl::index_t);
00117 };
00118
00119 }
00120
00121 }
00122
00123 #endif