Skip to content

Commit 121b717

Browse files
authored
refactor(core): Modernize function signatures in the streaming decompressor interface and its implementations to align with the latest C++ coding guidelines. (#702)
1 parent e9d6d1a commit 121b717

File tree

7 files changed

+76
-53
lines changed

7 files changed

+76
-53
lines changed

components/core/src/clp/WriterInterface.hpp

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class WriterInterface {
2121
char const* what() const noexcept override { return "WriterInterface operation failed"; }
2222
};
2323

24+
// Destructor
25+
virtual ~WriterInterface() = default;
26+
2427
// Methods
2528
/**
2629
* Writes the given data to the underlying medium

components/core/src/clp/streaming_compression/Compressor.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class Compressor : public WriterInterface {
3232
Compressor() = default;
3333

3434
// Destructor
35-
virtual ~Compressor() = default;
35+
~Compressor() override = default;
3636

3737
// Delete copy constructor and assignment operator
3838
Compressor(Compressor const&) = delete;

components/core/src/clp/streaming_compression/Decompressor.hpp

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Decompressor : public ReaderInterface {
1818
: TraceableException(error_code, filename, line_number) {}
1919

2020
// Methods
21-
char const* what() const noexcept override {
21+
[[nodiscard]] auto what() const noexcept -> char const* override {
2222
return "streaming_compression::Decompressor operation failed";
2323
}
2424
};
@@ -27,35 +27,42 @@ class Decompressor : public ReaderInterface {
2727
explicit Decompressor(CompressorType type) : m_compression_type(type) {}
2828

2929
// Destructor
30-
~Decompressor() = default;
30+
~Decompressor() override = default;
3131

32-
// Explicitly disable copy and move constructor/assignment
32+
// Delete copy constructor and assignment operator
3333
Decompressor(Decompressor const&) = delete;
34-
Decompressor& operator=(Decompressor const&) = delete;
34+
auto operator=(Decompressor const&) -> Decompressor& = delete;
35+
36+
// Default move constructor and assignment operator
37+
Decompressor(Decompressor&&) noexcept = default;
38+
auto operator=(Decompressor&&) noexcept -> Decompressor& = default;
3539

3640
// Methods
3741
/**
3842
* Initialize streaming decompressor to decompress from the specified compressed data buffer
3943
* @param compressed_data_buffer
4044
* @param compressed_data_buffer_size
4145
*/
42-
virtual void open(char const* compressed_data_buffer, size_t compressed_data_buffer_size) = 0;
46+
virtual auto open(char const* compressed_data_buffer, size_t compressed_data_buffer_size)
47+
-> void
48+
= 0;
4349
/**
4450
* Initializes the decompressor to decompress from a reader interface
4551
* @param reader
4652
* @param read_buffer_capacity The maximum amount of data to read from a reader at a time
4753
*/
48-
virtual void open(ReaderInterface& reader, size_t read_buffer_capacity) = 0;
54+
virtual auto open(ReaderInterface& reader, size_t read_buffer_capacity) -> void = 0;
4955
/**
5056
* Closes decompression stream
5157
*/
52-
virtual void close() = 0;
58+
virtual auto close() -> void = 0;
5359

54-
virtual ErrorCode get_decompressed_stream_region(
60+
[[nodiscard]] virtual auto get_decompressed_stream_region(
5561
size_t decompressed_stream_pos,
5662
char* extraction_buf,
5763
size_t extraction_len
58-
) = 0;
64+
) -> ErrorCode
65+
= 0;
5966

6067
protected:
6168
// Variables

components/core/src/clp/streaming_compression/passthrough/Decompressor.cpp

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
#include <cstring>
44

55
namespace clp::streaming_compression::passthrough {
6-
ErrorCode Decompressor::try_read(char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) {
6+
auto Decompressor::try_read(char* buf, size_t num_bytes_to_read, size_t& num_bytes_read)
7+
-> ErrorCode {
78
if (InputType::NotInitialized == m_input_type) {
89
throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__);
910
}
@@ -38,7 +39,7 @@ ErrorCode Decompressor::try_read(char* buf, size_t num_bytes_to_read, size_t& nu
3839
return ErrorCode_Success;
3940
}
4041

41-
ErrorCode Decompressor::try_seek_from_begin(size_t pos) {
42+
auto Decompressor::try_seek_from_begin(size_t pos) -> ErrorCode {
4243
if (InputType::NotInitialized == m_input_type) {
4344
throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__);
4445
}
@@ -64,7 +65,7 @@ ErrorCode Decompressor::try_seek_from_begin(size_t pos) {
6465
return ErrorCode_Success;
6566
}
6667

67-
ErrorCode Decompressor::try_get_pos(size_t& pos) {
68+
auto Decompressor::try_get_pos(size_t& pos) -> ErrorCode {
6869
if (InputType::NotInitialized == m_input_type) {
6970
throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__);
7071
}
@@ -74,7 +75,7 @@ ErrorCode Decompressor::try_get_pos(size_t& pos) {
7475
return ErrorCode_Success;
7576
}
7677

77-
void Decompressor::open(char const* compressed_data_buf, size_t compressed_data_buf_size) {
78+
auto Decompressor::open(char const* compressed_data_buf, size_t compressed_data_buf_size) -> void {
7879
if (InputType::NotInitialized != m_input_type) {
7980
throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__);
8081
}
@@ -85,7 +86,8 @@ void Decompressor::open(char const* compressed_data_buf, size_t compressed_data_
8586
m_input_type = InputType::CompressedDataBuf;
8687
}
8788

88-
void Decompressor::open(ReaderInterface& reader, size_t read_buffer_capacity) {
89+
auto Decompressor::open(ReaderInterface& reader, [[maybe_unused]] size_t read_buffer_capacity)
90+
-> void {
8991
if (InputType::NotInitialized != m_input_type) {
9092
throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__);
9193
}
@@ -95,7 +97,7 @@ void Decompressor::open(ReaderInterface& reader, size_t read_buffer_capacity) {
9597
m_input_type = InputType::ReaderInterface;
9698
}
9799

98-
void Decompressor::close() {
100+
auto Decompressor::close() -> void {
99101
switch (m_input_type) {
100102
case InputType::CompressedDataBuf:
101103
m_compressed_data_buf = nullptr;
@@ -113,11 +115,11 @@ void Decompressor::close() {
113115
m_input_type = InputType::NotInitialized;
114116
}
115117

116-
ErrorCode Decompressor::get_decompressed_stream_region(
118+
auto Decompressor::get_decompressed_stream_region(
117119
size_t decompressed_stream_pos,
118120
char* extraction_buf,
119121
size_t extraction_len
120-
) {
122+
) -> ErrorCode {
121123
auto error_code = try_seek_from_begin(decompressed_stream_pos);
122124
if (ErrorCode_Success != error_code) {
123125
return error_code;

components/core/src/clp/streaming_compression/passthrough/Decompressor.hpp

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
1919
: TraceableException(error_code, filename, line_number) {}
2020

2121
// Methods
22-
char const* what() const noexcept override {
22+
[[nodiscard]] auto what() const noexcept -> char const* override {
2323
return "streaming_compression::passthrough::Decompressor operation failed";
2424
}
2525
};
@@ -33,11 +33,15 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
3333
m_decompressed_stream_pos(0) {}
3434

3535
// Destructor
36-
~Decompressor() = default;
36+
~Decompressor() override = default;
3737

38-
// Explicitly disable copy and move constructor/assignment
38+
// Delete copy constructor and assignment operator
3939
Decompressor(Decompressor const&) = delete;
40-
Decompressor& operator=(Decompressor const&) = delete;
40+
auto operator=(Decompressor const&) -> Decompressor& = delete;
41+
42+
// Default move constructor and assignment operator
43+
Decompressor(Decompressor&&) noexcept = default;
44+
auto operator=(Decompressor&&) noexcept -> Decompressor& = default;
4145

4246
// Methods implementing the ReaderInterface
4347
/**
@@ -50,27 +54,28 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
5054
* @return ErrorCode_EndOfFile on EOF
5155
* @return ErrorCode_Success on success
5256
*/
53-
ErrorCode try_read(char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) override;
57+
[[nodiscard]] auto try_read(char* buf, size_t num_bytes_to_read, size_t& num_bytes_read)
58+
-> ErrorCode override;
5459
/**
5560
* Tries to seek from the beginning to the given position
5661
* @param pos
5762
* @return ErrorCode_NotInit if the decompressor is not open
5863
* @return ErrorCode_Truncated if the position is past the last byte in the file
5964
* @return ErrorCode_Success on success
6065
*/
61-
ErrorCode try_seek_from_begin(size_t pos) override;
66+
[[nodiscard]] auto try_seek_from_begin(size_t pos) -> ErrorCode override;
6267
/**
6368
* Tries to get the current position of the read head
6469
* @param pos Position of the read head in the file
6570
* @return ErrorCode_NotInit if the decompressor is not open
6671
* @return ErrorCode_Success on success
6772
*/
68-
ErrorCode try_get_pos(size_t& pos) override;
73+
[[nodiscard]] auto try_get_pos(size_t& pos) -> ErrorCode override;
6974

7075
// Methods implementing the Decompressor interface
71-
void open(char const* compressed_data_buf, size_t compressed_data_buf_size) override;
72-
void open(ReaderInterface& reader, size_t read_buffer_capacity) override;
73-
void close() override;
76+
auto open(char const* compressed_data_buf, size_t compressed_data_buf_size) -> void override;
77+
auto open(ReaderInterface& reader, size_t read_buffer_capacity) -> void override;
78+
auto close() -> void override;
7479
/**
7580
* Decompresses and copies the range of uncompressed data described by
7681
* decompressed_stream_pos and extraction_len into extraction_buf
@@ -80,11 +85,11 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
8085
* @return Same as streaming_compression::passthrough::Decompressor::try_seek_from_begin
8186
* @return Same as ReaderInterface::try_read_exact_length
8287
*/
83-
ErrorCode get_decompressed_stream_region(
88+
[[nodiscard]] auto get_decompressed_stream_region(
8489
size_t decompressed_stream_pos,
8590
char* extraction_buf,
8691
size_t extraction_len
87-
) override;
92+
) -> ErrorCode override;
8893

8994
private:
9095
enum class InputType {

components/core/src/clp/streaming_compression/zstd/Decompressor.cpp

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ Decompressor::~Decompressor() {
2323
ZSTD_freeDStream(m_decompression_stream);
2424
}
2525

26-
ErrorCode Decompressor::try_read(char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) {
26+
auto Decompressor::try_read(char* buf, size_t num_bytes_to_read, size_t& num_bytes_read)
27+
-> ErrorCode {
2728
if (InputType::NotInitialized == m_input_type) {
2829
throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__);
2930
}
@@ -103,7 +104,7 @@ ErrorCode Decompressor::try_read(char* buf, size_t num_bytes_to_read, size_t& nu
103104
return ErrorCode_Success;
104105
}
105106

106-
ErrorCode Decompressor::try_seek_from_begin(size_t pos) {
107+
auto Decompressor::try_seek_from_begin(size_t pos) -> ErrorCode {
107108
if (InputType::NotInitialized == m_input_type) {
108109
throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__);
109110
}
@@ -134,7 +135,7 @@ ErrorCode Decompressor::try_seek_from_begin(size_t pos) {
134135
return ErrorCode_Success;
135136
}
136137

137-
ErrorCode Decompressor::try_get_pos(size_t& pos) {
138+
auto Decompressor::try_get_pos(size_t& pos) -> ErrorCode {
138139
if (InputType::NotInitialized == m_input_type) {
139140
throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__);
140141
}
@@ -143,7 +144,7 @@ ErrorCode Decompressor::try_get_pos(size_t& pos) {
143144
return ErrorCode_Success;
144145
}
145146

146-
void Decompressor::open(char const* compressed_data_buf, size_t compressed_data_buf_size) {
147+
auto Decompressor::open(char const* compressed_data_buf, size_t compressed_data_buf_size) -> void {
147148
if (InputType::NotInitialized != m_input_type) {
148149
throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__);
149150
}
@@ -154,7 +155,7 @@ void Decompressor::open(char const* compressed_data_buf, size_t compressed_data_
154155
reset_stream();
155156
}
156157

157-
void Decompressor::open(ReaderInterface& reader, size_t read_buffer_capacity) {
158+
auto Decompressor::open(ReaderInterface& reader, size_t read_buffer_capacity) -> void {
158159
if (InputType::NotInitialized != m_input_type) {
159160
throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__);
160161
}
@@ -175,7 +176,7 @@ void Decompressor::open(ReaderInterface& reader, size_t read_buffer_capacity) {
175176
reset_stream();
176177
}
177178

178-
void Decompressor::close() {
179+
auto Decompressor::close() -> void {
179180
switch (m_input_type) {
180181
case InputType::MemoryMappedCompressedFile:
181182
m_memory_mapped_file.reset();
@@ -195,7 +196,7 @@ void Decompressor::close() {
195196
m_input_type = InputType::NotInitialized;
196197
}
197198

198-
ErrorCode Decompressor::open(std::string const& compressed_file_path) {
199+
auto Decompressor::open(std::string const& compressed_file_path) -> ErrorCode {
199200
if (InputType::NotInitialized != m_input_type) {
200201
throw OperationFailed(ErrorCode_NotReady, __FILENAME__, __LINE__);
201202
}
@@ -213,11 +214,11 @@ ErrorCode Decompressor::open(std::string const& compressed_file_path) {
213214
return ErrorCode_Success;
214215
}
215216

216-
ErrorCode Decompressor::get_decompressed_stream_region(
217+
auto Decompressor::get_decompressed_stream_region(
217218
size_t decompressed_stream_pos,
218219
char* extraction_buf,
219220
size_t extraction_len
220-
) {
221+
) -> ErrorCode {
221222
auto error_code = try_seek_from_begin(decompressed_stream_pos);
222223
if (ErrorCode_Success != error_code) {
223224
return error_code;
@@ -227,7 +228,7 @@ ErrorCode Decompressor::get_decompressed_stream_region(
227228
return error_code;
228229
}
229230

230-
void Decompressor::reset_stream() {
231+
auto Decompressor::reset_stream() -> void {
231232
if (InputType::ReaderInterface == m_input_type) {
232233
if (auto const rc = m_reader->try_seek_from_begin(m_reader_initial_pos);
233234
false == (ErrorCode_Success == rc || ErrorCode_EndOfFile == rc))

components/core/src/clp/streaming_compression/zstd/Decompressor.hpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
2424
: TraceableException(error_code, filename, line_number) {}
2525

2626
// Methods
27-
char const* what() const noexcept override {
27+
[[nodiscard]] auto what() const noexcept -> char const* override {
2828
return "streaming_compression::zstd::Decompressor operation failed";
2929
}
3030
};
@@ -37,11 +37,15 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
3737
Decompressor();
3838

3939
// Destructor
40-
~Decompressor();
40+
~Decompressor() override;
4141

42-
// Explicitly disable copy and move constructor/assignment
42+
// Delete copy constructor and assignment operator
4343
Decompressor(Decompressor const&) = delete;
44-
Decompressor& operator=(Decompressor const&) = delete;
44+
auto operator=(Decompressor const&) -> Decompressor& = delete;
45+
46+
// Default move constructor and assignment operator
47+
Decompressor(Decompressor&&) noexcept = default;
48+
auto operator=(Decompressor&&) noexcept -> Decompressor& = default;
4549

4650
// Methods implementing the ReaderInterface
4751
/**
@@ -56,27 +60,28 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
5660
* @return ErrorCode_Failure on decompression failure
5761
* @return ErrorCode_Success on success
5862
*/
59-
ErrorCode try_read(char* buf, size_t num_bytes_to_read, size_t& num_bytes_read) override;
63+
[[nodiscard]] auto try_read(char* buf, size_t num_bytes_to_read, size_t& num_bytes_read)
64+
-> ErrorCode override;
6065
/**
6166
* Tries to seek from the beginning to the given position
6267
* @param pos
6368
* @return ErrorCode_NotInit if the decompressor is not open
6469
* @return Same as ReaderInterface::try_read_exact_length
6570
* @return ErrorCode_Success on success
6671
*/
67-
ErrorCode try_seek_from_begin(size_t pos) override;
72+
[[nodiscard]] auto try_seek_from_begin(size_t pos) -> ErrorCode override;
6873
/**
6974
* Tries to get the current position of the read head
7075
* @param pos Position of the read head in the file
7176
* @return ErrorCode_NotInit if the decompressor is not open
7277
* @return ErrorCode_Success on success
7378
*/
74-
ErrorCode try_get_pos(size_t& pos) override;
79+
[[nodiscard]] auto try_get_pos(size_t& pos) -> ErrorCode override;
7580

7681
// Methods implementing the Decompressor interface
77-
void open(char const* compressed_data_buf, size_t compressed_data_buf_size) override;
78-
void open(ReaderInterface& reader, size_t read_buffer_capacity) override;
79-
void close() override;
82+
auto open(char const* compressed_data_buf, size_t compressed_data_buf_size) -> void override;
83+
auto open(ReaderInterface& reader, size_t read_buffer_capacity) -> void override;
84+
auto close() -> void override;
8085
/**
8186
* Decompresses and copies the range of uncompressed data described by
8287
* decompressed_stream_pos and extraction_len into extraction_buf
@@ -86,11 +91,11 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
8691
* @return Same as streaming_compression::zstd::Decompressor::try_seek_from_begin
8792
* @return Same as ReaderInterface::try_read_exact_length
8893
*/
89-
ErrorCode get_decompressed_stream_region(
94+
[[nodiscard]] auto get_decompressed_stream_region(
9095
size_t decompressed_stream_pos,
9196
char* extraction_buf,
9297
size_t extraction_len
93-
) override;
98+
) -> ErrorCode override;
9499

95100
// Methods
96101
/***
@@ -101,7 +106,7 @@ class Decompressor : public ::clp::streaming_compression::Decompressor {
101106
* @return ErrorCode_Failure if the provided path cannot be memory mapped
102107
* @return ErrorCode_Success on success
103108
*/
104-
ErrorCode open(std::string const& compressed_file_path);
109+
[[nodiscard]] auto open(std::string const& compressed_file_path) -> ErrorCode;
105110

106111
private:
107112
// Enum class

0 commit comments

Comments
 (0)