From ac38b8ec2af5fb5f6b20e8f6321f681e15710a68 Mon Sep 17 00:00:00 2001 From: Moritz Bunkus Date: Wed, 2 Jan 2019 21:14:21 +0100 Subject: [PATCH] common: implement clang-tidy's suggestions regarding modernization --- src/common/dts.cpp | 3 +- src/common/flac.cpp | 27 +++++-------- src/common/flac.h | 4 +- src/common/fourcc.cpp | 4 +- src/common/hevc.cpp | 2 +- src/common/hevc_es_parser.cpp | 2 +- src/common/hevcc.cpp | 16 ++++---- src/common/hevcc.h | 8 ++-- src/common/ivf.cpp | 2 +- src/common/json.cpp | 2 +- src/common/kax_analyzer.cpp | 37 ++++++++--------- src/common/kax_analyzer.h | 2 +- src/common/kax_file.cpp | 3 -- src/common/kax_file.h | 2 +- src/common/kax_info.cpp | 17 ++++---- src/common/kax_info_p.h | 2 +- src/common/locale.cpp | 21 +++------- src/common/locale.h | 8 ++-- src/common/logger.cpp | 13 +----- src/common/logger.h | 8 ++-- src/common/memory.cpp | 8 ++-- src/common/memory.h | 2 +- src/common/mm_io.cpp | 2 +- src/common/mm_io_x.cpp | 6 +-- src/common/mm_io_x.h | 28 ++++++------- src/common/mm_mem_io.cpp | 7 +++- src/common/mm_mem_io.h | 1 + src/common/mm_mpls_multi_file_io.cpp | 2 +- src/common/mm_multi_file_io.cpp | 13 ++++-- src/common/mm_multi_file_io.h | 2 + src/common/mm_proxy_io.cpp | 7 +++- src/common/mm_proxy_io.h | 2 + src/common/mm_read_buffer_io.cpp | 2 - src/common/mm_read_buffer_io_p.h | 1 + src/common/mm_stdio.cpp | 3 -- src/common/mm_stdio.h | 2 +- src/common/mm_text_io.cpp | 4 +- src/common/mm_write_buffer_io.cpp | 7 +++- src/common/mm_write_buffer_io.h | 3 +- src/common/mp3.cpp | 3 +- src/common/mpls.cpp | 3 -- src/common/mpls.h | 2 +- src/common/output.cpp | 2 +- src/common/property_element.cpp | 18 ++++----- src/common/property_element.h | 2 +- src/common/qt_kax_analyzer.cpp | 3 -- src/common/qt_kax_analyzer.h | 2 +- src/common/split_arg_parsing.cpp | 8 ++-- src/common/stereo_mode.cpp | 60 ++++++++++++++-------------- src/common/translation.cpp | 32 +++++++-------- src/common/translation.h | 14 +++---- src/common/truehd.cpp | 9 ----- src/common/truehd.h | 6 +-- src/common/vc1.cpp | 5 +-- src/common/vc1.h | 2 +- src/common/version.cpp | 8 +--- src/common/version.h | 2 +- src/common/wavpack.cpp | 5 +-- src/common/webvtt.cpp | 2 +- 59 files changed, 215 insertions(+), 258 deletions(-) diff --git a/src/common/dts.cpp b/src/common/dts.cpp index 52e037b9d..c4f1f9e3e 100644 --- a/src/common/dts.cpp +++ b/src/common/dts.cpp @@ -204,8 +204,7 @@ find_consecutive_headers(unsigned char const *buf, return base; ++base; - offset = 0; - pos = find_header(&buf[base], size - base, header, false); + pos = find_header(&buf[base], size - base, header, false); if (-1 == pos) return -1; diff --git a/src/common/flac.cpp b/src/common/flac.cpp index 3015e2453..405ec57f0 100644 --- a/src/common/flac.cpp +++ b/src/common/flac.cpp @@ -18,7 +18,7 @@ #include "common/common_pch.h" #include -#include +#include #include "common/bit_reader.h" #include "common/flac.h" @@ -85,12 +85,6 @@ flac_eof_cb(const FLAC__StreamDecoder *, // ---------------------------------------------------------------------- -decoder_c::decoder_c() { -} - -decoder_c::~decoder_c() { -} - void decoder_c::flac_metadata_cb(const FLAC__StreamMetadata *) { } @@ -341,21 +335,18 @@ decode_headers(unsigned char const *mem, int type; type = va_arg(ap, int); - switch (type) { - case FLAC_HEADER_STREAM_INFO: { - FLAC__StreamMetadata_StreamInfo *stream_info; + if (type != FLAC_HEADER_STREAM_INFO) + continue; - stream_info = va_arg(ap, FLAC__StreamMetadata_StreamInfo *); - if (result & FLAC_HEADER_STREAM_INFO) - memcpy(stream_info, &fhe.stream_info, sizeof(FLAC__StreamMetadata_StreamInfo)); + FLAC__StreamMetadata_StreamInfo *stream_info; - break; - } + stream_info = va_arg(ap, FLAC__StreamMetadata_StreamInfo *); + if (result & FLAC_HEADER_STREAM_INFO) + memcpy(stream_info, &fhe.stream_info, sizeof(FLAC__StreamMetadata_StreamInfo)); - default: - type = va_arg(ap, int); - } + break; } + va_end(ap); FLAC__stream_decoder_delete(decoder); diff --git a/src/common/flac.h b/src/common/flac.h index 09af41b4a..649b22d38 100644 --- a/src/common/flac.h +++ b/src/common/flac.h @@ -44,8 +44,8 @@ protected: stream_decoder_uptr m_flac_decoder; protected: - decoder_c(); - virtual ~decoder_c(); + decoder_c() = default; + virtual ~decoder_c() = default; public: virtual void flac_metadata_cb(const FLAC__StreamMetadata *metadata); diff --git a/src/common/fourcc.cpp b/src/common/fourcc.cpp index 72d888106..0b35c0917 100644 --- a/src/common/fourcc.cpp +++ b/src/common/fourcc.cpp @@ -123,8 +123,8 @@ fourcc_c::str() const { char buffer[4]; put_uint32_be(buffer, m_value); - for (auto idx = 0; 4 > idx; ++idx) - buffer[idx] = 32 <= buffer[idx] ? buffer[idx] : '?'; + for (auto &c : buffer) + c = 32 <= c ? c : '?'; return std::string{buffer, 4}; } diff --git a/src/common/hevc.cpp b/src/common/hevc.cpp index dea21fec6..43ed6d379 100644 --- a/src/common/hevc.cpp +++ b/src/common/hevc.cpp @@ -408,7 +408,7 @@ vui_parameters_copy(mtx::bits::reader_c &r, w.copy_unsigned_golomb(r); // vui_num_ticks_poc_diff_one_minus1 } if (w.copy_bits(1, r) == 1) { // vui_hrd_parameters_present_flag - hrd_parameters_copy(r, w, 1, max_sub_layers_minus1); // hrd_parameters + hrd_parameters_copy(r, w, true, max_sub_layers_minus1); // hrd_parameters } } diff --git a/src/common/hevc_es_parser.cpp b/src/common/hevc_es_parser.cpp index 8cc0514e7..9a7a1ee6e 100644 --- a/src/common/hevc_es_parser.cpp +++ b/src/common/hevc_es_parser.cpp @@ -129,7 +129,7 @@ es_parser_c::add_bytes(unsigned char *buffer, | (unsigned int)cursor.get_char() << 8 | (unsigned int)cursor.get_char(); - while (1) { + while (true) { if (NALU_START_CODE == marker) marker_size = 4; else if (NALU_START_CODE == (marker & 0x00ffffff)) diff --git a/src/common/hevcc.cpp b/src/common/hevcc.cpp index 0687fe9a9..7c11f9f3c 100644 --- a/src/common/hevcc.cpp +++ b/src/common/hevcc.cpp @@ -46,10 +46,10 @@ hevcc_c::hevcc_c() } hevcc_c::hevcc_c(unsigned int nalu_size_length, - std::vector const &vps_list, - std::vector const &sps_list, - std::vector const &pps_list, - user_data_t const &user_data, + std::vector vps_list, + std::vector sps_list, + std::vector pps_list, + user_data_t user_data, codec_private_t const &codec_private) : m_configuration_version{} , m_general_profile_space{} @@ -70,10 +70,10 @@ hevcc_c::hevcc_c(unsigned int nalu_size_length, , m_temporal_id_nesting_flag{} , m_size_nalu_minus_one{} , m_nalu_size_length{nalu_size_length} - , m_vps_list{vps_list} - , m_sps_list{sps_list} - , m_pps_list{pps_list} - , m_user_data{user_data} + , m_vps_list{std::move(vps_list)} + , m_sps_list{std::move(sps_list)} + , m_pps_list{std::move(pps_list)} + , m_user_data{std::move(user_data)} , m_codec_private{codec_private} { } diff --git a/src/common/hevcc.h b/src/common/hevcc.h index 25488b2bf..f925319f8 100644 --- a/src/common/hevcc.h +++ b/src/common/hevcc.h @@ -53,10 +53,10 @@ public: public: hevcc_c(); hevcc_c(unsigned int nalu_size_len, - std::vector const &vps_list, - std::vector const &sps_list, - std::vector const &pps_list, - user_data_t const &user_data, + std::vector vps_list, + std::vector sps_list, + std::vector pps_list, + user_data_t user_data, codec_private_t const &codec_private); explicit operator bool() const; diff --git a/src/common/ivf.cpp b/src/common/ivf.cpp index 922381888..c0b75558c 100644 --- a/src/common/ivf.cpp +++ b/src/common/ivf.cpp @@ -45,7 +45,7 @@ is_keyframe_vp9(memory_c const &buffer) { auto profile = bc.get_bit() + (bc.get_bit() * 2); if (3 == profile) - profile += bc.get_bit(); + bc.get_bit(); // profile += … if (bc.get_bit()) // show_existing_frame return false; diff --git a/src/common/json.cpp b/src/common/json.cpp index 24e29fd31..bd6aa2c77 100644 --- a/src/common/json.cpp +++ b/src/common/json.cpp @@ -13,7 +13,7 @@ #include "common/common_pch.h" -#include +#include #include "common/at_scope_exit.h" #include "common/json.h" diff --git a/src/common/kax_analyzer.cpp b/src/common/kax_analyzer.cpp index 1293e72c0..a8a67a23c 100644 --- a/src/common/kax_analyzer.cpp +++ b/src/common/kax_analyzer.cpp @@ -200,7 +200,7 @@ kax_analyzer_c::verify_data_structures_against_file(const std::string &hook_name bool row_is_identical = info_this.back() == info_actual.back(); ok &= row_is_identical; - info_markings.push_back(row_is_identical ? " " : "*"); + info_markings.emplace_back(row_is_identical ? " " : "*"); } if (ok) @@ -311,7 +311,7 @@ kax_analyzer_c::process_internal() { l0 = nullptr; } - while (1) { + while (true) { // Next element must be a segment l0 = m_stream->FindNextID(EBML_INFO(KaxSegment), 0xFFFFFFFFFFFFFFFFLL); if (!l0) @@ -502,7 +502,7 @@ kax_analyzer_c::adjust_segment_size() { if (!m_segment->IsFiniteSize()) return; - std::shared_ptr new_segment = std::shared_ptr(new KaxSegment); + auto new_segment = std::make_shared(); m_file->setFilePointer(m_segment->GetElementPosition()); new_segment->WriteHead(*m_file, m_segment->HeadSize() - 4); @@ -610,7 +610,7 @@ kax_analyzer_c::handle_void_elements(size_t data_idx) { // the element's head can be moved up and false if we have to // shrink it and fill the space with a new EBML void. - ebml_element_cptr e = read_element(m_data[data_idx + 1]); + auto e = read_element(m_data[data_idx + 1]); if (!e) { mxdebug_if(s_debug_void, fmt::format("handle_void_elements({0}): void_size == 1: could not read following element\n", data_idx)); @@ -796,8 +796,8 @@ kax_analyzer_c::remove_from_meta_seeks(EbmlId id) { // Read the element from the file. Remember its size so that a new // EbmlVoid element can be constructed afterwards. - ebml_element_cptr element = read_element(data_idx); - KaxSeekHead *seek_head = dynamic_cast(element.get()); + auto element = read_element(data_idx); + auto seek_head = dynamic_cast(element.get()); if (!seek_head) throw uer_error_unknown; @@ -812,7 +812,7 @@ kax_analyzer_c::remove_from_meta_seeks(EbmlId id) { continue; } - KaxSeek *seek_entry = dynamic_cast((*seek_head)[sh_idx]); + auto seek_entry = dynamic_cast((*seek_head)[sh_idx]); if (!seek_entry->IsEbmlId(id)) { ++sh_idx; @@ -1125,8 +1125,8 @@ kax_analyzer_c::try_adding_to_existing_meta_seek(EbmlElement *e) { available_space += m_data[data_idx + 1]->m_size; // Read the seek head, index the element and see how much space it needs. - ebml_element_cptr element = read_element(data_idx); - KaxSeekHead *seek_head = dynamic_cast(element.get()); + auto element = read_element(data_idx); + auto seek_head = dynamic_cast(element.get()); if (!seek_head) throw uer_error_unknown; @@ -1177,8 +1177,8 @@ void kax_analyzer_c::move_seek_head_to_end_and_create_new_one_at_start(EbmlElement *e, int first_seek_head_idx) { // Read the first seek head… - ebml_element_cptr element = read_element(first_seek_head_idx); - KaxSeekHead *seek_head = dynamic_cast(element.get()); + auto element = read_element(first_seek_head_idx); + auto seek_head = dynamic_cast(element.get()); if (!seek_head) throw uer_error_unknown; @@ -1394,7 +1394,7 @@ kax_analyzer_c::read_all(const EbmlCallbacks &callbacks) { if (!master) master = ebml_master_cptr(static_cast(element)); else { - EbmlMaster *src = static_cast(element); + auto src = static_cast(element); while (src->ListSize() > 0) { master->PushElement(*(*src)[0]); src->Remove(0); @@ -1447,8 +1447,8 @@ kax_analyzer_c::read_meta_seek(uint64_t pos, return; } - EbmlElement *l2 = nullptr; - EbmlMaster *master = static_cast(l1); + EbmlElement *l2 = nullptr; + auto master = static_cast(l1); master->Read(*m_stream, EBML_CONTEXT(l1), upper_lvl_el, l2, true); unsigned int i; @@ -1456,9 +1456,9 @@ kax_analyzer_c::read_meta_seek(uint64_t pos, if (!Is((*master)[i])) continue; - KaxSeek *seek = static_cast((*master)[i]); - KaxSeekID *seek_id = FindChild(seek); - int64_t seek_pos = seek->Location() + m_segment->GetElementPosition() + m_segment->HeadSize(); + auto seek = static_cast((*master)[i]); + auto seek_id = FindChild(seek); + int64_t seek_pos = seek->Location() + m_segment->GetElementPosition() + m_segment->HeadSize(); if ((0 == pos) || !seek_id) continue; @@ -1619,9 +1619,6 @@ console_kax_analyzer_c::console_kax_analyzer_c(std::string file_name) { } -console_kax_analyzer_c::~console_kax_analyzer_c() { -} - void console_kax_analyzer_c::set_show_progress(bool show_progress) { if (-1 == m_previous_percentage) diff --git a/src/common/kax_analyzer.h b/src/common/kax_analyzer.h index b927cd18c..dd225fd4e 100644 --- a/src/common/kax_analyzer.h +++ b/src/common/kax_analyzer.h @@ -225,7 +225,7 @@ private: public: console_kax_analyzer_c(std::string file_name); - virtual ~console_kax_analyzer_c(); + virtual ~console_kax_analyzer_c() = default; virtual void set_show_progress(bool show_progress); diff --git a/src/common/kax_file.cpp b/src/common/kax_file.cpp index e6f91f0c4..c49baf77d 100644 --- a/src/common/kax_file.cpp +++ b/src/common/kax_file.cpp @@ -41,9 +41,6 @@ kax_file_c::kax_file_c(mm_io_c &in) { } -kax_file_c::~kax_file_c() { -} - std::shared_ptr kax_file_c::read_next_level1_element(uint32_t wanted_id, bool report_cluster_timestamp) { diff --git a/src/common/kax_file.h b/src/common/kax_file.h index 3ded599aa..c8db6fb15 100644 --- a/src/common/kax_file.h +++ b/src/common/kax_file.h @@ -32,7 +32,7 @@ protected: public: kax_file_c(mm_io_c &in); - virtual ~kax_file_c(); + virtual ~kax_file_c() = default; virtual bool was_resynced() const; virtual int64_t get_resync_start_pos() const; diff --git a/src/common/kax_info.cpp b/src/common/kax_info.cpp index a0fea359f..0ced947e6 100644 --- a/src/common/kax_info.cpp +++ b/src/common/kax_info.cpp @@ -88,9 +88,6 @@ using namespace mtx::kax_info; namespace mtx { -kax_info::private_c::~private_c() { -} - kax_info_c::kax_info_c() : p_ptr{new kax_info::private_c} { @@ -103,7 +100,7 @@ kax_info_c::kax_info_c(kax_info::private_c &p) init(); } -kax_info_c::~kax_info_c() { +kax_info_c::~kax_info_c() { // NOLINT(modernize-use-equals-default) due to pimpl idiom requiring explicit dtor declaration somewhere } void @@ -360,7 +357,7 @@ kax_info_c::create_codec_dependent_private_info(KaxCodecPrivate &c_priv, return fmt::format(Y(" (FourCC: {0})"), fourcc_c{&bih->bi_compression}.description()); } else if ((codec_id == MKV_A_ACM) && ('a' == track_type) && (c_priv.GetSize() >= sizeof(alWAVEFORMATEX))) { - alWAVEFORMATEX *wfe = reinterpret_cast(c_priv.GetBuffer()); + auto wfe = reinterpret_cast(c_priv.GetBuffer()); return fmt::format(Y(" (format tag: 0x{0:04x})"), get_uint16_le(&wfe->w_format_tag)); } else if ((codec_id == MKV_V_MPEG4_AVC) && ('v' == track_type) && (c_priv.GetSize() >= 4)) { @@ -714,13 +711,13 @@ kax_info_c::init_custom_element_value_formatters_and_processors() { auto ce_scope = static_cast(e).GetValue(); if ((ce_scope & 0x01) == 0x01) - scope.push_back(Y("1: all frames")); + scope.emplace_back(Y("1: all frames")); if ((ce_scope & 0x02) == 0x02) - scope.push_back(Y("2: codec private data")); + scope.emplace_back(Y("2: codec private data")); if ((ce_scope & 0xfc) != 0x00) - scope.push_back(Y("rest: unknown")); + scope.emplace_back(Y("rest: unknown")); if (scope.empty()) - scope.push_back(Y("unknown")); + scope.emplace_back(Y("unknown")); return fmt::format("{0} ({1})", ce_scope, boost::join(scope, ", ")); }); @@ -1196,7 +1193,7 @@ kax_info_c::process_file() { handle_elements_generic(*l0); l0->SkipData(*p->m_es, EBML_CONTEXT(l0)); - while (1) { + while (true) { // NEXT element must be a segment l0 = ebml_element_cptr{ p->m_es->FindNextID(EBML_INFO(KaxSegment), 0xFFFFFFFFFFFFFFFFLL) }; if (!l0) diff --git a/src/common/kax_info_p.h b/src/common/kax_info_p.h index 9048e809e..f121a0042 100644 --- a/src/common/kax_info_p.h +++ b/src/common/kax_info_p.h @@ -63,7 +63,7 @@ public: public: private_c() = default; - ~private_c(); + ~private_c() = default; }; }} diff --git a/src/common/locale.cpp b/src/common/locale.cpp index 4dd13b374..16b5e0eb2 100644 --- a/src/common/locale.cpp +++ b/src/common/locale.cpp @@ -13,13 +13,13 @@ #include "common/common_pch.h" -#include +#include +#include #if HAVE_NL_LANGINFO # include #elif HAVE_LOCALE_CHARSET # include #endif -#include #if defined(SYS_WINDOWS) # include #endif @@ -39,20 +39,11 @@ charset_converter_cptr g_cc_local_utf8; std::map charset_converter_c::s_converters; -charset_converter_c::charset_converter_c() - : m_detect_byte_order_marker(false) +charset_converter_c::charset_converter_c(std::string charset) + : m_charset{std::move(charset)} { } -charset_converter_c::charset_converter_c(const std::string &charset) - : m_charset(charset) - , m_detect_byte_order_marker(false) -{ -} - -charset_converter_c::~charset_converter_c() { -} - std::string charset_converter_c::utf8(const std::string &source) { return source; @@ -74,7 +65,7 @@ charset_converter_c::init(const std::string &charset, bool ignore_errors) { std::string actual_charset = charset.empty() ? get_local_charset() : charset; - std::map::iterator converter = s_converters.find(actual_charset); + auto converter = s_converters.find(actual_charset); if (converter != s_converters.end()) return (*converter).second; @@ -177,7 +168,7 @@ iconv_charset_converter_c::convert(iconv_t handle, char *destination = (char *)safemalloc(length + 1); memset(destination, 0, length + 1); - iconv(handle, nullptr, 0, nullptr, 0); // Reset the iconv state. + iconv(handle, nullptr, nullptr, nullptr, nullptr); // Reset the iconv state. size_t length_source = length / 4; size_t length_destination = length; diff --git a/src/common/locale.h b/src/common/locale.h index 3b2a4a5f8..347f21aa5 100644 --- a/src/common/locale.h +++ b/src/common/locale.h @@ -23,12 +23,12 @@ using charset_converter_cptr = std::shared_ptr; class charset_converter_c { protected: std::string m_charset; - bool m_detect_byte_order_marker; + bool m_detect_byte_order_marker{}; public: - charset_converter_c(); - charset_converter_c(const std::string &charset); - virtual ~charset_converter_c(); + charset_converter_c() = default; + charset_converter_c(std::string charset); + virtual ~charset_converter_c() = default; virtual std::string utf8(const std::string &source); virtual std::string native(const std::string &source); diff --git a/src/common/logger.cpp b/src/common/logger.cpp index 3b4251ba6..f4228f189 100644 --- a/src/common/logger.cpp +++ b/src/common/logger.cpp @@ -36,9 +36,6 @@ target_c::target_c() { } -target_c::~target_c() { -} - std::string target_c::format_line(std::string const &message) { auto now = std::chrono::system_clock::now(); @@ -102,9 +99,9 @@ target_c::runtime() { // ---------------------------------------------------------------------- -file_target_c::file_target_c(bfs::path const &file_name) +file_target_c::file_target_c(bfs::path file_name) : target_c() // Don't use initializer-list syntax due to a bug in gcc < 4.8 - , m_file_name{file_name} + , m_file_name{std::move(file_name)} { if (!m_file_name.is_absolute()) m_file_name = bfs::temp_directory_path() / m_file_name; @@ -115,9 +112,6 @@ file_target_c::file_target_c(bfs::path const &file_name) } } -file_target_c::~file_target_c() { -} - void file_target_c::log_line(std::string const &message) { try { @@ -135,9 +129,6 @@ stderr_target_c::stderr_target_c() { } -stderr_target_c::~stderr_target_c() { -} - void stderr_target_c::log_line(std::string const &message) { std::cerr << message; diff --git a/src/common/logger.h b/src/common/logger.h index 71c05aae9..17f5474fe 100644 --- a/src/common/logger.h +++ b/src/common/logger.h @@ -25,7 +25,7 @@ private: public: target_c(); - virtual ~target_c(); + virtual ~target_c() = default; void log(std::string const &message) { log_line(message); @@ -48,8 +48,8 @@ private: bfs::path m_file_name; public: - file_target_c(bfs::path const &file_name); - virtual ~file_target_c(); + file_target_c(bfs::path file_name); + virtual ~file_target_c() = default; protected: virtual void log_line(std::string const &message) override; @@ -58,7 +58,7 @@ protected: class stderr_target_c: public target_c { public: stderr_target_c(); - virtual ~stderr_target_c(); + virtual ~stderr_target_c() = default; protected: virtual void log_line(std::string const &message) override; diff --git a/src/common/memory.cpp b/src/common/memory.cpp index ee59e5839..b12003879 100644 --- a/src/common/memory.cpp +++ b/src/common/memory.cpp @@ -18,7 +18,7 @@ void memory_c::resize(size_t new_size) - throw() + noexcept { if (new_size == m_size) return; @@ -145,10 +145,10 @@ _safememdup(const void *s, if (!s) return nullptr; - unsigned char *copy = reinterpret_cast(malloc(size)); + auto copy = reinterpret_cast(malloc(size)); if (!copy) mxerror(fmt::format(Y("memory.cpp/safememdup() called from file {0}, line {1}: malloc() returned nullptr for a size of {2} bytes.\n"), file, line, size)); - memcpy(copy, s, size); + memcpy(copy, s, size); // NOLINT(clang-analyzer-core.NonNullParamChecker) as mxerror() terminates the program return copy; } @@ -157,7 +157,7 @@ unsigned char * _safemalloc(size_t size, const char *file, int line) { - unsigned char *mem = reinterpret_cast(malloc(size)); + auto mem = reinterpret_cast(malloc(size)); if (!mem) mxerror(fmt::format(Y("memory.cpp/safemalloc() called from file {0}, line {1}: malloc() returned nullptr for a size of {2} bytes.\n"), file, line, size)); diff --git a/src/common/memory.h b/src/common/memory.h index a68fd2512..4548530b4 100644 --- a/src/common/memory.h +++ b/src/common/memory.h @@ -149,7 +149,7 @@ public: m_is_owned = false; } - void resize(std::size_t new_size) throw(); + void resize(std::size_t new_size) noexcept; void add(unsigned char const *new_buffer, std::size_t new_size); void add(memory_c const &new_buffer) { add(new_buffer.get_buffer(), new_buffer.get_size()); diff --git a/src/common/mm_io.cpp b/src/common/mm_io.cpp index 5a267c828..b2f639286 100644 --- a/src/common/mm_io.cpp +++ b/src/common/mm_io.cpp @@ -42,7 +42,7 @@ mm_io_c::mm_io_c(mm_io_private_c &p) { } -mm_io_c::~mm_io_c() { +mm_io_c::~mm_io_c() { // NOLINT(modernize-use-equals-default) due to pimpl idiom requiring explicit dtor declaration somewhere } std::string diff --git a/src/common/mm_io_x.cpp b/src/common/mm_io_x.cpp index 5bab458c6..af0dbfbb3 100644 --- a/src/common/mm_io_x.cpp +++ b/src/common/mm_io_x.cpp @@ -26,15 +26,15 @@ namespace mtx { namespace mm_io { std::error_code make_error_code() { #ifdef SYS_WINDOWS - return std::error_code(::GetLastError(), std::system_category()); + return { static_cast(::GetLastError()), std::system_category() }; #else - return std::error_code(errno, std::generic_category()); + return { errno, std::generic_category() }; #endif } std::string exception::error() - const throw() { + const noexcept { return std::errc::no_such_file_or_directory == code() ? Y("The file or directory was not found") : std::errc::no_space_on_device == code() ? Y("No space left to write to") : std::errc::permission_denied == code() ? Y("No permission to read from, to write to or to create") diff --git a/src/common/mm_io_x.h b/src/common/mm_io_x.h index 2c35c9ecb..42be95fcb 100644 --- a/src/common/mm_io_x.h +++ b/src/common/mm_io_x.h @@ -32,7 +32,7 @@ public: { } - virtual const char *what() const throw() { + virtual const char *what() const noexcept { return "unspecified I/O error"; } @@ -40,14 +40,14 @@ public: return m_error_code; } - virtual std::string error() const throw(); + virtual std::string error() const noexcept; }; class end_of_file_x: public exception { public: end_of_file_x(std::error_code const &error_code = std::error_code()) : exception(error_code) {} - virtual char const *what() const throw() { + virtual char const *what() const noexcept { return "end of file error"; } }; @@ -56,7 +56,7 @@ class seek_x: public exception { public: seek_x(std::error_code const &error_code = std::error_code()) : exception(error_code) {} - virtual char const *what() const throw() { + virtual char const *what() const noexcept { return "seek in file error"; } }; @@ -65,7 +65,7 @@ class read_write_x: public exception { public: read_write_x(std::error_code const &error_code = std::error_code()) : exception(error_code) {} - virtual char const *what() const throw() { + virtual char const *what() const noexcept { return "reading from/writing to the file error"; } }; @@ -74,7 +74,7 @@ class open_x: public exception { public: open_x(std::error_code const &error_code = std::error_code()) : exception(error_code) {} - virtual char const *what() const throw() { + virtual char const *what() const noexcept { return "open file error"; } }; @@ -83,7 +83,7 @@ class wrong_read_write_access_x: public exception { public: wrong_read_write_access_x(std::error_code const &error_code = std::error_code()) : exception(error_code) {} - virtual char const *what() const throw() { + virtual char const *what() const noexcept { return "write operation to read-only file or vice versa"; } }; @@ -92,7 +92,7 @@ class insufficient_space_x: public exception { public: insufficient_space_x(std::error_code const &error_code = std::error_code()) : exception(error_code) {} - virtual char const *what() const throw() { + virtual char const *what() const noexcept { return "insufficient space for write operation"; } }; @@ -108,12 +108,12 @@ public: { } - virtual ~create_directory_x() throw() { } + virtual ~create_directory_x() noexcept { } - virtual char const *what() const throw() { + virtual char const *what() const noexcept { return "create_directory() failed"; } - virtual std::string error() const throw() { + virtual std::string error() const noexcept { return fmt::format(Y("Creating directory '{0}' failed: {1}"), m_path, code().message()); } }; @@ -123,7 +123,7 @@ class exception: public mtx::mm_io::exception { public: exception(std::error_code const &error_code = std::error_code()) : mtx::mm_io::exception(error_code) {} - virtual char const *what() const throw() { + virtual char const *what() const noexcept { return "unspecified text I/O error"; } }; @@ -138,11 +138,11 @@ public: { } - virtual char const *what() const throw() { + virtual char const *what() const noexcept { return "invalid UTF-8 char"; } - virtual std::string error() const throw() { + virtual std::string error() const noexcept { return fmt::format(Y("Invalid UTF-8 char. First byte: 0x{0:02x}"), static_cast(m_first_char)); } }; diff --git a/src/common/mm_mem_io.cpp b/src/common/mm_mem_io.cpp index 019733916..e47543309 100644 --- a/src/common/mm_mem_io.cpp +++ b/src/common/mm_mem_io.cpp @@ -45,7 +45,7 @@ mm_mem_io_c::mm_mem_io_c(mm_mem_io_private_c &p) } mm_mem_io_c::~mm_mem_io_c() { - close(); + close_mem_io(); } uint64 @@ -120,6 +120,11 @@ mm_mem_io_c::_write(const void *buffer, void mm_mem_io_c::close() { + close_mem_io(); +} + +void +mm_mem_io_c::close_mem_io() { auto p = p_func(); if (p->free_mem) diff --git a/src/common/mm_mem_io.h b/src/common/mm_mem_io.h index d7852e965..cbfec5f09 100644 --- a/src/common/mm_mem_io.h +++ b/src/common/mm_mem_io.h @@ -43,4 +43,5 @@ public: protected: virtual uint32 _read(void *buffer, size_t size); virtual size_t _write(const void *buffer, size_t size); + void close_mem_io(); }; diff --git a/src/common/mm_mpls_multi_file_io.cpp b/src/common/mm_mpls_multi_file_io.cpp index 9f194b754..d190bbd6d 100644 --- a/src/common/mm_mpls_multi_file_io.cpp +++ b/src/common/mm_mpls_multi_file_io.cpp @@ -26,7 +26,7 @@ mm_mpls_multi_file_io_c::mm_mpls_multi_file_io_c(mm_mpls_multi_file_io_private_c { } -mm_mpls_multi_file_io_c::~mm_mpls_multi_file_io_c() { +mm_mpls_multi_file_io_c::~mm_mpls_multi_file_io_c() { // NOLINT(modernize-use-equals-default) due to pimpl idiom requiring explicit dtor declaration somewhere } std::vector const & diff --git a/src/common/mm_multi_file_io.cpp b/src/common/mm_multi_file_io.cpp index dd629cadf..ee6baf8b9 100644 --- a/src/common/mm_multi_file_io.cpp +++ b/src/common/mm_multi_file_io.cpp @@ -36,7 +36,7 @@ mm_multi_file_io_c::mm_multi_file_io_c(mm_multi_file_io_private_c &p) } mm_multi_file_io_c::~mm_multi_file_io_c() { - close(); + close_multi_file_io(); } uint64 @@ -74,10 +74,10 @@ mm_multi_file_io_c::setFilePointer(int64 offset, uint32 mm_multi_file_io_c::_read(void *buffer, size_t size) { - auto p = p_func(); + auto p = p_func(); - size_t num_read_total = 0; - unsigned char *buffer_ptr = static_cast(buffer); + size_t num_read_total = 0; + auto buffer_ptr = static_cast(buffer); while (!eof() && (num_read_total < size)) { auto &file = p->files[p->current_file]; @@ -112,6 +112,11 @@ mm_multi_file_io_c::_write(const void *, void mm_multi_file_io_c::close() { + close_multi_file_io(); +} + +void +mm_multi_file_io_c::close_multi_file_io() { auto p = p_func(); for (auto &file : p->files) diff --git a/src/common/mm_multi_file_io.h b/src/common/mm_multi_file_io.h index 1626ee752..5c106145a 100644 --- a/src/common/mm_multi_file_io.h +++ b/src/common/mm_multi_file_io.h @@ -48,4 +48,6 @@ public: protected: virtual uint32 _read(void *buffer, size_t size); virtual size_t _write(const void *buffer, size_t size); + + void close_multi_file_io(); }; diff --git a/src/common/mm_proxy_io.cpp b/src/common/mm_proxy_io.cpp index 4a1848aa6..54e9e778b 100644 --- a/src/common/mm_proxy_io.cpp +++ b/src/common/mm_proxy_io.cpp @@ -33,7 +33,7 @@ mm_proxy_io_c::mm_proxy_io_c(mm_proxy_io_private_c &p) } mm_proxy_io_c::~mm_proxy_io_c() { - close(); + close_proxy_io(); } void @@ -71,6 +71,11 @@ mm_proxy_io_c::get_proxied() void mm_proxy_io_c::close() { + close_proxy_io(); +} + +void +mm_proxy_io_c::close_proxy_io() { p_func()->proxy_io.reset(); } diff --git a/src/common/mm_proxy_io.h b/src/common/mm_proxy_io.h index 562f9925f..79c88b9dc 100644 --- a/src/common/mm_proxy_io.h +++ b/src/common/mm_proxy_io.h @@ -37,4 +37,6 @@ public: protected: virtual uint32 _read(void *buffer, size_t size); virtual size_t _write(const void *buffer, size_t size); + + void close_proxy_io(); }; diff --git a/src/common/mm_read_buffer_io.cpp b/src/common/mm_read_buffer_io.cpp index 6ac2094b6..4705c4c41 100644 --- a/src/common/mm_read_buffer_io.cpp +++ b/src/common/mm_read_buffer_io.cpp @@ -27,13 +27,11 @@ mm_read_buffer_io_c::mm_read_buffer_io_c(mm_io_cptr const &in, std::size_t buffer_size) : mm_proxy_io_c{*new mm_read_buffer_io_private_c{in, buffer_size}} { - setFilePointer(in->getFilePointer()); } mm_read_buffer_io_c::mm_read_buffer_io_c(mm_read_buffer_io_private_c &p) : mm_proxy_io_c{p} { - setFilePointer(p.proxy_io->getFilePointer()); } mm_read_buffer_io_c::~mm_read_buffer_io_c() { diff --git a/src/common/mm_read_buffer_io_p.h b/src/common/mm_read_buffer_io_p.h index 02ca1955c..51539d59b 100644 --- a/src/common/mm_read_buffer_io_p.h +++ b/src/common/mm_read_buffer_io_p.h @@ -32,6 +32,7 @@ public: : mm_proxy_io_private_c{proxy_io} , af_buffer{memory_c::alloc(buffer_size)} , buffer{af_buffer->get_buffer()} + , offset{static_cast(proxy_io->getFilePointer())} { } }; diff --git a/src/common/mm_stdio.cpp b/src/common/mm_stdio.cpp index 3abac14c7..e3c0b17d8 100644 --- a/src/common/mm_stdio.cpp +++ b/src/common/mm_stdio.cpp @@ -21,9 +21,6 @@ Class for reading from stdin & writing to stdout. */ -mm_stdio_c::mm_stdio_c() { -} - uint64 mm_stdio_c::getFilePointer() { return 0; diff --git a/src/common/mm_stdio.h b/src/common/mm_stdio.h index 63836c8ea..1de9d55ae 100644 --- a/src/common/mm_stdio.h +++ b/src/common/mm_stdio.h @@ -17,7 +17,7 @@ class mm_stdio_c: public mm_io_c { public: - mm_stdio_c(); + mm_stdio_c() = default; virtual uint64 getFilePointer(); virtual void setFilePointer(int64 offset, libebml::seek_mode mode=libebml::seek_beginning); diff --git a/src/common/mm_text_io.cpp b/src/common/mm_text_io.cpp index 836c4dc46..3e24e8b5b 100644 --- a/src/common/mm_text_io.cpp +++ b/src/common/mm_text_io.cpp @@ -64,7 +64,7 @@ mm_text_io_c::detect_eol_style() { auto num_chars_read = 0u; - while (1) { + while (true) { auto utf8char = read_next_codepoint(); auto len = utf8char.length(); @@ -228,7 +228,7 @@ mm_text_io_c::getline(boost::optional max_chars) { bool previous_was_carriage_return = false; std::size_t num_chars_read{}; - while (1) { + while (true) { auto previous_pos = getFilePointer(); auto utf8char = read_next_codepoint(); auto len = utf8char.length(); diff --git a/src/common/mm_write_buffer_io.cpp b/src/common/mm_write_buffer_io.cpp index a10baa39c..44ca765c6 100644 --- a/src/common/mm_write_buffer_io.cpp +++ b/src/common/mm_write_buffer_io.cpp @@ -36,7 +36,7 @@ mm_write_buffer_io_c::mm_write_buffer_io_c(mm_write_buffer_io_private_c &p) } mm_write_buffer_io_c::~mm_write_buffer_io_c() { - close(); + close_write_buffer_io(); } mm_io_cptr @@ -79,6 +79,11 @@ mm_write_buffer_io_c::flush() { void mm_write_buffer_io_c::close() { + close_write_buffer_io(); +} + +void +mm_write_buffer_io_c::close_write_buffer_io() { flush_buffer(); mm_proxy_io_c::close(); } diff --git a/src/common/mm_write_buffer_io.h b/src/common/mm_write_buffer_io.h index 4c3f82e60..9b89c49a8 100644 --- a/src/common/mm_write_buffer_io.h +++ b/src/common/mm_write_buffer_io.h @@ -40,5 +40,6 @@ public: protected: virtual uint32 _read(void *buffer, size_t size); virtual size_t _write(const void *buffer, size_t size); - virtual void flush_buffer(); + void flush_buffer(); + void close_write_buffer_io(); }; diff --git a/src/common/mp3.cpp b/src/common/mp3.cpp index b568c457b..533247e00 100644 --- a/src/common/mp3.cpp +++ b/src/common/mp3.cpp @@ -300,8 +300,7 @@ find_consecutive_mp3_headers(const unsigned char *buf, return base; } base++; - offset = 0; - pos = find_mp3_header(&buf[base], size - base); + pos = find_mp3_header(&buf[base], size - base); if (pos == -1) return -1; decode_mp3_header(&buf[base + pos], &mp3header); diff --git a/src/common/mpls.cpp b/src/common/mpls.cpp index d24857646..08e8d8c4e 100644 --- a/src/common/mpls.cpp +++ b/src/common/mpls.cpp @@ -185,9 +185,6 @@ parser_c::parser_c() { } -parser_c::~parser_c() { -} - void parser_c::enable_dropping_last_entry_if_at_end(bool enable) { m_drop_last_entry_if_at_end = enable; diff --git a/src/common/mpls.h b/src/common/mpls.h index 868ae9fd4..e795332bd 100644 --- a/src/common/mpls.h +++ b/src/common/mpls.h @@ -153,7 +153,7 @@ protected: public: parser_c(); - virtual ~parser_c(); + virtual ~parser_c() = default; virtual bool parse(mm_io_c &in); virtual bool is_ok() const { diff --git a/src/common/output.cpp b/src/common/output.cpp index ce418e46c..f03df1ab3 100644 --- a/src/common/output.cpp +++ b/src/common/output.cpp @@ -35,7 +35,7 @@ bool g_warning_issued = false; std::string g_stdio_charset; static bool s_mm_stdio_redirected = false; -charset_converter_cptr g_cc_stdio = charset_converter_cptr(new charset_converter_c); +charset_converter_cptr g_cc_stdio = std::make_shared(); std::shared_ptr g_mm_stdio = std::shared_ptr(new mm_stdio_c); static mxmsg_handler_t s_mxmsg_info_handler, s_mxmsg_warning_handler, s_mxmsg_error_handler; diff --git a/src/common/property_element.cpp b/src/common/property_element.cpp index 02ef0c670..714d3ed11 100644 --- a/src/common/property_element.cpp +++ b/src/common/property_element.cpp @@ -38,16 +38,16 @@ using namespace libmatroska; std::map > property_element_c::s_properties; std::map > property_element_c::s_composed_properties; -property_element_c::property_element_c(std::string const &name, +property_element_c::property_element_c(std::string name, EbmlCallbacks const &callbacks, - translatable_string_c const &title, - translatable_string_c const &description, + translatable_string_c title, + translatable_string_c description, EbmlCallbacks const &sub_master_callbacks, EbmlCallbacks const *sub_sub_master_callbacks, EbmlCallbacks const *sub_sub_sub_master_callbacks) - : m_name{name} - , m_title{title} - , m_description{description} + : m_name{std::move(name)} + , m_title{std::move(title)} + , m_description{std::move(description)} , m_callbacks{&callbacks} , m_sub_master_callbacks{&sub_master_callbacks} , m_sub_sub_master_callbacks{sub_sub_master_callbacks} @@ -222,15 +222,15 @@ property_element_c::get_table_for(const EbmlCallbacks &master_callbacks, if (s_properties.empty()) init_tables(); - std::map >::iterator src_map_it = s_properties.find(master_callbacks.GlobalId.Value); + auto src_map_it = s_properties.find(master_callbacks.GlobalId.Value); if (s_properties.end() == src_map_it) mxerror(fmt::format("property_element_c::get_table_for(): programming error: no table found for EBML ID {0:08x}\n", master_callbacks.GlobalId.Value)); if (full_table) return src_map_it->second; - uint32_t element_id = !sub_master_callbacks ? master_callbacks.GlobalId.Value : sub_master_callbacks->GlobalId.Value; - std::map >::iterator composed_map_it = s_composed_properties.find(element_id); + uint32_t element_id = !sub_master_callbacks ? master_callbacks.GlobalId.Value : sub_master_callbacks->GlobalId.Value; + auto composed_map_it = s_composed_properties.find(element_id); if (s_composed_properties.end() != composed_map_it) return composed_map_it->second; diff --git a/src/common/property_element.h b/src/common/property_element.h index da0f83d29..70f194fa4 100644 --- a/src/common/property_element.h +++ b/src/common/property_element.h @@ -40,7 +40,7 @@ public: ebml_type_e m_type; property_element_c(); - property_element_c(std::string const &name, EbmlCallbacks const &callbacks, translatable_string_c const &title, translatable_string_c const &description, + property_element_c(std::string name, EbmlCallbacks const &callbacks, translatable_string_c title, translatable_string_c description, EbmlCallbacks const &sub_master_callbacks, EbmlCallbacks const *sub_sub_master_callbacks = nullptr, EbmlCallbacks const *sub_sub_sub_master_callbacks = nullptr); bool is_valid() const; diff --git a/src/common/qt_kax_analyzer.cpp b/src/common/qt_kax_analyzer.cpp index 5cb388620..4eebf7461 100644 --- a/src/common/qt_kax_analyzer.cpp +++ b/src/common/qt_kax_analyzer.cpp @@ -28,9 +28,6 @@ QtKaxAnalyzer::QtKaxAnalyzer(QWidget *parent, { } -QtKaxAnalyzer::~QtKaxAnalyzer() { -} - void QtKaxAnalyzer::show_progress_start(int64_t size) { m_size = size; diff --git a/src/common/qt_kax_analyzer.h b/src/common/qt_kax_analyzer.h index 180736d17..61256c29e 100644 --- a/src/common/qt_kax_analyzer.h +++ b/src/common/qt_kax_analyzer.h @@ -29,7 +29,7 @@ private: public: QtKaxAnalyzer(QWidget *parent, QString const &fileName); - virtual ~QtKaxAnalyzer(); + virtual ~QtKaxAnalyzer() = default; virtual void show_progress_start(int64_t size) override; virtual bool show_progress_running(int percentage) override; diff --git a/src/common/split_arg_parsing.cpp b/src/common/split_arg_parsing.cpp index 73a80337e..6a22744a0 100644 --- a/src/common/split_arg_parsing.cpp +++ b/src/common/split_arg_parsing.cpp @@ -79,7 +79,7 @@ parse_split_parts(const std::string &arg, throw format_x{fmt::format(Y("Invalid start time for '--split' in '--split {0}' (current part: {1}). The start time must be bigger than or equal to the previous part's end time.\n"), arg, part_spec)}; } - requested_split_points.push_back(std::make_tuple(start, end, create_new_file)); + requested_split_points.emplace_back(start, end, create_new_file); } std::vector split_points; @@ -88,13 +88,13 @@ parse_split_parts(const std::string &arg, for (auto &split_point : requested_split_points) { if (previous_end < std::get<0>(split_point)) - split_points.push_back(split_point_c{ previous_end, sp_type, true, true, std::get<2>(split_point) }); - split_points.push_back(split_point_c{ std::get<0>(split_point), sp_type, true, false, std::get<2>(split_point) }); + split_points.emplace_back(previous_end, sp_type, true, true, std::get<2>(split_point)); + split_points.emplace_back(std::get<0>(split_point), sp_type, true, false, std::get<2>(split_point)); previous_end = std::get<1>(split_point); } if (std::get<1>(requested_split_points.back()) < std::numeric_limits::max()) - split_points.push_back(split_point_c{ std::get<1>(requested_split_points.back()), sp_type, true, true }); + split_points.emplace_back(std::get<1>(requested_split_points.back()), sp_type, true, true); return split_points; } diff --git a/src/common/stereo_mode.cpp b/src/common/stereo_mode.cpp index 9d19d19de..89222f424 100644 --- a/src/common/stereo_mode.cpp +++ b/src/common/stereo_mode.cpp @@ -24,21 +24,21 @@ std::vector stereo_mode_c::s_translations; void stereo_mode_c::init() { - s_modes.push_back("mono"); - s_modes.push_back("side_by_side_left_first"); - s_modes.push_back("top_bottom_right_first"); - s_modes.push_back("top_bottom_left_first"); - s_modes.push_back("checkerboard_right_first"); - s_modes.push_back("checkerboard_left_first"); - s_modes.push_back("row_interleaved_right_first"); - s_modes.push_back("row_interleaved_left_first"); - s_modes.push_back("column_interleaved_right_first"); - s_modes.push_back("column_interleaved_left_first"); - s_modes.push_back("anaglyph_cyan_red"); - s_modes.push_back("side_by_side_right_first"); - s_modes.push_back("anaglyph_green_magenta"); - s_modes.push_back("both_eyes_laced_left_first"); - s_modes.push_back("both_eyes_laced_right_first"); + s_modes.emplace_back("mono"); + s_modes.emplace_back("side_by_side_left_first"); + s_modes.emplace_back("top_bottom_right_first"); + s_modes.emplace_back("top_bottom_left_first"); + s_modes.emplace_back("checkerboard_right_first"); + s_modes.emplace_back("checkerboard_left_first"); + s_modes.emplace_back("row_interleaved_right_first"); + s_modes.emplace_back("row_interleaved_left_first"); + s_modes.emplace_back("column_interleaved_right_first"); + s_modes.emplace_back("column_interleaved_left_first"); + s_modes.emplace_back("anaglyph_cyan_red"); + s_modes.emplace_back("side_by_side_right_first"); + s_modes.emplace_back("anaglyph_green_magenta"); + s_modes.emplace_back("both_eyes_laced_left_first"); + s_modes.emplace_back("both_eyes_laced_right_first"); } void @@ -46,21 +46,21 @@ stereo_mode_c::init_translations() { if (!s_translations.empty()) return; - s_translations.push_back(YT("mono")); - s_translations.push_back(YT("side by side (left first)")); - s_translations.push_back(YT("top bottom (right first)")); - s_translations.push_back(YT("top bottom (left first)")); - s_translations.push_back(YT("checkerboard (right first)")); - s_translations.push_back(YT("checkerboard (left first)")); - s_translations.push_back(YT("row interleaved (right first)")); - s_translations.push_back(YT("row interleaved (left first)")); - s_translations.push_back(YT("column interleaved (right first)")); - s_translations.push_back(YT("column interleaved (left first)")); - s_translations.push_back(YT("anaglyph (cyan/red)")); - s_translations.push_back(YT("side by side (right first)")); - s_translations.push_back(YT("anaglyph (green/magenta)")); - s_translations.push_back(YT("both eyes laced in one block (left first)")); - s_translations.push_back(YT("both eyes laced in one block (right first)")); + s_translations.emplace_back(YT("mono")); + s_translations.emplace_back(YT("side by side (left first)")); + s_translations.emplace_back(YT("top bottom (right first)")); + s_translations.emplace_back(YT("top bottom (left first)")); + s_translations.emplace_back(YT("checkerboard (right first)")); + s_translations.emplace_back(YT("checkerboard (left first)")); + s_translations.emplace_back(YT("row interleaved (right first)")); + s_translations.emplace_back(YT("row interleaved (left first)")); + s_translations.emplace_back(YT("column interleaved (right first)")); + s_translations.emplace_back(YT("column interleaved (left first)")); + s_translations.emplace_back(YT("anaglyph (cyan/red)")); + s_translations.emplace_back(YT("side by side (right first)")); + s_translations.emplace_back(YT("anaglyph (green/magenta)")); + s_translations.emplace_back(YT("both eyes laced in one block (left first)")); + s_translations.emplace_back(YT("both eyes laced in one block (right first)")); } const std::string diff --git a/src/common/translation.cpp b/src/common/translation.cpp index 79d0e0b1e..df0557a68 100644 --- a/src/common/translation.cpp +++ b/src/common/translation.cpp @@ -13,14 +13,14 @@ #include "common/common_pch.h" +#include +#include #if HAVE_NL_LANGINFO # include #elif HAVE_LOCALE_CHARSET # include #endif #include -#include -#include #include "common/fs_sys_helpers.h" #include "common/locale_string.h" @@ -38,21 +38,21 @@ std::vector translation_c::ms_available_translations; int translation_c::ms_active_translation_idx = 0; -translation_c::translation_c(std::string const &iso639_2_code, - std::string const &unix_locale, - std::string const &windows_locale, - std::string const &windows_locale_sysname, - std::string const &english_name, - std::string const &translated_name, +translation_c::translation_c(std::string iso639_2_code, + std::string unix_locale, + std::string windows_locale, + std::string windows_locale_sysname, + std::string english_name, + std::string translated_name, bool line_breaks_anywhere, int language_id, int sub_language_id) - : m_iso639_2_code{iso639_2_code} - , m_unix_locale{unix_locale} - , m_windows_locale{windows_locale} - , m_windows_locale_sysname{windows_locale_sysname} - , m_english_name{english_name} - , m_translated_name{translated_name} + : m_iso639_2_code{std::move(iso639_2_code)} + , m_unix_locale{std::move(unix_locale)} + , m_windows_locale{std::move(windows_locale)} + , m_windows_locale_sysname{std::move(windows_locale_sysname)} + , m_english_name{std::move(english_name)} + , m_translated_name{std::move(translated_name)} , m_line_breaks_anywhere{line_breaks_anywhere} , m_language_id{language_id} , m_sub_language_id{sub_language_id} @@ -218,10 +218,6 @@ translation_c::set_active_translation(const std::string &locale) { // ------------------------------------------------------------ -translatable_string_c::translatable_string_c() -{ -} - translatable_string_c::translatable_string_c(const std::string &untranslated_string) : m_untranslated_strings{untranslated_string} { diff --git a/src/common/translation.h b/src/common/translation.h index 52ae3de83..4e3a303ad 100644 --- a/src/common/translation.h +++ b/src/common/translation.h @@ -27,12 +27,12 @@ public: bool m_line_breaks_anywhere; int m_language_id, m_sub_language_id; - translation_c(std::string const &iso639_2_code, - std::string const &unix_locale, - std::string const &windows_locale, - std::string const &windows_locale_sysname, - std::string const &english_name, - std::string const &translated_name, + translation_c(std::string iso639_2_code, + std::string unix_locale, + std::string windows_locale, + std::string windows_locale_sysname, + std::string english_name, + std::string translated_name, bool line_breaks_anywhere, int language_id, int sub_language_id); @@ -54,7 +54,7 @@ protected: boost::optional m_overridden_by; public: - translatable_string_c(); + translatable_string_c() = default; translatable_string_c(const std::string &untranslated_string); translatable_string_c(const char *untranslated_string); translatable_string_c(std::vector const &untranslated_strings); diff --git a/src/common/truehd.cpp b/src/common/truehd.cpp index d42dafab4..6229b316a 100644 --- a/src/common/truehd.cpp +++ b/src/common/truehd.cpp @@ -176,15 +176,6 @@ frame_t::decode_channel_map(int channel_map) { // ---------------------------------------------------------------------- -parser_c::parser_c() - : m_sync_state(state_unsynced) -{ -} - -parser_c::~parser_c() -{ -} - void parser_c::add_data(unsigned char const *new_data, unsigned int new_size) { diff --git a/src/common/truehd.h b/src/common/truehd.h index c9fc52c68..287caacf6 100644 --- a/src/common/truehd.h +++ b/src/common/truehd.h @@ -101,15 +101,15 @@ protected: enum { state_unsynced, state_synced, - } m_sync_state; + } m_sync_state{state_unsynced}; mtx::bytes::buffer_c m_buffer; std::deque m_frames; frame_t::codec_e m_sync_codec{frame_t::truehd}; public: - parser_c(); - virtual ~parser_c(); + parser_c() = default; + virtual ~parser_c() = default; virtual void add_data(const unsigned char *new_data, unsigned int new_size); virtual void parse(bool end_of_stream = false); diff --git a/src/common/vc1.cpp b/src/common/vc1.cpp index 231cbdbbf..04852190f 100644 --- a/src/common/vc1.cpp +++ b/src/common/vc1.cpp @@ -296,9 +296,6 @@ es_parser_c::es_parser_c() { } -es_parser_c::~es_parser_c() { -} - void es_parser_c::add_bytes(unsigned char *buffer, int size) { @@ -314,7 +311,7 @@ es_parser_c::add_bytes(unsigned char *buffer, if (3 <= cursor.get_remaining_size()) { uint32_t marker = (1 << 24) | ((unsigned int)cursor.get_char() << 16) | ((unsigned int)cursor.get_char() << 8) | (unsigned int)cursor.get_char(); - while (1) { + while (true) { if (is_marker(marker)) { if (-1 != previous_pos) { int new_size = cursor.get_position() - 4 - previous_pos; diff --git a/src/common/vc1.h b/src/common/vc1.h index 51b0720c6..d7d792305 100644 --- a/src/common/vc1.h +++ b/src/common/vc1.h @@ -175,7 +175,7 @@ protected: public: es_parser_c(); - virtual ~es_parser_c(); + virtual ~es_parser_c() = default; virtual void add_bytes(unsigned char *buf, int size); virtual void add_bytes(memory_cptr &buf) { diff --git a/src/common/version.cpp b/src/common/version.cpp index ccf9c2d21..7d8b6c09e 100644 --- a/src/common/version.cpp +++ b/src/common/version.cpp @@ -24,10 +24,6 @@ #define VERSIONNAME "Like It Or Not" -version_number_t::version_number_t() -{ -} - version_number_t::version_number_t(const std::string &s) : valid{} { @@ -114,10 +110,10 @@ version_number_t::to_string() std::string v; - for (auto idx = 0u; idx < parts.size(); ++idx) { + for (auto const &part : parts) { if (!v.empty()) v += "."; - v += ::to_string(parts[idx]); + v += ::to_string(part); } if (0 != build) diff --git a/src/common/version.h b/src/common/version.h index 93018e149..12d8eb3b4 100644 --- a/src/common/version.h +++ b/src/common/version.h @@ -29,7 +29,7 @@ struct version_number_t { unsigned int build{}; bool valid{}; - version_number_t(); + version_number_t() = default; version_number_t(const std::string &s); bool operator <(const version_number_t &cmp) const; diff --git a/src/common/wavpack.cpp b/src/common/wavpack.cpp index eae0f7bad..3fa47f292 100644 --- a/src/common/wavpack.cpp +++ b/src/common/wavpack.cpp @@ -34,7 +34,7 @@ wavpack_meta_t::wavpack_meta_t() static void little_endian_to_native(void *data, const char *format) { - uint8_t *cp = (uint8_t *)data; + auto cp = static_cast(data); uint32_t temp; while (*format) { @@ -70,7 +70,7 @@ read_next_header(mm_io_c &in, uint32_t bytes_skipped = 0; int bleft; - while (1) { + while (true) { if (sp < ep) { bleft = ep - sp; memmove(buffer, sp, bleft); @@ -165,4 +165,3 @@ wv_parse_frame(mm_io_c &in, return wphdr.ck_size - sizeof(wavpack_header_t) + 8; } - diff --git a/src/common/webvtt.cpp b/src/common/webvtt.cpp index 3b6afc981..1cadb8f01 100644 --- a/src/common/webvtt.cpp +++ b/src/common/webvtt.cpp @@ -35,7 +35,7 @@ webvtt_parser_c::webvtt_parser_c() { } -webvtt_parser_c::~webvtt_parser_c() { +webvtt_parser_c::~webvtt_parser_c() { // NOLINT(modernize-use-equals-default) due to pimpl idiom requiring explicit dtor declaration somewhere } void