ObjFW  Check-in [612cd94090]

Overview
Comment:Make OFNumber a subclass of OFValue
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 612cd94090084b586b6f5b7c81cf6b3046b047c5f87b2b1e820b90aae64d8053
User & Date: js on 2018-02-11 12:15:14
Other Links: manifest | tags
Context
2018-02-11
14:33
Add exception for currentDirectoryPath failing check-in: d133fa0a89 user: js tags: trunk
12:15
Make OFNumber a subclass of OFValue check-in: 612cd94090 user: js tags: trunk
2018-02-10
20:20
configure: Run win64 tests using wine64 check-in: 48e1aad2cd user: js tags: trunk
Changes

Modified src/OFJSONRepresentation.h from [a2b7b0adc0] to [c8cfac8bfd].

10
11
12
13
14
15
16


17
18
19
20
21
22
23
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */



@class OFString;

OF_ASSUME_NONNULL_BEGIN

enum {
	OF_JSON_REPRESENTATION_PRETTY	  = 0x01,







>
>







10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 * the packaging of this file.
 *
 * Alternatively, it may be distributed under the terms of the GNU General
 * Public License, either version 2 or 3, which can be found in the file
 * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
 * file.
 */

#import "OFObject.h"

@class OFString;

OF_ASSUME_NONNULL_BEGIN

enum {
	OF_JSON_REPRESENTATION_PRETTY	  = 0x01,

Modified src/OFNumber.h from [2c125c945d] to [d08367a725].

24
25
26
27
28
29
30
31

32
33
34
35
36
37
38
39
40
41

#include "objfw-defs.h"

#ifdef OF_HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif

#import "OFObject.h"

#import "OFSerialization.h"
#import "OFJSONRepresentation.h"
#import "OFMessagePackRepresentation.h"

OF_ASSUME_NONNULL_BEGIN

/*! @file */

/*!
 * @brief The C type of a number stored in an OFNumber.







|
>

|
<







24
25
26
27
28
29
30
31
32
33
34

35
36
37
38
39
40
41

#include "objfw-defs.h"

#ifdef OF_HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif

#import "OFJSONRepresentation.h"
#import "OFMessagePackRepresentation.h"
#import "OFSerialization.h"
#import "OFValue.h"


OF_ASSUME_NONNULL_BEGIN

/*! @file */

/*!
 * @brief The C type of a number stored in an OFNumber.
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
} of_number_type_t;

/*!
 * @class OFNumber OFNumber.h ObjFW/OFNumber.h
 *
 * @brief Provides a way to store a number in an object.
 */
@interface OFNumber: OFObject <OFCopying, OFComparing, OFSerialization,
    OFJSONRepresentation, OFMessagePackRepresentation>
{
	union of_number_value {
		bool		   bool_;
		signed char	   sChar;
		signed short	   sShort;
		signed int	   sInt;







|







112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
} of_number_type_t;

/*!
 * @class OFNumber OFNumber.h ObjFW/OFNumber.h
 *
 * @brief Provides a way to store a number in an object.
 */
@interface OFNumber: OFValue <OFComparing, OFSerialization,
    OFJSONRepresentation, OFMessagePackRepresentation>
{
	union of_number_value {
		bool		   bool_;
		signed char	   sChar;
		signed short	   sShort;
		signed int	   sInt;
292
293
294
295
296
297
298











299
300
301
302
303
304
305
 */
@property (readonly, nonatomic) float floatValue;

/*!
 * @brief The OFNumber as a `double`.
 */
@property (readonly, nonatomic) double doubleValue;












/*!
 * @brief Creates a new OFNumber with the specified `bool`.
 *
 * @param bool_ A `bool` which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */







>
>
>
>
>
>
>
>
>
>
>







292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
 */
@property (readonly, nonatomic) float floatValue;

/*!
 * @brief The OFNumber as a `double`.
 */
@property (readonly, nonatomic) double doubleValue;

#ifdef OF_HAVE_UNAVAILABLE
+ (instancetype)valueWithBytes: (const void *)bytes
		      objCType: (const char *)objCType OF_UNAVAILABLE;
+ (instancetype)valueWithPointer: (const void *)pointer OF_UNAVAILABLE;
+ (instancetype)valueWithNonretainedObject: (id)object OF_UNAVAILABLE;
+ (instancetype)valueWithRange: (of_range_t)range OF_UNAVAILABLE;
+ (instancetype)valueWithPoint: (of_point_t)point OF_UNAVAILABLE;
+ (instancetype)valueWithDimension: (of_dimension_t)dimension OF_UNAVAILABLE;
+ (instancetype)valueWithRectangle: (of_rectangle_t)rectangle OF_UNAVAILABLE;
#endif

/*!
 * @brief Creates a new OFNumber with the specified `bool`.
 *
 * @param bool_ A `bool` which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */
518
519
520
521
522
523
524










525
526
527
528
529
530
531
 *
 * @param double_ A `double` which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */
+ (instancetype)numberWithDouble: (double)double_;

- (instancetype)init OF_UNAVAILABLE;











/*!
 * @brief Initializes an already allocated OFNumber with the specified `bool`.
 *
 * @param bool_ A `bool` which the OFNumber should contain
 * @return An initialized OFNumber
 */







>
>
>
>
>
>
>
>
>
>







529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
 *
 * @param double_ A `double` which the OFNumber should contain
 * @return A new autoreleased OFNumber
 */
+ (instancetype)numberWithDouble: (double)double_;

- (instancetype)init OF_UNAVAILABLE;
#ifdef OF_HAVE_UNAVAILABLE
- (instancetype)initWithBytes: (const void *)bytes
		     objCType: (const char *)objCType OF_UNAVAILABLE;
- (instancetype)initWithPointer: (const void *)pointer OF_UNAVAILABLE;
- (instancetype)initWithNonretainedObject: (id)object OF_UNAVAILABLE;
- (instancetype)initWithRange: (of_range_t)range OF_UNAVAILABLE;
- (instancetype)initWithPoint: (of_point_t)point OF_UNAVAILABLE;
- (instancetype)initWithDimension: (of_dimension_t)dimension OF_UNAVAILABLE;
- (instancetype)initWithRectangle: (of_rectangle_t)rectangle OF_UNAVAILABLE;
#endif

/*!
 * @brief Initializes an already allocated OFNumber with the specified `bool`.
 *
 * @param bool_ A `bool` which the OFNumber should contain
 * @return An initialized OFNumber
 */

Modified src/OFNumber.m from [63e83c2f21] to [15e27ceca1].

587
588
589
590
591
592
593

















































































































































































































































594
595
596
597
598
599
600
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}


















































































































































































































































- (bool)boolValue
{
	RETURN_AS(bool)
}

- (signed char)charValue







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
	} @catch (id e) {
		[self release];
		@throw e;
	}

	return self;
}

- (const char *)objCType
{
	switch (_type) {
	case OF_NUMBER_TYPE_BOOL:
		return @encode(bool);
	case OF_NUMBER_TYPE_CHAR:
		return @encode(signed char);
	case OF_NUMBER_TYPE_SHORT:
		return @encode(signed short);
	case OF_NUMBER_TYPE_INT:
		return @encode(signed int);
	case OF_NUMBER_TYPE_LONG:
		return @encode(signed long);
	case OF_NUMBER_TYPE_LONGLONG:
		return @encode(signed long long);
	case OF_NUMBER_TYPE_UCHAR:
		return @encode(unsigned char);
	case OF_NUMBER_TYPE_USHORT:
		return @encode(unsigned short);
	case OF_NUMBER_TYPE_UINT:
		return @encode(unsigned int);
	case OF_NUMBER_TYPE_ULONG:
		return @encode(unsigned long);
	case OF_NUMBER_TYPE_ULONGLONG:
		return @encode(unsigned long long);
	case OF_NUMBER_TYPE_INT8:
		return @encode(int8_t);
	case OF_NUMBER_TYPE_INT16:
		return @encode(int16_t);
	case OF_NUMBER_TYPE_INT32:
		return @encode(int32_t);
	case OF_NUMBER_TYPE_INT64:
		return @encode(int64_t);
	case OF_NUMBER_TYPE_UINT8:
		return @encode(uint8_t);
	case OF_NUMBER_TYPE_UINT16:
		return @encode(uint16_t);
	case OF_NUMBER_TYPE_UINT32:
		return @encode(uint32_t);
	case OF_NUMBER_TYPE_UINT64:
		return @encode(uint64_t);
	case OF_NUMBER_TYPE_SIZE:
		return @encode(size_t);
	case OF_NUMBER_TYPE_SSIZE:
		return @encode(ssize_t);
	case OF_NUMBER_TYPE_INTMAX:
		return @encode(intmax_t);
	case OF_NUMBER_TYPE_UINTMAX:
		return @encode(uintmax_t);
	case OF_NUMBER_TYPE_PTRDIFF:
		return @encode(ptrdiff_t);
	case OF_NUMBER_TYPE_INTPTR:
		return @encode(intptr_t);
	case OF_NUMBER_TYPE_UINTPTR:
		return @encode(uintptr_t);
	case OF_NUMBER_TYPE_FLOAT:
		return @encode(float);
	case OF_NUMBER_TYPE_DOUBLE:
		return @encode(double);
	default:
		@throw [OFInvalidFormatException exception];
	}
}

- (void)getValue: (void *)value
	    size: (size_t)size
{
	switch (_type) {
	case OF_NUMBER_TYPE_BOOL:
		if (size != sizeof(bool))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.bool_, sizeof(bool));
		break;
	case OF_NUMBER_TYPE_CHAR:
		if (size != sizeof(signed char))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.sChar, sizeof(signed char));
		break;
	case OF_NUMBER_TYPE_SHORT:
		if (size != sizeof(signed short))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.sShort, sizeof(signed short));
		break;
	case OF_NUMBER_TYPE_INT:
		if (size != sizeof(signed int))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.sInt, sizeof(signed int));
		break;
	case OF_NUMBER_TYPE_LONG:
		if (size != sizeof(signed long))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.sLong, sizeof(signed long));
		break;
	case OF_NUMBER_TYPE_LONGLONG:
		if (size != sizeof(signed long long))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.sLongLong, sizeof(signed long long));
		break;
	case OF_NUMBER_TYPE_UCHAR:
		if (size != sizeof(unsigned char))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.uChar, sizeof(unsigned char));
		break;
	case OF_NUMBER_TYPE_USHORT:
		if (size != sizeof(unsigned short))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.uShort, sizeof(unsigned short));
		break;
	case OF_NUMBER_TYPE_UINT:
		if (size != sizeof(unsigned int))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.uInt, sizeof(unsigned int));
		break;
	case OF_NUMBER_TYPE_ULONG:
		if (size != sizeof(unsigned long))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.uLong, sizeof(unsigned long));
		break;
	case OF_NUMBER_TYPE_ULONGLONG:
		if (size != sizeof(unsigned long long))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.uLongLong, sizeof(unsigned long long));
		break;
	case OF_NUMBER_TYPE_INT8:
		if (size != sizeof(int8_t))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.int8, sizeof(int8_t));
		break;
	case OF_NUMBER_TYPE_INT16:
		if (size != sizeof(int16_t))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.int16, sizeof(int16_t));
		break;
	case OF_NUMBER_TYPE_INT32:
		if (size != sizeof(int32_t))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.int32, sizeof(int32_t));
		break;
	case OF_NUMBER_TYPE_INT64:
		if (size != sizeof(int64_t))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.int64, sizeof(int64_t));
		break;
	case OF_NUMBER_TYPE_UINT8:
		if (size != sizeof(uint8_t))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.uInt8, sizeof(uint8_t));
		break;
	case OF_NUMBER_TYPE_UINT16:
		if (size != sizeof(uint16_t))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.uInt16, sizeof(uint16_t));
		break;
	case OF_NUMBER_TYPE_UINT32:
		if (size != sizeof(uint32_t))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.uInt32, sizeof(uint32_t));
		break;
	case OF_NUMBER_TYPE_UINT64:
		if (size != sizeof(uint64_t))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.uInt64, sizeof(uint64_t));
		break;
	case OF_NUMBER_TYPE_SIZE:
		if (size != sizeof(size_t))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.size, sizeof(size_t));
		break;
	case OF_NUMBER_TYPE_SSIZE:
		if (size != sizeof(ssize_t))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.sSize, sizeof(ssize_t));
		break;
	case OF_NUMBER_TYPE_INTMAX:
		if (size != sizeof(intmax_t))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.intMax, sizeof(intmax_t));
		break;
	case OF_NUMBER_TYPE_UINTMAX:
		if (size != sizeof(uintmax_t))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.uIntMax, sizeof(uintmax_t));
		break;
	case OF_NUMBER_TYPE_PTRDIFF:
		if (size != sizeof(ptrdiff_t))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.ptrDiff, sizeof(ptrdiff_t));
		break;
	case OF_NUMBER_TYPE_INTPTR:
		if (size != sizeof(intptr_t))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.intPtr, sizeof(intptr_t));
		break;
	case OF_NUMBER_TYPE_UINTPTR:
		if (size != sizeof(uintptr_t))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.uIntPtr, sizeof(uintptr_t));
		break;
	case OF_NUMBER_TYPE_FLOAT:
		if (size != sizeof(float))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.float_, sizeof(float));
		break;
	case OF_NUMBER_TYPE_DOUBLE:
		if (size != sizeof(double))
			@throw [OFOutOfRangeException exception];

		memcpy(value, &_value.double_, sizeof(double));
		break;
	default:
		@throw [OFInvalidFormatException exception];
	}
}

- (bool)boolValue
{
	RETURN_AS(bool)
}

- (signed char)charValue

Modified src/macros.h from [6b06f3d8b7] to [579cf46e72].

231
232
233
234
235
236
237

238
239
240
241
242
243
244
# define OF_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
#else
# define OF_WARN_UNUSED_RESULT
#endif

#if __has_attribute(__unavailable__)
# define OF_UNAVAILABLE __attribute__((__unavailable__))

#else
# define OF_UNAVAILABLE
#endif

#if __has_attribute(__objc_requires_super__)
# define OF_REQUIRES_SUPER __attribute__((__objc_requires_super__))
#else







>







231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
# define OF_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__))
#else
# define OF_WARN_UNUSED_RESULT
#endif

#if __has_attribute(__unavailable__)
# define OF_UNAVAILABLE __attribute__((__unavailable__))
# define OF_HAVE_UNAVAILABLE
#else
# define OF_UNAVAILABLE
#endif

#if __has_attribute(__objc_requires_super__)
# define OF_REQUIRES_SUPER __attribute__((__objc_requires_super__))
#else