bool OSDictionary::initWithObjects(const OSObject *objects[], const OSSymbol *keys[], unsigned int theCount, unsigned int theCapacity) { unsigned int newCapacity = theCount; if (!objects || !keys) return false; if ( theCapacity ) { if (theCount > theCapacity) return false; newCapacity = theCapacity; } if (!initWithCapacity(newCapacity)) return false; for (unsigned int i = 0; i < theCount; i++) { const OSMetaClassBase *newObject = *objects++; if (!newObject || !keys[i] || !setObject(keys[i], newObject)) return false; } return true; }
bool OSSet::initWithObjects(const OSObject *inObjects[], unsigned int inCount, unsigned int inCapacity) { unsigned int capacity = inCount; if ( inCapacity ) { if ( inCount > inCapacity ) return false; capacity = inCapacity; } if (!inObjects || !initWithCapacity(capacity)) return false; for ( unsigned int i = 0; i < inCount; i++ ) { // xx-review: no test here for failure of setObject() if (members->getCount() < inCapacity) setObject(inObjects[i]); else return false; } return true; }
bool OSArray::initWithObjects(const OSObject *objects[], unsigned int theCount, unsigned int theCapacity) { unsigned int initCapacity; if (!theCapacity) initCapacity = theCount; else if (theCount > theCapacity) return false; else initCapacity = theCapacity; if (!objects || !initWithCapacity(initCapacity)) return false; for ( unsigned int i = 0; i < theCount; i++ ) { const OSMetaClassBase *newObject = *objects++; if (!newObject) return false; array[count++] = newObject; newObject->taggedRetain(OSTypeID(OSCollection)); } return true; }
bool OSDictionary::initWithDictionary(const OSDictionary *dict, unsigned int theCapacity) { unsigned int capacity; if ( !dict ) return false; capacity = dict->count; if ( theCapacity ) { if ( dict->count > theCapacity ) return false; capacity = theCapacity; } if (!initWithCapacity(capacity)) return false; count = dict->count; bcopy(dict->dictionary, dictionary, count * sizeof(dictEntry)); for (unsigned int i = 0; i < count; i++) { dictionary[i].key->taggedRetain(OSTypeID(OSCollection)); dictionary[i].value->taggedRetain(OSTypeID(OSCollection)); } return true; }
void BulletPool::init(int capacity, cocos2d::Node* parent) { if (getAvailableItemCount() > 0) clearPool(); mParent = parent; initWithCapacity(capacity); }
void SpritePool::init(int capacity, cocos2d::SpriteFrame* spriteFrame, cocos2d::Node* parent) { if (getAvailableItemCount() > 0) clearPool(); mSpriteFrame = spriteFrame; mParent = parent; initWithCapacity(capacity); }
bool CCArray::initWithArray(CCArray* otherArray) { bool bRet = false; do { CC_BREAK_IF(! initWithCapacity(otherArray->data->num)); addObjectsFromArray(otherArray); bRet = true; } while (0); return bRet; }
//============================================================================== // IOHIDEvent::initWithType //============================================================================== bool IOHIDEvent::initWithType(IOHIDEventType type, IOByteCount additionalCapacity) { size_t capacity = 0; IOHIDEventGetSize(type,capacity); if ( !initWithCapacity(capacity+additionalCapacity) ) return false; _data->type = type; _typeMask = IOHIDEventTypeMask(type); return true; }
Boolean IODataQueue::initWithEntries(UInt32 numEntries, UInt32 entrySize) { // Checking overflow for (numEntries + 1)*(entrySize + DATA_QUEUE_ENTRY_HEADER_SIZE): // check (entrySize + DATA_QUEUE_ENTRY_HEADER_SIZE) if ((entrySize > UINT32_MAX - DATA_QUEUE_ENTRY_HEADER_SIZE) || // check (numEntries + 1) (numEntries > UINT32_MAX-1) || // check (numEntries + 1)*(entrySize + DATA_QUEUE_ENTRY_HEADER_SIZE) (entrySize + DATA_QUEUE_ENTRY_HEADER_SIZE > UINT32_MAX/(numEntries+1))) { return false; } return (initWithCapacity((numEntries + 1) * (DATA_QUEUE_ENTRY_HEADER_SIZE + entrySize))); }
void ObjectPool::init(int capacity, Object* sample, cocos2d::Node* parent) { if (getAvailableItemCount() > 0) clearPool(); mParent = parent; mSample = sample; mSample->setVisible(false); mSample->pause(); mSample->setPosition(-10, -10); mParent->addChild(mSample); //TODO: enable retain, and implement release // mSample->retain(); initWithCapacity(capacity); }
bool OSDictionary::initWithDictionary(const OSDictionary *dict, unsigned int theCapacity) { unsigned int newCapacity; if ( !dict ) return false; newCapacity = dict->count; if ( theCapacity ) { if ( dict->count > theCapacity ) return false; newCapacity = theCapacity; } if (!initWithCapacity(newCapacity)) return false; if ((kSort & fOptions) && !(kSort & dict->fOptions)) { for (unsigned int i = 0; i < dict->count; i++) { if (!setObject(dict->dictionary[i].key, dict->dictionary[i].value)) { return false; } } return true; } count = dict->count; bcopy(dict->dictionary, dictionary, count * sizeof(dictEntry)); for (unsigned int i = 0; i < count; i++) { dictionary[i].key->taggedRetain(OSTypeID(OSCollection)); dictionary[i].value->taggedRetain(OSTypeID(OSCollection)); } return true; }
bool OSDictionary::initWithObjects(const OSObject *objects[], const OSString *keys[], unsigned int theCount, unsigned int theCapacity) { unsigned int capacity = theCount; if (!objects || !keys) return false; if ( theCapacity ) { if (theCount > theCapacity) return false; capacity = theCapacity; } if (!initWithCapacity(capacity)) return false; for (unsigned int i = 0; i < theCount; i++) { const OSSymbol *key = OSSymbol::withString(*keys++); const OSMetaClassBase *newObject = *objects++; if (!key) return false; if (!newObject || !setObject(key, newObject)) { key->release(); return false; } key->release(); } return true; }
CCArray::CCArray(unsigned int capacity) : data(NULL) { initWithCapacity(capacity); }
bool CCArray::init() { return initWithCapacity(1); }