MISR Toolkit  1.5.1
dynarray.h
Go to the documentation of this file.
1 /* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2  * Copyright by The HDF Group. *
3  * Copyright by the Board of Trustees of the University of Illinois. *
4  * All rights reserved. *
5  * *
6  * This file is part of HDF. The full HDF copyright notice, including *
7  * terms governing use, modification, and redistribution, is contained in *
8  * the COPYING file, which can be found at the root of the source code *
9  * distribution tree, or in https://support.hdfgroup.org/ftp/HDF/releases/. *
10  * If you do not have access to either file, you may request a copy from *
11  * help@hdfgroup.org. *
12  * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
13 
14 /* $Id$ */
15 
16 /*-----------------------------------------------------------------------------
17  * File: dynarray.h
18  * Purpose: header file for dynamic array API
19  * Dependencies:
20  * Invokes:
21  * Contents:
22  * Structure definitions:
23  * Constant definitions:
24  *---------------------------------------------------------------------------*/
25 
26 /* avoid re-inclusion */
27 #ifndef __DYNARRAY_H
28 #define __DYNARRAY_H
29 
30 #include "hdf.h"
31 
32 /*
33  Define the pointer to the dynarray without giving outside routines access
34  to the internal workings of the structure.
35 */
36 typedef struct dynarray_tag *dynarr_p;
37 
38 #if defined DYNARRAY_MASTER | defined DYNARRAY_TESTER
39 typedef struct dynarray_tag
40  {
41  intn num_elems; /* Number of elements in the array currently */
42  intn incr_mult; /* Multiple to increment the array size by */
43  VOIDP *arr; /* Pointer to the actual array of void *'s */
44  }dynarr_t;
45 
46 #endif /* DYNARRAY_MASTER | DYNARRAY_TESTER */
47 
48 #if defined c_plusplus || defined __cplusplus
49 extern "C"
50 {
51 #endif /* c_plusplus || __cplusplus */
52 
53 /******************************************************************************
54  NAME
55  DAcreate_array - Create a dynarray
56 
57  DESCRIPTION
58  Create a dynarray for later use. This routine allocates the dynarray
59  structure and creates a dynarray with the specified minimum size.
60 
61  RETURNS
62  Returns pointer to the dynarray created if successful and NULL otherwise
63 
64 *******************************************************************************/
65 dynarr_p DAcreate_array(intn start_size, /* IN: Initial array size */
66  intn incr_mult /* IN: multiple to create additional elements in */
67 );
68 
69 /******************************************************************************
70  NAME
71  DAdestroy_array - Destroy a dynarray
72 
73  DESCRIPTION
74  Destroy an existing dynarray from use. This routine de-allocates the
75  dynarray structure and deletes the current dynarray.
76 
77  RETURNS
78  Returns SUCCEED if successful and FAIL otherwise
79 
80 *******************************************************************************/
81 intn DAdestroy_array(dynarr_p arr, /* IN: Array to destroy */
82  intn free_elem /* IN: whether to free each element */
83 );
84 
85 /******************************************************************************
86  NAME
87  DAdestroy_array - Get the current size of a dynarray
88 
89  DESCRIPTION
90  Get the number of elements in use currently.
91 
92  RETURNS
93  Returns # of dynarray elements if successful and FAIL otherwise
94 
95 *******************************************************************************/
96 intn DAsize_array(dynarr_p arr /* IN: Array to get size of */
97 );
98 
99 /******************************************************************************
100  NAME
101  DAget_elem - Get an element from a dynarray
102 
103  DESCRIPTION
104  Retrieve an element from a dynarray. If the element to be retrieved is
105  beyond the end of the currently allocated array elements, the array is
106  not extended, a NULL pointer is merely returned.
107 
108  RETURNS
109  Returns object ptr if successful and NULL otherwise
110 
111 *******************************************************************************/
112 VOIDP DAget_elem(dynarr_p arr_ptr, /* IN: Array to access */
113  intn elem /* IN: Array element to retrieve */
114 );
115 
116 /******************************************************************************
117  NAME
118  DAset_elem - Set an element pointer for a dynarray
119 
120  DESCRIPTION
121  Set an element pointer for a dynarray. If the element to be set is
122  beyond the end of the currently allocated array elements, the array is
123  extended by whatever multiple of the incr_mult is needed to expand the
124  # of array elements to include the array element to set.
125 
126  RETURNS
127  Returns SUCCEED if successful and NULL otherwise
128 
129 *******************************************************************************/
130 intn DAset_elem(dynarr_p arr_ptr, /* IN: Array to access */
131  intn elem, /* IN: Array element to set */
132  VOIDP obj /* IN: Pointer to the object to store */
133 );
134 
135 /*****************************************************************************
136  NAME
137  DAdel_elem - Delete an element from a dynarray
138 
139  DESCRIPTION
140  Retrieve an element from a dynarray & delete it from the dynarray. If the
141  element to be retrieved is beyond the end of the currently allocated array
142  elements, the array is not extended, a NULL pointer is merely returned.
143 
144  RETURNS
145  Returns object ptr if successful and NULL otherwise
146 
147 *******************************************************************************/
148 VOIDP DAdel_elem(dynarr_p arr_ptr, /* IN: Array to access */
149  intn elem /* IN: Array element to retrieve */
150 );
151 
152 #if defined c_plusplus || defined __cplusplus
153 }
154 #endif /* c_plusplus || __cplusplus */
155 
156 #endif /* __DYNARRAY_H */
157 
intn DAdestroy_array(dynarr_p arr, intn free_elem)
VOIDP DAget_elem(dynarr_p arr_ptr, intn elem)
intn DAsize_array(dynarr_p arr)
struct dynarray_tag * dynarr_p
Definition: dynarray.h:36
intn DAset_elem(dynarr_p arr_ptr, intn elem, VOIDP obj)
dynarr_p DAcreate_array(intn start_size, intn incr_mult)
VOIDP DAdel_elem(dynarr_p arr_ptr, intn elem)

MISR Toolkit - Copyright © 2005 - 2020 Jet Propulsion Laboratory
Generated on Fri Jun 19 2020 22:49:52