ObjFW
OFIntrospection.h
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
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 "OFObject.h"
18 
19 OF_ASSUME_NONNULL_BEGIN
20 
21 @class OFString;
22 #ifndef DOXYGEN
23 @class OFArray OF_GENERIC(ObjectType);
24 @class OFMutableArray OF_GENERIC(ObjectType);
25 #endif
26 
27 enum {
28  OF_PROPERTY_READONLY = 0x01,
29  OF_PROPERTY_ASSIGN = 0x04,
30  OF_PROPERTY_READWRITE = 0x08,
31  OF_PROPERTY_RETAIN = 0x10,
32  OF_PROPERTY_COPY = 0x20,
33  OF_PROPERTY_NONATOMIC = 0x40,
34  OF_PROPERTY_SYNTHESIZED = 0x100,
35  OF_PROPERTY_DYNAMIC = 0x200,
36  OF_PROPERTY_ATOMIC = 0x400,
37  OF_PROPERTY_WEAK = 0x800
38 };
39 
45 @interface OFMethod: OFObject
46 {
47  SEL _selector;
48  OFString *_name;
49  const char *_typeEncoding;
50 }
51 
52 #ifdef OF_HAVE_PROPERTIES
53 @property (readonly) SEL selector;
54 @property (readonly, copy) OFString *name;
55 @property OF_NULLABLE_PROPERTY (assign, readonly) const char *typeEncoding;
56 #endif
57 
63 - (SEL)selector;
64 
70 - (OFString*)name;
71 
77 - (nullable const char*)typeEncoding;
78 @end
79 
85 @interface OFProperty: OFObject
86 {
87  OFString *_name;
88  unsigned _attributes;
89  OFString *_getter, *_setter;
90 }
91 
92 #ifdef OF_HAVE_PROPERTIES
93 @property (readonly, copy) OFString *name;
94 @property (readonly) unsigned attributes;
95 @property OF_NULLABLE_PROPERTY (copy, readonly) OFString *getter, *setter;
96 #endif
97 
103 - (OFString*)name;
104 
124 - (unsigned)attributes;
125 
131 - (nullable OFString*)getter;
132 
138 - (nullable OFString*)setter;
139 @end
140 
147 {
148  OFString *_name;
149  const char *_typeEncoding;
150  ptrdiff_t _offset;
151 }
152 
153 #ifdef OF_HAVE_PROPERTIES
154 @property (readonly, copy) OFString *name;
155 @property (readonly) ptrdiff_t offset;
156 @property OF_NULLABLE_PROPERTY (assign, readonly) const char *typeEncoding;
157 #endif
158 
164 - (OFString*)name;
165 
171 - (ptrdiff_t)offset;
172 
178 - (nullable const char*)typeEncoding;
179 @end
180 
187 {
188  OFMutableArray OF_GENERIC(OFMethod*) *_classMethods;
189  OFMutableArray OF_GENERIC(OFMethod*) *_instanceMethods;
190  OFMutableArray OF_GENERIC(OFProperty*) *_properties;
191  OFMutableArray OF_GENERIC(OFInstanceVariable*) *_instanceVariables;
192 }
193 
194 #ifdef OF_HAVE_PROPERTIES
195 @property (readonly, copy) OFArray OF_GENERIC(OFMethod*) *classMethods;
196 @property (readonly, copy) OFArray OF_GENERIC(OFMethod*) *instanceMethods;
197 @property (readonly, copy) OFArray OF_GENERIC(OFProperty*) *properties;
198 @property (readonly, copy)
199  OFArray OF_GENERIC(OFInstanceVariable*) *instanceVariables;
200 #endif
201 
207 + (instancetype)introspectionWithClass: (Class)class_;
208 
215 - initWithClass: (Class)class_;
216 
222 - (OFArray OF_GENERIC(OFMethod*)*)classMethods;
223 
229 - (OFArray OF_GENERIC(OFMethod*)*)instanceMethods;
230 
253 - (OFArray OF_GENERIC(OFProperty*)*)properties;
254 
260 - (OFArray OF_GENERIC(OFInstanceVariable*)*)instanceVariables;
261 
262 /* TODO: protocols */
263 @end
264 
265 OF_ASSUME_NONNULL_END
An abstract class for storing objects in an array.
Definition: OFArray.h:95
The root class for all other classes inside ObjFW.
Definition: OFObject.h:364
A class for describing a method.
Definition: OFIntrospection.h:45
A class for introspecting classes.
Definition: OFIntrospection.h:186
An abstract class for storing, adding and removing objects in an array.
Definition: OFMutableArray.h:46
A class for describing an instance variable.
Definition: OFIntrospection.h:146
A class for handling strings.
Definition: OFString.h:91
A class for describing a property.
Definition: OFIntrospection.h:85