ObjFW
Loading...
Searching...
No Matches
OFObject.h File Reference
#include "objfw-defs.h"
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <limits.h>
#include "macros.h"
import "OFOnce.h"
import "OFBlock.h"
import "OFObject+KeyValueCoding.h"

Go to the source code of this file.

Classes

struct  OFRange
 A range. More...
 
struct  OFPoint
 A point in 2D space. More...
 
struct  OFSize
 A size. More...
 
struct  OFRect
 A rectangle. More...
 
struct  OFVector3D
 A vector in 3D space. More...
 
struct  OFVector4D
 A vector in 4D space. More...
 
protocol  <OFObject>
 The protocol which all root classes implement. More...
 
class  OFObject
 The root class for all other classes inside ObjFW. More...
 
protocol  <OFCopying>
 A protocol for the creation of copies. More...
 
protocol  <OFMutableCopying>
 A protocol for the creation of mutable copies. More...
 
protocol  <OFComparing>
 A protocol for comparing objects. More...
 

Typedefs

typedef OFComparisonResult(* OFCompareFunction) (id left, id right, void *context)
 A function to compare two objects.
 
typedef OFComparisonResult(^ OFComparator) (id left, id right)
 A comparator to compare two objects.
 
typedef double OFTimeInterval
 A time interval in seconds.
 

Enumerations

enum  OFComparisonResult { OFOrderedAscending = -1 , OFOrderedSame = 0 , OFOrderedDescending = 1 }
 A result of a comparison. More...
 
enum  OFByteOrder { OFByteOrderBigEndian , OFByteOrderLittleEndian , OFByteOrderNative = OFByteOrderLittleEndian }
 An enum for representing endianness. More...
 

Functions

static OF_INLINE OFRange OF_CONST_FUNC OFMakeRange (size_t start, size_t length)
 Creates a new OFRange.
 
static OF_INLINE bool OFEqualRanges (OFRange range1, OFRange range2)
 Returns whether the two ranges are equal.
 
static OF_INLINE OFPoint OF_CONST_FUNC OFMakePoint (float x, float y)
 Creates a new OFPoint.
 
static OF_INLINE bool OFEqualPoints (OFPoint point1, OFPoint point2)
 Returns whether the two points are equal.
 
static OF_INLINE OFSize OF_CONST_FUNC OFMakeSize (float width, float height)
 Creates a new OFSize.
 
static OF_INLINE bool OFEqualSizes (OFSize size1, OFSize size2)
 Returns whether the two sizes are equal.
 
static OF_INLINE OFRect OF_CONST_FUNC OFMakeRect (float x, float y, float width, float height)
 Creates a new OFRect.
 
static OF_INLINE bool OFEqualRects (OFRect rect1, OFRect rect2)
 Returns whether the two rectangles are equal.
 
static OF_INLINE OFVector3D OF_CONST_FUNC OFMakeVector3D (float x, float y, float z)
 Creates a new OFVector3D.
 
static OF_INLINE bool OFEqualVectors3D (OFVector3D vector1, OFVector3D vector2)
 Returns whether the two vectors are equal.
 
static OF_INLINE OFVector4D OF_CONST_FUNC OFMakeVector4D (float x, float y, float z, float w)
 Creates a new OFVector4D.
 
static OF_INLINE bool OFEqualVectors4D (OFVector4D vector1, OFVector4D vector2)
 Returns whether the two vectors are equal.
 
static OF_INLINE void OFHashAddByte (unsigned long *hash, unsigned char byte)
 Adds the specified byte to the hash.
 
static OF_INLINE void OFHashAddHash (unsigned long *hash, unsigned long otherHash)
 Adds the specified hash to the hash.
 
static OF_INLINE void OFHashFinalize (unsigned long *hash)
 Finalizes the specified hash.
 
void * OFAllocMemory (size_t count, size_t size)
 Allocates memory for the specified number of items of the specified size.
 
void * OFAllocZeroedMemory (size_t count, size_t size)
 Allocates memory for the specified number of items of the specified size and initializes it with zeros.
 
void * OFResizeMemory (void *pointer, size_t count, size_t size)
 Resizes memory to the specified number of items of the specified size.
 
void OFFreeMemory (void *pointer)
 Frees memory allocated by OFAllocMemory, OFAllocZeroedMemory or OFResizeMemory.
 
id OFAllocObject (Class class_, size_t extraSize, size_t extraAlignment, void **extra)
 Allocates a new object.
 
void OFMethodNotFound (id self, SEL _cmd)
 This function is called when a method is not found.
 
void OFHashInit (unsigned long *hash)
 Initializes the specified hash.
 
