ObjFW  Check-in [7b91334e8e]

Overview
Comment:OFValue: Add OFVector[34]D
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 7b91334e8ec929675e865761d55d05a94ea12173736df442df32010d2fa39d78
User & Date: js on 2023-08-09 22:53:14
Other Links: manifest | tags
Context
2023-08-12
12:05
OFArray: Add designated initializer check-in: 47860977ff user: js tags: trunk
2023-08-09
22:53
OFValue: Add OFVector[34]D check-in: 7b91334e8e user: js tags: trunk
22:39
OFValue: Improve -[description] check-in: 772e8b8f78 user: js tags: trunk
Changes

Modified src/OFValue.h from [268d38bfae] to [fec80b138b].

60
61
62
63
64
65
66
67
68
69
70
71
72














73
74
75
76
77
78
79
 * @brief The value as an OFSize.
 *
 * @throw OFOutOfRangeException The value is not OFSize-sized
 */
@property (readonly, nonatomic) OFSize sizeValue;

/**
 * @brief The value as a OFRect.
 *
 * @throw OFOutOfRangeException The value is not OFRect-sized
 */
@property (readonly, nonatomic) OFRect rectValue;















/**
 * @brief Creates a new, autorelease OFValue with the specified bytes of the
 *	  specified type.
 *
 * @param bytes The bytes containing the value
 * @param objCType The ObjC type encoding for the value
 * @return A new, autoreleased OFValue







|





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







60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
 * @brief The value as an OFSize.
 *
 * @throw OFOutOfRangeException The value is not OFSize-sized
 */
@property (readonly, nonatomic) OFSize sizeValue;

/**
 * @brief The value as an OFRect.
 *
 * @throw OFOutOfRangeException The value is not OFRect-sized
 */
@property (readonly, nonatomic) OFRect rectValue;

/**
 * @brief The value as an OFVector3D.
 *
 * @throw OFOutOfRangeException The value is not OFVector3D-sized
 */
@property (readonly, nonatomic) OFVector3D vector3DValue;

/**
 * @brief The value as an OFVector4D.
 *
 * @throw OFOutOfRangeException The value is not OFVector4D-sized
 */
@property (readonly, nonatomic) OFVector4D vector4DValue;

/**
 * @brief Creates a new, autorelease OFValue with the specified bytes of the
 *	  specified type.
 *
 * @param bytes The bytes containing the value
 * @param objCType The ObjC type encoding for the value
 * @return A new, autoreleased OFValue
132
133
134
135
136
137
138


















139
140
141
142
143
144
145
 *	  rectangle.
 *
 * @param rect The rectangle the OFValue should contain
 * @return A new, autoreleased OFValue
 */
+ (instancetype)valueWithRect: (OFRect)rect;



















/**
 * @brief Initializes an already allocated OFValue with the specified bytes of
 *	  the specified type.
 *
 * @param bytes The bytes containing the value
 * @param objCType The ObjC type encoding for the value
 * @return An initialized OFValue







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







146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
 *	  rectangle.
 *
 * @param rect The rectangle the OFValue should contain
 * @return A new, autoreleased OFValue
 */
+ (instancetype)valueWithRect: (OFRect)rect;

/**
 * @brief Creates a new, autoreleased OFValue containing the specified
 *	  3D vector.
 *
 * @param vector3D The 3D vector the OFValue should contain
 * @return A new, autoreleased OFValue
 */
+ (instancetype)valueWithVector3D: (OFVector3D)vector3D;

/**
 * @brief Creates a new, autoreleased OFValue containing the specified
 *	  4D vector.
 *
 * @param vector4D The 4D vector the OFValue should contain
 * @return A new, autoreleased OFValue
 */
+ (instancetype)valueWithVector4D: (OFVector4D)vector4D;

