1
2
3
4
5
6
7
8
9
10
11
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
54
55
56
57
58
59
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
94
95
96
97
98
99
100
101
102
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
|
1
2
3
4
5
6
7
8
9
10
11
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
54
55
56
57
58
59
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
94
95
96
97
98
99
100
101
102
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
|
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
+
-
-
-
-
-
-
-
+
-
-
-
-
-
+
-
-
-
-
-
-
-
-
-
-
-
-
-
+
-
+
-
-
-
-
-
+
-
-
+
+
+
+
+
+
+
+
-
+
-
-
+
+
-
+
+
+
+
|
/*
* Copyright (c) 2008-2022 Jonathan Schleifer <js@nil.im>
* Copyright (c) 2008-2024 Jonathan Schleifer <js@nil.im>
*
* All rights reserved.
*
* This file is part of ObjFW. It may be distributed under the terms of the
* Q Public License 1.0, which can be found in the file LICENSE.QPL included in
* the packaging of this file.
*
* Alternatively, it may be distributed under the terms of the GNU General
* Public License, either version 2 or 3, which can be found in the file
* LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this
* file.
*/
#include "config.h"
#include <stdlib.h>
#import "OFMutableMapTableDictionary.h"
#import "OFConcreteMutableDictionary.h"
#import "OFArray.h"
#import "OFString.h"
static struct {
Class isa;
} placeholder;
@interface OFMutableDictionaryPlaceholder: OFDictionary
@interface OFPlaceholderMutableDictionary: OFDictionary
@end
@implementation OFMutableDictionaryPlaceholder
@implementation OFPlaceholderMutableDictionary
- (instancetype)init
{
return (id)[[OFMutableMapTableDictionary alloc] init];
return (id)[[OFConcreteMutableDictionary alloc] init];
}
- (instancetype)initWithDictionary: (OFDictionary *)dictionary
{
return (id)[[OFMutableMapTableDictionary alloc]
return (id)[[OFConcreteMutableDictionary alloc]
initWithDictionary: dictionary];
}
- (instancetype)initWithObject: (id)object forKey: (id)key
{
return (id)[[OFMutableMapTableDictionary alloc] initWithObject: object
return (id)[[OFConcreteMutableDictionary alloc] initWithObject: object
forKey: key];
}
- (instancetype)initWithObjects: (OFArray *)objects forKeys: (OFArray *)keys
{
return (id)[[OFMutableMapTableDictionary alloc] initWithObjects: objects
return (id)[[OFConcreteMutableDictionary alloc] initWithObjects: objects
forKeys: keys];
}
- (instancetype)initWithObjects: (id const *)objects
forKeys: (id const *)keys
count: (size_t)count
{
return (id)[[OFMutableMapTableDictionary alloc] initWithObjects: objects
return (id)[[OFConcreteMutableDictionary alloc] initWithObjects: objects
forKeys: keys
count: count];
}
- (instancetype)initWithKeysAndObjects: (id)firstKey, ...
{
id ret;
va_list arguments;
va_start(arguments, firstKey);
ret = (id)[[OFMutableMapTableDictionary alloc] initWithKey: firstKey
ret = (id)[[OFConcreteMutableDictionary alloc] initWithKey: firstKey
arguments: arguments];
va_end(arguments);
return ret;
}
- (instancetype)initWithKey: (id)firstKey arguments: (va_list)arguments
{
return (id)[[OFMutableMapTableDictionary alloc] initWithKey: firstKey
return (id)[[OFConcreteMutableDictionary alloc] initWithKey: firstKey
arguments: arguments];
}
- (instancetype)initWithSerialization: (OFXMLElement *)element
{
return (id)[[OFMutableMapTableDictionary alloc]
initWithSerialization: element];
}
- (instancetype)initWithCapacity: (size_t)capacity
{
return (id)[[OFMutableMapTableDictionary alloc]
return (id)[[OFConcreteMutableDictionary alloc]
initWithCapacity: capacity];
}
- (instancetype)retain
{
return self;
}
OF_SINGLETON_METHODS
- (instancetype)autorelease
{
return self;
}
- (void)release
{
}
- (void)dealloc
{
OF_DEALLOC_UNSUPPORTED
}
@end
@implementation OFMutableDictionary
+ (void)initialize
{
if (self == [OFMutableDictionary class])
object_setClass((id)&placeholder,
placeholder.isa = [OFMutableDictionaryPlaceholder class];
[OFPlaceholderMutableDictionary class]);
}
+ (instancetype)alloc
{
if (self == [OFMutableDictionary class])
return (id)&placeholder;
return [super alloc];
}
+ (instancetype)dictionaryWithCapacity: (size_t)capacity
{
return [[[self alloc] initWithCapacity: capacity] autorelease];
}
- (instancetype)init
{
if ([self isMemberOfClass: [OFMutableDictionary class]]) {
@try {
[self doesNotRecognizeSelector: _cmd];
} @catch (id e) {
[self release];
return [super init];
@throw e;
}
}
#ifdef __clang__
/* We intentionally don't call into super, so silence the warning. */
# pragma clang diagnostic push
# pragma clang diagnostic ignored "-Wunknown-pragmas"
# pragma clang diagnostic ignored "-Wobjc-designated-initializers"
#endif
- (instancetype)initWithObjects: (id const *)objects
abort();
forKeys: (id const *)keys
}
count: (size_t)count
{
return [super init];
OF_INVALID_INIT_METHOD
}
- (instancetype)initWithCapacity: (size_t)capacity
{
OF_INVALID_INIT_METHOD
}
#ifdef __clang__
# pragma clang diagnostic pop
#endif
- (void)setObject: (id)object forKey: (id)key
{
OF_UNRECOGNIZED_SELECTOR
}
- (void)setObject: (id)object forKeyedSubscript: (id)key
|