00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00034 #ifndef ALP_FILESTREAM_H
00035 #define ALP_FILESTREAM_H
00036
00037
00038 #include <stdio.h>
00039 #include <string>
00040
00041
00042 namespace alp {
00043
00044
00045 class FileStream
00046 {
00047 public:
00048 enum openmode
00049 {
00050 app = 0x01,
00051 ate = 0x02,
00052 binary = 0x04,
00053 in = 0x08,
00054 out = 0x10,
00055 trunc = 0x20
00056 };
00057 enum iostate
00058 {
00059 goodbit = 0x00,
00060 badbit = 0x01,
00061 eofbit = 0x02,
00062 failbit = 0x04
00063 };
00064
00065 FileStream();
00066 FileStream(const char* path, int mode);
00067 FileStream(const std::string& path, int mode);
00068 ~FileStream();
00069
00070 void open(const char* path, int mode);
00071 void open(const std::string& path, int mode);
00072 void close();
00073
00074 FileStream& getline(char* s, size_t size);
00075 FileStream& getline(char* s, size_t size, char delim);
00076 FileStream& getline(std::string& s);
00077 FileStream& getline(std::string& s, char delim);
00078
00079 FileStream& read(char* s, size_t size);
00080 FileStream& write(const char* s, size_t size);
00081
00082 bool eof();
00083 bool good();
00084 int openmode();
00085 int rdstate();
00086 void clear(int state = goodbit);
00087
00088 private:
00089 bool getlinechar(int& c, char delim);
00090 void getlinecheck(int& c, char delim);
00091
00092 FILE* fHandle;
00093 uint8_t fOpenMode;
00094 uint8_t fState;
00095 };
00096
00097
00098
00099 inline FileStream& getline(FileStream& fs, std::string& s) { return fs.getline(s); }
00100 inline FileStream& getline(FileStream& fs, std::string& s, char delim) { return fs.getline(s, delim); }
00101
00102 FileStream& operator<<(FileStream& fs, const char* s);
00103 FileStream& operator<<(FileStream& fs, const std::string& s);
00104 FileStream& operator<<(FileStream& fs, int i);
00105
00106 }
00107
00108
00109 #endif // ALP_FILESTREAM_H