29 #include "../my_config.h"
64 cellule() : next(NULL), prev(NULL), data(NULL), size(0) {};
65 struct cellule *next, *prev;
72 { E_BEGIN; make_alloc(size, first, last); E_END(
"storage::storage",
"U_32"); };
75 { E_BEGIN; copy_from(ref); E_END(
"storage::storage",
"storage &"); };
78 { E_BEGIN;
detruit(first); E_END(
"storage::~storage",
""); };
81 { E_BEGIN;
detruit(first); copy_from(val);
return *
this; E_END(
"storage::operator=",
""); };
83 bool operator < (
const storage & ref)
const
84 { E_BEGIN;
return difference(ref) < 0; E_END(
"storage::operator <",
""); };
85 bool operator == (
const storage & ref)
const
86 { E_BEGIN;
return difference(ref) == 0; E_END(
"storage::operator ==",
""); };
87 bool operator > (
const storage & ref)
const
88 { E_BEGIN;
return difference(ref) > 0; E_END(
"storage::operator >",
""); };
89 bool operator <= (
const storage & ref)
const
90 { E_BEGIN;
return difference(ref) <= 0; E_END(
"storage::operator <=",
""); };
91 bool operator >= (
const storage & ref)
const
92 { E_BEGIN;
return difference(ref) >= 0; E_END(
"storage::operator >=",
""); };
93 bool operator != (
const storage & ref)
const
94 { E_BEGIN;
return difference(ref) != 0; E_END(
"storage::operator !=",
""); };
95 unsigned char & operator [](
infinint position);
96 unsigned char operator [](
const infinint & position)
const;
98 void clear(
unsigned char val = 0);
104 iterator() : ref(NULL), cell(NULL), offset(0) {};
109 iterator operator ++ (S_I x)
110 { E_BEGIN; iterator ret = *
this; skip_plus_one();
return ret; E_END(
"storage::iterator::operator++",
"(S_I)"); };
111 iterator operator -- (S_I x)
112 { E_BEGIN; iterator ret = *
this; skip_less_one();
return ret; E_END(
"storage::iterator::operator--",
"(S_I)");};
113 iterator & operator ++ ()
114 { E_BEGIN; skip_plus_one();
return *
this; E_END(
"storage::iterator::operator++",
"()"); };
115 iterator & operator -- ()
116 { E_BEGIN; skip_less_one();
return *
this; E_END(
"storage::iterator::operator--",
"()"); };
117 iterator operator + (U_32 s)
const
118 { E_BEGIN; iterator ret = *
this; ret += s;
return ret; E_END(
"storage::iterator::operator +",
""); };
119 iterator operator - (U_32 s)
const
120 { E_BEGIN; iterator ret = *
this; ret -= s;
return ret; E_END(
"storage::iterator::operator -",
""); };
122 iterator & operator -= (U_32 s);
123 unsigned char &operator *()
const;
128 bool operator == (
const iterator & cmp)
const
129 { E_BEGIN;
return ref == cmp.ref && cell == cmp.cell && offset == cmp.offset; E_END(
"storage::iterator::operator ==",
""); };
130 bool operator != (
const iterator & cmp)
const
131 { E_BEGIN;
return ! (*
this == cmp); E_END(
"storage::iterator::operator !=",
""); };
134 static const U_32 OFF_BEGIN = 1;
135 static const U_32 OFF_END = 2;
138 struct cellule *cell;
141 void relative_skip_to(S_32 val);
142 bool points_on_data()
const
143 { E_BEGIN;
return ref != NULL && cell != NULL && offset < cell->size; E_END(
"storage::iterator::point_on_data",
"");};
145 inline void skip_plus_one();
146 inline void skip_less_one();
153 iterator begin()
const
154 { E_BEGIN; iterator ret; ret.cell = first;
if(ret.cell != NULL) ret.offset = 0;
else ret.offset = iterator::OFF_END; ret.ref =
this;
return ret; E_END(
"storage::begin",
""); };
156 { E_BEGIN; iterator ret; ret.cell = NULL; ret.offset = iterator::OFF_END; ret.ref =
this;
return ret; E_END(
"storage::end",
""); };
162 iterator rbegin()
const
163 { E_BEGIN; iterator ret; ret.cell = last; ret.offset = last != NULL ? last->size-1 : 0; ret.ref =
this;
return ret; E_END(
"storage::rbegin",
""); };
164 iterator rend()
const
165 { E_BEGIN; iterator ret; ret.cell = NULL, ret.offset = iterator::OFF_BEGIN; ret.ref =
this;
return ret; E_END(
"storage::rend",
""); };
172 U_I
write(iterator & it,
unsigned char *a, U_I size);
173 U_I read(iterator & it,
unsigned char *a, U_I size)
const;
174 bool write(iterator & it,
unsigned char a)
175 { E_BEGIN;
return write(it, &a, 1) == 1; E_END(
"storage::write",
"unsigned char"); };
176 bool read(iterator & it,
unsigned char &a)
const
177 { E_BEGIN;
return read(it, &a, 1) == 1; E_END(
"storage::read",
"unsigned char"); };
180 void insert_null_bytes_at_iterator(iterator it, U_I size);
181 void insert_const_bytes_at_iterator(iterator it,
unsigned char a, U_I size);
182 void insert_bytes_at_iterator(iterator it,
unsigned char *a, U_I size);
183 void insert_as_much_as_necessary_const_byte_to_be_as_wider_as(
const storage & ref,
const iterator & it,
unsigned char value);
184 void remove_bytes_at_iterator(iterator it, U_I number);
185 void remove_bytes_at_iterator(iterator it,
infinint number);
189 struct cellule *first, *last;
191 void copy_from(
const storage & ref);
192 S_32 difference(
const storage & ref)
const;
194 void insert_bytes_at_iterator_cmn(iterator it,
bool constant,
unsigned char *a, U_I size);
195 void fusionne(
struct cellule *a_first,
struct cellule *a_last,
struct cellule *b_first,
struct cellule *b_last,
196 struct cellule *&res_first,
struct cellule * & res_last);
202 static void detruit(
struct cellule *c);
203 static void make_alloc(U_32 size,
struct cellule * & begin,
struct cellule * & end);
204 static void make_alloc(
infinint size, cellule * & begin,
struct cellule * & end);
206 friend class storage::iterator;
209 inline void storage::iterator::skip_plus_one()
213 if(++offset >= cell->size)
221 E_END(
"storage::iterator::slik_plus_one",
"");
224 inline void storage::iterator::skip_less_one()
235 offset = cell->size - 1;
240 E_END(
"storage::iterator::slik_plus_one",
"");