ObjFW  Check-in [f48ee629e3]

Overview
Comment:Always use [self alloc] in + new.
This way, derivated classes are not forced to always override + new.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: f48ee629e39d4f69375d29229d5acb3a02d95dbff75c138f7d17e06dd16968cc
User & Date: js on 2008-12-10 17:53:03
Other Links: manifest | tags
Context
2008-12-10
17:54
When closing an OFTCPSocket, set it's internal socket to -1. check-in: e9f870cfc0 user: js tags: trunk
17:53
Always use [self alloc] in + new.
This way, derivated classes are not forced to always override + new.
check-in: f48ee629e3 user: js tags: trunk
2008-12-09
17:36
Don't use - raise anymore, but @throw.
- raise was only because at first, exceptions were self-raising, but
this was later changed so they had to be risen manually. - rise was
introduced for that, but it would've been better to use @throw
directly. Thus, this change now.
check-in: d88aec8e95 user: js tags: trunk
Changes

Modified src/OFArray.h from [d5e6d44d98] to [2a9748db76].

98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
 * to store large hunks of data.
 */
@interface OFBigArray: OFArray
{
	size_t size;
}

/**
 * Creates a new OFBigArray whose items all have the same size.
 *
 * \param is The size of each element in the OFBigArray
 * \return A new allocated and initialized OFBigArray
 */
+ newWithItemSize: (size_t)is;

/**
 * Initializes an already allocated OFBigArray whose items all have the same
 * size.
 * 
 * \param is The size of each element in the OFBigArray
 * \return An initialized OFBigArray
 */







<
<
<
<
<
<
<
<







98
99
100
101
102
103
104








105
106
107
108
109
110
111
 * to store large hunks of data.
 */
@interface OFBigArray: OFArray
{
	size_t size;
}









/**
 * Initializes an already allocated OFBigArray whose items all have the same
 * size.
 * 
 * \param is The size of each element in the OFBigArray
 * \return An initialized OFBigArray
 */

Modified src/OFArray.m from [190e0d7eea] to [e1c0bd1b7d].

20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#import "OFMacros.h"

static size_t lastpagebyte = 0;

@implementation OFArray
+ newWithItemSize: (size_t)is
{
	return [[OFArray alloc] initWithItemSize: is];
}

