From 725a42ae6ca7f227308f3f8ce243bf2f8b3200d8 Mon Sep 17 00:00:00 2001 From: Greg Foss Date: Thu, 7 May 2020 19:48:14 -0400 Subject: [PATCH] Changing incoming attribute storage from vector to map --- bfs/include/Attribute.hpp | 13 ++++++++++++- bfs/include/DataSyncThread.hpp | 5 +++-- bfs/src/comms/DataSyncThread.cpp | 8 ++++---- 3 files changed, 19 insertions(+), 7 deletions(-) diff --git a/bfs/include/Attribute.hpp b/bfs/include/Attribute.hpp index 075c07d..43905cd 100644 --- a/bfs/include/Attribute.hpp +++ b/bfs/include/Attribute.hpp @@ -21,6 +21,12 @@ class Attribute size_t length; void* value; public: + Attribute() + { + key = ""; + length = 0; + value = NULL; + } Attribute(BinaryAttributeStructure bin, void* value) { key = ""; for (int i = 0; i < ATTRIB_KEY_SIZE; i++) @@ -28,13 +34,18 @@ class Attribute length = bin.length; this->value = value; } - Attribute(string key, size_t length, void* value) { this->key = key; this->length = length; this->value = value; } + Attribute(const Attribute& toCopy) + { + this->key = string(toCopy.key); + this->length = toCopy.length; + this->value = toCopy.value; + } ~Attribute() { diff --git a/bfs/include/DataSyncThread.hpp b/bfs/include/DataSyncThread.hpp index bcd47e5..797ccd2 100644 --- a/bfs/include/DataSyncThread.hpp +++ b/bfs/include/DataSyncThread.hpp @@ -10,6 +10,7 @@ #include #include #include +#include #include #include @@ -45,10 +46,10 @@ class DataSyncThread // if this one is still running bool threadRunning = false; - vector incomingAttributes; + map incomingAttributes; HANDLE attribMutex; public: - DataSyncThread(SOCKET s) + DataSyncThread(SOCKET s) { sock = s; attribMutex = CreateMutex(NULL, false, NULL); diff --git a/bfs/src/comms/DataSyncThread.cpp b/bfs/src/comms/DataSyncThread.cpp index 4e7c6b8..dd9424b 100644 --- a/bfs/src/comms/DataSyncThread.cpp +++ b/bfs/src/comms/DataSyncThread.cpp @@ -147,7 +147,7 @@ void DataSyncThread::addIncomingAttribute(Attribute attrib) { DWORD result = WaitForSingleObject(attribMutex, INFINITE); if (result == WAIT_OBJECT_0) { - incomingAttributes.push_back(attrib); + incomingAttributes[string(attrib.getKey())] = attrib; ReleaseMutex(attribMutex); } else { @@ -253,7 +253,7 @@ int DataSyncThread::connectToAlgorithm(char* serverName) } } -vector DataSyncThread::getIncomingAttributes() +vector DataSyncThread :: getIncomingAttributes() { vector newAttribVector; if (! areIncomingAttributesAvailable()) @@ -261,9 +261,9 @@ vector DataSyncThread::getIncomingAttributes() DWORD result = WaitForSingleObject(attribMutex, INFINITE); if (result == WAIT_OBJECT_0) { - for (Attribute attrib : incomingAttributes) + for (auto attrib : incomingAttributes) { - newAttribVector.push_back(attrib); + newAttribVector.push_back(attrib.second); } incomingAttributes.clear(); ReleaseMutex(attribMutex);