uint16_t OFRandom16 (void)
 Returns 16 bit or non-cryptographical randomness.
 
uint32_t OFRandom32 (void)
 Returns 32 bit or non-cryptographical randomness.
 
uint64_t OFRandom64 (void)
 Returns 64 bit or non-cryptographical randomness.
 

Typedef Documentation

◆ OFComparator

typedef OFComparisonResult(^ OFComparator) (id left, id right)

A comparator to compare two objects.

Parameters
leftThe left object
rightThe right object
Returns
The order of the objects

◆ OFCompareFunction

typedef OFComparisonResult(* OFCompareFunction) (id left, id right, void *context)

A function to compare two objects.

Parameters
leftThe left object
rightThe right object
contextContext passed along for comparing
Returns
The order of the objects

Enumeration Type Documentation

◆ OFByteOrder

An enum for representing endianness.

Enumerator
OFByteOrderBigEndian 

Most significant byte first (big endian)

OFByteOrderLittleEndian 

Least significant byte first (little endian)

OFByteOrderNative 

Native byte order of the system

◆ OFComparisonResult

A result of a comparison.

Enumerator
OFOrderedAscending 

The left object is smaller than the right

OFOrderedSame 

Both objects are equal

OFOrderedDescending 

The left object is bigger than the right

Function Documentation

◆ OFAllocMemory()

void * OFAllocMemory ( size_t count,
size_t size )
extern

Allocates memory for the specified number of items of the specified size.

To free the allocated memory, use OFFreeMemory.

Parameters
countThe number of items to allocate
sizeThe size of each item to allocate
Returns
A pointer to the allocated memory. May return NULL if the specified size or count is 0.
Exceptions
OFOutOfMemoryExceptionThe allocation failed due to not enough memory
OFOutOfRangeExceptionThe requested count * size exceeds the address space

◆ OFAllocObject()

id OFAllocObject ( Class class_,
size_t extraSize,
size_t extraAlignment,
void ** extra )
extern

Allocates a new object.

This is useful to override alloc (OFObject) in a subclass that can then allocate extra memory in the same memory allocation.

Parameters
class_The class of which to allocate an object
extraSizeExtra space after the ivars to allocate
extraAlignmentAlignment of the extra space after the ivars
extraA pointer to set to a pointer to the extra space
Returns
The allocated object

◆ OFAllocZeroedMemory()

void * OFAllocZeroedMemory ( size_t count,
size_t size )
extern

Allocates memory for the specified number of items of the specified size and initializes it with zeros.

To free the allocated memory, use OFFreeMemory.

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.
Exceptions
OFOutOfMemoryExceptionThe allocation failed due to not enough memory
OFOutOfRangeExceptionThe requested count * size exceeds the address space

◆ OFEqualPoints()

static OF_INLINE bool OFEqualPoints ( OFPoint point1,
OFPoint point2 )
static

Returns whether the two points are equal.

Parameters
point1The first point for the comparison
point2The second point for the comparison
Returns
Whether the two points are equal

◆ OFEqualRanges()

static OF_INLINE bool OFEqualRanges ( OFRange range1,
OFRange range2 )
static

Returns whether the two ranges are equal.

Parameters
range1The first range for the comparison
range2The second range for the comparison
Returns
Whether the two ranges are equal

◆ OFEqualRects()

static OF_INLINE bool OFEqualRects ( OFRect rect1,
OFRect rect2 )
static

Returns whether the two rectangles are equal.

Parameters
rect1The first rectangle for the comparison
rect2The second rectangle for the comparison
Returns
Whether the two rectangles are equal

◆ OFEqualSizes()

static OF_INLINE bool OFEqualSizes ( OFSize size1,
OFSize size2 )
static

Returns whether the two sizes are equal.

Parameters
size1The first size for the comparison
size2The second size for the comparison
Returns
Whether the two sizes are equal

◆ OFEqualVectors3D()

static OF_INLINE bool OFEqualVectors3D ( OFVector3D vector1,
OFVector3D vector2 )
static

Returns whether the two vectors are equal.

Parameters
vector1The first vector for the comparison
vector2The second vectors for the comparison
Returns
Whether the two vectors are equal

◆ OFEqualVectors4D()

static OF_INLINE bool OFEqualVectors4D ( OFVector4D vector1,
OFVector4D vector2 )
static

Returns whether the two vectors are equal.

Parameters
vector1The first vector for the comparison
vector2The second vectors for the comparison
Returns
Whether the two vectors are equal

◆ OFFreeMemory()

void OFFreeMemory ( void * pointer)
extern

