Objectively
Ultra-lightweight object oriented framework for GNU C.
Loading...
Searching...
No Matches
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.
 
double value
 The backing value.
 
- 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_Number (void)
 The Number archetype.
 
bool boolValue (const Number *self)
 
char charValue (const Number *self)
 
Order compareTo (const Number *self, const Number *other)
 Compares this Number to another.
 
double doubleValue (const Number *self)
 
float floatValue (const Number *self)
 
NumberinitWithValue (Number *self, double value)
 Initializes this Number with the specified value.
 
int intValue (const Number *self)
 
long longValue (const Number *self)
 
NumbernumberWithValue (double value)
 Returns a new Number with the given value.
 
short shortValue (const Number *self)
 
- 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

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

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}
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
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:55
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 129 of file Number.c.

129 {
130
131 self = (Number *) super(Object, self, init);
132 if (self) {
133 self->value = value;
134 }
135
136 return self;
137}
#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 143 of file Number.c.

143 {
144 return (int) self->value;
145}

◆ longValue()

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

Definition at line 151 of file Number.c.

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

◆ 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:176
Number * initWithValue(Number *self, double value)
Initializes this Number with the specified value.
Definition Number.c:129

◆ 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: