blob: 227ab981a68b5f1f6b4d29ce0fbd165e50466817 [file] [log] [blame]
Julian Hall1d313022021-05-07 14:27:55 +01001/*
2 * Copyright (c) 2021, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#ifndef CLAIM_VECTOR_H
8#define CLAIM_VECTOR_H
9
10#include <stddef.h>
11#include "claim.h"
12
13#ifdef __cplusplus
14extern "C" {
15#endif
16
17/**
18 * A claim_vector is a general purpose variable length array
19 * of claims. The maximum number of claims is specified
20 * when the claim_vector is initialized. Deinit must be
21 * called after use to free any allocated space.
22 */
23struct claim_vector
24{
25 size_t limit;
26 size_t size;
27 struct claim *claims;
28};
29
30/**
31 * \brief Initializes a claim_vector.
32 *
33 * Space is allocated for the specified limit but the vector is
34 * initially empty.
35 *
36 * \param[in] v This claim_vector
37 * \param[in] limit The maximum number of claims that can be held
38 */
39void claim_vector_init(struct claim_vector *v, size_t limit);
40
41/**
42 * \brief De-initializes a claim_vector.
43 *
44 * Frees any space allocated. Must be called when the claim_vector
45 * is finished with.
46 *
47 * \param[in] v This claim_vector
48 */
49void claim_vector_deinit(struct claim_vector *v);
50
51/**
52 * \brief Add a claim to the back of the vector
53 *
54 * \param[in] v This claim_vector
55 * \param[in] claim Claim to add to the vector
56 */
57void claim_vector_push_back(struct claim_vector *v, const struct claim *claim);
58
59/**
60 * \brief Returns the number of claims held
61 *
62 * \param[in] v This claim_vector
63 *
64 * \return Count of claims held
65 */
66size_t claim_vector_size(const struct claim_vector *v);
67
68/**
69 * \brief Returns a pointer to the claim at the specified index
70 *
71 * \param[in] v This claim_vector
72 * \param[in] index Index into vector
73 *
74 * \return Pointer to claim or NULL
75 */
76const struct claim *claim_vector_get_claim(const struct claim_vector *v, size_t index);
77
78#ifdef __cplusplus
79} /* extern "C" */
80#endif
81
82#endif /* CLAIM_VECTOR_H */