From 881db18f7d3670abdcd0cc5035e7799940c1d857 Mon Sep 17 00:00:00 2001 From: Lioncash Date: Mon, 26 Aug 2019 19:31:55 -0400 Subject: [PATCH] General: Make constructors explicit where applicable Makes non-conversion constructors explicit to make their construction obvious. --- include/LZ77/LZLookupTable.hpp | 2 +- include/athena/DNAOp.hpp | 7 ++++--- include/athena/FileReader.hpp | 4 ++-- include/athena/FileWriter.hpp | 8 ++++---- include/athena/MemoryReader.hpp | 6 +++--- include/athena/MemoryWriter.hpp | 2 +- include/athena/Socket.hpp | 4 ++-- include/athena/YAMLCommon.hpp | 2 +- include/athena/YAMLDocReader.hpp | 6 +++--- include/athena/YAMLDocWriter.hpp | 6 +++--- 10 files changed, 24 insertions(+), 23 deletions(-) diff --git a/include/LZ77/LZLookupTable.hpp b/include/LZ77/LZLookupTable.hpp index b157eb0..ec27367 100644 --- a/include/LZ77/LZLookupTable.hpp +++ b/include/LZ77/LZLookupTable.hpp @@ -15,7 +15,7 @@ struct LZLengthOffset { class LZLookupTable { public: LZLookupTable(); - LZLookupTable(atInt32 minimumMatch, atInt32 slidingWindow = 4096, atInt32 lookAheadWindow = 18); + explicit LZLookupTable(atInt32 minimumMatch, atInt32 slidingWindow = 4096, atInt32 lookAheadWindow = 18); ~LZLookupTable(); LZLengthOffset search(const atUint8* curPos, const atUint8* dataBegin, const atUint8* dataEnd); void setLookAheadWindow(atInt32 lookAheadWindow); diff --git a/include/athena/DNAOp.hpp b/include/athena/DNAOp.hpp index f37d2aa..f777863 100644 --- a/include/athena/DNAOp.hpp +++ b/include/athena/DNAOp.hpp @@ -21,8 +21,9 @@ struct PropId { template constexpr T opget() const; constexpr PropId() = default; - constexpr PropId(const char* name, uint32_t rcrc32, uint64_t crc64) : name(name), rcrc32(rcrc32), crc64(crc64) {} - constexpr PropId(const char* name) + constexpr explicit PropId(const char* name, uint32_t rcrc32, uint64_t crc64) + : name(name), rcrc32(rcrc32), crc64(crc64) {} + constexpr explicit PropId(const char* name) : name(name) , rcrc32(athena::checksums::literals::rcrc32_rec(0xFFFFFFFF, name)) , crc64(athena::checksums::literals::crc64_rec(0xFFFFFFFFFFFFFFFF, name)) {} @@ -41,7 +42,7 @@ constexpr uint64_t PropId::opget() const { } namespace literals { -constexpr PropId operator"" _propid(const char* s, size_t len) { return {s}; } +constexpr PropId operator"" _propid(const char* s, size_t len) { return PropId{s}; } } // namespace literals #define AT_PROP_CASE(...) case athena::io::PropId(__VA_ARGS__).opget() diff --git a/include/athena/FileReader.hpp b/include/athena/FileReader.hpp index 69a3357..11330c7 100644 --- a/include/athena/FileReader.hpp +++ b/include/athena/FileReader.hpp @@ -18,8 +18,8 @@ namespace athena::io { class FileReader : public IStreamReader { public: - FileReader(std::string_view filename, atInt32 cacheSize = (32 * 1024), bool globalErr = true); - FileReader(std::wstring_view filename, atInt32 cacheSize = (32 * 1024), bool globalErr = true); + explicit FileReader(std::string_view filename, atInt32 cacheSize = (32 * 1024), bool globalErr = true); + explicit FileReader(std::wstring_view filename, atInt32 cacheSize = (32 * 1024), bool globalErr = true); ~FileReader() override; std::string filename() const { diff --git a/include/athena/FileWriter.hpp b/include/athena/FileWriter.hpp index 99994ba..792b9be 100644 --- a/include/athena/FileWriter.hpp +++ b/include/athena/FileWriter.hpp @@ -15,8 +15,8 @@ namespace athena::io { class FileWriter : public IStreamWriter { public: - FileWriter(std::string_view filename, bool overwrite = true, bool globalErr = true); - FileWriter(std::wstring_view filename, bool overwrite = true, bool globalErr = true); + explicit FileWriter(std::string_view filename, bool overwrite = true, bool globalErr = true); + explicit FileWriter(std::wstring_view filename, bool overwrite = true, bool globalErr = true); ~FileWriter() override; std::string filename() const { @@ -71,7 +71,7 @@ class TransactionalFileWriter : public IStreamWriter { atUint64 m_position = 0; public: - TransactionalFileWriter(std::string_view filename, bool overwrite = true, bool globalErr = true) + explicit TransactionalFileWriter(std::string_view filename, bool overwrite = true, bool globalErr = true) : m_overwrite(overwrite), m_globalErr(globalErr) { #if _WIN32 m_filename = utility::utf8ToWide(filename); @@ -79,7 +79,7 @@ public: m_filename = filename; #endif } - TransactionalFileWriter(std::wstring_view filename, bool overwrite = true, bool globalErr = true) + explicit TransactionalFileWriter(std::wstring_view filename, bool overwrite = true, bool globalErr = true) : m_overwrite(overwrite), m_globalErr(globalErr) { #if _WIN32 m_filename = filename; diff --git a/include/athena/MemoryReader.hpp b/include/athena/MemoryReader.hpp index 7c254f2..ac780e7 100644 --- a/include/athena/MemoryReader.hpp +++ b/include/athena/MemoryReader.hpp @@ -28,7 +28,7 @@ public: * \param takeOwnership Memory will be freed with the reader if set. * \param globalErr Whether or not global errors are enabled. */ - MemoryReader(const void* data, atUint64 length, bool takeOwnership = false, bool globalErr = true); + explicit MemoryReader(const void* data, atUint64 length, bool takeOwnership = false, bool globalErr = true); /*! \brief Sets the buffers position relative to the specified position.
* It seeks relative to the current position by default. @@ -92,13 +92,13 @@ public: * \param data The existing buffer * \param length The length of the existing buffer */ - MemoryCopyReader(const void* data, atUint64 length); + explicit MemoryCopyReader(const void* data, atUint64 length); /*! \brief This constructor creates an instance from a file on disk. * * \param filename The file to create the stream from */ - MemoryCopyReader(const std::string& filename) : m_filepath(filename) { loadData(); } + explicit MemoryCopyReader(const std::string& filename) : m_filepath(filename) { loadData(); } void setData(const atUint8* data, atUint64 length); diff --git a/include/athena/MemoryWriter.hpp b/include/athena/MemoryWriter.hpp index 2e59e94..c9306d0 100644 --- a/include/athena/MemoryWriter.hpp +++ b/include/athena/MemoryWriter.hpp @@ -111,7 +111,7 @@ public: * * @param filename The file to create the stream from */ - MemoryCopyWriter(std::string_view filename); + explicit MemoryCopyWriter(std::string_view filename); /*! @brief Sets the buffers position relative to the specified position.
* It seeks relative to the current position by default. diff --git a/include/athena/Socket.hpp b/include/athena/Socket.hpp index fb19b89..94ff13a 100644 --- a/include/athena/Socket.hpp +++ b/include/athena/Socket.hpp @@ -21,7 +21,7 @@ class IPAddress { void resolve(const std::string& address); public: - IPAddress(const std::string& address) { resolve(address); } + explicit IPAddress(const std::string& address) { resolve(address); } uint32_t toInteger() const; operator bool() const { return m_valid; } @@ -47,7 +47,7 @@ public: static EResult LastWSAError(); #endif - Socket(bool blocking) : m_isBlocking(blocking) {} + explicit Socket(bool blocking) : m_isBlocking(blocking) {} ~Socket() { close(); } Socket(const Socket& other) = delete; diff --git a/include/athena/YAMLCommon.hpp b/include/athena/YAMLCommon.hpp index 1b282ea..2353c21 100644 --- a/include/athena/YAMLCommon.hpp +++ b/include/athena/YAMLCommon.hpp @@ -166,7 +166,7 @@ struct YAMLStdStringViewReaderState { std::string_view::const_iterator begin; std::string_view::const_iterator end; - YAMLStdStringViewReaderState(std::string_view str) { + explicit YAMLStdStringViewReaderState(std::string_view str) { begin = str.begin(); end = str.end(); } diff --git a/include/athena/YAMLDocReader.hpp b/include/athena/YAMLDocReader.hpp index a0f2cb4..af0f901 100644 --- a/include/athena/YAMLDocReader.hpp +++ b/include/athena/YAMLDocReader.hpp @@ -41,7 +41,7 @@ public: class RecordRAII { friend class YAMLDocReader; YAMLDocReader* m_r = nullptr; - RecordRAII(YAMLDocReader* r) : m_r(r) {} + explicit RecordRAII(YAMLDocReader* r) : m_r(r) {} RecordRAII() = default; public: @@ -70,11 +70,11 @@ public: class VectorRAII { friend class YAMLDocReader; YAMLDocReader* m_r = nullptr; - VectorRAII(YAMLDocReader* r) : m_r(r) {} + explicit VectorRAII(YAMLDocReader* r) : m_r(r) {} VectorRAII() = default; public: - operator bool() const { return m_r != nullptr; } + explicit operator bool() const { return m_r != nullptr; } ~VectorRAII() { if (m_r) m_r->_leaveSubVector(); diff --git a/include/athena/YAMLDocWriter.hpp b/include/athena/YAMLDocWriter.hpp index 557a061..47d0cdb 100644 --- a/include/athena/YAMLDocWriter.hpp +++ b/include/athena/YAMLDocWriter.hpp @@ -20,7 +20,7 @@ class YAMLDocWriter { void _leaveSubVector(); public: - YAMLDocWriter(const char* classType, athena::io::IStreamReader* reader = nullptr); + explicit YAMLDocWriter(const char* classType, athena::io::IStreamReader* reader = nullptr); ~YAMLDocWriter(); yaml_emitter_t* getEmitter() { return &m_emitter; } @@ -32,7 +32,7 @@ public: class RecordRAII { friend class YAMLDocWriter; YAMLDocWriter* m_w = nullptr; - RecordRAII(YAMLDocWriter* w) : m_w(w) {} + explicit RecordRAII(YAMLDocWriter* w) : m_w(w) {} RecordRAII() = default; public: @@ -55,7 +55,7 @@ public: class VectorRAII { friend class YAMLDocWriter; YAMLDocWriter* m_w = nullptr; - VectorRAII(YAMLDocWriter* w) : m_w(w) {} + explicit VectorRAII(YAMLDocWriter* w) : m_w(w) {} VectorRAII() = default; public: