From d6da8fbb20e99d261b4d2554be56729c203fc1b8 Mon Sep 17 00:00:00 2001 From: visuve Date: Sat, 13 Apr 2024 11:45:13 +0300 Subject: [PATCH] Mark classes non copyable --- PystykorvaLib/EncodingDetector.cpp | 2 ++ PystykorvaLib/EncodingDetector.hpp | 2 ++ PystykorvaLib/LineAnalyzer.cpp | 2 ++ PystykorvaLib/LineAnalyzer.hpp | 2 ++ PystykorvaLib/MemoryMappedFile.cpp | 4 ++++ PystykorvaLib/MemoryMappedFile.hpp | 2 ++ PystykorvaLib/NonCopyable.hpp | 23 +++++++++++++++++++++++ PystykorvaLib/PystykorvaLib.vcxproj | 1 + PystykorvaLib/TextProcessor.hpp | 2 ++ PystykorvaLib/TextSearcher.cpp | 2 ++ PystykorvaLib/TextSearcher.hpp | 2 ++ PystykorvaLib/UnicodeConverter.cpp | 2 ++ PystykorvaLib/UnicodeConverter.hpp | 3 +++ 13 files changed, 49 insertions(+) create mode 100644 PystykorvaLib/NonCopyable.hpp diff --git a/PystykorvaLib/EncodingDetector.cpp b/PystykorvaLib/EncodingDetector.cpp index 164c814..85d864f 100644 --- a/PystykorvaLib/EncodingDetector.cpp +++ b/PystykorvaLib/EncodingDetector.cpp @@ -21,6 +21,8 @@ class EncodingDetectorImpl } } + NonCopyable(EncodingDetectorImpl); + bool DetectEncoding(std::string_view sample, Pystykorva::EncodingGuess& encoding) { ucsdet_setText( diff --git a/PystykorvaLib/EncodingDetector.hpp b/PystykorvaLib/EncodingDetector.hpp index 9099ef6..05013a4 100644 --- a/PystykorvaLib/EncodingDetector.hpp +++ b/PystykorvaLib/EncodingDetector.hpp @@ -1,5 +1,6 @@ #pragma once +#include "NonCopyable.hpp" #include "Pystykorva.hpp" class EncodingDetectorImpl; @@ -17,6 +18,7 @@ class EncodingDetector public: EncodingDetector(); ~EncodingDetector(); + NonCopyable(EncodingDetector); bool DetectEncoding(std::string_view sample, Pystykorva::EncodingGuess& encoding); diff --git a/PystykorvaLib/LineAnalyzer.cpp b/PystykorvaLib/LineAnalyzer.cpp index 838db6a..bd5cd05 100644 --- a/PystykorvaLib/LineAnalyzer.cpp +++ b/PystykorvaLib/LineAnalyzer.cpp @@ -21,6 +21,8 @@ class LineAnalyzerImpl } } + NonCopyable(LineAnalyzerImpl); + std::vector Boundaries(std::u16string_view sample) { std::vector result; diff --git a/PystykorvaLib/LineAnalyzer.hpp b/PystykorvaLib/LineAnalyzer.hpp index d5c56ef..93b87e8 100644 --- a/PystykorvaLib/LineAnalyzer.hpp +++ b/PystykorvaLib/LineAnalyzer.hpp @@ -1,5 +1,6 @@ #pragma once +#include "NonCopyable.hpp" #include "Pystykorva.hpp" class LineAnalyzerImpl; @@ -17,6 +18,7 @@ class LineAnalyzer public: LineAnalyzer(); ~LineAnalyzer(); + NonCopyable(LineAnalyzer); std::vector Boundaries(std::u16string_view sample); diff --git a/PystykorvaLib/MemoryMappedFile.cpp b/PystykorvaLib/MemoryMappedFile.cpp index 8934adf..f057d5f 100644 --- a/PystykorvaLib/MemoryMappedFile.cpp +++ b/PystykorvaLib/MemoryMappedFile.cpp @@ -68,6 +68,8 @@ class MemoryMappedFileImpl } } + NonCopyable(MemoryMappedFileImpl); + std::string_view Data() const { return { reinterpret_cast(_view), _size }; @@ -120,6 +122,8 @@ class MemoryMappedFileImpl } } + NonCopyable(MemoryMappedFileImpl); + std::string_view Sample(size_t size) { return { reinterpret_cast(_view), std::min(_size, size) }; diff --git a/PystykorvaLib/MemoryMappedFile.hpp b/PystykorvaLib/MemoryMappedFile.hpp index 371829a..1802b1e 100644 --- a/PystykorvaLib/MemoryMappedFile.hpp +++ b/PystykorvaLib/MemoryMappedFile.hpp @@ -1,5 +1,6 @@ #pragma once +#include "NonCopyable.hpp" #include "Pystykorva.hpp" class MemoryMappedFileImpl; @@ -11,6 +12,7 @@ class MemoryMappedFile : public Pystykorva::IFile public: MemoryMappedFile(const std::filesystem::path&, uint64_t); ~MemoryMappedFile(); + NonCopyable(MemoryMappedFile); std::string_view Sample(size_t size = 0x400) const override; std::string_view Data() const override; diff --git a/PystykorvaLib/NonCopyable.hpp b/PystykorvaLib/NonCopyable.hpp new file mode 100644 index 0000000..90b6e60 --- /dev/null +++ b/PystykorvaLib/NonCopyable.hpp @@ -0,0 +1,23 @@ +#pragma once + +#define NonCopyConstructible(Class) \ + Class(const Class &) = delete; + +#define NonMoveConstructible(Class) \ + Class(Class&&) = delete; + +#define NonCopyAssignable(Class) \ + Class& operator = (const Class&) = delete; + +#define NonMoveAssignable(Class) \ + Class& operator = (Class&&) = delete; + +#define NonCopyable(Class) \ + NonCopyConstructible(Class) \ + NonMoveConstructible(Class) \ + NonCopyAssignable(Class) \ + NonMoveAssignable(Class) + +#define NonAssignable(Class) \ + NonCopyAssignable(Class) \ + NonMoveAssignable(Class) diff --git a/PystykorvaLib/PystykorvaLib.vcxproj b/PystykorvaLib/PystykorvaLib.vcxproj index e0ce81f..026eeae 100644 --- a/PystykorvaLib/PystykorvaLib.vcxproj +++ b/PystykorvaLib/PystykorvaLib.vcxproj @@ -28,6 +28,7 @@ + diff --git a/PystykorvaLib/TextProcessor.hpp b/PystykorvaLib/TextProcessor.hpp index dc20501..a937222 100644 --- a/PystykorvaLib/TextProcessor.hpp +++ b/PystykorvaLib/TextProcessor.hpp @@ -1,5 +1,6 @@ #pragma once +#include "NonCopyable.hpp" #include "Pystykorva.hpp" #include "EncodingDetector.hpp" #include "UnicodeConverter.hpp" @@ -11,6 +12,7 @@ class TextProcessor public: TextProcessor(std::stop_token, const Pystykorva::Options&); ~TextProcessor(); + NonCopyable(TextProcessor); Pystykorva::Result ProcessFile(const std::filesystem::path&); void FindAll(Pystykorva::IFile& file, std::vector& matches, Pystykorva::EncodingGuess& encoding); diff --git a/PystykorvaLib/TextSearcher.cpp b/PystykorvaLib/TextSearcher.cpp index 48e29e5..10536c5 100644 --- a/PystykorvaLib/TextSearcher.cpp +++ b/PystykorvaLib/TextSearcher.cpp @@ -47,6 +47,8 @@ class TextSearcherImpl } } + NonCopyable(TextSearcherImpl); + std::vector FindIn(std::u16string_view sentence) { std::vector result; diff --git a/PystykorvaLib/TextSearcher.hpp b/PystykorvaLib/TextSearcher.hpp index c0a51ae..f69eff8 100644 --- a/PystykorvaLib/TextSearcher.hpp +++ b/PystykorvaLib/TextSearcher.hpp @@ -1,5 +1,6 @@ #pragma once +#include "NonCopyable.hpp" #include "Pystykorva.hpp" struct SearchException : std::runtime_error @@ -17,6 +18,7 @@ class TextSearcher public: TextSearcher(std::u16string_view expression, Pystykorva::MatchMode mode); ~TextSearcher(); + NonCopyable(TextSearcher); std::vector FindIn(std::u16string_view sentence); private: diff --git a/PystykorvaLib/UnicodeConverter.cpp b/PystykorvaLib/UnicodeConverter.cpp index 1a32b18..6864f78 100644 --- a/PystykorvaLib/UnicodeConverter.cpp +++ b/PystykorvaLib/UnicodeConverter.cpp @@ -18,6 +18,8 @@ class UnicodeConverterImpl } } + NonCopyable(UnicodeConverterImpl); + uint8_t CharSize() const { int8_t minCharSize = ucnv_getMinCharSize(_converter); diff --git a/PystykorvaLib/UnicodeConverter.hpp b/PystykorvaLib/UnicodeConverter.hpp index cae10f6..0bc3f56 100644 --- a/PystykorvaLib/UnicodeConverter.hpp +++ b/PystykorvaLib/UnicodeConverter.hpp @@ -1,5 +1,7 @@ #pragma once +#include "NonCopyable.hpp" + class UnicodeConverterImpl; struct ConversionException : std::runtime_error @@ -15,6 +17,7 @@ class UnicodeConverter public: UnicodeConverter(std::string_view encoding); ~UnicodeConverter(); + NonCopyable(UnicodeConverter); uint8_t CharSize() const; void Convert(std::string_view sample, bool flush = true);