Util: Add some base vector implementations

This commit is contained in:
Vicki Pfau 2023-01-10 23:13:58 -08:00
parent 7824a317ae
commit 62c84ab815
5 changed files with 27 additions and 7 deletions

View File

@ -97,8 +97,16 @@ CXX_GUARD_START
dest->size = src->size; \
} \
DECLARE_VECTOR(StringList, char*);
DECLARE_VECTOR(IntList, int);
DECLARE_VECTOR(SInt8List, int8_t);
DECLARE_VECTOR(SInt16List, int16_t);
DECLARE_VECTOR(SInt32List, int32_t);
DECLARE_VECTOR(SIntPtrList, intptr_t);
DECLARE_VECTOR(UInt8List, uint8_t);
DECLARE_VECTOR(UInt16List, uint16_t);
DECLARE_VECTOR(UInt32List, uint32_t);
DECLARE_VECTOR(UIntPtrList, uintptr_t);
DECLARE_VECTOR(StringList, char*);
CXX_GUARD_END

View File

@ -11,8 +11,6 @@
DEFINE_VECTOR(LexVector, struct Token);
DEFINE_VECTOR(IntList, int32_t);
enum LexState {
LEX_ERROR = -1,
LEX_ROOT = 0,

View File

@ -8,6 +8,7 @@ set(BASE_SOURCE_FILES
hash.c
string.c
table.c
vector.c
vfs.c)
set(SOURCE_FILES

View File

@ -5,12 +5,8 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <mgba-util/string.h>
#include <mgba-util/vector.h>
#include <string.h>
DEFINE_VECTOR(StringList, char*);
#ifndef HAVE_STRNDUP
char* strndup(const char* start, size_t len) {
// This is suboptimal, but anything recent should have strndup

17
src/util/vector.c Normal file
View File

@ -0,0 +1,17 @@
/* Copyright (c) 2013-2023 Jeffrey Pfau
*
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include <mgba-util/vector.h>
DEFINE_VECTOR(IntList, int);
DEFINE_VECTOR(SInt8List, int8_t);
DEFINE_VECTOR(SInt16List, int16_t);
DEFINE_VECTOR(SInt32List, int32_t);
DEFINE_VECTOR(SIntPtrList, intptr_t);
DEFINE_VECTOR(UInt8List, uint8_t);
DEFINE_VECTOR(UInt16List, uint16_t);
DEFINE_VECTOR(UInt32List, uint32_t);
DEFINE_VECTOR(UIntPtrList, uintptr_t);
DEFINE_VECTOR(StringList, char*);