Skip to content

Commit 7aea626

Browse files
refactor(core): Fix clang-tidy warnings in the streaming compressor interface and its implementations; Modernize and refactor test-StreamingCompression for conciseness. (#599)
Co-authored-by: Bingran Hu <[email protected]> Co-authored-by: Lin Zhihao <[email protected]>
1 parent a864e42 commit 7aea626

File tree

8 files changed

+225
-303
lines changed

8 files changed

+225
-303
lines changed

components/core/src/clp/TraceableException.hpp

+1
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class TraceableException : public std::exception {
3939
// Macros
4040
// Define a version of __FILE__ that's relative to the source directory
4141
#ifdef SOURCE_PATH_SIZE
42+
// NOLINTNEXTLINE
4243
#define __FILENAME__ ((__FILE__) + SOURCE_PATH_SIZE)
4344
#else
4445
// We don't know the source path size, so just default to __FILE__

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

+30-15
Original file line numberDiff line numberDiff line change
@@ -1,63 +1,78 @@
11
#ifndef CLP_STREAMING_COMPRESSION_COMPRESSOR_HPP
22
#define CLP_STREAMING_COMPRESSION_COMPRESSOR_HPP
33

4-
#include <cstdint>
5-
#include <string>
4+
#include <sys/types.h>
65

6+
#include <cstddef>
7+
8+
#include "../ErrorCode.hpp"
9+
#include "../FileWriter.hpp"
710
#include "../TraceableException.hpp"
811
#include "../WriterInterface.hpp"
9-
#include "Constants.hpp"
1012

1113
namespace clp::streaming_compression {
14+
/**
15+
* Abstract compressor interface.
16+
*/
1217
class Compressor : public WriterInterface {
1318
public:
1419
// Types
1520
class OperationFailed : public TraceableException {
1621
public:
1722
// Constructors
1823
OperationFailed(ErrorCode error_code, char const* const filename, int line_number)
19-
: TraceableException(error_code, filename, line_number) {}
24+
: TraceableException{error_code, filename, line_number} {}
2025

2126
// Methods
22-
char const* what() const noexcept override {
27+
[[nodiscard]] auto what() const noexcept -> char const* override {
2328
return "streaming_compression::Compressor operation failed";
2429
}
2530
};
2631

2732
// Constructor
28-
explicit Compressor(CompressorType type) : m_type(type) {}
33+
Compressor() = default;
2934

3035
// Destructor
3136
virtual ~Compressor() = default;
3237

33-
// Explicitly disable copy and move constructor/assignment
38+
// Delete copy constructor and assignment operator
3439
Compressor(Compressor const&) = delete;
35-
Compressor& operator=(Compressor const&) = delete;
40+
auto operator=(Compressor const&) -> Compressor& = delete;
41+
42+
// Default move constructor and assignment operator
43+
Compressor(Compressor&&) noexcept = default;
44+
auto operator=(Compressor&&) noexcept -> Compressor& = default;
3645

3746
// Methods implementing the WriterInterface
3847
/**
3948
* Unsupported operation
4049
* @param pos
4150
* @return ErrorCode_Unsupported
4251
*/
43-
ErrorCode try_seek_from_begin(size_t pos) override { return ErrorCode_Unsupported; }
52+
[[nodiscard]] auto try_seek_from_begin([[maybe_unused]] size_t pos) -> ErrorCode override {
53+
return ErrorCode_Unsupported;
54+
}
4455

4556
/**
4657
* Unsupported operation
4758
* @param pos
4859
* @return ErrorCode_Unsupported
4960
*/
50-
ErrorCode try_seek_from_current(off_t offset) override { return ErrorCode_Unsupported; }
61+
[[nodiscard]] auto try_seek_from_current([[maybe_unused]] off_t offset) -> ErrorCode override {
62+
return ErrorCode_Unsupported;
63+
}
5164

5265
// Methods
5366
/**
54-
* Closes the compression stream
67+
* Closes the compressor
5568
*/
56-
virtual void close() = 0;
69+
virtual auto close() -> void = 0;
5770

58-
protected:
59-
// Variables
60-
CompressorType m_type;
71+
/**
72+
* Initializes the compression stream
73+
* @param file_writer
74+
*/
75+
virtual auto open(FileWriter& file_writer) -> void = 0;
6176
};
6277
} // namespace clp::streaming_compression
6378

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

+9-6
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
11
#include "Compressor.hpp"
22

3-
#include "../../Defs.h"
3+
#include <cstddef>
4+
5+
#include "../../ErrorCode.hpp"
6+
#include "../../TraceableException.hpp"
47

58
namespace clp::streaming_compression::passthrough {
6-
void Compressor::write(char const* data, size_t const data_length) {
9+
auto Compressor::write(char const* data, size_t const data_length) -> void {
710
if (nullptr == m_compressed_stream_file_writer) {
811
throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__);
912
}
@@ -19,27 +22,27 @@ void Compressor::write(char const* data, size_t const data_length) {
1922
m_compressed_stream_file_writer->write(data, data_length);
2023
}
2124

22-
void Compressor::flush() {
25+
auto Compressor::flush() -> void {
2326
if (nullptr == m_compressed_stream_file_writer) {
2427
throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__);
2528
}
2629

2730
m_compressed_stream_file_writer->flush();
2831
}
2932

30-
ErrorCode Compressor::try_get_pos(size_t& pos) const {
33+
auto Compressor::try_get_pos(size_t& pos) const -> ErrorCode {
3134
if (nullptr == m_compressed_stream_file_writer) {
3235
return ErrorCode_NotInit;
3336
}
3437

3538
return m_compressed_stream_file_writer->try_get_pos(pos);
3639
}
3740

38-
void Compressor::close() {
41+
auto Compressor::close() -> void {
3942
m_compressed_stream_file_writer = nullptr;
4043
}
4144

42-
void Compressor::open(FileWriter& file_writer) {
45+
auto Compressor::open(FileWriter& file_writer) -> void {
4346
m_compressed_stream_file_writer = &file_writer;
4447
}
4548
} // namespace clp::streaming_compression::passthrough

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

+25-16
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
#ifndef CLP_STREAMING_COMPRESSION_PASSTHROUGH_COMPRESSOR_HPP
22
#define CLP_STREAMING_COMPRESSION_PASSTHROUGH_COMPRESSOR_HPP
33

4+
#include <cstddef>
5+
6+
#include "../../ErrorCode.hpp"
47
#include "../../FileWriter.hpp"
58
#include "../../TraceableException.hpp"
69
#include "../Compressor.hpp"
@@ -16,58 +19,64 @@ class Compressor : public ::clp::streaming_compression::Compressor {
1619
public:
1720
// Constructors
1821
OperationFailed(ErrorCode error_code, char const* const filename, int line_number)
19-
: TraceableException(error_code, filename, line_number) {}
22+
: TraceableException{error_code, filename, line_number} {}
2023

2124
// Methods
22-
char const* what() const noexcept override {
25+
[[nodiscard]] auto what() const noexcept -> char const* override {
2326
return "streaming_compression::passthrough::Compressor operation failed";
2427
}
2528
};
2629

27-
// Constructors
28-
Compressor()
29-
: ::clp::streaming_compression::Compressor(CompressorType::Passthrough),
30-
m_compressed_stream_file_writer(nullptr) {}
30+
// Constructor
31+
Compressor() = default;
32+
33+
// Destructor
34+
~Compressor() override = default;
3135

32-
// Explicitly disable copy and move constructor/assignment
36+
// Delete copy constructor and assignment operator
3337
Compressor(Compressor const&) = delete;
34-
Compressor& operator=(Compressor const&) = delete;
38+
auto operator=(Compressor const&) -> Compressor& = delete;
39+
40+
// Default move constructor and assignment operator
41+
Compressor(Compressor&&) noexcept = default;
42+
auto operator=(Compressor&&) noexcept -> Compressor& = default;
3543

3644
// Methods implementing the WriterInterface
3745
/**
3846
* Writes the given data to the compressor
3947
* @param data
4048
* @param data_length
4149
*/
42-
void write(char const* data, size_t data_length) override;
50+
auto write(char const* data, size_t data_length) -> void override;
51+
4352
/**
4453
* Flushes any buffered data
4554
*/
46-
void flush() override;
55+
auto flush() -> void override;
56+
4757
/**
4858
* Tries to get the current position of the write head
4959
* @param pos Position of the write head
5060
* @return ErrorCode_NotInit if the compressor is not open
5161
* @return Same as FileWriter::try_get_pos
5262
*/
53-
ErrorCode try_get_pos(size_t& pos) const override;
63+
[[nodiscard]] auto try_get_pos(size_t& pos) const -> ErrorCode override;
5464

5565
// Methods implementing the Compressor interface
5666
/**
5767
* Closes the compressor
5868
*/
59-
void close() override;
69+
auto close() -> void override;
6070

61-
// Methods
6271
/**
63-
* Initializes the compressor
72+
* Initializes the compression stream
6473
* @param file_writer
6574
*/
66-
void open(FileWriter& file_writer);
75+
auto open(FileWriter& file_writer) -> void override;
6776

6877
private:
6978
// Variables
70-
FileWriter* m_compressed_stream_file_writer;
79+
FileWriter* m_compressed_stream_file_writer{nullptr};
7180
};
7281
} // namespace clp::streaming_compression::passthrough
7382

0 commit comments

Comments
 (0)