|
Objectively
Object oriented framework for C.
|
Classes describe the state and behavior of an Objectively type. More...
Go to the source code of this file.
Data Structures | |
| struct | Class |
| The runtime representation of a Class. More... | |
| struct | ClassDef |
ClassDefs are passed to _initialize via an archetype to initialize a Class. More... | |
Macros | |
| #define | alloc(type) ((type *) _alloc(_##type())) |
Allocate and initialize and instance of type. | |
| #define | cast(type, obj) ((type *) _cast(_##type(), (const ident) obj)) |
Safely cast obj to type. | |
| #define | classnameof(obj) classof(obj)->def.name |
| Resolve the Class name of the given Object instance. | |
| #define | classof(obj) ((Object *) obj)->clazz |
| Resolve the Class of an Object instance. | |
| #define | instanceof(type, obj) (isobject(obj) && $((Object *) obj, isKindOfClass, _##type())) |
| Test if the given pointer is an instance of the specified type. | |
| #define | interfaceof(type, clazz) ((type##Interface *) (clazz)->interface) |
| Resolve the typed interface of a Class. | |
| #define | isobject(obj) (obj && *((unsigned int *) obj) == OBJECTIVELY_MAGIC) |
| Test if the given pointer is an Object. | |
| #define | obj |
| #define | OBJECTIVELY_MAGIC 0xdeadbeef |
| The header value identifying Objectively types. | |
| #define | super(type, obj, method, ...) interfaceof(type, _Class()->def.superclass)->method(cast(type, obj), ## __VA_ARGS__) |
| #define | type |
Functions | |
| OBJECTIVELY_EXPORT ident | _alloc (Class *clazz) |
| Instantiate a type through the given Class. | |
| OBJECTIVELY_EXPORT ident | _cast (const Class *clazz, const ident obj) |
| Perform a type-checking cast. | |
| OBJECTIVELY_EXPORT Class * | _initialize (const ClassDef *clazz) |
| Initializes the given Class. | |
| OBJECTIVELY_EXPORT void | addClassImage (ident handle) |
| Registers an image that provides Classes, e.g. a plugin. | |
| OBJECTIVELY_EXPORT Class * | classForName (const char *name) |
| OBJECTIVELY_EXPORT ident | release (ident obj) |
Atomically decrement the given Object's reference count. If the resulting reference count is 0, the Object is deallocated. | |
| OBJECTIVELY_EXPORT void | removeClassImage (ident handle) |
| Unregisters an image, and every Class it declared. | |
| OBJECTIVELY_EXPORT ident | retain (ident obj) |
| Atomically increment the given Object's reference count. | |
Variables | |
| OBJECTIVELY_EXPORT size_t | _pageSize |
| The page size, in bytes, of the target host. | |
Classes describe the state and behavior of an Objectively type.
Definition in file Class.h.
| #define isobject | ( | obj | ) | (obj && *((unsigned int *) obj) == OBJECTIVELY_MAGIC) |
| #define obj |
| #define OBJECTIVELY_MAGIC 0xdeadbeef |
| #define super | ( | type, | |
| obj, | |||
| method, | |||
| ... | |||
| ) | interfaceof(type, _Class()->def.superclass)->method(cast(type, obj), ## __VA_ARGS__) |
| OBJECTIVELY_EXPORT ident _alloc | ( | Class * | clazz | ) |
Instantiate a type through the given Class.
Definition at line 170 of file Class.c.
| OBJECTIVELY_EXPORT ident _cast | ( | const Class * | clazz, |
| const ident | obj | ||
| ) |
| OBJECTIVELY_EXPORT Class * _initialize | ( | const ClassDef * | clazz | ) |
Initializes the given Class.
| clazz | The Class descriptor. |
Definition at line 129 of file Class.c.
| OBJECTIVELY_EXPORT void addClassImage | ( | ident | handle | ) |
Registers an image that provides Classes, e.g. a plugin.
| handle | A handle from dlopen. |
classForName resolves a name it has not yet initialized through the process-wide namespace, which holds only images loaded RTLD_GLOBAL, and which Windows does not have at all. An application that loads Classes from a plugin registers it here instead, and may then load it RTLD_LOCAL - which is how it keeps two plugins exporting the same symbols from coalescing.
Definition at line 284 of file Class.c.
| OBJECTIVELY_EXPORT Class * classForName | ( | const char * | name | ) |
Definition at line 292 of file Class.c.
| OBJECTIVELY_EXPORT ident release | ( | ident | obj | ) |
| OBJECTIVELY_EXPORT void removeClassImage | ( | ident | handle | ) |
Unregisters an image, and every Class it declared.
| handle | The handle given to addClassImage. |
classForName answers from that cache ahead of any image. On a platform where closing an image really unmaps it - which dlclose does on Linux and FreeLibrary does on Windows - the next lookup would then read a ClassDef that is no longer mapped. classForName compares the name of every Class it walks, so one left behind breaks every lookup, not only its own. dlclose does not unmap on macOS, so an archetype that has already run keeps answering from its own static Class * for as long as the process lives, and would hand back whatever this freed. Unregistering is the only thing that is safe whether the image goes away or stays: the Class becomes unreachable by name, and remains valid for the archetype that owns it. The cost is the Class and its interface, which are not reclaimed. | OBJECTIVELY_EXPORT ident retain | ( | ident | obj | ) |
| OBJECTIVELY_EXPORT size_t _pageSize |