Remove unnecessary base class
This commit is contained in:
parent
ce843015d6
commit
c5ef3d9366
4 changed files with 47 additions and 69 deletions
|
@ -1,48 +0,0 @@
|
|||
#include <Communicator.h>
|
||||
|
||||
Communicator::Communicator(__SIZE_TYPE__ bufferSize)
|
||||
{
|
||||
this->messageBuffer = new char[bufferSize];
|
||||
this->bufferSize = bufferSize;
|
||||
}
|
||||
|
||||
char *Communicator::getBuffer()
|
||||
{
|
||||
return messageBuffer;
|
||||
}
|
||||
|
||||
int Communicator::getBufferSize()
|
||||
{
|
||||
return this->bufferSize;
|
||||
}
|
||||
|
||||
__SIZE_TYPE__ Communicator::calculateMessageOutSize(__SIZE_TYPE__ numberOfValues)
|
||||
{
|
||||
return numberOfValues + (numberOfValues - 1) + 1;
|
||||
}
|
||||
|
||||
void Communicator::parseIDs(int *values, __SIZE_TYPE__ numberOfValues, char *output)
|
||||
{
|
||||
__SIZE_TYPE__ outputSize = calculateMessageOutSize(numberOfValues);
|
||||
__SIZE_TYPE__ outputCharPointer = 0;
|
||||
output[outputSize - 1] = '\0';
|
||||
|
||||
for (__SIZE_TYPE__ i = 0; i < numberOfValues; i++)
|
||||
{
|
||||
output[outputCharPointer++] = values[i] + '0';
|
||||
if (outputCharPointer < outputSize - 1)
|
||||
output[outputCharPointer++] = ',';
|
||||
}
|
||||
}
|
||||
|
||||
void Communicator::sendMessage(int *values, __SIZE_TYPE__ numberOfValues)
|
||||
{
|
||||
}
|
||||
void Communicator::sendMessage(char *message)
|
||||
{
|
||||
}
|
||||
|
||||
char *Communicator::receiveMessage()
|
||||
{
|
||||
return nullptr;
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
class Communicator
|
||||
{
|
||||
private:
|
||||
char *messageBuffer;
|
||||
__SIZE_TYPE__ bufferSize;
|
||||
|
||||
public:
|
||||
Communicator(__SIZE_TYPE__ bufferSize);
|
||||
virtual void sendMessage(int *values, __SIZE_TYPE__ numberOfValues);
|
||||
virtual void sendMessage(char *message);
|
||||
virtual char *receiveMessage();
|
||||
char *getBuffer();
|
||||
int getBufferSize();
|
||||
void parseIDs(int *values, __SIZE_TYPE__ numberOfValues, char *out);
|
||||
__SIZE_TYPE__ calculateMessageOutSize(__SIZE_TYPE__ numberOfValues);
|
||||
};
|
|
@ -1,10 +1,12 @@
|
|||
#include <StreamCommunicator.h>
|
||||
|
||||
StreamCommunicator::StreamCommunicator(Stream &s_out, __SIZE_TYPE__ bufferSize) : Communicator(bufferSize), stream(s_out)
|
||||
StreamCommunicator::StreamCommunicator(Stream &s_out, __SIZE_TYPE__ bufferSize) : stream(s_out)
|
||||
{
|
||||
this->messageBuffer = new char[bufferSize];
|
||||
this->bufferSize = bufferSize;
|
||||
}
|
||||
|
||||
void StreamCommunicator::sendMessage(int *values, int numberOfValues)
|
||||
void StreamCommunicator::sendMessage(int *values, __SIZE_TYPE__ numberOfValues)
|
||||
{
|
||||
char message[calculateMessageOutSize(numberOfValues)];
|
||||
parseIDs(values, numberOfValues, message);
|
||||
|
@ -25,3 +27,37 @@ char *StreamCommunicator::receiveMessage()
|
|||
}
|
||||
return getBuffer();
|
||||
}
|
||||
|
||||
__SIZE_TYPE__ StreamCommunicator::calculateMessageOutSize(__SIZE_TYPE__ numberOfValues)
|
||||
{
|
||||
return numberOfValues + (numberOfValues - 1) + 1;
|
||||
}
|
||||
|
||||
void StreamCommunicator::parseIDs(int *values, __SIZE_TYPE__ numberOfValues, char *output)
|
||||
{
|
||||
__SIZE_TYPE__ outputSize = calculateMessageOutSize(numberOfValues);
|
||||
__SIZE_TYPE__ outputCharPointer = 0;
|
||||
output[outputSize - 1] = '\0';
|
||||
|
||||
for (__SIZE_TYPE__ i = 0; i < numberOfValues; i++)
|
||||
{
|
||||
output[outputCharPointer++] = values[i] + '0';
|
||||
if (outputCharPointer < outputSize - 1)
|
||||
output[outputCharPointer++] = ',';
|
||||
}
|
||||
}
|
||||
|
||||
char *StreamCommunicator::getBuffer()
|
||||
{
|
||||
return messageBuffer;
|
||||
}
|
||||
|
||||
int StreamCommunicator::getBufferSize()
|
||||
{
|
||||
return this->bufferSize;
|
||||
}
|
||||
|
||||
Stream *StreamCommunicator::getStream()
|
||||
{
|
||||
return &stream;
|
||||
}
|
|
@ -1,14 +1,20 @@
|
|||
#include <Communicator.h>
|
||||
#include "Stream.h"
|
||||
|
||||
class StreamCommunicator : public Communicator
|
||||
class StreamCommunicator
|
||||
{
|
||||
protected:
|
||||
Stream &stream;
|
||||
char *messageBuffer;
|
||||
__SIZE_TYPE__ bufferSize;
|
||||
__SIZE_TYPE__ calculateMessageOutSize(__SIZE_TYPE__ numberOfValues);
|
||||
void parseIDs(int *values, __SIZE_TYPE__ numberOfValues, char *out);
|
||||
|
||||
public:
|
||||
StreamCommunicator(Stream &s_out, __SIZE_TYPE__ bufferSize);
|
||||
void sendMessage(int *values, int numberOfValues);
|
||||
void sendMessage(int *values, __SIZE_TYPE__ numberOfValues);
|
||||
void sendMessage(char *message);
|
||||
char *receiveMessage();
|
||||
char *getBuffer();
|
||||
int getBufferSize();
|
||||
Stream *getStream();
|
||||
};
|
Reference in a new issue