libxcks  0.1.0.1
libxcks::ChecksumCalculator Class Reference

Calculates a checksum. More...

#include <ckcalculator.hpp>

Inheritance diagram for libxcks::ChecksumCalculator:
Collaboration diagram for libxcks::ChecksumCalculator:

Public Types

enum class  State {
  Ok = 0 , NoValidAlgoId , OutOfMemory , ReadError ,
  FileNotFound , CantOpenFile , CancelledByUser
}
 States that can be returned by the calculate or the check method. More...
 

Public Member Functions

 ChecksumCalculator (ChecksumCalculatorProgress &progressHandler=defaultChecksumCalculatorProgress, const unsigned int newNbThreads=automatic_thread_number, const size_t newBufferSize=default_buffer_size)
 Constructor. More...
 
 ChecksumCalculator (const ChecksumCalculator &)=delete
 Deleted copy constructor. More...
 
ChecksumCalculatoroperator= (const ChecksumCalculator &)=delete
 Deleted assignment operator. More...
 
virtual ~ChecksumCalculator ()=default
 Destructor. More...
 
size_t getBufferSize () const
 Gets the size of the buffer to use for reading in the input stream. More...
 
size_t setBufferSize (const size_t newBufSize)
 Sets the size of the buffer to use for reading in the input stream. More...
 
unsigned int getNbThreads () const
 Returns the number of threads to use to compute checksums. More...
 
unsigned int setNbThreads (const unsigned int newNbThreads)
 Sets the number of threads to use to compute checksums. More...
 
ChecksumCalculatorProgressgetChecksumProgress () const
 Gets the progress handler used to show the progression. More...
 
State calculate (ChecksumValue &sumValue, const ChecksumAlgoId id, std::istream &is)
 Calculates the checksum from the given stream. More...
 
State calculate (ArrayChecksumValue &sumValues, const ArrayChecksumAlgoId &ids, std::istream &is)
 Calculates the checksums from the given stream. More...
 

Static Public Attributes

static constexpr unsigned int automatic_thread_number = 0u
 System dependent value for number of threads for computing checksums. More...
 

Protected Attributes

ChecksumCalculatorProgressprogress
 The progress handler used to show the progression. More...
 
size_t bufferSize
 The size of the buffer to use for reading the input stream. More...
 
unsigned int nbThreads
 Number of threads to compute checksums. More...
 

Static Protected Attributes

static DefaultChecksumCalculatorProgress defaultChecksumCalculatorProgress
 Default progress checksum calculator instance. More...
 
static constexpr size_t default_buffer_size = 4096u
 Default buffer size for reading streams. More...
 
static constexpr size_t min_buffer_size = 1u
 Minimal buffer size for reading streams. More...
 
static constexpr size_t max_buffer_size = 1048576u
 Maximal buffer size for reading streams. More...
 
static constexpr unsigned int default_thread_number = 2u
 Default number of threads for computing checksums if the number of cores of the system cannot be automatically found. More...
 
static constexpr unsigned int max_thread_number = 32u
 Maximal value for number of threads for computing checksums. More...
 

Detailed Description

Calculates a checksum.

Provides an interface for showing the progression.

Please note that all the pointers passed to this class are not freed, it is the responsibility to the users of this class to free them.

Definition at line 112 of file ckcalculator.hpp.

Member Enumeration Documentation

◆ State

States that can be returned by the calculate or the check method.

Enumerator
Ok 

Checksums have been calculated.

NoValidAlgoId 

No valid id of algorithm of checksum has been provided.

OutOfMemory 

No enough memory left.

ReadError 

Error while reading the stream.

FileNotFound 

The file has been not found.

CantOpenFile 

Can't open the stream.

CancelledByUser 

User has cancelled the calculation.

Definition at line 116 of file ckcalculator.hpp.

Constructor & Destructor Documentation

◆ ChecksumCalculator() [1/2]

libxcks::ChecksumCalculator::ChecksumCalculator ( ChecksumCalculatorProgress progressHandler = defaultChecksumCalculatorProgress,
const unsigned int  newNbThreads = automatic_thread_number,
const size_t  newBufferSize = default_buffer_size 
)

Constructor.

Parameters
progressHandlerChecksumCalculatorProgress instance class to show the progress.
newNbThreadsThe number of threads to use to compute checksums.
newBufferSizeThe size of the buffer to use for reading in the input stream.

Definition at line 134 of file ckcalculator.cpp.

◆ ChecksumCalculator() [2/2]

libxcks::ChecksumCalculator::ChecksumCalculator ( const ChecksumCalculator )
delete

Deleted copy constructor.

◆ ~ChecksumCalculator()

virtual libxcks::ChecksumCalculator::~ChecksumCalculator ( )
virtualdefault

Destructor.

Member Function Documentation

◆ calculate() [1/2]

ChecksumCalculator::State libxcks::ChecksumCalculator::calculate ( ArrayChecksumValue sumValues,
const ArrayChecksumAlgoId ids,
std::istream &  is 
)

Calculates the checksums from the given stream.

