Skip to content

Rule of three for Client #306

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Oct 4, 2021
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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