| Disk ARchive 2.5.10 Full featured and portable backup and archiving tool

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

int_tools.hpp
Go to the documentation of this file.
1 /*********************************************************************/
2 // dar - disk archive - a backup/restoration program
3 // Copyright (C) 2002-2052 Denis Corbin
4 //
5 // This program is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU General Public License
7 // as published by the Free Software Foundation; either version 2
8 // of the License, or (at your option) any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
14 //
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software
17 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18 //
19 // to contact the author : http://dar.linux.free.fr/email.html
20 /*********************************************************************/
21
25
26 #ifndef INT_TOOLS_HPP
27 #define INT_TOOLS_HPP
28
29 #include "../my_config.h"
30
31 #include "integers.hpp"
32 #include "erreurs.hpp"
33
34 namespace libdar
35 {
36
39
40 typedef unsigned char int_tools_bitfield[8];
41
42 extern void int_tools_swap_bytes(unsigned char &a, unsigned char &b);
43 extern void int_tools_swap_bytes(unsigned char *a, U_I size);
44 extern void int_tools_expand_byte(unsigned char a, int_tools_bitfield &bit);
45 extern void int_tools_contract_byte(const int_tools_bitfield &b, unsigned char & a);
46
47 // integer (agregates) manipulations
48 // argument must be a regular interger (a bit field).
49 template <class T> extern T int_tools_rotate_right_one_bit(T v)
50 {
51 bool retenue = (v & 1) != 0;
52
53 v >>= 1;
54 if(retenue)
55 v |= T(1) << (sizeof(v)*8 - 1);
56
57 return v;
58 }
59
60 template <class T> extern T int_tools_maxof_agregate(T unused) { unused = 0; unused = ~unused; unused = unused > 0 ? unused : ~int_tools_rotate_right_one_bit(T(1)); return unused; }
61
62 template <class B> static B int_tools_higher_power_of_2(B val)
63 {
64 B i = 0;
65
66 while((val >> i) > 1)
67 i++;
68
69 return i;
70 }
71
73
74 }
75
76 #endif
integers.hpp
are defined here basic integer types that tend to be portable
erreurs.hpp
contains all the excetion class thrown by libdar
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47