libxcks  0.1.0.1
All Classes Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
xcksfilewriter.hpp
Go to the documentation of this file.
1 /*
2  * libxcks
3  * Copyright (C) 2022 Julien Couot
4  *
5  * This program is free software: you can redistribute it and/or modify it
6  * under the terms of the GNU Lesser General Public License as published by
7  * the Free Software Foundation, either version 3 of the License, or (at your
8  * option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful, but
11  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
13  * License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * along with this program. If not, see <https://www.gnu.org/licenses/>.
17  */
18 
24 #ifndef INC_XCKSFILEWRITER_HPP_82011D48_E442_4D38_8BFE_2DFF49B069B4
25 #define INC_XCKSFILEWRITER_HPP_82011D48_E442_4D38_8BFE_2DFF49B069B4
26 
27 //---------------------------------------------------------------------------
28 #include <ostream>
29 // #include <filesystem> // Included in "libxcks/handlers.hpp"
30 
31 #include "libxcks/handlers.hpp"
32 #include "libxcks/ckformatter.hpp"
33 //---------------------------------------------------------------------------
34 
35 
36 namespace libxcks
37 {
41 class XCKSFileWriter final
42 {
43  protected:
47  const std::filesystem::path baseDirectory;
48  const Version version;
52 
53  static const std::string parentDir; // Parent directory.
54 
55  public:
56  // Constructor.
57  XCKSFileWriter(XCKSWriterHandler& xcksWriterHandler,
58  XCKSWriterChecksumProvider& checksumProvider,
59  const XCKSWriterOptions& options,
60  const std::filesystem::path& baseDir,
61  const ArrayChecksumAlgoId& algoIds,
62  const ChecksumFormatter::ConfigurationProvider& confProvider,
63  Version version = Version::Last_Valid);
64 
66  XCKSFileWriter(const XCKSFileWriter& source) = delete;
67 
69  XCKSFileWriter& operator=(const XCKSFileWriter& source) = delete;
70 
71  // Destructor.
73 
74  // Returns the list of names of available checksums algorithms for this
75  // particular version of XCKS file.
77 
78  // Returns the list of available checksums algorithms for this type of
79  // checksums' file.
81 
82  // Returns the list of checksums algorithms to compute for new entries of this
83  // type of checksums' file.
85 
86  // Returns the version of the checksums' file type.
87  Version getVersion() const;
88 
89  // Gets the version of the checksums' file type.
90  void getVersion(unsigned int& major, unsigned int& minor, unsigned int& revision) const;
91 
92  // Gets the version of the checksums' file type as a string.
93  std::string getStrVersion() const;
94 
95  // Writes the checksums in a stream.
96  bool write(std::ostream& os, const ArrayPath& relativePaths);
97 
98  protected:
99  // Ensures a valid version.
100  static Version getValidVersion(const Version ver);
101 
102  // Gets a valid list of algorithms to calculate for each file.
104 
105  // Gets checksums values from an array of wanted algorithms of checksums.
107  uintmax_t& filesize,
108  time_t& filedatetime,
109  const ArrayChecksumAlgoId& ids,
110  const std::filesystem::path& filePath,
111  bool& stopWriting) const;
112 
113  // Writes the "localFiles" section of a XCKS file version 1.0.0 in a stream.
114  bool writeLocalFilesV1(std::ostream& os, const ArrayPath& relativePaths, int& indent);
115 
116  // Writes the checksums in a stream.
117  bool writeV1(std::ostream& os, const ArrayPath& relativePaths);
118 
119  // Writes a line in the XCKS file.
120  bool writeLine(std::ostream& os, const std::string& line, const int indent);
121 
122  // Gets the algorithm name in the XCKS specification.
123  bool getXCKSAlgorithmName(std::string& algoName, const ChecksumAlgoId algoId);
124 };
125 //---------------------------------------------------------------------------
126 } // namespace libxcks
127 //---------------------------------------------------------------------------
128 
129 #endif // INC_XCKSFILEWRITER_HPP_82011D48_E442_4D38_8BFE_2DFF49B069B4
Format checksum and hash values.
std::vector< ChecksumValue > ArrayChecksumValue
Array of values of checksum.
Definition: ckvalue.hpp:113
Configuration provider for ChecksumFormatter.
Definition: ckformatter.hpp:69
A XCKS file writer.
ArrayChecksumAlgoId getValidChecksumTypesForNewEntries(const ArrayChecksumAlgoId &ids) const
Gets a valid list of algorithms to calculate for each file.
bool getXCKSAlgorithmName(std::string &algoName, const ChecksumAlgoId algoId)
Gets the algorithm name in the XCKS specification.
std::string getStrVersion() const
Gets the version of the checksums' file type as a string.
static const std::string parentDir
Parent directory on Unix and windows.
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.
Version getVersion() const
Returns the version of the checksums' file type.
static Version getValidVersion(const Version ver)
Ensures a valid version of XCKS file.
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.
const std::filesystem::path baseDirectory
The base directory of the checksums' file.
bool writeV1(std::ostream &os, const ArrayPath &relativePaths)
Writes the XCKS file version 1.0.0 in a stream.
ArrayChecksumAlgoId getChecksumTypesForNewEntries() const
Returns the list of checksums algorithms to compute for new entries of this type of checksums' file.
const Version version
Version of the (Z)XCKS file to write.
const XCKSWriterOptions & writerOptions
The writer options.
XCKSFileWriter(const XCKSFileWriter &source)=delete
Deleted copy constructor.
XCKSFileWriter & operator=(const XCKSFileWriter &source)=delete
Deleted assignment operator.
bool writeLine(std::ostream &os, const std::string &line, const int indent)
Writes a line in the XCKS file.
XCKSWriterHandler & writerHandler
The XCKS file writer handler.
const ChecksumFormatter::ConfigurationProvider & ckfConfProvider
Configuration provider for ChecksumFormatter.
StringSet getAvailableChecksumTypesName() const
Returns the list of names of available checksums algorithms for this particular version of XCKS file.
const StringSet possibleSumsAlgos
Possible algorithms names for a (Z)XCKS file.
bool write(std::ostream &os, const ArrayPath &relativePaths)
Writes the checksums in a stream.
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.
const ArrayChecksumAlgoId sumsAlgos
Type of algorithms' checksums to write for each file.
XCKSWriterChecksumProvider & ckProvider
The provider of checksums values.
ArrayChecksumAlgoId getAvailableChecksumTypes() const
Returns the list of available checksums algorithms for this type of checksums' file.
Provides checksums values from an array of wanted algorithms of checksums for the XCKS writer.
Definition: handlers.hpp:375
Status
Return status of getChecksumValues().
Definition: handlers.hpp:379
Handler for writing XCKS files.
Definition: handlers.hpp:423
Provides options for the XCKS writer.
Definition: handlers.hpp:818
Handlers for reading and writing XCKS files.
std::vector< ChecksumAlgoId > ArrayChecksumAlgoId
Array of ids of algorithms of checksums.
Definition: types.hpp:92
std::vector< std::filesystem::path > ArrayPath
Array of paths.
Definition: types.hpp:49
ChecksumAlgoId
Ids of algorithms of checksums.
Definition: types.hpp:65
Version
Known versions of XCKS file.
Definition: types.hpp:55
std::set< std::string > StringSet
Set of strings.
Definition: types.hpp:39