10000 Use `delete` instead of hiding copy constructors and assignments (#1820) · smartcoder00/ArduinoJson@b2b995e · GitHub
[go: up one dir, main page]

Skip to content

Commit b2b995e

Browse files
committed
Use delete instead of hiding copy constructors and assignments (#1820)
1 parent 33a4773 commit b2b995e

File tree

5 files changed

+9
-15
lines changed

5 files changed

+9
-15
lines changed

extras/tests/Helpers/CustomReader.hpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ class CustomReader {
1111

1212
public:
1313
CustomReader(const char* input) : _stream(input) {}
14+
CustomReader(const CustomReader&) = delete;
1415

1516
int read() {
1617
return _stream.get();
@@ -20,7 +21,4 @@ class CustomReader {
2021
_stream.read(buffer, static_cast<std::streamsize>(length));
2122
return static_cast<size_t>(_stream.gcount());
2223
}
23-
24-
private:
25-
CustomReader(const CustomReader&);
2624
};

extras/tests/JsonDocument/BasicJsonDocument.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ class SpyingAllocator {
1212
public:
1313
SpyingAllocator(const SpyingAllocator& src) : _log(src._log) {}
1414
SpyingAllocator(std::ostream& log) : _log(log) {}
15+
SpyingAllocator& operator=(const SpyingAllocator& src) = delete;
1516

1617
void* allocate(size_t n) {
1718
_log << "A" << n;
@@ -23,8 +24,6 @@ class SpyingAllocator {
2324
}
2425

2526
private:
26-
SpyingAllocator& operator=(const SpyingAllocator& src);
27-
2827
std::ostream& _log;
2928
};
3029

extras/tests/JsonSerializer/CustomWriter.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
class CustomWriter {
99
public:
1010
CustomWriter() {}
11+
CustomWriter(const CustomWriter&) = delete;
12+
CustomWriter& operator=(const CustomWriter&) = delete;
1113

1214
size_t write(uint8_t c) {
1315
_str.append(1, static_cast<char>(c));
@@ -24,9 +26,6 @@ class CustomWriter {
2426
}
2527

2628
private:
27-
CustomWriter(const CustomWriter&); // non-copiable
28-
CustomWriter& operator=(const CustomWriter&);
29-
3029
std::string _str;
3130
};
3231

src/ArduinoJson/Document/JsonDocument.hpp

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,9 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
2020
friend class detail::VariantAttorney;
2121

2222
public:
23+
8000 JsonDocument(const JsonDocument&) = delete;
24+
JsonDocument& operator=(const JsonDocument&) = delete;
25+
2326
// Casts the root to the specified type.
2427
// https://arduinojson.org/v6/api/jsondocument/as/
2528
template <typename T>
@@ -303,10 +306,6 @@ class JsonDocument : public detail::VariantOperators<const JsonDocument&> {
303306
detail::MemoryPool _pool;
304307
detail::VariantData _data;
305308

306-
private:
307-
JsonDocument(const JsonDocument&);
308-
JsonDocument& operator=(const JsonDocument&);
309-
310309
protected:
311310
detail::MemoryPool* getPool() {
312311
return &_pool;

src/ArduinoJson/Json/TextFormatter.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ class TextFormatter {
2222
public:
2323
explicit TextFormatter(TWriter writer) : _writer(writer) {}
2424

25+
TextFormatter& operator=(const TextFormatter&) = delete;
26+
2527
// Returns the number of bytes sent to the TWriter implementation.
2628
size_t bytesWritten() const {
2729
return _writer.count();
@@ -166,9 +168,6 @@ class TextFormatter {
166168

167169
protected:
168170
CountingDecorator<TWriter> _writer;
169-
170-
private:
171-
TextFormatter& operator=(const TextFormatter&); // cannot be assigned
172171
};
173172

174173
ARDUINOJSON_END_PRIVATE_NAMESPACE

0 commit comments

Comments
 (0)
0