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
163static OF_INLINE size_t
165{
166 if (range.length > SIZE_MAX - range.location) {
167 extern void OF_NO_RETURN_FUNC _OFThrowOutOfRangeException(void);
168 _OFThrowOutOfRangeException();
169 }
170
171 return range.location + range.length;
172}
173
181static OF_INLINE bool
182OFLocationInRange(size_t location, OFRange range)
183{
184 return (location >= range.location &&
185 location < OFEndOfRange(range));
186}
187
196static OF_INLINE OFRange
198{
199 OFRange range;
200
201 if (range1.location >= OFEndOfRange(range2) ||
202 range2.location >= OFEndOfRange(range1))
203 return OFMakeRange(OFNotFound, 0);
204
205 range.location = (range1.location > range2.location
206 ? range1.location : range2.location);
207 range.length = (OFEndOfRange(range1) < OFEndOfRange(range2))
208 ? OFEndOfRange(range1) - range.location
209 : OFEndOfRange(range2) - range.location;
210
211 return range;
212}
213
223static OF_INLINE OFRange
225{
226 OFRange range;
227
228 if (range1.location > OFEndOfRange(range2) ||
229 range2.location > OFEndOfRange(range1))
230 return OFMakeRange(OFNotFound, 0);
231
232 range.location = (range1.location < range2.location
233 ? range1.location : range2.location);
234 range.length = (OFEndOfRange(range1) > OFEndOfRange(range2))
235 ? OFEndOfRange(range1) - range.location
236 : OFEndOfRange(range2) - range.location;
237
238 return range;
239}
240
244typedef double OFTimeInterval;
245
251typedef struct OF_BOXABLE OFPoint {
253 float x;
255 float y;
256} OFPoint;
257
265static OF_INLINE OFPoint OF_CONST_FUNC
266OFMakePoint(float x, float y)
267{
268 OFPoint point = { x, y };
269
270 return point;
271}
272
280static OF_INLINE bool
282{
283 if (point1.x != point2.x)
284 return false;
285
286 if (point1.y != point2.y)
287 return false;
288
289 return true;
290}
291
297typedef struct OF_BOXABLE OFSize {
299 float width;
301 float height;
302} OFSize;
303
311static OF_INLINE OFSize OF_CONST_FUNC
312OFMakeSize(float width, float height)
313{
314 OFSize size = { width, height };
315
316 return size;
317}
318
326static OF_INLINE bool
328{
329 if (size1.width != size2.width)
330 return false;
331
332 if (size1.height != size2.height)
333 return false;
334
335 return true;
336}
337
343typedef struct OF_BOXABLE OFRect {
348} OFRect;
349
359static OF_INLINE OFRect OF_CONST_FUNC
360OFMakeRect(float x, float y, float width, float height)
361{
362 OFRect rect = {
363 OFMakePoint(x, y),
364 OFMakeSize(width, height)
365 };
366
367 return rect;
368}
369
377static OF_INLINE bool
379{
380 if (!OFEqualPoints(rect1.origin, rect2.origin))
381 return false;
382
383 if (!OFEqualSizes(rect1.size, rect2.size))
384 return false;
385
386 return true;
387}
388
394typedef struct OF_BOXABLE OFVector3D {
396 float x;
398 float y;
400 float z;
401} OFVector3D;
402
411static OF_INLINE OFVector3D OF_CONST_FUNC
412OFMakeVector3D(float x, float y, float z)
413{
414 OFVector3D vector = { x, y, z };
415
416 return vector;
417}
418
426static OF_INLINE bool
428{
429 if (vector1.x != vector2.x)
430 return false;
431
432 if (vector1.y != vector2.y)
433 return false;
434
435 if (vector1.z != vector2.z)
436 return false;
437
438 return true;
439}
440
448static OF_INLINE OFVector3D
450{
451 return OFMakeVector3D(vector1.x + vector2.x, vector1.y + vector2.y,
452 vector1.z + vector2.z);
453}
454
462static OF_INLINE OFVector3D
464{
465 return OFMakeVector3D(vector1.x - vector2.x, vector1.y - vector2.y,
466 vector1.z - vector2.z);
467}
468
476static OF_INLINE OFVector3D
477OFMultiplyVector3D(OFVector3D vector, float scalar)
478{
479 return OFMakeVector3D(vector.x * scalar, vector.y * scalar,
480 vector.z * scalar);
481}
482
490static OF_INLINE float
492{
493 return vector1.x * vector2.x + vector1.y * vector2.y +
494 vector1.z * vector2.z;
495}
496
504static OF_INLINE float
506{
507 OFVector3D difference = OFSubtractVectors3D(vector1, vector2);
508
509 return sqrtf(OFDotProductOfVectors3D(difference, difference));
510}
511
517typedef struct OF_BOXABLE OFVector4D {
519 float x;
521 float y;
523 float z;
525 float w;
526} OFVector4D;
527
537static OF_INLINE OFVector4D OF_CONST_FUNC
538OFMakeVector4D(float x, float y, float z, float w)
539{
540 OFVector4D vector = { x, y, z, w };
541
542 return vector;
543}
544
552static OF_INLINE bool
554{
555 if (vector1.x != vector2.x)
556 return false;
557
558 if (vector1.y != vector2.y)
559 return false;
560
561 if (vector1.z != vector2.z)
562 return false;
563
564 if (vector1.w != vector2.w)
565 return false;
566
567 return true;
568}
569
577static OF_INLINE OFVector4D
579{
580 return OFMakeVector4D(vector1.x + vector2.x, vector1.y + vector2.y,
581 vector1.z + vector2.z, vector1.w + vector2.w);
582}
583
591static OF_INLINE OFVector4D
593{
594 return OFMakeVector4D(vector1.x - vector2.x, vector1.y - vector2.y,
595 vector1.z - vector2.z, vector1.w - vector2.w);
596}
597
605static OF_INLINE OFVector4D
606OFMultiplyVector4D(OFVector4D vector, float scalar)
607{
608 return OFMakeVector4D(vector.x * scalar, vector.y * scalar,
609 vector.z * scalar, vector.w * scalar);
610}
611
619static OF_INLINE float
621{
622 return vector1.x * vector2.x + vector1.y * vector2.y +
623 vector1.z * vector2.z + vector1.w * vector2.w;
624}
625
633static OF_INLINE float
635{
636 OFVector4D difference = OFSubtractVectors4D(vector1, vector2);
637
638 return sqrtf(OFDotProductOfVectors4D(difference, difference));
639}
640
647static OF_INLINE void
648OFHashAddByte(unsigned long *_Nonnull hash, unsigned char byte)
649{
650 uint32_t tmp = (uint32_t)*hash;
651
652 tmp += byte;
653 tmp += tmp << 10;
654 tmp ^= tmp >> 6;
655
656 *hash = tmp;
657}
658
665static OF_INLINE void
666OFHashAddHash(unsigned long *_Nonnull hash, unsigned long otherHash)
667{
668 OFHashAddByte(hash, (otherHash >> 24) & 0xFF);
669 OFHashAddByte(hash, (otherHash >> 16) & 0xFF);
670 OFHashAddByte(hash, (otherHash >> 8) & 0xFF);
671 OFHashAddByte(hash, otherHash & 0xFF);
672}
673
679static OF_INLINE void
680OFHashFinalize(unsigned long *_Nonnull hash)
681{
682 uint32_t tmp = (uint32_t)*hash;
683
684 tmp += tmp << 3;
685 tmp ^= tmp >> 11;
686 tmp += tmp << 15;
687
688 *hash = tmp;
689}
690
691@class OFMethodSignature;
692@class OFString;
693@class OFThread;
694
700@protocol OFObject
706- (Class)class;
707
713- (nullable Class)superclass;
714
727- (unsigned long)hash;
728
734- (unsigned int)retainCount;
735
741- (bool)isProxy;
742
749- (bool)isKindOfClass: (Class)class_;
750
758- (bool)isMemberOfClass: (Class)class_;
759
767- (bool)respondsToSelector: (SEL)selector;
768
775- (bool)conformsToProtocol: (Protocol *)protocol;
776
783- (nullable IMP)methodForSelector: (SEL)selector;
784
791- (nullable id)performSelector: (SEL)selector;
792
801- (nullable id)performSelector: (SEL)selector withObject: (nullable id)object;
802
813- (nullable id)performSelector: (SEL)selector
814 withObject: (nullable id)object1
815 withObject: (nullable id)object2;
816
829- (nullable id)performSelector: (SEL)selector
830 withObject: (nullable id)object1
831 withObject: (nullable id)object2
832 withObject: (nullable id)object3;
833
848- (nullable id)performSelector: (SEL)selector
849 withObject: (nullable id)object1
850 withObject: (nullable id)object2
851 withObject: (nullable id)object3
852 withObject: (nullable id)object4;
853
866- (bool)isEqual: (nullable id)object;
867
874- (instancetype)retain;
875
882- (void)release;
883
890- (instancetype)autorelease;
891
897- (instancetype)self;
898
905
912@end
913
919OF_ROOT_CLASS
920@interface OFObject <OFObject>
921{
922@private
923#ifndef __clang_analyzer__
924 Class _isa;
925#else
926 Class _isa __attribute__((__unused__));
927#endif
928}
929
930#ifdef OF_HAVE_CLASS_PROPERTIES
931# ifndef __cplusplus
932@property (class, readonly, nonatomic) Class class;
933# else
934@property (class, readonly, nonatomic, getter=class) Class class_;
935# endif
936@property (class, readonly, nonatomic) OFString *className;
937@property (class, readonly, nullable, nonatomic) Class superclass;
938@property (class, readonly, nonatomic) OFString *description;
939#endif
940
941#ifndef __cplusplus
942@property (readonly, nonatomic) Class class;
943#else
944@property (readonly, nonatomic, getter=class) Class class_;
945#endif
946@property OF_NULLABLE_PROPERTY (readonly, nonatomic) Class superclass;
947@property (readonly, nonatomic) unsigned long hash;
948@property (readonly, nonatomic) unsigned int retainCount;
949@property (readonly, nonatomic) bool isProxy;
950@property (readonly, nonatomic) bool allowsWeakReference;
951
955@property (readonly, nonatomic) OFString *className;
956
963@property (readonly, nonatomic) OFString *description;
964
976+ (void)load;
977
989+ (void)unload;
990
1000+ (void)initialize;
1001
1013+ (instancetype)alloc;
1014
1020+ (Class)class;
1027+ (OFString *)className;
1036+ (bool)isSubclassOfClass: (Class)class_;
1037
1043+ (nullable Class)superclass;
1052+ (bool)instancesRespondToSelector: (SEL)selector;
1053
1060+ (bool)conformsToProtocol: (Protocol *)protocol;
1061
1070+ (nullable IMP)instanceMethodForSelector: (SEL)selector;
1071
1081+ (nullable OFMethodSignature *)
1082 instanceMethodSignatureForSelector: (SEL)selector;
1083
1100+ (nullable IMP)replaceClassMethod: (SEL)selector
1101 withMethodFromClass: (Class)class_;
1102
1111+ (nullable IMP)replaceInstanceMethod: (SEL)selector
1112 withMethodFromClass: (Class)class_;
1113
1132+ (void)inheritMethodsFromClass: (Class)class_;
1133
1142+ (bool)resolveClassMethod: (SEL)selector;
1143
1152+ (bool)resolveInstanceMethod: (SEL)selector;
1153
1162+ (id)copy;
1163
1195- (instancetype)init;
1196
1204- (nullable OFMethodSignature *)methodSignatureForSelector: (SEL)selector;
1205
1213- (void)dealloc;
1214
1221- (void)performSelector: (SEL)selector afterDelay: (OFTimeInterval)delay;
1222
1232- (void)performSelector: (SEL)selector
1233 withObject: (nullable id)object
1234 afterDelay: (OFTimeInterval)delay;
1235
1247- (void)performSelector: (SEL)selector
1248 withObject: (nullable id)object1
1249 withObject: (nullable id)object2
1250 afterDelay: (OFTimeInterval)delay;
1251
1265- (void)performSelector: (SEL)selector
1266 withObject: (nullable id)object1
1267 withObject: (nullable id)object2
1268 withObject: (nullable id)object3
1269 afterDelay: (OFTimeInterval)delay;
1270
1286- (void)performSelector: (SEL)selector
1287 withObject: (nullable id)object1
1288 withObject: (nullable id)object2
1289 withObject: (nullable id)object3
1290 withObject: (nullable id)object4
1291 afterDelay: (OFTimeInterval)delay;
1292
1293#ifdef OF_HAVE_THREADS
1301- (void)performSelector: (SEL)selector
1302 onThread: (OFThread *)thread
1303 waitUntilDone: (bool)waitUntilDone;
1304
1315- (void)performSelector: (SEL)selector
1316 onThread: (OFThread *)thread
1317 withObject: (nullable id)object
1318 waitUntilDone: (bool)waitUntilDone;
1319
1332- (void)performSelector: (SEL)selector
1333 onThread: (OFThread *)thread
1334 withObject: (nullable id)object1
1335 withObject: (nullable id)object2
1336 waitUntilDone: (bool)waitUntilDone;
1337
1352- (void)performSelector: (SEL)selector
1353 onThread: (OFThread *)thread
1354 withObject: (nullable id)object1
1355 withObject: (nullable id)object2
1356 withObject: (nullable id)object3
1357 waitUntilDone: (bool)waitUntilDone;
1358
1375- (void)performSelector: (SEL)selector
1376 onThread: (OFThread *)thread
1377 withObject: (nullable id)object1
1378 withObject: (nullable id)object2
1379 withObject: (nullable id)object3
1380 withObject: (nullable id)object4
1381 waitUntilDone: (bool)waitUntilDone;
1382
1389- (void)performSelectorOnMainThread: (SEL)selector
1390 waitUntilDone: (bool)waitUntilDone;
1391
1401- (void)performSelectorOnMainThread: (SEL)selector
1402 withObject: (nullable id)object
1403 waitUntilDone: (bool)waitUntilDone;
1404
1416- (void)performSelectorOnMainThread: (SEL)selector
1417 withObject: (nullable id)object1
1418 withObject: (nullable id)object2
1419 waitUntilDone: (bool)waitUntilDone;
1420
1434- (void)performSelectorOnMainThread: (SEL)selector
1435 withObject: (nullable id)object1
1436 withObject: (nullable id)object2
1437 withObject: (nullable id)object3
1438 waitUntilDone: (bool)waitUntilDone;
1439
1455- (void)performSelectorOnMainThread: (SEL)selector
1456 withObject: (nullable id)object1
1457 withObject: (nullable id)object2
1458 withObject: (nullable id)object3
1459 withObject: (nullable id)object4
1460 waitUntilDone: (bool)waitUntilDone;
1461
1470- (void)performSelector: (SEL)selector
1471 onThread: (OFThread *)thread
1472 afterDelay: (OFTimeInterval)delay;
1473
1484- (void)performSelector: (SEL)selector
1485 onThread: (OFThread *)thread
1486 withObject: (nullable id)object
1487 afterDelay: (OFTimeInterval)delay;
1488
1501- (void)performSelector: (SEL)selector
1502 onThread: (OFThread *)thread
1503 withObject: (nullable id)object1
1504 withObject: (nullable id)object2
1505 afterDelay: (OFTimeInterval)delay;
1506
1521- (void)performSelector: (SEL)selector
1522 onThread: (OFThread *)thread
1523 withObject: (nullable id)object1
1524 withObject: (nullable id)object2
1525 withObject: (nullable id)object3
1526 afterDelay: (OFTimeInterval)delay;
1527
1544- (void)performSelector: (SEL)selector
1545 onThread: (OFThread *)thread
1546 withObject: (nullable id)object1
1547 withObject: (nullable id)object2
1548 withObject: (nullable id)object3
1549 withObject: (nullable id)object4
1550 afterDelay: (OFTimeInterval)delay;
1551#endif
1552
1564- (nullable id)forwardingTargetForSelector: (SEL)selector;
1565
1575- (void)doesNotRecognizeSelector: (SEL)selector OF_NO_RETURN;
1576@end
1577
1583@protocol OFCopying
1593- (id)copy;
1594@end
1595
1604@protocol OFMutableCopying
1610- (id)mutableCopy;
1611@end
1612
1621@protocol OFComparing
1628- (OFComparisonResult)compare: (id <OFComparing>)object;
1629@end
1630
1631#ifdef __cplusplus
1632extern "C" {
1633#endif
1648extern void *_Nullable OFAllocMemory(size_t count, size_t size)
1649 OF_MALLOC_FUNC OF_WARN_UNUSED_RESULT;
1650
1665extern void *_Nullable OFAllocZeroedMemory(size_t count, size_t size)
1666 OF_MALLOC_FUNC OF_WARN_UNUSED_RESULT;
1667
1685extern void *_Nullable OFResizeMemory(void *_Nullable pointer, size_t count,
1686 size_t size) OF_WARN_UNUSED_RESULT;
1687
1695extern void OFFreeMemory(void *_Nullable pointer);
1696
1697#ifdef OF_APPLE_RUNTIME
1698extern void *_Null_unspecified objc_autoreleasePoolPush(void);
1699extern void objc_autoreleasePoolPop(void *_Null_unspecified pool);
1700extern id _Nullable objc_retain(id _Nullable object);
1701extern id _Nullable objc_retainBlock(id _Nullable block);
1702extern id _Nullable objc_retainAutorelease(id _Nullable object);
1703extern void objc_release(id _Nullable object);
1704extern id _Nullable objc_autorelease(id _Nullable object);
1705extern id _Nullable objc_autoreleaseReturnValue(id _Nullable object);
1706extern id _Nullable objc_retainAutoreleaseReturnValue(id _Nullable object);
1707extern id _Nullable objc_retainAutoreleasedReturnValue(id _Nullable object);
1708extern id _Nullable objc_storeStrong(id _Nullable *_Nonnull object,
1709 id _Nullable value);
1710extern id _Nullable objc_storeWeak(id _Nullable *_Nonnull object,
1711 id _Nullable value);
1712extern id _Nullable objc_loadWeakRetained(id _Nullable *_Nonnull object);
1713extern _Nullable id objc_initWeak(id _Nullable *_Nonnull object,
1714 id _Nullable value);
1715extern void objc_destroyWeak(id _Nullable *_Nonnull object);
1716extern id _Nullable objc_loadWeak(id _Nullable *_Nonnull object);
1717extern void objc_copyWeak(id _Nullable *_Nonnull dest,
1718 id _Nullable *_Nonnull src);
1719extern void objc_moveWeak(id _Nullable *_Nonnull dest,
1720 id _Nullable *_Nonnull src);
1721# ifdef OF_DECLARE_CONSTRUCT_INSTANCE
1722extern id _Nullable objc_constructInstance(Class _Nullable class_,
1723 void *_Nullable bytes);
1724extern void *_Nullable objc_destructInstance(id _Nullable object);
1725# endif
1726# ifdef OF_DECLARE_SET_ASSOCIATED_OBJECT
1727typedef enum objc_associationPolicy {
1734extern void objc_setAssociatedObject(id _Nonnull object,
1735 const void *_Nonnull key, id _Nullable value,
1736 objc_associationPolicy policy);
1737extern id _Nullable objc_getAssociatedObject(id _Nonnull object,
1738 const void *_Nonnull key);
1739extern void objc_removeAssociatedObjects(id _Nonnull object);
1740# endif
1741#endif
1742
1755extern id OFAllocObject(Class class_, size_t extraSize, size_t extraAlignment,
1756 void *_Nullable *_Nullable extra);
1757
1780extern void OF_NO_RETURN_FUNC OFMethodNotFound(id self, SEL _cmd);
1781
1787extern void OFHashInit(unsigned long *_Nonnull hash);
1788
1794extern uint16_t OFRandom16(void);
1795
1801extern uint32_t OFRandom32(void);
1802
1808extern uint64_t OFRandom64(void);
1809#ifdef __cplusplus
1810}
1811#endif
1812
1813OF_ASSUME_NONNULL_END
1814
1815#import "OFBlock.h"
1816#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:360
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:680
static OF_INLINE void OFHashAddByte(unsigned long *hash, unsigned char byte)
Adds the specified byte to the hash.
Definition OFObject.h:648
static OF_INLINE OFVector4D OFMultiplyVector4D(OFVector4D vector, float scalar)
Multiplies the specified vector with a scalar.
Definition OFObject.h:606
static OF_INLINE OFVector4D OFAddVectors4D(OFVector4D vector1, OFVector4D vector2)
Adds the two specified vectors.
Definition OFObject.h:578
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:224
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:164
static OF_INLINE OFVector3D OFAddVectors3D(OFVector3D vector1, OFVector3D vector2)
Adds the two specified vectors.
Definition OFObject.h:449
static OF_INLINE bool OFEqualVectors4D(OFVector4D vector1, OFVector4D vector2)
Returns whether the two vectors are equal.
Definition OFObject.h:553
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:620
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:666
static OF_INLINE bool OFEqualSizes(OFSize size1, OFSize size2)
Returns whether the two sizes are equal.
Definition OFObject.h:327
static OF_INLINE OFSize OF_CONST_FUNC OFMakeSize(float width, float height)
Creates a new OFSize.
Definition OFObject.h:312
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:244
static OF_INLINE OFVector3D OFMultiplyVector3D(OFVector3D vector, float scalar)
Multiplies the specified vector with a scalar.
Definition OFObject.h:477
static OF_INLINE OFVector4D OFSubtractVectors4D(OFVector4D vector1, OFVector4D vector2)
Subtracts the second vector from the first vector.
Definition OFObject.h:592
static OF_INLINE float OFDotProductOfVectors3D(OFVector3D vector1, OFVector3D vector2)
Calculates the dot product of the two specified vectors.
Definition OFObject.h:491
static OF_INLINE bool OFLocationInRange(size_t location, OFRange range)
Returns whether the specified location is in the specified range.
Definition OFObject.h:182
static OF_INLINE float OFDistanceOfVectors4D(OFVector4D vector1, OFVector4D vector2)
Calculates the distance between two vectors.
Definition OFObject.h:634
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:427
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:197
static OF_INLINE OFVector3D OFSubtractVectors3D(OFVector3D vector1, OFVector3D vector2)
Subtracts the second vector from the first vector.
Definition OFObject.h:463
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:281
static OF_INLINE bool OFEqualRects(OFRect rect1, OFRect rect2)
Returns whether the two rectangles are equal.
Definition OFObject.h:378
static OF_INLINE float OFDistanceOfVectors3D(OFVector3D vector1, OFVector3D vector2)
Calculates the distance between two vectors.
Definition OFObject.h:505
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:538
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:266
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:412
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:922
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:251
float y
Definition OFObject.h:255
float x
Definition OFObject.h:253
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:343
OFPoint origin
Definition OFObject.h:345
OFSize size
Definition OFObject.h:347
A size.
Definition OFObject.h:297
float width
Definition OFObject.h:299
float height
Definition OFObject.h:301
A vector in 3D space.
Definition OFObject.h:394
float x
Definition OFObject.h:396
float y
Definition OFObject.h:398
float z
Definition OFObject.h:400
A vector in 4D space.
Definition OFObject.h:517
float x
Definition OFObject.h:519
float z
Definition OFObject.h:523
float y
Definition OFObject.h:521
float w
Definition OFObject.h:525