annotate src/vector.h @ 10:1ae09f1ddaa9

Move additional dynamic libraries under lib/
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 05 Aug 2013 15:02:32 +0300
parents 785057719d9b
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
1 /* ============================================================================
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
2 * Freetype GL - A C OpenGL Freetype engine
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
3 * Platform: Any
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
4 * WWW: http://code.google.com/p/freetype-gl/
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
5 * ----------------------------------------------------------------------------
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
6 * Copyright 2011,2012 Nicolas P. Rougier. All rights reserved.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
7 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
8 * Redistribution and use in source and binary forms, with or without
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
9 * modification, are permitted provided that the following conditions are met:
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
10 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
11 * 1. Redistributions of source code must retain the above copyright notice,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
12 * this list of conditions and the following disclaimer.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
13 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
14 * 2. Redistributions in binary form must reproduce the above copyright
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
15 * notice, this list of conditions and the following disclaimer in the
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
16 * documentation and/or other materials provided with the distribution.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
17 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
18 * THIS SOFTWARE IS PROVIDED BY NICOLAS P. ROUGIER ''AS IS'' AND ANY EXPRESS OR
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
19 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
20 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
21 * EVENT SHALL NICOLAS P. ROUGIER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
22 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
23 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
24 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
25 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
27 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
28 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
29 * The views and conclusions contained in the software and documentation are
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
30 * those of the authors and should not be interpreted as representing official
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
31 * policies, either expressed or implied, of Nicolas P. Rougier.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
32 * ============================================================================
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
33 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
34 #ifndef __VECTOR_H__
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
35 #define __VECTOR_H__
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
36
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
37 #include <stdlib.h>
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
38
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
39 #ifdef __cplusplus
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
40 extern "C" {
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
41 #endif
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
42
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
43 #include <stddef.h>
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
44
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
45 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
46 * @file vector.h
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
47 * @author Nicolas Rougier (Nicolas.Rougier@inria.fr)
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
48 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
49 * @defgroup vector Vector
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
50 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
51 * The vector structure and accompanying functions loosely mimic the STL C++
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
52 * vector class. It is used by @ref texture-atlas (for storing nodes), @ref
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
53 * texture-font (for storing glyphs) and @ref font-manager (for storing fonts).
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
54 * More information at http://www.cppreference.com/wiki/container/vector/start
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
55 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
56 * <b>Example Usage</b>:
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
57 * @code
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
58 * #include "vector.h"
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
59 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
60 * int main( int arrgc, char *argv[] )
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
61 * {
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
62 * int i,j = 1;
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
63 * vector_t * vector = vector_new( sizeof(int) );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
64 * vector_push_back( &i );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
65 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
66 * j = * (int *) vector_get( vector, 0 );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
67 * vector_delete( vector);
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
68 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
69 * return 0;
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
70 * }
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
71 * @endcode
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
72 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
73 * @{
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
74 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
75
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
76 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
77 * Generic vector structure.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
78 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
79 * @memberof vector
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
80 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
81 typedef struct
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
82 {
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
83 /** Pointer to dynamically allocated items. */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
84 void * items;
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
85
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
86 /** Number of items that can be held in currently allocated storage. */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
87 size_t capacity;
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
88
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
89 /** Number of items. */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
90 size_t size;
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
91
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
92 /** Size (in bytes) of a single item. */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
93 size_t item_size;
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
94 } vector_t;
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
95
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
96
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
97 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
98 * Creates a new empty vector.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
99 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
100 * @param item_size item size in bytes
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
101 * @return a new empty vector
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
102 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
103 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
104 vector_t *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
105 vector_new( size_t item_size );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
106
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
107
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
108 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
109 * Deletes a vector.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
110 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
111 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
112 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
113 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
114 void
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
115 vector_delete( vector_t *self );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
116
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
117
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
118 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
119 * Returns a pointer to the item located at specified index.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
120 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
121 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
122 * @param index the index of the item to be returned
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
123 * @return pointer on the specified item
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
124 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
125 const void *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
126 vector_get( const vector_t *self,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
127 size_t index );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
128
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
129
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
130 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
131 * Returns a pointer to the first item.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
132 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
133 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
134 * @return pointer on the first item
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
135 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
136 const void *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
137 vector_front( const vector_t *self );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
138
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
139
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
140 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
141 * Returns a pointer to the last item
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
142 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
143 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
144 * @return pointer on the last item
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
145 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
146 const void *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
147 vector_back( const vector_t *self );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
148
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
149
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
150 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
151 * Check if an item is contained within the vector.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
152 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
153 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
154 * @param item item to be searched in the vector
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
155 * @param cmp a pointer a comparison function
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
156 * @return 1 if item is contained within the vector, 0 otherwise
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
157 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
158 int
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
159 vector_contains( const vector_t *self,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
160 const void *item,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
161 int (*cmp)(const void *, const void *) );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
162
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
163
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
164 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
165 * Checks whether the vector is empty.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
166 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
167 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
168 * @return 1 if the vector is empty, 0 otherwise
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
169 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
170 int
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
171 vector_empty( const vector_t *self );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
172
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
173
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
174 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
175 * Returns the number of items
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
176 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
177 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
178 * @return number of items
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
179 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
180 size_t
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
181 vector_size( const vector_t *self );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
182
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
183
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
184 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
185 * Reserve storage such that it can hold at last size items.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
186 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
187 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
188 * @param size the new storage capacity
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
189 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
190 void
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
191 vector_reserve( vector_t *self,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
192 const size_t size );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
193
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
194
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
195 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
196 * Returns current storage capacity
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
197 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
198 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
199 * @return storage capacity
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
200 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
201 size_t
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
202 vector_capacity( const vector_t *self );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
203
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
204
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
205 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
206 * Decrease capacity to fit actual size.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
207 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
208 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
209 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
210 void
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
211 vector_shrink( vector_t *self );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
212
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
213
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
214 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
215 * Removes all items.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
216 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
217 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
218 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
219 void
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
220 vector_clear( vector_t *self );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
221
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
222
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
223 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
224 * Replace an item.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
225 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
226 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
227 * @param index the index of the item to be replaced
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
228 * @param item the new item
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
229 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
230 void
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
231 vector_set( vector_t *self,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
232 const size_t index,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
233 const void *item );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
234
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
235
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
236 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
237 * Erase an item.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
238 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
239 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
240 * @param index the index of the item to be erased
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
241 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
242 void
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
243 vector_erase( vector_t *self,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
244 const size_t index );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
245
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
246
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
247 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
248 * Erase a range of items.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
249 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
250 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
251 * @param first the index of the first item to be erased
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
252 * @param last the index of the last item to be erased
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
253 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
254 void
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
255 vector_erase_range( vector_t *self,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
256 const size_t first,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
257 const size_t last );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
258
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
259
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
260 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
261 * Appends given item to the end of the vector.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
262 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
263 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
264 * @param item the item to be inserted
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
265 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
266 void
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
267 vector_push_back( vector_t *self,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
268 const void *item );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
269
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
270
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
271 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
272 * Removes the last item of the vector.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
273 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
274 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
275 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
276 void
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
277 vector_pop_back( vector_t *self );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
278
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
279
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
280 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
281 * Resizes the vector to contain size items
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
282 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
283 * If the current size is less than size, additional items are appended and
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
284 * initialized with value. If the current size is greater than size, the
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
285 * vector is reduced to its first size elements.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
286 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
287 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
288 * @param size the new size
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
289 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
290 void
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
291 vector_resize( vector_t *self,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
292 const size_t size );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
293
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
294
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
295 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
296 * Insert a single item at specified index.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
297 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
298 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
299 * @param index location before which to insert item
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
300 * @param item the item to be inserted
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
301 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
302 void
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
303 vector_insert( vector_t *self,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
304 const size_t index,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
305 const void *item );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
306
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
307
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
308 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
309 * Insert raw data at specified index.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
310 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
311 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
312 * @param index location before which to insert item
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
313 * @param data a pointer to the items to be inserted
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
314 * @param count the number of items to be inserted
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
315 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
316 void
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
317 vector_insert_data( vector_t *self,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
318 const size_t index,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
319 const void * data,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
320 const size_t count );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
321
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
322
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
323 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
324 * Append raw data to the end of the vector.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
325 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
326 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
327 * @param data a pointer to the items to be inserted
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
328 * @param count the number of items to be inserted
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
329 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
330 void
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
331 vector_push_back_data( vector_t *self,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
332 const void * data,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
333 const size_t count );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
334
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
335
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
336 /**
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
337 * Sort vector items according to cmp function.
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
338 *
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
339 * @param self a vector structure
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
340 * @param cmp a pointer a comparison function
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
341 */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
342 void
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
343 vector_sort( vector_t *self,
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
344 int (*cmp)(const void *, const void *) );
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
345
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
346
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
347 /** @} */
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
348
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
349 #ifdef __cplusplus
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
350 }
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
351 #endif
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
352
785057719d9b Import.
Matti Hamalainen <ccr@tnsp.org>
parents:
diff changeset
353 #endif /* __VECTOR_H__ */