libxcks  0.1.0.1
libxcks::ChecksumFileCalculator Class Reference

Computes a checksum from a file. More...

#include <ckcalculator.hpp>

Inheritance diagram for libxcks::ChecksumFileCalculator:
Collaboration diagram for libxcks::ChecksumFileCalculator:

Public Member Functions

 ChecksumFileCalculator (ChecksumCalculatorProgress &progressHandler=defaultChecksumCalculatorProgress, const unsigned int newNbThreads=automatic_thread_number, const size_t newBufferSize=default_file_buffer_size)
 Constructor. More...
 
 ChecksumFileCalculator (const ChecksumFileCalculator &)=delete
 Deleted copy constructor. More...
 
ChecksumFileCalculatoroperator= (const ChecksumFileCalculator &)=delete
 Deleted assignment operator. More...
 
virtual ~ChecksumFileCalculator ()=default
 Destructor. More...
 
State calculate (ChecksumValue &sumValue, const ChecksumAlgoId id, const std::filesystem::path &filepath)
 Calculates the checksum from the given file. More...
 
State calculate (ArrayChecksumValue &sumValues, const ArrayChecksumAlgoId &ids, const std::filesystem::path &filepath)
 Calculates the checksums from the given file. More...
 
- Public Member Functions inherited from libxcks::ChecksumCalculator
 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 Protected Attributes

static constexpr size_t default_file_buffer_size = 0xFFFFu
 Default buffer size for reading files. More...
 
- Static Protected Attributes inherited from libxcks::ChecksumCalculator
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...
 

Additional Inherited Members

- Public Types inherited from libxcks::ChecksumCalculator
enum class  State {
  Ok = 0 , NoValidAlgoId , OutOfMemory , ReadError ,
  FileNotFound , CantOpenFile , CancelledByUser
}
 States that can be returned by the calculate or the check method. More...
 
- Static Public Attributes inherited from libxcks::ChecksumCalculator
static constexpr unsigned int automatic_thread_number = 0u
 System dependent value for number of threads for computing checksums. More...
 
- Protected Attributes inherited from libxcks::ChecksumCalculator
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...
 

Detailed Description

Computes a checksum from a file.

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 268 of file ckcalculator.hpp.

Constructor & Destructor Documentation

◆ ChecksumFileCalculator() [1/2]

libxcks::ChecksumFileCalculator::ChecksumFileCalculator ( ChecksumCalculatorProgress progressHandler = defaultChecksumCalculatorProgress,
const unsigned int  newNbThreads = automatic_thread_number,
const size_t  newBufferSize = default_file_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 375 of file ckcalculator.cpp.

◆ ChecksumFileCalculator() [2/2]

libxcks::ChecksumFileCalculator::ChecksumFileCalculator ( const ChecksumFileCalculator )
delete

Deleted copy constructor.

◆ ~ChecksumFileCalculator()

virtual libxcks::ChecksumFileCalculator::~ChecksumFileCalculator ( )
virtualdefault

Destructor.

Member Function Documentation

◆ calculate() [1/2]

ChecksumFileCalculator::State libxcks::ChecksumFileCalculator::calculate ( ArrayChecksumValue sumValues,
const ArrayChecksumAlgoId ids,
const std::filesystem::path &  filepath 
)

Calculates the checksums from the given file.

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 file.
[in]idsThe ids of the wanted algorithm of checksums.
[in]filepathPath of the file from which the data will be extracted to compute the checksum. The data are extracted until the end of the file 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.
  • FileNotFound if the file doesn't exist.
  • CantOpenFile if the file can't be opened.
  • Cancelled if the user has cancelled the calculation.

Definition at line 409 of file ckcalculator.cpp.

◆ calculate() [2/2]

ChecksumFileCalculator::State libxcks::ChecksumFileCalculator::calculate ( ChecksumValue sumValue,
const ChecksumAlgoId  id,
const std::filesystem::path &  filepath 
)

Calculates the checksum from the given file.

Parameters
[out]sumValueThe calculated value of the checksum from the input stream.
[in]idThe id of the wanted algorithm of checksums.
[in,out]filepathPath of the file from which the data will be extracted to compute the checksum. The data are extracted until the end of the file 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.
  • FileNotFound if the file doesn't exist.
  • CantOpenFile if the file can't be opened.
  • Cancelled if the user has cancelled the calculation.

Definition at line 389 of file ckcalculator.cpp.

◆ operator=()

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

Deleted assignment operator.

Member Data Documentation

◆ default_file_buffer_size

constexpr size_t libxcks::ChecksumFileCalculator::default_file_buffer_size = 0xFFFFu
staticconstexprprotected

Default buffer size for reading files.

Definition at line 271 of file ckcalculator.hpp.


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