This repository has been archived by the owner on Oct 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
154 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#include <stdint.h> | ||
|
||
#define ENUM_MAP_DEFINE(enum_name, enum_value, str_value) \ | ||
EnumMap_Define(ENUM_MAP_NAME(enum_name), enum_value, str_value); | ||
#define ENUM_MAP_DEFINE_SELF(enum_name, enum_value) \ | ||
EnumMap_Define(ENUM_MAP_NAME(enum_name), enum_value, #enum_value); | ||
|
||
#define ENUM_MAP_GET(enum_name, str_value, default_value) \ | ||
EnumMap_Get(ENUM_MAP_NAME(enum_name), str_value, default_value) | ||
|
||
#define ENUM_MAP_TO_STRING(enum_name, enum_value) \ | ||
EnumMap_ToString(ENUM_MAP_NAME(enum_name), enum_value) | ||
|
||
#define ENUM_MAP_NAME(enum_name) #enum_name | ||
|
||
// The function to put the EnumMap_Define calls in | ||
extern void EnumMap_Init(void); | ||
|
||
void EnumMap_Shutdown(void); | ||
|
||
void EnumMap_Define( | ||
const char *enum_name, int32_t enum_value, const char *str_value); | ||
int32_t EnumMap_Get( | ||
const char *enum_name, const char *str_value, int32_t default_value); | ||
const char *EnumMap_ToString(const char *enum_name, int32_t enum_value); |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#if TR_VERSION == 1 | ||
#include "./ids_tr1.def" | ||
#elif TR_VERSION == 2 | ||
#include "./ids_tr2.def" | ||
#endif |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
#include "enum_map.h" | ||
|
||
#include "memory.h" | ||
|
||
#include <stdio.h> | ||
#include <uthash.h> | ||
|
||
typedef struct { | ||
char *key; | ||
int32_t value; | ||
UT_hash_handle hh; | ||
} M_ENTRY; | ||
|
||
typedef struct { | ||
char *key; | ||
char *str_value; | ||
UT_hash_handle hh; | ||
} M_INVERSE_ENTRY; | ||
|
||
static M_ENTRY *m_Map = NULL; | ||
static M_INVERSE_ENTRY *m_InverseMap = NULL; | ||
|
||
void EnumMap_Define( | ||
const char *const enum_name, const int32_t enum_value, | ||
const char *const str_value) | ||
{ | ||
{ | ||
const size_t key_len = strlen(enum_name) + strlen(str_value) + 2; | ||
char *const key = Memory_Alloc(key_len); | ||
snprintf(key, key_len, "%s|%s", enum_name, str_value); | ||
|
||
M_ENTRY *const entry = Memory_Alloc(sizeof(M_ENTRY)); | ||
entry->key = key; | ||
entry->value = enum_value; | ||
HASH_ADD_KEYPTR(hh, m_Map, entry->key, strlen(entry->key), entry); | ||
} | ||
|
||
{ | ||
const size_t key_len = | ||
snprintf(NULL, 0, "%s|%d", enum_name, enum_value) + 1; | ||
char *const key = Memory_Alloc(key_len); | ||
snprintf(key, key_len, "%s|%d", enum_name, enum_value); | ||
|
||
M_INVERSE_ENTRY *const entry = Memory_Alloc(sizeof(M_INVERSE_ENTRY)); | ||
entry->key = key; | ||
entry->str_value = Memory_DupStr(str_value); | ||
HASH_ADD_KEYPTR( | ||
hh, m_InverseMap, entry->key, strlen(entry->key), entry); | ||
} | ||
} | ||
|
||
int32_t EnumMap_Get( | ||
const char *const enum_name, const char *const str_value, | ||
int32_t default_value) | ||
{ | ||
size_t key_len = strlen(enum_name) + strlen(str_value) + 2; | ||
char key[key_len]; | ||
snprintf(key, key_len, "%s|%s", enum_name, str_value); | ||
|
||
M_ENTRY *entry; | ||
HASH_FIND_STR(m_Map, key, entry); | ||
return entry != NULL ? entry->value : default_value; | ||
} | ||
|
||
const char *EnumMap_ToString( | ||
const char *const enum_name, const int32_t enum_value) | ||
{ | ||
size_t key_len = snprintf(NULL, 0, "%s|%d", enum_name, enum_value) + 1; | ||
char key[key_len]; | ||
snprintf(key, key_len, "%s|%d", enum_name, enum_value); | ||
|
||
M_INVERSE_ENTRY *entry; | ||
HASH_FIND_STR(m_InverseMap, key, entry); | ||
return entry != NULL ? entry->str_value : NULL; | ||
} | ||
|
||
void EnumMap_Shutdown(void) | ||
{ | ||
{ | ||
M_ENTRY *current, *tmp; | ||
HASH_ITER(hh, m_Map, current, tmp) | ||
{ | ||
HASH_DEL(m_Map, current); | ||
Memory_Free(current->key); | ||
Memory_Free(current); | ||
} | ||
} | ||
|
||
{ | ||
M_INVERSE_ENTRY *current, *tmp; | ||
HASH_ITER(hh, m_InverseMap, current, tmp) | ||
{ | ||
HASH_DEL(m_InverseMap, current); | ||
Memory_Free(current->str_value); | ||
Memory_Free(current->key); | ||
Memory_Free(current); | ||
} | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters