-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathBt_PlacementPointer.hpp
81 lines (61 loc) · 1.86 KB
/
Bt_PlacementPointer.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
//*************************************************************************************************
//
// BITTAILOR.CH - BtMqttSn, an Arduino library for MQTT-SN over nRF24L01+
//
//-------------------------------------------------------------------------------------------------
//
// BT::PlacementPointer
//
//*************************************************************************************************
#ifndef INC__Bt_PlacementPointer__hpp
#define INC__Bt_PlacementPointer__hpp
namespace Bt {
template<typename T>
class PlacementPointer {
public:
PlacementPointer(){
}
T& operator*() {
return *typed();
}
T* operator-> ()
{
return typed();
}
void create() {
new (raw()) T();
}
template<typename Arg1>
void create(Arg1 iArg1) {
new (raw()) T(iArg1);
}
template<typename Arg1, typename Arg2>
void create(Arg1 iArg1, Arg2 iArg2) {
new (raw()) T(iArg1, iArg2);
}
template<typename Arg1, typename Arg2, typename Arg3>
void create(Arg1 iArg1, Arg2 iArg2, Arg3 iArg3) {
new (raw()) T(iArg1, iArg2, iArg3);
}
template<typename Arg1, typename Arg2, typename Arg3, typename Arg4>
void create(Arg1 iArg1, Arg2 iArg2, Arg3 iArg3, Arg4 iArg4) {
new (raw()) T(iArg1, iArg2, iArg3, iArg4);
}
void dispose() {
typed()->~T();
}
private:
// Constructor to prohibit copy construction.
PlacementPointer(const PlacementPointer&);
// Operator= to prohibit copy assignment
PlacementPointer& operator=(const PlacementPointer&);
T* typed() {
return reinterpret_cast<T*>(mMemory);
}
void* raw() {
return mMemory;
}
uint8_t mMemory[sizeof(T)];
};
} // namespace Bt
#endif // INC__Bt_PlacementPointer__hpp