Skip to content

Commit 1e8de71

Browse files
Clean up shared base types
1 parent c4994f2 commit 1e8de71

File tree

4 files changed

+13
-96
lines changed

4 files changed

+13
-96
lines changed

source/corefoundation/core.d

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*/
88
module corefoundation.core;
99
import numem.core.types;
10+
public import objc.basetypes;
1011
public import objc.bridge : objd_bridge;
1112

1213
extern(C) @nogc nothrow:
@@ -89,32 +90,6 @@ struct CFRange {
8990
CFIndex location;
9091
}
9192

92-
// Declaration of base types.
93-
alias Boolean = bool;
94-
alias UInt8 = ubyte;
95-
alias SInt8 = byte;
96-
alias UInt16 = ushort;
97-
alias SInt16 = short;
98-
alias UInt32 = uint;
99-
alias SInt32 = int;
100-
alias UInt64 = ulong;
101-
alias SInt64 = long;
102-
alias Int = ptrdiff_t;
103-
alias UInt = size_t;
104-
alias UniChar = wchar;
105-
alias StringPtr = const(char)*;
106-
alias Str255 = const(char)[255];
107-
alias ConstStr255Param = const(char)*;
108-
alias OSErr = UInt16;
109-
alias OSStatus = UInt32;
110-
alias UTF32Char = dchar;
111-
alias UTF16Char = wchar;
112-
alias UTF8Char = char;
113-
alias LangCode = ushort;
114-
alias RegionCode = ushort;
115-
alias FourCharCode = uint;
116-
alias OSType = FourCharCode;
117-
11893
extern(C) @nogc nothrow:
11994

12095
/**
@@ -191,8 +166,8 @@ extern CFTypeID CFGetTypeID(CFTypeRef cfObject);
191166
Generic CoreFoundation reference, essentially equivalent to
192167
NSObject
193168
*/
194-
alias CFTypeRef = __CFType*;
195169
struct __CFType; /// ditto
170+
alias CFTypeRef = __CFType*;
196171

197172
/**
198173
Defines a CFTypeRef subtype; said subtype can be cast down to
@@ -206,6 +181,6 @@ template CFSubType(string name, AllowedBridge...) {
206181
import objc.bridge : objd_bridge;
207182

208183
@objd_bridge!(AllowedBridge)
209-
struct __CFSubType(string name) { alias self this; __CFType* self; }
210-
alias CFSubType = __CFSubType!name;
184+
struct __CFSubType(string name) { alias isa this; __CFType* isa; }
185+
alias CFSubType = __CFSubType!(name)*;
211186
}

source/foundation/core.d

Lines changed: 1 addition & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -6,69 +6,7 @@
66
Authors: Luna Nielsen
77
*/
88
module foundation.core;
9-
10-
/**
11-
A structure used to describe a portion of a series, such as characters in a string or objects in an array.
12-
*/
13-
struct NSRange {
14-
nothrow @nogc:
15-
16-
/**
17-
The index of the first member of the range.
18-
*/
19-
NSUInteger location;
20-
21-
/**
22-
The number of items in the range.
23-
*/
24-
NSUInteger length;
25-
26-
/**
27-
Returns the sum of the location and length of the range.
28-
*/
29-
@property max() => location+length;
30-
31-
/**
32-
Returns a Boolean value that indicates whether two given ranges are equal.
33-
*/
34-
bool opEquals(const(NSRange) other) const {
35-
return this.location == other.location && this.length == other.length;
36-
}
37-
38-
/**
39-
Returns a Boolean value that indicates whether a specified position is in a given range.
40-
*/
41-
bool inRange(NSUInteger location) => this.location >= location && location < this.max();
42-
43-
/**
44-
Returns the intersection of the specified ranges.
45-
46-
Returns:
47-
A range describing the intersection of range1 and range2—that is,
48-
a range containing the indices that exist in both ranges.
49-
50-
If the returned range’s length field is 0, then the two ranges don’t intersect,
51-
and the value of the location field is undefined.
52-
*/
53-
NSRange intersect(NSRange other) {
54-
NSUInteger loc = NSMax(this.location, other.location);
55-
return NSRange(
56-
location: loc,
57-
length: NSMin(this.max, other.max)-loc,
58-
);
59-
}
60-
61-
/**
62-
Returns the union of the specified ranges.
63-
*/
64-
NSRange unionize(NSRange other) {
65-
NSUInteger loc = NSMin(location, other.location);
66-
return NSRange(
67-
location: loc,
68-
length: NSMin(this.max, other.max)-loc
69-
);
70-
}
71-
}
9+
public import objc.basetypes;
7210

7311
/**
7412
Type indicating a parameter is a pointer to an NSRange structure.

source/foundation/nsdictionary.d

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,10 +113,11 @@ public:
113113
/**
114114
Adds a given key-value pair to the dictionary.
115115
*/
116-
void opIndexAssign(Value value, Key key) {
116+
final
117+
extern(D) void opIndexAssign(Value value, inout(Key) key) {
117118
static if (is(Key : NSString))
118-
this.message!void("setValue:forKey:", value, key);
119+
self.send!void("setValue:forKey:", value, key);
119120
else
120-
this.message!void("setObject:forKey:", value, key);
121+
self.send!void("setObject:forKey:", value, key);
121122
}
122123
}

source/objc/basetypes.d

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,4 +118,7 @@ alias OSStatus = UInt32;
118118
alias UTF32Char = dchar;
119119
alias UTF16Char = wchar;
120120
alias UTF8Char = char;
121-
alias OSType = uint;
121+
alias LangCode = ushort;
122+
alias RegionCode = ushort;
123+
alias FourCharCode = uint;
124+
alias OSType = FourCharCode;

0 commit comments

Comments
 (0)