Note
Returned array of values of computed checksums only contains a same type of checksum once even if it present several times in the ids array.
Returned array of values of computed checksums only contains values of checksums with a valid type.
Attention
sumValues is cleared before adding computed values.
Parameters
[out]sumValuesThe calculated values of the checksums from the input stream.
[in]idsThe ids of the wanted algorithm of checksums.
[in,out]isInput stream from which the data will be extracted to compute the checksum. The data are extracted until the end of the stream is reached.
Returns
  • Ok if the checksum has been successfully calculated.
  • NoValidAlgoId if no valid id of algorithm of checksum has been provided.
  • ReadError if a read error has occurred.
  • Cancelled if the user has cancelled the calculation.

Definition at line 243 of file ckcalculator.cpp.

◆ calculate() [2/2]

ChecksumCalculator::State libxcks::ChecksumCalculator::calculate ( ChecksumValue sumValue,
const ChecksumAlgoId  id,
std::istream &  is 
)

Calculates the checksum from the given stream.

Parameters
[out]sumValueThe calculated value of the checksum from the input stream.
[in]idThe id of the wanted algorithm of checksums.
[in,out]isInput stream from which the data will be extracted to compute the checksum. The data are extracted until the end of the stream is reached.
Returns
  • Ok if the checksum has been successfully calculated.
  • NoValidAlgoId if no valid id of algorithm of checksum has been provided.
  • ReadError if a read error has occurred.
  • Cancelled if the user has cancelled the calculation.

Definition at line 225 of file ckcalculator.cpp.

◆ getBufferSize()

size_t libxcks::ChecksumCalculator::getBufferSize ( ) const

Gets the size of the buffer to use for reading in the input stream.

Returns
The size of buffer to use for reading in the input stream.

Definition at line 148 of file ckcalculator.cpp.

◆ getChecksumProgress()

ChecksumCalculatorProgress & libxcks::ChecksumCalculator::getChecksumProgress ( ) const

Gets the progress handler used to show the progression.

Returns
The progress handler used to show the progression.

Definition at line 215 of file ckcalculator.cpp.

◆ getNbThreads()

unsigned int libxcks::ChecksumCalculator::getNbThreads ( ) const

Returns the number of threads to use to compute checksums.

Returns
The number of threads to use to compute checksums.

Definition at line 173 of file ckcalculator.cpp.

◆ operator=()

ChecksumCalculator& libxcks::ChecksumCalculator::operator= ( const ChecksumCalculator )
delete

Deleted assignment operator.

◆ setBufferSize()

size_t libxcks::ChecksumCalculator::setBufferSize ( const size_t  newBufSize)

Sets the size of the buffer to use for reading in the input stream.

The provided size must be between min_buffer_size and max_buffer_size, otherwise, the default value is used.

Parameters
newBufSizeThe new size of the buffer to use for reading in the input stream.
Returns
The old size of the buffer to use for reading in the input stream.

Definition at line 158 of file ckcalculator.cpp.

◆ setNbThreads()

unsigned int libxcks::ChecksumCalculator::setNbThreads ( const unsigned int  newNbThreads)

Sets the number of threads to use to compute checksums.

Parameters
newNbThreadsThe new number of threads to use to compute checksums.
Returns
The old number of threads to use to compute checksums.

Definition at line 183 of file ckcalculator.cpp.

Member Data Documentation

◆ automatic_thread_number

constexpr unsigned int libxcks::ChecksumCalculator::automatic_thread_number = 0u
staticconstexpr

System dependent value for number of threads for computing checksums.

Definition at line 146 of file ckcalculator.hpp.

◆ bufferSize

size_t libxcks::ChecksumCalculator::bufferSize
protected

The size of the buffer to use for reading the input stream.

Definition at line 141 of file ckcalculator.hpp.

◆ default_buffer_size

constexpr size_t libxcks::ChecksumCalculator::default_buffer_size = 4096u
staticconstexprprotected

Default buffer size for reading streams.

Definition at line 129 of file ckcalculator.hpp.

◆ default_thread_number

constexpr unsigned int libxcks::ChecksumCalculator::default_thread_number = 2u
staticconstexprprotected

Default number of threads for computing checksums if the number of cores of the system cannot be automatically found.

Definition at line 136 of file ckcalculator.hpp.

◆ defaultChecksumCalculatorProgress

DefaultChecksumCalculatorProgress libxcks::ChecksumCalculator::defaultChecksumCalculatorProgress
staticprotected

Default progress checksum calculator instance.

Definition at line 128 of file ckcalculator.hpp.

◆ max_buffer_size

constexpr size_t libxcks::ChecksumCalculator::max_buffer_size = 1048576u
staticconstexprprotected

Maximal buffer size for reading streams.

Definition at line 131 of file ckcalculator.hpp.

◆ max_thread_number

constexpr unsigned int libxcks::ChecksumCalculator::max_thread_number = 32u
staticconstexprprotected

Maximal value for number of threads for computing checksums.

Definition at line 138 of file ckcalculator.hpp.

◆ min_buffer_size

constexpr size_t libxcks::ChecksumCalculator::min_buffer_size = 1u
staticconstexprprotected

Minimal buffer size for reading streams.

Definition at line 130 of file ckcalculator.hpp.

◆ nbThreads

unsigned int libxcks::ChecksumCalculator::nbThreads
protected

Number of threads to compute checksums.

Definition at line 142 of file ckcalculator.hpp.

◆ progress

ChecksumCalculatorProgress& libxcks::ChecksumCalculator::progress
protected

The progress handler used to show the progression.

Definition at line 140 of file ckcalculator.hpp.


The documentation for this class was generated from the following files: