ObjFW  Diff

Differences From Artifact [75df3d0578]:

To Artifact [60c8cd9af5]:


16
17
18
19
20
21
22

23
24
25
26
27
28
29

#include "config.h"

#include "assert.h"

#import "OFList.h"
#import "OFString.h"

#import "OFAutoreleasePool.h"

#import "OFEnumerationMutationException.h"

#import "macros.h"

@implementation OFList







>







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

#include "config.h"

#include "assert.h"

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

#import "OFEnumerationMutationException.h"

#import "macros.h"

@implementation OFList
319
320
321
322
323
324
325
326
327
328
329

330
331
332
333
334
335
336


337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
	 * to be OFString*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.
	 */
	ret->isa = [OFString class];
	return ret;
}

- (OFString*)stringBySerializing
{
	OFMutableString *ret;
	OFAutoreleasePool *pool;

	of_list_object_t *iter;

	if (count == 0)
		return @"(list,mutable)[]";

	ret = [OFMutableString stringWithString: @"(list,mutable)[\n"];
	pool = [[OFAutoreleasePool alloc] init];



	for (iter = firstListObject; iter != NULL; iter = iter->next) {
		[ret appendString: [iter->object stringBySerializing]];

		if (iter->next != NULL)
			[ret appendString: @",\n"];

		[pool releaseObjects];
	}
	[ret replaceOccurrencesOfString: @"\n"
			     withString: @"\n\t"];
	[ret appendString: @"\n]"];

	[pool release];

	/*
	 * Class swizzle the string to be immutable. We declared the return type
	 * to be OFString*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.
	 */
	ret->isa = [OFString class];
	return ret;
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
			   objects: (id*)objects
			     count: (int)count_
{
	of_list_object_t **list_obj = (of_list_object_t**)state->extra;

	state->itemsPtr = objects;
	state->mutationsPtr = &mutations;

	if (state->state == 0) {
		*list_obj = firstListObject;
		state->state = 1;
	}

	if (*list_obj == NULL)
		return 0;

	objects[0] = (*list_obj)->object;
	*list_obj = (*list_obj)->next;
	return 1;
}

- (OFEnumerator*)objectEnumerator
{
	return [[[OFListEnumerator alloc]
	        initWithList: self







|

<

>


|
|

<

>
>


<
|
<
<
<


<
<
<



<
<
<
<
<
<
|






|





|



|


|
|







320
321
322
323
324
325
326
327
328

329
330
331
332
333
334
335

336
337
338
339
340

341



342
343



344
345
346






347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
	 * to be OFString*, so it can't be modified anyway. But not swizzling it
	 * would create a real copy each time -[copy] is called.
	 */
	ret->isa = [OFString class];
	return ret;
}

- (OFXMLElement*)XMLElementBySerializing
{

	OFAutoreleasePool *pool;
	OFXMLElement *element;
	of_list_object_t *iter;

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


	pool = [[OFAutoreleasePool alloc] init];
	[element addAttributeWithName: @"class"
			  stringValue: [self className]];

	for (iter = firstListObject; iter != NULL; iter = iter->next) {

		[element addChild: [iter->object XMLElementBySerializing]];



		[pool releaseObjects];
	}




	[pool release];







	return element;
}

- (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state
			   objects: (id*)objects
			     count: (int)count_
{
	of_list_object_t **listObject = (of_list_object_t**)state->extra;

	state->itemsPtr = objects;
	state->mutationsPtr = &mutations;

	if (state->state == 0) {
		*listObject = firstListObject;
		state->state = 1;
	}

	if (*listObject == NULL)
		return 0;

	objects[0] = (*listObject)->object;
	*listObject = (*listObject)->next;
	return 1;
}

- (OFEnumerator*)objectEnumerator
{
	return [[[OFListEnumerator alloc]
	        initWithList: self