From 12bf23e4c869153e1ed409d2d5630b0b735acd49 Mon Sep 17 00:00:00 2001 From: Stephen Birarda Date: Fri, 17 May 2013 12:14:44 -0700 Subject: [PATCH] disallow Agent copying --- libraries/shared/src/Agent.cpp | 61 -------------------------------- libraries/shared/src/Agent.h | 7 ++-- libraries/shared/src/AgentData.h | 7 ++-- 3 files changed, 7 insertions(+), 68 deletions(-) diff --git a/libraries/shared/src/Agent.cpp b/libraries/shared/src/Agent.cpp index db4170515a..f79e5702df 100644 --- a/libraries/shared/src/Agent.cpp +++ b/libraries/shared/src/Agent.cpp @@ -55,67 +55,6 @@ Agent::Agent(sockaddr* publicSocket, sockaddr* localSocket, char type, uint16_t } } -Agent::Agent(const Agent &otherAgent) : - _type(otherAgent._type), - _agentID(otherAgent._agentID), - _wakeMicrostamp(otherAgent._wakeMicrostamp), - _lastHeardMicrostamp(otherAgent._lastHeardMicrostamp), - _isAlive(otherAgent._isAlive) -{ - if (otherAgent._publicSocket) { - _publicSocket = new sockaddr(*otherAgent._localSocket); - } else { - _publicSocket = NULL; - } - - if (otherAgent._localSocket) { - _localSocket = new sockaddr(*otherAgent._localSocket); - } else { - _localSocket = NULL; - } - - if (otherAgent._activeSocket == otherAgent._publicSocket) { - _activeSocket = _publicSocket; - } else if (otherAgent._activeSocket == otherAgent._localSocket) { - _activeSocket = _localSocket; - } else { - _activeSocket = NULL; - } - - if (otherAgent._linkedData) { - _linkedData = otherAgent._linkedData->clone(); - } else { - _linkedData = NULL; - } - - if (otherAgent._bytesReceivedMovingAverage != NULL) { - _bytesReceivedMovingAverage = new SimpleMovingAverage(100); - memcpy(_bytesReceivedMovingAverage, otherAgent._bytesReceivedMovingAverage, sizeof(SimpleMovingAverage)); - } else { - _bytesReceivedMovingAverage = NULL; - } -} - -Agent& Agent::operator=(Agent otherAgent) { - swap(*this, otherAgent); - return *this; -} - -void Agent::swap(Agent &first, Agent &second) { - using std::swap; - - swap(first._isAlive, second._isAlive); - swap(first._publicSocket, second._publicSocket); - swap(first._localSocket, second._localSocket); - swap(first._activeSocket, second._activeSocket); - swap(first._type, second._type); - swap(first._linkedData, second._linkedData); - swap(first._agentID, second._agentID); - swap(first._wakeMicrostamp, second._wakeMicrostamp); - swap(first._lastHeardMicrostamp, second._lastHeardMicrostamp); - swap(first._bytesReceivedMovingAverage, second._bytesReceivedMovingAverage); -} - Agent::~Agent() { delete _publicSocket; delete _localSocket; diff --git a/libraries/shared/src/Agent.h b/libraries/shared/src/Agent.h index 55ef67c8e5..5201fd9048 100644 --- a/libraries/shared/src/Agent.h +++ b/libraries/shared/src/Agent.h @@ -24,9 +24,8 @@ class Agent { public: Agent(sockaddr* publicSocket, sockaddr* localSocket, char type, uint16_t agentID); - Agent(const Agent &otherAgent); ~Agent(); - Agent& operator=(Agent otherAgent); + bool operator==(const Agent& otherAgent); bool matches(sockaddr* otherPublicSocket, sockaddr* otherLocalSocket, char otherAgentType); @@ -66,7 +65,9 @@ public: static void printLog(Agent const&); private: - void swap(Agent &first, Agent &second); + // privatize copy and assignment operator to disallow Agent copying + Agent(const Agent &otherAgent); + Agent& operator=(Agent otherAgent); char _type; uint16_t _agentID; diff --git a/libraries/shared/src/AgentData.h b/libraries/shared/src/AgentData.h index f8bef16b41..342f501a1e 100644 --- a/libraries/shared/src/AgentData.h +++ b/libraries/shared/src/AgentData.h @@ -10,10 +10,9 @@ #define hifi_AgentData_h class AgentData { - public: - virtual ~AgentData() = 0; - virtual int parseData(unsigned char* sourceBuffer, int numBytes) = 0; - virtual AgentData* clone() const = 0; +public: + virtual ~AgentData() = 0; + virtual int parseData(unsigned char* sourceBuffer, int numBytes) = 0; }; #endif