mirror of
https://github.com/thunderbrewhq/common.git
synced 2025-12-12 03:02:29 +00:00
feat(prop): add prop functions
This commit is contained in:
parent
900aed5ee6
commit
5068af21cd
4 changed files with 81 additions and 0 deletions
42
common/Prop.cpp
Normal file
42
common/Prop.cpp
Normal file
|
|
@ -0,0 +1,42 @@
|
|||
#include "common/Prop.hpp"
|
||||
#include "common/Thread.hpp"
|
||||
#include <storm/Memory.hpp>
|
||||
|
||||
namespace Prop {
|
||||
uint32_t s_tlsIndex;
|
||||
}
|
||||
|
||||
HPROPCONTEXT PropCreateContext() {
|
||||
return SMemAlloc(sizeof(void*) * PROPERTIES, __FILE__, __LINE__, 0x8);
|
||||
}
|
||||
|
||||
void* PropGet(PROPERTY id) {
|
||||
auto properties = static_cast<void**>(OsTlsGetValue(Prop::s_tlsIndex));
|
||||
|
||||
if (properties) {
|
||||
return properties[id];
|
||||
} else {
|
||||
return nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
HPROPCONTEXT PropGetSelectedContext() {
|
||||
return OsTlsGetValue(Prop::s_tlsIndex);
|
||||
}
|
||||
|
||||
void PropInitialize() {
|
||||
Prop::s_tlsIndex = OsTlsAlloc();
|
||||
OsTlsSetValue(Prop::s_tlsIndex, nullptr);
|
||||
}
|
||||
|
||||
void PropSelectContext(HPROPCONTEXT context) {
|
||||
OsTlsSetValue(Prop::s_tlsIndex, context);
|
||||
}
|
||||
|
||||
void PropSet(PROPERTY id, void* value) {
|
||||
auto properties = static_cast<void**>(OsTlsGetValue(Prop::s_tlsIndex));
|
||||
|
||||
if (properties) {
|
||||
properties[id] = value;
|
||||
}
|
||||
}
|
||||
18
common/Prop.hpp
Normal file
18
common/Prop.hpp
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
#ifndef COMMON_PROP_HPP
|
||||
#define COMMON_PROP_HPP
|
||||
|
||||
#include "common/prop/Types.hpp"
|
||||
|
||||
HPROPCONTEXT PropCreateContext();
|
||||
|
||||
void* PropGet(PROPERTY id);
|
||||
|
||||
HPROPCONTEXT PropGetSelectedContext();
|
||||
|
||||
void PropInitialize();
|
||||
|
||||
void PropSelectContext(HPROPCONTEXT context);
|
||||
|
||||
void PropSet(PROPERTY id, void* value);
|
||||
|
||||
#endif
|
||||
12
common/prop/Types.hpp
Normal file
12
common/prop/Types.hpp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
#ifndef COMMON_PROP_TYPES_HPP
|
||||
#define COMMON_PROP_TYPES_HPP
|
||||
|
||||
enum PROPERTY {
|
||||
PROP_EVENTCONTEXT = 0,
|
||||
// TODO
|
||||
PROPERTIES,
|
||||
};
|
||||
|
||||
typedef void* HPROPCONTEXT;
|
||||
|
||||
#endif
|
||||
9
test/Prop.cpp
Normal file
9
test/Prop.cpp
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
#include "common/Prop.hpp"
|
||||
#include "test/Test.hpp"
|
||||
|
||||
TEST_CASE("PropInitialize", "[prop]") {
|
||||
SECTION("initializes prop") {
|
||||
PropInitialize();
|
||||
SUCCEED();
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue