ObjFW
Instance Methods | Class Methods | List of all members
OFObject Class Reference

The root class for all other classes inside ObjFW. More...

#import <ObjFW/OFObject.h>

Inheritance diagram for OFObject:
<OFObject> OFAllocFailedException OFApplication OFArray OFAutoreleasePool OFBlock OFData OFDate OFDictionary OFEnumerator OFException OFFileManager OFHMAC OFHTTPClient OFHTTPCookie OFHTTPCookieManager OFHTTPRequest OFHTTPServer OFINICategory OFINIFile OFInstanceVariable OFIntrospection OFKernelEventObserver OFList OFLocalization OFMapTable OFMapTableEnumerator OFMD5Hash OFMessagePackExtension OFMethod OFMutex OFNull OFNumber OFOptionsParser OFPlugin OFProperty OFRecursiveMutex OFRIPEMD160Hash OFRunLoop OFSandbox OFSet OFSettings OFSHA1Hash OFSHA224Or256Hash OFSHA384Or512Hash OFStream OFString OFSystemInfo OFTarArchive OFThread OFThreadPool OFTimer OFUDPSocket OFURL OFXMLElementBuilder OFXMLNode OFXMLParser OFZIPArchive OFZIPArchiveEntry

Instance Methods

(id) - init
 Initializes an already allocated object. More...
 
(OFString *) - className
 Returns the name of the object's class. More...
 
(OFString *) - description
 Returns a description for the object. More...
 
(nullable void *) - allocMemoryWithSize:
 Allocates memory and stores it in the object's memory pool. More...
 
(nullable void *) - allocMemoryWithSize:count:
 Allocates memory for the specified number of items and stores it in the object's memory pool. More...
 
(nullable void *) - resizeMemory:size:
 Resizes memory in the object's memory pool to the specified size. More...
 
(nullable void *) - resizeMemory:size:count:
 Resizes memory in the object's memory pool to the specific number of items of the specified size. More...
 
(void) - freeMemory:
 Frees allocated memory and removes it from the object's memory pool. More...
 
(void) - dealloc
 Deallocates the object. More...
 
(void) - performSelector:afterDelay:
 Performs the specified selector after the specified delay. More...
 
(void) - performSelector:withObject:afterDelay:
 Performs the specified selector with the specified object after the specified delay. More...
 
(void) - performSelector:withObject:withObject:afterDelay:
 Performs the specified selector with the specified objects after the specified delay. More...
 
(void) - performSelector:onThread:waitUntilDone:
 Performs the specified selector on the specified thread. More...
 
(void) - performSelector:onThread:withObject:waitUntilDone:
 Performs the specified selector on the specified thread with the specified object. More...
 
(void) - performSelector:onThread:withObject:withObject:waitUntilDone:
 Performs the specified selector on the specified thread with the specified objects. More...
 
(void) - performSelectorOnMainThread:waitUntilDone:
 Performs the specified selector on the main thread. More...
 
(void) - performSelectorOnMainThread:withObject:waitUntilDone:
 Performs the specified selector on the main thread with the specified object. More...
 
(void) - performSelectorOnMainThread:withObject:withObject:waitUntilDone:
 Performs the specified selector on the main thread with the specified objects. More...
 
(void) - performSelector:onThread:afterDelay:
 Performs the specified selector on the specified thread after the specified delay. More...
 
(void) - performSelector:onThread:withObject:afterDelay:
 Performs the specified selector on the specified thread with the specified object after the specified delay. More...
 
(void) - performSelector:onThread:withObject:withObject:afterDelay:
 Performs the specified selector on the specified thread with the specified objects after the specified delay. More...
 
(nullable id) - forwardingTargetForSelector:
 This method is called when resolveClassMethod: or resolveInstanceMethod: returned false. It should return a target to which the message should be forwarded. More...
 
(void) - doesNotRecognizeSelector:
 Handles messages which are not understood by the receiver. More...
 
(OFString *) - stringBySerializing
 Creates a string by serializing the receiver. More...
 
- Instance Methods inherited from <OFObject>
(bool) - isKindOfClass:
 Returns a boolean whether the object of the specified kind. More...
 
(bool) - isMemberOfClass:
 Returns a boolean whether the object is a member of the specified class. More...
 
(bool) - respondsToSelector:
 Returns a boolean whether the object responds to the specified selector. More...
 
(nullable IMP) - methodForSelector:
 Returns the implementation for the specified selector. More...
 
