ObjFW  Diff

Differences From Artifact [2324ed47e6]:

To Artifact [01b0cb5868]:


16
17
18
19
20
21
22


23
24
25
26
27
28
29

#include "config.h"

#include <math.h>

#import "OFNumber.h"
#import "OFString.h"



#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"

#import "macros.h"

#define RETURN_AS(t)							\







>
>







16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31

#include "config.h"

#include <math.h>

#import "OFNumber.h"
#import "OFString.h"
#import "OFXMLElement.h"
#import "OFAutoreleasePool.h"

#import "OFInvalidFormatException.h"
#import "OFNotImplementedException.h"

#import "macros.h"

#define RETURN_AS(t)							\
1086
1087
1088
1089
1090
1091
1092
1093
1094












1095
1096

1097

1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130

1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164

1165
1166
1167
1168

1169

1170
1171

1172

1173
1174
1175
1176




1177
	case OF_NUMBER_DOUBLE:
		return [OFString stringWithFormat: @"%lf", value.double_];
	default:
		@throw [OFInvalidFormatException newWithClass: isa];
	}
}

- (OFString*)stringBySerializing
{












	switch (type) {
	case OF_NUMBER_BOOL:

		return (value.bool_ ? @"<BOOL>1" : @"<BOOL>0");

	case OF_NUMBER_UCHAR:
		return [OFString stringWithFormat: @"<unsigned char>%hhu",
						   value.uchar];
	case OF_NUMBER_USHORT:
		return [OFString stringWithFormat: @"<unsigned short>%hu",
						   value.ushort];
	case OF_NUMBER_UINT:
		return [OFString stringWithFormat: @"<unsigned int>%u",
						   value.uint];
	case OF_NUMBER_ULONG:
		return [OFString stringWithFormat: @"<unsigned long>%lu",
						   value.ulong];
	case OF_NUMBER_UINT8:
		return [OFString stringWithFormat: @"<uint8_t>%" @PRIu8,
						   value.uint8];
	case OF_NUMBER_UINT16:
		return [OFString stringWithFormat: @"<uint16_t>%" @PRIu16,
						   value.uint16];
	case OF_NUMBER_UINT32:
		return [OFString stringWithFormat: @"<uint32_t>%" @PRIu32,
						   value.uint32];
	case OF_NUMBER_UINT64:
		return [OFString stringWithFormat: @"<uint64_t>%" @PRIu64,
						   value.uint64];
	case OF_NUMBER_SIZE:
		return [OFString stringWithFormat: @"<size_t>%ju",
						   (uintmax_t)value.size];
	case OF_NUMBER_UINTMAX:
		return [OFString stringWithFormat: @"<uintmax_t>%ju",
						   value.uintmax];
	case OF_NUMBER_UINTPTR:
		return [OFString stringWithFormat: @"<uintptr_t>%" @PRIuPTR,
						   value.uintptr];

	case OF_NUMBER_CHAR:
		return [OFString stringWithFormat: @"<char>%hhd",
						   value.char_];
	case OF_NUMBER_SHORT:
		return [OFString stringWithFormat: @"<short>%hd",
						   value.short_];
	case OF_NUMBER_INT:
		return [OFString stringWithFormat: @"<int>%d",
						   value.int_];
	case OF_NUMBER_LONG:
		return [OFString stringWithFormat: @"<long>%ld",
						   value.long_];
	case OF_NUMBER_INT8:
		return [OFString stringWithFormat: @"<int8_t>%" @PRId8,
						   value.int8];
	case OF_NUMBER_INT16:
		return [OFString stringWithFormat: @"<int16_t>%" @PRId16,
						   value.int16];
	case OF_NUMBER_INT32:
		return [OFString stringWithFormat: @"<int32_t>%" @PRId32,
						   value.int32];
	case OF_NUMBER_INT64:
		return [OFString stringWithFormat: @"<int64_t>%" @PRId64,
						   value.int64];
	case OF_NUMBER_SSIZE:
		return [OFString stringWithFormat: @"<ssize_t>%jd",
						   (intmax_t)value.ssize];
	case OF_NUMBER_INTMAX:
		return [OFString stringWithFormat: @"<intmax_t>%jd",
						   value.intmax];
	case OF_NUMBER_PTRDIFF:
		return [OFString stringWithFormat: @"<ptrdiff_t>%td" @PRIdPTR,
						   value.ptrdiff];
	case OF_NUMBER_INTPTR:

		return [OFString stringWithFormat: @"<intptr_t>%" @PRIdPTR,
						   value.intptr];
	case OF_NUMBER_FLOAT:
		return [OFString stringWithFormat: @"<float>%f",

						   value.float_];

	case OF_NUMBER_DOUBLE:
		return [OFString stringWithFormat: @"<double>%lf",

						   value.double_];

	default:
		@throw [OFInvalidFormatException newWithClass: isa];
	}
}




