Skip to content

Commit

Permalink
Mark classes non copyable
Browse files Browse the repository at this point in the history
  • Loading branch information
visuve committed Apr 13, 2024
1 parent 01308f8 commit d6da8fb
Show file tree
Hide file tree
Showing 13 changed files with 49 additions and 0 deletions.
2 changes: 2 additions & 0 deletions PystykorvaLib/EncodingDetector.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class EncodingDetectorImpl
}
}

NonCopyable(EncodingDetectorImpl);

bool DetectEncoding(std::string_view sample, Pystykorva::EncodingGuess& encoding)
{
ucsdet_setText(
Expand Down
2 changes: 2 additions & 0 deletions PystykorvaLib/EncodingDetector.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "NonCopyable.hpp"
#include "Pystykorva.hpp"

class EncodingDetectorImpl;
Expand All @@ -17,6 +18,7 @@ class EncodingDetector
public:
EncodingDetector();
~EncodingDetector();
NonCopyable(EncodingDetector);

bool DetectEncoding(std::string_view sample, Pystykorva::EncodingGuess& encoding);

Expand Down
2 changes: 2 additions & 0 deletions PystykorvaLib/LineAnalyzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ class LineAnalyzerImpl
}
}

NonCopyable(LineAnalyzerImpl);

std::vector<Pystykorva::Position> Boundaries(std::u16string_view sample)
{
std::vector<Pystykorva::Position> result;
Expand Down
2 changes: 2 additions & 0 deletions PystykorvaLib/LineAnalyzer.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "NonCopyable.hpp"
#include "Pystykorva.hpp"

class LineAnalyzerImpl;
Expand All @@ -17,6 +18,7 @@ class LineAnalyzer
public:
LineAnalyzer();
~LineAnalyzer();
NonCopyable(LineAnalyzer);

std::vector<Pystykorva::Position> Boundaries(std::u16string_view sample);

Expand Down
4 changes: 4 additions & 0 deletions PystykorvaLib/MemoryMappedFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ class MemoryMappedFileImpl
}
}

NonCopyable(MemoryMappedFileImpl);

std::string_view Data() const
{
return { reinterpret_cast<char*>(_view), _size };
Expand Down Expand Up @@ -120,6 +122,8 @@ class MemoryMappedFileImpl
}
}

NonCopyable(MemoryMappedFileImpl);

std::string_view Sample(size_t size)
{
return { reinterpret_cast<char*>(_view), std::min(_size, size) };
Expand Down
2 changes: 2 additions & 0 deletions PystykorvaLib/MemoryMappedFile.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "NonCopyable.hpp"
#include "Pystykorva.hpp"

class MemoryMappedFileImpl;
Expand All @@ -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;
Expand Down
23 changes: 23 additions & 0 deletions PystykorvaLib/NonCopyable.hpp
Original file line number Diff line number Diff line change
@@ -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)
1 change: 1 addition & 0 deletions PystykorvaLib/PystykorvaLib.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
<ClInclude Include="EncodingDetector.hpp" />
<ClInclude Include="LineAnalyzer.hpp" />
<ClInclude Include="MemoryMappedFile.hpp" />
<ClInclude Include="NonCopyable.hpp" />
<ClInclude Include="TextProcessor.hpp" />
<ClInclude Include="Pystykorva.hpp" />
<ClInclude Include="PCH.hpp" />
Expand Down
2 changes: 2 additions & 0 deletions PystykorvaLib/TextProcessor.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "NonCopyable.hpp"
#include "Pystykorva.hpp"
#include "EncodingDetector.hpp"
#include "UnicodeConverter.hpp"
Expand All @@ -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<Pystykorva::Match>& matches, Pystykorva::EncodingGuess& encoding);
Expand Down
2 changes: 2 additions & 0 deletions PystykorvaLib/TextSearcher.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ class TextSearcherImpl
}
}

NonCopyable(TextSearcherImpl);

std::vector<Pystykorva::Position> FindIn(std::u16string_view sentence)
{
std::vector<Pystykorva::Position> result;
Expand Down
2 changes: 2 additions & 0 deletions PystykorvaLib/TextSearcher.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "NonCopyable.hpp"
#include "Pystykorva.hpp"

struct SearchException : std::runtime_error
Expand All @@ -17,6 +18,7 @@ class TextSearcher
public:
TextSearcher(std::u16string_view expression, Pystykorva::MatchMode mode);
~TextSearcher();
NonCopyable(TextSearcher);

std::vector<Pystykorva::Position> FindIn(std::u16string_view sentence);
private:
Expand Down
2 changes: 2 additions & 0 deletions PystykorvaLib/UnicodeConverter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ class UnicodeConverterImpl
}
}

NonCopyable(UnicodeConverterImpl);

uint8_t CharSize() const
{
int8_t minCharSize = ucnv_getMinCharSize(_converter);
Expand Down
3 changes: 3 additions & 0 deletions PystykorvaLib/UnicodeConverter.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#pragma once

#include "NonCopyable.hpp"

class UnicodeConverterImpl;

struct ConversionException : std::runtime_error
Expand All @@ -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);
Expand Down

0 comments on commit d6da8fb

Please sign in to comment.