(nullable const char *) - typeEncodingForSelector:
 Returns the type encoding for the specified selector. More...
 
(nullable id) - performSelector:
 Performs the specified selector. More...
 
(nullable id) - performSelector:withObject:
 Performs the specified selector with the specified object. More...
 
(nullable id) - performSelector:withObject:withObject:
 Performs the specified selector with the specified objects. More...
 
(bool) - isEqual:
 Checks two objects for equality. More...
 
(uint32_t) - hash
 Calculates a hash for the object. More...
 
(id) - retain
 Increases the retain count. More...
 
(unsigned int) - retainCount
 Returns the retain count. More...
 
(void) - release
 Decreases the retain count. More...
 
(id) - autorelease
 Adds the object to the topmost OFAutoreleasePool of the thread's autorelease pool stack. More...
 
(id) - self
 Returns the receiver. More...
 
(bool) - isProxy
 Returns whether the object is a proxy object. More...
 
(bool) - allowsWeakReference
 Returns whether the class allows weak references. More...
 
(bool) - retainWeakReference
 Retain a weak reference to this object. More...
 

Class Methods

(void) + load
 A method which is called once when the class is loaded into the runtime. More...
 
(void) + unload
 A method which is called when the class is unloaded from the runtime. More...
 
(void) + initialize
 A method which is called the moment before the first call to the class is being made. More...
 
(id) + alloc
 Allocates memory for an instance of the class and sets up the memory pool for the object. More...
 
(id) + new
 Allocates memory for a new instance and calls init on it. More...
 
(Class) + class
 Returns the class. More...
 
(OFString *) + className
 Returns the name of the class as a string. More...
 
(bool) + isSubclassOfClass:
 Returns a boolean whether the class is a subclass of the specified class. More...
 
(nullable Class) + superclass
 Returns the superclass of the class. More...
 
(bool) + instancesRespondToSelector:
 Checks whether instances of the class respond to a given selector. More...
 
(bool) + conformsToProtocol:
 Checks whether the class conforms to a given protocol. More...
 
(nullable IMP) + instanceMethodForSelector:
 Returns the implementation of the instance method for the specified selector. More...
 
(nullable const char *) + typeEncodingForInstanceSelector:
 Returns the type encoding of the instance method for the specified selector. More...
 
(OFString *) + description
 Returns a description for the class, which is usually the class name. More...
 
(nullable IMP) + replaceClassMethod:withMethodFromClass:
 Replaces a class method with a class method from another class. More...
 
(nullable IMP) + replaceInstanceMethod:withMethodFromClass:
 Replaces an instance method with an instance method from another class. More...
 
(nullable IMP) + replaceClassMethod:withImplementation:typeEncoding:
 Replaces or adds a class method. More...
 
(nullable IMP) + replaceInstanceMethod:withImplementation:typeEncoding:
 Replaces or adds an instance method. More...
 
(void) + inheritMethodsFromClass:
 Adds all methods from the specified class to the class that is the receiver. More...
 
(BOOL) + resolveClassMethod:
 Try to resolve the specified class method. More...
 
(BOOL) + resolveInstanceMethod:
 Try to resolve the specified instance method. More...
 
(id) + copy
 Returns the class. More...
 

Detailed Description

The root class for all other classes inside ObjFW.

Method Documentation

◆ alloc()

+ (id) alloc

Allocates memory for an instance of the class and sets up the memory pool for the object.

This method will never return nil, instead, it will throw an OFAllocFailedException.

Returns
The allocated object

◆ allocMemoryWithSize:()

- (void *) allocMemoryWithSize: (size_t)  size

Allocates memory and stores it in the object's memory pool.

It will be freed automatically when the object is deallocated.

Parameters
sizeThe size of the memory to allocate
Returns
A pointer to the allocated memory. May return NULL if the specified size is 0.

◆ allocMemoryWithSize:count:()

- (void *) allocMemoryWithSize: (size_t)  size
count: (size_t)  count 

Allocates memory for the specified number of items and stores it in the object's memory pool.

It will be freed automatically when the object is deallocated.

Parameters
sizeThe size of each item to allocate
countThe number of items to allocate
Returns
A pointer to the allocated memory. May return NULL if the specified size or count is 0.

◆ class()

+ (Class) class

Returns the class.

Returns
The class

Reimplemented from <OFObject>.

◆ className() [1/2]

- (OFString *) className

Returns the name of the object's class.

Returns
The name of the object's class

◆ className() [2/2]

+ (OFString *) className

Returns the name of the class as a string.