@end







|

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


>
|
>

<
<

<
<

<
<

<
<

<
<

<
<

<
<

<
<

<
<

<
<

|
|
>

<
<

<
<

<
<

<
<

<
<

<
<

<
<

<
<

<
<

<
<

<
<

>
|
|

<
>
|
>

<
>
|
>



|
>
>
>
>

1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114


1115


1116


1117


1118


1119


1120


1121


1122


1123


1124
1125
1126
1127
1128


1129


1130


1131


1132


1133


1134


1135


1136


1137


1138


1139
1140
1141
1142
1143

1144
1145
1146
1147

1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
	case OF_NUMBER_DOUBLE:
		return [OFString stringWithFormat: @"%lf", value.double_];
	default:
		@throw [OFInvalidFormatException newWithClass: isa];
	}
}

- (OFXMLElement*)XMLElementBySerializing
{
	OFAutoreleasePool *pool;
	OFXMLElement *element;

	element = [OFXMLElement elementWithName: @"object"
				      namespace: OF_SERIALIZATION_NS];

	pool = [[OFAutoreleasePool alloc] init];

	[element addAttributeWithName: @"class"
			  stringValue: [self className]];
	[element setStringValue: [self description]];

	switch (type) {
	case OF_NUMBER_BOOL:
		[element addAttributeWithName: @"type"
				  stringValue: @"boolean"];
		break;
	case OF_NUMBER_UCHAR:


	case OF_NUMBER_USHORT:


	case OF_NUMBER_UINT:


	case OF_NUMBER_ULONG:


	case OF_NUMBER_UINT8:


	case OF_NUMBER_UINT16:


	case OF_NUMBER_UINT32:


	case OF_NUMBER_UINT64:


	case OF_NUMBER_SIZE:


	case OF_NUMBER_UINTMAX:


	case OF_NUMBER_UINTPTR:
		[element addAttributeWithName: @"type"
				  stringValue: @"unsigned"];
		break;
	case OF_NUMBER_CHAR:


	case OF_NUMBER_SHORT:


	case OF_NUMBER_INT:


	case OF_NUMBER_LONG:


	case OF_NUMBER_INT8:


	case OF_NUMBER_INT16:


	case OF_NUMBER_INT32:


	case OF_NUMBER_INT64:


	case OF_NUMBER_SSIZE:


	case OF_NUMBER_INTMAX:


	case OF_NUMBER_PTRDIFF:


	case OF_NUMBER_INTPTR:
		[element addAttributeWithName: @"type"
				  stringValue: @"signed"];
		break;
	case OF_NUMBER_FLOAT:

		[element addAttributeWithName: @"type"
				  stringValue: @"float"];
		break;
	case OF_NUMBER_DOUBLE:

		[element addAttributeWithName: @"type"
				  stringValue: @"double"];
		break;
	default:
		@throw [OFInvalidFormatException newWithClass: isa];
	}

	[pool release];

	return element;
}
@end