Objectively
Ultra-lightweight object oriented framework for GNU C.
Loading...
Searching...
No Matches
Pointer Struct Reference

#include <Pointer.h>

Overview

Pointers provide Object encapsulation for raw C pointers.

Definition at line 40 of file Pointer.h.

Inheritance diagram for Pointer:
Object

Properties

Consumer destroy
 An optional destructor that, if set, is called on dealloc.
 
Object object
 The superclass.
 
ident pointer
 The backing pointer.
 
- Properties inherited from Object
Classclazz
 Every instance of Object begins with a pointer to its Class.
 
unsigned int magic
 A header to allow introspection of Object types.
 

Methods

Class_Pointer (void)
 The Pointer archetype.
 
PointerinitWithBytes (Pointer *self, const uint8_t *bytes, size_t length)
 Initializes this Pointer by copying length of bytes.
 
PointerinitWithPointer (Pointer *self, ident pointer, Consumer destroy)
 Initializes this Pointer.
 
- Methods inherited from Object
Class_Object (void)
 The Object archetype.
 
Objectcopy (const Object *self)
 Creates a shallow copy of this Object.
 
void dealloc (Object *self)
 Frees all resources held by this Object.
 
Stringdescription (const Object *self)
 
int hash (const Object *self)
 
Objectinit (Object *self)
 Initializes this Object.
 
bool isEqual (const Object *self, const Object *other)
 Tests equality of the other Object.
 
bool isKindOfClass (const Object *self, const Class *clazz)
 Tests for Class hierarchy membership.
 

Protected Attributes

PointerInterface * interface
 The interface.
 
- Protected Attributes inherited from Object
ObjectInterface * interface
 The interface.
 

Related Symbols

OBJECTIVELY_EXPORT Pointerptr (ident pointer, Consumer destroy)
 A convenience function for instantiating Pointers.
 

Property Details

◆ destroy

Consumer Pointer::destroy

An optional destructor that, if set, is called on dealloc.

Definition at line 56 of file Pointer.h.

◆ interface

PointerInterface* Pointer::interface
protected

The interface.

Definition at line 51 of file Pointer.h.

◆ object

Object Pointer::object

The superclass.

Definition at line 45 of file Pointer.h.

◆ pointer

ident Pointer::pointer

The backing pointer.

Definition at line 61 of file Pointer.h.

Method Details

◆ _Pointer()

Class * _Pointer ( void  )

The Pointer archetype.

Returns
The Pointer Class.

Definition at line 137 of file Pointer.c.

137 {
138 static Class *clazz;
139 static Once once;
140
141 do_once(&once, {
142 clazz = _initialize(&(const ClassDef) {
143 .name = "Pointer",
144 .superclass = _Object(),
145 .instanceSize = sizeof(Pointer),
146 .interfaceOffset = offsetof(Pointer, interface),
147 .interfaceSize = sizeof(PointerInterface),
149 });
150 });
151
152 return clazz;
153}
static void initialize(Class *clazz)
Definition Array.c:710
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition Class.c:86
long Once
The Once type.
Definition Once.h:37
#define do_once(once, block)
Executes the given block at most one time.
Definition Once.h:43
ClassDefs are passed to _initialize via an archetype to initialize a Class.
Definition Class.h:41
The runtime representation of a Class.
Definition Class.h:95
Class * clazz
Every instance of Object begins with a pointer to its Class.
Definition Object.h:55
Class * _Object(void)
The Object archetype.
Definition Object.c:136
Pointers provide Object encapsulation for raw C pointers.
Definition Pointer.h:40
PointerInterface * interface
The interface.
Definition Pointer.h:51

◆ initWithBytes()

Pointer * initWithBytes ( Pointer self,
const uint8_t *  bytes,
size_t  length 
)

Initializes this Pointer by copying length of bytes.

Parameters
selfThe Pointer.
bytesThe bytes to copy.
lengthThe count of bytes to copy.
Returns
The initialized Pointer, or NULL on error.
Remarks
The copied bytes will be freed on dealloc.

Definition at line 87 of file Pointer.c.

87 {
88
89 self = (Pointer *) super(Object, self, init);
90 if (self) {
91 if (bytes) {
92 self->pointer = calloc(1, length);
93 assert(self->pointer);
94
95 memcpy(self->pointer, bytes, length);
96 self->destroy = free;
97 }
98 }
99
100 return self;
101}
#define super(type, obj, method,...)
Object is the root Class of The Objectively Class hierarchy.
Definition Object.h:46
Object * init(Object *self)
Initializes this Object.
Definition Object.c:83
ident pointer
The backing pointer.
Definition Pointer.h:61
Consumer destroy
An optional destructor that, if set, is called on dealloc.
Definition Pointer.h:56

◆ initWithPointer()

Pointer * initWithPointer ( Pointer self,
ident  pointer,
Consumer  destroy 
)

Initializes this Pointer.

Parameters
selfThe Pointer.
pointerThe backing pointer.
destroyAn optional destructor, or NULL.
Returns
The initialized Pointer, or NULL on error.

Definition at line 107 of file Pointer.c.

107 {
108
109 self = (Pointer *) super(Object, self, init);
110 if (self) {
111 self->pointer = pointer;
112 self->destroy = destroy;
113 }
114
115 return self;
116}

Related

◆ ptr()

OBJECTIVELY_EXPORT Pointer * ptr ( ident  pointer,
Consumer  destroy 
)
related

A convenience function for instantiating Pointers.

Parameters
pointerThe backing pointer.
destroyAn optional destructor, or NULL.
Returns
A new Pointer, or NULL on error.

Definition at line 157 of file Pointer.c.

157 {
159}
#define alloc(type)
Allocate and initialize and instance of type.
Definition Class.h:176
Pointer * initWithPointer(Pointer *self, ident pointer, Consumer destroy)
Initializes this Pointer.
Definition Pointer.c:107

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