diff options
Diffstat (limited to 'coding')
-rw-r--r-- | coding/coding_tests/file_container_test.cpp | 4 | ||||
-rw-r--r-- | coding/file_writer.cpp | 1 | ||||
-rw-r--r-- | coding/file_writer.hpp | 8 | ||||
-rw-r--r-- | coding/multilang_utf8_string.cpp | 10 | ||||
-rw-r--r-- | coding/writer.hpp | 36 |
5 files changed, 28 insertions, 31 deletions
diff --git a/coding/coding_tests/file_container_test.cpp b/coding/coding_tests/file_container_test.cpp index 9278d80fb4..15f4cea75c 100644 --- a/coding/coding_tests/file_container_test.cpp +++ b/coding/coding_tests/file_container_test.cpp @@ -289,12 +289,12 @@ UNIT_TEST(FilesMappingContainer_Smoke) { FilesContainerW writer(fName); - for (uint32_t i = 0; i < ARRAY_SIZE(key); ++i) + for (size_t i = 0; i < ARRAY_SIZE(key); ++i) { FileWriter w = writer.GetWriter(key[i]); for (uint32_t j = 0; j < count; ++j) { - uint32_t v = j + i; + uint32_t v = j + static_cast<uint32_t>(i); w.Write(&v, sizeof(v)); } } diff --git a/coding/file_writer.cpp b/coding/file_writer.cpp index 61dd6ea2ae..4b95804fd7 100644 --- a/coding/file_writer.cpp +++ b/coding/file_writer.cpp @@ -30,7 +30,6 @@ uint64_t FileWriter::Pos() const void FileWriter::Seek(uint64_t pos) { - ASSERT_GREATER_OR_EQUAL(pos, 0, ()); m_pFileData->Seek(pos); } diff --git a/coding/file_writer.hpp b/coding/file_writer.hpp index 04f7919269..5b3ade04fd 100644 --- a/coding/file_writer.hpp +++ b/coding/file_writer.hpp @@ -29,11 +29,11 @@ public: explicit FileWriter(string const & fileName, Op operation = OP_WRITE_TRUNCATE, bool bTruncOnClose = false); - ~FileWriter(); + ~FileWriter() override; - void Seek(uint64_t pos); - uint64_t Pos() const; - void Write(void const * p, size_t size); + void Seek(uint64_t pos) override; + uint64_t Pos() const override; + void Write(void const * p, size_t size) override; void WritePaddingByEnd(size_t factor); void WritePaddingByPos(size_t factor); diff --git a/coding/multilang_utf8_string.cpp b/coding/multilang_utf8_string.cpp index 76d7c3cfa0..12a5ca5a67 100644 --- a/coding/multilang_utf8_string.cpp +++ b/coding/multilang_utf8_string.cpp @@ -26,6 +26,9 @@ StringUtf8Multilang::Languages const g_languages = {{ {"default", "Native for ea {"gsw", "Schwiizertüütsch"}, {"et", "Eesti"}, {"ku", "Kurdish"}, {"mn", "Mongolian"}, {"mk", "Македонски"}, {"lv", "Latviešu"}, {"hi", "हिन्दी"} }}; + +static_assert(g_languages.size() == StringUtf8Multilang::kMaxSupportedLanguages, + "With current encoding we are limited to 64 languages max."); } // namespace int8_t constexpr StringUtf8Multilang::kUnsupportedLanguageCode; @@ -44,9 +47,6 @@ StringUtf8Multilang::Languages const & StringUtf8Multilang::GetSupportedLanguage // static int8_t StringUtf8Multilang::GetLangIndex(string const & lang) { - static_assert(g_languages.size() == kMaxSupportedLanguages, - "With current encoding we are limited to 64 languages max."); - for (size_t i = 0; i < g_languages.size(); ++i) if (lang == g_languages[i].m_code) return static_cast<int8_t>(i); @@ -56,14 +56,14 @@ int8_t StringUtf8Multilang::GetLangIndex(string const & lang) // static char const * StringUtf8Multilang::GetLangByCode(int8_t langCode) { - if (langCode < 0 || langCode > static_cast<int8_t>(g_languages.size()) - 1) + if (langCode < 0 || langCode >= static_cast<int8_t>(g_languages.size())) return ""; return g_languages[langCode].m_code; } // static char const * StringUtf8Multilang::GetLangNameByCode(int8_t langCode) { - if (langCode < 0 || langCode > static_cast<int8_t>(g_languages.size()) - 1) + if (langCode < 0 || langCode >= static_cast<int8_t>(g_languages.size())) return ""; return g_languages[langCode].m_name; } diff --git a/coding/writer.hpp b/coding/writer.hpp index c7177499cd..59f56a623e 100644 --- a/coding/writer.hpp +++ b/coding/writer.hpp @@ -1,6 +1,7 @@ #pragma once #include "base/assert.hpp" #include "base/base.hpp" +#include "base/checked_cast.hpp" #include "base/exception.hpp" #include "std/algorithm.hpp" #include "std/shared_ptr.hpp" @@ -9,7 +10,6 @@ #include "std/vector.hpp" // Generic Writer. Not thread-safe. -// When SubWriter is used, pos can negative, so int64_t is used to store pos. class Writer { public: @@ -30,24 +30,22 @@ template <typename ContainerT> class MemWriter : public Writer { public: - inline MemWriter(ContainerT & data) : m_Data(data), m_Pos(0) + inline explicit MemWriter(ContainerT & data) : m_Data(data), m_Pos(0) { static_assert(sizeof(typename ContainerT::value_type) == 1, ""); } - inline void Seek(uint64_t pos) + inline void Seek(uint64_t pos) override { - ASSERT_EQUAL(pos, static_cast<uintptr_t>(pos), ()); - ASSERT_GREATER_OR_EQUAL(pos, 0, ()); - m_Pos = static_cast<uintptr_t>(pos); + m_Pos = base::asserted_cast<uintptr_t>(pos); } - inline uint64_t Pos() const + inline uint64_t Pos() const override { return m_Pos; } - inline void Write(void const * p, size_t size) + inline void Write(void const * p, size_t size) override { intptr_t freeSize = m_Data.size() - m_Pos; if (freeSize < 0) @@ -75,7 +73,7 @@ private: // Original writer should not be used when SubWriter is active! // In destructor, SubWriter calls Seek() of original writer to the end of what has been written. template <typename WriterT> -class SubWriter +class SubWriter : public Writer { public: inline explicit SubWriter(WriterT & writer) @@ -86,14 +84,14 @@ public: { } - ~SubWriter() + ~SubWriter() override { ASSERT_EQUAL(m_offset, GetOffset(), ()); if (m_pos != m_maxPos) Seek(m_maxPos); } - inline void Seek(uint64_t pos) + inline void Seek(uint64_t pos) override { ASSERT_EQUAL(m_offset, GetOffset(), ()); m_writer.Seek(GetOffset() + pos); @@ -102,13 +100,13 @@ public: m_maxPos = max(m_maxPos, m_pos); } - inline uint64_t Pos() const + inline uint64_t Pos() const override { ASSERT_EQUAL(m_offset, GetOffset(), ()); return m_pos; } - inline void Write(void const * p, size_t size) + inline void Write(void const * p, size_t size) override { ASSERT_EQUAL(m_offset, GetOffset(), ()); m_writer.Write(p, size); @@ -132,22 +130,22 @@ private: }; template<typename WriterT> -class WriterPtr +class WriterPtr : public Writer { public: - WriterPtr(WriterT * p = 0) : m_p(p) {} + explicit WriterPtr(WriterT * p = 0) : m_p(p) {} - void Seek(uint64_t pos) + void Seek(uint64_t pos) override { m_p->Seek(pos); } - uint64_t Pos() const + uint64_t Pos() const override { return m_p->Pos(); } - void Write(void const * p, size_t size) + void Write(void const * p, size_t size) override { m_p->Write(p, size); } @@ -162,7 +160,7 @@ template <typename WriterT> class WriterSink { public: - inline WriterSink(WriterT & writer) : m_writer(writer), m_pos(0) {} + inline explicit WriterSink(WriterT & writer) : m_writer(writer), m_pos(0) {} inline void Write(void const * p, size_t size) { |