Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
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};
80
81typedef struct MutableArray MutableArray;
82
86struct ArrayInterface {
87
91 ObjectInterface objectInterface;
92
101 Array *(*arrayWithArray)(const Array *array);
102
111 Array *(*arrayWithObjects)(ident obj, ...);
112
121 Array *(*arrayWithVaList)(va_list args);
122
131 String *(*componentsJoinedByCharacters)(const Array *self, const char *chars);
132
141 String *(*componentsJoinedByString)(const Array *self, const String *string);
142
150 _Bool (*containsObject)(const Array *self, const ident obj);
151
160 void (*enumerateObjects)(const Array *self, ArrayEnumerator enumerator, ident data);
161
171 Array *(*filteredArray)(const Array *self, Predicate predicate, ident data);
172
181 ident (*findObject)(const Array *self, Predicate predicate, ident data);
182
189 ident (*firstObject)(const Array *self);
190
198 ssize_t (*indexOfObject)(const Array *self, const ident obj);
199
208 Array *(*initWithArray)(Array *self, const Array *array);
209
217 Array *(*initWithObjects)(Array *self, ...);
218
227 Array *(*initWithVaList)(Array *self, va_list args);
228
235 ident (*lastObject)(const Array *self);
236
246 Array *(*mappedArray)(const Array *self, Functor functor, ident data);
247
254 MutableArray *(*mutableCopy)(const Array *self);
255
263 ident (*objectAtIndex)(const Array *self, size_t index);
264
274 ident (*reduce)(const Array *self, Reducer reducer, ident accumulator, ident data);
275
283 Array *(*sortedArray)(const Array *self, Comparator comparator);
284};
285
static ident findObject(const Array *self, Predicate predicate, ident data)
Definition: Array.c:245
static ident reduce(const Array *self, Reducer reducer, ident accumulator, ident data)
Definition: Array.c:405
static ident objectAtIndex(const Array *self, size_t index)
Definition: Array.c:394
static _Bool containsObject(const Array *self, const ident obj)
Definition: Array.c:208
static ident lastObject(const Array *self)
Definition: Array.c:349
static void enumerateObjects(const Array *self, ArrayEnumerator enumerator, ident data)
Definition: Array.c:217
static ident firstObject(const Array *self)
Definition: Array.c:262
static ssize_t indexOfObject(const Array *self, const ident obj)
Definition: Array.c:271
void(* ArrayEnumerator)(const Array *array, ident obj, ident data)
A function pointer for Array enumeration (iteration).
Definition: Array.h:49
#define obj
static MutableArray * array(void)
Definition: MutableArray.c:153
static MutableData * data(void)
Definition: MutableData.c:75
static MutableString * string(void)
Object is the root Class of The Objectively Class hierarchy.
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
Immutable arrays.
Definition: Array.h:56
Class * _Array(void)
The Array archetype.
Definition: Array.c:470
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
Mutable arrays.
Definition: MutableArray.h:40
MutableArray * array(void)
Returns a new MutableArray.
Definition: MutableArray.c:153
MutableData * data(void)
Returns a new MutableData.
Definition: MutableData.c:75
Object is the root Class of The Objectively Class hierarchy.
Definition: Object.h:46
Immutable UTF-8 strings.
Definition: String.h:69