Skip to content

Commit

Permalink
eckit::codec update to new .clang-format
Browse files Browse the repository at this point in the history
  • Loading branch information
Pedro Maciel committed Nov 16, 2023
1 parent c34dd3f commit 0c58e27
Show file tree
Hide file tree
Showing 26 changed files with 107 additions and 177 deletions.
3 changes: 1 addition & 2 deletions src/eckit/codec/Data.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ namespace eckit::codec {

//---------------------------------------------------------------------------------------------------------------------

Data::Data(void* p, size_t size) :
buffer_(p, size), size_(size) {}
Data::Data(void* p, size_t size) : buffer_(p, size), size_(size) {}

std::uint64_t Data::write(Stream& out) const {
if (size() > 0) {
Expand Down
6 changes: 3 additions & 3 deletions src/eckit/codec/Exceptions.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@

#include "eckit/codec/detail/demangle.h"

namespace eckit::codec{
namespace eckit::codec {

//---------------------------------------------------------------------------------------------------------------------

NotEncodable::NotEncodable(const std::string& type_name):
NotEncodable::NotEncodable(const std::string& type_name) :
Exception{[&type_name] {
std::stringstream message;
message << "eckit::codec::NotEncodable: Cannot encode values of type " << type_name << ".";
Expand All @@ -42,7 +42,7 @@ NotEncodable::NotEncodable(const std::string& type_name):

//---------------------------------------------------------------------------------------------------------------------

NotDecodable::NotDecodable(const std::string& type_name):
NotDecodable::NotDecodable(const std::string& type_name) :
Exception{[&type_name] {
std::stringstream message;
message << "eckit::codec::NotDecodable: Cannot decode values of type " << type_name << ".";
Expand Down
12 changes: 6 additions & 6 deletions src/eckit/codec/Exceptions.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@
#include <type_traits>
#include <typeinfo>

#include "eckit/exception/Exceptions.h"
#include "eckit/codec/detail/demangle.h"
#include "eckit/exception/Exceptions.h"

namespace eckit::codec {

Expand All @@ -34,7 +34,7 @@ class NotEncodable : Exception {
NotEncodable(const std::string& type_name);

template <typename T>
NotEncodable(const T&): NotEncodable{demangle<typename std::decay<T>::type>()} {}
NotEncodable(const T&) : NotEncodable{demangle<typename std::decay<T>::type>()} {}

~NotEncodable() override;
};
Expand All @@ -46,7 +46,7 @@ class NotDecodable : public Exception {
NotDecodable(const std::string& type_name);

template <typename T>
NotDecodable(const T&): NotDecodable{demangle<typename std::decay<T>::type>()} {}
NotDecodable(const T&) : NotDecodable{demangle<typename std::decay<T>::type>()} {}

~NotDecodable() override;
};
Expand All @@ -55,7 +55,7 @@ class NotDecodable : public Exception {

class InvalidRecord : public Exception {
public:
InvalidRecord(const std::string& message): Exception("eckit::codec::InvalidRecord: " + message) {}
InvalidRecord(const std::string& message) : Exception("eckit::codec::InvalidRecord: " + message) {}

~InvalidRecord() override;
};
Expand All @@ -64,7 +64,7 @@ class InvalidRecord : public Exception {

class DataCorruption : public Exception {
public:
DataCorruption(const std::string& message): Exception("eckit::codec::DataCorruption: " + message) {}
DataCorruption(const std::string& message) : Exception("eckit::codec::DataCorruption: " + message) {}

~DataCorruption() override;
};
Expand All @@ -73,7 +73,7 @@ class DataCorruption : public Exception {

class WriteError : public Exception {
public:
WriteError(const std::string& message): Exception("eckit::codec::WriteError: " + message) {}
WriteError(const std::string& message) : Exception("eckit::codec::WriteError: " + message) {}

~WriteError() override;
};
Expand Down
40 changes: 14 additions & 26 deletions src/eckit/codec/FileStream.cc
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@ namespace {
/// * append: for appending implemented via write and seek to eof.
class FileHandle : public eckit::FileHandle {
public:
FileHandle(const PathName& path, char openmode) :
eckit::FileHandle(path, openmode == 'a' /*overwrite*/) {
FileHandle(const PathName& path, char openmode) : eckit::FileHandle(path, openmode == 'a' /*overwrite*/) {
if (openmode == 'r') {
openForRead();
}
Expand All @@ -53,13 +52,11 @@ class FileHandle : public eckit::FileHandle {
}

FileHandle(const PathName& path, Mode openmode) :
FileHandle(path,
openmode == Mode::read ? 'r'
: openmode == Mode::write ? 'w'
: 'a') {}
FileHandle(path, openmode == Mode::read ? 'r'
: openmode == Mode::write ? 'w'
: 'a') {}

FileHandle(const PathName& path, const std::string& openmode) :
FileHandle(path, openmode[0]) {}
FileHandle(const PathName& path, const std::string& openmode) : FileHandle(path, openmode[0]) {}

FileHandle(const FileHandle&) = delete;
FileHandle(FileHandle&&) = delete;
Expand All @@ -85,10 +82,7 @@ class FileHandle : public eckit::FileHandle {
/// - Automatic opening and closing of file
class PooledHandle : public eckit::PooledHandle {
public:
explicit PooledHandle(const PathName& path) :
eckit::PooledHandle(path), path_(path) {
openForRead();
}
explicit PooledHandle(const PathName& path) : eckit::PooledHandle(path), path_(path) { openForRead(); }

PooledHandle(const PooledHandle&) = delete;
PooledHandle(PooledHandle&&) = delete;
Expand All @@ -114,29 +108,23 @@ FileStream::FileStream(const PathName& path, char openmode) :
}

FileStream::FileStream(const PathName& path, Mode openmode) :
FileStream(path,
openmode == Mode::read ? 'r'
: openmode == Mode::write ? 'w'
: 'a') {}
FileStream(path, openmode == Mode::read ? 'r'
: openmode == Mode::write ? 'w'
: 'a') {}

FileStream::FileStream(const PathName& path, const std::string& openmode) :
FileStream(path, openmode[0]) {}
FileStream::FileStream(const PathName& path, const std::string& openmode) : FileStream(path, openmode[0]) {}

//---------------------------------------------------------------------------------------------------------------------

InputFileStream::InputFileStream(const PathName& path) :
FileStream(path, Mode::read) {}
InputFileStream::InputFileStream(const PathName& path) : FileStream(path, Mode::read) {}

//---------------------------------------------------------------------------------------------------------------------

OutputFileStream::OutputFileStream(const PathName& path, Mode openmode) :
FileStream(path, openmode) {}
OutputFileStream::OutputFileStream(const PathName& path, Mode openmode) : FileStream(path, openmode) {}

OutputFileStream::OutputFileStream(const PathName& path, const std::string& openmode) :
FileStream(path, openmode) {}
OutputFileStream::OutputFileStream(const PathName& path, const std::string& openmode) : FileStream(path, openmode) {}

OutputFileStream::OutputFileStream(const PathName& path, char openmode) :
FileStream(path, openmode) {}
OutputFileStream::OutputFileStream(const PathName& path, char openmode) : FileStream(path, openmode) {}

void OutputFileStream::close() {
datahandle().close();
Expand Down
3 changes: 1 addition & 2 deletions src/eckit/codec/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ class Metadata : public LocalConfiguration {
}

/// @brief Constructor starting from a Configuration
Metadata(const Configuration& other) :
LocalConfiguration(other) {}
Metadata(const Configuration& other) : LocalConfiguration(other) {}


Metadata& remove(const std::string& name) {
Expand Down
6 changes: 2 additions & 4 deletions src/eckit/codec/ReadRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,10 @@ class ReadRequest {
ReadRequest{stream, offset, key, new Decoder(value)} {}

template <typename T>
ReadRequest(const std::string& URI, T& value) :
ReadRequest{URI, new Decoder(value)} {}
ReadRequest(const std::string& URI, T& value) : ReadRequest{URI, new Decoder(value)} {}

template <typename T>
ReadRequest(const RecordItem::URI& URI, T& value) :
ReadRequest{URI.str(), value} {}
ReadRequest(const RecordItem::URI& URI, T& value) : ReadRequest{URI.str(), value} {}

ReadRequest() = delete;
ReadRequest(const ReadRequest&) = delete;
Expand Down
32 changes: 15 additions & 17 deletions src/eckit/codec/Record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@

#include "eckit/codec/Record.h"

#include "eckit/codec/Exceptions.h"
#include "eckit/codec/detail/ParsedRecord.h"
#include "eckit/codec/detail/Version.h"
#include "eckit/codec/Exceptions.h"
#include "eckit/config/YAMLConfiguration.h"
#include "eckit/filesystem/URI.h"

Expand Down Expand Up @@ -63,10 +63,7 @@ std::string Record::URI::str() const {

//---------------------------------------------------------------------------------------------------------------------

Record::Record() :
record_(new ParsedRecord()) {}

Record::Record(const Record& other) = default;
Record::Record() : record_(new ParsedRecord()) {}

//---------------------------------------------------------------------------------------------------------------------

Expand Down Expand Up @@ -172,8 +169,9 @@ Record& Record::read(Stream& in, bool read_to_end) {
}

if (r.metadata_length < sizeof(RecordMetadataSection::Begin) + sizeof(RecordMetadataSection::End)) {
throw InvalidRecord("Unexpected metadata section length: " + std::to_string(r.metadata_length) + " < " +
std::to_string(sizeof(RecordMetadataSection::Begin) + sizeof(RecordMetadataSection::End)));
throw InvalidRecord(
"Unexpected metadata section length: " + std::to_string(r.metadata_length) + " < "
+ std::to_string(sizeof(RecordMetadataSection::Begin) + sizeof(RecordMetadataSection::End)));
}

if (r.index_length < sizeof(RecordDataIndexSection::Begin) + sizeof(RecordDataIndexSection::End)) {
Expand All @@ -188,12 +186,12 @@ Record& Record::read(Stream& in, bool read_to_end) {
in.seek(r.metadata_offset);
auto metadata_begin = read_struct<RecordMetadataSection::Begin>(in);
if (not metadata_begin.valid()) {
throw InvalidRecord("Metadata section is not valid. Invalid section begin marker: [" + metadata_begin.str() +
"]");
throw InvalidRecord("Metadata section is not valid. Invalid section begin marker: [" + metadata_begin.str()
+ "]");
}
std::string metadata_str;
metadata_str.resize(static_cast<size_t>(r.metadata_length) - sizeof(RecordMetadataSection::Begin) -
sizeof(RecordMetadataSection::End));
metadata_str.resize(static_cast<size_t>(r.metadata_length) - sizeof(RecordMetadataSection::Begin)
- sizeof(RecordMetadataSection::End));
if (in.read(const_cast<char*>(metadata_str.data()), metadata_str.size()) != metadata_str.size()) {
throw InvalidRecord("Unexpected EOF reached");
}
Expand Down Expand Up @@ -225,11 +223,11 @@ Record& Record::read(Stream& in, bool read_to_end) {
in.seek(r.index_offset);
auto index_begin = read_struct<RecordDataIndexSection::Begin>(in);
if (not index_begin.valid()) {
throw InvalidRecord("Data index section is not valid. Invalid section begin marker: [" + index_begin.str() +
"]");
throw InvalidRecord("Data index section is not valid. Invalid section begin marker: [" + index_begin.str()
+ "]");
}
const auto index_length = (static_cast<size_t>(r.index_length) - sizeof(RecordDataIndexSection::Begin) -
sizeof(RecordDataIndexSection::End));
const auto index_length = (static_cast<size_t>(r.index_length) - sizeof(RecordDataIndexSection::Begin)
- sizeof(RecordDataIndexSection::End));
const auto index_size = index_length / sizeof(RecordDataIndexSection::Entry);
auto& data_sections = record_->data_sections;
data_sections.resize(index_size);
Expand Down Expand Up @@ -277,8 +275,8 @@ void ParsedRecord::parse() {
if (item.data.section() != 0) {
auto& data_section = data_sections.at(static_cast<size_t>(item.data.section() - 1));
item.data.checksum(data_section.checksum);
item.data.compressed_size(data_section.length - sizeof(RecordDataSection::Begin) -
sizeof(RecordDataSection::End));
item.data.compressed_size(data_section.length - sizeof(RecordDataSection::Begin)
- sizeof(RecordDataSection::End));
if (item.data.compressed()) {
item.data.size(uncompressed_size(item));
}
Expand Down
5 changes: 1 addition & 4 deletions src/eckit/codec/Record.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,7 @@ class Record {
URI() = default;
URI(const URI&) = default;

explicit URI(const std::string& _path, std::uint64_t _offset = 0) :
path(_path), offset(_offset) {}
explicit URI(const std::string& _path, std::uint64_t _offset = 0) : path(_path), offset(_offset) {}
};

private:
Expand All @@ -49,8 +48,6 @@ class Record {
public:
Record();

Record(const Record&);

bool empty() const;

Record& read(Stream&, bool read_to_end = false);
Expand Down
6 changes: 2 additions & 4 deletions src/eckit/codec/RecordItem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,11 @@ std::string RecordItem::URI::str() const {

//---------------------------------------------------------------------------------------------------------------------

RecordItem::RecordItem(RecordItem&& other) :
metadata_(std::move(other.metadata_)), data_(std::move(other.data_)) {}
RecordItem::RecordItem(RecordItem&& other) : metadata_(std::move(other.metadata_)), data_(std::move(other.data_)) {}

//---------------------------------------------------------------------------------------------------------------------

RecordItem::RecordItem(Metadata&& metadata, Data&& data) :
metadata_(new Metadata(metadata)), data_(std::move(data)) {}
RecordItem::RecordItem(Metadata&& metadata, Data&& data) : metadata_(new Metadata(metadata)), data_(std::move(data)) {}

//---------------------------------------------------------------------------------------------------------------------

Expand Down
16 changes: 6 additions & 10 deletions src/eckit/codec/RecordItemReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ Data read_data(const Record& record, int data_section_index, Stream in) {
if (not data_begin.valid()) {
throw InvalidRecord("Data section is not valid");
}
auto data_size =
static_cast<size_t>(data_section.length) - sizeof(RecordDataSection::Begin) - sizeof(RecordDataSection::End);
auto data_size
= static_cast<size_t>(data_section.length) - sizeof(RecordDataSection::Begin) - sizeof(RecordDataSection::End);
if (data_size > 0) {
if (data.read(in, data_size) != data_size) {
throw InvalidRecord("Data section is not valid");
Expand Down Expand Up @@ -115,17 +115,15 @@ Record read_record(Stream in, size_t offset) {

//---------------------------------------------------------------------------------------------------------------------

RecordItemReader::RecordItemReader(Stream in, size_t offset, const std::string& key) :
in_(in), uri_{"", offset, key} {
RecordItemReader::RecordItemReader(Stream in, size_t offset, const std::string& key) : in_(in), uri_{"", offset, key} {
record_ = read_record(in, uri_.offset);

if (not record_.has(uri_.key)) {
throw InvalidRecord(uri_.key + " not found in record " + uri_.path);
}
}

RecordItemReader::RecordItemReader(Stream in, const std::string& key) :
in_(in), uri_{"", 0, key} {
RecordItemReader::RecordItemReader(Stream in, const std::string& key) : in_(in), uri_{"", 0, key} {
record_ = read_record(in, uri_.offset);

if (not record_.has(uri_.key)) {
Expand All @@ -136,13 +134,11 @@ RecordItemReader::RecordItemReader(Stream in, const std::string& key) :

//---------------------------------------------------------------------------------------------------------------------

RecordItemReader::RecordItemReader(const std::string& uri) :
RecordItemReader("", uri) {}
RecordItemReader::RecordItemReader(const std::string& uri) : RecordItemReader("", uri) {}

//---------------------------------------------------------------------------------------------------------------------

RecordItemReader::RecordItemReader(const std::string& ref, const std::string& uri) :
ref_{ref}, uri_{uri} {
RecordItemReader::RecordItemReader(const std::string& ref, const std::string& uri) : ref_{ref}, uri_{uri} {
auto absolute_path = make_absolute_path(ref_, uri_);

if (not absolute_path.exists()) {
Expand Down
3 changes: 1 addition & 2 deletions src/eckit/codec/RecordPrinter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,7 @@ namespace eckit::codec {

//---------------------------------------------------------------------------------------------------------------------

RecordPrinter::RecordPrinter(const PathName& path, const Configuration& config) :
RecordPrinter(path, 0, config) {}
RecordPrinter::RecordPrinter(const PathName& path, const Configuration& config) : RecordPrinter(path, 0, config) {}

//---------------------------------------------------------------------------------------------------------------------

Expand Down
9 changes: 3 additions & 6 deletions src/eckit/codec/RecordReader.cc
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,13 @@ namespace eckit::codec {

//---------------------------------------------------------------------------------------------------------------------

RecordReader::RecordReader(const Record::URI& ref) :
RecordReader(ref.path, ref.offset) {}
RecordReader::RecordReader(const Record::URI& ref) : RecordReader(ref.path, ref.offset) {}

//---------------------------------------------------------------------------------------------------------------------

RecordReader::RecordReader(const std::string& path, uint64_t offset) :
path_{path}, offset_{offset} {}
RecordReader::RecordReader(const std::string& path, uint64_t offset) : path_{path}, offset_{offset} {}

RecordReader::RecordReader(Stream stream, uint64_t offset) :
stream_{stream}, offset_{offset} {}
RecordReader::RecordReader(Stream stream, uint64_t offset) : stream_{stream}, offset_{offset} {}

//---------------------------------------------------------------------------------------------------------------------

Expand Down
Loading

0 comments on commit 0c58e27

Please sign in to comment.