Objectively
Ultra-lightweight object oriented framework for GNU C.
Loading...
Searching...
No Matches
Vector.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
35typedef struct Vector Vector;
36typedef struct VectorInterface VectorInterface;
37
44typedef void (*VectorEnumerator)(const Vector *vector, ident obj, ident data);
45
51struct Vector {
52
57
62 VectorInterface *interface;
63
67 size_t capacity;
68
72 size_t count;
73
77 size_t size;
78
83
91};
92
96#define VectorElement(vector, type, index) \
97 (((type *) vector->elements) + (index))
98
102#define VectorValue(vector, type, index) \
103 *(VectorElement(vector, type, index))
104
108struct VectorInterface {
109
113 ObjectInterface objectInterface;
114
122 void (*add)(Vector *self, const ident element);
123
132 void (*enumerate)(const Vector *self, VectorEnumerator enumerator, ident data);
133
142 void (*filter)(Vector *self, Predicate predicate, ident data);
143
152 ident (*find)(const Vector *self, Predicate predicate, ident data);
153
161 ssize_t (*indexOf)(const Vector *self, const ident element);
162
173 Vector *(*initWithElements)(Vector *self, size_t size, size_t count, ident elements);
174
183 Vector *(*initWithSize)(Vector *self, size_t size);
184
193 void (*insert)(Vector *self, const ident element, size_t index);
194
204 Vector *(*mappedVector)(const Vector *self, Functor functor, ident data);
205
215 ident (*reduce)(const Vector *self, Reducer reducer, ident accumulator, ident data);
216
223 void (*removeAll)(Vector *self);
224
232 void (*removeAt)(Vector *self, size_t index);
233
241 void (*resize)(Vector *self, size_t capacity);
242
250 void (*sort)(Vector *self, Comparator comparator);
251
262 Vector *(*vectorWithElements)(size_t size, size_t count, ident elements);
263
272 Vector *(*vectorWithSize)(size_t size);
273};
274
#define obj
static Data * data(void)
Definition Data.c:286
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
void(* Consumer)(ident data)
The Consumer function type.
Definition Types.h:88
ident(* Reducer)(const ident obj, ident accumulator, ident data)
The Reducer function type for reducing collections.
Definition Types.h:127
void(* VectorEnumerator)(const Vector *vector, ident obj, ident data)
The VectorEnumerator function type.
Definition Vector.h:44
OBJECTIVELY_EXPORT Class * _Vector(void)
Definition Vector.c:428
The runtime representation of a Class.
Definition Class.h:95
Object is the root Class of The Objectively Class hierarchy.
Definition Object.h:46
Vectors.
Definition Vector.h:51
Object object
The superclass.
Definition Vector.h:56
Consumer destroy
Optional destructor called when an element is removed.
Definition Vector.h:90
VectorInterface * interface
The interface.
Definition Vector.h:62
size_t count
The count of elements.
Definition Vector.h:72
size_t capacity
The capacity.
Definition Vector.h:67
ident elements
The elements.
Definition Vector.h:82
size_t size
The size of each element.
Definition Vector.h:77