2 * Copyright 2019 The OpenSSL Project Authors. All Rights Reserved.
3 * Copyright (c) 2019, Oracle and/or its affiliates. All rights reserved.
5 * Licensed under the Apache License 2.0 (the "License"). You may not use
6 * this file except in compliance with the License. You can obtain a copy
7 * in the file LICENSE in the source distribution or at
8 * https://www.openssl.org/source/license.html
11 #ifndef HEADER_SPARSE_ARRAY_H
12 # define HEADER_SPARSE_ARRAY_H
14 # include <openssl/e_os2.h>
20 # define SPARSE_ARRAY_OF(type) struct sparse_array_st_ ## type
22 # define DEFINE_SPARSE_ARRAY_OF(type) \
23 SPARSE_ARRAY_OF(type); \
24 static ossl_unused ossl_inline SPARSE_ARRAY_OF(type) * \
25 ossl_sa_##type##_new(void) \
27 return (SPARSE_ARRAY_OF(type) *)OPENSSL_SA_new(); \
29 static ossl_unused ossl_inline void ossl_sa_##type##_free(SPARSE_ARRAY_OF(type) *sa) \
31 OPENSSL_SA_free((OPENSSL_SA *)sa); \
33 static ossl_unused ossl_inline void ossl_sa_##type##_free_leaves(SPARSE_ARRAY_OF(type) *sa) \
35 OPENSSL_SA_free_leaves((OPENSSL_SA *)sa); \
37 static ossl_unused ossl_inline size_t ossl_sa_##type##_num(const SPARSE_ARRAY_OF(type) *sa) \
39 return OPENSSL_SA_num((OPENSSL_SA *)sa); \
41 static ossl_unused ossl_inline void ossl_sa_##type##_doall(const SPARSE_ARRAY_OF(type) *sa, \
42 void (*leaf)(size_t, type *)) \
44 OPENSSL_SA_doall((OPENSSL_SA *)sa, (void (*)(size_t, void *))leaf); \
46 static ossl_unused ossl_inline \
47 void ossl_sa_##type##_doall_arg(const SPARSE_ARRAY_OF(type) *sa, \
48 void (*leaf)(size_t, type *, void *), \
51 OPENSSL_SA_doall_arg((OPENSSL_SA *)sa, (void (*)(size_t, void *, void *))leaf, \
54 static ossl_unused ossl_inline type *ossl_sa_##type##_get(const SPARSE_ARRAY_OF(type) *sa, \
57 return (type *)OPENSSL_SA_get((OPENSSL_SA *)sa, n); \
59 static ossl_unused ossl_inline int ossl_sa_##type##_set(SPARSE_ARRAY_OF(type) *sa, \
60 size_t n, type *val) \
62 return OPENSSL_SA_set((OPENSSL_SA *)sa, n, (void *)val); \
66 typedef struct sparse_array_st OPENSSL_SA;
67 OPENSSL_SA *OPENSSL_SA_new(void);
68 void OPENSSL_SA_free(OPENSSL_SA *sa);
69 void OPENSSL_SA_free_leaves(OPENSSL_SA *sa);
70 size_t OPENSSL_SA_num(const OPENSSL_SA *sa);
71 void OPENSSL_SA_doall(const OPENSSL_SA *sa, void (*leaf)(size_t, void *));
72 void OPENSSL_SA_doall_arg(const OPENSSL_SA *sa,
73 void (*leaf)(size_t, void *, void *), void *);
74 void *OPENSSL_SA_get(const OPENSSL_SA *sa, size_t n);
75 int OPENSSL_SA_set(OPENSSL_SA *sa, size_t n, void *val);