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

http://github.com/jfahrenkrug/MapKit-HelloWorld · Unknown · 260 lines · 259 code · 1 blank · 0 comment · 0 complexity · dab3270a0812acd679984fe47ab29fc9 MD5 · raw file

  1. i;10;CPObject.ji;14;CPEnumerator.ji;13;CPException.jc;10057;
  2. {var the_class = objj_allocateClassPair(CPEnumerator, "_CPDictionaryValueEnumerator"),
  3. meta_class = the_class.isa;class_addIvars(the_class, [new objj_ivar("_keyEnumerator"), new objj_ivar("_dictionary")]);
  4. objj_registerClassPair(the_class);
  5. objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  6. class_addMethods(the_class, [new objj_method(sel_getUid("initWithDictionary:"), function $_CPDictionaryValueEnumerator__initWithDictionary_(self, _cmd, aDictionary)
  7. { with(self)
  8. {
  9. self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPEnumerator") }, "init");
  10. if (self)
  11. {
  12. _keyEnumerator = objj_msgSend(aDictionary, "keyEnumerator");
  13. _dictionary = aDictionary;
  14. }
  15. return self;
  16. }
  17. }), new objj_method(sel_getUid("nextObject"), function $_CPDictionaryValueEnumerator__nextObject(self, _cmd)
  18. { with(self)
  19. {
  20. var key = objj_msgSend(_keyEnumerator, "nextObject");
  21. if (!key)
  22. return nil;
  23. return objj_msgSend(_dictionary, "objectForKey:", key);
  24. }
  25. })]);
  26. }
  27. {var the_class = objj_allocateClassPair(CPObject, "CPDictionary"),
  28. meta_class = the_class.isa;objj_registerClassPair(the_class);
  29. objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  30. class_addMethods(the_class, [new objj_method(sel_getUid("initWithDictionary:"), function $CPDictionary__initWithDictionary_(self, _cmd, aDictionary)
  31. { with(self)
  32. {
  33. var key = "",
  34. dictionary = objj_msgSend(objj_msgSend(CPDictionary, "alloc"), "init");
  35. for (key in aDictionary._buckets)
  36. objj_msgSend(dictionary, "setObject:forKey:", objj_msgSend(aDictionary, "objectForKey:", key), key);
  37. return dictionary;
  38. }
  39. }), new objj_method(sel_getUid("initWithObjects:forKeys:"), function $CPDictionary__initWithObjects_forKeys_(self, _cmd, objects, keyArray)
  40. { with(self)
  41. {
  42. self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPObject") }, "init");
  43. if (objj_msgSend(objects, "count") != objj_msgSend(keyArray, "count"))
  44. objj_msgSend(CPException, "raise:reason:", CPInvalidArgumentException, "Counts are different.("+objj_msgSend(objects, "count")+"!="+objj_msgSend(keyArray, "count")+")");
  45. if (self)
  46. {
  47. var i = objj_msgSend(keyArray, "count");
  48. while (i--)
  49. objj_msgSend(self, "setObject:forKey:", objects[i], keyArray[i]);
  50. }
  51. return self;
  52. }
  53. }), new objj_method(sel_getUid("initWithObjectsAndKeys:"), function $CPDictionary__initWithObjectsAndKeys_(self, _cmd, firstObject)
  54. { with(self)
  55. {
  56. var argCount = arguments.length;
  57. if (argCount % 2 !== 0)
  58. objj_msgSend(CPException, "raise:reason:", CPInvalidArgumentException, "Key-value count is mismatched. (" + argCount + " arguments passed)");
  59. self = objj_msgSendSuper({ receiver:self, super_class:objj_getClass("CPObject") }, "init");
  60. if (self)
  61. {
  62. var index = 2;
  63. for(; index < argCount; index += 2)
  64. {
  65. var value = arguments[index];
  66. if (value === nil)
  67. break;
  68. objj_msgSend(self, "setObject:forKey:", value, arguments[index + 1]);
  69. }
  70. }
  71. return self;
  72. }
  73. }), new objj_method(sel_getUid("copy"), function $CPDictionary__copy(self, _cmd)
  74. { with(self)
  75. {
  76. return objj_msgSend(CPDictionary, "dictionaryWithDictionary:", self);
  77. }
  78. }), new objj_method(sel_getUid("count"), function $CPDictionary__count(self, _cmd)
  79. { with(self)
  80. {
  81. return count;
  82. }
  83. }), new objj_method(sel_getUid("allKeys"), function $CPDictionary__allKeys(self, _cmd)
  84. { with(self)
  85. {
  86. return _keys;
  87. }
  88. }), new objj_method(sel_getUid("allValues"), function $CPDictionary__allValues(self, _cmd)
  89. { with(self)
  90. {
  91. var index = _keys.length,
  92. values = [];
  93. while (index--)
  94. values.push(dictionary_getValue(self, [_keys[index]]));
  95. return values;
  96. }
  97. }), new objj_method(sel_getUid("keyEnumerator"), function $CPDictionary__keyEnumerator(self, _cmd)
  98. { with(self)
  99. {
  100. return objj_msgSend(_keys, "objectEnumerator");
  101. }
  102. }), new objj_method(sel_getUid("objectEnumerator"), function $CPDictionary__objectEnumerator(self, _cmd)
  103. { with(self)
  104. {
  105. return objj_msgSend(objj_msgSend(_CPDictionaryValueEnumerator, "alloc"), "initWithDictionary:", self);
  106. }
  107. }), new objj_method(sel_getUid("isEqualToDictionary:"), function $CPDictionary__isEqualToDictionary_(self, _cmd, aDictionary)
  108. { with(self)
  109. {
  110. if (count !== objj_msgSend(aDictionary, "count"))
  111. return NO;
  112. var index = count;
  113. while (index--)
  114. {
  115. var currentKey = _keys[index],
  116. lhsObject = _buckets[currentKey],
  117. rhsObject = aDictionary._buckets[currentKey];
  118. if (lhsObject === rhsObject)
  119. continue;
  120. if (lhsObject.isa && rhsObject.isa && objj_msgSend(lhsObject, "respondsToSelector:", sel_getUid("isEqual:")) && objj_msgSend(lhsObject, "isEqual:", rhsObject))
  121. continue;
  122. return NO;
  123. }
  124. return YES;
  125. }
  126. }), new objj_method(sel_getUid("objectForKey:"), function $CPDictionary__objectForKey_(self, _cmd, aKey)
  127. { with(self)
  128. {
  129. var object = _buckets[aKey];
  130. return (object === undefined) ? nil : object;
  131. }
  132. }), new objj_method(sel_getUid("removeAllObjects"), function $CPDictionary__removeAllObjects(self, _cmd)
  133. { with(self)
  134. {
  135. _keys = [];
  136. count = 0;
  137. _buckets = {};
  138. }
  139. }), new objj_method(sel_getUid("removeObjectForKey:"), function $CPDictionary__removeObjectForKey_(self, _cmd, aKey)
  140. { with(self)
  141. {
  142. dictionary_removeValue(self, aKey);
  143. }
  144. }), new objj_method(sel_getUid("removeObjectsForKeys:"), function $CPDictionary__removeObjectsForKeys_(self, _cmd, allKeys)
  145. { with(self)
  146. {
  147. var index = allKeys.length;
  148. while (index--)
  149. dictionary_removeValue(self, allKeys[index]);
  150. }
  151. }), new objj_method(sel_getUid("setObject:forKey:"), function $CPDictionary__setObject_forKey_(self, _cmd, anObject, aKey)
  152. { with(self)
  153. {
  154. dictionary_setValue(self, aKey, anObject);
  155. }
  156. }), new objj_method(sel_getUid("addEntriesFromDictionary:"), function $CPDictionary__addEntriesFromDictionary_(self, _cmd, aDictionary)
  157. { with(self)
  158. {
  159. if (!aDictionary)
  160. return;
  161. var keys = objj_msgSend(aDictionary, "allKeys"),
  162. index = objj_msgSend(keys, "count");
  163. while (index--)
  164. {
  165. var key = keys[index];
  166. objj_msgSend(self, "setObject:forKey:", objj_msgSend(aDictionary, "objectForKey:", key), key);
  167. }
  168. }
  169. }), new objj_method(sel_getUid("description"), function $CPDictionary__description(self, _cmd)
  170. { with(self)
  171. {
  172. var description = "CPDictionary {\n";
  173. var i = _keys.length;
  174. while (i--)
  175. {
  176. description += _keys[i] + ":";
  177. var object = _buckets[_keys[i]];
  178. if (object && object.isa)
  179. description += objj_msgSend(object, "description");
  180. else
  181. description += object;
  182. description += "\n";
  183. }
  184. description += "}";
  185. return description;
  186. }
  187. })]);
  188. class_addMethods(meta_class, [new objj_method(sel_getUid("alloc"), function $CPDictionary__alloc(self, _cmd)
  189. { with(self)
  190. {
  191. return new objj_dictionary();
  192. }
  193. }), new objj_method(sel_getUid("dictionary"), function $CPDictionary__dictionary(self, _cmd)
  194. { with(self)
  195. {
  196. return objj_msgSend(objj_msgSend(self, "alloc"), "init");
  197. }
  198. }), new objj_method(sel_getUid("dictionaryWithDictionary:"), function $CPDictionary__dictionaryWithDictionary_(self, _cmd, aDictionary)
  199. { with(self)
  200. {
  201. return objj_msgSend(objj_msgSend(self, "alloc"), "initWithDictionary:", aDictionary);
  202. }
  203. }), new objj_method(sel_getUid("dictionaryWithObject:forKey:"), function $CPDictionary__dictionaryWithObject_forKey_(self, _cmd, anObject, aKey)
  204. { with(self)
  205. {
  206. return objj_msgSend(objj_msgSend(self, "alloc"), "initWithObjects:forKeys:", [anObject], [aKey]);
  207. }
  208. }), new objj_method(sel_getUid("dictionaryWithObjects:forKeys:"), function $CPDictionary__dictionaryWithObjects_forKeys_(self, _cmd, objects, keys)
  209. { with(self)
  210. {
  211. return objj_msgSend(objj_msgSend(self, "alloc"), "initWithObjects:forKeys:", objects, keys);
  212. }
  213. }), new objj_method(sel_getUid("dictionaryWithJSObject:"), function $CPDictionary__dictionaryWithJSObject_(self, _cmd, object)
  214. { with(self)
  215. {
  216. return objj_msgSend(self, "dictionaryWithJSObject:recursively:", object, NO);
  217. }
  218. }), new objj_method(sel_getUid("dictionaryWithJSObject:recursively:"), function $CPDictionary__dictionaryWithJSObject_recursively_(self, _cmd, object, recursively)
  219. { with(self)
  220. {
  221. var dictionary = objj_msgSend(objj_msgSend(self, "alloc"), "init");
  222. for (var key in object)
  223. {
  224. var value = object[key];
  225. if (recursively && value.constructor === Object)
  226. value = objj_msgSend(CPDictionary, "dictionaryWithJSObject:recursively:", value, YES);
  227. objj_msgSend(dictionary, "setObject:forKey:", value, key);
  228. }
  229. return dictionary;
  230. }
  231. }), new objj_method(sel_getUid("dictionaryWithObjectsAndKeys:"), function $CPDictionary__dictionaryWithObjectsAndKeys_(self, _cmd, firstObject)
  232. { with(self)
  233. {
  234. arguments[0] = objj_msgSend(self, "alloc");
  235. arguments[1] = sel_getUid("initWithObjectsAndKeys:");
  236. return objj_msgSend.apply(this, arguments);
  237. }
  238. })]);
  239. }
  240. {
  241. var the_class = objj_getClass("CPDictionary")
  242. if(!the_class) objj_exception_throw(new objj_exception(OBJJClassNotFoundException, "*** Could not find definition for class \"CPDictionary\""));
  243. var meta_class = the_class.isa;class_addMethods(the_class, [new objj_method(sel_getUid("initWithCoder:"), function $CPDictionary__initWithCoder_(self, _cmd, aCoder)
  244. { with(self)
  245. {
  246. return objj_msgSend(aCoder, "_decodeDictionaryOfObjectsForKey:", "CP.objects");
  247. }
  248. }), new objj_method(sel_getUid("encodeWithCoder:"), function $CPDictionary__encodeWithCoder_(self, _cmd, aCoder)
  249. { with(self)
  250. {
  251. objj_msgSend(aCoder, "_encodeDictionaryOfObjects:forKey:", self, "CP.objects");
  252. }
  253. })]);
  254. }
  255. {var the_class = objj_allocateClassPair(CPDictionary, "CPMutableDictionary"),
  256. meta_class = the_class.isa;objj_registerClassPair(the_class);
  257. objj_addClassForBundle(the_class, objj_getBundleWithPath(OBJJ_CURRENT_BUNDLE.path));
  258. }
  259. objj_dictionary.prototype.isa = CPDictionary;