Objectively
Ultra-lightweight object oriented framework for GNU C.
Loading...
Searching...
No Matches
List.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/Object.h>
27
33typedef struct List List;
34typedef struct ListInterface ListInterface;
35typedef struct ListNode ListNode;
36
44typedef bool (*ListEnumerator)(const List *list, ListNode *node, ident data);
45
54
60struct List {
61
66
71 ListInterface *interface;
72
76 size_t count;
77
82
87
92};
93
97struct ListInterface {
98
102 ObjectInterface objectInterface;
103
111 void (*append)(List *self, const ident element);
112
120 bool (*contains)(const List *self, const ident element);
121
130 void (*enumerate)(const List *self, ListEnumerator enumerator, ident data);
131
140 void (*filter)(List *self, Predicate predicate, ident data);
141
151 List *(*filteredList)(const List *self, Predicate predicate, ident data);
152
161 ident (*find)(const List *self, Predicate predicate, ident data);
162
170 List *(*init)(List *self);
171
180 void (*insertAfter)(List *self, ListNode *node, const ident element);
181
190 void (*map)(List *self, Functor functor, ident data);
191
201 List *(*mappedList)(const List *self, Functor functor, ident data);
202
210 ListNode *(*nodeForElement)(const List *self, const ident element);
211
219 void (*prepend)(List *self, const ident element);
220
230 ident (*reduce)(const List *self, Reducer reducer, ident accumulator, ident data);
231
238 void (*removeAll)(List *self);
239
247 void (*remove)(List *self, const ident element);
248
256 void (*removeNode)(List *self, ListNode *node);
257
265 void (*sort)(List *self, Comparator comparator);
266};
267
static Data * data(void)
Definition Data.c:286
OBJECTIVELY_EXPORT Class * _List(void)
Definition List.c:385
bool(* ListEnumerator)(const List *list, ListNode *node, ident data)
The ListEnumerator function type.
Definition List.h:44
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
The runtime representation of a Class.
Definition Class.h:95
Doubly-linked lists of raw C pointers.
Definition List.h:60
ListNode * head
The head node.
Definition List.h:81
size_t count
The number of elements.
Definition List.h:76
Object object
The superclass.
Definition List.h:65
Consumer destroy
Optional destructor called when an element is removed.
Definition List.h:91
ListInterface * interface
The interface.
Definition List.h:71
ListNode * tail
The tail node.
Definition List.h:86
A node in a List.
Definition List.h:49
ListNode * prev
Definition List.h:51
ident element
Definition List.h:50
ListNode * next
Definition List.h:52
Object is the root Class of The Objectively Class hierarchy.
Definition Object.h:46