Moved some code to shared dir

This commit is contained in:
2023-02-06 22:22:19 -08:00
parent c70c4fe6c4
commit 192f6b7f59
18 changed files with 211 additions and 227 deletions

View File

@ -16,9 +16,9 @@ extern "C" {
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#include <assert.h> #include <assert.h>
#include <float.h>
typedef bool bool_t; typedef bool bool_t;
typedef float float_t;
} }
#include <vector> #include <vector>

View File

@ -1,45 +1,45 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "dawnlibs.hpp" #include "dawnlibs.hpp"
#include "assert/assert.hpp" #include "assert/assert.hpp"
namespace Dawn { namespace Dawn {
/** /**
* Append a list on to another list. * Append a list on to another list.
* *
* @param list Pointer to list that is being appended to. * @param list Pointer to list that is being appended to.
* @param append Pointer to list that will be appended. * @param append Pointer to list that will be appended.
*/ */
template<typename T> template<typename T>
void vectorAppend(std::vector<T> *list, std::vector<T> *append) { void vectorAppend(std::vector<T> *list, std::vector<T> *append) {
assertNotNull(list); assertNotNull(list);
assertNotNull(append); assertNotNull(append);
auto it = append->begin(); auto it = append->begin();
while(it != append->end()) { while(it != append->end()) {
list->push_back(*it); list->push_back(*it);
++it; ++it;
} }
} }
/** /**
* Append a list on to another list. * Append a list on to another list.
* *
* @param list Pointer to list that is being appended to. * @param list Pointer to list that is being appended to.
* @param append List that will be appended. * @param append List that will be appended.
*/ */
template<typename T> template<typename T>
void vectorAppend(std::vector<T> *list, std::vector<T> append) { void vectorAppend(std::vector<T> *list, std::vector<T> append) {
assertNotNull(list); assertNotNull(list);
auto it = append.begin(); auto it = append.begin();
while(it != append.end()) { while(it != append.end()) {
list->push_back(*it); list->push_back(*it);
++it; ++it;
} }
} }
} }

View File

@ -1,15 +1,15 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "dawnlibs.hpp" #include "dawnlibs.hpp"
typedef uint_fast8_t flag8_t; typedef uint_fast8_t flag8_t;
typedef uint_fast16_t flag16_t; typedef uint_fast16_t flag16_t;
typedef uint_fast32_t flag32_t; typedef uint_fast32_t flag32_t;
typedef flag32_t flag_t; typedef flag32_t flag_t;
#define FLAG_DEFINE(n) (1 << n) #define FLAG_DEFINE(n) (1 << n)

View File

