14 #ifndef __INCLUDED_SCOPIRA_TOOL_CACHEFLOW_H__ 15 #define __INCLUDED_SCOPIRA_TOOL_CACHEFLOW_H__ 17 #include <scopira/tool/array.h> 18 #include <scopira/tool/flow.h> 19 #include <scopira/tool/export.h> 42 typedef typename basic_array<T>::iterator iterator;
43 typedef typename basic_array<T>::const_iterator const_iterator;
49 iterator dm_read, dm_write;
55 void reserve(
size_t reserve_size);
57 iterator begin1(
void) {
return dm_read; }
59 {
return (dm_write<dm_read) ? dm_ary.
end() : dm_write; }
60 const_iterator begin1(
void)
const {
return dm_read; }
61 const_iterator end1(
void)
const 62 {
return (dm_write<dm_read) ? dm_ary.
end() : dm_write; }
63 iterator begin2(
void) {
return dm_ary.
begin(); }
65 {
return (dm_write<dm_read) ? dm_write : dm_ary.
begin(); }
66 const_iterator begin2(
void)
const {
return dm_ary.
begin(); }
67 const_iterator end2(
void)
const 68 {
return (dm_write<dm_read) ? dm_write : dm_ary.
begin(); }
71 bool empty(
void)
const {
return dm_read == dm_write; }
74 {
return (dm_write+1 == dm_read) ||
75 (dm_read == dm_ary.
begin() && dm_write == dm_ary.
end()-1); }
77 size_t size(
void)
const;
83 void clear(
void) { dm_read = dm_write = dm_ary.
begin(); }
86 const T &
front(
void)
const {
return *dm_read; }
102 void push_seek(
size_t sz) { dm_write += sz; assert(dm_write<dm_ary.
end()); }
115 : dm_ary(reserve_size+1)
118 dm_write = dm_read = dm_ary.
begin();
124 dm_ary.
resize(reserve_size+1);
126 dm_write = dm_read = dm_ary.
begin();
132 if (dm_write >= dm_read)
133 return dm_write - dm_read;
135 return dm_ary.
size() + (dm_write - dm_read);
143 assert(dm_read != dm_write);
152 if (dm_read == dm_ary.
end())
153 dm_read = dm_ary.
begin();
156 template <
class T>
template <
class ITER>
159 assert(free() >= (tail - head));
162 while (head != tail && dm_write != dm_ary.
end()) {
168 if (dm_write == dm_ary.
end())
169 dm_write = dm_ary.
begin();
173 while (head != tail) {
180 template <
class T>
template <
class ITER>
185 endend = dm_write < dm_read ? dm_ary.
end() : dm_write;
187 while (head != tail && dm_read != endend) {
193 if (head != tail && !empty())
194 dm_read = dm_ary.
begin();
198 while (head != tail && dm_read != dm_write) {
226 SCOPIRA_EXPORT
cacheiflow(
bool doref,
iflow_i* innie,
size_t buffersize = 32768);
229 SCOPIRA_EXPORT
virtual bool failed(
void)
const {
return dm_failed; }
232 SCOPIRA_EXPORT
virtual size_t read(byte_t* _buf,
size_t _maxsize);
234 SCOPIRA_EXPORT
virtual size_t read_byte(byte_t &out);
237 SCOPIRA_EXPORT
void open(
iflow_i* in);
239 SCOPIRA_EXPORT
void close(
void);
244 SCOPIRA_EXPORT
void short_rewind(
void);
247 SCOPIRA_EXPORT
void load_cache(
void);
272 SCOPIRA_EXPORT ~cacheoflow();
275 SCOPIRA_EXPORT
virtual bool failed(
void)
const {
return dm_failed; }
278 SCOPIRA_EXPORT
virtual size_t write(
const byte_t* _buf,
size_t _size);
280 SCOPIRA_EXPORT
virtual size_t write_byte(byte_t b);
283 SCOPIRA_EXPORT
void open(
oflow_i* in);
285 SCOPIRA_EXPORT
void close(
void);
290 SCOPIRA_EXPORT
void flush_cache(
void);
Definition: archiveflow.h:20