-
Notifications
You must be signed in to change notification settings - Fork 2
/
KeyboardPlayerInfo.h
39 lines (39 loc) · 1.12 KB
/
KeyboardPlayerInfo.h
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
#pragma once
namespace sds
{
/// <summary>
/// A data structure to hold player information.
/// A default constructed KeyboardPlayerInfo struct has default values that are usable.
/// Thread safe.
/// </summary>
struct KeyboardPlayerInfo final
{
using PidType = int;
//ISO CPP guidelines C.45 followed here: https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-default
std::atomic<PidType> player_id{ 0 };
//default ctor
KeyboardPlayerInfo() = default;
//copy constructor
KeyboardPlayerInfo(const KeyboardPlayerInfo &sp)
{
//temporary copies must be made to copy atomic to atomic
const PidType pid = sp.player_id;
player_id = pid;
}
//assignment
KeyboardPlayerInfo &operator=(const KeyboardPlayerInfo &sp)
{
if (this == &sp)
return *this;
//temporary copies must be made to copy atomic to atomic
const PidType pid= sp.player_id;
player_id = pid;
return *this;
}
//move constructor
KeyboardPlayerInfo(KeyboardPlayerInfo &&sp) = delete;
//Move assignment operator
KeyboardPlayerInfo &operator=(KeyboardPlayerInfo &&sp) = delete;
~KeyboardPlayerInfo() = default;
};
}