@ -1,108 +1,108 @@
/** /**
* Copyright (c) 2022 Dominic Masters * Copyright (c) 2022 Dominic Masters
* *
* This software is released under the MIT License. * This software is released under the MIT License.
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
#pragma once #pragma once
#include "dawnlibs.hpp" #include "dawnlibs.hpp"
/** /**
* Allocate some space in memory to use for your needs. Memory allocation may * Allocate some space in memory to use for your needs. Memory allocation may
* change how it functions later on to keep things nice and efficient. For now * change how it functions later on to keep things nice and efficient. For now
* this is just an API forward for malloc. * this is just an API forward for malloc.
* *
* @param size Size of the array you wish to buffer. * @param size Size of the array you wish to buffer.
* @return Pointer to the space in memory to use. * @return Pointer to the space in memory to use.
*/ */
static inline void * memoryAllocate(const size_t size) { static inline void * memoryAllocate(const size_t size) {
return (void *)malloc(size); return (void *)malloc(size);
} }
/** /**
* Allocate space in memory, where all values are set to 0 (in binary space). * Allocate space in memory, where all values are set to 0 (in binary space).
* *
* @param size Size of the array. * @param size Size of the array.
* @return Pointer to the space in memory to use. * @return Pointer to the space in memory to use.
*/ */
static inline void * memoryFillWithZero(const size_t size) { static inline void * memoryFillWithZero(const size_t size) {
return (void *)calloc(1, size); return (void *)calloc(1, size);
} }
/** /**
* Free some previously allocated memory space. * Free some previously allocated memory space.
* @param pointer Pointer in memory to free. * @param pointer Pointer in memory to free.
*/ */
static inline void memoryFree(void *pointer) { static inline void memoryFree(void *pointer) {
free(pointer); free(pointer);
} }
/** /**
* Copies data from one buffer to another. Typically used for array operations. * Copies data from one buffer to another. Typically used for array operations.
* *
* @param source Source pointer. * @param source Source pointer.
* @param destination Destination buffer. * @param destination Destination buffer.
* @param size Size in bytes of data to copy. * @param size Size in bytes of data to copy.
*/ */
static inline void memoryCopy( static inline void memoryCopy(
void *source, void *source,
void *destination, void *destination,
size_t size size_t size
) { ) {
memcpy(destination, source, size); memcpy(destination, source, size);
} }
/** /**
* Compares the data within two memory banks. Shorthand for memcpy. * Compares the data within two memory banks. Shorthand for memcpy.
* *
* @param left Left item to compare. * @param left Left item to compare.
* @param right Right item to compare. * @param right Right item to compare.
* @param size Count of bytes to compare. * @param size Count of bytes to compare.
* @return 0 for equal, <0 for left being greater, >0 for right being greater. * @return 0 for equal, <0 for left being greater, >0 for right being greater.
*/ */
static inline int32_t memoryCompare( static inline int32_t memoryCompare(
const void *left, const void *left,
const void *right, const void *right,
const size_t size const size_t size
) { ) {
return memcmp(left, right, size); return memcmp(left, right, size);
} }
/** /**
* Fill destination with a repeating set of bytes. * Fill destination with a repeating set of bytes.
* *
* @param dest Destination pointer in memory. * @param dest Destination pointer in memory.
* @param data Data byte to write. * @param data Data byte to write.
* @param length How many times to write that byte. * @param length How many times to write that byte.
*/ */
static inline void memorySet( static inline void memorySet(
void *dest, void *dest,
uint8_t data, uint8_t data,
size_t length size_t length
) { ) {
memset(dest, data, length); memset(dest, data, length);
} }
/** /**
* Reallocate a part of memory. Reallocation simply creates a new buffer that * Reallocate a part of memory. Reallocation simply creates a new buffer that
* will take all of the existing contents and then free's the original buffer. * will take all of the existing contents and then free's the original buffer.
* *
* @param pointer Pointer to pointer in memory that you wish to re-allocate. * @param pointer Pointer to pointer in memory that you wish to re-allocate.
* @param currentSize Current size of the buffer that the pointer points to. * @param currentSize Current size of the buffer that the pointer points to.
* @param newSize The new size of the buffer. * @param newSize The new size of the buffer.
* @return The new size param you provided. * @return The new size param you provided.
*/ */
static inline size_t memoryReallocate( static inline size_t memoryReallocate(
void **pointer, void **pointer,
size_t currentSize, size_t currentSize,
size_t newSize size_t newSize
) { ) {
// Create the new buffer // Create the new buffer
void *newBuffer = memoryAllocate(newSize); void *newBuffer = memoryAllocate(newSize);
memoryCopy(*pointer, newBuffer, currentSize); memoryCopy(*pointer, newBuffer, currentSize);
memoryFree(*pointer); memoryFree(*pointer);
*pointer = newBuffer; *pointer = newBuffer;
return newSize; return newSize;
} }

View File

@ -1,35 +1,35 @@
// Copyright (c) 2022 Dominic Masters // Copyright (c) 2022 Dominic Masters
// //
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#pragma once #pragma once
#include "assert/assert.hpp" #include "assert/assert.hpp"
/** /**
* Finds the next instance of a character within a string, safely (with a * Finds the next instance of a character within a string, safely (with a
* limit). The returned pointer will be NULL if not found, or a pointer to a * limit). The returned pointer will be NULL if not found, or a pointer to a
* point within the string where the instance is. * point within the string where the instance is.
* *
* @param haystack String to search. * @param haystack String to search.
* @param needle Character to search for. * @param needle Character to search for.
* @param limit Max length you want to search for to limit yourself to. * @param limit Max length you want to search for to limit yourself to.
* @return Pointer to the character found, or NULL if not found. * @return Pointer to the character found, or NULL if not found.
*/ */
static inline char * stringFindNext( static inline char * stringFindNext(
char *haystack, char *haystack,
char needle, char needle,
size_t limit size_t limit
) { ) {
char *p; char *p;
assertNotNull(haystack); assertNotNull(haystack);
assertTrue(limit > 0); assertTrue(limit > 0);
for(p = haystack; (size_t)(p - haystack) < limit; p++) { for(p = haystack; (size_t)(p - haystack) < limit; p++) {
if(*p == needle) return p; if(*p == needle) return p;
assertFalse(*p == '\0');// We don't allow you to have a limit > strlen assertFalse(*p == '\0');// We don't allow you to have a limit > strlen
} }
return NULL; return NULL;
} }

