• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*---------------------------------------------------------------------------*
2  *  IntArrayList.h  *
3  *                                                                           *
4  *  Copyright 2007, 2008 Nuance Communciations, Inc.                               *
5  *                                                                           *
6  *  Licensed under the Apache License, Version 2.0 (the 'License');          *
7  *  you may not use this file except in compliance with the License.         *
8  *                                                                           *
9  *  You may obtain a copy of the License at                                  *
10  *      http://www.apache.org/licenses/LICENSE-2.0                           *
11  *                                                                           *
12  *  Unless required by applicable law or agreed to in writing, software      *
13  *  distributed under the License is distributed on an 'AS IS' BASIS,        *
14  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
15  *  See the License for the specific language governing permissions and      *
16  *  limitations under the License.                                           *
17  *                                                                           *
18  *---------------------------------------------------------------------------*/
19 
20 #ifndef __INTARRAYLIST_H
21 #define __INTARRAYLIST_H
22 
23 
24 
25 #include "ESR_ReturnCode.h"
26 #include "ESR_SharedPrefix.h"
27 #include "ptypes.h"
28 #include <stdlib.h>
29 
30 /**
31  * @addtogroup IntArrayListModule IntArrayList API functions
32  * List of elements.
33  *
34  * @{
35  */
36 
37 /**
38  * List of elements.
39  */
40 typedef struct IntArrayList_t
41 {
42   /**
43    * Adds element to list.
44    *
45    * @param self IntArrayList handle
46    * @param element Element to be added
47    */
48   ESR_ReturnCode(*add)(struct IntArrayList_t* self, int element);
49 
50   /**
51   * Removes element from list.
52   *
53   * @param self IntArrayList handle
54   * @param element Element to be removed
55   */
56   ESR_ReturnCode(*remove)(struct IntArrayList_t* self, int element);
57 
58   /**
59   * Removes all elements from list.
60   *
61   * @param self IntArrayList handle
62   */
63   ESR_ReturnCode(*removeAll)(struct IntArrayList_t* self);
64 
65   /**
66   * Indicates if element is contained within the list.
67   *
68   * @param self IntArrayList handle
69   * @param element Element to check for
70   * @param exists True if element was found
71   */
72   ESR_ReturnCode(*contains)(struct IntArrayList_t* self, int element, ESR_BOOL* exists);
73 
74   /**
75   * Returns array size.
76   *
77   * @param self IntArrayList handle
78   * @param size Returned size
79   */
80   ESR_ReturnCode(*getSize)(struct IntArrayList_t* self, size_t* size);
81 
82   /**
83   * Returns the element at the specified index.
84   *
85   * @param self IntArrayList handle
86   * @param index Element index
87   * @param element Element being returned
88   */
89   ESR_ReturnCode(*get)(struct IntArrayList_t* self, size_t index, int* element);
90 
91   /**
92   * Sets the element at the specified index.
93   *
94   * NOTE: Does *not* deallocate the element being overwritten.
95   * @param self IntArrayList handle
96   * @param index Element index
97   * @param element Element's new value
98   */
99   ESR_ReturnCode(*set)(struct IntArrayList_t* self, size_t index, int element);
100 
101   /**
102    * Converts the IntArrayList to a static array.
103    * The use of the IntArrayList handle is undefined past this point.
104    *
105    * @param self IntArrayList handle
106    * @param newArray Pointer to resulting array
107    */
108   ESR_ReturnCode(*toStaticArray)(struct IntArrayList_t* self, int** newArray);
109 
110   /**
111   * Destroys the IntArrayList.
112   * @param self IntArrayList handle
113   */
114   ESR_ReturnCode(*destroy)(struct IntArrayList_t* self);
115 }
116 IntArrayList;
117 
118 /**
119  * Creates a new IntArrayList.
120  *
121  * @param self ArrayList handle
122  */
123 ESR_SHARED_API ESR_ReturnCode IntArrayListCreate(IntArrayList** self);
124 
125 /**
126  * Creates a new IntArrayList from the supplied static array.
127  * The static array may not be used past this point.
128  *
129  * @param value Initial value
130  * @param self IntArrayList handle
131  */
132 ESR_SHARED_API ESR_ReturnCode IntArrayListImport(int* value, IntArrayList** self);
133 
134 /**
135  * Adds element to list.
136  *
137  * @param self IntArrayList handle
138  * @param element Element to be added
139  */
140 ESR_SHARED_API ESR_ReturnCode IntArrayListAdd(IntArrayList* self, int element);
141 
142 /**
143  * Removes element from list.
144  *
145  * @param self IntArrayList handle
146  * @param element Element to be removed
147  */
148 ESR_SHARED_API ESR_ReturnCode IntArrayListRemove(IntArrayList* self, int element);
149 
150 /**
151  * Removes all elements from list.
152  *
153  * @param self IntArrayList handle
154  */
155 ESR_SHARED_API ESR_ReturnCode IntArrayListRemoveAll(IntArrayList* self);
156 
157 /**
158  * Indicates if element is contained within the list.
159  *
160  * @param self IntArrayList handle
161  * @param element Element to check for
162  * @param exists True if element was found
163  */
164 ESR_SHARED_API ESR_ReturnCode IntArrayListContains(IntArrayList* self, int element, ESR_BOOL* exists);
165 
166 /**
167  * Returns array size.
168  *
169  * @param self IntArrayList handle
170  * @param size Returned size
171  */
172 ESR_SHARED_API ESR_ReturnCode IntArrayListGetSize(IntArrayList* self, size_t* size);
173 
174 /**
175  * Returns the element at the specified index.
176  *
177  * @param self IntArrayList handle
178  * @param index Element index
179  * @param element Element being returned
180  */
181 ESR_SHARED_API ESR_ReturnCode IntArrayListGet(IntArrayList* self, size_t index, int* element);
182 
183 /**
184  * Sets the element at the specified index.
185  *
186  * NOTE: Does *not* deallocate the element being overwritten.
187  * @param self IntArrayList handle
188  * @param index Element index
189  * @param element Element's new value
190  */
191 ESR_SHARED_API ESR_ReturnCode IntArrayListSet(IntArrayList* self, size_t index, int element);
192 
193 /**
194  * Converts the IntArrayList to a static array.
195  * The IntArrayList handle may not be used past this point.
196  *
197  * @param self IntArrayList handle
198  * @param newArray Pointer to resulting array
199  */
200 ESR_SHARED_API ESR_ReturnCode IntArrayListToStaticArray(IntArrayList* self, int** newArray);
201 
202 /**
203  * Destroys an IntArrayList.
204  *
205  * @param self IntArrayList handle
206  */
207 ESR_SHARED_API ESR_ReturnCode IntArrayListDestroy(IntArrayList* self);
208 
209 /**
210  * @}
211  */
212 
213 
214 #endif /* __INTARRAYLIST_H */
215