RTI Connext Micro  Version 2.4.1.0
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups
reda_indexer.h
1 /*
2  * FILE: reda_indexer.h - Indexer interface
3  *
4  * Copyright 2012-2014 Real-Time Innovations, Inc.
5  *
6  * No duplications, whole or partial, manual or electronic, may be made
7  * without express written permission. Any such copies, or
8  * revisions thereof, must display this notice unaltered.
9  * This code contains trade secrets of Real-Time Innovations, Inc.
10  *
11  * Modification History
12  * --------------------
13  * 31jul2014,tk MICRO-172/PR#1064 - Removed superfluous REDA_Indexer fields
14  * 25oct2012,tk Written
15  */
16 /*ci
17  * \file
18  *
19  * \brief The REDA Indexer interface provides a implementation independent API
20  * for searching and finding elements.
21  *
22  * \defgroup REDAIndexerClass REDA Indexer
23  * \ingroup REDAModule
24  *
25  * \details
26  *
27  * The REDA Indexer indexes elements based on a compare function and
28  * provides function to search and iterate over the elements in the index.
29  * The API is defined so that the underlying data-structures are not exposed.
30  */
31 #ifndef reda_indexer_h
32 #define reda_indexer_h
33 #ifndef reda_dll_h
34 #include "reda/reda_dll.h"
35 #endif
36 
37 #ifdef __cplusplus
38 extern "C"
39 {
40 #endif
41 
42 /*ci
43  * \addtogroup REDAIndexerClass
44  * @{
45  */
46 struct REDA_Indexer;
47 
48 /*ci
49  * \brief Abstract Indexer type
50  */
51 typedef struct REDA_Indexer REDA_Indexer_T;
52 
53 /*ci
54  * \brief The properties an index can be created with.
55  */
56 struct REDA_IndexerProperty
57 {
58  /*ci
59  * \brief The maximum number of elements the index can handle
60  */
61  RTI_INT32 max_entries;
62 };
63 
64 /*ci
65  * \def REDA_IndexerProperty_INITIALIZER
66  * \brief \ref REDA_IndexerProperty initializer
67  */
68 #define REDA_IndexerProperty_INITIALIZER \
69 {\
70  1\
71 }
72 
73 /*ci
74  * \brief A generic record compare function
75  *
76  * \details
77  *
78  * The compare function must maintain an ordered relationship.
79  *
80  * \param[in] record Already indexed element to compare against
81  * \param[in] key_is_record Whether the key is a complete record or the user
82  * defined key
83  * \param[in] key Key to compare against
84  *
85  * \return The function must return a 0 if record == key,
86  * < 0 if record < key and > 0 if record > key
87  */
88 FUNCTION_MUST_TYPEDEF(
89 RTI_INT32
90 (*REDA_Indexer_compare_T)(const void *const record, RTI_BOOL key_is_record,
91  const void *const key)
92 )
93 
94 /*ci
95  * \brief Create a new indexer
96  *
97  * \param[in] compare Compare function that determines the ordering of the
98  * indexed elements as defined for
99  * \ref REDA_Indexer_compare_T
100  *
101  * \param[in] property Indexer property. Refer to \ref
102  * REDA_IndexerProperty for details.
103  *
104  * \return Pointer to new indexer on success, NULL on failure
105  *
106  * \sa REDA_Indexer_delete
107  */
108 MUST_CHECK_RETURN REDADllExport REDA_Indexer_T*
109 REDA_Indexer_new(REDA_Indexer_compare_T compare,
110  struct REDA_IndexerProperty *property);
111 
112 /*ci
113  * \brief Delete an indexer
114  *
115  * \details
116  *
117  * Delete an index. It is legal to delete an index which contains elements.
118  * It is the callers responsibility to make sure that the elements in the
119  * index can be properly deleted.
120  *
121  * \param[in] indexer Indexer to delete
122  *
123  * \return RTI_TRUE on success, RTI_FALSE on failure
124  *
125  * \sa REDA_Indexer_new
126  */
127 SHOULD_CHECK_RETURN REDADllExport RTI_BOOL
128 REDA_Indexer_delete(REDA_Indexer_T *indexer);
129 
130 /*ci
131  * \brief Add an element to an index
132  *
133  * \details
134  *
135  * Add an element to the indexer. The indexer is not responsible for mananging
136  * the memory owner the entry.
137  *
138  * \param[in] indexer Indexer to add the element to
139  * \param[in] entry Entry to add to indexer
140  *
141  * \return RTI_TRUE on success, RTI_FALSE on failure
142  *
143  * \sa REDA_Indexer_remove_entry
144  */
145 MUST_CHECK_RETURN REDADllExport RTI_BOOL
146 REDA_Indexer_add_entry(REDA_Indexer_T *indexer,void *entry);
147 
148 /*ci
149  * \brief Remove an element from an index
150  *
151  * \details
152  *
153  * Remove an element from an indexer based on the key. The indexer is not
154  * responsible for managing the memory used by the removed entry.
155  *
156  * \param[in] indexer Indexer to add the element to
157  * \param[in] key Key to remove
158  *
159  * \return pointer to removed entry if it existed, NULL otherwise.
160  *
161  * \sa REDA_Indexer_add_entry
162  */
163 SHOULD_CHECK_RETURN REDADllExport void*
164 REDA_Indexer_remove_entry(REDA_Indexer_T *indexer,const void *const key);
165 
166 /*ci
167  * \brief Find an entry based on the key
168  *
169  * \details
170  *
171  * Search for an entry based on the key.
172  *
173  * \param[in] indexer Indexer to search for element in
174  * \param[in] key Key to search for
175  *
176  * \return pointer to entry if it existed, NULL otherwise.
177  *
178  * \sa REDA_Indexer_find_entry_eq_or_gt
179  */
180 MUST_CHECK_RETURN REDADllExport void*
181 REDA_Indexer_find_entry(REDA_Indexer_T *indexer,const void *const key);
182 
183 /*ci
184  * \brief Find an entry with a key greater or equal to the key
185  *
186  * \details
187  *
188  * Find an entry with a key greater or equal to the key.
189  *
190  * \param[in] indexer Indexer to search for element in
191  * \param[in] key Key to search for
192  *
193  * \return pointer to entry if it existed, NULL otherwise.
194  *
195  * \sa REDA_Indexer_find_entry
196  */
197 MUST_CHECK_RETURN REDADllExport void*
198 REDA_Indexer_find_entry_eq_or_gt(REDA_Indexer_T *indexer,const void *const key);
199 
200 /*ci
201  * \brief Return the number of elements in the index
202  *
203  * \details
204  *
205  * Return the number of elements in the index
206  *
207  * \param[in] indexer Indexer to return count for. Indexer cannot be NULL,
208  * and it is callers responsibility to ensure it is not.
209  *
210  * \return Number of elements in the index.
211  *
212  * \sa REDA_Indexer_get_entry
213  */
214 MUST_CHECK_RETURN REDADllExport RTI_INT32
215 REDA_Indexer_get_count(REDA_Indexer_T *indexer);
216 
217 /*ci
218  * \brief Return the index'th element in the index
219  *
220  * \details
221  *
222  * Return the index'th element in the index.
223  *
224  * \param[in] indexer Indexer to return the element from
225  * \param[in] index Which element to return, starting at 0
226  *
227  * \return The index'th element in the indexer
228  *
229  * \sa REDA_Indexer_get_count
230  */
231 MUST_CHECK_RETURN REDADllExport void*
232 REDA_Indexer_get_entry(REDA_Indexer_T *indexer,RTI_INT32 index);
233 
234 /*ci
235  * \brief Return the first element in the index
236  *
237  * \details
238  *
239  * Return the first element in the index
240  *
241  * \param[in] indexer Indexer to return the the first element from
242  *
243  * \return The first element in the index, NULL if the index is empty.
244  *
245  * \sa
246  */
247 MUST_CHECK_RETURN REDADllExport void*
248 REDA_Indexer_get_first_entry(REDA_Indexer_T *indexer);
249 
250 /*ci
251  * \brief Return the last element in the index
252  *
253  * \details
254  *
255  * Return the last element in the index
256  *
257  * \param[in] indexer Indexer to return the the last element from
258  *
259  * \return The last element in the index, NULL if the index is empty.
260  *
261  * \sa
262  */
263 MUST_CHECK_RETURN REDADllExport void*
264 REDA_Indexer_get_last_entry(REDA_Indexer_T *indexer);
265 
266 #ifdef __cplusplus
267 } /* extern "C" */
268 #endif
269 
270 #endif /* reda_indexer_h */
271 
272 /*ci @} */

RTI Connext Micro Version 2.4.1.0 Copyright © Thu Nov 20 2014 Real-Time Innovations, Inc