Mercurial > projects > dstep
annotate dstep/foundation/NSArchiver.d @ 16:19885b43130e
Huge update, the bridge actually works now
author | Jacob Carlborg <doob@me.com> |
---|---|
date | Sun, 03 Jan 2010 22:06:11 +0100 |
parents | 89f3c3ef1fd2 |
children | b9de51448c6b |
rev | line source |
---|---|
14 | 1 /** |
2 * Copyright: Copyright (c) 2009 Jacob Carlborg. | |
3 * Authors: Jacob Carlborg | |
4 * Version: Initial created: Aug 3, 2009 | |
5 * License: $(LINK2 http://www.boost.org/LICENSE_1_0.txt, Boost Software License 1.0) | |
6 */ | |
7 module dstep.foundation.NSArchiver; | |
8 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
9 import dstep.foundation.NSArray; |
14 | 10 import dstep.foundation.NSCoder; |
11 import dstep.foundation.NSData; | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
12 import dstep.foundation.NSDictionary; |
14 | 13 import dstep.foundation.NSString; |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
14 import dstep.foundation.NSZone; |
14 | 15 import dstep.objc.bridge.Bridge; |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
16 import dstep.objc.objc; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
17 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
18 |
14 | 19 |
20 import bindings = dstep.foundation.NSArchiver_bindings; | |
21 | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
22 private NSString NSInconsistentArchiveException_; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
23 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
24 NSString NSInconsistentArchiveException () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
25 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
26 if (NSInconsistentArchiveException_) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
27 return NSInconsistentArchiveException_; |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
28 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
29 return NSInconsistentArchiveException_ = new NSString(bindings.NSInconsistentArchiveException); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
30 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
31 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
32 const TNSArchiverCallback = ` |
14 | 33 |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
34 Class classForArchiver () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
35 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
36 return invokeObjcSelf!(Class, "classForArchiver"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
37 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
38 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
39 Object replacementObjectForArchiver (NSArchiver archiver) |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
40 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
41 return invokeObjcSelf!(Object, "replacementObjectForArchiver:", NSArchiver)(archiver); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
42 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
43 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
44 //mixin ObjcBindMethod!(classForArchiver, "classForArchiver"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
45 //mixin ObjcBindMethod!(replacementObjectForArchiver, "replacementObjectForArchiver:"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
46 `; |
14 | 47 |
48 class NSArchiver : NSCoder | |
49 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
50 mixin (ObjcWrap); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
51 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
52 this () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
53 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
54 super(typeof(this).alloc.init.objcObject); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
55 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
56 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
57 typeof(this) init () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
58 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
59 return invokeObjcSelf!(typeof(this), "init"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
60 } |
14 | 61 |
62 Object initForWritingWithMutableData (NSMutableData mdata) | |
63 { | |
64 return invokeObjcSelf!(Object, "initForWritingWithMutableData:", NSMutableData)(mdata); | |
65 } | |
66 | |
67 this (NSMutableData mdata) | |
68 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
69 typeof(this).alloc.initForWritingWithMutableData(mdata); |
14 | 70 } |
71 | |
72 NSMutableData archiverData () | |
73 { | |
74 return invokeObjcSelf!(NSMutableData, "archiverData"); | |
75 } | |
76 | |
77 void encodeRootObject (Object rootObject) | |
78 { | |
79 return invokeObjcSelf!(void, "encodeRootObject:", Object)(rootObject); | |
80 } | |
81 | |
82 void encodeConditionalObject (Object object) | |
83 { | |
84 return invokeObjcSelf!(void, "encodeConditionalObject:", Object)(object); | |
85 } | |
86 | |
87 static NSData archivedDataWithRootObject (Object rootObject) | |
88 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
89 return invokeObjcSuperClass!(NSData, "archivedDataWithRootObject:", Object)(rootObject); |
14 | 90 } |
91 | |
92 static bool archiveRootObject (Object rootObject, NSString path) | |
93 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
94 return invokeObjcSuperClass!(bool, "archiveRootObject:toFile:", Object, NSString)(rootObject, path); |
14 | 95 } |
96 | |
97 void encodeClassName (NSString trueName, NSString inArchiveName) | |
98 { | |
99 return invokeObjcSelf!(void, "encodeClassName:intoClassName:", NSString, NSString)(trueName, inArchiveName); | |
100 } | |
101 | |
102 NSString classNameEncodedForTrueClassName (NSString trueName) | |
103 { | |
104 return invokeObjcSelf!(NSString, "classNameEncodedForTrueClassName:", NSString)(trueName); | |
105 } | |
106 | |
107 void replaceObject (Object object, Object newObject) | |
108 { | |
109 return invokeObjcSelf!(void, "replaceObject:withObject:", Object, Object)(object, newObject); | |
110 } | |
111 } | |
112 | |
113 class NSUnarchiver : NSCoder | |
114 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
115 mixin (ObjcWrap); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
116 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
117 this () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
118 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
119 super(typeof(this).alloc.init.objcObject); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
120 } |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
121 |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
122 typeof(this) init () |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
123 { |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
124 return invokeObjcSelf!(typeof(this), "init"); |
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
125 } |
14 | 126 |
127 Object initForReadingWithData (NSData data) | |
128 { | |
129 return invokeObjcSelf!(Object, "initForReadingWithData:", NSData)(data); | |
130 } | |
131 | |
132 this (NSData data) | |
133 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
134 typeof(this).alloc.initForReadingWithData(data); |
14 | 135 } |
136 | |
137 void setObjectZone (NSZone* zone) | |
138 { | |
139 return invokeObjcSelf!(void, "setObjectZone:", NSZone*)(zone); | |
140 } | |
141 | |
142 NSZone* objectZone () | |
143 { | |
144 return invokeObjcSelf!(NSZone*, "objectZone"); | |
145 } | |
146 | |
147 bool isAtEnd () | |
148 { | |
149 return invokeObjcSelf!(bool, "isAtEnd"); | |
150 } | |
151 | |
152 uint systemVersion () | |
153 { | |
154 return invokeObjcSelf!(uint, "systemVersion"); | |
155 } | |
156 | |
157 static Object unarchiveObjectWithData (NSData data) | |
158 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
159 return invokeObjcSuperClass!(Object, "unarchiveObjectWithData:", NSData)(data); |
14 | 160 } |
161 | |
162 static Object unarchiveObjectWithFile (NSString path) | |
163 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
164 return invokeObjcSuperClass!(Object, "unarchiveObjectWithFile:", NSString)(path); |
14 | 165 } |
166 | |
167 static void decodeClassName (NSString inArchiveName, NSString trueName) | |
168 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
169 return invokeObjcSuperClass!(void, "decodeClassName:asClassName:", NSString, NSString)(inArchiveName, trueName); |
14 | 170 } |
171 | |
172 void decodeClassName (NSString inArchiveName, NSString trueName) | |
173 { | |
174 return invokeObjcSelf!(void, "decodeClassName:asClassName:", NSString, NSString)(inArchiveName, trueName); | |
175 } | |
176 | |
177 static NSString classNameDecodedForArchiveClassName (NSString inArchiveName) | |
178 { | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
179 return invokeObjcSuperClass!(NSString, "classNameDecodedForArchiveClassName:", NSString)(inArchiveName); |
14 | 180 } |
181 | |
182 NSString classNameDecodedForArchiveClassName (NSString inArchiveName) | |
183 { | |
184 return invokeObjcSelf!(NSString, "classNameDecodedForArchiveClassName:", NSString)(inArchiveName); | |
185 } | |
186 | |
187 void replaceObject (Object object, Object newObject) | |
188 { | |
189 return invokeObjcSelf!(void, "replaceObject:withObject:", Object, Object)(object, newObject); | |
190 } | |
16
19885b43130e
Huge update, the bridge actually works now
Jacob Carlborg <doob@me.com>
parents:
14
diff
changeset
|
191 } |