Disk ARchive 2.7.16
Full featured and portable backup and archiving tool
int_tools.hpp
Go to the documentation of this file.
1/*********************************************************************/
2// dar - disk archive - a backup/restoration program
3// Copyright (C) 2002-2024 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18//
19// to contact the author, see the AUTHOR file
20/*********************************************************************/
21
26
27#ifndef INT_TOOLS_HPP
28#define INT_TOOLS_HPP
29
30#include "../my_config.h"
31
32#include "integers.hpp"
33
34namespace libdar
35{
36
39
40 using int_tools_bitfield = unsigned char[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_aggregate(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
are defined here basic integer types that tend to be portable
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47