Objectively
Ultra-lightweight object oriented framework for GNU C.
Loading...
Searching...
No Matches
Set.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 <Objectively/Array.h>
27#include <Objectively/Object.h>
28
39typedef struct Set Set;
40typedef struct SetInterface SetInterface;
41
48typedef void (*SetEnumerator)(const Set *set, ident obj, ident data);
49
55struct Set {
56
61
66 SetInterface *interface;
67
72 size_t capacity;
73
77 size_t count;
78
83 ident *elements;
84};
85
86
90struct SetInterface {
91
95 ObjectInterface objectInterface;
96
104 void (*addObject)(Set *self, const ident obj);
105
113 void (*addObjectsFromArray)(Set *self, const Array *array);
114
122 void (*addObjectsFromSet)(Set *self, const Set *set);
123
130 Array *(*allObjects)(const Set *self);
131
139 bool (*containsObject)(const Set *self, const ident obj);
140
149 bool (*containsObjectMatching)(const Set *self, Predicate predicate, ident data);
150
160 void (*enumerateObjects)(const Set *self, SetEnumerator enumerator, ident data);
161
170 void (*filter)(Set *self, Predicate predicate, ident data);
171
181 Set *(*filteredSet)(const Set *self, Predicate predicate, ident data);
182
190 Set *(*init)(Set *self);
191
200 Set *(*initWithArray)(Set *self, const Array *array);
201
210 Set *(*initWithCapacity)(Set *self, size_t capacity);
211
219 Set *(*initWithObjects)(Set *self, ...);
220
229 Set *(*initWithSet)(Set *self, const Set *set);
230
240 Set *(*mappedSet)(const Set *self, Functor functor, ident data);
241
251 ident (*reduce)(const Set *self, Reducer reducer, ident accumulator, ident data);
252
259 void (*removeAllObjects)(Set *self);
260
268 void (*removeObject)(Set *self, const ident obj);
269
277 Set *(*set)(void);
278
287 Set *(*setWithArray)(const Array *array);
288
297 Set *(*setWithCapacity)(size_t capacity);
298
307 Set *(*setWithObjects)(ident obj, ...);
308
317 Set *(*setWithSet)(const Set *set);
318
319};
320
static Array * array(void)
Definition Array.c:234
Arrays.
#define obj
static Data * data(void)
Definition Data.c:286
Object is the root Class of The Objectively Class hierarchy.
static Set * set(void)
Definition Set.c:572
void(* SetEnumerator)(const Set *set, ident obj, ident data)
A function pointer for Set enumeration (iteration).
Definition Set.h:48
OBJECTIVELY_EXPORT Class * _Set(void)
Definition Set.c:669
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
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
The runtime representation of a Class.
Definition Class.h:95
Object is the root Class of The Objectively Class hierarchy.
Definition Object.h:46
Sets.
Definition Set.h:55
Object object
The superclass.
Definition Set.h:60
size_t count
The count of elements.
Definition Set.h:77
SetInterface * interface
The interface.
Definition Set.h:66