Objectively
Object oriented framework for C.
Loading...
Searching...
No Matches
Types.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 <stddef.h>
27#include <stdint.h>
28#include <stdbool.h>
29#include <sys/types.h>
30
31#if defined(_MSC_VER)
32 #include "Windowly.h"
33#endif
34
35#ifndef OBJECTIVELY_EXPORT
36 #define OBJECTIVELY_EXPORT extern
37#endif
38
39#undef interface
40
49typedef void *ident;
50
54typedef struct {
58 ssize_t location;
59
63 size_t length;
64} Range;
65
69typedef enum {
73} Order;
74
81typedef Order (*Comparator)(const ident obj1, const ident obj2);
82
87typedef void (*Consumer)(ident data);
88
94typedef void (*BiConsumer)(ident data1, ident data2);
95
102typedef ident (*Functor)(const ident obj, ident data);
103
110typedef bool (*Predicate)(const ident obj, ident data);
111
118
126typedef ident (*Reducer)(const ident obj, ident accumulator, ident data);
127
131#define clamp(val, min, max) \
132 ({ \
133 typeof(val) _val = (val); typeof(min) _min = (min); typeof(max) _max = (max); \
134 _max < _min ? \
135 _val < _max ? _max : _val > _min ? _min : _val \
136 : \
137 _val < _min ? _min : _val > _max ? _max : _val; \
138 })
139
143#ifndef lengthof
144 #define lengthof(array) (sizeof(array) / sizeof((array)[0]))
145#endif
146
150#ifndef max
151 #define max(a, b) ({ typeof (a) _a = (a); typeof (b) _b = (b); _a > _b ? _a : _b; })
152#endif
153
157#ifndef min
158 #define min(a, b) ({ typeof (a) _a = (a); typeof (b) _b = (b); _a < _b ? _a : _b; })
159#endif
#define obj
static Data * data(void)
Definition Data.c:286
void * ident
The identity type, similar to Objective-C id.
Definition Types.h:49
bool(* Predicate)(const ident obj, ident data)
The Predicate function type for filtering Objects.
Definition Types.h:110
Order(* Comparator)(const ident obj1, const ident obj2)
The Comparator function type for ordering Objects.
Definition Types.h:81
ident(* Functor)(const ident obj, ident data)
The Functor function type for transforming Objects.
Definition Types.h:102
void(* Consumer)(ident data)
The Consumer function type.
Definition Types.h:87
ident(* Reducer)(const ident obj, ident accumulator, ident data)
The Reducer function type for reducing collections.
Definition Types.h:126
void(* BiConsumer)(ident data1, ident data2)
The BiConsumer function type.
Definition Types.h:94
ident(* Producer)(ident data)
The Producer function type.
Definition Types.h:117
Order
Comparison constants.
Definition Types.h:69
@ OrderSame
Definition Types.h:71
@ OrderDescending
Definition Types.h:72
@ OrderAscending
Definition Types.h:70
A location and length into contiguous collections.
Definition Types.h:54
ssize_t location
The location.
Definition Types.h:58
size_t length
The length.
Definition Types.h:63