ObjFW
OFNumber.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2025 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This program is free software: you can redistribute it and/or modify it
7  * under the terms of the GNU Lesser General Public License version 3.0 only,
8  * as published by the Free Software Foundation.
9  *
10  * This program is distributed in the hope that it will be useful, but WITHOUT
11  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12  * FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License
13  * version 3.0 for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public License
16  * version 3.0 along with this program. If not, see
17  * <https://www.gnu.org/licenses/>.
18  */
19 
20 #ifndef __STDC_LIMIT_MACROS
21 # define __STDC_LIMIT_MACROS
22 #endif
23 #ifndef __STDC_CONSTANT_MACROS
24 # define __STDC_CONSTANT_MACROS
25 #endif
26 
27 #include "objfw-defs.h"
28 
29 #ifdef OF_HAVE_SYS_TYPES_H
30 # include <sys/types.h>
31 #endif
32 
33 #import "OFJSONRepresentation.h"
34 #import "OFMessagePackRepresentation.h"
35 #import "OFValue.h"
36 
37 OF_ASSUME_NONNULL_BEGIN
38 
51 @property (readonly, nonatomic) bool boolValue;
52 
59 @property (readonly, nonatomic) signed char charValue;
60 
67 @property (readonly, nonatomic) short shortValue;
68 
75 @property (readonly, nonatomic) int intValue;
76 
83 @property (readonly, nonatomic) long longValue;
84 
91 @property (readonly, nonatomic) long long longLongValue;
92 
99 @property (readonly, nonatomic) unsigned char unsignedCharValue;
100 
107 @property (readonly, nonatomic) unsigned short unsignedShortValue;
108 
115 @property (readonly, nonatomic) unsigned int unsignedIntValue;
116 
123 @property (readonly, nonatomic) unsigned long unsignedLongValue;
124 
131 @property (readonly, nonatomic) unsigned long long unsignedLongLongValue;
132 
136 @property (readonly, nonatomic) float floatValue;
137 
141 @property (readonly, nonatomic) double doubleValue;
142 
146 @property (readonly, nonatomic) OFString *stringValue;
147 
148 + (instancetype)valueWithPointer: (const void *)pointer OF_UNAVAILABLE;
149 + (instancetype)valueWithNonretainedObject: (id)object OF_UNAVAILABLE;
150 + (instancetype)valueWithRange: (OFRange)range OF_UNAVAILABLE;
151 + (instancetype)valueWithPoint: (OFPoint)point OF_UNAVAILABLE;
152 + (instancetype)valueWithSize: (OFSize)size OF_UNAVAILABLE;
153 + (instancetype)valueWithRect: (OFRect)rect OF_UNAVAILABLE;
154 
161 + (instancetype)numberWithBool: (bool)value;
162 
169 + (instancetype)numberWithChar: (signed char)value;
170 
177 + (instancetype)numberWithShort: (short)value;
178 
185 + (instancetype)numberWithInt: (int)value;
186 
193 + (instancetype)numberWithLong: (long)value;
194 
201 + (instancetype)numberWithLongLong: (long long)value;
202 
209 + (instancetype)numberWithUnsignedChar: (unsigned char)value;
210 
217 + (instancetype)numberWithUnsignedShort: (unsigned short)value;
218 
225 + (instancetype)numberWithUnsignedInt: (unsigned int)value;
226 
233 + (instancetype)numberWithUnsignedLong: (unsigned long)value;
234 
241 + (instancetype)numberWithUnsignedLongLong: (unsigned long long)value;
242 
249 + (instancetype)numberWithFloat: (float)value;
250 
257 + (instancetype)numberWithDouble: (double)value;
258 
265 - (instancetype)initWithBool: (bool)value;
266 
274 - (instancetype)initWithChar: (signed char)value;
275 
282 - (instancetype)initWithShort: (short)value;
283 
290 - (instancetype)initWithInt: (int)value;
291 
298 - (instancetype)initWithLong: (long)value;
299 
307 - (instancetype)initWithLongLong: (long long)value;
308 
316 - (instancetype)initWithUnsignedChar: (unsigned char)value;
317 
325 - (instancetype)initWithUnsignedShort: (unsigned short)value;
326 
334 - (instancetype)initWithUnsignedInt: (unsigned int)value;
335 
343 - (instancetype)initWithUnsignedLong: (unsigned long)value;
344 
352 - (instancetype)initWithUnsignedLongLong: (unsigned long long)value;
353 
360 - (instancetype)initWithFloat: (float)value;
361 
368 - (instancetype)initWithDouble: (double)value;
369 
376 - (OFComparisonResult)compare: (OFNumber *)number;
377 @end
378 
379 OF_ASSUME_NONNULL_END
380 
381 #if !defined(NSINTEGER_DEFINED) && !__has_feature(modules)
382 /* Required for number literals to work */
383 @compatibility_alias NSNumber OFNumber;
384 #endif
double doubleValue
The OFNumber as a double.
Definition: OFNumber.h:141
A protocol for comparing objects.
Definition: OFObject.h:1392
float floatValue
The OFNumber as a float.
Definition: OFNumber.h:136
long longValue
The OFNumber as a long.
Definition: OFNumber.h:83
A protocol implemented by classes that support encoding to a JSON representation. ...
Definition: OFJSONRepresentation.h:49
A class for handling strings.
Definition: OFString.h:142
A rectangle.
Definition: OFObject.h:253
OFComparisonResult
A result of a comparison.
Definition: OFObject.h:58
unsigned long long unsignedLongLongValue
The OFNumber as an unsigned long long.
Definition: OFNumber.h:131
A protocol implemented by classes that support encoding to a MessagePack representation.
Definition: OFMessagePackRepresentation.h:33
short shortValue
The OFNumber as a short.
Definition: OFNumber.h:67
Provides a way to store a number in an object.
Definition: OFNumber.h:46
unsigned char unsignedCharValue
The OFNumber as an unsigned char.
Definition: OFNumber.h:99
int intValue
The OFNumber as an int.
Definition: OFNumber.h:75
A size.
Definition: OFObject.h:207
unsigned int unsignedIntValue
The OFNumber as an unsigned int.
Definition: OFNumber.h:115
A class for storing arbitrary values in an object.
Definition: OFValue.h:29
OFString * stringValue
The OFNumber as a string.
Definition: OFNumber.h:146
signed char charValue
The OFNumber as a signed char.
Definition: OFNumber.h:59
unsigned short unsignedShortValue
The OFNumber as an unsigned short.
Definition: OFNumber.h:107
unsigned long unsignedLongValue
The OFNumber as an unsigned long.
Definition: OFNumber.h:123
bool boolValue
The OFNumber as a bool.
Definition: OFNumber.h:51
A range.
Definition: OFObject.h:110
long long longLongValue
The OFNumber as a long long.
Definition: OFNumber.h:91
A point in 2D space.
Definition: OFObject.h:161