mirror of
https://github.com/gbdev/rgbds.git
synced 2025-11-21 02:32:06 +00:00
Use std::stack for charmaps
This commit is contained in:
@@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <new>
|
#include <new>
|
||||||
|
#include <stack>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
@@ -37,12 +38,7 @@ static HashMap charmaps;
|
|||||||
// that gets reallocated.
|
// that gets reallocated.
|
||||||
static struct Charmap **currentCharmap;
|
static struct Charmap **currentCharmap;
|
||||||
|
|
||||||
struct CharmapStackEntry {
|
std::stack<struct Charmap **> charmapStack;
|
||||||
struct Charmap **charmap;
|
|
||||||
struct CharmapStackEntry *next;
|
|
||||||
};
|
|
||||||
|
|
||||||
struct CharmapStackEntry *charmapStack;
|
|
||||||
|
|
||||||
static struct Charmap *charmap_Get(char const *name)
|
static struct Charmap *charmap_Get(char const *name)
|
||||||
{
|
{
|
||||||
@@ -119,29 +115,18 @@ void charmap_Set(char const *name)
|
|||||||
|
|
||||||
void charmap_Push(void)
|
void charmap_Push(void)
|
||||||
{
|
{
|
||||||
struct CharmapStackEntry *stackEntry = (struct CharmapStackEntry *)malloc(sizeof(*stackEntry));
|
charmapStack.push(currentCharmap);
|
||||||
|
|
||||||
if (stackEntry == NULL)
|
|
||||||
fatalerror("Failed to alloc charmap stack entry: %s\n", strerror(errno));
|
|
||||||
|
|
||||||
stackEntry->charmap = currentCharmap;
|
|
||||||
stackEntry->next = charmapStack;
|
|
||||||
|
|
||||||
charmapStack = stackEntry;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void charmap_Pop(void)
|
void charmap_Pop(void)
|
||||||
{
|
{
|
||||||
if (charmapStack == NULL) {
|
if (charmapStack.empty()) {
|
||||||
error("No entries in the charmap stack\n");
|
error("No entries in the charmap stack\n");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
struct CharmapStackEntry *top = charmapStack;
|
currentCharmap = charmapStack.top();
|
||||||
|
charmapStack.pop();
|
||||||
currentCharmap = top->charmap;
|
|
||||||
charmapStack = top->next;
|
|
||||||
free(top);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void charmap_Add(char *mapping, uint8_t value)
|
void charmap_Add(char *mapping, uint8_t value)
|
||||||
|
|||||||
Reference in New Issue
Block a user