00001
00002
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 #ifndef header_file
00030 #define header_file
00031
00032 #include "iodevice.h"
00033 #include "bytearray.h"
00034
00035 class CL_SecurityDescriptor;
00036
00037 class CL_File : public CL_IODevice
00038 {
00040 public:
00041 enum AccessFlags
00042 {
00043 access_read = 1,
00044 access_write = 2
00045 };
00046
00047 enum ShareFlags
00048 {
00049 share_read = 1,
00050 share_write = 2,
00051 share_delete = 4,
00052 share_all = share_read + share_write + share_delete
00053 };
00054
00055 enum OpenMode
00056 {
00057 open_always,
00058 open_existing,
00059 open_existing_truncate
00060 };
00061
00062 enum CreateMode
00063 {
00064 create_always,
00065 create_new
00066 };
00067
00069 public:
00070 CL_File();
00071
00072 CL_File(
00073 const CL_String &filename,
00074 CreateMode mode,
00075 unsigned int access = access_read | access_write,
00076 unsigned int share = share_all);
00077
00078 CL_File(
00079 const CL_String &filename,
00080 CreateMode mode,
00081 const CL_SecurityDescriptor &permissions,
00082 unsigned int access = access_read | access_write,
00083 unsigned int share = share_all);
00084
00085 CL_File(
00086 const CL_String &filename,
00087 OpenMode mode = open_existing,
00088 unsigned int access = access_read | access_write,
00089 unsigned int share = share_all);
00090
00091 CL_File(
00092 const CL_String &filename,
00093 OpenMode mode,
00094 const CL_SecurityDescriptor &permissions,
00095 unsigned int access = access_read | access_write,
00096 unsigned int share = share_all);
00097
00098 ~CL_File();
00099
00101 public:
00102 int get_size() const;
00103
00104 int get_position() const;
00105
00106 CL_SecurityDescriptor get_permissions() const;
00107
00109 public:
00110 bool create(
00111 const CL_String &filename,
00112 CreateMode mode = create_always,
00113 unsigned int access = access_read | access_write,
00114 unsigned int share = share_all);
00115
00116 bool create(
00117 const CL_String &filename,
00118 CreateMode mode,
00119 const CL_SecurityDescriptor &permissions,
00120 unsigned int access = access_read | access_write,
00121 unsigned int share = share_all);
00122
00123 bool open(
00124 const CL_String &filename,
00125 OpenMode mode = open_existing,
00126 unsigned int access = access_read | access_write,
00127 unsigned int share = share_all);
00128
00129 bool open(
00130 const CL_String &filename,
00131 OpenMode mode,
00132 const CL_SecurityDescriptor &permissions,
00133 unsigned int access = access_read | access_write,
00134 unsigned int share = share_all);
00135
00136 void close();
00137
00138 bool set_permissions(const CL_SecurityDescriptor &permissions);
00139
00140 int read(void *buffer, int size, bool read_all = true);
00141
00142 int write(const void *buffer, int size, bool write_all = true);
00143
00144 int send(const void *data, int len, bool send_all = true);
00145
00146 int receive(void *data, int len, bool receive_all = true);
00147
00148 int peek(void *data, int len);
00149
00150 bool seek(int position, SeekMode mode = seek_set);
00151
00153 private:
00154 int lowlevel_read(void *buffer, int size, bool read_all);
00155
00156 #ifdef WIN32
00157 HANDLE handle;
00158 #else
00159 int handle;
00160 #endif
00161 CL_ByteArray peeked_data;
00162 };
00163
00164 #endif