Objectively 1.0.0
Ultra-lightweight object oriented framework for GNU C.
Macros | Functions | Variables
Boole.c File Reference
#include <assert.h>
#include "Boole.h"
#include "String.h"

Go to the source code of this file.

Macros

#define _Class   _Boole
 

Functions

Class_Boole (void)
 
static Objectcopy (const Object *self)
 
static Stringdescription (const Object *self)
 
static void destroy (Class *clazz)
 
static BooleFalse (void)
 
static void initialize (Class *clazz)
 
static BooleTrue (void)
 
static Boolevalueof (_Bool value)
 

Variables

static Boole_False
 
static Boole_True
 

Macro Definition Documentation

◆ _Class

#define _Class   _Boole

Definition at line 29 of file Boole.c.

Function Documentation

◆ _Boole()

Class * _Boole ( void  )

Definition at line 125 of file Boole.c.

125 {
126 static Class *clazz;
127 static Once once;
128
129 do_once(&once, {
130 clazz = _initialize(&(const ClassDef) {
131 .name = "Boole",
132 .superclass = _Object(),
133 .instanceSize = sizeof(Boole),
134 .interfaceOffset = offsetof(Boole, interface),
135 .interfaceSize = sizeof(BooleInterface),
137 .destroy = destroy,
138 });
139 });
140
141 return clazz;
142}
static void destroy(Class *clazz)
Definition: Boole.c:115
static void initialize(Class *clazz)
Definition: Boole.c:102
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition: Class.c:91
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
A wrapper for placing boolean primitives into collections, etc.
Definition: Boole.h:41
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 * _Object(void)
The Object archetype.
Definition: Object.c:136

◆ copy()

static Object * copy ( const Object self)
static
See also
Object::copy(const Object *)

Definition at line 36 of file Boole.c.

36 {
37
38 return (Object *) self;
39}
Object is the root Class of The Objectively Class hierarchy.
Definition: Object.h:46

◆ description()

static String * description ( const Object self)
static
See also
Object::description(const Object *)

Definition at line 44 of file Boole.c.

44 {
45
46 const Boole *this = (Boole *) self;
47
48 return $(alloc(String), initWithCharacters, this->value ? "true" : "false");
49}
#define alloc(type)
Allocate and initialize and instance of type.
Definition: Class.h:159
Immutable UTF-8 strings.
Definition: String.h:69
String * initWithCharacters(String *self, const char *chars)
Initializes this String by copying chars.
Definition: String.c:310

◆ destroy()

static void destroy ( Class clazz)
static
See also
Class::destroy(Class *)

Definition at line 115 of file Boole.c.

115 {
116
118 release(_True);
119}
static Boole * _True
Definition: Boole.c:71
static Boole * _False
Definition: Boole.c:53
ident release(ident obj)
Atomically decrement the given Object's reference count. If the resulting reference count is 0,...
Definition: Class.c:196

◆ False()

static Boole * False ( void  )
static

Definition at line 59 of file Boole.c.

59 {
60
61 static Once once;
62
63 do_once(&once, {
64 _False = (Boole *) $((Object *) alloc(Boole), init);
65 _False->value = false;
66 });
67
68 return _False;
69}
_Bool value
The backing _Bool.
Definition: Boole.h:57
Condition * init(Condition *self)
Initializes this Condition.
Definition: Condition.c:67

◆ initialize()

static void initialize ( Class clazz)
static
See also
Class::initialize(Class *)

Definition at line 102 of file Boole.c.

102 {
103
104 ((ObjectInterface *) clazz->interface)->copy = copy;
105 ((ObjectInterface *) clazz->interface)->description = description;
106
107 ((BooleInterface *) clazz->interface)->False = False;
108 ((BooleInterface *) clazz->interface)->True = True;
109 ((BooleInterface *) clazz->interface)->valueof = valueof;
110}
Boole * valueof(_Bool value)
Definition: Boole.c:93
Boole * False(void)
Definition: Boole.c:59
Boole * True(void)
Definition: Boole.c:77
ident interface
The interface of the Class.
Definition: Class.h:105
Object * copy(const Object *self)
Creates a shallow copy of this Object.
Definition: Array.c:40
String * description(const Object *self)
Definition: Array.c:66

◆ True()

static Boole * True ( void  )
static

Definition at line 77 of file Boole.c.

77 {
78
79 static Once once;
80
81 do_once(&once, {
82 _True = (Boole *) $((Object *) alloc(Boole), init);
83 _True->value = true;
84 });
85
86 return _True;
87}

◆ valueof()

static Boole * valueof ( _Bool  value)
static

Definition at line 93 of file Boole.c.

93 {
94 return value ? $$(Boole, True) : $$(Boole, False);
95}

Variable Documentation

◆ _False

Boole* _False
static

Definition at line 53 of file Boole.c.

◆ _True

Boole* _True
static

Definition at line 71 of file Boole.c.