Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
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 {
55
59 ssize_t location;
60
64 size_t length;
65} Range;
66
70typedef enum {
74} Order;
75
82typedef Order (*Comparator)(const ident obj1, const ident obj2);
83
88typedef void (*Consumer)(ident data);
89
95typedef void (*BiConsumer)(ident data1, ident data2);
96
103typedef ident (*Functor)(const ident obj, ident data);
104
111typedef _Bool (*Predicate)(const ident obj, ident data);
112
119
127typedef ident (*Reducer)(const ident obj, ident accumulator, ident data);
128
132#define clamp(val, min, max) \
133 ({ \
134 typeof(val) _val = (val); typeof(min) _min = (min); typeof(max) _max = (max); \
135 _max < _min ? \
136 _val < _max ? _max : _val > _min ? _min : _val \
137 : \
138 _val < _min ? _min : _val > _max ? _max : _val; \
139 })
140
144#ifndef lengthof
145 #define lengthof(array) (sizeof(array) / sizeof((array)[0]))
146#endif
147
151#ifndef max
152 #define max(a, b) ({ typeof (a) _a = (a); typeof (b) _b = (b); _a > _b ? _a : _b; })
153#endif
154
158#ifndef min
159 #define min(a, b) ({ typeof (a) _a = (a); typeof (b) _b = (b); _a < _b ? _a : _b; })
160#endif
#define obj
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: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(* BiConsumer)(ident data1, ident data2)
The BiConsumer function type.
Definition: Types.h:95
ident(* Producer)(ident data)
The Producer function type.
Definition: Types.h:118
Order
Comparison constants.
Definition: Types.h:70
@ OrderSame
Definition: Types.h:72
@ OrderDescending
Definition: Types.h:73
@ OrderAscending
Definition: Types.h:71
MutableData * data(void)
Returns a new MutableData.
Definition: MutableData.c:75
A location and length into contiguous collections.
Definition: Types.h:54
ssize_t location
The location.
Definition: Types.h:59
size_t length
The length.
Definition: Types.h:64