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

- Main Page
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

crc.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 CRC_HPP
27 #define CRC_HPP
28
29 #include "../my_config.h"
30
31 #include <string>
32 #include <list>
33 #include "integers.hpp"
34 #include "storage.hpp"
35 #include "infinint.hpp"
36 #include "on_pool.hpp"
37
38 namespace libdar
39 {
40
43
44 class crc : public on_pool
45 {
46 public:
47 static const U_I OLD_CRC_SIZE = 2;
48
49 virtual ~crc() throw(Ebug) {};
50
51 virtual bool operator == (const crc & ref) const = 0;
52 bool operator != (const crc & ref) const { return ! (*this == ref); };
53
54 virtual void compute(const infinint & offset, const char *buffer, U_I length) = 0;
55 virtual void compute(const char *buffer, U_I length) = 0; // for sequential read only
56 virtual void clear() = 0;
57 virtual void dump(generic_file & f) const = 0;
58 virtual std::string crc2str() const = 0;
59 virtual infinint get_size() const = 0;
60 virtual crc *clone() const = 0;
61 };
62
63 extern crc *create_crc_from_file(generic_file & f, memory_pool *pool, bool old = false);
64 extern crc *create_crc_from_size(infinint width, memory_pool *pool);
65
66 class crc_i : public crc
67 {
68 public:
69 crc_i(const infinint & width);
70 crc_i(const infinint & width, generic_file & f);
71 crc_i(const crc_i & ref) : size(ref.size), cyclic(ref.size) { copy_data_from(ref); pointer = cyclic.begin(); };
72 const crc_i & operator = (const crc_i & ref) { copy_from(ref); return *this; };
73
74 bool operator == (const crc & ref) const;
75
76 void compute(const infinint & offset, const char *buffer, U_I length);
77 void compute(const char *buffer, U_I length); // for sequential read only
78 void clear();
79 void dump(generic_file & f) const;
80 std::string crc2str() const;
81 infinint get_size() const { return size; };
82
83 protected:
84 crc *clone() const { return new (get_pool()) crc_i(*this); };
85
86 private:
87
88 infinint size; //< size of the checksum
89 storage::iterator pointer; //< points to the next byte to modify
90 storage cyclic; //< the checksum storage
91
92 void copy_from(const crc_i & ref);
93 void copy_data_from(const crc_i & ref);
94 };
95
96
97 class crc_n : public crc
98 {
99 public:
100
101 crc_n(U_I width);
102 crc_n(U_I width, generic_file & f);
103 crc_n(const crc_n & ref) { copy_from(ref); };
104 const crc_n & operator = (const crc_n & ref);
105 ~crc_n() { destroy(); };
106
107 bool operator == (const crc & ref) const;
108
109 void compute(const infinint & offset, const char *buffer, U_I length);
110 void compute(const char *buffer, U_I length); // for sequential read only
111 void clear();
112 void dump(generic_file & f) const;
113 std::string crc2str() const;
114 infinint get_size() const { return size; };
115
116 protected:
117 crc *clone() const { return new (get_pool()) crc_n(*this); };
118
119 private:
120
121 U_I size; //< size of checksum (non infinint mode)
122 unsigned char *pointer; //< points to the next byte to modify (non infinint mode)
123 unsigned char *cyclic; //< the checksum storage (non infinint mode)
124
125 void alloc(U_I width);
126 void copy_from(const crc_n & ref);
127 void copy_data_from(const crc_n & ref);
128 void destroy();
129 };
130
131
133
134 } // end of namespace
135
136
137 #endif
integers.hpp
are defined here basic integer types that tend to be portable
storage.hpp
contains a class that permits arbitrary large data storage
libdar::on_pool::get_pool
memory_pool * get_pool() const
Definition: on_pool.hpp:144
infinint.hpp
switch module to limitint (32 ou 64 bits integers) or infinint
on_pool.hpp
this is the base class of object that can be allocated on a memory pool
libdar
libdar namespace encapsulate all libdar symbols
Definition: archive.hpp:47