Remove unnecessary base class

This commit is contained in:
GHOSCHT 2022-02-05 19:08:51 +01:00
parent ce843015d6
commit c5ef3d9366
No known key found for this signature in database
GPG key ID: A35BD466B8871994
4 changed files with 47 additions and 69 deletions

View file

@ -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;
}

View file

@ -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);
};

View file

@ -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;
}

View file

@ -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();
};