Disk ARchive
2.4.2
|
00001 /*********************************************************************/ 00002 // dar - disk archive - a backup/restoration program 00003 // Copyright (C) 2002-2052 Denis Corbin 00004 // 00005 // This program is free software; you can redistribute it and/or 00006 // modify it under the terms of the GNU General Public License 00007 // as published by the Free Software Foundation; either version 2 00008 // of the License, or (at your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00013 // GNU General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program; if not, write to the Free Software 00017 // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 00018 // 00019 // to contact the author : http://dar.linux.free.fr/email.html 00020 /*********************************************************************/ 00021 // $Id: crc.hpp,v 1.8 2011/02/11 20:23:42 edrusb Rel $ 00022 // 00023 /*********************************************************************/ 00024 00028 00029 #ifndef CRC_HPP 00030 #define CRC_HPP 00031 00032 #include "../my_config.h" 00033 00034 #include <string> 00035 #include <list> 00036 00037 #include "integers.hpp" 00038 #include "storage.hpp" 00039 #include "infinint.hpp" 00040 00041 namespace libdar 00042 { 00043 00046 00047 class crc 00048 { 00049 public: 00050 static const U_I OLD_CRC_SIZE = 2; 00051 00052 crc(U_I width = 1); 00053 crc(const infinint & width); 00054 crc(const crc & ref) : i_cyclic(1) { copy_from(ref); }; 00055 const crc & operator = (const crc & ref) { destroy(); copy_from(ref); return *this; }; 00056 ~crc() { destroy(); }; 00057 00058 bool operator == (const crc & ref) const; 00059 bool operator != (const crc & ref) const { return ! (*this == ref); }; 00060 00061 void compute(const infinint & offset, const char *buffer, U_I length); 00062 void compute(const char *buffer, U_I length); // for sequential read only 00063 void clear(); 00064 void dump(generic_file & f) const; 00065 void read(generic_file & f); 00066 void old_read(generic_file & f); 00067 std::string crc2str() const; 00068 void resize(const infinint & width); 00069 void resize(U_I width) { resize_non_infinint(width); }; 00070 void resize_based_on(const crc & ref) { resize(ref.get_size()); }; 00071 infinint get_size() const { return infinint_mode ? i_size : n_size; }; 00072 00073 static void set_crc_pointer(crc * & dst, const crc *src); 00074 00075 private: 00076 00077 bool infinint_mode; //< true for infinint mode 00078 // --- 00079 infinint i_size; //< size of the checksum (infinint mode) 00080 storage::iterator i_pointer; //< points to the next byte to modify (infinint mode) 00081 storage i_cyclic; //< the checksum storage (infinint mode) 00082 // --- 00083 U_I n_size; //< size of checksum (non infinint mode) 00084 unsigned char *n_pointer; //< points to the next byte to modify (non infinint mode) 00085 unsigned char *n_cyclic; //< the checksum storage (non infinint mode) 00086 00087 void copy_from(const crc & ref); 00088 void destroy(); 00089 void resize_infinint(const infinint & width); 00090 void resize_non_infinint(U_I width); 00091 }; 00092 00093 00095 00096 } // end of namespace 00097 00098 00099 #endif