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 {
123  OF_BYTE_ORDER_BIG_ENDIAN,
124  OF_BYTE_ORDER_LITTLE_ENDIAN
125 } of_byte_order_t;
126 
130 typedef struct of_range_t {
132  size_t location;
134  size_t length;
135 } of_range_t;
136 
140 typedef struct of_point_t {
141  float x;
142  float y;
143 } of_point_t;
144 
148 typedef struct of_dimension_t {
149  float width;
150  float height;
152 
156 typedef struct of_rectangle_t
157 {
158  of_point_t origin;
159  of_dimension_t size;
161 
162 @class OFString;
163 @class OFThread;
164 
168 @protocol OFObject
174 - (Class)class;
175 
182 - (BOOL)isKindOfClass: (Class)class_;
183 
191 - (BOOL)isMemberOfClass: (Class)class_;
192 
200 - (BOOL)respondsToSelector: (SEL)selector;
201 
208 - (BOOL)conformsToProtocol: (Protocol*)protocol;
209 
216 - (IMP)methodForSelector: (SEL)selector;
217 
224 - (const char*)typeEncodingForSelector: (SEL)selector;
225 
232 - (id)performSelector: (SEL)selector;
233 
242 - (id)performSelector: (SEL)selector
243  withObject: (id)object;
244 
255 - (id)performSelector: (SEL)selector
256  withObject: (id)object1
257  withObject: (id)object2;
258 
268 - (BOOL)isEqual: (id)object;
269 
278 - (uint32_t)hash;
279 
286 - retain;
287 
293 - (unsigned int)retainCount;
294 
301 - (void)release;
302 
309 - autorelease;
310 
316 - self;
317 
323 - (BOOL)isProxy;
324 @end
325 
329 @interface OFObject <OFObject>
330 {
331 @public
333  Class isa;
334 }
335 
343 + (void)load;
344 
354 + (void)initialize;
355 
365 + alloc;
366 
371 + new;
372 
378 + (Class)class;
379 
385 + (OFString*)className;
386 
394 + (BOOL)isSubclassOfClass: (Class)class_;
395 
401 + (Class)superclass;
402 
410 + (BOOL)instancesRespondToSelector: (SEL)selector;
411 
418 + (BOOL)conformsToProtocol: (Protocol*)protocol;
419 
428 + (IMP)instanceMethodForSelector: (SEL)selector;
429 
437 + (const char*)typeEncodingForInstanceSelector: (SEL)selector;
438 
447 
455 + (IMP)replaceClassMethod: (SEL)selector
456  withMethodFromClass: (Class)class_;
457 
466 + (IMP)replaceInstanceMethod: (SEL)selector
467  withMethodFromClass: (Class)class_;
468 
481 + (IMP)replaceClassMethod: (SEL)selector
482  withImplementation: (IMP)implementation
483  typeEncoding: (const char*)typeEncoding;
484 
497 + (IMP)replaceInstanceMethod: (SEL)selector
498  withImplementation: (IMP)implementation
499  typeEncoding: (const char*)typeEncoding;
500 
519 + (void)inheritMethodsFromClass: (Class)class_;
520 
529 + (BOOL)resolveClassMethod: (SEL)selector;
530 
539 + (BOOL)resolveInstanceMethod: (SEL)selector;
540 
550 - init;
551 
557 - (OFString*)className;
558 
567 
576 - (void*)allocMemoryWithSize: (size_t)size;
577 
588 - (void*)allocMemoryWithSize: (size_t)size
589  count: (size_t)count;
590 
601 - (void*)resizeMemory: (void*)pointer
602  size: (size_t)size;
603 
616 - (void*)resizeMemory: (void*)pointer
617  size: (size_t)size
618  count: (size_t)count;
619 
627 - (void)freeMemory: (void*)pointer;
628 
636 - (void)dealloc;
637 
644 - (void)performSelector: (SEL)selector
645  afterDelay: (double)delay;
646 
656 - (void)performSelector: (SEL)selector
657  withObject: (id)object
658  afterDelay: (double)delay;
659 
671 - (void)performSelector: (SEL)selector
672  withObject: (id)object1
673  withObject: (id)object2
674  afterDelay: (double)delay;
675 
683 - (void)performSelector: (SEL)selector
684  onThread: (OFThread*)thread
685  waitUntilDone: (BOOL)waitUntilDone;
686 
697 - (void)performSelector: (SEL)selector
698  onThread: (OFThread*)thread
699  withObject: (id)object
700  waitUntilDone: (BOOL)waitUntilDone;
701 
714 - (void)performSelector: (SEL)selector
715  onThread: (OFThread*)thread
716  withObject: (id)object1
717  withObject: (id)object2
718  waitUntilDone: (BOOL)waitUntilDone;
719 
726 - (void)performSelectorOnMainThread: (SEL)selector
727  waitUntilDone: (BOOL)waitUntilDone;
728 
738 - (void)performSelectorOnMainThread: (SEL)selector
739  withObject: (id)object
740  waitUntilDone: (BOOL)waitUntilDone;
741 
753 - (void)performSelectorOnMainThread: (SEL)selector
754  withObject: (id)object1
755  withObject: (id)object2
756  waitUntilDone: (BOOL)waitUntilDone;
757 
766 - (void)performSelector: (SEL)selector
767  onThread: (OFThread*)thread
768  afterDelay: (double)delay;
769 
780 - (void)performSelector: (SEL)selector
781  onThread: (OFThread*)thread
782  withObject: (id)object
783  afterDelay: (double)delay;
784 
797 - (void)performSelector: (SEL)selector
798  onThread: (OFThread*)thread
799  withObject: (id)object1
800  withObject: (id)object2
801  afterDelay: (double)delay;
802 @end
803 
807 @protocol OFCopying
817 - copy;
818 @end
819 
826 @protocol OFMutableCopying
832 - mutableCopy;
833 @end
834 
840 @protocol OFComparing <OFObject>
847 - (of_comparison_result_t)compare: (id <OFComparing>)object;
848 @end
849 
850 #import "OFObject+Serialization.h"
851 
852 #ifdef __cplusplus
853 extern "C" {
854 #endif
855 extern size_t of_pagesize;
856 extern size_t of_num_cpus;
857 extern id of_alloc_object(Class class_, size_t extraSize, size_t extraAlignment,
858  void **extra);
859 #ifdef __cplusplus
860 }
861 #endif