1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-16 11:33:03 +01:00

Refactor intent

This commit is contained in:
Marijn van der Werf
2017-09-20 20:00:49 +02:00
parent 47e65d1ab1
commit 34ee3df318
2 changed files with 39 additions and 12 deletions

View File

@@ -7,28 +7,44 @@ Intent::Intent(rct_windowclass windowclass)
Intent * Intent::putExtra(uint32 key, uint32 value)
{
_UInts.insert(std::make_pair(key, value));
IntentData data = {};
data.uintVal = value;
data.type = IntentData::DT_UINT;
_Data.insert(std::make_pair(key, data));
return this;
}
Intent * Intent::putExtra(uint32 key, void * value)
{
_Pointers.insert(std::make_pair(key, (uintptr_t) value));
IntentData data = {};
data.pointerVal = value;
data.type = IntentData::DT_POINTER;
_Data.insert(std::make_pair(key, data));
return this;
}
Intent * Intent::putExtra(uint32 key, sint32 value)
{
_Pointers.insert(std::make_pair(key, value));
IntentData data = {};
data.sintVal = value;
data.type = IntentData::DT_SINT;
_Data.insert(std::make_pair(key, data));
return this;
}
Intent * Intent::putExtra(uint32 key, utf8string value)
{
_Strings.insert(std::make_pair(key, value));
IntentData data = {};
data.stringVal = value;
data.type = IntentData::DT_STRING;
_Data.insert(std::make_pair(key, data));
return this;
}
@@ -40,22 +56,26 @@ rct_windowclass Intent::GetWindowClass()
void * Intent::GetPointerExtra(uint32 key)
{
return (void *) _Pointers.at(key);
auto data = _Data.at(key);
return (void *) data.pointerVal;
}
uint32 Intent::GetUIntExtra(uint32 key)
{
return _UInts.at(key);
auto data = _Data.at(key);
return data.uintVal;
}
sint32 Intent::GetSIntExtra(uint32 key)
{
return _SInts.at(key);
auto data = _Data.at(key);
return data.sintVal;
}
utf8string Intent::GetStringExtra(uint32 key)
{
return _Strings.at(key);
auto data = _Data.at(key);
return data.stringVal;
}
extern "C" {

View File

@@ -15,14 +15,21 @@ extern "C" {
#include <map>
struct IntentData
{
enum DATATYPE { DT_UINT, DT_SINT, DT_STRING, DT_POINTER } type;
uint32 uintVal;
sint32 sintVal;
utf8string stringVal;
void * pointerVal;
};
class Intent
{
private:
rct_windowclass _Class;
std::map<uint32, uint32> _UInts;
std::map<uint32, sint32> _SInts;
std::map<uint32, utf8string> _Strings;
std::map<uint32, uintptr_t> _Pointers;
std::map<uint32, IntentData> _Data;
public:
explicit Intent(rct_windowclass windowclass);
rct_windowclass GetWindowClass();