Objectively
Ultra-lightweight object oriented framework for GNU C.
Loading...
Searching...
No Matches
Array.h
Go to the documentation of this file.
1/*
2 * Objectively: Ultra-lightweight object oriented framework for GNU C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#pragma once
25
26#include <stdarg.h>
27
28#include <Objectively/Object.h>
29
40typedef struct Array Array;
41typedef struct ArrayInterface ArrayInterface;
42
49typedef void (*ArrayEnumerator)(const Array *array, ident obj, ident data);
50
56struct Array {
57
62
67 ArrayInterface *interface;
68
72 size_t count;
73
78 ident *elements;
79
84 size_t capacity;
85};
86
87
91struct ArrayInterface {
92
96 ObjectInterface objectInterface;
97
105 void (*addObject)(Array *self, const ident obj);
106
114 void (*addObjects)(Array *self, const ident obj, ...);
115
123 void (*addObjectsFromArray)(Array *self, const Array *array);
124
132 Array *(*array)(void);
133
142 Array *(*arrayWithArray)(const Array *array);
143
152 Array *(*arrayWithCapacity)(size_t capacity);
153
162 Array *(*arrayWithObjects)(ident obj, ...);
163
172 Array *(*arrayWithVaList)(va_list args);
173
182 String *(*componentsJoinedByCharacters)(const Array *self, const char *chars);
183
192 String *(*componentsJoinedByString)(const Array *self, const String *string);
193
201 bool (*containsObject)(const Array *self, const ident obj);
202
211 void (*enumerate)(const Array *self, ArrayEnumerator enumerator, ident data);
212
221 void (*filter)(Array *self, Predicate predicate, ident data);
222
232 Array *(*filteredArray)(const Array *self, Predicate predicate, ident data);
233
242 ident (*find)(const Array *self, Predicate predicate, ident data);
243
250 ident (*firstObject)(const Array *self);
251
259 ssize_t (*indexOfObject)(const Array *self, const ident obj);
260
268 Array *(*init)(Array *self);
269
278 Array *(*initWithArray)(Array *self, const Array *array);
279
288 Array *(*initWithCapacity)(Array *self, size_t capacity);
289
297 Array *(*initWithObjects)(Array *self, ...);
298
307 Array *(*initWithVaList)(Array *self, va_list args);
308
317 void (*insertObjectAtIndex)(Array *self, ident obj, size_t index);
318
325 ident (*lastObject)(const Array *self);
326
335 void (*map)(Array *self, Functor functor, ident data);
336
346 Array *(*mappedArray)(const Array *self, Functor functor, ident data);
347
355 ident (*objectAtIndex)(const Array *self, size_t index);
356
366 ident (*reduce)(const Array *self, Reducer reducer, ident accumulator, ident data);
367
374 void (*removeAllObjects)(Array *self);
375
384 void (*removeAllObjectsWithEnumerator)(Array *self, ArrayEnumerator enumerator, ident data);
385
392 void (*removeLastObject)(Array *self);
393
401 void (*removeObject)(Array *self, const ident obj);
402
410 void (*removeObjectAtIndex)(Array *self, size_t index);
411
421 void (*setObjectAtIndex)(Array *self, const ident obj, size_t index);
422
430 void (*sort)(Array *self, Comparator comparator);
431
439 Array *(*sortedArray)(const Array *self, Comparator comparator);
440
441};
442
450
451
460OBJECTIVELY_EXPORT void quicksort(ident base, size_t count, size_t size, Comparator comparator, ident data);
static Array * array(void)
Definition Array.c:234
void(* ArrayEnumerator)(const Array *array, ident obj, ident data)
A function pointer for Array enumeration (iteration).
Definition Array.h:49
OBJECTIVELY_EXPORT Class * _Array(void)
Definition Array.c:760
OBJECTIVELY_EXPORT void quicksort(ident base, size_t count, size_t size, Comparator comparator, ident data)
A portability wrapper around reentrant qsort.
Definition Array.c:69
#define obj
static Data * data(void)
Definition Data.c:286
Object is the root Class of The Objectively Class hierarchy.
static String * string(void)
Definition String.c:905
void * ident
The identity type, similar to Objective-C id.
Definition Types.h:49
#define OBJECTIVELY_EXPORT
Definition Types.h:36
bool(* Predicate)(const ident obj, ident data)
The Predicate function type for filtering Objects.
Definition Types.h:111
Order(* Comparator)(const ident obj1, const ident obj2)
The Comparator function type for ordering Objects.
Definition Types.h:82
ident(* Functor)(const ident obj, ident data)
The Functor function type for transforming Objects.
Definition Types.h:103
ident(* Reducer)(const ident obj, ident accumulator, ident data)
The Reducer function type for reducing collections.
Definition Types.h:127
Arrays.
Definition Array.h:56
ArrayInterface * interface
The interface.
Definition Array.h:67
Object object
The superclass.
Definition Array.h:61
size_t count
The count of elements.
Definition Array.h:72
The runtime representation of a Class.
Definition Class.h:95
Object is the root Class of The Objectively Class hierarchy.
Definition Object.h:46
UTF-8 strings.
Definition String.h:69