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

#include <Number.h>

Overview

A wrapper for placing numeric primitives into collections, etc.

Definition at line 41 of file Number.h.

Inheritance diagram for Number:
Object

Properties

Object object
 The superclass. More...
 
double value
 The backing value. More...
 
- Properties inherited from Object
Classclazz
 Every instance of Object begins with a pointer to its Class. More...
 

Methods

Class_Number (void)
 The Number archetype. More...
 
_Bool boolValue (const Number *self)
 
char charValue (const Number *self)
 
Order compareTo (const Number *self, const Number *other)
 Compares this Number to another. More...
 
double doubleValue (const Number *self)
 
float floatValue (const Number *self)
 
NumberinitWithValue (Number *self, double value)
 Initializes this Number with the specified value. More...
 
int intValue (const Number *self)
 
long longValue (const Number *self)
 
NumbernumberWithValue (double value)
 Returns a new Number with the given value. More...
 
short shortValue (const Number *self)
 
- 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

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

Property Details

◆ interface

NumberInterface* Number::interface
protected

The interface.

Definition at line 52 of file Number.h.

◆ object

Object Number::object

The superclass.

Definition at line 46 of file Number.h.

◆ value

double Number::value

The backing value.

Definition at line 57 of file Number.h.

Method Details

◆ _Number()

Class * _Number ( void  )

The Number archetype.

Returns
The Number Class.

Definition at line 198 of file Number.c.

198 {
199 static Class *clazz;
200 static Once once;
201
202 do_once(&once, {
203 clazz = _initialize(&(const ClassDef) {
204 .name = "Number",
205 .superclass = _Object(),
206 .instanceSize = sizeof(Number),
207 .interfaceOffset = offsetof(Number, interface),
208 .interfaceSize = sizeof(NumberInterface),
210 });
211 });
212
213 return clazz;
214}
Class * _initialize(const ClassDef *def)
Initializes the given Class.
Definition: Class.c:91
static void initialize(Class *clazz)
Definition: Number.c:176
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
A wrapper for placing numeric primitives into collections, etc.
Definition: Number.h:41
NumberInterface * interface
The interface.
Definition: Number.h:52
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

◆ boolValue()

_Bool boolValue ( const Number self)
Parameters
selfThe Number.
Returns
This Number's _Bool value.

Definition at line 80 of file Number.c.

80 {
81 return self->value ? true : false;
82}
double value
The backing value.
Definition: Number.h:57

◆ charValue()

char charValue ( const Number self)
Parameters
selfThe Number.
Returns
This Number's char value.

Definition at line 88 of file Number.c.

88 {
89 return (char) self->value;
90}

◆ compareTo()

Order compareTo ( const Number self,
const Number other 
)

Compares this Number to another.

Parameters
selfThe Number.
otherThe Number to compare to.
Returns
The ordering of this Number compared to other.

Definition at line 96 of file Number.c.

96 {
97
98 if (other) {
99 if (self->value == other->value) {
100 return OrderSame;
101 }
102
103 return self->value < other->value ? OrderAscending : OrderDescending;
104 }
105
106 return OrderAscending;
107}
@ OrderSame
Definition: Types.h:72
@ OrderDescending
Definition: Types.h:73
@ OrderAscending
Definition: Types.h:71

◆ doubleValue()

double doubleValue ( const Number self)
Parameters
selfThe Number.
Returns
This Number's double value.

Definition at line 113 of file Number.c.

113 {
114 return self->value;
115}

◆ floatValue()

float floatValue ( const Number self)
Parameters
selfThe Number.
Returns
This Number's floating point value.

Definition at line 121 of file Number.c.

121 {
122 return (float) self->value;
123}

◆ initWithValue()

Number * initWithValue ( Number self,
double  value 
)

Initializes this Number with the specified value.

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

Definition at line 137 of file Number.c.

137 {
138
139 self = (Number *) super(Object, self, init);
140 if (self) {
141 self->value = value;
142 }
143
144 return self;
145}
#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

◆ intValue()

int intValue ( const Number self)
Parameters
selfThe Number.
Returns
This Number's integer value.

Definition at line 151 of file Number.c.

151 {
152 return (int) self->value;
153}

◆ longValue()

long longValue ( const Number self)
Parameters
selfThe Number.
Returns
This Number's long value.

Definition at line 129 of file Number.c.

129 {
130 return (long) self->value;
131}

◆ numberWithValue()

Number * numberWithValue ( double  value)

Returns a new Number with the given value.

Parameters
valueThe value.
Returns
The new Number, or NULL on error.

Definition at line 159 of file Number.c.

159 {
160 return $(alloc(Number), initWithValue, value);
161}
#define alloc(type)
Allocate and initialize and instance of type.
Definition: Class.h:159
Number * initWithValue(Number *self, double value)
Initializes this Number with the specified value.
Definition: Number.c:137

◆ shortValue()

short shortValue ( const Number self)
Parameters
selfThe Number.
Returns
This Number's short value.

Definition at line 167 of file Number.c.

167 {
168 return (short) self->value;
169}

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