libxcks  0.1.0.1
libxcks::ChecksumFormatter Class Reference

This class provides some convenient tools to format checksum and hash values. More...

#include <ckformatter.hpp>

Classes

class  ConfigurationProvider
 Configuration provider for ChecksumFormatter. More...
 

Public Types

enum class  NumericBase : uint_least8_t { hexadecimal = 0 , decimal = 1 , octal = 2 }
 The available numeric bases. More...
 
using Positions = std::set< uint_fast16_t >
 Set of unsigned integers. More...
 

Public Member Functions

 ChecksumFormatter ()=delete
 Deleted default constructor. More...
 
 ChecksumFormatter (const ChecksumFormatter &)=delete
 Deleted copy constructor. More...
 
ChecksumFormatteroperator= (const ChecksumFormatter &)=delete
 Deleted assignment operator. More...
 
 ChecksumFormatter (const ConfigurationProvider &provider, const std::string &algoName, const bool lookInAltNames=true)
 Constructs a new checksum's formatter for the given algorithm name or alternative name. More...
 
 ChecksumFormatter (const ConfigurationProvider &provider, const ChecksumAlgoId type)
 Constructs a new checksum's formatter for the given algorithm type. More...
 
 ChecksumFormatter (const bool uc=false, const NumericBase nb=NumericBase::hexadecimal, const Positions &sp=Positions())
 Constructs a new checksum's formatter with the given parameters. More...
 
std::string format (const uint8_t *value, const size_t size)
 Format the given checksum's value. More...
 
bool getUpperCase () const
 Returns whether the output will be in uppercase. More...
 
void setUpperCase (const bool isUpperCase)
 Sets whether the output will be in uppercase. More...
 
NumericBase getNumericBase () const
 Returns the numeric base for the output. More...
 
void setNumericBase (const NumericBase base)
 Sets the numeric base for the output. More...
 
Positions getSpacesPositions () const
 Returns the positions of the spaces between two bytes. More...
 
void setSpacesPositions (const std::string &spacesPositions)
 Sets the positions of the spaces between two bytes. More...
 
void setSpacesPositions (const Positions &spacesPositions)
 Sets the positions of the spaces between two bytes. More...
 

Static Public Member Functions

static std::string format (const ConfigurationProvider &provider, const uint8_t *value, const size_t size, const std::string &algoName, const bool lookInAltNames=true)
 Format the given checksum's value with the given algorithm's name. More...
 
static std::string format (const ConfigurationProvider &provider, const uint8_t *value, const size_t size, const ChecksumAlgoId type)
 Format the given checksum's value with the given algorithm's type. More...
 
static std::string format (const ConfigurationProvider &provider, const ChecksumValue &value)
 Format the given checksum's value. More...
 
static Positions toSpacesPositions (const std::string &spacesPositions)
 Gets the positions of the spaces between two bytes from a string. More...
 

Protected Member Functions

void initialise (const ConfigurationProvider &provider, const ChecksumAlgoId type)
 Initialises the instance. More...
 

Protected Attributes

bool upperCase
 Case of the output if numeric base is hexadecimal. More...
 
NumericBase numericBase
 Numeric base of the output. More...
 
Positions spacesPos
 Positions of spaces between two bytes. More...
 

Detailed Description

This class provides some convenient tools to format checksum and hash values.

Format parameters are :

  • Positions for spaces (one at maximum between two bytes) in the output.
  • Numeric base : octal, decimal or hexadecimal.
  • Case of the output if numeric base is hexadecimal.

Convenient static methods are provided to simplify the usage of this class.

Definition at line 51 of file ckformatter.hpp.

Member Typedef Documentation

◆ Positions

using libxcks::ChecksumFormatter::Positions = std::set<uint_fast16_t>

Set of unsigned integers.

Definition at line 55 of file ckformatter.hpp.

Member Enumeration Documentation

◆ NumericBase

enum libxcks::ChecksumFormatter::NumericBase : uint_least8_t
strong

The available numeric bases.

Definition at line 58 of file ckformatter.hpp.

Constructor & Destructor Documentation

◆ ChecksumFormatter() [1/5]

libxcks::ChecksumFormatter::ChecksumFormatter ( )
delete

Deleted default constructor.

◆ ChecksumFormatter() [2/5]

libxcks::ChecksumFormatter::ChecksumFormatter ( const ChecksumFormatter )
delete

Deleted copy constructor.

◆ ChecksumFormatter() [3/5]

libxcks::ChecksumFormatter::ChecksumFormatter ( const ConfigurationProvider provider,
const std::string &  algoName,
const bool  lookInAltNames = true 
)

Constructs a new checksum's formatter for the given algorithm name or alternative name.

Parameters
providerThe configuration provider.
algoNameThe name of the checksum or hash algorithm.
lookInAltNamesLooks for the name of the checksum or hash algorithm in the alternative names.

Definition at line 54 of file ckformatter.cpp.

◆ ChecksumFormatter() [4/5]

libxcks::ChecksumFormatter::ChecksumFormatter ( const ConfigurationProvider provider,
const ChecksumAlgoId  type 
)

Constructs a new checksum's formatter for the given algorithm type.

Parameters
providerThe configuration provider.
typeThe type (identifier) of the algorithm of the checksum.

Definition at line 73 of file ckformatter.cpp.

◆ ChecksumFormatter() [5/5]

libxcks::ChecksumFormatter::ChecksumFormatter ( const bool  uc = false,
const NumericBase  nb = NumericBase::hexadecimal,
const Positions sp = Positions() 
)

Constructs a new checksum's formatter with the given parameters.

