Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
Properties | Methods | Protected Attributes
Value Struct Reference

#include <Value.h>

Overview

Values provide Object encapsulation for C types.

Definition at line 45 of file Value.h.

Inheritance diagram for Value:
Object

Properties

ValueDestructor destructor
 An optional destructor that, if set, is called on dealloc. More...
 
Object object
 The superclass. More...
 
ident value
 The backing value. More...
 
- Properties inherited from Object
Classclazz
 Every instance of Object begins with a pointer to its Class. More...
 

Methods

Class_Value (void)
 The Value archetype. More...
 
ValueinitWithBytes (Value *self, const uint8_t *bytes, size_t length)
 Initializes this Value by copying length of bytes. More...
 
ValueinitWithValue (Value *self, ident value)
 Initializes this Value. More...
 
- Methods inherited from Object
Class_Object (void)
 The Object archetype. More...
 
Objectcopy (const Object *self)
 Creates a shallow copy of this Object. More...
 
void dealloc (Object *self)
 Frees all resources held by this Object. More...
 
Stringdescription (const Object *self)
 
int hash (const Object *self)
 
Objectinit (Object *self)
 Initializes this Object. More...
 
_Bool isEqual (const Object *self, const Object *other)
 Tests equality of the other Object. More...
 
_Bool isKindOfClass (const Object *self, const Class *clazz)
 Tests for Class hierarchy membership. More...
 

Protected Attributes

ValueInterface * interface
 The interface. More...
 
- Protected Attributes inherited from Object
ObjectInterface * interface
 The interface. More...
 

Property Details

◆ destructor

ValueDestructor Value::destructor

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

Definition at line 66 of file Value.h.

◆ interface

ValueInterface* Value::interface
protected

The interface.

Definition at line 56 of file Value.h.

◆ object

Object Value::object

The superclass.

Definition at line 50 of file Value.h.

◆ value

ident Value::value

The backing value.

Definition at line 61 of file Value.h.

Method Details

◆ _Value()

Class * _Value ( void  )

The Value archetype.

Returns
The Value Class.

Definition at line 136 of file Value.c.

136 {
137 static Class *clazz;
138 static Once once;
139
140 do_once(&once, {
141 clazz = _initialize(&(const ClassDef) {
142 .name = "Value",
143 .superclass = _Object(),
144 .instanceSize = sizeof(Value),
145 .interfaceOffset = offsetof(Value, interface),
146 .interfaceSize = sizeof(ValueInterface),
148 });
149 });
150
151 return clazz;
152}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition: Class.c:91
static void initialize(Class *clazz)
Definition: Value.c:122
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:51
Class * _Object(void)
The Object archetype.
Definition: Object.c:136
Values provide Object encapsulation for C types.
Definition: Value.h:45
ValueInterface * interface
The interface.
Definition: Value.h:56

◆ initWithBytes()

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

Initializes this Value by copying length of bytes.

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

Definition at line 87 of file Value.c.

87 {
88
89 self = (Value *) super(Object, self, init);
90 if (self) {
91 if (bytes) {
92 self->value = calloc(1, length);
93 assert(self->value);
94
95 memcpy(self->value, bytes, length);
96 self->destructor = 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
ValueDestructor destructor
An optional destructor that, if set, is called on dealloc.
Definition: Value.h:66
ident value
The backing value.
Definition: Value.h:61

◆ initWithValue()

Value * initWithValue ( Value self,
ident  value 
)

Initializes this Value.

Parameters
selfThe Value.
valueThe backing value.
Returns
The initialized Value, or NULL on error.

Definition at line 107 of file Value.c.

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

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