idx.h (1133B)
1#pragma once 2 3#include "allocator.h" 4 5#include <stdint.h> 6#include <stddef.h> 7 8enum { 9 IDX_TYPE_UNKNOWN = -1, 10 IDX_TYPE_UNSIGNED_BYTE, 11 IDX_TYPE_SIGNED_BYTE, 12 IDX_TYPE_SHORT, 13 IDX_TYPE_INT, 14 IDX_TYPE_FLOAT, 15 IDX_TYPE_DOUBLE, 16 IDX_TYPE_COUNT, 17}; 18 19enum { 20 IDX_OK, 21 IDX_BAD_PARAM, 22 IDX_FILE_ACCESS, 23 IDX_FILE_BAD_MAGIC, 24 IDX_FILE_BAD_TYPE, 25 IDX_FILE_BAD_DIMS, 26 IDX_FILE_WRITE_MAGIC, 27 IDX_FILE_WRITE_DIMS, 28 IDX_FILE_WRITE_DATA, 29 IDX_FILE_READ_MAGIC, 30 IDX_FILE_READ_DIMS, 31 IDX_FILE_READ_DATA, 32}; 33 34struct idx { 35 struct { 36 int val; 37 uint8_t size; 38 } type; 39 40 struct { 41 void *data; 42 size_t len; 43 } buf; 44 45 struct { 46 uint8_t count; 47 uint32_t *sizes; 48 } dims; 49 50 const struct allocator *allocator; 51}; 52 53int idx_new(struct idx *idx, uint8_t dims_count, uint32_t *dims, 54 int data_type, const struct allocator *allocator); 55int idx_wrap(struct idx *idx, void *data, uint8_t dims_count, 56 uint32_t *dims, int data_type); 57 58int idx_load(struct idx *idx, const char *filename, 59 const struct allocator *allocator); 60int idx_save(struct idx *idx, const char *filename); 61 62int idx_deinit(struct idx *idx); 63 64void *idx_get(struct idx *idx, int dims, ...); 65