Skip to content
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed
- Change 266 files from CRLF to LF.
- Apply "rule of three" to Client copy constructor and copy assignment operator

### Deprecated

Expand Down
7 changes: 7 additions & 0 deletions SampleProjects/TestSomething/test/clientServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@ unittest(Client) {
assertEqual(outData + "\r\n", inData);
}

unittest(Client_copy_constructor) {
Client client1;
Client client2;
client2 = client1;
assertTrue(true);
}

unittest(IPAddress) {
IPAddress ipAddress0;
assertEqual(0, ipAddress0.asWord());
Expand Down
21 changes: 20 additions & 1 deletion cpp/arduino/Client.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#pragma once

#include <Stream.h>
#include <IPAddress.h>
#include <Stream.h>

class Client : public Stream {
public:
Expand All @@ -11,6 +11,25 @@ class Client : public Stream {
mGodmodeDataIn = new String;
}
}
Client(const Client &client) { // copy constructor
if (this != &client) { // not a self-assignment
if (mGodmodeDataIn &&
client.mGodmodeDataIn) { // replace what we previously had
delete mGodmodeDataIn; // get rid of previous value
mGodmodeDataIn = new String(client.mGodmodeDataIn->c_str());
}
}
}
Client &operator=(const Client &client) { // copy assignment operator
if (this != &client) { // not a self-assignment
if (mGodmodeDataIn &&
client.mGodmodeDataIn) { // replace what we previously had
delete mGodmodeDataIn; // get rid of previous value
mGodmodeDataIn = new String(client.mGodmodeDataIn->c_str());
}
}
return *this;
}
~Client() {
if (mGodmodeDataIn) {
delete mGodmodeDataIn;
Expand Down