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 <math.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 size_t OFEndOfRange (OFRange range)
 Returns the end of the range, which is its location + its length.
static OF_INLINE bool OFLocationInRange (size_t location, OFRange range)
 Returns whether the specified location is in the specified range.
static OF_INLINE OFRange OFIntersectionRange (OFRange range1, OFRange range2)
 Returns the intersection of the two ranges or OFNotFound and length 0 if they don't intersect.
static OF_INLINE OFRange OFUnionRange (OFRange range1, OFRange range2)
 Returns the union of the two ranges if they are overlapping or adjacent, otherwise returns a range with location OFNotFound and length 0.
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 OFRect OFIntersectionRect (OFRect rect1, OFRect rect2)
 Returns the intersection of the two rectangles or a rectangle with x, y, width and height set to 0 if the two rectangles don't intersect.
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 OFVector3D OFAddVectors3D (OFVector3D vector1, OFVector3D vector2)
 Adds the two specified vectors.
static OF_INLINE OFVector3D OFSubtractVectors3D (OFVector3D vector1, OFVector3D vector2)
 Subtracts the second vector from the first vector.
static OF_INLINE OFVector3D OFMultiplyVector3D (OFVector3D vector, float scalar)
 Multiplies the specified vector with a scalar.
static OF_INLINE float OFDotProductOfVectors3D (OFVector3D vector1, OFVector3D vector2)
 Calculates the dot product of the two specified vectors.
static OF_INLINE float OFDistanceOfVectors3D (OFVector3D vector1, OFVector3D vector2)
 Calculates the distance between two vectors.
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 OFVector4D OFAddVectors4D (OFVector4D vector1, OFVector4D vector2)
 Adds the two specified vectors.
static OF_INLINE OFVector4D OFSubtractVectors4D (OFVector4D vector1, OFVector4D vector2)
 Subtracts the second vector from the first vector.
static OF_INLINE OFVector4D OFMultiplyVector4D (OFVector4D vector, float scalar)
 Multiplies the specified vector with a scalar.
static OF_INLINE float OFDotProductOfVectors4D (OFVector4D vector1, OFVector4D vector2)
 Calculates the dot product of the two specified vectors.
static OF_INLINE float OFDistanceOfVectors4D (OFVector4D vector1, OFVector4D vector2)
 Calculates the distance between two vectors.
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) OF_MALLOC_FUNC
 Allocates memory for the specified number of items of the specified size.
void * OFAllocZeroedMemory (size_t count, size_t size) OF_MALLOC_FUNC
 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.

Variables

static const size_t OFNotFound = SIZE_MAX
 A special not found index.

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

◆ OFAddVectors3D()

OF_INLINE OFVector3D OFAddVectors3D ( OFVector3D vector1,
OFVector3D vector2 )
static

Adds the two specified vectors.

Parameters
vector1The vector to add to
vector2The vector to add
Returns
The sum of the two vectors

◆ OFAddVectors4D()

OF_INLINE OFVector4D OFAddVectors4D ( OFVector4D vector1,
OFVector4D vector2 )
static

Adds the two specified vectors.

Parameters
vector1The vector to add to
vector2The vector to add
Returns
The sum of the two vectors

◆ 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

◆ OFDistanceOfVectors3D()

OF_INLINE float OFDistanceOfVectors3D ( OFVector3D vector1,
OFVector3D vector2 )
static

Calculates the distance between two vectors.

Parameters
vector1The first vector
vector2The second vector
Returns
The distance of the two vectors

◆ OFDistanceOfVectors4D()

OF_INLINE float OFDistanceOfVectors4D ( OFVector4D vector1,
OFVector4D vector2 )
static

Calculates the distance between two vectors.

Parameters
vector1The first vector
vector2The second vector
Returns
The distance of the two vectors

◆ OFDotProductOfVectors3D()

OF_INLINE float OFDotProductOfVectors3D ( OFVector3D vector1,
OFVector3D vector2 )
static

Calculates the dot product of the two specified vectors.

Parameters
vector1The first vector
vector2The second vector
Returns
The dot product of the two vectors

◆ OFDotProductOfVectors4D()

OF_INLINE float OFDotProductOfVectors4D ( OFVector4D vector1,
OFVector4D vector2 )
static

Calculates the dot product of the two specified vectors.

Parameters
vector1The first vector
vector2The second vector
Returns
The dot product of the two vectors

◆ OFEndOfRange()

OF_INLINE size_t OFEndOfRange ( OFRange range)
static

Returns the end of the range, which is its location + its length.

Parameters
rangeThe range whose end to return
Returns
The end of the range

◆ OFEqualPoints()

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()

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()

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()

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()

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()

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()

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()

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()

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

◆ OFIntersectionRange()

OF_INLINE OFRange OFIntersectionRange ( OFRange range1,
OFRange range2 )
static

Returns the intersection of the two ranges or OFNotFound and length 0 if they don't intersect.

Parameters
range1The first range
range2The second range
Returns
The intersection of both ranges

◆ OFIntersectionRect()

OF_INLINE OFRect OFIntersectionRect ( OFRect rect1,
OFRect rect2 )
static

Returns the intersection of the two rectangles or a rectangle with x, y, width and height set to 0 if the two rectangles don't intersect.

Parameters
rect1The first rectangle
rect2The second rectangle
Returns
The intersection of both rectangles

◆ OFLocationInRange()

OF_INLINE bool OFLocationInRange ( size_t location,
OFRange range )
static

Returns whether the specified location is in the specified range.

Parameters
locationThe location
rangeThe range
Returns
Whether the specified location is in the specified range

◆ OFMakePoint()

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()

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()

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()

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()

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()

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 implemented, 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

◆ OFMultiplyVector3D()

OF_INLINE OFVector3D OFMultiplyVector3D ( OFVector3D vector,
float scalar )
static

Multiplies the specified vector with a scalar.

Parameters
vectorThe vector
scalarThe scalar to multiply with
Returns
The vector multiplied with the scalar

◆ OFMultiplyVector4D()

OF_INLINE OFVector4D OFMultiplyVector4D ( OFVector4D vector,
float scalar )
static

Multiplies the specified vector with a scalar.

Parameters
vectorThe vector
scalarThe scalar to multiply with
Returns
The vector multiplied with the scalar

◆ 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

◆ OFSubtractVectors3D()

OF_INLINE OFVector3D OFSubtractVectors3D ( OFVector3D vector1,
OFVector3D vector2 )
static

Subtracts the second vector from the first vector.

Parameters
vector1The vector to subtract from
vector2The vector to subtract
Returns
The second vector subtracted from the first vector

◆ OFSubtractVectors4D()

OF_INLINE OFVector4D OFSubtractVectors4D ( OFVector4D vector1,
OFVector4D vector2 )
static

Subtracts the second vector from the first vector.

Parameters
vector1The vector to subtract from
vector2The vector to subtract
Returns
The second vector subtracted from the first vector

◆ OFUnionRange()

OF_INLINE OFRange OFUnionRange ( OFRange range1,
OFRange range2 )
static

Returns the union of the two ranges if they are overlapping or adjacent, otherwise returns a range with location OFNotFound and length 0.

Parameters
range1The first range
range2The second range
Returns
The two ranges merged