ObjFW
 
Loading...
Searching...
No Matches
OFObject.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008-2026 Jonathan Schleifer <js@nil.im>
3 *
4 * All rights reserved.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU Lesser General Public License version 3.0 only,
8 * as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13 * version 3.0 for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * version 3.0 along with this program. If not, see
17 * <https://www.gnu.org/licenses/>.
18 */
19
20#include "objfw-defs.h"
21
22#ifndef __STDC_LIMIT_MACROS
23# define __STDC_LIMIT_MACROS
24#endif
25#ifndef __STDC_CONSTANT_MACROS
26# define __STDC_CONSTANT_MACROS
27#endif
28
29#include <stddef.h>
30#include <stdint.h>
31#include <stdbool.h>
32#include <limits.h>
33#include <math.h>
34
35#include "macros.h"
36
37#import "OFOnce.h"
38
39/*
40 * Some versions of MinGW require <winsock2.h> to be included before
41 * <windows.h>. Do this here to make sure this is always done in the correct
42 * order, even if another header includes just <windows.h>.
43 */
44#ifdef __MINGW32__
45# include <_mingw.h>
46# ifdef __MINGW64_VERSION_MAJOR
47# include <winsock2.h>
48# include <windows.h>
49# endif
50#endif
51
52OF_ASSUME_NONNULL_BEGIN
53
55
59static const size_t OFNotFound = SIZE_MAX;
60
72
81typedef OFComparisonResult (*OFCompareFunction)(id _Nonnull left,
82 id _Nonnull right, void *_Nullable context);
83
84#ifdef OF_HAVE_BLOCKS
92typedef OFComparisonResult (^OFComparator)(id _Nonnull left, id _Nonnull right);
93#endif
94
110
116typedef struct OF_BOXABLE OFRange {
118 size_t location;
120 size_t length;
121} OFRange;
122
130static OF_INLINE OFRange OF_CONST_FUNC
131OFMakeRange(size_t start, size_t length)
132{
133 OFRange range = { start, length };
134
135 return range;
136}
137
145static OF_INLINE bool
147{
148 if (range1.location != range2.location)
149 return false;
150
151 if (range1.length != range2.length)
152 return false;
153
154 return true;
155}
156
157#ifdef __cplusplus
158extern "C" {
159#endif
160extern void OF_NO_RETURN_FUNC _OFThrowOutOfRangeException(void);
161#ifdef __cplusplus
162}
163#endif
164
171static OF_INLINE size_t
173{
174 if (range.length > SIZE_MAX - range.location)
175 _OFThrowOutOfRangeException();
176
177 return range.location + range.length;
178}
179
187static OF_INLINE bool
188OFLocationInRange(size_t location, OFRange range)
189{
190 return (location >= range.location &&
191 location < OFEndOfRange(range));
192}
193
202static OF_INLINE OFRange
204{
205 OFRange range;
206
207 if (range1.location >= OFEndOfRange(range2) ||
208 range2.location >= OFEndOfRange(range1))
209 return OFMakeRange(OFNotFound, 0);
210
211 range.location = (range1.location > range2.location
212 ? range1.location : range2.location);
213 range.length = (OFEndOfRange(range1) < OFEndOfRange(range2))
214 ? OFEndOfRange(range1) - range.location
215 : OFEndOfRange(range2) - range.location;
216
217 return range;
218}
219
229static OF_INLINE OFRange
231{
232 OFRange range;
233
234 if (range1.location > OFEndOfRange(range2) ||
235 range2.location > OFEndOfRange(range1))
236 return OFMakeRange(OFNotFound, 0);
237
238 range.location = (range1.location < range2.location
239 ? range1.location : range2.location);
240 range.length = (OFEndOfRange(range1) > OFEndOfRange(range2))
241 ? OFEndOfRange(range1) - range.location
242 : OFEndOfRange(range2) - range.location;
243
244 return range;
245}
246
250typedef double OFTimeInterval;
251
257typedef struct OF_BOXABLE OFPoint {
259 float x;
261 float y;
262} OFPoint;
263
271static OF_INLINE OFPoint OF_CONST_FUNC
272OFMakePoint(float x, float y)
273{
274 OFPoint point = { x, y };
275
276 return point;
277}
278
286static OF_INLINE bool
288{
289 if (point1.x != point2.x)
290 return false;
291
292 if (point1.y != point2.y)
293 return false;
294
295 return true;
296}
297
303typedef struct OF_BOXABLE OFSize {
305 float width;
307 float height;
308} OFSize;
309
317static OF_INLINE OFSize OF_CONST_FUNC
318OFMakeSize(float width, float height)
319{
320 OFSize size = { width, height };
321
322 return size;
323}
324
332static OF_INLINE bool
334{
335 if (size1.width != size2.width)
336 return false;
337
338 if (size1.height != size2.height)
339 return false;
340
341 return true;
342}
343
349typedef struct OF_BOXABLE OFRect {
354} OFRect;
355
365static OF_INLINE OFRect OF_CONST_FUNC
366OFMakeRect(float x, float y, float width, float height)
367{
368 OFRect rect = {
369 OFMakePoint(x, y),
370 OFMakeSize(width, height)
371 };
372
373 return rect;
374}
375
383static OF_INLINE bool
385{
386 if (!OFEqualPoints(rect1.origin, rect2.origin))
387 return false;
388
389 if (!OFEqualSizes(rect1.size, rect2.size))
390 return false;
391
392 return true;
393}
394
403static OF_INLINE OFRect
405{
406 OFRect rect;
407
408 rect.origin.x = (rect1.origin.x >= rect2.origin.x
409 ? rect1.origin.x : rect2.origin.x);
410 rect.origin.y = (rect1.origin.y >= rect2.origin.y
411 ? rect1.origin.y : rect2.origin.y);
412 rect.size.width = (rect1.origin.x + rect1.size.width <
413 rect2.origin.x + rect2.size.width
414 ? rect1.origin.x + rect1.size.width
415 : rect2.origin.x + rect2.size.width) - rect.origin.x;
416 rect.size.height = (rect1.origin.y + rect1.size.height <
417 rect2.origin.y + rect2.size.height
418 ? rect1.origin.y + rect1.size.height
419 : rect2.origin.y + rect2.size.height) - rect.origin.y;
420
421 if (rect.size.width <= 0.0f || rect.size.height <= 0.0f) {
422 rect.origin.x = rect.origin.y = 0.0f;
423 rect.size.width = rect.size.height = 0.0f;
424 }
425
426 return rect;
427}
428
434typedef struct OF_BOXABLE OFVector3D {
436 float x;
438 float y;
440 float z;
441} OFVector3D;
442
451static OF_INLINE OFVector3D OF_CONST_FUNC
452OFMakeVector3D(float x, float y, float z)
453{
454 OFVector3D vector = { x, y, z };
455
456 return vector;
457}
458
466static OF_INLINE bool
468{
469 if (vector1.x != vector2.x)
470 return false;
471
472 if (vector1.y != vector2.y)
473 return false;
474
475 if (vector1.z != vector2.z)
476 return false;
477
478 return true;
479}
480
488static OF_INLINE OFVector3D
490{
491 return OFMakeVector3D(vector1.x + vector2.x, vector1.y + vector2.y,
492 vector1.z + vector2.z);
493}
494
502static OF_INLINE OFVector3D
504{
505 return OFMakeVector3D(vector1.x - vector2.x, vector1.y - vector2.y,
506 vector1.z - vector2.z);
507}
508
516static OF_INLINE OFVector3D
517OFMultiplyVector3D(OFVector3D vector, float scalar)
518{
519 return OFMakeVector3D(vector.x * scalar, vector.y * scalar,
520 vector.z * scalar);
521}
522
530static OF_INLINE float
532{
533 return vector1.x * vector2.x + vector1.y * vector2.y +
534 vector1.z * vector2.z;
535}
536
544static OF_INLINE float
546{
547 OFVector3D difference = OFSubtractVectors3D(vector1, vector2);
548
549 return sqrtf(OFDotProductOfVectors3D(difference, difference));
550}
551
557typedef struct OF_BOXABLE OFVector4D {
559 float x;
561 float y;
563 float z;
565 float w;
566} OFVector4D;
567
577static OF_INLINE OFVector4D OF_CONST_FUNC
578OFMakeVector4D(float x, float y, float z, float w)
579{
580 OFVector4D vector = { x, y, z, w };
581
582 return vector;
583}
584
592static OF_INLINE bool
594{
595 if (vector1.x != vector2.x)
596 return false;
597
598 if (vector1.y != vector2.y)
599 return false;
600
601 if (vector1.z != vector2.z)
602 return false;
603
604 if (vector1.w != vector2.w)
605 return false;
606
607 return true;
608}
609
617static OF_INLINE OFVector4D
619{
620 return OFMakeVector4D(vector1.x + vector2.x, vector1.y + vector2.y,
621 vector1.z + vector2.z, vector1.w + vector2.w);
622}
623
631static OF_INLINE OFVector4D
633{
634 return OFMakeVector4D(vector1.x - vector2.x, vector1.y - vector2.y,
635 vector1.z - vector2.z, vector1.w - vector2.w);
636}
637
645static OF_INLINE OFVector4D
646OFMultiplyVector4D(OFVector4D vector, float scalar)
647{
648 return OFMakeVector4D(vector.x * scalar, vector.y * scalar,
649 vector.z * scalar, vector.w * scalar);
650}
651
659static OF_INLINE float
661{
662 return vector1.x * vector2.x + vector1.y * vector2.y +
663 vector1.z * vector2.z + vector1.w * vector2.w;
664}
665
673static OF_INLINE float
675{
676 OFVector4D difference = OFSubtractVectors4D(vector1, vector2);
677
678 return sqrtf(OFDotProductOfVectors4D(difference, difference));
679}
680
687static OF_INLINE void
688OFHashAddByte(unsigned long *_Nonnull hash, unsigned char byte)
689{
690 uint32_t tmp = (uint32_t)*hash;
691
692 tmp += byte;
693 tmp += tmp << 10;
694 tmp ^= tmp >> 6;
695
696 *hash = tmp;
697}
698
705static OF_INLINE void
706OFHashAddHash(unsigned long *_Nonnull hash, unsigned long otherHash)
707{
708 OFHashAddByte(hash, (otherHash >> 24) & 0xFF);
709 OFHashAddByte(hash, (otherHash >> 16) & 0xFF);
710 OFHashAddByte(hash, (otherHash >> 8) & 0xFF);
711 OFHashAddByte(hash, otherHash & 0xFF);
712}
713
719static OF_INLINE void
720OFHashFinalize(unsigned long *_Nonnull hash)
721{
722 uint32_t tmp = (uint32_t)*hash;
723
724 tmp += tmp << 3;
725 tmp ^= tmp >> 11;
726 tmp += tmp << 15;
727
728 *hash = tmp;
729}
730
731@class OFMethodSignature;
732@class OFString;
733@class OFThread;
734
740@protocol OFObject
746- (Class)class;
747
753- (nullable Class)superclass;
754
767- (unsigned long)hash;
768
774- (unsigned int)retainCount;
775
781- (bool)isProxy;
782
789- (bool)isKindOfClass: (Class)class_;
790
798- (bool)isMemberOfClass: (Class)class_;
799
807- (bool)respondsToSelector: (SEL)selector;
808
815- (bool)conformsToProtocol: (Protocol *)protocol;
816
823- (nullable IMP)methodForSelector: (SEL)selector;
824
831- (nullable id)performSelector: (SEL)selector;
832
841- (nullable id)performSelector: (SEL)selector withObject: (nullable id)object;
842
853- (nullable id)performSelector: (SEL)selector
854 withObject: (nullable id)object1
855 withObject: (nullable id)object2;
856
869- (nullable id)performSelector: (SEL)selector
870 withObject: (nullable id)object1
871 withObject: (nullable id)object2
872 withObject: (nullable id)object3;
873
888- (nullable id)performSelector: (SEL)selector
889 withObject: (nullable id)object1
890 withObject: (nullable id)object2
891 withObject: (nullable id)object3
892 withObject: (nullable id)object4;
893
906- (bool)isEqual: (nullable id)object;
907
914- (instancetype)retain;
915
922- (void)release;
923
930- (instancetype)autorelease;
931
937- (instancetype)self;
938
945
952@end
953
959OF_ROOT_CLASS
960@interface OFObject <OFObject>
961{
962@private
963#ifndef __clang_analyzer__
964 Class _isa;
965#else
966 Class _isa __attribute__((__unused__));
967#endif
968}
969
970#ifdef OF_HAVE_CLASS_PROPERTIES
971# ifndef __cplusplus
972@property (class, readonly, nonatomic) Class class;
973# else
974@property (class, readonly, nonatomic, getter=class) Class class_;
975# endif
976@property (class, readonly, nonatomic) OFString *className;
977@property (class, readonly, nullable, nonatomic) Class superclass;
978@property (class, readonly, nonatomic) OFString *description;
979#endif
980
981#ifndef __cplusplus
982@property (readonly, nonatomic) Class class;
983#else
984@property (readonly, nonatomic, getter=class) Class class_;
985#endif
986@property OF_NULLABLE_PROPERTY (readonly, nonatomic) Class superclass;
987@property (readonly, nonatomic) unsigned long hash;
988@property (readonly, nonatomic) unsigned int retainCount;
989@property (readonly, nonatomic) bool isProxy;
990@property (readonly, nonatomic) bool allowsWeakReference;
991
995@property (readonly, nonatomic) OFString *className;
996
1003@property (readonly, nonatomic) OFString *description;
1004
1016+ (void)load;
1017
1029+ (void)unload;
1030
1040+ (void)initialize;
1041
1053+ (instancetype)alloc;
1054
1060+ (Class)class;
1067+ (OFString *)className;
1076+ (bool)isSubclassOfClass: (Class)class_;
1077
1083+ (nullable Class)superclass;
1092+ (bool)instancesRespondToSelector: (SEL)selector;
1093
1100+ (bool)conformsToProtocol: (Protocol *)protocol;
1101
1110+ (nullable IMP)instanceMethodForSelector: (SEL)selector;
1111
1121+ (nullable OFMethodSignature *)
1122 instanceMethodSignatureForSelector: (SEL)selector;
1123
1140+ (nullable IMP)replaceClassMethod: (SEL)selector
1141 withMethodFromClass: (Class)class_;
1142
1151+ (nullable IMP)replaceInstanceMethod: (SEL)selector
1152 withMethodFromClass: (Class)class_;
1153
1172+ (void)inheritMethodsFromClass: (Class)class_;
1173
1182+ (bool)resolveClassMethod: (SEL)selector;
1183
1192+ (bool)resolveInstanceMethod: (SEL)selector;
1193
1202+ (id)copy;
1203
1235- (instancetype)init;
1236
1244- (nullable OFMethodSignature *)methodSignatureForSelector: (SEL)selector;
1245
1253- (void)dealloc;
1254
1261- (void)performSelector: (SEL)selector afterDelay: (OFTimeInterval)delay;
1262
1272- (void)performSelector: (SEL)selector
1273 withObject: (nullable id)object
1274 afterDelay: (OFTimeInterval)delay;
1275
1287- (void)performSelector: (SEL)selector
1288 withObject: (nullable id)object1
1289 withObject: (nullable id)object2
1290 afterDelay: (OFTimeInterval)delay;
1291
1305- (void)performSelector: (SEL)selector
1306 withObject: (nullable id)object1
1307 withObject: (nullable id)object2
1308 withObject: (nullable id)object3
1309 afterDelay: (OFTimeInterval)delay;
1310
1326- (void)performSelector: (SEL)selector
1327 withObject: (nullable id)object1
1328 withObject: (nullable id)object2
1329 withObject: (nullable id)object3
1330 withObject: (nullable id)object4
1331 afterDelay: (OFTimeInterval)delay;
1332
1333#ifdef OF_HAVE_THREADS
1341- (void)performSelector: (SEL)selector
1342 onThread: (OFThread *)thread
1343 waitUntilDone: (bool)waitUntilDone;
1344
1355- (void)performSelector: (SEL)selector
1356 onThread: (OFThread *)thread
1357 withObject: (nullable id)object
1358 waitUntilDone: (bool)waitUntilDone;
1359
1372- (void)performSelector: (SEL)selector
1373 onThread: (OFThread *)thread
1374 withObject: (nullable id)object1
1375 withObject: (nullable id)object2
1376 waitUntilDone: (bool)waitUntilDone;
1377
1392- (void)performSelector: (SEL)selector
1393 onThread: (OFThread *)thread
1394 withObject: (nullable id)object1
1395 withObject: (nullable id)object2
1396 withObject: (nullable id)object3
1397 waitUntilDone: (bool)waitUntilDone;
1398
1415- (void)performSelector: (SEL)selector
1416 onThread: (OFThread *)thread
1417 withObject: (nullable id)object1
1418 withObject: (nullable id)object2
1419 withObject: (nullable id)object3
1420 withObject: (nullable id)object4
1421 waitUntilDone: (bool)waitUntilDone;
1422
1429- (void)performSelectorOnMainThread: (SEL)selector
1430 waitUntilDone: (bool)waitUntilDone;
1431
1441- (void)performSelectorOnMainThread: (SEL)selector
1442 withObject: (nullable id)object
1443 waitUntilDone: (bool)waitUntilDone;
1444
1456- (void)performSelectorOnMainThread: (SEL)selector
1457 withObject: (nullable id)object1
1458 withObject: (nullable id)object2
1459 waitUntilDone: (bool)waitUntilDone;
1460
1474- (void)performSelectorOnMainThread: (SEL)selector
1475 withObject: (nullable id)object1
1476 withObject: (nullable id)object2
1477 withObject: (nullable id)object3
1478 waitUntilDone: (bool)waitUntilDone;
1479
1495- (void)performSelectorOnMainThread: (SEL)selector
1496 withObject: (nullable id)object1
1497 withObject: (nullable id)object2
1498 withObject: (nullable id)object3
1499 withObject: (nullable id)object4
1500 waitUntilDone: (bool)waitUntilDone;
1501
1510- (void)performSelector: (SEL)selector
1511 onThread: (OFThread *)thread
1512 afterDelay: (OFTimeInterval)delay;
1513
1524- (void)performSelector: (SEL)selector
1525 onThread: (OFThread *)thread
1526 withObject: (nullable id)object
1527 afterDelay: (OFTimeInterval)delay;
1528
1541- (void)performSelector: (SEL)selector
1542 onThread: (OFThread *)thread
1543 withObject: (nullable id)object1
1544 withObject: (nullable id)object2
1545 afterDelay: (OFTimeInterval)delay;
1546
1561- (void)performSelector: (SEL)selector
1562 onThread: (OFThread *)thread
1563 withObject: (nullable id)object1
1564 withObject: (nullable id)object2
1565 withObject: (nullable id)object3
1566 afterDelay: (OFTimeInterval)delay;
1567
1584- (void)performSelector: (SEL)selector
1585 onThread: (OFThread *)thread
1586 withObject: (nullable id)object1
1587 withObject: (nullable id)object2
1588 withObject: (nullable id)object3
1589 withObject: (nullable id)object4
1590 afterDelay: (OFTimeInterval)delay;
1591#endif
1592
1604- (nullable id)forwardingTargetForSelector: (SEL)selector;
1605
1615- (void)doesNotRecognizeSelector: (SEL)selector OF_NO_RETURN;
1616@end
1617
1623@protocol OFCopying
1633- (id)copy;
1634@end
1635
1644@protocol OFMutableCopying
1650- (id)mutableCopy;
1651@end
1652
1661@protocol OFComparing
1668- (OFComparisonResult)compare: (id <OFComparing>)object;
1669@end
1670
1671#ifdef __cplusplus
1672extern "C" {
1673#endif
1688extern void *_Nullable OFAllocMemory(size_t count, size_t size)
1689 OF_MALLOC_FUNC OF_WARN_UNUSED_RESULT;
1690
1705extern void *_Nullable OFAllocZeroedMemory(size_t count, size_t size)
1706 OF_MALLOC_FUNC OF_WARN_UNUSED_RESULT;
1707
1725extern void *_Nullable OFResizeMemory(void *_Nullable pointer, size_t count,
1726 size_t size) OF_WARN_UNUSED_RESULT;
1727
1735extern void OFFreeMemory(void *_Nullable pointer);
1736
1737#ifdef OF_APPLE_RUNTIME
1738extern void *_Null_unspecified objc_autoreleasePoolPush(void);
1739extern void objc_autoreleasePoolPop(void *_Null_unspecified pool);
1740extern id _Nullable objc_retain(id _Nullable object);
1741extern id _Nullable objc_retainBlock(id _Nullable block);
1742extern id _Nullable objc_retainAutorelease(id _Nullable object);
1743extern void objc_release(id _Nullable object);
1744extern id _Nullable objc_autorelease(id _Nullable object);
1745extern id _Nullable objc_autoreleaseReturnValue(id _Nullable object);
1746extern id _Nullable objc_retainAutoreleaseReturnValue(id _Nullable object);
1747extern id _Nullable objc_retainAutoreleasedReturnValue(id _Nullable object);
1748extern id _Nullable objc_storeStrong(id _Nullable *_Nonnull object,
1749 id _Nullable value);
1750extern id _Nullable objc_storeWeak(id _Nullable *_Nonnull object,
1751 id _Nullable value);
1752extern id _Nullable objc_loadWeakRetained(id _Nullable *_Nonnull object);
1753extern _Nullable id objc_initWeak(id _Nullable *_Nonnull object,
1754 id _Nullable value);
1755extern void objc_destroyWeak(id _Nullable *_Nonnull object);
1756extern id _Nullable objc_loadWeak(id _Nullable *_Nonnull object);
1757extern void objc_copyWeak(id _Nullable *_Nonnull dest,
1758 id _Nullable *_Nonnull src);
1759extern void objc_moveWeak(id _Nullable *_Nonnull dest,
1760 id _Nullable *_Nonnull src);
1761# ifdef OF_DECLARE_CONSTRUCT_INSTANCE
1762extern id _Nullable objc_constructInstance(Class _Nullable class_,
1763 void *_Nullable bytes);
1764extern void *_Nullable objc_destructInstance(id _Nullable object);
1765# endif
1766# ifdef OF_DECLARE_SET_ASSOCIATED_OBJECT
1767typedef enum objc_associationPolicy {
1774extern void objc_setAssociatedObject(id _Nonnull object,
1775 const void *_Nonnull key, id _Nullable value,
1776 objc_associationPolicy policy);
1777extern id _Nullable objc_getAssociatedObject(id _Nonnull object,
1778 const void *_Nonnull key);
1779extern void objc_removeAssociatedObjects(id _Nonnull object);
1780# endif
1781#endif
1782
1795extern id OFAllocObject(Class class_, size_t extraSize, size_t extraAlignment,
1796 void *_Nullable *_Nullable extra);
1797
1820extern void OF_NO_RETURN_FUNC OFMethodNotFound(id self, SEL _cmd);
1821
1827extern void OFHashInit(unsigned long *_Nonnull hash);
1828
1834extern uint16_t OFRandom16(void);
1835
1841extern uint32_t OFRandom32(void);
1842
1848extern uint64_t OFRandom64(void);
1849#ifdef __cplusplus
1850}
1851#endif
1852
1853OF_ASSUME_NONNULL_END
1854
1855#import "OFBlock.h"
1856#import "OFObject+KeyValueCoding.h"
static OF_INLINE OFRect OF_CONST_FUNC OFMakeRect(float x, float y, float width, float height)
Creates a new OFRect.
Definition OFObject.h:366
void * OFResizeMemory(void *pointer, size_t count, size_t size)
Resizes memory to the specified number of items of the specified size.
Definition OFObject.m:138
static OF_INLINE void OFHashFinalize(unsigned long *hash)
Finalizes the specified hash.
Definition OFObject.h:720
static OF_INLINE void OFHashAddByte(unsigned long *hash, unsigned char byte)
Adds the specified byte to the hash.
Definition OFObject.h:688
static OF_INLINE OFVector4D OFMultiplyVector4D(OFVector4D vector, float scalar)
Multiplies the specified vector with a scalar.
Definition OFObject.h:646
static OF_INLINE OFVector4D OFAddVectors4D(OFVector4D vector1, OFVector4D vector2)
Adds the two specified vectors.
Definition OFObject.h:618
OFComparisonResult
A result of a comparison.
Definition OFObject.h:64
@ OFOrderedAscending
Definition OFObject.h:66
@ OFOrderedDescending
Definition OFObject.h:70
@ OFOrderedSame
Definition OFObject.h:68
static OF_INLINE OFRange OFUnionRange(OFRange range1, OFRange range2)
Returns the union of the two ranges if they are overlapping or adjacent, otherwise returns a range wi...
Definition OFObject.h:230
void OFHashInit(unsigned long *hash)
Initializes the specified hash.
Definition OFObject.m:276
static OF_INLINE size_t OFEndOfRange(OFRange range)
Returns the end of the range, which is its location + its length.
Definition OFObject.h:172
static OF_INLINE OFVector3D OFAddVectors3D(OFVector3D vector1, OFVector3D vector2)
Adds the two specified vectors.
Definition OFObject.h:489
static OF_INLINE bool OFEqualVectors4D(OFVector4D vector1, OFVector4D vector2)
Returns whether the two vectors are equal.
Definition OFObject.h:593
OFComparisonResult(^ OFComparator)(id left, id right)
A comparator to compare two objects.
Definition OFObject.h:92
static OF_INLINE float OFDotProductOfVectors4D(OFVector4D vector1, OFVector4D vector2)
Calculates the dot product of the two specified vectors.
Definition OFObject.h:660
static OF_INLINE bool OFEqualRanges(OFRange range1, OFRange range2)
Returns whether the two ranges are equal.
Definition OFObject.h:146
void * OFAllocZeroedMemory(size_t count, size_t size) OF_MALLOC_FUNC
Allocates memory for the specified number of items of the specified size and initializes it with zero...
Definition OFObject.m:119
static OF_INLINE void OFHashAddHash(unsigned long *hash, unsigned long otherHash)
Adds the specified hash to the hash.
Definition OFObject.h:706
static OF_INLINE bool OFEqualSizes(OFSize size1, OFSize size2)
Returns whether the two sizes are equal.
Definition OFObject.h:333
static OF_INLINE OFSize OF_CONST_FUNC OFMakeSize(float width, float height)
Creates a new OFSize.
Definition OFObject.h:318
uint32_t OFRandom32(void)
Returns 32 bit or non-cryptographical randomness.
Definition OFObject.m:220
void OFFreeMemory(void *pointer)
Frees memory allocated by OFAllocMemory, OFAllocZeroedMemory or OFResizeMemory.
Definition OFObject.m:156
double OFTimeInterval
A time interval in seconds.
Definition OFObject.h:250
static OF_INLINE OFRect OFIntersectionRect(OFRect rect1, OFRect rect2)
Returns the intersection of the two rectangles or a rectangle with x, y, width and height set to 0 if...
Definition OFObject.h:404
static OF_INLINE OFVector3D OFMultiplyVector3D(OFVector3D vector, float scalar)
Multiplies the specified vector with a scalar.
Definition OFObject.h:517
static OF_INLINE OFVector4D OFSubtractVectors4D(OFVector4D vector1, OFVector4D vector2)
Subtracts the second vector from the first vector.
Definition OFObject.h:632
static OF_INLINE float OFDotProductOfVectors3D(OFVector3D vector1, OFVector3D vector2)
Calculates the dot product of the two specified vectors.
Definition OFObject.h:531
static OF_INLINE bool OFLocationInRange(size_t location, OFRange range)
Returns whether the specified location is in the specified range.
Definition OFObject.h:188
static OF_INLINE float OFDistanceOfVectors4D(OFVector4D vector1, OFVector4D vector2)
Calculates the distance between two vectors.
Definition OFObject.h:674
uint64_t OFRandom64(void)
Returns 64 bit or non-cryptographical randomness.
Definition OFObject.m:246
static const size_t OFNotFound
A special not found index.
Definition OFObject.h:59
OFByteOrder
An enum for representing endianness.
Definition OFObject.h:98
@ OFByteOrderBigEndian
Definition OFObject.h:100
@ OFByteOrderLittleEndian
Definition OFObject.h:102
@ OFByteOrderNative
Definition OFObject.h:107
static OF_INLINE bool OFEqualVectors3D(OFVector3D vector1, OFVector3D vector2)
Returns whether the two vectors are equal.
Definition OFObject.h:467
static OF_INLINE OFRange OFIntersectionRange(OFRange range1, OFRange range2)
Returns the intersection of the two ranges or OFNotFound and length 0 if they don't intersect.
Definition OFObject.h:203
static OF_INLINE OFVector3D OFSubtractVectors3D(OFVector3D vector1, OFVector3D vector2)
Subtracts the second vector from the first vector.
Definition OFObject.h:503
id OFAllocObject(Class class_, size_t extraSize, size_t extraAlignment, void **extra)
Allocates a new object.
Definition OFObject.m:432
uint16_t OFRandom16(void)
Returns 16 bit or non-cryptographical randomness.
Definition OFObject.m:190
static OF_INLINE bool OFEqualPoints(OFPoint point1, OFPoint point2)
Returns whether the two points are equal.
Definition OFObject.h:287
static OF_INLINE bool OFEqualRects(OFRect rect1, OFRect rect2)
Returns whether the two rectangles are equal.
Definition OFObject.h:384
static OF_INLINE float OFDistanceOfVectors3D(OFVector3D vector1, OFVector3D vector2)
Calculates the distance between two vectors.
Definition OFObject.h:545
void * OFAllocMemory(size_t count, size_t size) OF_MALLOC_FUNC
Allocates memory for the specified number of items of the specified size.
Definition OFObject.m:101
OFComparisonResult(* OFCompareFunction)(id left, id right, void *context)
A function to compare two objects.
Definition OFObject.h:81
static OF_INLINE OFVector4D OF_CONST_FUNC OFMakeVector4D(float x, float y, float z, float w)
Creates a new OFVector4D.
Definition OFObject.h:578
void OFMethodNotFound(id self, SEL _cmd)
This function is called when a method is not found.
Definition OFObject.m:412
static OF_INLINE OFPoint OF_CONST_FUNC OFMakePoint(float x, float y)
Creates a new OFPoint.
Definition OFObject.h:272
static OF_INLINE OFRange OF_CONST_FUNC OFMakeRange(size_t start, size_t length)
Creates a new OFRange.
Definition OFObject.h:131
static OF_INLINE OFVector3D OF_CONST_FUNC OFMakeVector3D(float x, float y, float z)
Creates a new OFVector3D.
Definition OFObject.h:452
id(* IMP)(id object, SEL selector,...)
A method implementation.
Definition ObjFWRT.h:146
objc_associationPolicy
A policy for object association, see objc_setAssociatedObject.
Definition ObjFWRT.h:183
@ OBJC_ASSOCIATION_RETAIN_NONATOMIC
Associate the object like a retained, nonatomic property.
Definition ObjFWRT.h:187
@ OBJC_ASSOCIATION_COPY
Associate the object like a copied property.
Definition ObjFWRT.h:193
@ OBJC_ASSOCIATION_RETAIN
Associate the object like a retained property.
Definition ObjFWRT.h:189
@ OBJC_ASSOCIATION_ASSIGN
Associate the object like an assigned property.
Definition ObjFWRT.h:185
@ OBJC_ASSOCIATION_COPY_NONATOMIC
Associate the object like a copied, nonatomic property.
Definition ObjFWRT.h:191
A class for parsing type encodings and accessing them.
Definition OFMethodSignature.h:33
The root class for all other classes inside ObjFW.
Definition OFObject.h:962
OFString * description
A description for the object.
Definition OFObject.m:1206
OFString * className
The name of the object's class.
Definition OFObject.m:686
instancetype init()
Initializes an already allocated object.
Definition OFObject.m:671
void dealloc()
Deallocates the object.
Definition OFObject.m:1321
id copy()
Returns the class.
Definition OFObject.m:1326
void unload()
A method which is called when the class is unloaded from the runtime.
Definition OFObject.m:507
instancetype alloc()
Allocates memory for an instance of the class and sets up the memory pool for the object.
Definition OFObject.m:515
void initialize()
A method which is called the moment before the first call to the class is being made.
Definition OFObject.m:511
void load()
A method which is called once when the class is loaded into the runtime.
Definition OFObject.m:472
A class for handling strings.
Definition OFString.h:143
A class which provides portable threads.
Definition OFThread.h:66
id copy()
Copies the object.
id mutableCopy()
Creates a mutable copy of the object.
bool allowsWeakReference()
Returns whether the object allows a weak reference.
instancetype autorelease()
Adds the object to the topmost autorelease pool of the thread's autorelease pool stack.
bool isProxy()
Returns whether the object is a proxy object.
Class class()
Returns the class of the object.
unsigned int retainCount()
Returns the retain count.
unsigned long hash()
Returns a hash for the object.
nullable Class superclass()
Returns the superclass of the object.
instancetype self()
Returns the receiver.
void release()
Decreases the retain count.
instancetype retain()
Increases the retain count.
bool retainWeakReference()
Retain a weak reference to this object.
A point in 2D space.
Definition OFObject.h:257
float y
Definition OFObject.h:261
float x
Definition OFObject.h:259
A range.
Definition OFObject.h:116
size_t length
Definition OFObject.h:120
size_t location
Definition OFObject.h:118
A rectangle.
Definition OFObject.h:349
OFPoint origin
Definition OFObject.h:351
OFSize size
Definition OFObject.h:353
A size.
Definition OFObject.h:303
float width
Definition OFObject.h:305
float height
Definition OFObject.h:307
A vector in 3D space.
Definition OFObject.h:434
float x
Definition OFObject.h:436
float y
Definition OFObject.h:438
float z
Definition OFObject.h:440
A vector in 4D space.
Definition OFObject.h:557
float x
Definition OFObject.h:559
float z
Definition OFObject.h:563
float y
Definition OFObject.h:561
float w
Definition OFObject.h:565