/* Copyright (c) 2022 Alex Diener This software is provided 'as-is', without any express or implied warranty. In no event will the authors be held liable for any damages arising from the use of this software. Permission is granted to anyone to use this software for any purpose, including commercial applications, and to alter it and redistribute it freely, subject to the following restrictions: 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required. 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. Alex Diener alex@ludobloom.com */ #ifndef __StrideArray_H__ #define __StrideArray_H__ #ifdef __cplusplus extern "C" { #endif #include typedef struct StrideArray { void * data; unsigned int count; unsigned int stride; bool dataOwned; } StrideArray; // If data is NULL and count is nonzero, space will be allocated equal to count * stride and ownership taken, regardless of the values of the takeOwnership and copy parameters // If ownership is taken and data is not copied, the provided data must be heap-allocated. StrideArray StrideArray_init(unsigned int count, unsigned int stride, void * data, bool takeOwnership, bool copy); void StrideArray_free(StrideArray * array); void * StrideArray_entryAtIndex(StrideArray * array, unsigned int index); // Returns UINT_MAX for entries out of range or alignment unsigned int StrideArray_indexOfEntry(StrideArray * array, void * entry); // Data must be owned to mutate array contents; these have no effect if ownership has not been taken // append and insert return the newly added entry. If data is NULL, space will be allocated and returned without a value being assigned. void * StrideArray_append(StrideArray * array, void * data); void * StrideArray_insert(StrideArray * array, unsigned int index, void * data); void StrideArray_remove(StrideArray * array, unsigned int index); void StrideArray_removeAll(StrideArray * array); // Overwrites the data at the specified index with new data. Has no effect if index is out of range. void StrideArray_replace(StrideArray * array, unsigned int index, void * data); #ifdef __cplusplus } #endif #endif