26 @implementation _CPDictionaryValueEnumerator :
CPEnumerator
39 _dictionary = aDictionary;
47 var key = [_keyEnumerator nextObject];
52 return [_dictionary objectForKey:key];
84 var result =
new CFMutableDictionary();
85 result.isa = [
self class];
94 return [[
self alloc] init];
104 return [[
self alloc] initWithDictionary:aDictionary];
113 + (id)dictionaryWithObject:(
id)anObject forKey:(
id)aKey
135 + (id)dictionaryWithJSObject:(JSObject)object
145 + (id)dictionaryWithJSObject:(JSObject)object recursively:(BOOL)recursively
148 dictionary = [[
self alloc] init];
152 if (!
object.hasOwnProperty(key))
155 var value =
object[key];
165 if (value.constructor === Object)
167 else if ([value isKindOfClass:
CPArray])
171 count = value.length;
173 for (; i < count; i++)
175 var thisValue = value[i];
177 if (thisValue === null)
179 newValue.push([
CPNull null]);
183 if (thisValue.constructor === Object)
184 newValue.push([
CPDictionary dictionaryWithJSObject:thisValue recursively:YES]);
186 newValue.push(thisValue);
217 + (id)dictionaryWithObjectsAndKeys:(
id)firstObject, ...
219 arguments[0] = [
self alloc];
220 arguments[1] =
@selector(initWithObjectsAndKeys:);
222 return objj_msgSend.apply(
this, arguments);
235 for (key in aDictionary._buckets)
252 if ([objects count] != [keyArray count])
257 var i = [keyArray
count];
280 - (id)initWithObjectsAndKeys:(
id)firstObject, ...
282 var argCount = arguments.length;
284 if (argCount % 2 !== 0)
285 [
CPException raise:CPInvalidArgumentException
reason:"Key-value count is mismatched. (" + argCount + " arguments passed)"];
294 for (; index < argCount; index += 2)
296 var value = arguments[index];
337 var index = _keys.length,
341 values.push(
self.valueForKey(_keys[index]));
356 var count = _keys.length,
362 for (; index < count; ++index)
365 value = _buckets[key];
367 if (value.isa && anObject && anObject.isa && [value respondsToSelector:
@selector(
isEqual:)] && [value
isEqual:anObject])
368 matchingKeys.push(key);
369 else if (value === anObject)
370 matchingKeys.push(key);
376 - (
CPArray)keysOfEntriesPassingTest:(Function )predicate
381 - (
CPArray)keysOfEntriesWithOptions:(CPEnumerationOptions)options passingTest:(Function )predicate
385 var index = [_keys count] - 1,
392 stop = [_keys count],
396 var matchingKeys = [],
400 stopRef = AT_REF(shouldStop);
402 for (; index !== stop; index += increment)
405 value = _buckets[key];
407 if (predicate(key, value, stopRef))
408 matchingKeys.push(key);
417 - (
CPArray)keysSortedByValueUsingComparator:(Function )comparator
424 return comparator(a, b);
429 - (
CPArray)keysSortedByValueUsingSelector:(
SEL)theSelector
436 return [a performSelector:theSelector withObject:b];
446 return [_keys objectEnumerator];
454 return [[_CPDictionaryValueEnumerator alloc] initWithDictionary:self];
462 if (
self === aDictionary)
465 var count = [
self count];
467 if (count !== [aDictionary count])
474 var currentKey = _keys[index],
475 lhsObject = _buckets[currentKey],
476 rhsObject = aDictionary._buckets[currentKey];
478 if (lhsObject === rhsObject)
481 if (lhsObject && lhsObject.isa && rhsObject && rhsObject.isa && [lhsObject respondsToSelector:
@selector(
isEqual:)] && [lhsObject
isEqual:rhsObject])
492 if (
self === anObject)
529 - (id)objectForKey:(
id)aKey
531 var
object = _buckets[aKey];
533 return (
object === undefined) ? nil : object;
560 - (void)removeAllObjects
562 self.removeAllValues();
569 - (void)removeObjectForKey:(
id)aKey
571 self.removeValueForKey(aKey);
578 - (void)removeObjectsForKeys:(
CPArray)keysForRemoval
580 var index = keysForRemoval.length;
603 - (void)setObject:(
id)anObject forKey:(
id)aKey
605 self.setValueForKey(aKey, anObject);
616 var keys = [aDictionary
allKeys],
617 index = [keys
count];
621 var key = keys[index];
637 for (; index < count; ++index)
639 var key = keys[index],
640 value = valueForKey(key);
648 - (BOOL)containsKey:(
id)aKey
651 return ((value !== nil) && (value !== undefined));
654 - (void)enumerateKeysAndObjectsUsingBlock:(Function )aFunction
657 shouldStopRef = AT_REF(shouldStop);
659 for (var index = 0; index < _count; index++)
661 var key = _keys[index],
662 value = valueForKey(key);
664 aFunction(key, value, shouldStopRef);
671 - (void)enumerateKeysAndObjectsWithOptions:(CPEnumerationOptions)opts usingBlock:(Function )aFunction
690 return [aCoder _decodeDictionaryOfObjectsForKey:@"CP.objects"];
699 [aCoder _encodeDictionaryOfObjects:self forKey:@"CP.objects"];