Returns
The name of the class as a string

◆ conformsToProtocol:()

+ (bool) conformsToProtocol: (Protocol *)  protocol

Checks whether the class conforms to a given protocol.

Parameters
protocolThe protocol which should be checked for conformance
Returns
A boolean whether the class conforms to the specified protocol

Reimplemented from <OFObject>.

◆ copy()

+ (id) copy

Returns the class.

This method exists so that classes can be used in collections requiring conformance to the OFCopying protocol.

Returns
The class of the object

◆ dealloc()

- (void) dealloc

Deallocates the object.

It is automatically called when the retain count reaches zero.

This also frees all memory in its memory pool.

◆ description() [1/2]

- (OFString *) description

Returns a description for the object.

This is mostly for debugging purposes.

Returns
A description for the object

Reimplemented in OFException, and OFAllocFailedException.

◆ description() [2/2]

+ (OFString *) description

Returns a description for the class, which is usually the class name.

This is mostly for debugging purposes.

Returns
A description for the class, which is usually the class name

Reimplemented in OFException, and OFAllocFailedException.

◆ doesNotRecognizeSelector:()

- (void) doesNotRecognizeSelector: (SEL)  selector

Handles messages which are not understood by the receiver.

Warning
If you override this method, you must make sure that it never returns!
Parameters
selectorThe selector not understood by the receiver

◆ forwardingTargetForSelector:()

- (id) forwardingTargetForSelector: (SEL)  selector

This method is called when resolveClassMethod: or resolveInstanceMethod: returned false. It should return a target to which the message should be forwarded.

Note
When the message should not be forwarded, you should not return nil, but instead return the result of [super forwardingTargetForSelector: selector].
Returns
The target to forward the message to

◆ freeMemory:()

- (void) freeMemory: (nullable void *)  pointer

Frees allocated memory and removes it from the object's memory pool.

Does nothing if the pointer is NULL.

Parameters
pointerA pointer to the allocated memory

◆ inheritMethodsFromClass:()

+ (void) inheritMethodsFromClass: (Class)  class_

Adds all methods from the specified class to the class that is the receiver.

Methods implemented by the receiving class itself will not be overridden, however methods implemented by its superclass will. Therefore it behaves similar as if the specified class is the superclass of the receiver.

All methods from the superclasses of the specified class will also be added.

If the specified class is a superclass of the receiving class, nothing is done.

The methods which will be added from the specified class are not allowed to use super or access instance variables, instead they have to use accessors.

Parameters
class_The class from which the instance methods should be inherited

◆ init()

- (id) init

Initializes an already allocated object.

Derived classes may override this, but need to do

self = [super init]

before they do any initialization themselves. init may never return nil, instead an exception (for example OFInitializationFailedException) should be thrown.

Returns
An initialized object

Reimplemented in OFLocalization, OFMutableURL, and OFMutableData.

◆ initialize()

+ (void) initialize

A method which is called the moment before the first call to the class is being made.

Derived classes can override this to execute their own code on initialization. They should make sure to not execute any code if self is not the class itself, as it might happen that the method was called for a subclass which did not override this method.

◆ instanceMethodForSelector:()

+ (IMP) instanceMethodForSelector: (SEL)  selector

Returns the implementation of the instance method for the specified selector.

Parameters
selectorThe selector for which the method should be returned
Returns
The implementation of the instance method for the specified selector or nil if it isn't implemented

◆ instancesRespondToSelector:()

+ (bool) instancesRespondToSelector: (SEL)  selector

Checks whether instances of the class respond to a given selector.

Parameters
selectorThe selector which should be checked for respondence
Returns
A boolean whether instances of the class respond to the specified selector

◆ isSubclassOfClass:()

+ (bool) isSubclassOfClass: (Class)  class_

Returns a boolean whether the class is a subclass of the specified class.

Parameters
class_The class which is checked for being a superclass
Returns
A boolean whether the class is a subclass of the specified class

◆ load()

+ (void) load

A method which is called once when the class is loaded into the runtime.

Derived classes can override this to execute their own code when the class is loaded.

◆ new()

+ (id) new

Allocates memory for a new instance and calls init on it.

Returns
An allocated and initialized object

◆ performSelector:afterDelay:()