Parameters
ucThe case of the output if numeric base is hexadecimal.
nbThe numeric base of the output.
spThe positions of spaces between two bytes.

Definition at line 88 of file ckformatter.cpp.

Member Function Documentation

◆ format() [1/4]

string libxcks::ChecksumFormatter::format ( const ConfigurationProvider provider,
const ChecksumValue value 
)
static

Format the given checksum's value.

Parameters
providerThe configuration provider.
valueThe checksum's value to format.
Returns
The given checksum's value formatted.

Definition at line 310 of file ckformatter.cpp.

◆ format() [2/4]

string libxcks::ChecksumFormatter::format ( const ConfigurationProvider provider,
const uint8_t *  value,
const size_t  size,
const ChecksumAlgoId  type 
)
static

Format the given checksum's value with the given algorithm's type.

Parameters
providerThe configuration provider.
valueThe value of the checksum.
sizeThe size of the value of the checksum.
typeThe type (identifier) of the algorithm of the checksum.
Returns
The given checksum's value formatted.

Definition at line 293 of file ckformatter.cpp.

◆ format() [3/4]

string libxcks::ChecksumFormatter::format ( const ConfigurationProvider provider,
const uint8_t *  value,
const size_t  size,
const std::string &  algoName,
const bool  lookInAltNames = true 
)
static

Format the given checksum's value with the given algorithm's name.

Parameters
providerThe configuration provider.
valueThe value of the checksum.
sizeThe size of the value of the checksum.
algoNameThe name of the checksum or hash algorithm.
lookInAltNamesLooks for the name of the checksum or hash algorithm in the alternative names.
Returns
The given checksum's value formatted.

Definition at line 269 of file ckformatter.cpp.

◆ format() [4/4]

string libxcks::ChecksumFormatter::format ( const uint8_t *  value,
const size_t  size 
)

Format the given checksum's value.

Parameters
valueThe value of the checksum.
sizeThe size of the value of the checksum.

3 (hex)digits max + nul character

Definition at line 120 of file ckformatter.cpp.

◆ getNumericBase()

ChecksumFormatter::NumericBase libxcks::ChecksumFormatter::getNumericBase ( ) const

Returns the numeric base for the output.

Returns
the numeric base for the output.

Definition at line 186 of file ckformatter.cpp.

◆ getSpacesPositions()

ChecksumFormatter::Positions libxcks::ChecksumFormatter::getSpacesPositions ( ) const

Returns the positions of the spaces between two bytes.

Returns
The positions of the spaces between two bytes.

Definition at line 221 of file ckformatter.cpp.

◆ getUpperCase()

bool libxcks::ChecksumFormatter::getUpperCase ( ) const

Returns whether the output will be in uppercase.

Returns
Whether the output will be in uppercase.

Definition at line 161 of file ckformatter.cpp.

◆ initialise()

void libxcks::ChecksumFormatter::initialise ( const ConfigurationProvider provider,
const ChecksumAlgoId  type 
)
protected

Initialises the instance.

Parameters
providerThe configuration provider.
typeThe type (identifier) of the algorithm of the checksum.

Definition at line 104 of file ckformatter.cpp.

◆ operator=()

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

Deleted assignment operator.

◆ setNumericBase()

void libxcks::ChecksumFormatter::setNumericBase ( const NumericBase  base)

Sets the numeric base for the output.

Parameters
baseThe new numeric base for the output.
Remarks
If the given numeric base doesn't exist, the hexadecimal base is assumed.

Definition at line 200 of file ckformatter.cpp.

◆ setSpacesPositions() [1/2]

void libxcks::ChecksumFormatter::setSpacesPositions ( const Positions spacesPositions)

Sets the positions of the spaces between two bytes.

Parameters
spacesPositionsThe new list of the positions of the spaces.

Definition at line 251 of file ckformatter.cpp.

◆ setSpacesPositions() [2/2]

void libxcks::ChecksumFormatter::setSpacesPositions ( const std::string &  spacesPositions)

Sets the positions of the spaces between two bytes.

The given string must be a suite of integers (which represent the position of the byte where the space will be placed after, the first byte is identified as 0) separated by commas with or without spaces.

Parameters
spacesPositionsThe new list of the positions of the spaces.

Definition at line 237 of file ckformatter.cpp.

◆ setUpperCase()

void libxcks::ChecksumFormatter::setUpperCase ( const bool  isUpperCase)

Sets whether the output will be in uppercase.

Parameters
isUpperCasetrue if the output should be in uppercase, false otherwise.

Definition at line 174 of file ckformatter.cpp.

◆ toSpacesPositions()

ChecksumFormatter::Positions libxcks::ChecksumFormatter::toSpacesPositions ( const std::string &  spacesPositions)
static

Gets the positions of the spaces between two bytes from a string.

The given string must be a suite of integers (which represent the position of the byte where the space will be placed after, the first byte is identified as 0) separated by commas with or without spaces.

Parameters
spacesPositionsThe new list of the positions of the spaces.
Returns
The positions of the spaces between two bytes from spacesPositions.

Definition at line 328 of file ckformatter.cpp.

Member Data Documentation

◆ numericBase

NumericBase libxcks::ChecksumFormatter::numericBase
protected

Numeric base of the output.

Definition at line 115 of file ckformatter.hpp.

◆ spacesPos

Positions libxcks::ChecksumFormatter::spacesPos
protected

Positions of spaces between two bytes.

Definition at line 116 of file ckformatter.hpp.

◆ upperCase

bool libxcks::ChecksumFormatter::upperCase
protected

Case of the output if numeric base is hexadecimal.

Definition at line 114 of file ckformatter.hpp.


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