29 #ifndef REAL_INFININT_HPP
30 #define REAL_INFININT_HPP
32 #include "../my_config.h"
37 #include <sys/types.h>
48 #define ZEROED_SIZE 50
53 class user_interaction;
63 #if SIZEOF_OFF_T > SIZEOF_TIME_T
64 #if SIZEOF_OFF_T > SIZEOF_SIZE_T
66 { infinint_from(a); };
69 { infinint_from(a); };
72 #if SIZEOF_TIME_T > SIZEOF_SIZE_T
74 { infinint_from(a); };
77 { infinint_from(a); };
92 {
detruit(); copy_from(ref);
return *
this; };
100 infinint & operator *= (
unsigned char arg);
102 template <
class T>
infinint power(
const T & exponent)
const;
113 {
infinint ret = *
this; ++(*this);
return ret; };
115 {
infinint ret = *
this; --(*this);
return ret; };
117 {
return *
this += 1; };
119 {
return *
this -= 1; };
121 U_32 operator % (U_32 arg)
const
122 {
return modulo(arg); };
127 template <
class T>
void unstack(T &v)
128 { infinint_unstack_to(v); }
130 infinint get_storage_size()
const {
return field->size(); };
133 unsigned char operator [] (
const infinint & position)
const;
144 static bool is_system_big_endian();
146 #ifdef LIBDAR_SPECIAL_ALLOC
150 static const int TG = 4;
152 enum endian { big_endian, little_endian, not_initialized };
153 typedef unsigned char group[TG];
157 bool is_valid()
const;
160 void copy_from(
const infinint & ref);
162 void make_at_least_as_wider_as(
const infinint & ref);
163 template <
class T>
void infinint_from(T a);
164 template <
class T> T max_val_of(T x);
165 template <
class T>
void infinint_unstack_to(T &a);
166 template <
class T> T modulo(T arg)
const;
167 signed int difference(
const infinint & b)
const;
172 static endian used_endian;
173 static U_8 zeroed_field[ZEROED_SIZE];
174 static void setup_endian();
178 #define OPERATOR(OP) inline bool operator OP (const infinint &a, const infinint &b) \
180 return a.difference(b) OP 0; \
191 infinint operator - (const infinint &, const infinint &);
192 infinint operator * (const infinint &, const infinint &);
193 infinint operator * (const infinint &, const
unsigned char);
194 infinint operator * (const
unsigned char, const infinint &);
195 infinint operator / (const infinint &, const infinint &);
196 infinint operator % (const infinint &, const infinint &);
197 infinint operator & (const infinint & a, const infinint & bit);
198 infinint operator | (const infinint & a, const infinint & bit);
199 infinint operator ^ (const infinint & a, const infinint & bit);
200 infinint operator >> (const infinint & a, U_32 bit);
201 infinint operator >> (const infinint & a, const infinint & bit);
202 infinint operator << (const infinint & a, U_32 bit);
203 infinint operator << (const infinint & a, const infinint & bit);
204 void euclide(infinint a, const infinint &b, infinint &q, infinint &r);
205 template <class T> inline
void euclide(T a, T b, T & q, T &r)
210 inline infinint & infinint::operator /= (
const infinint & ref)
216 inline infinint & infinint::operator %= (
const infinint & ref)
227 template <
class T> infinint infinint::power(
const T & exponent)
const
230 for(T count = 0; count < exponent; ++count)
236 template <
class T> T infinint::modulo(T arg)
const
238 infinint tmp = *
this % infinint(arg);
240 unsigned char *debut = (
unsigned char *)(&ret);
241 unsigned char *ptr = debut +
sizeof(T) - 1;
242 storage::iterator it = tmp.field->rbegin();
244 while(it != tmp.field->rend() && ptr >= debut)
253 while(it != tmp.field->rend())
260 if(used_endian == little_endian)
261 int_tools_swap_bytes(debut,
sizeof(T));
267 template <
class T>
void infinint::infinint_from(T a)
269 U_I size =
sizeof(a);
271 unsigned char *ptr, *fin;
273 if(used_endian == not_initialized)
276 if(used_endian == little_endian)
279 ptr = (
unsigned char *)(&a) + (size - 1);
280 fin = (
unsigned char *)(&a) - 1;
285 ptr = (
unsigned char *)(&a);
286 fin = (
unsigned char *)(&a) + size;
289 while(ptr != fin && *ptr == 0)
301 field =
new (std::nothrow) storage(size);
304 storage::iterator it = field->begin();
312 if(it != field->end())
316 throw Ememory(
"template infinint::infinint_from");
319 template <
class T> T infinint::max_val_of(T x)
327 x = int_tools_rotate_right_one_bit(x);
334 template <
class T>
void infinint::infinint_unstack_to(T &a)
339 static const T max_T = max_val_of(a);
340 infinint step = max_T - a;
345 unsigned char *debut = (
unsigned char *)&transfert;
346 unsigned char *ptr = debut +
sizeof(transfert) - 1;
347 storage::iterator it = field->rbegin();
349 while(ptr >= debut && it != field->rend())
356 if(used_endian == little_endian)
357 int_tools_swap_bytes(debut,
sizeof(transfert));
are defined here basic integer types that tend to be portable
This is a pure virtual class that is used by libdar when interaction with the user is required...
contains a class that permits arbitrary large data storage
arbitrary large storage structure
this is the interface class from which all other data transfer classes inherit
the arbitrary large positive integer class
libdar namespace encapsulate all libdar symbols