Пример #1
0
bool OSDictionary::
setObject(const OSSymbol *aKey, const OSMetaClassBase *anObject)
{
    if (!anObject || !aKey)
        return false;

    // if the key exists, replace the object
    for (unsigned int i = 0; i < count; i++) {
        if (aKey == dictionary[i].key) {
            const OSMetaClassBase *oldObject = dictionary[i].value;

            anObject->taggedRetain(OSTypeID(OSCollection));
            dictionary[i].value = anObject;

            haveUpdated();

            oldObject->taggedRelease(OSTypeID(OSCollection));
            return true;
        }
    }

    // add new key, possibly extending our capacity
    if (count >= capacity && count >= ensureCapacity(count+1))
        return 0;

    aKey->taggedRetain(OSTypeID(OSCollection));
    anObject->taggedRetain(OSTypeID(OSCollection));
    dictionary[count].key = aKey;
    dictionary[count].value = anObject;
    count++;

    haveUpdated();

    return true;
}
Пример #2
0
bool OSDictionary::
setObject(const OSSymbol *aKey, const OSMetaClassBase *anObject, bool onlyAdd)
{
    unsigned int i;
    bool exists;

    if (!anObject || !aKey)
        return false;

    // if the key exists, replace the object

    if (fOptions & kSort) {
    	i = OSSymbol::bsearch(aKey, &dictionary[0], count, sizeof(dictionary[0]));
	exists = (i < count) && (aKey == dictionary[i].key);
    } else for (exists = false, i = 0; i < count; i++) {
        if ((exists = (aKey == dictionary[i].key))) break;
    }

    if (exists) {

	if (onlyAdd) return false;

	const OSMetaClassBase *oldObject = dictionary[i].value;
    
	haveUpdated();
    
	anObject->taggedRetain(OSTypeID(OSCollection));
	dictionary[i].value = anObject;
    
	oldObject->taggedRelease(OSTypeID(OSCollection));
	return true;
    }

    // add new key, possibly extending our capacity
    if (count >= capacity && count >= ensureCapacity(count+1))
        return false;

    haveUpdated();

    bcopy(&dictionary[i], &dictionary[i+1], (count - i) * sizeof(dictionary[0]));

    aKey->taggedRetain(OSTypeID(OSCollection));
    anObject->taggedRetain(OSTypeID(OSCollection));
    dictionary[i].key = aKey;
    dictionary[i].value = anObject;
    count++;

    return true;
}
Пример #3
0
/* internal */
bool OSOrderedSet::setObject(unsigned int index, const OSMetaClassBase *anObject)
{
    unsigned int i;
    unsigned int newCount = count + 1;

    if ((index > count) || !anObject)
        return false;

    if (containsObject(anObject))
        return false;

    // do we need more space?
    if (newCount > capacity && newCount > ensureCapacity(newCount))
        return false;

    haveUpdated();
    if (index != count) {
        for (i = count; i > index; i--)
            array[i] = array[i-1];
    }
    array[index].obj = anObject;
//    array[index].pri = pri;
    anObject->taggedRetain(OSTypeID(OSCollection));
    count++;

    return true;
}
Пример #4
0
void OSDictionary::removeObject(const OSSymbol *aKey)
{
    unsigned int i;
    bool exists;

    if (!aKey)
        return;

    // if the key exists, remove the object

    if (fOptions & kSort) {
    	i = OSSymbol::bsearch(aKey, &dictionary[0], count, sizeof(dictionary[0]));
	exists = (i < count) && (aKey == dictionary[i].key);
    } else for (exists = false, i = 0; i < count; i++) {
        if ((exists = (aKey == dictionary[i].key))) break;
    }

    if (exists) {
	dictEntry oldEntry = dictionary[i];

	haveUpdated();

	count--;
	bcopy(&dictionary[i+1], &dictionary[i], (count - i) * sizeof(dictionary[0]));

	oldEntry.key->taggedRelease(OSTypeID(OSCollection));
	oldEntry.value->taggedRelease(OSTypeID(OSCollection));
	return;
    }
}
Пример #5
0
bool OSSet::setObject(const OSMetaClassBase *anObject)
{
    if (containsObject(anObject)) {
        return false;
    } else {
        haveUpdated();
        return members->setObject(anObject);
    }
}
Пример #6
0
void OSDictionary::flushCollection()
{
    haveUpdated();

    for (unsigned int i = 0; i < count; i++) {
        dictionary[i].key->taggedRelease(OSTypeID(OSCollection));
        dictionary[i].value->taggedRelease(OSTypeID(OSCollection));
    }
    count = 0;
}
Пример #7
0
void OSArray::flushCollection()
{
    unsigned int i;

    haveUpdated();
    for (i = 0; i < count; i++) {
        array[i]->taggedRelease(OSTypeID(OSCollection));
    }
    count = 0;
}
Пример #8
0
void OSOrderedSet::flushCollection()
{
    unsigned int i;

    haveUpdated();

    for (i = 0; i < count; i++)
        array[i].obj->taggedRelease(OSTypeID(OSCollection));

    count = 0;
}
Пример #9
0
void OSSet::removeObject(const OSMetaClassBase *anObject)
{
    const OSMetaClassBase *probeObject;

    for (int i = 0; (probeObject = members->getObject(i)); i++)
        if (probeObject == anObject) {
            haveUpdated();
            members->removeObject(i);
            return;
        }
}
Пример #10
0
void OSArray::
replaceObject(unsigned int index, const OSMetaClassBase *anObject)
{
    const OSMetaClassBase *oldObject;

    if ((index >= count) || !anObject)
        return;

    haveUpdated();
    oldObject = array[index];
    array[index] = anObject;
    anObject->taggedRetain(OSTypeID(OSCollection));

    oldObject->taggedRelease(OSTypeID(OSCollection));
}
Пример #11
0
void OSArray::removeObject(unsigned int index)
{
    unsigned int i;
    const OSMetaClassBase *oldObject;

    if (index >= count)
        return;

    haveUpdated();
    oldObject = array[index];

    count--;
    for (i = index; i < count; i++)
        array[i] = array[i+1];

    oldObject->taggedRelease(OSTypeID(OSCollection));
}
Пример #12
0
void OSOrderedSet::removeObject(const OSMetaClassBase *anObject)
{
    bool		deleted = false;
    unsigned int 	i;

    for (i = 0; i < count; i++) {

        if (deleted)
            array[i-1] = array[i];
        else if (array[i].obj == anObject) {
            deleted = true;
	    haveUpdated();	// Pity we can't flush the log
            array[i].obj->taggedRelease(OSTypeID(OSCollection));
        }
    }

    if (deleted)
	count--;
}
Пример #13
0
void OSDictionary::removeObject(const OSSymbol *aKey)
{
    if (!aKey)
        return;

    // if the key exists, remove the object
    for (unsigned int i = 0; i < count; i++)
        if (aKey == dictionary[i].key) {
            dictEntry oldEntry = dictionary[i];

            haveUpdated();

            count--;
            for (; i < count; i++)
                dictionary[i] = dictionary[i+1];

            oldEntry.key->taggedRelease(OSTypeID(OSCollection));
            oldEntry.value->taggedRelease(OSTypeID(OSCollection));
            return;
        }
}
Пример #14
0
bool OSArray::merge(const OSArray * otherArray)
{
    unsigned int otherCount = otherArray->getCount();
    unsigned int newCount = count + otherCount;

    if (!otherCount)
        return true;

    // do we need more space?
    if (newCount > capacity && newCount > ensureCapacity(newCount))
        return false;

    haveUpdated();
    for (unsigned int i = 0; i < otherCount; i++) {
        const OSMetaClassBase *newObject = otherArray->getObject(i);

        array[count++] = newObject;
        newObject->taggedRetain(OSTypeID(OSCollection));
    }

    return true;
}
Пример #15
0
void OSSet::flushCollection()
{
    haveUpdated();
    members->flushCollection();
}