ObjFW
OFNumber.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2021 Jonathan Schleifer <js@nil.im>
3  *
4  * All rights reserved.
5  *
6  * This file is part of ObjFW. It may be distributed under the terms of the
7  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
8  * the packaging of this file.
9  *
10  * Alternatively, it may be distributed under the terms of the GNU General
11  * Public License, either version 2 or 3, which can be found in the file
12  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
13  * file.
14  */
15 
16 #ifndef __STDC_LIMIT_MACROS
17 # define __STDC_LIMIT_MACROS
18 #endif
19 #ifndef __STDC_CONSTANT_MACROS
20 # define __STDC_CONSTANT_MACROS
21 #endif
22 
23 #include "objfw-defs.h"
24 
25 #ifdef OF_HAVE_SYS_TYPES_H
26 # include <sys/types.h>
27 #endif
28 
29 #import "OFJSONRepresentation.h"
30 #import "OFMessagePackRepresentation.h"
31 #import "OFSerialization.h"
32 #import "OFValue.h"
33 
34 OF_ASSUME_NONNULL_BEGIN
35 
43 #ifndef OF_NUMBER_M
44 OF_SUBCLASSING_RESTRICTED
45 #endif
48 {
49  union of_number_value {
50  double float_;
51  long long signed_;
52  unsigned long long unsigned_;
53  } _value;
54  const char *_typeEncoding;
55 }
56 
60 @property (readonly, nonatomic) bool boolValue;
61 
65 @property (readonly, nonatomic) signed char charValue;
66 
70 @property (readonly, nonatomic) short shortValue;
71 
75 @property (readonly, nonatomic) int intValue;
76 
80 @property (readonly, nonatomic) long longValue;
81 
85 @property (readonly, nonatomic) long long longLongValue;
86 
90 @property (readonly, nonatomic) unsigned char unsignedCharValue;
91 
95 @property (readonly, nonatomic) unsigned short unsignedShortValue;
96 
100 @property (readonly, nonatomic) unsigned int unsignedIntValue;
101 
105 @property (readonly, nonatomic) unsigned long unsignedLongValue;
106 
110 @property (readonly, nonatomic) unsigned long long unsignedLongLongValue;
111 
115 @property (readonly, nonatomic) float floatValue;
116 
120 @property (readonly, nonatomic) double doubleValue;
121 
125 @property (readonly, nonatomic) OFString *stringValue;
126 
127 #ifdef OF_HAVE_UNAVAILABLE
128 + (instancetype)valueWithBytes: (const void *)bytes
129  objCType: (const char *)objCType OF_UNAVAILABLE;
130 + (instancetype)valueWithPointer: (const void *)pointer OF_UNAVAILABLE;
131 + (instancetype)valueWithNonretainedObject: (id)object OF_UNAVAILABLE;
132 + (instancetype)valueWithRange: (of_range_t)range OF_UNAVAILABLE;
133 + (instancetype)valueWithPoint: (of_point_t)point OF_UNAVAILABLE;
134 + (instancetype)valueWithDimension: (of_dimension_t)dimension OF_UNAVAILABLE;
135 + (instancetype)valueWithRectangle: (of_rectangle_t)rectangle OF_UNAVAILABLE;
136 #endif
137 
144 + (instancetype)numberWithBool: (bool)value;
145 
152 + (instancetype)numberWithChar: (signed char)value;
153 
160 + (instancetype)numberWithShort: (short)value;
161 
168 + (instancetype)numberWithInt: (int)value;
169 
176 + (instancetype)numberWithLong: (long)value;
177 
184 + (instancetype)numberWithLongLong: (long long)value;
185 
192 + (instancetype)numberWithUnsignedChar: (unsigned char)value;
193 
200 + (instancetype)numberWithUnsignedShort: (unsigned short)value;
201 
208 + (instancetype)numberWithUnsignedInt: (unsigned int)value;
209 
216 + (instancetype)numberWithUnsignedLong: (unsigned long)value;
217 
224 + (instancetype)numberWithUnsignedLongLong: (unsigned long long)value;
225 
232 + (instancetype)numberWithFloat: (float)value;
233 
240 + (instancetype)numberWithDouble: (double)value;
241 
242 - (instancetype)init OF_UNAVAILABLE;
243 #ifdef OF_HAVE_UNAVAILABLE
244 - (instancetype)initWithBytes: (const void *)bytes
245  objCType: (const char *)objCType OF_UNAVAILABLE;
246 - (instancetype)initWithPointer: (const void *)pointer OF_UNAVAILABLE;
247 - (instancetype)initWithNonretainedObject: (id)object OF_UNAVAILABLE;
248 - (instancetype)initWithRange: (of_range_t)range OF_UNAVAILABLE;
249 - (instancetype)initWithPoint: (of_point_t)point OF_UNAVAILABLE;
250 - (instancetype)initWithDimension: (of_dimension_t)dimension OF_UNAVAILABLE;
251 - (instancetype)initWithRectangle: (of_rectangle_t)rectangle OF_UNAVAILABLE;
252 #endif
253 
260 - (instancetype)initWithBool: (bool)value;
261 
269 - (instancetype)initWithChar: (signed char)value;
270 
277 - (instancetype)initWithShort: (short)value;
278 
285 - (instancetype)initWithInt: (int)value;
286 
293 - (instancetype)initWithLong: (long)value;
294 
302 - (instancetype)initWithLongLong: (long long)value;
303 
311 - (instancetype)initWithUnsignedChar: (unsigned char)value;
312 
320 - (instancetype)initWithUnsignedShort: (unsigned short)value;
321 
329 - (instancetype)initWithUnsignedInt: (unsigned int)value;
330 
338 - (instancetype)initWithUnsignedLong: (unsigned long)value;
339 
347 - (instancetype)initWithUnsignedLongLong: (unsigned long long)value;
348 
355 - (instancetype)initWithFloat: (float)value;
356 
363 - (instancetype)initWithDouble: (double)value;
364 @end
365 
366 OF_ASSUME_NONNULL_END
367 
368 #if !defined(NSINTEGER_DEFINED) && !__has_feature(modules)
369 /* Required for number literals to work */
370 @compatibility_alias NSNumber OFNumber;
371 #endif
Provides a way to store a number in an object.
Definition: OFNumber.h:49
A class for handling strings.
Definition: OFString.h:132
A class for storing arbitrary values in an object.
Definition: OFValue.h:27
A protocol for comparing objects.
Definition: OFObject.h:1224
A protocol implemented by classes that support encoding to a JSON representation.
Definition: OFJSONRepresentation.h:39
A protocol implemented by classes that support encoding to a MessagePack representation.
Definition: OFMessagePackRepresentation.h:29
A protocol for serializing objects.
Definition: OFSerialization.h:29
A dimension.
Definition: OFObject.h:192
A point.
Definition: OFObject.h:145
A range.
Definition: OFObject.h:93
A rectangle.
Definition: OFObject.h:239