- (void) performSelector: (SEL)  selector
afterDelay: (of_time_interval_t delay 

Performs the specified selector after the specified delay.

Parameters
selectorThe selector to perform
delayThe delay after which the selector will be performed

◆ performSelector:onThread:afterDelay:()

- (void) performSelector: (SEL)  selector
onThread: (OFThread *)  thread
afterDelay: (of_time_interval_t delay 

Performs the specified selector on the specified thread after the specified delay.

Parameters
selectorThe selector to perform
threadThe thread on which to perform the selector
delayThe delay after which the selector will be performed

◆ performSelector:onThread:waitUntilDone:()

- (void) performSelector: (SEL)  selector
onThread: (OFThread *)  thread
waitUntilDone: (bool)  waitUntilDone 

Performs the specified selector on the specified thread.

Parameters
selectorThe selector to perform
threadThe thread on which to perform the selector
waitUntilDoneWhether to wait until the perform finished

◆ performSelector:onThread:withObject:afterDelay:()

- (void) performSelector: (SEL)  selector
onThread: (OFThread *)  thread
withObject: (nullable id)  object
afterDelay: (of_time_interval_t delay 

Performs the specified selector on the specified thread with the specified object after the specified delay.

Parameters
selectorThe selector to perform
threadThe thread on which to perform the selector
objectThe object that is passed to the method specified by the selector
delayThe delay after which the selector will be performed

◆ performSelector:onThread:withObject:waitUntilDone:()

- (void) performSelector: (SEL)  selector
onThread: (OFThread *)  thread
withObject: (nullable id)  object
waitUntilDone: (bool)  waitUntilDone 

Performs the specified selector on the specified thread with the specified object.

Parameters
selectorThe selector to perform
threadThe thread on which to perform the selector
objectThe object that is passed to the method specified by the selector
waitUntilDoneWhether to wait until the perform finished

◆ performSelector:onThread:withObject:withObject:afterDelay:()

- (void) performSelector: (SEL)  selector
onThread: (OFThread *)  thread
withObject: (nullable id)  object1
withObject: (nullable id)  object2
afterDelay: (of_time_interval_t delay 

Performs the specified selector on the specified thread with the specified objects after the specified delay.

Parameters
selectorThe selector to perform
threadThe thread on which to perform the selector
object1The first object that is passed to the method specified by the selector
object2The second object that is passed to the method specified by the selector
delayThe delay after which the selector will be performed

◆ performSelector:onThread:withObject:withObject:waitUntilDone:()

- (void) performSelector: (SEL)  selector
onThread: (OFThread *)  thread
withObject: (nullable id)  object1
withObject: (nullable id)  object2
waitUntilDone: (bool)  waitUntilDone 

Performs the specified selector on the specified thread with the specified objects.

Parameters
selectorThe selector to perform
threadThe thread on which to perform the selector
object1The first object that is passed to the method specified by the selector
object2The second object that is passed to the method specified by the selector
waitUntilDoneWhether to wait until the perform finished

◆ performSelector:withObject:afterDelay:()

- (void) performSelector: (SEL)  selector
withObject: (nullable id)  object
afterDelay: (of_time_interval_t delay 

Performs the specified selector with the specified object after the specified delay.

Parameters
selectorThe selector to perform
objectThe object that is passed to the method specified by the selector
delayThe delay after which the selector will be performed

◆ performSelector:withObject:withObject:afterDelay:()

- (void) performSelector: (SEL)  selector
withObject: (nullable id)  object1
withObject: (nullable id)  object2
afterDelay: (of_time_interval_t delay 

Performs the specified selector with the specified objects after the specified delay.

Parameters
selectorThe selector to perform
object1The first object that is passed to the method specified by the selector
object2The second object that is passed to the method specified by the selector
delayThe delay after which the selector will be performed

◆ performSelectorOnMainThread:waitUntilDone:()

- (void) performSelectorOnMainThread: (SEL)  selector
waitUntilDone: (bool)  waitUntilDone 

Performs the specified selector on the main thread.

Parameters
selectorThe selector to perform
waitUntilDoneWhether to wait until the perform finished

◆ performSelectorOnMainThread:withObject:waitUntilDone:()

- (void) performSelectorOnMainThread: (SEL)  selector
withObject: (nullable id)  object
waitUntilDone: (bool)  waitUntilDone 

Performs the specified selector on the main thread with the specified object.

Parameters
selectorThe selector to perform
objectThe object that is passed to the method specified by the selector
waitUntilDoneWhether to wait until the perform finished

◆ performSelectorOnMainThread:withObject:withObject:waitUntilDone:()

- (void) performSelectorOnMainThread: (SEL)  selector
withObject: (nullable id)  object1
withObject: (nullable id)  object2
waitUntilDone: (bool)  waitUntilDone 

Performs the specified selector on the main thread with the specified objects.

Parameters
selectorThe selector to perform
object1The first object that is passed to the method specified by the selector
object2The second object that is passed to the method specified by the selector
waitUntilDoneWhether to wait until the perform finished

◆ replaceClassMethod:withImplementation:typeEncoding:()

+ (IMP) replaceClassMethod: (SEL)  selector
withImplementation: (IMP)  implementation
typeEncoding: (const char *)  typeEncoding 

Replaces or adds a class method.

If the method already exists, it is replaced and the old implementation returned. If the method does not exist, it is added with the specified type encoding.

Parameters
selectorThe selector for the new method
implementationThe implementation for the new method
typeEncodingThe type encoding for the new method
Returns
The old implementation or nil if the method was added

◆ replaceClassMethod:withMethodFromClass:()

+ (IMP) replaceClassMethod: (SEL)  selector
withMethodFromClass: (Class)  class_ 

Replaces a class method with a class method from another class.

Parameters
selectorThe selector of the class method to replace
class_The class from which the new class method should be taken
Returns
The old implementation

◆ replaceInstanceMethod:withImplementation:typeEncoding:()

+ (IMP) replaceInstanceMethod: (SEL)  selector
withImplementation: (IMP)  implementation
typeEncoding: (const char *)  typeEncoding 

Replaces or adds an instance method.

If the method already exists, it is replaced and the old implementation returned. If the method does not exist, it is added with the specified type encoding.

Parameters
selectorThe selector for the new method
implementationThe implementation for the new method
typeEncodingThe type encoding for the new method
Returns
The old implementation or nil if the method was added

◆ replaceInstanceMethod:withMethodFromClass:()

+ (IMP) replaceInstanceMethod: (SEL)  selector
withMethodFromClass: (Class)  class_ 

Replaces an instance method with an instance method from another class.

Parameters
selectorThe selector of the instance method to replace
class_The class from which the new instance method should be taken
Returns
The old implementation

◆ resizeMemory:size:()

- (nullable void *) resizeMemory: (nullable void *)  pointer
size: (size_t)  size 

Resizes memory in the object's memory pool to the specified size.

If the pointer is NULL, this is equivalent to allocating memory. If the size is 0, this is equivalent to freeing memory.

Parameters
pointerA pointer to the already allocated memory
sizeThe new size for the memory chunk
Returns
A pointer to the resized memory chunk

◆ resizeMemory:size:count:()

- (nullable void *) resizeMemory: (nullable void *)  pointer
size: (size_t)  size
count: (size_t)  count 

Resizes memory in the object's memory pool to the specific number of items of the specified size.

If the pointer is NULL, this is equivalent to allocating memory. If the size or number of items is 0, this is equivalent to freeing memory.

Parameters
pointerA pointer to the already allocated memory
sizeThe size of each item to resize to
countThe number of items to resize to
Returns
A pointer to the resized memory chunk

◆ resolveClassMethod:()

+ (BOOL) resolveClassMethod: (SEL)  selector

Try to resolve the specified class method.

This method is called if a class method was not found, so that an implementation can be provided at runtime.

Returns
Whether the method has been added to the class

◆ resolveInstanceMethod:()

+ (BOOL) resolveInstanceMethod: (SEL)  selector

Try to resolve the specified instance method.

This method is called if an instance method was not found, so that an implementation can be provided at runtime.

Returns
Whether the method has been added to the class

◆ stringBySerializing()

- (OFString *) stringBySerializing

Creates a string by serializing the receiver.

Returns
The object serialized as a string

◆ superclass()

+ (Class) superclass

Returns the superclass of the class.

Returns
The superclass of the class

Reimplemented from <OFObject>.

◆ typeEncodingForInstanceSelector:()

+ (const char *) typeEncodingForInstanceSelector: (SEL)  selector

Returns the type encoding of the instance method for the specified selector.

Parameters
selectorThe selector for which the type encoding should be returned
Returns
The type encoding of the instance method for the specified selector

◆ unload()

+ (void) unload

A method which is called when the class is unloaded from the runtime.

Derived classes can override this to execute their own code when the class is unloaded.

Warning
This is not supported by the Apple runtime and currently only called by the ObjFW runtime when objc_unregister_class() or objc_exit() has been called! In the future, this might also be called by the ObjFW runtime when the class is part of a plugin that has been unloaded.

The documentation for this class was generated from the following files: