libxcks  0.1.0.1
libxcks::XCKSFileWriter Class Referencefinal

A XCKS file writer. More...

#include <xcksfilewriter.hpp>

Collaboration diagram for libxcks::XCKSFileWriter:

Public Member Functions

 XCKSFileWriter (XCKSWriterHandler &xcksWriterHandler, XCKSWriterChecksumProvider &checksumProvider, const XCKSWriterOptions &options, const std::filesystem::path &baseDir, const ArrayChecksumAlgoId &algoIds, const ChecksumFormatter::ConfigurationProvider &confProvider, Version version=Version::Last_Valid)
 Constructor. More...
 
 XCKSFileWriter (const XCKSFileWriter &source)=delete
 Deleted copy constructor. More...
 
XCKSFileWriteroperator= (const XCKSFileWriter &source)=delete
 Deleted assignment operator. More...
 
 ~XCKSFileWriter ()
 Destructor. More...
 
StringSet getAvailableChecksumTypesName () const
 Returns the list of names of available checksums algorithms for this particular version of XCKS file. More...
 
ArrayChecksumAlgoId getAvailableChecksumTypes () const
 Returns the list of available checksums algorithms for this type of checksums' file. More...
 
ArrayChecksumAlgoId getChecksumTypesForNewEntries () const
 Returns the list of checksums algorithms to compute for new entries of this type of checksums' file. More...
 
Version getVersion () const
 Returns the version of the checksums' file type. More...
 
void getVersion (unsigned int &major, unsigned int &minor, unsigned int &revision) const
 Gets the version of the checksums' file type. More...
 
std::string getStrVersion () const
 Gets the version of the checksums' file type as a string. More...
 
bool write (std::ostream &os, const ArrayPath &relativePaths)
 Writes the checksums in a stream. More...
 

Protected Member Functions

ArrayChecksumAlgoId getValidChecksumTypesForNewEntries (const ArrayChecksumAlgoId &ids) const
 Gets a valid list of algorithms to calculate for each file. More...
 
XCKSWriterChecksumProvider::Status getChecksumValues (ArrayChecksumValue &ckValues, uintmax_t &filesize, time_t &filedatetime, const ArrayChecksumAlgoId &ids, const std::filesystem::path &filePath, bool &stopWriting) const
 Gets checksums values from an array of wanted algorithms of checksums. More...
 
bool writeLocalFilesV1 (std::ostream &os, const ArrayPath &relativePaths, int &indent)
 Writes the "localFiles" section of a XCKS file version 1.0.0 in a stream. More...
 
bool writeV1 (std::ostream &os, const ArrayPath &relativePaths)
 Writes the XCKS file version 1.0.0 in a stream. More...
 
bool writeLine (std::ostream &os, const std::string &line, const int indent)
 Writes a line in the XCKS file. More...
 
bool getXCKSAlgorithmName (std::string &algoName, const ChecksumAlgoId algoId)
 Gets the algorithm name in the XCKS specification. More...
 

Static Protected Member Functions

static Version getValidVersion (const Version ver)
 Ensures a valid version of XCKS file. More...
 

Protected Attributes

XCKSWriterHandlerwriterHandler
 The XCKS file writer handler. More...
 
XCKSWriterChecksumProviderckProvider
 The provider of checksums values. More...
 
const XCKSWriterOptionswriterOptions
 The writer options. More...
 
const std::filesystem::path baseDirectory
 The base directory of the checksums' file. More...
 
const Version version
 Version of the (Z)XCKS file to write. More...
 
const StringSet possibleSumsAlgos
 Possible algorithms names for a (Z)XCKS file. More...
 
const ArrayChecksumAlgoId sumsAlgos
 Type of algorithms' checksums to write for each file. More...
 
const ChecksumFormatter::ConfigurationProviderckfConfProvider
 Configuration provider for ChecksumFormatter. More...
 

Static Protected Attributes

static const std::string parentDir = ".."
 Parent directory on Unix and windows. More...
 

Detailed Description

A XCKS file writer.

Definition at line 41 of file xcksfilewriter.hpp.

Constructor & Destructor Documentation

◆ XCKSFileWriter() [1/2]

libxcks::XCKSFileWriter::XCKSFileWriter ( XCKSWriterHandler xcksWriterHandler,
XCKSWriterChecksumProvider checksumProvider,
const XCKSWriterOptions options,
const std::filesystem::path &  baseDir,
const ArrayChecksumAlgoId algoIds,
const ChecksumFormatter::ConfigurationProvider confProvider,
Version  version = Version::Last_Valid 
)

Constructor.

