PageRenderTime 20ms CodeModel.GetById 14ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/Frameworks/Debug/Foundation/objj.platform/CPKeyedArchiver.j

http://github.com/jfahrenkrug/MapKit-HelloWorld
Unknown | 312 lines | 311 code | 1 blank | 0 comment | 0 complexity | c0bd70785ba64f672afc9df90e68d66b MD5 | raw file
  1i;8;CPData.ji;9;CPCoder.ji;9;CPArray.ji;10;CPString.ji;10;CPNumber.ji;14;CPDictionary.ji;9;CPValue.jc;16071;
  2var CPArchiverReplacementClassNames = nil;
  3var _CPKeyedArchiverDidEncodeObjectSelector = 1,
  4    _CPKeyedArchiverWillEncodeObjectSelector = 2,
  5    _CPKeyedArchiverWillReplaceObjectWithObjectSelector = 4,
  6    _CPKeyedArchiverDidFinishSelector = 8,
  7    _CPKeyedArchiverWillFinishSelector = 16;
  8var _CPKeyedArchiverNullString = "$null",
  9    _CPKeyedArchiverNullReference = nil,
 10    _CPKeyedArchiverUIDKey = "CP$UID",
 11    _CPKeyedArchiverTopKey = "$top",
 12    _CPKeyedArchiverObjectsKey = "$objects",
 13    _CPKeyedArchiverArchiverKey = "$archiver",
 14    _CPKeyedArchiverVersionKey = "$version",
 15    _CPKeyedArchiverClassNameKey = "$classname",
 16    _CPKeyedArchiverClassesKey = "$classes",
 17    _CPKeyedArchiverClassKey = "$class";
 18var _CPKeyedArchiverStringClass = Nil,
 19    _CPKeyedArchiverNumberClass = Nil;
 20{var the_class = objj_allocateClassPair(CPValue, "_CPKeyedArchiverValue"),
 21meta_class = the_class.isa;objj_registerClassPair(the_class);
 22objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
 23}
 24{var the_class = objj_allocateClassPair(CPCoder, "CPKeyedArchiver"),
 25meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_delegate"), new objj_ivar("_delegateSelectors"), new objj_ivar("_data"), new objj_ivar("_objects"), new objj_ivar("_UIDs"), new objj_ivar("_conditionalUIDs"), new objj_ivar("_replacementObjects"), new objj_ivar("_replacementClassNames"), new objj_ivar("_plistObject"), new objj_ivar("_plistObjects"), new objj_ivar("_outputFormat")]);
 26objj_registerClassPair(the_class);
 27objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
 28class_addMethods(the_class, [new objj_method(sel_getUid("initForWritingWithMutableData:"), function $CPKeyedArchiver__initForWritingWithMutableData_(self, _cmd, data)
 29{ with(self)
 30{
 31    self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPCoder") }, "init");
 32    if (self)
 33    {
 34        _data = data;
 35        _objects = [];
 36        _UIDs = objj_msgSend(CPDictionary, "dictionary");
 37        _conditionalUIDs = objj_msgSend(CPDictionary, "dictionary");
 38        _replacementObjects = objj_msgSend(CPDictionary, "dictionary");
 39        _data = data;
 40        _plistObject = objj_msgSend(CPDictionary, "dictionary");
 41        _plistObjects = objj_msgSend(CPArray, "arrayWithObject:", _CPKeyedArchiverNullString);
 42    }
 43    return self;
 44}
 45}), new objj_method(sel_getUid("finishEncoding"), function $CPKeyedArchiver__finishEncoding(self, _cmd)
 46{ with(self)
 47{
 48    if (_delegate && _delegateSelectors & _CPKeyedArchiverWillFinishSelector)
 49        objj_msgSend(_delegate, "archiverWillFinish:", self);
 50    var i = 0,
 51        topObject = _plistObject,
 52        classes = [];
 53    for (; i < _objects.length; ++i)
 54    {
 55        var object = _objects[i],
 56            theClass = objj_msgSend(object, "classForKeyedArchiver");
 57        _plistObject = _plistObjects[objj_msgSend(_UIDs, "objectForKey:", objj_msgSend(object, "hash"))];
 58        objj_msgSend(object, "encodeWithCoder:", self);
 59        if (_delegate && _delegateSelectors & _CPKeyedArchiverDidEncodeObjectSelector)
 60            objj_msgSend(_delegate, "archiver:didEncodeObject:", self, object);
 61    }
 62    _plistObject = objj_msgSend(CPDictionary, "dictionary");
 63    objj_msgSend(_plistObject, "setObject:forKey:", topObject, _CPKeyedArchiverTopKey);
 64    objj_msgSend(_plistObject, "setObject:forKey:", _plistObjects, _CPKeyedArchiverObjectsKey);
 65    objj_msgSend(_plistObject, "setObject:forKey:", objj_msgSend(self, "className"), _CPKeyedArchiverArchiverKey);
 66    objj_msgSend(_plistObject, "setObject:forKey:", "100000", _CPKeyedArchiverVersionKey);
 67    objj_msgSend(_data, "setPlistObject:", _plistObject);
 68    if (_delegate && _delegateSelectors & _CPKeyedArchiverDidFinishSelector)
 69        objj_msgSend(_delegate, "archiverDidFinish:", self);
 70}
 71}), new objj_method(sel_getUid("outputFormat"), function $CPKeyedArchiver__outputFormat(self, _cmd)
 72{ with(self)
 73{
 74    return _outputFormat;
 75}
 76}), new objj_method(sel_getUid("setOutputFormat:"), function $CPKeyedArchiver__setOutputFormat_(self, _cmd, aPropertyListFormat)
 77{ with(self)
 78{
 79    _outputFormat = aPropertyListFormat;
 80}
 81}), new objj_method(sel_getUid("encodeBool:forKey:"), function $CPKeyedArchiver__encodeBool_forKey_(self, _cmd, aBOOL, aKey)
 82{ with(self)
 83{
 84    objj_msgSend(_plistObject, "setObject:forKey:", _CPKeyedArchiverEncodeObject(self, aBOOL, NO), aKey);
 85}
 86}), new objj_method(sel_getUid("encodeDouble:forKey:"), function $CPKeyedArchiver__encodeDouble_forKey_(self, _cmd, aDouble, aKey)
 87{ with(self)
 88{
 89    objj_msgSend(_plistObject, "setObject:forKey:", _CPKeyedArchiverEncodeObject(self, aDouble, NO), aKey);
 90}
 91}), new objj_method(sel_getUid("encodeFloat:forKey:"), function $CPKeyedArchiver__encodeFloat_forKey_(self, _cmd, aFloat, aKey)
 92{ with(self)
 93{
 94    objj_msgSend(_plistObject, "setObject:forKey:", _CPKeyedArchiverEncodeObject(self, aFloat, NO), aKey);
 95}
 96}), new objj_method(sel_getUid("encodeInt:forKey:"), function $CPKeyedArchiver__encodeInt_forKey_(self, _cmd, anInt, aKey)
 97{ with(self)
 98{
 99    objj_msgSend(_plistObject, "setObject:forKey:", _CPKeyedArchiverEncodeObject(self, anInt, NO), aKey);
100}
101}), new objj_method(sel_getUid("setDelegate:"), function $CPKeyedArchiver__setDelegate_(self, _cmd, aDelegate)
102{ with(self)
103{
104    _delegate = aDelegate;
105    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("archiver:didEncodeObject:")))
106        _delegateSelectors |= _CPKeyedArchiverDidEncodeObjectSelector;
107    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("archiver:willEncodeObject:")))
108        _delegateSelectors |= _CPKeyedArchiverWillEncodeObjectSelector;
109    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("archiver:willReplaceObject:withObject:")))
110        _delegateSelectors |= _CPKeyedArchiverWillReplaceObjectWithObjectSelector;
111    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("archiver:didFinishEncoding:")))
112        _delegateSelectors |= _CPKeyedArchiverDidFinishEncodingSelector;
113    if (objj_msgSend(_delegate, "respondsToSelector:", sel_getUid("archiver:willFinishEncoding:")))
114        _delegateSelectors |= _CPKeyedArchiverWillFinishEncodingSelector;
115}
116}), new objj_method(sel_getUid("delegate"), function $CPKeyedArchiver__delegate(self, _cmd)
117{ with(self)
118{
119    return _delegate;
120}
121}), new objj_method(sel_getUid("encodePoint:forKey:"), function $CPKeyedArchiver__encodePoint_forKey_(self, _cmd, aPoint, aKey)
122{ with(self)
123{
124    objj_msgSend(_plistObject, "setObject:forKey:", _CPKeyedArchiverEncodeObject(self, CPStringFromPoint(aPoint), NO), aKey);
125}
126}), new objj_method(sel_getUid("encodeRect:forKey:"), function $CPKeyedArchiver__encodeRect_forKey_(self, _cmd, aRect, aKey)
127{ with(self)
128{
129    objj_msgSend(_plistObject, "setObject:forKey:", _CPKeyedArchiverEncodeObject(self, CPStringFromRect(aRect), NO), aKey);
130}
131}), new objj_method(sel_getUid("encodeSize:forKey:"), function $CPKeyedArchiver__encodeSize_forKey_(self, _cmd, aSize, aKey)
132{ with(self)
133{
134    objj_msgSend(_plistObject, "setObject:forKey:", _CPKeyedArchiverEncodeObject(self, CPStringFromSize(aSize), NO), aKey);
135}
136}), new objj_method(sel_getUid("encodeConditionalObject:forKey:"), function $CPKeyedArchiver__encodeConditionalObject_forKey_(self, _cmd, anObject, aKey)
137{ with(self)
138{
139    objj_msgSend(_plistObject, "setObject:forKey:", _CPKeyedArchiverEncodeObject(self, anObject, YES), aKey);
140}
141}), new objj_method(sel_getUid("encodeNumber:forKey:"), function $CPKeyedArchiver__encodeNumber_forKey_(self, _cmd, aNumber, aKey)
142{ with(self)
143{
144    objj_msgSend(_plistObject, "setObject:forKey:", _CPKeyedArchiverEncodeObject(self, aNumber, NO), aKey);
145}
146}), new objj_method(sel_getUid("encodeObject:forKey:"), function $CPKeyedArchiver__encodeObject_forKey_(self, _cmd, anObject, aKey)
147{ with(self)
148{
149    objj_msgSend(_plistObject, "setObject:forKey:", _CPKeyedArchiverEncodeObject(self, anObject, NO), aKey);
150}
151}), new objj_method(sel_getUid("_encodeArrayOfObjects:forKey:"), function $CPKeyedArchiver___encodeArrayOfObjects_forKey_(self, _cmd, objects, aKey)
152{ with(self)
153{
154    var i = 0,
155        count = objects.length,
156        references = objj_msgSend(CPArray, "arrayWithCapacity:", count);
157    for (; i < count; ++i)
158        objj_msgSend(references, "addObject:", _CPKeyedArchiverEncodeObject(self, objects[i], NO));
159    objj_msgSend(_plistObject, "setObject:forKey:", references, aKey);
160}
161}), new objj_method(sel_getUid("_encodeDictionaryOfObjects:forKey:"), function $CPKeyedArchiver___encodeDictionaryOfObjects_forKey_(self, _cmd, aDictionary, aKey)
162{ with(self)
163{
164    var key,
165        keys = objj_msgSend(aDictionary, "keyEnumerator"),
166        references = objj_msgSend(CPDictionary, "dictionary");
167    while (key = objj_msgSend(keys, "nextObject"))
168        objj_msgSend(references, "setObject:forKey:", _CPKeyedArchiverEncodeObject(self, objj_msgSend(aDictionary, "objectForKey:", key), NO), key);
169    objj_msgSend(_plistObject, "setObject:forKey:", references, aKey);
170}
171}), new objj_method(sel_getUid("setClassName:forClass:"), function $CPKeyedArchiver__setClassName_forClass_(self, _cmd, aClassName, aClass)
172{ with(self)
173{
174    if (!_replacementClassNames)
175        _replacementClassNames = objj_msgSend(CPDictionary, "dictionary");
176    objj_msgSend(_replacementClassNames, "setObject:forKey:", aClassName, CPStringFromClass(aClass));
177}
178}), new objj_method(sel_getUid("classNameForClass:"), function $CPKeyedArchiver__classNameForClass_(self, _cmd, aClass)
179{ with(self)
180{
181    if (!_replacementClassNames)
182        return aClass.name;
183    var className = objj_msgSend(_replacementClassNames, "objectForKey:", CPStringFromClass(aClassName));
184    return className ? className : aClass.name;
185}
186})]);
187class_addMethods(meta_class, [new objj_method(sel_getUid("initialize"), function $CPKeyedArchiver__initialize(self, _cmd)
188{ with(self)
189{
190    if (self != objj_msgSend(CPKeyedArchiver, "class"))
191        return;
192    _CPKeyedArchiverStringClass = objj_msgSend(CPString, "class");
193    _CPKeyedArchiverNumberClass = objj_msgSend(CPNumber, "class");
194    _CPKeyedArchiverNullReference = objj_msgSend(CPDictionary, "dictionaryWithObject:forKey:", 0, _CPKeyedArchiverUIDKey);
195}
196}), new objj_method(sel_getUid("allowsKeyedCoding"), function $CPKeyedArchiver__allowsKeyedCoding(self, _cmd)
197{ with(self)
198{
199    return YES;
200}
201}), new objj_method(sel_getUid("archivedDataWithRootObject:"), function $CPKeyedArchiver__archivedDataWithRootObject_(self, _cmd, anObject)
202{ with(self)
203{
204    var data = objj_msgSend(CPData, "dataWithPlistObject:", nil),
205        archiver = objj_msgSend(objj_msgSend(self, "alloc"), "initForWritingWithMutableData:", data);
206    objj_msgSend(archiver, "encodeObject:forKey:", anObject, "root");
207    objj_msgSend(archiver, "finishEncoding");
208    return data;
209}
210}), new objj_method(sel_getUid("setClassName:forClass:"), function $CPKeyedArchiver__setClassName_forClass_(self, _cmd, aClassName, aClass)
211{ with(self)
212{
213    if (!CPArchiverReplacementClassNames)
214        CPArchiverReplacementClassNames = objj_msgSend(CPDictionary, "dictionary");
215    objj_msgSend(CPArchiverReplacementClassNames, "setObject:forKey:", aClassName, CPStringFromClass(aClass));
216}
217}), new objj_method(sel_getUid("classNameForClass:"), function $CPKeyedArchiver__classNameForClass_(self, _cmd, aClass)
218{ with(self)
219{
220    if (!CPArchiverReplacementClassNames)
221        return aClass.name;
222    var className = objj_msgSend(CPArchiverReplacementClassNames, "objectForKey:", CPStringFromClass(aClassName));
223    return className ? className : aClass.name;
224}
225})]);
226}
227var _CPKeyedArchiverEncodeObject = function(self, anObject, isConditional)
228{
229    if (anObject !== nil && !anObject.isa)
230        anObject = objj_msgSend(_CPKeyedArchiverValue, "valueWithJSObject:", anObject);
231    var hash = objj_msgSend(anObject, "hash"),
232        object = objj_msgSend(self._replacementObjects, "objectForKey:", hash);
233    if (object === nil)
234    {
235        object = objj_msgSend(anObject, "replacementObjectForKeyedArchiver:", self);
236        if (self._delegate)
237        {
238            if (object !== anObject && self._delegateSelectors & _CPKeyedArchiverWillReplaceObjectWithObjectSelector)
239                objj_msgSend(self._delegate, "archiver:willReplaceObject:withObject:", self, anObject, object);
240            if (self._delegateSelectors & _CPKeyedArchiverWillEncodeObjectSelector)
241            {
242                anObject = objj_msgSend(self._delegate, "archiver:willEncodeObject:", self, object);
243                if (anObject !== object && self._delegateSelectors & _CPKeyedArchiverWillReplaceObjectWithObjectSelector)
244                    objj_msgSend(self._delegate, "archiver:willReplaceObject:withObject:", self, object, anObject);
245                object = anObject;
246            }
247        }
248        objj_msgSend(self._replacementObjects, "setObject:forKey:", object, hash);
249    }
250    if (object === nil)
251        return _CPKeyedArchiverNullReference;
252    var UID = objj_msgSend(self._UIDs, "objectForKey:", hash = objj_msgSend(object, "hash"));
253    if (UID === nil)
254    {
255        if (isConditional)
256        {
257            if ((UID = objj_msgSend(self._conditionalUIDs, "objectForKey:", hash)) === nil)
258            {
259                objj_msgSend(self._conditionalUIDs, "setObject:forKey:", UID = objj_msgSend(self._plistObjects, "count"), hash);
260                objj_msgSend(self._plistObjects, "addObject:", _CPKeyedArchiverNullString);
261            }
262        }
263        else
264        {
265            var theClass = objj_msgSend(object, "classForKeyedArchiver"),
266                plistObject = nil;
267            if ((theClass === _CPKeyedArchiverStringClass) || (theClass === _CPKeyedArchiverNumberClass))
268                plistObject = object;
269            else
270            {
271                plistObject = objj_msgSend(CPDictionary, "dictionary");
272                objj_msgSend(self._objects, "addObject:", object);
273                var className = objj_msgSend(self, "classNameForClass:", theClass);
274                if (!className)
275                    className = objj_msgSend(objj_msgSend(self, "class"), "classNameForClass:", theClass);
276                if (!className)
277                    className = theClass.name;
278                else
279                    theClass = window[className];
280                var classUID = objj_msgSend(self._UIDs, "objectForKey:", className);
281                if (!classUID)
282                {
283                    var plistClass = objj_msgSend(CPDictionary, "dictionary"),
284                        hierarchy = [];
285                    objj_msgSend(plistClass, "setObject:forKey:", className, _CPKeyedArchiverClassNameKey);
286                    do
287                    {
288                        objj_msgSend(hierarchy, "addObject:", CPStringFromClass(theClass));
289                    } while (theClass = objj_msgSend(theClass, "superclass"));
290                    objj_msgSend(plistClass, "setObject:forKey:", hierarchy, _CPKeyedArchiverClassesKey);
291                    classUID = objj_msgSend(self._plistObjects, "count");
292                    objj_msgSend(self._plistObjects, "addObject:", plistClass);
293                    objj_msgSend(self._UIDs, "setObject:forKey:", classUID, className);
294                }
295                objj_msgSend(plistObject, "setObject:forKey:", objj_msgSend(CPDictionary, "dictionaryWithObject:forKey:", classUID, _CPKeyedArchiverUIDKey), _CPKeyedArchiverClassKey);
296            }
297            UID = objj_msgSend(self._conditionalUIDs, "objectForKey:", hash);
298            if (UID !== nil)
299            {
300                objj_msgSend(self._UIDs, "setObject:forKey:", UID, hash);
301                objj_msgSend(self._plistObjects, "replaceObjectAtIndex:withObject:", UID, plistObject);
302            }
303            else
304            {
305                objj_msgSend(self._UIDs, "setObject:forKey:", UID = objj_msgSend(self._plistObjects, "count"), hash);
306                objj_msgSend(self._plistObjects, "addObject:", plistObject);
307            }
308        }
309    }
310    return objj_msgSend(CPDictionary, "dictionaryWithObject:forKey:", UID, _CPKeyedArchiverUIDKey);
311}
312