acme
Foundational cross-platform layer of the ca2 framework
Loading...
Searching...
No Matches
file.h
1#pragma once
2
3
5//#include "acme/filesystem/filesystem/path.h"
6#include "streamable.h"
7
8
9namespace file
10{
11
12
13 enum enum_buffer
14 {
15
16 e_buffer_read,
17 e_buffer_write,
18 e_buffer_commit,
19 e_buffer_check
20
21 };
22
23
24 class exception;
25 struct file_status;
26
27 class file;
28
29
30 class CLASS_DECL_ACME file :
31 virtual public property_object,
32 virtual public streamable
33 {
34 public:
35
36
37 ::file::e_open m_eopen;
38 ::file::path m_path;
39 ::file::e_state m_estate;
40 class ::time m_timeErrorBlockTimeout;
41
42
43 file();
44 explicit file(const ::file::path & path);
45 ~file() override;
46
47
50
51
52 virtual ::i32_boolean is_end_of_file() const;
53 virtual void set_end_of_file();
54
55 inline bool _is_end_of_file() const { return is_end_of_file(); }
56
57 virtual bool is_in_memory_file() const;
58
59 virtual ::u8 * full_data_begin();
60
61 virtual ::u8 * full_data_end();
62
63 virtual const ::u8 * full_data_begin() const;
64
65 virtual const ::u8 * full_data_end() const;
66
67
68 inline ::block full_data(memsize start = 0, memsize count = -1)
69 {
70
71 return ::block(full_data_begin(), full_data_end())(start, count);
72
73 }
74
75
76 inline ::block full_data(memsize start = 0, memsize count = -1) const
77 {
78
79 return ::block(full_data_begin(), full_data_end())(start, count);
80
81 }
82
83
84 inline memsize full_data_size() const { return full_data_end() - full_data_begin(); }
85
86 inline bool full_data_is_set() const { return ::is_set(full_data_begin()); }
87
88
89 virtual ::u8 * data_begin();
90
91 virtual ::u8 * data_end();
92
93 virtual const ::u8 * data_begin() const;
94
95 virtual const ::u8 * data_end() const;
96
97
98 inline ::block data(memsize start = 0, memsize count = -1)
99 {
100
101 return ::block(data_begin(), data_end())(start, count);
102
103 }
104
105
106 inline ::block data(memsize start = 0, memsize count = -1) const
107 {
108
109 return ::block(data_begin(), data_end())(start, count);
110
111 }
112
113 inline memsize data_size() const { return data_end() - data_begin(); }
114
115 inline bool data_is_set() const { return ::is_set(data_begin()) && data_size() > 0; }
116
117
118 //virtual const void* get_internal_data() const;
119 //virtual memsize get_internal_data_size() const;
120
124 virtual bool full_data_set_size(memsize c);
125
126
130 virtual bool full_data_increase_size(memsize c);
131
132
133 void translate(filesize offset, ::enum_seek eseek) override;
134 virtual ::i32 getc();
135 virtual ::i32 ungetc(::i32 iChar);
136
137 inline filesize get_remaining_byte_count() const { return size() - get_position(); }
138
139 //memsize read(void* pdata, memsize nCount) override;
140
141 using ::file::readable::read;
142 memsize read(void * p, ::memsize s) override;
143
144
145 virtual filesize find(const void* pFind, memsize size, const filesize* limit);
146
147 ::filesize right_size() const override;
148
149
150 virtual ::memory as_memory();
151
152
153 template < typename TYPE >
154 void write_as_block(const TYPE & t) { write({ e_as_block, t }); }
155
156
157 using ::file::writable::write;
158 void write(const void * p, memsize s) override;
159
160 virtual void write_unsigned_char(::u8 uch);
161
163 memsize defer_write(const void * dataToWrite, memsize amountToWrite) override;
164
165
166 virtual void write(::file::readable * preader, memsize uiBufferSize = 16_MiB);
167 virtual void write_from_beginning(::file::streamable * preader, memsize uiBufSize = 16_MiB);
168
169 //void write(const void* pdata, memsize nCount) override;
170
171 //virtual void write(const void* pdata, memsize nCount, memsize* dwWritten);
172
173 //virtual void from(::file::file * preader, memsize uiBufferSize = 16 * 1024);
174 //virtual void from_begin(::file::file * preader, memsize uiBufSize = 16 * 1024);
175 //virtual void to(::file::file * pwriter, memsize uiBufferSize = 1024 * 1024);
176
177
179
180
181 ::file::file * get_file() override;
182
183
184 void abort() override;
185 void flush() override;
186 void close() override;
187
188
189 virtual file & put(::i8 ch);
190
191 virtual file & getline(char_pointer sz, character_count n);
192 //virtual ::i32 get();
193 //virtual ::i32 peek();
194 virtual bool read(char_pointer pch);
195 virtual bool read(::u8 * puch);
196 virtual bool peek(char_pointer pch);
197 virtual bool peek(::u8 * puch);
198 //virtual ::i32 sgetc();
199 //virtual ::i32 sbumpc();
200
201 virtual ::i32 peek_byte(); // 0-255 - -1 if eof otherwise exception?
202 virtual void put_byte_back(::u8 b);
203
204 virtual ::i32 get_unsigned_char(); // 0-255 - -1 if eof otherwise exception?
205 inline ::u8 get_byte_unbounded() { return get_unsigned_char(); }
206
207 virtual ::i32 get_unsigned_short(); // 0-255 - -1 if eof otherwise exception?
208 inline ::u16 get_u16_unbounded() { return get_unsigned_short(); }
209
210 virtual bool get_u64(::u64 & hn); // 0-255 - -1 if eof otherwise exception?
211 inline ::u64 get_u64_unbounded() { ::u64 ull; get_u64(ull); return ull; }
212
213
214 virtual bool unget_if(::ansi_character ch);
215
216 inline filesize _right_size() { return this->right_size(); }
217
218
219 virtual bool read_string(string & str);
220 virtual bool read_string(memory_base & mem);
221 virtual bool read_block(block & block);
222
223 //virtual ::memory right_memory();
224 //virtual void right_memory(memory_base & memory);
225 //virtual ::string right_string();
226 //virtual void right_string(::string & str);
227
228 virtual void print(const ::scoped_string & scopedstr);
229 virtual void println(const ::scoped_string & scopedstr);
230 virtual void printf(const_char_pointer format, ...);
231
233 virtual bool full_read(const ::block & block);
234
235 virtual void write_from_hex(const ::block & block);
236
237 virtual void set_storing();
238 virtual void set_loading();
239
240 virtual i32_boolean has_write_mode();
241
242 virtual file_status get_status() const;
243 virtual ::file::path get_file_path() const;
244 virtual void set_file_path(const ::file::path & path);
245
246
247 virtual void open(const ::file::path & path, ::file::e_open eopen, ::pointer < ::file::exception > * pfileexception = nullptr);
248
249
250 inline void open_for_reading(const ::file::path& path, ::file::e_open eopen =
251 ::file::e_open_binary, ::pointer < ::file::exception > * pfileexception = nullptr)
252 {
253
254 open(path, eopen | ::file::e_open_read);
255
256 }
257
258
259 virtual void open_for_writing(const ::file::path& path, ::file::e_open eopen =
260 ::file::e_open_binary | ::file::e_open_defer_create_directory, ::pointer < ::file::exception > * pfileexception = nullptr)
261 {
262
263 open(path, eopen | ::file::e_open_write);
264
265 }
266
267
268 ::file::fmtflags flags() const;
269
270 ::file::fmtflags flags(::file::fmtflags flags);
271
272
273 //virtual filesize seek_begin(filesize lPos = 0);
274 void set_size(filesize dwNewLen) override;
275 filesize size() const override;
276 inline bool is_empty() const { return size() <= 0; }
277 inline bool has_data() const { return size() > 0; }
278 inline void clear() { set_size(0); }
279
280 virtual void lock(filesize dwPos, filesize dwCount);
281 virtual void unlock(filesize dwPos, filesize dwCount);
282
283
284 virtual string get_location() const;
285
286
287 virtual bool is_valid() const;
288 virtual bool is_opened() const;
289
290
291 virtual void put_lines(const string_array_base& stra);
292
293 virtual class ::time modification_time();
294 virtual void set_modification_time(const class ::time & time);
295
296
297 };
298
299
300 CLASS_DECL_ACME void set_no_cache(::payload& payload);
301 CLASS_DECL_ACME ::i32_boolean get_no_cache(const ::payload & payload);
302
303
304 } // namespace file
305
306
307
Definition exception.h:13
Definition file.h:33
void flush() override
Definition file.cpp:192
virtual bool full_read(const ::block &block)
virtual void write(const string &);
Definition file.cpp:273
virtual bool full_data_increase_size(memsize c)
full_data is plain memory segment mapping entire file
Definition file.cpp:875
virtual void open(const ::file::path &path, ::file::e_open eopen, ::pointer< ::file::exception > *pfileexception=nullptr)
Definition file.cpp:109
memsize defer_write(const void *dataToWrite, memsize amountToWrite) override
Definition file.cpp:1125
::file::file * get_file() override
virtual void read_file(file::file * pwriter, memsize uiBufferSize = 1024 * 1024);
Definition file.cpp:1155
virtual bool full_data_set_size(memsize c)
full_data is plain memory segment mapping entire file
Definition file.cpp:867
Definition path.h:52
::memsize defer_write(const void *p, ::memsize s) override
Definition streamable.cpp:81
Definition boolean.h:7
Definition memory_base.h:92
Definition payload.h:54
Definition aaa_time.h:13
Definition filesystem.h:16
Definition block.h:46
Definition status.h:12