Parameters
xcksWriterHandlerThe XCKS file reader handler.
checksumProviderThe provider of checksums values from an array of of wanted algorithms of checksums.
optionsOptions of the XCKS writer.
baseDirThe base directory of the (Z)XCKS file to read. Must be an absolute path name.
algoIdsThe algorithms to compute for each file. Each algorithm must appears only once in the array.
confProviderConfiguration provider for ChecksumFormatter.
versionThe wanted version of XCKS specification file.

Definition at line 934 of file xcksfilewriter.cpp.

◆ XCKSFileWriter() [2/2]

libxcks::XCKSFileWriter::XCKSFileWriter ( const XCKSFileWriter source)
delete

Deleted copy constructor.

◆ ~XCKSFileWriter()

libxcks::XCKSFileWriter::~XCKSFileWriter ( )

Destructor.

Definition at line 960 of file xcksfilewriter.cpp.

Member Function Documentation

◆ getAvailableChecksumTypes()

ArrayChecksumAlgoId libxcks::XCKSFileWriter::getAvailableChecksumTypes ( ) const

Returns the list of available checksums algorithms for this type of checksums' file.

Returns
The list of available checksums algorithms for this type of checksums' file.

Definition at line 990 of file xcksfilewriter.cpp.

◆ getAvailableChecksumTypesName()

StringSet libxcks::XCKSFileWriter::getAvailableChecksumTypesName ( ) const

Returns the list of names of available checksums algorithms for this particular version of XCKS file.

Note
The returned names are exactly those present in the XCKS format specification.
Returns
The list of names of available checksums algorithms for this particular version of XCKS file.

Definition at line 976 of file xcksfilewriter.cpp.

◆ getChecksumTypesForNewEntries()

ArrayChecksumAlgoId libxcks::XCKSFileWriter::getChecksumTypesForNewEntries ( ) const

Returns the list of checksums algorithms to compute for new entries of this type of checksums' file.

Must be equal or a subgroup of getAvailableChecksumTypes().

Returns
The list of checksums algorithms to compute for new entries of this type of checksums' file.

Definition at line 1016 of file xcksfilewriter.cpp.

◆ getChecksumValues()

XCKSWriterChecksumProvider::Status libxcks::XCKSFileWriter::getChecksumValues ( ArrayChecksumValue ckValues,
uintmax_t &  filesize,
time_t &  filedatetime,
const ArrayChecksumAlgoId ids,
const std::filesystem::path &  filePath,
bool &  stopWriting 
) const
protected

Gets checksums values from an array of wanted algorithms of checksums.

When returning sumValues must contains the checksums values required in ids, in any order, but no less and no more.

Parameters
[out]ckValuesThe calculated values.
[out]filesizeThe size of path. Can be Invalid_File_Size.
[out]filedatetimeThe date/time of path. Can be Invalid_DateTime.
[in]idsThe ids of the wanted algorithm of checksums.
[in]filePathRelative path to baseDirectory of the file from which the checksums must be calculated.
[out]stopWritingShould the writing of the XCKS must be stopped on error? Must be set to true to stop the writing.
Returns
true if the file has been successfully read and the required checksums has been successfully calculated and provided, false otherwise.

Definition at line 1190 of file xcksfilewriter.cpp.

◆ getStrVersion()

string libxcks::XCKSFileWriter::getStrVersion ( ) const

Gets the version of the checksums' file type as a string.

Returns
The version of the checksums' file type as a string.

Definition at line 1061 of file xcksfilewriter.cpp.

◆ getValidChecksumTypesForNewEntries()

ArrayChecksumAlgoId libxcks::XCKSFileWriter::getValidChecksumTypesForNewEntries ( const ArrayChecksumAlgoId ids) const
protected

Gets a valid list of algorithms to calculate for each file.

Parameters
[in]idsThe ids of the wanted algorithm of checksums to validate.

Definition at line 1130 of file xcksfilewriter.cpp.

◆ getValidVersion()

Version libxcks::XCKSFileWriter::getValidVersion ( const Version  ver)
staticprotected

Ensures a valid version of XCKS file.

Parameters
[in]verThe version to check.
Returns
The given version if valid or a valid version otherwise.

Definition at line 1115 of file xcksfilewriter.cpp.

◆ getVersion() [1/2]

Version libxcks::XCKSFileWriter::getVersion ( ) const

Returns the version of the checksums' file type.

Returns
The version of the checksums' file type.

Definition at line 1028 of file xcksfilewriter.cpp.

◆ getVersion() [2/2]

void libxcks::XCKSFileWriter::getVersion ( unsigned int &  major,
unsigned int &  minor,
unsigned int &  revision 
) const

Gets the version of the checksums' file type.

Parameters
[out]majorMajor version of the XCKS file.
[out]minorMinor version of the XCKS file.
[out]revisionRevision of the XCKS file.

Definition at line 1042 of file xcksfilewriter.cpp.