View File

@ -3,7 +3,7 @@
// This software is released under the MIT License. // This software is released under the MIT License.
// https://opensource.org/licenses/MIT // https://opensource.org/licenses/MIT
#include "../../utils/common.hpp" #include "dawnsharedlibs.hpp"
#include "../../utils/file.hpp" #include "../../utils/file.hpp"
#include "AudioFile.h" #include "AudioFile.h"

View File

@ -5,7 +5,7 @@
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
#include "../../utils/common.hpp" #include "dawnsharedlibs.hpp"
#include "../../utils/file.hpp" #include "../../utils/file.hpp"
#include "../../utils/image.hpp" #include "../../utils/image.hpp"

View File

@ -5,7 +5,7 @@
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
#include "../../utils/common.hpp" #include "dawnsharedlibs.hpp"
#include "../../utils/file.hpp" #include "../../utils/file.hpp"
#include "../../utils/image.hpp" #include "../../utils/image.hpp"

View File

@ -5,7 +5,7 @@
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
#include "../../utils/common.hpp" #include "dawnsharedlibs.hpp"
#include "../../utils/file.hpp" #include "../../utils/file.hpp"
#include "../../utils/image.hpp" #include "../../utils/image.hpp"
#ifndef STB_TRUETYPE_IMPLEMENTATION #ifndef STB_TRUETYPE_IMPLEMENTATION

View File

@ -5,7 +5,7 @@
* https://opensource.org/licenses/MIT * https://opensource.org/licenses/MIT
*/ */
#include "../../utils/common.hpp" #include "dawnsharedlibs.hpp"
#include "../../utils/file.hpp" #include "../../utils/file.hpp"
#include "../../utils/csv.hpp" #include "../../utils/csv.hpp"
#include "../../utils/xml.hpp" #include "../../utils/xml.hpp"

View File

@ -1,16 +0,0 @@
/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#pragma once
#include "dawnsharedlibs.hpp"
#include <stdio.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <stdlib.h>
#include <float.h>

View File

@ -6,7 +6,7 @@
*/ */
#pragma once #pragma once
#include "common.hpp" #include "dawnsharedlibs.hpp"
#include "string.h" #include "string.h"
#define CSV_ROW_COUNT_MAX 128 #define CSV_ROW_COUNT_MAX 128

View File

@ -6,7 +6,7 @@
*/ */
#pragma once #pragma once
#include "common.hpp" #include "dawnsharedlibs.hpp"
#define FILE_CHILD_TYPE_DIR 0x00 #define FILE_CHILD_TYPE_DIR 0x00
#define FILE_CHILD_TYPE_FILE 0x01 #define FILE_CHILD_TYPE_FILE 0x01

View File

@ -6,7 +6,7 @@
*/ */
#pragma once #pragma once
#include "common.hpp" #include "dawnsharedlibs.hpp"
#include "file.hpp" #include "file.hpp"
#include <stb_image.h> #include <stb_image.h>

View File

@ -6,7 +6,7 @@
*/ */
#pragma once #pragma once
#include "common.hpp" #include "dawnsharedlibs.hpp"
static inline void stringRemoveAll(char *string, char remove) { static inline void stringRemoveAll(char *string, char remove) {
size_t len = strlen(string); size_t len = strlen(string);

View File

@ -6,7 +6,7 @@
*/ */
#pragma once #pragma once
#include "common.hpp" #include "dawnsharedlibs.hpp"
#include "file.hpp" #include "file.hpp"
#define XML_DOING_NOTHING 0x00 #define XML_DOING_NOTHING 0x00