forked from RetroAchievements/RAIntegration
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathModelPropertyContainer.hh
More file actions
149 lines (122 loc) · 4.85 KB
/
Copy pathModelPropertyContainer.hh
File metadata and controls
149 lines (122 loc) · 4.85 KB
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
#ifndef RA_DATA_MODEL_PROPERTY_CONTAINER_H
#define RA_DATA_MODEL_PROPERTY_CONTAINER_H
#pragma once
#include "data\ModelProperty.hh"
#include <mutex>
namespace ra {
namespace data {
class ModelPropertyContainer
{
public:
GSL_SUPPRESS_F6 ModelPropertyContainer() = default;
#ifdef DEBUG
virtual ~ModelPropertyContainer() noexcept {
m_bDestructed = true;
}
bool m_bDestructed = false;
#else
virtual ~ModelPropertyContainer() noexcept = default;
#endif
ModelPropertyContainer(const ModelPropertyContainer&) = delete;
ModelPropertyContainer& operator=(const ModelPropertyContainer&) = delete;
GSL_SUPPRESS_F6 ModelPropertyContainer(ModelPropertyContainer&&) = delete;
GSL_SUPPRESS_F6 ModelPropertyContainer& operator=(ModelPropertyContainer&&) = delete;
/// <summary>
/// Gets the value associated to the requested boolean property.
/// </summary>
/// <param name="pProperty">The property to query.</param>
/// <returns>The current value of the property for this object.</returns>
bool GetValue(const BoolModelProperty& pProperty) const
{
const int* pValue = FindValue(pProperty.GetKey());
return pValue ? (*pValue != 0) : pProperty.GetDefaultValue();
}
/// <summary>
/// Sets the specified boolean property to the specified value.
/// </summary>
/// <param name="pProperty">The property to set.</param>
/// <param name="bValue">The value to set.</param>
void SetValue(const BoolModelProperty& pProperty, bool bValue);
/// <summary>
/// Called when a boolean value changes.
/// </summary>
/// <param name="args">Information about the change.</param>
virtual void OnValueChanged(const BoolModelProperty::ChangeArgs& args) noexcept(false);
/// <summary>
/// Gets the value associated to the requested string property.
/// </summary>
/// <param name="pProperty">The property to query.</param>
/// <returns>The current value of the property for this object.</returns>
const std::wstring& GetValue(const StringModelProperty& pProperty) const
{
const int* pValue = FindValue(pProperty.GetKey());
if (pValue == nullptr)
return pProperty.GetDefaultValue();
return GetString(*pValue);
}
/// <summary>
/// Sets the specified string property to the specified value.
/// </summary>
/// <param name="pProperty">The property to set.</param>
/// <param name="sValue">The value to set.</param>
void SetValue(const StringModelProperty& pProperty, const std::wstring& sValue);
/// <summary>
/// Called when a string value changes.
/// </summary>
/// <param name="args">Information about the change.</param>
virtual void OnValueChanged(const StringModelProperty::ChangeArgs& args) noexcept(false);
/// <summary>
/// Gets the value associated to the requested integer property.
/// </summary>
/// <param name="pProperty">The property to query.</param>
/// <returns>The current value of the property for this object.</returns>
int GetValue(const IntModelProperty& pProperty) const
{
const int* pValue = FindValue(pProperty.GetKey());
return pValue ? *pValue : pProperty.GetDefaultValue();
}
/// <summary>
/// Sets the specified integer property to the specified value.
/// </summary>
/// <param name="pProperty">The property to set.</param>
/// <param name="nValue">The value to set.</param>
void SetValue(const IntModelProperty& pProperty, int nValue);
/// <summary>
/// Called when a integer value changes.
/// </summary>
/// <param name="args">Information about the change.</param>
virtual void OnValueChanged(const IntModelProperty::ChangeArgs& args) noexcept(false);
private:
typedef struct ModelPropertyValue
{
ModelPropertyValue(int nKey, int nValue) noexcept
: nKey(nKey), nValue(nValue)
{
}
int nKey;
int nValue;
} ModelPropertyValue;
std::vector<ModelPropertyValue> m_vValues;
typedef struct ModelPropertyStrings
{
static constexpr size_t ChunkCount = 4;
std::wstring sStrings[ChunkCount];
std::unique_ptr<struct ModelPropertyStrings> pNext;
} ModelPropertyStrings;
std::unique_ptr<ModelPropertyStrings> m_pStrings;
#ifdef _DEBUG
/// <summary>
/// Complete list of values as strings for viewing in the debugger
/// </summary>
std::map<std::string, std::wstring> m_mDebugValues;
#endif
static std::wstring s_sEmpty;
static int CompareModelPropertyKey(const ModelPropertyValue& left, int nKey) noexcept;
const int* FindValue(int nKey) const;
const std::wstring& GetString(int nIndex) const noexcept;
int LoadIntoEmptyStringSlot(const std::wstring& sValue);
mutable std::mutex m_mtxData;
};
} // namespace data
} // namespace ra
#endif RA_DATA_MODEL_PROPERTY_CONTAINER_H