30 #include "../my_config.h"
34 #if LIBDAR_MODE == 32 || LIBDAR_MODE == 64
57 cellule() : next(
nullptr), prev(
nullptr), data(
nullptr), size(0) {};
58 struct cellule *next, *prev;
64 storage(U_32 size) { make_alloc(size, first, last); };
68 storage(
storage && ref) noexcept: first(
nullptr), last(
nullptr) { move_from(std::move(ref)); };
69 storage & operator = (
const storage & val) { detruit(first); copy_from(val);
return *
this; };
70 storage & operator = (
storage && val) noexcept { move_from(std::move(val));
return *
this; };
73 bool operator < (
const storage & ref)
const noexcept
74 {
return difference(ref) < 0; };
75 bool operator == (
const storage & ref)
const noexcept
76 {
return difference(ref) == 0; };
77 bool operator > (
const storage & ref)
const noexcept
78 {
return difference(ref) > 0; };
79 bool operator <= (
const storage & ref)
const noexcept
80 {
return difference(ref) <= 0; };
81 bool operator >= (
const storage & ref)
const noexcept
82 {
return difference(ref) >= 0; };
83 bool operator != (
const storage & ref)
const noexcept
84 {
return difference(ref) != 0; };
85 unsigned char & operator [](
infinint position);
86 unsigned char operator [](
const infinint & position)
const;
88 void clear(
unsigned char val = 0) noexcept;
94 iterator() : ref(
nullptr), cell(
nullptr), offset(0) {};
95 iterator(
const iterator & ref) =
default;
96 iterator(iterator && ref) =
default;
97 iterator & operator = (
const iterator & ref) =
default;
98 iterator & operator = (iterator && ref) =
default;
99 ~iterator() =
default;
101 iterator operator ++ (S_I x)
102 { iterator ret = *
this; skip_plus_one();
return ret; };
103 iterator operator -- (S_I x)
104 { iterator ret = *
this; skip_less_one();
return ret; };
105 iterator & operator ++ ()
106 { skip_plus_one();
return *
this; };
107 iterator & operator -- ()
108 { skip_less_one();
return *
this; };
109 iterator operator + (U_32 s)
const
110 { iterator ret = *
this; ret += s;
return ret; };
111 iterator operator - (U_32 s)
const
112 { iterator ret = *
this; ret -= s;
return ret; };
114 iterator & operator -= (U_32 s);
115 unsigned char &operator *()
const;
120 bool operator == (
const iterator & cmp)
const noexcept
121 {
return ref == cmp.ref && cell == cmp.cell && offset == cmp.offset; };
122 bool operator != (
const iterator & cmp)
const noexcept
123 {
return ! (*
this == cmp); };
126 static constexpr U_32 OFF_BEGIN = 1;
127 static constexpr U_32 OFF_END = 2;
130 struct cellule *cell;
133 void relative_skip_to(S_32 val);
134 bool points_on_data()
const noexcept
135 {
return ref !=
nullptr && cell !=
nullptr && offset < cell->size; };
137 inline void skip_plus_one();
138 inline void skip_less_one();
145 iterator begin()
const
146 { iterator ret; ret.cell = first;
if(ret.cell !=
nullptr) ret.offset = 0;
else ret.offset = iterator::OFF_END; ret.ref =
this;
return ret; };
148 { iterator ret; ret.cell =
nullptr; ret.offset = iterator::OFF_END; ret.ref =
this;
return ret; };
154 iterator rbegin()
const
155 { iterator ret; ret.cell = last; ret.offset = last !=
nullptr ? last->size-1 : 0; ret.ref =
this;
return ret; };
156 iterator rend()
const
157 { iterator ret; ret.cell =
nullptr, ret.offset = iterator::OFF_BEGIN; ret.ref =
this;
return ret; };
164 U_I
write(iterator & it,
unsigned char *a, U_I size);
165 U_I read(iterator & it,
unsigned char *a, U_I size)
const;
166 bool write(iterator & it,
unsigned char a)
167 {
return write(it, &a, 1) == 1; };
168 bool read(iterator & it,
unsigned char &a)
const
169 {
return read(it, &a, 1) == 1; };
172 void insert_null_bytes_at_iterator(iterator it, U_I size);
173 void insert_const_bytes_at_iterator(iterator it,
unsigned char a, U_I size);
174 void insert_bytes_at_iterator(iterator it,
unsigned char *a, U_I size);
175 void insert_as_much_as_necessary_const_byte_to_be_as_wider_as(
const storage & ref,
const iterator & it,
unsigned char value);
176 void remove_bytes_at_iterator(iterator it, U_I number);
177 void remove_bytes_at_iterator(iterator it, infinint number);
180 struct cellule *first, *last;
182 void copy_from(
const storage & ref);
183 void move_from(storage && ref) noexcept;
184 S_32 difference(
const storage & ref)
const;
186 void insert_bytes_at_iterator_cmn(iterator it,
bool constant,
unsigned char *a, U_I size);
187 void fusionne(
struct cellule *a_first,
struct cellule *a_last,
struct cellule *b_first,
struct cellule *b_last,
188 struct cellule *&res_first,
struct cellule * & res_last);
190 static void detruit(
struct cellule *c);
191 static void make_alloc(U_32 size,
struct cellule * & begin,
struct cellule * & end);
192 static void make_alloc(infinint size, cellule * & begin,
struct cellule * & end);
194 friend class storage::iterator;
197 inline void storage::iterator::skip_plus_one()
200 if(++offset >= cell->size)
210 inline void storage::iterator::skip_less_one()
220 offset = cell->size - 1;
the arbitrary large positive integer class
ancestor class of generic_file
arbitrary large storage structure
U_I write(iterator &it, unsigned char *a, U_I size)
write data to the storage at the location pointed to by it
std::vector< T > operator+=(std::vector< T > &a, const std::vector< T > &b)
template function to add two vectors
switch module to limitint (32 ou 64 bits integers) or infinint
are defined here basic integer types that tend to be portable
libdar namespace encapsulate all libdar symbols
precursor class of generic_file used to avoid cyclic dependencies with storage and infinint