/**
 * @brief Initializes an already allocated OFValue with the specified bytes of
 *	  the specified type.
 *
 * @param bytes The bytes containing the value
 * @param objCType The ObjC type encoding for the value
 * @return An initialized OFValue

Modified src/OFValue.m from [358230f36d] to [d066bfb20d].

103
104
105
106
107
108
109














110
111
112
113
114
115
116
}

+ (instancetype)valueWithRect: (OFRect)rect
{
	return [[[OFValue alloc] initWithBytes: &rect
				      objCType: @encode(OFRect)] autorelease];
}















- (instancetype)initWithBytes: (const void *)bytes
		     objCType: (const char *)objCType
{
	if ([self isMemberOfClass: [OFValue class]]) {
		@try {
			[self doesNotRecognizeSelector: _cmd];







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







103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
}

+ (instancetype)valueWithRect: (OFRect)rect
{
	return [[[OFValue alloc] initWithBytes: &rect
				      objCType: @encode(OFRect)] autorelease];
}

+ (instancetype)valueWithVector3D: (OFVector3D)vector3D
{
	return [[[OFValue alloc]
	    initWithBytes: &vector3D
		 objCType: @encode(OFVector3D)] autorelease];
}

+ (instancetype)valueWithVector4D: (OFVector4D)vector4D
{
	return [[[OFValue alloc]
	    initWithBytes: &vector4D
		 objCType: @encode(OFVector4D)] autorelease];
}

- (instancetype)initWithBytes: (const void *)bytes
		     objCType: (const char *)objCType
{
	if ([self isMemberOfClass: [OFValue class]]) {
		@try {
			[self doesNotRecognizeSelector: _cmd];
245
246
247
248
249
250
251














252
253
254
255
256
257
258

- (OFRect)rectValue
{
	OFRect ret;
	[self getValue: &ret size: sizeof(ret)];
	return ret;
}















- (OFString *)description
{
	const char *objCType = self.objCType;
	OFMutableString *ret;
	size_t size;
	unsigned char *value;







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







259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286

- (OFRect)rectValue
{
	OFRect ret;
	[self getValue: &ret size: sizeof(ret)];
	return ret;
}

- (OFVector3D)vector3DValue
{
	OFVector3D ret;
	[self getValue: &ret size: sizeof(ret)];
	return ret;
}

- (OFVector4D)vector4DValue
{
	OFVector4D ret;
	[self getValue: &ret size: sizeof(ret)];
	return ret;
}

- (OFString *)description
{
	const char *objCType = self.objCType;
	OFMutableString *ret;
	size_t size;
	unsigned char *value;
282
283
284
285
286
287
288















289
290
291
292
293
294
295
	    strcmp(objCType, @encode(const OFRect)) == 0) {
		OFRect rectValue;
		[self getValue: &rectValue size: sizeof(rectValue)];
		return [OFString stringWithFormat:
		    @"<OFValue: OFRect { %g, %g, %g, %g }>",
		    rectValue.origin.x, rectValue.origin.y,
		    rectValue.size.width, rectValue.size.height];















	}

	ret = [OFMutableString stringWithString: @"<OFValue: "];
	size = OFSizeOfTypeEncoding(objCType);
	value = OFAllocMemory(1, size);
	@try {
		[self getValue: value size: size];







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







310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
	    strcmp(objCType, @encode(const OFRect)) == 0) {
		OFRect rectValue;
		[self getValue: &rectValue size: sizeof(rectValue)];
		return [OFString stringWithFormat:
		    @"<OFValue: OFRect { %g, %g, %g, %g }>",
		    rectValue.origin.x, rectValue.origin.y,
		    rectValue.size.width, rectValue.size.height];
	} else if (strcmp(objCType, @encode(OFVector3D)) == 0 ||
	    strcmp(objCType, @encode(const OFVector3D)) == 0) {
		OFVector3D vector3DValue;
		[self getValue: &vector3DValue size: sizeof(vector3DValue)];
		return [OFString stringWithFormat:
		    @"<OFValue: OFVector3D { %g, %g, %g }>",
		    vector3DValue.x, vector3DValue.y, vector3DValue.z];
	} else if (strcmp(objCType, @encode(OFVector4D)) == 0 ||
	    strcmp(objCType, @encode(const OFVector4D)) == 0) {
		OFVector4D vector4DValue;
		[self getValue: &vector4DValue size: sizeof(vector4DValue)];
		return [OFString stringWithFormat:
		    @"<OFValue: OFVector4D { %g, %g, %g, %g }>",
		    vector4DValue.x, vector4DValue.y, vector4DValue.z,
		    vector4DValue.w];
	}

	ret = [OFMutableString stringWithString: @"<OFValue: "];
	size = OFSizeOfTypeEncoding(objCType);
	value = OFAllocMemory(1, size);
	@try {
		[self getValue: value size: size];