-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommunicator.hpp
93 lines (70 loc) · 1.8 KB
/
Communicator.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*
* Communicator.hpp
*
* Created on: 10.04.2017
* Author: hartung
*/
#ifndef COMMUNICATOR_HPP_
#define COMMUNICATOR_HPP_
#include <vector>
#include "Indicator.hpp"
template<typename T>
class Communicator
{
public:
typedef T value_type;
Communicator( const unsigned & sizeBuffer)
: _sizeBuffer(sizeBuffer),
_charBufferSize(_sizeBuffer * sizeof(T) + sizeof(Indicator))
{
}
virtual ~Communicator()
{
for(unsigned i=0;i<_mem.size();++i)
delete[] _mem[i];
}
virtual void addBuffer()
{
_mem.push_back( new char[_charBufferSize]);
}
Indicator & getIndicatorOfWin(const unsigned & pos)
{
return *reinterpret_cast<Indicator*>(_mem[pos]);
}
const Indicator & getIndicatorOfWin(const unsigned & pos) const
{
return *reinterpret_cast<Indicator*>(_mem[pos]);
}
T * getDataOfWin(const unsigned & pos)
{
return reinterpret_cast<T*>(_mem[pos] + sizeof(Indicator));
}
const T * getDataOfWin(const unsigned & pos) const
{
return reinterpret_cast<T*>(_mem[pos] + sizeof(Indicator));
}
unsigned getNumCreatedBuffer() const
{
return _mem.size();
}
unsigned getCharBufferSize() const
{
return _charBufferSize;
}
const unsigned & getSizeBuffer() const
{
return _sizeBuffer;
}
virtual void openConnection(const unsigned & pos) = 0;
virtual bool checkIfRecvCompleted(const unsigned & pos) = 0;
virtual bool checkIfFreeForSend(const unsigned & pos) = 0;
virtual void sendData(const unsigned & pos, const int & num) = 0;
virtual void finishReceiver() = 0;
virtual void finishSender() = 0;
private:
const unsigned _sizeBuffer;
const unsigned _charBufferSize;
protected:
std::vector<char*> _mem;
};
#endif /* COMMUNICATOR_HPP_ */