◆ getXCKSAlgorithmName()

bool libxcks::XCKSFileWriter::getXCKSAlgorithmName ( std::string &  algoName,
const ChecksumAlgoId  algoId 
)
protected

Gets the algorithm name in the XCKS specification.

Parameters
[out]algoNameThe algorithm's name.
[in]algoIdThe algorithm's identifier.
Returns
true if the algorithm's identifier is a valid algorithm for the XCKS file, false otherwise.

Definition at line 1566 of file xcksfilewriter.cpp.

◆ operator=()

XCKSFileWriter& libxcks::XCKSFileWriter::operator= ( const XCKSFileWriter source)
delete

Deleted assignment operator.

◆ write()

bool libxcks::XCKSFileWriter::write ( std::ostream &  os,
const ArrayPath relativePaths 
)

Writes the checksums in a stream.

After the writing of the stream, the state of the file should be unmodified and the file name must be modified to fileName. The paths of the files in SumFile::entries must be relative to the path of SumFile::fileName.

Parameters
osThe output stream in which the checksums are written.
relativePathsRelative paths (from baseDir) of files to add in the XCKS file.
Returns
true if the checksums have been written successfully, false otherwise.

Definition at line 1084 of file xcksfilewriter.cpp.

◆ writeLine()

bool libxcks::XCKSFileWriter::writeLine ( std::ostream &  os,
const std::string &  line,
const int  indent 
)
protected

Writes a line in the XCKS file.

The line is written with the parameters defined for this XCKS file (compact or not, type of indentation).

Parameters
osThe output stream in which the line is written.
lineThe line to write.
indentThe level of indentation, must be greater or equal to 0.

Definition at line 1537 of file xcksfilewriter.cpp.

◆ writeLocalFilesV1()

bool libxcks::XCKSFileWriter::writeLocalFilesV1 ( std::ostream &  os,
const ArrayPath relativePaths,
int &  indent 
)
protected

Writes the "localFiles" section of a XCKS file version 1.0.0 in a stream.

Parameters
[in,out]osThe output stream in which the checksums are written.
[in]relativePathsRelative paths (from baseDir) of files to add in the XCKS file.
[in,out]indentThe current indentation level in XML structure.
Returns
true if the checksums' file have been written successfully, false otherwise.

Definition at line 1297 of file xcksfilewriter.cpp.

◆ writeV1()

bool libxcks::XCKSFileWriter::writeV1 ( std::ostream &  os,
const ArrayPath relativePaths 
)
protected

Writes the XCKS file version 1.0.0 in a stream.

Parameters
osThe output stream in which the checksums are written.
relativePathsRelative paths (from baseDir) of files to add in the XCKS file.
Returns
true if the checksums' file have been written successfully, false otherwise.

Definition at line 1446 of file xcksfilewriter.cpp.

Member Data Documentation

◆ baseDirectory

const std::filesystem::path libxcks::XCKSFileWriter::baseDirectory
protected

The base directory of the checksums' file.

Definition at line 47 of file xcksfilewriter.hpp.

◆ ckfConfProvider

const ChecksumFormatter::ConfigurationProvider& libxcks::XCKSFileWriter::ckfConfProvider
protected

Configuration provider for ChecksumFormatter.

Definition at line 51 of file xcksfilewriter.hpp.

◆ ckProvider

XCKSWriterChecksumProvider& libxcks::XCKSFileWriter::ckProvider
protected

The provider of checksums values.

Definition at line 45 of file xcksfilewriter.hpp.

◆ parentDir

const string libxcks::XCKSFileWriter::parentDir = ".."
staticprotected

Parent directory on Unix and windows.

Definition at line 53 of file xcksfilewriter.hpp.

◆ possibleSumsAlgos

const StringSet libxcks::XCKSFileWriter::possibleSumsAlgos
protected

Possible algorithms names for a (Z)XCKS file.

Definition at line 49 of file xcksfilewriter.hpp.

◆ sumsAlgos

const ArrayChecksumAlgoId libxcks::XCKSFileWriter::sumsAlgos
protected

Type of algorithms' checksums to write for each file.

Definition at line 50 of file xcksfilewriter.hpp.

◆ version

const Version libxcks::XCKSFileWriter::version
protected

Version of the (Z)XCKS file to write.

Definition at line 48 of file xcksfilewriter.hpp.

◆ writerHandler

XCKSWriterHandler& libxcks::XCKSFileWriter::writerHandler
protected

The XCKS file writer handler.

Definition at line 44 of file xcksfilewriter.hpp.

◆ writerOptions

const XCKSWriterOptions& libxcks::XCKSFileWriter::writerOptions
protected

The writer options.

Definition at line 46 of file xcksfilewriter.hpp.


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