Frees memory allocated by OFAllocMemory, OFAllocZeroedMemory or OFResizeMemory.

Parameters
pointerA pointer to the memory to free or nil (passing nil does nothing)

◆ OFHashAddByte()

static OF_INLINE void OFHashAddByte ( unsigned long * hash,
unsigned char byte )
static

Adds the specified byte to the hash.

Parameters
hashA pointer to a hash to add the byte to
byteThe byte to add to the hash

◆ OFHashAddHash()

static OF_INLINE void OFHashAddHash ( unsigned long * hash,
unsigned long otherHash )
static

Adds the specified hash to the hash.

Parameters
hashA pointer to a hash to add the hash to
otherHashThe hash to add to the hash

◆ OFHashFinalize()

static OF_INLINE void OFHashFinalize ( unsigned long * hash)
static

Finalizes the specified hash.

Parameters
hashA pointer to the hash to finalize

◆ OFHashInit()

void OFHashInit ( unsigned long * hash)
extern

Initializes the specified hash.

Parameters
hashA pointer to the hash to initialize

◆ OFMakePoint()

static OF_INLINE OFPoint OF_CONST_FUNC OFMakePoint ( float x,
float y )
static

Creates a new OFPoint.

Parameters
xThe x coordinate of the point
yThe x coordinate of the point
Returns
An OFPoint with the specified coordinates

◆ OFMakeRange()

static OF_INLINE OFRange OF_CONST_FUNC OFMakeRange ( size_t start,
size_t length )
static

Creates a new OFRange.

Parameters
startThe starting index of the range
lengthThe length of the range
Returns
An OFRange with the specified start and length

◆ OFMakeRect()

static OF_INLINE OFRect OF_CONST_FUNC OFMakeRect ( float x,
float y,
float width,
float height )
static

Creates a new OFRect.

Parameters
xThe x coordinate of the top left corner of the rectangle
yThe y coordinate of the top left corner of the rectangle
widthThe width of the rectangle
heightThe height of the rectangle
Returns
An OFRect with the specified origin and size

◆ OFMakeSize()

static OF_INLINE OFSize OF_CONST_FUNC OFMakeSize ( float width,
float height )
static

Creates a new OFSize.

Parameters
widthThe width of the size
heightThe height of the size
Returns
An OFSize with the specified width and height

◆ OFMakeVector3D()

static OF_INLINE OFVector3D OF_CONST_FUNC OFMakeVector3D ( float x,
float y,
float z )
static

Creates a new OFVector3D.

Parameters
xThe x coordinate of the vector
yThe x coordinate of the vector
zThe z coordinate of the vector
Returns
An OFVector3D with the specified coordinates

◆ OFMakeVector4D()

static OF_INLINE OFVector4D OF_CONST_FUNC OFMakeVector4D ( float x,
float y,
float z,
float w )
static

Creates a new OFVector4D.

Parameters
xThe x coordinate of the vector
yThe x coordinate of the vector
zThe z coordinate of the vector
wThe w coordinate of the vector
Returns
An OFVector4D with the specified coordinates

◆ OFMethodNotFound()

void OFMethodNotFound ( id self,
SEL _cmd )
extern

This function is called when a method is not found.

It can also be called intentionally to indicate that a method is not implemetned, for example in an abstract method. However, instead of calling OFMethodNotFound directly, it is preferred to do the following:

- (void)abstractMethod
{
    OF_UNRECOGNIZED_SELECTOR
}

However, do not use this for init methods. Instead, use the following:

- (instancetype)init
{
    OF_INVALID_INIT_METHOD
}
Parameters
selfThe object which does not have the method
_cmdThe selector of the method that does not exist

◆ OFRandom16()

uint16_t OFRandom16 ( void )
extern

Returns 16 bit or non-cryptographical randomness.

Returns
16 bit or non-cryptographical randomness

◆ OFRandom32()

uint32_t OFRandom32 ( void )
extern

Returns 32 bit or non-cryptographical randomness.

Returns
32 bit or non-cryptographical randomness

◆ OFRandom64()

uint64_t OFRandom64 ( void )
extern

Returns 64 bit or non-cryptographical randomness.

Returns
64 bit or non-cryptographical randomness

◆ OFResizeMemory()

void * OFResizeMemory ( void * pointer,
size_t count,
size_t size )
extern

Resizes memory to the specified number of items of the specified size.

To free the allocated memory, use OFFreeMemory.

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
Exceptions
OFOutOfMemoryExceptionThe reallocation failed due to not enough memory
OFOutOfRangeExceptionThe requested count * size exceeds the address space