libxcks  0.1.0.1
handlers.cpp
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 
25 //---------------------------------------------------------------------------
26 #include "libxcks/handlers.hpp"
27 //---------------------------------------------------------------------------
28 
29 
31 using namespace std;
32 
34 using namespace std::filesystem;
35 //---------------------------------------------------------------------------
36 
37 
38 namespace libxcks
39 {
40 /*
41  * Constructor.
42  */
43 XCKSWriterOptions::XCKSWriterOptions(const bool writeGeneratedElement,
44  const bool writeFileSize,
45  const bool writeFileDateTime,
46  const bool useCompactXML,
47  const bool useTabsforIndentation,
48  const unsigned int nbIndentSpaces,
49  const bool checkReturnedChecksums,
50  const std::string applicationWriter,
51  const std::string applicationVersion,
52  const bool writeLibXCKSVersion)
53 {
54  setWriteGeneratedElement(writeGeneratedElement);
55  setWriteFileSize(writeFileSize);
56  setWriteFileDateTime(writeFileDateTime);
57  setUseCompactXML(useCompactXML);
58  setUseTabsforIndentation(useTabsforIndentation);
59  setIndentSpaces(nbIndentSpaces);
60  setCheckReturnedChecksums(checkReturnedChecksums);
61  setApplicationWriter(applicationWriter);
62  setApplicationWriterVersion(applicationVersion);
63  setWriteLibXCKSVersion(writeLibXCKSVersion);
64 }
65 //---------------------------------------------------------------------------
66 
67 
68 /*
69  * Sets the number of spaces to use for indention (meaningful only if
70  * useTabsforIndentation() returns false).
71  */
72 void XCKSWriterOptions::setIndentSpaces(const unsigned int nbIndentSpaces)
73 {
74  indentSpaces = (nbIndentSpaces >= 1u && nbIndentSpaces <= max_indent_spaces) ?
75  nbIndentSpaces : default_indent_spaces;
76 }
77 //---------------------------------------------------------------------------
78 
79 
80 #if defined(__GNUC__) && defined(LIBXCKS_SHARED) && defined(BUILDING_LIBXCKS) && (__GNUC__ <= 11)
81 constexpr int ZXCKSWriterOptions::min_compression_level;
82 constexpr int ZXCKSWriterOptions::max_compression_level;
83 constexpr int ZXCKSWriterOptions::default_compression_level;
84 #endif
85 
86 
87 /*
88  * Constructor.
89  */
90 ZXCKSWriterOptions::ZXCKSWriterOptions(const bool writeGeneratedElement,
91  const bool writeFileSize,
92  const bool writeFileDateTime,
93  const bool useCompactXML,
94  const bool useTabsforIndentation,
95  const unsigned int nbIndentSpaces,
96  const bool checkReturnedChecksums,
97  const std::string applicationWriter,
98  const std::string applicationVersion,
99  const bool writeLibXCKSVersion,
100  const int compressionLevel) :
101  XCKSWriterOptions(writeGeneratedElement, writeFileSize, writeFileDateTime,
102  useCompactXML, useTabsforIndentation, nbIndentSpaces,
103  checkReturnedChecksums, applicationWriter,
104  applicationVersion, writeLibXCKSVersion)
105 {
106  setCompressionLevel(compressionLevel);
107 }
108 //---------------------------------------------------------------------------
109 
110 
111 /*
112  * Sets the compression level.
113  */
115 {
116  compressionLevel = (level >= min_compression_level && level <= max_compression_level) ?
118 }
119 //---------------------------------------------------------------------------
120 } // namespace libxcks
121 //---------------------------------------------------------------------------
Provides options for the XCKS writer.
Definition: handlers.hpp:818
static constexpr int max_compression_level
Maximum compression level.
Definition: handlers.hpp:1077
static constexpr int default_compression_level
Default compression level.
Definition: handlers.hpp:1078
virtual void setCompressionLevel(const int level) final
Sets the compression level.
Definition: handlers.cpp:114
static constexpr int min_compression_level
Minimum compression level.
Definition: handlers.hpp:1076
Handlers for reading and writing XCKS files.