29#include "//include/dar/libdar_my_config.h"
33#include "//include/dar/integers.hpp"
34#include "//include/dar/storage.hpp"
35#include "//include/dar/infinint.hpp"
36#include "//include/dar/proto_generic_file.hpp"
49 static constexpr U_I OLD_CRC_SIZE = 2;
52 crc(
const crc & ref) =
default;
53 crc(crc && ref)
noexcept =
default;
54 crc & operator = (
const crc & ref) =
default;
55 crc & operator = (crc && ref)
noexcept =
default;
56 virtual ~crc() =
default;
58 virtual bool operator == (
const crc & ref)
const = 0;
59 bool operator != (
const crc & ref)
const {
return ! (*
this == ref); };
61 virtual void compute(
const infinint & offset,
const char *buffer, U_I length) = 0;
62 virtual void compute(
const char *buffer, U_I length) = 0;
63 virtual void clear() = 0;
65 virtual std::string crc2str()
const = 0;
66 virtual infinint get_size()
const = 0;
67 virtual crc *clone()
const = 0;
78 class crc_i :
public crc
84 crc_i(crc_i && ref)
noexcept =
default;
85 crc_i & operator = (
const crc_i & ref) { copy_from(ref);
return *
this; };
86 crc_i & operator = (crc_i && ref)
noexcept =
default;
89 bool operator == (
const crc & ref)
const override;
91 virtual void compute(
const infinint & offset,
const char *buffer, U_I length)
override;
92 virtual void compute(
const char *buffer, U_I length)
override;
93 virtual void clear()
override;
95 virtual std::string crc2str()
const override;
96 virtual infinint get_size()
const override {
return size; };
99 virtual crc *clone()
const override { crc *tmp =
new (std::nothrow) crc_i(*
this);
if(tmp ==
nullptr)
throw Ememory(
"crc");
return tmp; };
107 void copy_from(
const crc_i & ref);
108 void copy_data_from(
const crc_i & ref);
114 class crc_n :
public crc
120 crc_n(
const crc_n & ref) { copy_from(ref); };
121 crc_n(crc_n && ref)
noexcept =
default;
122 crc_n & operator = (
const crc_n & ref);
123 crc_n & operator = (crc_n && ref)
noexcept =
default;
124 ~crc_n() { destroy(); };
126 bool operator == (
const crc & ref)
const override;
128 virtual void compute(
const infinint & offset,
const char *buffer, U_I length)
override;
129 virtual void compute(
const char *buffer, U_I length)
override;
130 virtual void clear()
override;
132 virtual std::string crc2str()
const override;
133 virtual infinint get_size()
const override {
return size; };
136 virtual crc *clone()
const override { crc *tmp =
new (std::nothrow) crc_n(*
this);
if(tmp ==
nullptr)
throw Ememory(
"crc");
return tmp; };
144 void alloc(U_I width);
145 void copy_from(
const crc_n & ref);
146 void copy_data_from(
const crc_n & ref);
exception used when memory has been exhausted
storage cyclic
the checksum storage
storage::iterator pointer
points to the next byte to modify
infinint size
size of the checksum
unsigned char * pointer
points to the next byte to modify (non infinint mode)
unsigned char * cyclic
the checksum storage (non infinint mode)
U_I size
size of checksum (non infinint mode)
pure virtual class defining interface of a CRC object
the arbitrary large positive integer class
ancestor class of generic_file
arbitrary large storage structure
crc * create_crc_from_file(proto_generic_file &f, bool old=false)
generate a CRC object reading it from file
crc * create_crc_from_size(infinint width)
generate a CRC object with adhoc width based on a file size
libdar namespace encapsulate all libdar symbols