- initWithItemSize: (size_t)is
{
	if ((self = [super init])) {
		data = NULL;
		itemsize = is;







|







20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#import "OFMacros.h"

static size_t lastpagebyte = 0;

@implementation OFArray
+ newWithItemSize: (size_t)is
{
	return [[self alloc] initWithItemSize: is];
}

- initWithItemSize: (size_t)is
{
	if ((self = [super init])) {
		data = NULL;
		itemsize = is;
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
	items -= nitems;

	return self;
}
@end

@implementation OFBigArray
+ newWithItemSize: (size_t)is
{
	return [[OFBigArray alloc] initWithItemSize: is];
}

- initWithItemSize: (size_t)is
{
	if (lastpagebyte == 0)
		lastpagebyte = getpagesize() - 1;

	if ((self = [super initWithItemSize: is]))
		size = 0;







<
<
<
<
<







108
109
110
111
112
113
114





115
116
117
118
119
120
121
	items -= nitems;

	return self;
}
@end

@implementation OFBigArray





- initWithItemSize: (size_t)is
{
	if (lastpagebyte == 0)
		lastpagebyte = getpagesize() - 1;

	if ((self = [super initWithItemSize: is]))
		size = 0;

Modified src/OFExceptions.m from [c6047432b6] to [4ac6f2f10b].

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#else
#error "You need either sel_get_name() or sel_getName!"
#endif

@implementation OFException
+ newWithObject: (id)obj
{
	return [[OFException alloc] initWithObject: obj];
}

- initWithObject: (id)obj
{
	if ((self = [super init])) {
		object = obj;
		string = NULL;







|







27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#else
#error "You need either sel_get_name() or sel_getName!"
#endif

@implementation OFException
+ newWithObject: (id)obj
{
	return [[self alloc] initWithObject: obj];
}

- initWithObject: (id)obj
{
	if ((self = [super init])) {
		object = obj;
		string = NULL;
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
}
@end

@implementation OFNoMemException
+ newWithObject: (id)obj
	andSize: (size_t)size
{
	return [[OFNoMemException alloc] initWithObject: obj
						andSize: size];
}

- initWithObject: (id)obj
	 andSize: (size_t)size
{
	if ((self = [super initWithObject: obj]))
		req_size = size;







|
|







58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
}
@end

@implementation OFNoMemException
+ newWithObject: (id)obj
	andSize: (size_t)size
{
	return [[self alloc] initWithObject: obj
				    andSize: size];
}

- initWithObject: (id)obj
	 andSize: (size_t)size
{
	if ((self = [super initWithObject: obj]))
		req_size = size;
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
}
@end

@implementation OFMemNotPartOfObjException
+ newWithObject: (id)obj
     andPointer: (void*)ptr
{
	return [[OFMemNotPartOfObjException alloc] initWithObject: obj
						       andPointer: ptr];
}

- initWithObject: (id)obj
      andPointer: (void*)ptr
{
	if ((self = [super initWithObject: obj]))
		pointer = ptr;







|
|







92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
}
@end

@implementation OFMemNotPartOfObjException
+ newWithObject: (id)obj
     andPointer: (void*)ptr
{
	return [[self alloc] initWithObject: obj
				 andPointer: ptr];
}

- initWithObject: (id)obj
      andPointer: (void*)ptr
{
	if ((self = [super initWithObject: obj]))
		pointer = ptr;
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
	return pointer;
}
@end

@implementation OFOutOfRangeException
+ newWithObject: (id)obj
{
	return [[OFOutOfRangeException alloc] initWithObject: obj];
}

- initWithObject: (id)obj
{
	return (self = [super initWithObject: obj]);
}








|







129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
	return pointer;
}
@end

@implementation OFOutOfRangeException
+ newWithObject: (id)obj
{
	return [[self alloc] initWithObject: obj];
}

- initWithObject: (id)obj
{
	return (self = [super initWithObject: obj]);
}

154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@end

@implementation OFOpenFileFailedException
+ newWithObject: (id)obj
	andPath: (const char*)p
	andMode: (const char*)m
{
	return [[OFOpenFileFailedException alloc] initWithObject: obj
							 andPath: p
							 andMode: m];
}

- initWithObject: (id)obj
	 andPath: (const char*)p
	 andMode: (const char*)m
{
	if ((self = [super initWithObject: obj])) {







|
|
|







154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
@end

@implementation OFOpenFileFailedException
+ newWithObject: (id)obj
	andPath: (const char*)p
	andMode: (const char*)m
{
	return [[self alloc] initWithObject: obj
				    andPath: p
				    andMode: m];
}

- initWithObject: (id)obj
	 andPath: (const char*)p
	 andMode: (const char*)m
{
	if ((self = [super initWithObject: obj])) {
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
@end

@implementation OFReadOrWriteFailedException
+ newWithObject: (id)obj
	andSize: (size_t)size
      andNItems: (size_t)nitems
{
	return [[OFReadOrWriteFailedException alloc] initWithObject: obj
							    andSize: size
							  andNItems: nitems];
}

- initWithObject: (id)obj
	 andSize: (size_t)size
       andNItems: (size_t)nitems
{
	if ((self = [super initWithObject: obj])) {







|
|
|







208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
@end

@implementation OFReadOrWriteFailedException
+ newWithObject: (id)obj
	andSize: (size_t)size
      andNItems: (size_t)nitems
{
	return [[self alloc] initWithObject: obj
				    andSize: size
				  andNItems: nitems];
}

- initWithObject: (id)obj
	 andSize: (size_t)size
       andNItems: (size_t)nitems
{
	if ((self = [super initWithObject: obj])) {

Modified src/OFFile.m from [88173cbff8] to [0b28d6c4b4].

21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#import "OFFile.h"
#import "OFExceptions.h"

@implementation OFFile
+ newWithPath: (const char*)path
      andMode: (const char*)mode
{
	return [[OFFile alloc] initWithPath: path
				    andMode: mode];
}

+ (BOOL)changeModeOfFile: (const char*)path
		 toMode: (mode_t)mode
{
	// FIXME: On error, throw exception







|







21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
#import "OFFile.h"
#import "OFExceptions.h"

@implementation OFFile
+ newWithPath: (const char*)path
      andMode: (const char*)mode
{
	return [[self alloc] initWithPath: path
				    andMode: mode];
}

+ (BOOL)changeModeOfFile: (const char*)path
		 toMode: (mode_t)mode
{
	// FIXME: On error, throw exception

Modified src/OFListObject.m from [24a5cb35a1] to [9ba11309d6].

14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#import <stdlib.h>

#import "OFListObject.h"

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

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







|







14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
#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;

Modified src/OFString.m from [1aa922997d] to [56af24d281].

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

#import "OFString.h"
#import "OFExceptions.h"

@implementation OFString
+ new
{
	return [[OFString alloc] init];
}

+ newFromCString: (const char*)str
{
	return [[OFString alloc] initFromCString: str];
}

+ newFromWideCString: (const wchar_t*)str
{
	return [[OFString alloc] initFromWideCString: str];
}

- init
{
	if ((self = [super init])) {
		length = 0;
		string = NULL;







|




|




|







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

#import "OFString.h"
#import "OFExceptions.h"

@implementation OFString
+ new
{
	return [[self alloc] init];
}

+ newFromCString: (const char*)str
{
	return [[self alloc] initFromCString: str];
}

+ newFromWideCString: (const wchar_t*)str
{
	return [[self alloc] initFromWideCString: str];
}

- init
{
	if ((self = [super init])) {
		length = 0;
		string = NULL;