Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
Null.c
Go to the documentation of this file.
1/*
2 * Objectively: Ultra-lightweight object oriented framework for GNU C.
3 * Copyright (C) 2014 Jay Dolan <jay@jaydolan.com>
4 *
5 * This software is provided 'as-is', without any express or implied
6 * warranty. In no event will the authors be held liable for any damages
7 * arising from the use of this software.
8 *
9 * Permission is granted to anyone to use this software for any purpose,
10 * including commercial applications, and to alter it and redistribute it
11 * freely, subject to the following restrictions:
12 *
13 * 1. The origin of this software must not be misrepresented; you must not
14 * claim that you wrote the original software. If you use this software
15 * in a product, an acknowledgment in the product documentation would be
16 * appreciated but is not required.
17 *
18 * 2. Altered source versions must be plainly marked as such, and must not be
19 * misrepresented as being the original software.
20 *
21 * 3. This notice may not be removed or altered from any source distribution.
22 */
23
24#include <assert.h>
25
26#include "Null.h"
27
28#define _Class _Null
29
30#pragma mark - Object
31
35static Object *copy(const Object *self) {
36
37 return (Object *) self;
38}
39
40#pragma mark - Null
41
42static Null *_null;
43
48static Null *null(void) {
49
50 static Once once;
51
52 do_once(&once, {
53 _null = (Null *) $((Object *) alloc(Null), init);
54 });
55
56 return _null;
57}
58
59#pragma mark - Class lifecycle
60
64static void initialize(Class *clazz) {
65
66 ((ObjectInterface *) clazz->interface)->copy = copy;
67
68 ((NullInterface *) clazz->interface)->null = null;
69}
70
74static void destroy(Class *clazz) {
75
77}
78
83Class *_Null(void) {
84 static Class *clazz;
85 static Once once;
86
87 do_once(&once, {
88 clazz = _initialize(&(const ClassDef) {
89 .name = "Null",
90 .superclass = _Object(),
91 .instanceSize = sizeof(Null),
92 .interfaceOffset = offsetof(Null, interface),
93 .interfaceSize = sizeof(NullInterface),
96 });
97 });
98
99 return clazz;
100}
101
102#undef _Class
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Definition: Class.c:196
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition: Class.c:91
#define alloc(type)
Allocate and initialize and instance of type.
Definition: Class.h:159
static void destroy(Class *clazz)
Definition: Null.c:74
static Null * _null
Definition: Null.c:42
static void initialize(Class *clazz)
Definition: Null.c:64
The Null sentinel.
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
ident interface
The interface of the Class.
Definition: Class.h:105
Condition * init(Condition *self)
Initializes this Condition.
Definition: Condition.c:67
The Null sentinel.
Definition: Null.h:42
Null * null(void)
Definition: Null.c:48
Class * _Null(void)
The Null archetype.
Definition: Null.c:83
Object is the root Class of The Objectively Class hierarchy.
Definition: Object.h:46
Class * _Object(void)
The Object archetype.
Definition: Object.c:136
Object * copy(const Object *self)
Creates a shallow copy of this Object.
Definition: Array.c:40