Skip to content

Commit

Permalink
Clang-tidy all compressor/constant files in streaming compression and…
Browse files Browse the repository at this point in the history
… unit test
  • Loading branch information
Bill-hbrhbr committed Nov 19, 2024
1 parent d969aaf commit 7f55892
Show file tree
Hide file tree
Showing 9 changed files with 214 additions and 287 deletions.
1 change: 1 addition & 0 deletions components/core/src/clp/TraceableException.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class TraceableException : public std::exception {
// Macros
// Define a version of __FILE__ that's relative to the source directory
#ifdef SOURCE_PATH_SIZE
// NOLINTNEXTLINE
#define __FILENAME__ ((__FILE__) + SOURCE_PATH_SIZE)
#else
// We don't know the source path size, so just default to __FILE__
Expand Down
41 changes: 31 additions & 10 deletions components/core/src/clp/streaming_compression/Compressor.hpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,20 @@
#ifndef CLP_STREAMING_COMPRESSION_COMPRESSOR_HPP
#define CLP_STREAMING_COMPRESSION_COMPRESSOR_HPP

#include <cstdint>
#include <string>
#include <sys/types.h>

#include <cstddef>

#include "../ErrorCode.hpp"
#include "../FileWriter.hpp"
#include "../TraceableException.hpp"
#include "../WriterInterface.hpp"
#include "Constants.hpp"

namespace clp::streaming_compression {
/**
* Generic compressor interface.
*/
class Compressor : public WriterInterface {
public:
// Types
Expand All @@ -19,7 +25,7 @@ class Compressor : public WriterInterface {
: TraceableException(error_code, filename, line_number) {}

// Methods
char const* what() const noexcept override {
[[nodiscard]] auto what() const noexcept -> char const* override {
return "streaming_compression::Compressor operation failed";
}
};
Expand All @@ -30,34 +36,49 @@ class Compressor : public WriterInterface {
// Destructor
virtual ~Compressor() = default;

// Explicitly disable copy and move constructor/assignment
// Explicitly disable copy constructor/assignment and enable the move version
Compressor(Compressor const&) = delete;
Compressor& operator=(Compressor const&) = delete;
auto operator=(Compressor const&) -> Compressor& = delete;

Compressor(Compressor&&) noexcept = default;
auto operator=(Compressor&&) -> Compressor& = default;

// Methods implementing the WriterInterface
/**
* Unsupported operation
* @param pos
* @return ErrorCode_Unsupported
*/
ErrorCode try_seek_from_begin(size_t pos) override { return ErrorCode_Unsupported; }
[[nodiscard]] auto try_seek_from_begin([[maybe_unused]] size_t pos) -> ErrorCode override {
return ErrorCode_Unsupported;
}

/**
* Unsupported operation
* @param pos
* @return ErrorCode_Unsupported
*/
ErrorCode try_seek_from_current(off_t offset) override { return ErrorCode_Unsupported; }
[[nodiscard]] auto try_seek_from_current([[maybe_unused]] off_t offset) -> ErrorCode override {
return ErrorCode_Unsupported;
}

// Methods
/**
* Closes the compression stream
*/
virtual void close() = 0;
virtual auto close() -> void = 0;

/**
* Initializes the compression stream with the given compression level
* @param file_writer
* @param compression_level
*/
virtual auto open(FileWriter& file_writer, [[maybe_unused]] int compression_level = 0) -> void
= 0;

protected:
private:
// Variables
CompressorType m_type;
CompressorType m_type{};
};
} // namespace clp::streaming_compression

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#ifndef CLP_STREAMING_COMPRESSION_CONSTANTS_HPP
#define CLP_STREAMING_COMPRESSION_CONSTANTS_HPP

#include <cstddef>
#include <cstdint>

namespace clp::streaming_compression {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#include "Compressor.hpp"

#include "../../Defs.h"
#include <cstddef>

#include "../../ErrorCode.hpp"
#include "../../TraceableException.hpp"

namespace clp::streaming_compression::passthrough {
void Compressor::write(char const* data, size_t const data_length) {
auto Compressor::write(char const* data, size_t const data_length) -> void {
if (nullptr == m_compressed_stream_file_writer) {
throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__);
}
Expand All @@ -19,27 +22,27 @@ void Compressor::write(char const* data, size_t const data_length) {
m_compressed_stream_file_writer->write(data, data_length);
}

void Compressor::flush() {
auto Compressor::flush() -> void {
if (nullptr == m_compressed_stream_file_writer) {
throw OperationFailed(ErrorCode_NotInit, __FILENAME__, __LINE__);
}

m_compressed_stream_file_writer->flush();
}

ErrorCode Compressor::try_get_pos(size_t& pos) const {
auto Compressor::try_get_pos(size_t& pos) const -> ErrorCode {
if (nullptr == m_compressed_stream_file_writer) {
return ErrorCode_NotInit;
}

return m_compressed_stream_file_writer->try_get_pos(pos);
}

void Compressor::close() {
auto Compressor::close() -> void {
m_compressed_stream_file_writer = nullptr;
}

void Compressor::open(FileWriter& file_writer) {
auto Compressor::open(FileWriter& file_writer, [[maybe_unused]] int compression_level) -> void {
m_compressed_stream_file_writer = &file_writer;
}
} // namespace clp::streaming_compression::passthrough
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#ifndef CLP_STREAMING_COMPRESSION_PASSTHROUGH_COMPRESSOR_HPP
#define CLP_STREAMING_COMPRESSION_PASSTHROUGH_COMPRESSOR_HPP

#include <cstddef>

#include "../../ErrorCode.hpp"
#include "../../FileWriter.hpp"
#include "../../TraceableException.hpp"
#include "../Compressor.hpp"
#include "../Constants.hpp"

namespace clp::streaming_compression::passthrough {
/**
Expand All @@ -19,55 +23,61 @@ class Compressor : public ::clp::streaming_compression::Compressor {
: TraceableException(error_code, filename, line_number) {}

// Methods
char const* what() const noexcept override {
[[nodiscard]] auto what() const noexcept -> char const* override {
return "streaming_compression::passthrough::Compressor operation failed";
}
};

// Constructors
Compressor()
: ::clp::streaming_compression::Compressor(CompressorType::Passthrough),
m_compressed_stream_file_writer(nullptr) {}
Compressor() : ::clp::streaming_compression::Compressor{CompressorType::Passthrough} {}

// Destructor
~Compressor() override = default;

// Explicitly disable copy and move constructor/assignment
// Explicitly disable copy constructor/assignment and enable the move version
Compressor(Compressor const&) = delete;
Compressor& operator=(Compressor const&) = delete;
auto operator=(Compressor const&) -> Compressor& = delete;

Compressor(Compressor&&) noexcept = default;
auto operator=(Compressor&&) -> Compressor& = default;

// Methods implementing the WriterInterface
/**
* Writes the given data to the compressor
* @param data
* @param data_length
*/
void write(char const* data, size_t data_length) override;
auto write(char const* data, size_t data_length) -> void override;

/**
* Flushes any buffered data
*/
void flush() override;
auto flush() -> void override;

/**
* Tries to get the current position of the write head
* @param pos Position of the write head
* @return ErrorCode_NotInit if the compressor is not open
* @return Same as FileWriter::try_get_pos
*/
ErrorCode try_get_pos(size_t& pos) const override;
[[nodiscard]] auto try_get_pos(size_t& pos) const -> ErrorCode override;

// Methods implementing the Compressor interface
/**
* Closes the compressor
*/
void close() override;
auto close() -> void override;

// Methods
/**
* Initializes the compressor
* Initializes the compression stream
* @param file_writer
* @param compression_level
*/
void open(FileWriter& file_writer);
auto open(FileWriter& file_writer, [[maybe_unused]] int compression_level = 0) -> void override;

private:
// Variables
FileWriter* m_compressed_stream_file_writer;
FileWriter* m_compressed_stream_file_writer{nullptr};
};
} // namespace clp::streaming_compression::passthrough

Expand Down
Loading

0 comments on commit 7f55892

Please sign in to comment.