ObjFW
 All Classes Functions Variables
OFObject.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012
3  * Jonathan Schleifer <js@webkeks.org>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #import "objfw-defs.h"
18 
19 #ifndef __STDC_LIMIT_MACROS
20 # define __STDC_LIMIT_MACROS
21 #endif
22 #ifndef __STDC_CONSTANT_MACROS
23 # define __STDC_CONSTANT_MACROS
24 #endif
25 
26 #include <stddef.h>
27 #include <stdint.h>
28 #include <limits.h>
29 
30 #ifdef OF_OBJFW_RUNTIME
31 # import "runtime.h"
32 #else
33 # import <objc/objc.h>
34 #endif
35 
36 #ifdef OF_APPLE_RUNTIME
37 # import <objc/runtime.h>
38 #endif
39 
40 #if defined(__GNUC__)
41 # define restrict __restrict__
42 #elif __STDC_VERSION__ < 199901L
43 # define restrict
44 #endif
45 
46 #ifndef __has_feature
47 # define __has_feature(x) 0
48 #endif
49 
50 #ifdef __GNUC__
51 # define __GCC_VERSION__ (__GNUC__ * 100 + __GNUC_MINOR__)
52 #else
53 # define __GCC_VERSION__ 0
54 #endif
55 
56 #if defined(__clang__)
57 # define OF_HAVE_PROPERTIES
58 # define OF_HAVE_OPTIONAL_PROTOCOLS
59 # define OF_HAVE_FAST_ENUMERATION
60 #elif __GCC_VERSION__ >= 406
61 # define OF_HAVE_PROPERTIES
62 # define OF_HAVE_OPTIONAL_PROTOCOLS
63 # define OF_HAVE_FAST_ENUMERATION
64 #endif
65 
66 #if !__has_feature(objc_instancetype)
67 # define instancetype id
68 #endif
69 
70 #if __has_feature(blocks)
71 # define OF_HAVE_BLOCKS
72 #endif
73 
74 #if __has_feature(objc_bool)
75 # undef YES
76 # define YES __objc_yes
77 # undef NO
78 # define NO __objc_no
79 #endif
80 
81 #if defined(__clang__) || __GCC_VERSION__ >= 406
82 # define OF_SENTINEL __attribute__((sentinel))
83 #else
84 # define OF_SENTINEL
85 #endif
86 
87 #if __has_feature(objc_arc)
88 # define OF_RETURNS_RETAINED __attribute__((ns_returns_retained))
89 # define OF_RETURNS_NOT_RETAINED __attribute__((ns_returns_not_retained))
90 # define OF_RETURNS_INNER_POINTER __attribute__((objc_returns_inner_pointer))
91 # define OF_CONSUMED __attribute__((ns_consumed))
92 # define OF_WEAK_UNAVAILABLE __attribute__((objc_arc_weak_unavailable))
93 #else
94 # define OF_RETURNS_RETAINED
95 # define OF_RETURNS_NOT_RETAINED
96 # define OF_RETURNS_INNER_POINTER
97 # define OF_CONSUMED
98 # define OF_WEAK_UNAVAILABLE
99 # define __unsafe_unretained
100 # define __bridge
101 # define __autoreleasing
102 #endif
103 
104 #define OF_RETAIN_COUNT_MAX UINT_MAX
105 #define OF_NOT_FOUND SIZE_MAX
106 
110 typedef enum of_comparison_result_t {
112  OF_ORDERED_ASCENDING = -1,
114  OF_ORDERED_SAME = 0,
116  OF_ORDERED_DESCENDING = 1
117 } of_comparison_result_t;
118 
122 typedef enum of_byte_order_t {
124  OF_BYTE_ORDER_BIG_ENDIAN,
126  OF_BYTE_ORDER_LITTLE_ENDIAN
127 } of_byte_order_t;
128 
132 typedef struct of_range_t {
134  size_t location;
136  size_t length;
137 } of_range_t;
138 
142 typedef struct of_point_t {
144  float x;
146  float y;
147 } of_point_t;
148 
152 typedef struct of_dimension_t {
154  float width;
156  float height;
158 
162 typedef struct of_rectangle_t
163 {
169 
170 @class OFString;
171 @class OFThread;
172 
176 @protocol OFObject
182 - (Class)class;
183 
190 - (BOOL)isKindOfClass: (Class)class_;
191 
199 - (BOOL)isMemberOfClass: (Class)class_;
200 
208 - (BOOL)respondsToSelector: (SEL)selector;
209 
216 - (BOOL)conformsToProtocol: (Protocol*)protocol;
217 
224 - (IMP)methodForSelector: (SEL)selector;
225 
232 - (const char*)typeEncodingForSelector: (SEL)selector;
233 
240 - (id)performSelector: (SEL)selector;
241 
250 - (id)performSelector: (SEL)selector
251  withObject: (id)object;
252 
263 - (id)performSelector: (SEL)selector
264  withObject: (id)object1
265  withObject: (id)object2;
266 
276 - (BOOL)isEqual: (id)object;
277 
286 - (uint32_t)hash;
287 
294 - retain;
295 
301 - (unsigned int)retainCount;
302 
309 - (void)release;
310 
317 - autorelease;
318 
324 - self;
325 
331 - (BOOL)isProxy;
332 @end
333 
337 @interface OFObject <OFObject>
338 {
339 @public
340  Class isa;
341 }
342 
350 + (void)load;
351 
361 + (void)initialize;
362 
372 + alloc;
373 
378 + new;
379 
385 + (Class)class;
386 
392 + (OFString*)className;
393 
401 + (BOOL)isSubclassOfClass: (Class)class_;
402 
408 + (Class)superclass;
409 
417 + (BOOL)instancesRespondToSelector: (SEL)selector;
418 
425 + (BOOL)conformsToProtocol: (Protocol*)protocol;
426 
435 + (IMP)instanceMethodForSelector: (SEL)selector;
436 
444 + (const char*)typeEncodingForInstanceSelector: (SEL)selector;
445 
454 
462 + (IMP)replaceClassMethod: (SEL)selector
463  withMethodFromClass: (Class)class_;
464 
473 + (IMP)replaceInstanceMethod: (SEL)selector
474  withMethodFromClass: (Class)class_;
475 
488 + (IMP)replaceClassMethod: (SEL)selector
489  withImplementation: (IMP)implementation
490  typeEncoding: (const char*)typeEncoding;
491 
504 + (IMP)replaceInstanceMethod: (SEL)selector
505  withImplementation: (IMP)implementation
506  typeEncoding: (const char*)typeEncoding;
507 
526 + (void)inheritMethodsFromClass: (Class)class_;
527 
536 + (BOOL)resolveClassMethod: (SEL)selector;
537 
546 + (BOOL)resolveInstanceMethod: (SEL)selector;
547 
561 - init;
562 
568 - (OFString*)className;
569 
578 
587 - (void*)allocMemoryWithSize: (size_t)size;
588 
599 - (void*)allocMemoryWithSize: (size_t)size
600  count: (size_t)count;
601 
612 - (void*)resizeMemory: (void*)pointer
613  size: (size_t)size;
614 
627 - (void*)resizeMemory: (void*)pointer
628  size: (size_t)size
629  count: (size_t)count;
630 
638 - (void)freeMemory: (void*)pointer;
639 
647 - (void)dealloc;
648 
655 - (void)performSelector: (SEL)selector
656  afterDelay: (double)delay;
657 
667 - (void)performSelector: (SEL)selector
668  withObject: (id)object
669  afterDelay: (double)delay;
670 
682 - (void)performSelector: (SEL)selector
683  withObject: (id)object1
684  withObject: (id)object2
685  afterDelay: (double)delay;
686 
694 - (void)performSelector: (SEL)selector
695  onThread: (OFThread*)thread
696  waitUntilDone: (BOOL)waitUntilDone;
697 
708 - (void)performSelector: (SEL)selector
709  onThread: (OFThread*)thread
710  withObject: (id)object
711  waitUntilDone: (BOOL)waitUntilDone;
712 
725 - (void)performSelector: (SEL)selector
726  onThread: (OFThread*)thread
727  withObject: (id)object1
728  withObject: (id)object2
729  waitUntilDone: (BOOL)waitUntilDone;
730 
737 - (void)performSelectorOnMainThread: (SEL)selector
738  waitUntilDone: (BOOL)waitUntilDone;
739 
749 - (void)performSelectorOnMainThread: (SEL)selector
750  withObject: (id)object
751  waitUntilDone: (BOOL)waitUntilDone;
752 
764 - (void)performSelectorOnMainThread: (SEL)selector
765  withObject: (id)object1
766  withObject: (id)object2
767  waitUntilDone: (BOOL)waitUntilDone;
768 
777 - (void)performSelector: (SEL)selector
778  onThread: (OFThread*)thread
779  afterDelay: (double)delay;
780 
791 - (void)performSelector: (SEL)selector
792  onThread: (OFThread*)thread
793  withObject: (id)object
794  afterDelay: (double)delay;
795 
808 - (void)performSelector: (SEL)selector
809  onThread: (OFThread*)thread
810  withObject: (id)object1
811  withObject: (id)object2
812  afterDelay: (double)delay;
813 @end
814 
818 @protocol OFCopying
828 - copy;
829 @end
830 
837 @protocol OFMutableCopying
843 - mutableCopy;
844 @end
845 
851 @protocol OFComparing <OFObject>
858 - (of_comparison_result_t)compare: (id <OFComparing>)object;
859 @end
860 
861 #import "OFObject+Serialization.h"
862 
863 #ifdef __cplusplus
864 extern "C" {
865 #endif
866 extern size_t of_pagesize;
867 extern size_t of_num_cpus;
868 extern id of_alloc_object(Class class_, size_t extraSize, size_t extraAlignment,
869  void **extra);
870 #ifdef __cplusplus
871 }
872 #endif