#include "Config.h"
#include <assert.h>
#include <dlfcn.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#include "Class.h"
#include "Object.h"
Go to the source code of this file.
◆ _alloc()
Instantiate a type through the given Class.
Definition at line 128 of file Class.c.
128 {
129
132
134
135 object->clazz = clazz;
136 object->referenceCount = 1;
137
138 ident interface = clazz->interface;
139 do {
142
144}
void * ident
The identity type, similar to Objective-C id.
size_t instanceSize
The instance size (required).
ptrdiff_t interfaceOffset
The interface offset (required).
Class * superclass
The superclass (required). e.g. _Object().
ClassDef def
The Class definition.
Object is the root Class of The Objectively Class hierarchy.
◆ _cast()
Perform a type-checking cast.
Definition at line 146 of file Class.c.
146 {
147
150 while (c) {
151
152
153 if (c == clazz || clazz ==
_Object()) {
154 break;
155 }
156
158 }
159 assert(c);
160 }
161
163}
The runtime representation of a Class.
Class * _Object(void)
The Object archetype.
◆ _initialize()
Initializes the given Class.
- Parameters
-
clazz | The Class descriptor. |
- Returns
- The initialized Class.
Definition at line 91 of file Class.c.
91 {
92
95
96 assert(def);
101
103 assert(clazz);
104
106
109
111 if (superclass) {
112
115
117 }
118
121 }
122
123 clazz->
next = __sync_lock_test_and_set(&
_classes, clazz);
124
125 return clazz;
126}
#define do_once(once, block)
Executes the given block at most one time.
size_t interfaceSize
The interface size (required).
const char * name
The Class name (required).
void(* initialize)(Class *clazz)
The Class initializer (optional).
Class * next
Provides chaining of initialized Classes.
ident interface
The interface of the Class.
void setup(URLSessionTask *)
Sets up this task.
◆ classForName()
Class * classForName |
( |
const char * |
name | ) |
|
- Returns
- The Class with the given name, or
NULL
if no such Class has been initialized.
Definition at line 165 of file Class.c.
165 {
166
167 if (name) {
169 while (c) {
170 if (strcmp(name, c->
def.
name) == 0) {
171 return c;
172 }
174 }
175
176 char *s;
177 if (asprintf(&s, "_%s", name) > 0) {
179
181
184 if (archetype) {
185 clazz = archetype();
186 }
187
188 free(s);
189 return clazz;
190 }
191 }
192
193 return NULL;
194}
◆ release()
Atomically decrement the given Object's reference count. If the resulting reference count is 0
, the Object is deallocated.
- Returns
- This function always returns
NULL
.
Definition at line 196 of file Class.c.
196 {
197
200
201 assert(object);
202
203 if (__sync_add_and_fetch(&object->referenceCount, -1) == 0) {
205 }
206 }
207
208 return NULL;
209}
#define cast(type, obj)
Safely cast obj to type.
void dealloc(Object *self)
Frees all resources held by this Object.
◆ retain()
Atomically increment the given Object's reference count.
- Returns
- The Object.
Definition at line 211 of file Class.c.
211 {
212
214
215 assert(object);
216
217 __sync_add_and_fetch(&object->referenceCount, 1);
218
220}
◆ setup()
static void setup |
( |
void |
| ) |
|
|
static |
Called when initializing Object
to setup Objectively.
Definition at line 78 of file Class.c.
78 {
79
81
82#if !defined(_SC_PAGESIZE)
84#else
86#endif
87
89}
void teardown(URLSessionTask *)
Tears down this task.
◆ teardown()
static void teardown |
( |
void |
| ) |
|
|
static |
Called atexit
to teardown Objectively.
Definition at line 47 of file Class.c.
47 {
49
51 while (c) {
54 }
55
57 }
58
60 while (c) {
61
63
65 free(c);
66
68 }
69
72 }
73}
void(* destroy)(Class *clazz)
The Class destructor (optional). This method is run for initialized Classes when your application exi...
Unicode next(StringReader *self)
◆ _classes
◆ _handle
◆ _pageSize