ObjFW
OFNumber.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015
3  * Jonathan Schleifer <js@webkeks.org>
4  *
5  * All rights reserved.
6  *
7  * This file is part of ObjFW. It may be distributed under the terms of the
8  * Q Public License 1.0, which can be found in the file LICENSE.QPL included in
9  * the packaging of this file.
10  *
11  * Alternatively, it may be distributed under the terms of the GNU General
12  * Public License, either version 2 or 3, which can be found in the file
13  * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
14  * file.
15  */
16 
17 #ifndef __STDC_LIMIT_MACROS
18 # define __STDC_LIMIT_MACROS
19 #endif
20 #ifndef __STDC_CONSTANT_MACROS
21 # define __STDC_CONSTANT_MACROS
22 #endif
23 
24 #include <sys/types.h>
25 
26 #import "OFObject.h"
27 #import "OFSerialization.h"
28 #import "OFJSONRepresentation.h"
29 #import "OFMessagePackRepresentation.h"
30 
31 OF_ASSUME_NONNULL_BEGIN
32 
38 typedef enum {
65  OF_NUMBER_TYPE_SIGNED = 0x10,
68  OF_NUMBER_TYPE_SIGNED,
71  OF_NUMBER_TYPE_SIGNED,
74  OF_NUMBER_TYPE_SIGNED,
77  OF_NUMBER_TYPE_SIGNED,
80  OF_NUMBER_TYPE_SIGNED,
83  OF_NUMBER_TYPE_SIGNED,
86  OF_NUMBER_TYPE_SIGNED,
89  OF_NUMBER_TYPE_SIGNED,
92  OF_NUMBER_TYPE_SIGNED,
95  OF_NUMBER_TYPE_SIGNED,
98  OF_NUMBER_TYPE_SIGNED,
100  OF_NUMBER_TYPE_PTRDIFF = 0x0E | OF_NUMBER_TYPE_SIGNED,
102  OF_NUMBER_TYPE_INTPTR = 0x0F | OF_NUMBER_TYPE_SIGNED,
108 
116 {
117  union of_number_value {
118  bool bool_;
119  signed char schar;
120  signed short sshort;
121  signed int sint;
122  signed long slong;
123  signed long long slonglong;
124  unsigned char uchar;
125  unsigned short ushort;
126  unsigned int uint;
127  unsigned long ulong;
128  unsigned long long ulonglong;
129  int8_t int8;
130  int16_t int16;
131  int32_t int32;
132  int64_t int64;
133  uint8_t uint8;
134  uint16_t uint16;
135  uint32_t uint32;
136  uint64_t uint64;
137  size_t size;
138  ssize_t ssize;
139  intmax_t intmax;
140  uintmax_t uintmax;
141  ptrdiff_t ptrdiff;
142  intptr_t intptr;
143  uintptr_t uintptr;
144  float float_;
145  double double_;
146  } _value;
147  of_number_type_t _type;
148 }
149 
150 #ifdef OF_HAVE_PROPERTIES
151 @property (readonly) of_number_type_t type;
152 #endif
153 
160 + (instancetype)numberWithBool: (bool)bool_;
161 
168 + (instancetype)numberWithChar: (signed char)schar;
169 
176 + (instancetype)numberWithShort: (signed short)sshort;
177 
184 + (instancetype)numberWithInt: (signed int)sint;
185 
192 + (instancetype)numberWithLong: (signed long)slong;
193 
200 + (instancetype)numberWithLongLong: (signed long long)slonglong;
201 
208 + (instancetype)numberWithUnsignedChar: (unsigned char)uchar;
209 
216 + (instancetype)numberWithUnsignedShort: (unsigned short)ushort;
217 
224 + (instancetype)numberWithUnsignedInt: (unsigned int)uint;
225 
232 + (instancetype)numberWithUnsignedLong: (unsigned long)ulong;
233 
240 + (instancetype)numberWithUnsignedLongLong: (unsigned long long)ulonglong;
241 
248 + (instancetype)numberWithInt8: (int8_t)int8;
249 
256 + (instancetype)numberWithInt16: (int16_t)int16;
257 
264 + (instancetype)numberWithInt32: (int32_t)int32;
265 
272 + (instancetype)numberWithInt64: (int64_t)int64;
273 
280 + (instancetype)numberWithUInt8: (uint8_t)uint8;
281 
288 + (instancetype)numberWithUInt16: (uint16_t)uint16;
289 
296 + (instancetype)numberWithUInt32: (uint32_t)uint32;
297 
304 + (instancetype)numberWithUInt64: (uint64_t)uint64;
305 
312 + (instancetype)numberWithSize: (size_t)size;
313 
320 + (instancetype)numberWithSSize: (ssize_t)ssize;
321 
328 + (instancetype)numberWithIntMax: (intmax_t)intmax;
329 
336 + (instancetype)numberWithUIntMax: (uintmax_t)uintmax;
337 
344 + (instancetype)numberWithPtrDiff: (ptrdiff_t)ptrdiff;
345 
352 + (instancetype)numberWithIntPtr: (intptr_t)intptr;
353 
360 + (instancetype)numberWithUIntPtr: (uintptr_t)uintptr;
361 
368 + (instancetype)numberWithFloat: (float)float_;
369 
376 + (instancetype)numberWithDouble: (double)double_;
377 
384 - initWithBool: (bool)bool_;
385 
393 - initWithChar: (signed char)schar;
394 
402 - initWithShort: (signed short)sshort;
403 
411 - initWithInt: (signed int)sint;
412 
420 - initWithLong: (signed long)slong;
421 
429 - initWithLongLong: (signed long long)slonglong;
430 
438 - initWithUnsignedChar: (unsigned char)uchar;
439 
447 - initWithUnsignedShort: (unsigned short)ushort;
448 
456 - initWithUnsignedInt: (unsigned int)uint;
457 
465 - initWithUnsignedLong: (unsigned long)ulong;
466 
474 - initWithUnsignedLongLong: (unsigned long long)ulonglong;
475 
482 - initWithInt8: (int8_t)int8;
483 
490 - initWithInt16: (int16_t)int16;
491 
498 - initWithInt32: (int32_t)int32;
499 
506 - initWithInt64: (int64_t)int64;
507 
514 - initWithUInt8: (uint8_t)uint8;
515 
522 - initWithUInt16: (uint16_t)uint16;
523 
530 - initWithUInt32: (uint32_t)uint32;
531 
538 - initWithUInt64: (uint64_t)uint64;
539 
546 - initWithSize: (size_t)size;
547 
554 - initWithSSize: (ssize_t)ssize;
555 
562 - initWithIntMax: (intmax_t)intmax;
563 
571 - initWithUIntMax: (uintmax_t)uintmax;
572 
580 - initWithPtrDiff: (ptrdiff_t)ptrdiff;
581 
588 - initWithIntPtr: (intptr_t)intptr;
589 
597 - initWithUIntPtr: (uintptr_t)uintptr;
598 
605 - initWithFloat: (float)float_;
606 
613 - initWithDouble: (double)double_;
614 
620 - (of_number_type_t)type;
621 
627 - (bool)boolValue;
628 
634 - (signed char)charValue;
635 
641 - (signed short)shortValue;
642 
648 - (signed int)intValue;
649 
655 - (signed long)longValue;
656 
662 - (signed long long)longLongValue;
663 
669 - (unsigned char)unsignedCharValue;
670 
676 - (unsigned short)unsignedShortValue;
677 
683 - (unsigned int)unsignedIntValue;
684 
690 - (unsigned long)unsignedLongValue;
691 
697 - (unsigned long long)unsignedLongLongValue;
698 
704 - (int8_t)int8Value;
705 
711 - (int16_t)int16Value;
712 
718 - (int32_t)int32Value;
719 
725 - (int64_t)int64Value;
726 
732 - (uint8_t)uInt8Value;
733 
739 - (uint16_t)uInt16Value;
740 
746 - (uint32_t)uInt32Value;
747 
753 - (uint64_t)uInt64Value;
754 
760 - (size_t)sizeValue;
761 
767 - (ssize_t)sSizeValue;
768 
774 - (intmax_t)intMaxValue;
775 
781 - (uintmax_t)uIntMaxValue;
782 
788 - (ptrdiff_t)ptrDiffValue;
789 
795 - (intptr_t)intPtrValue;
796 
802 - (uintptr_t)uIntPtrValue;
803 
809 - (float)floatValue;
810 
816 - (double)doubleValue;
817 @end
818 
819 OF_ASSUME_NONNULL_END
820 
821 #ifndef NSINTEGER_DEFINED
822 /* Required for number literals to work */
823 @compatibility_alias NSNumber OFNumber;
824 #endif
Definition: OFNumber.h:88
of_number_type_t
The C type of a number stored in an OFNumber.
Definition: OFNumber.h:38
Definition: OFNumber.h:100
Definition: OFNumber.h:76
Definition: OFNumber.h:64
Definition: OFNumber.h:44
Definition: OFNumber.h:58
Definition: OFNumber.h:73
Definition: OFNumber.h:54
Definition: OFNumber.h:46
Definition: OFNumber.h:50
A protocol implemented by classes that support encoding to a JSON representation. ...
Definition: OFJSONRepresentation.h:38
Definition: OFNumber.h:48
Definition: OFNumber.h:97
Definition: OFNumber.h:40
Definition: OFNumber.h:82
A protocol implemented by classes that support encoding to a MessagePack representation.
Definition: OFMessagePackRepresentation.h:30
Provides a way to store a number in an object.
Definition: OFNumber.h:114
Definition: OFNumber.h:67
A protocol for the creation of copies.
Definition: OFObject.h:896
Definition: OFNumber.h:106
Definition: OFNumber.h:60
A protocol for comparing objects.
Definition: OFObject.h:933
Definition: OFNumber.h:62
The root class for all other classes inside ObjFW.
Definition: OFObject.h:364
Definition: OFNumber.h:79
Definition: OFNumber.h:102
Definition: OFNumber.h:104
A protocol for serializing objects.
Definition: OFSerialization.h:30
Definition: OFNumber.h:56
Definition: OFNumber.h:42
Definition: OFNumber.h:52
Definition: OFNumber.h:70
Definition: OFNumber.h:85
Definition: OFNumber.h:94
Definition: OFNumber.h:91