ObjFW  Check-in [b2c9f574cb]

Overview
Comment:Don't put void* in lists, but objects.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: b2c9f574cb6456f0707a0b3c357f2bb8e812119145908f772ce5b66d1f3d6046
User & Date: js on 2008-12-20 14:41:10
Other Links: manifest | tags
Context
2008-12-21
15:42
Initial UTF-8 support for OFString. check-in: b4a4e95798 user: js tags: trunk
2008-12-20
14:41
Don't put void* in lists, but objects. check-in: b2c9f574cb user: js tags: trunk
14:26
Fix printf in tests. check-in: b023058e08 user: js tags: trunk
Changes

Modified TODO from [f827867bc5] to [db83e9cc17].



1
2
3
4
5
6
7


Tests for OFFile.

OFBase64

OFDirectory
OFDictionary
OFSortedArray
>
>







1
2
3
4
5
6
7
8
9
OFInteger

Tests for OFFile.

OFBase64

OFDirectory
OFDictionary
OFSortedArray

Modified src/OFList.h from [304e257df3] to [bd47bd6017].

49
50
51
52
53
54
55
56
57
58
59
 * \param obj An OFListObject
 */
- add: (OFListObject*)obj;

/**
 * Creates a new OFListObject and adds it to the OFList.
 *
 * \param ptr Pointer to the data for the OFListObject which will be added
 */
- addNew: (void*)ptr;
@end







|

|

49
50
51
52
53
54
55
56
57
58
59
 * \param obj An OFListObject
 */
- add: (OFListObject*)obj;

/**
 * Creates a new OFListObject and adds it to the OFList.
 *
 * \param obj A data object for the OFListObject which will be added
 */
- addNew: (id)obj;
@end

Modified src/OFList.m from [91a37e1146] to [4f5a56511d].

69
70
71
72
73
74
75
76
77
78
79
80
	[last setNext: obj];

	last = obj;

	return self;
}

- addNew: (void*)ptr
{
	return [self add: [OFListObject newWithData: ptr]];
}
@end







|

|


69
70
71
72
73
74
75
76
77
78
79
80
	[last setNext: obj];

	last = obj;

	return self;
}

- addNew: (id)obj
{
	return [self add: [OFListObject newWithData: obj]];
}
@end

Modified src/OFListObject.h from [a259bd4ceb] to [c773fcc63a].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#import "OFObject.h"

/**
 * The OFListObject class is a class for objects to be stored in an OFObject.
 */
@interface OFListObject: OFObject
{
	void	     *data;
	OFListObject *next;
	OFListObject *prev;
}

/**
 * \param The data the OFListObject should contain
 * \return A new OFListObject.
 */
+ newWithData: (void*)ptr;

/**
 * Initializes an already allocated OFListObjeect.
 *
 * \param The data the OFListObject should contain
 * \return An initialized OFListObject.
 */
- initWithData: (void*)ptr;

/**
 * Free the OFListObject and the data it contains.
 */
- freeIncludingData;

/**
 * \return The data included in the OFListObject
 */
- (void*)data;

/**
 * \return The next OFListObject in the OFList
 */
- (OFListObject*)next;

/**







|





|


|




|


|







|

|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#import "OFObject.h"

/**
 * The OFListObject class is a class for objects to be stored in an OFObject.
 */
@interface OFListObject: OFObject
{
	id	     data;
	OFListObject *next;
	OFListObject *prev;
}

/**
 * \param obj The data object the OFListObject should contain
 * \return A new OFListObject.
 */
+ newWithData: (id)obj;

/**
 * Initializes an already allocated OFListObjeect.
 *
 * \param obj The data object the OFListObject should contain
 * \return An initialized OFListObject.
 */
- initWithData: (id)obj;

/**
 * Free the OFListObject and the data it contains.
 */
- freeIncludingData;

/**
 * \return The data object included in the OFListObject
 */
- (id)data;

/**
 * \return The next OFListObject in the OFList
 */
- (OFListObject*)next;

/**

Modified src/OFListObject.m from [35f5ab154e] to [c1c0822d3e].

12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#import "config.h"

#import <stdlib.h>

#import "OFListObject.h"

@implementation OFListObject
+ newWithData: (void*)ptr
{
	return [[self alloc] initWithData: ptr];
}

- initWithData: (void*)ptr
{
	if ((self = [super init])) {
		next = nil;
		prev = nil;
		data = ptr;
	}

	return self;
}

- freeIncludingData
{
	if (data != NULL)
		free(data);

	return [super free];
}

- (void*)data
{
	return data;
}

- (OFListObject*)next
{
	return next;







|

|


|




|







|
|




|







12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#import "config.h"

#import <stdlib.h>

#import "OFListObject.h"

@implementation OFListObject
+ newWithData: (id)obj
{
	return [[self alloc] initWithData: obj];
}

- initWithData: (id)obj
{
	if ((self = [super init])) {
		next = nil;
		prev = nil;
		data = obj;
	}

	return self;
}

- freeIncludingData
{
	if (data != nil)
		[data free];

	return [super free];
}

- (id)data
{
	return data;
}

- (OFListObject*)next
{
	return next;

Modified tests/OFList/OFList.m from [74e719b9d6] to [f3b973c1b4].

53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
	list = [OFList new];
 
	[list addNew: [OFString newFromCString: strings[0]]];
	[list addNew: [OFString newFromCString: strings[1]]];
	[list addNew: [OFString newFromCString: strings[2]]];
 
	for (iter = [list first], i = 0; iter != nil; iter = [iter next], i++)
		if (!strcmp([(OFString*)[iter data] cString], strings[i]))
			SUCCESS
		else
			FAIL

	CHECK(!strcmp([(OFString*)[[list first] data] cString], strings[0]))
	CHECK(!strcmp([(OFString*)[[list last] data] cString], strings[2]))

	puts("");
 
	[list freeIncludingData];

	return 0;
}







|




|
|







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
	list = [OFList new];
 
	[list addNew: [OFString newFromCString: strings[0]]];
	[list addNew: [OFString newFromCString: strings[1]]];
	[list addNew: [OFString newFromCString: strings[2]]];
 
	for (iter = [list first], i = 0; iter != nil; iter = [iter next], i++)
		if (!strcmp([[iter data] cString], strings[i]))
			SUCCESS
		else
			FAIL

	CHECK(!strcmp([[[list first] data] cString], strings[0]))
	CHECK(!strcmp([[[list last] data] cString], strings[2]))

	puts("");
 
	[list freeIncludingData];

	return 0;
}