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 
22     /// \file label.hpp
23     /// \brief define the datastructure "label" used to identify slice membership to an archive
24     /// \ingroup Private
25 
26 #ifndef LABEL_HPP
27 #define LABEL_HPP
28 
29 #include "../my_config.h"
30 
31 #include "integers.hpp"
32 #include "generic_file.hpp"
33 #include "on_pool.hpp"
34 
35 namespace libdar
36 {
37 
38 	/// \addtogroup Private
39 	/// @{
40 
41     class label : public on_pool
42     {
43     public:
44 	label(); // builds a label equal to 'zero'
label(const label & ref)45 	label(const label & ref) { copy_from(ref); };
operator =(const label & ref)46 	const label & operator = (const label & ref) { copy_from(ref); return *this; };
47 
48 	bool operator == (const label & ref) const;
operator !=(const label & ref) const49 	bool operator != (const label & ref) const { return ! ((*this) == ref); };
50 
51 	void clear();
52 	bool is_cleared() const;
53 
54 	void generate_internal_filename();
55 
56 	void read(generic_file & f);
57 	void dump(generic_file & f) const;
58 
invert_first_byte()59 	void invert_first_byte() { val[0] = ~val[0]; };
60 
61 	    // avoid using these two calls, only here for backward compatibility
62 	    // where the cost to move to object is really too heavy than
63 	    // sticking with an char array.
size() const64 	U_I size() const { return LABEL_SIZE; };
data()65 	char *data() { return (char *)&val; };
data() const66 	const char *data() const { return (char *)&val; };
67 
common_size()68 	static U_I common_size() { return LABEL_SIZE; };
69 
70     private:
71 	static const U_I LABEL_SIZE = 10;
72 
73 	char val[LABEL_SIZE];
74 
75 	void copy_from(const label & ref);
76     };
77 
78 
79     extern const label label_zero;
80 
81 	/// @}
82 
83 } // end of namespace
84 
85 #endif
86