DeprecatedValueListImplIterator DeprecatedValueListImpl::removeIterator(DeprecatedValueListImplIterator &iterator)
{
    copyOnWrite();

    if (iterator.nodeImpl == NULL) {
        return iterator;
    }

    DeprecatedValueListImplNode *next = iterator.nodeImpl->next;

    // detach node
    if (iterator.nodeImpl->next != NULL) {
        iterator.nodeImpl->next->prev = iterator.nodeImpl->prev;
    } else {
        d->tail = iterator.nodeImpl->prev;
    }
    if (iterator.nodeImpl->prev != NULL) {
        iterator.nodeImpl->prev->next = iterator.nodeImpl->next;
    } else {
        d->head = iterator.nodeImpl->next;
    }
    
    d->deleteNode(iterator.nodeImpl);
    d->count--;

    return DeprecatedValueListImplIterator(next);
}
示例#2
0
static void test2( void )
{
    static const char *p1Str = "1234512345";
    static const char *p2Str = "1234567890";

    char *p1;
    char *p2;

    printf("***** Test2: Copy to source memory...\n");

    DosAllocMem(( PPVOID )&p1, ALLOC_SIZE, fPERM | PAG_COMMIT );

    strcpy( p1, p2Str);
    p2 = copyOnWrite( p1, COPY_SIZE );

    printf("p1 = %p, p2 = %p\n", p1, p2 );
    printf("p1 = [%s], p2 = [%s]\n", p1, p2 );

    printf("Copying %.5s to ( p1 + 5 )\n", p1Str );
    memcpy( p1 + 5, p1Str, 5 );

    printf("p1 = [%s], p2 = [%s]\n", p1, p2 );

    fprintf( stderr, "Test2: ");
    if( memcmp( p1, p1Str, strlen( p1Str ))
        || memcmp( p2, p2Str, strlen( p2Str )))
        fprintf( stderr, "Failed\n");
    else
        fprintf( stderr, "Succeeded\n");

    DosFreeMem( p2 );
    DosFreeMem( p1 );
}
void DeprecatedValueListImpl::removeEqualNodes(DeprecatedValueListImplNode *node, bool (*equalFunc)(const DeprecatedValueListImplNode *, const DeprecatedValueListImplNode *))
{
    copyOnWrite();

    DeprecatedValueListImplNode *next;
    for (DeprecatedValueListImplNode *p = d->head; p != NULL; p = next) {
        next = p->next;
        if (equalFunc(node, p)) {
            if (p->next != NULL) {
                p->next->prev = p->prev;
            } else {
                d->tail = p->prev;
            }

            if (p->prev != NULL) {
                p->prev->next = p->next;
            } else {
                d->head = p->next;
            }

            d->deleteNode(p);

            d->count--;
        }
    }
}
void VirtualMemberFunctionTable::setMemberFunction( size_t a_uiIndex, MemberFunction* a_pMemberFunction )
{
    o_assert(a_pMemberFunction->getVirtualTableIndex() == a_uiIndex);
    if(sharesMemberFunctions())
        copyOnWrite();
    m_pMemberFunctions->resize(std::max(a_uiIndex+1, getMemberFunctionCount()));
    (*m_pMemberFunctions)[a_uiIndex] = a_pMemberFunction;
}
void DeprecatedValueListImpl::clear()
{
    if (d->head) {
        copyOnWrite();
        d->deleteList(d->head);
        d->head = NULL;
        d->tail = NULL;
        d->count = 0;
    }
}
示例#6
0
static void test7( void )
{
    printf("***** Test7: Decommit source memory which is destination memory "
           "of other source memory...\n");

    static const char *p1Str = "6789067890";
    static const char *p3Str = "1234567890";

    char *p1;
    char *p2;
    char *p3;

    DosAllocMem(( PPVOID )&p1, ALLOC_SIZE, fPERM | PAG_COMMIT );

    strcpy( p1, p3Str);
    p2 = copyOnWrite( p1, COPY_SIZE );
    p3 = copyOnWrite( p2, COPY_SIZE );

    printf("p1 = %p, p2 = %p, p3 = %p\n", p1, p2, p3 );
    printf("p1 = [%s], p2 = [%s], p3 = [%s]\n", p1, p2, p3 );

    printf("Decommiting p2\n");
    printf("DosSetMem( p2 ) = %ld\n",
           DosSetMem( p2, COPY_SIZE, PAG_DECOMMIT ));

    printf("Copying %.5s to p1\n", p1 + 5 );
    memcpy( p1, p1 + 5, 5 );

    printf("p1 = [%s], p3 = [%s]\n", p1, p3 );

    fprintf( stderr, "Test7: ");
    if( memcmp( p1, p1Str, strlen( p1Str ))
        || memcmp( p3, p3Str, strlen( p3Str )))
        fprintf( stderr, "Failed\n");
    else
        fprintf( stderr, "Succeeded\n");

    DosFreeMem( p3 );
    DosFreeMem( p2 );
    DosFreeMem( p1 );
}
示例#7
0
static void test4( void )
{
    printf("***** Test4: Free source memory...\n");

    static const char *p2Str = "6789067890";
    static const char *p3Str = "1234567890";

    char *p1;
    char *p2;
    char *p3;

    DosAllocMem(( PPVOID )&p1, ALLOC_SIZE, fPERM | PAG_COMMIT );

    strcpy( p1, p3Str);
    p2 = copyOnWrite( p1, COPY_SIZE );
    p3 = copyOnWrite( p2, COPY_SIZE );

    printf("p1 = %p, p2 = %p, p3 = %p\n", p1, p2, p3 );
    printf("p1 = [%s], p2 = [%s], p3 = [%s]\n", p1, p2, p3 );

    printf("Freeing p1\n");
    printf("DosFreeMem( p1 ) = %ld\n", DosFreeMem( p1 ));

    printf("Copying %.5s to p2\n", p2 + 5 );
    memcpy( p2, p2 + 5, 5 );

    printf("p2 = [%s], p3 = [%s]\n", p2, p3 );

    fprintf( stderr, "Test4: ");
    if( memcmp( p2, p2Str, strlen( p2Str ))
        || memcmp( p3, p3Str, strlen( p3Str )))
        fprintf( stderr, "Failed\n");
    else
        fprintf( stderr, "Succeeded\n");

    DosFreeMem( p3 );
    DosFreeMem( p2 );
}
DeprecatedValueListImplNode *DeprecatedValueListImpl::nodeAt(unsigned index)
{
    copyOnWrite();

    if (d->count <= index) {
        return NULL;
    }

    DeprecatedValueListImplNode *p = d->head;

    for (unsigned i = 0; i < index; i++) {
        p = p->next;
    }

    return p;
}
DeprecatedValueListImplIterator DeprecatedValueListImpl::prependNode(DeprecatedValueListImplNode *node)
{
    copyOnWrite();

    node->next = d->head;
    node->prev = NULL;
    d->head = node;

    if (d->tail == NULL) {
        d->tail = node;
    } else {
        node->next->prev = node;
    }

    d->count++;
    
    return node;
}
DeprecatedValueListImplIterator DeprecatedValueListImpl::insert(const DeprecatedValueListImplIterator &iterator, DeprecatedValueListImplNode *node)
{
    copyOnWrite();
    
    DeprecatedValueListImplNode *next = iterator.nodeImpl;
    
    if (next == NULL)
        return appendNode(node);
    
    if (next == d->head)
        return prependNode(node);
    
    DeprecatedValueListImplNode *prev = next->prev;
    
    node->next = next;
    node->prev = prev;
    next->prev = node;
    prev->next = node;
    
    d->count++;
    
    return node;
}
DeprecatedValueListImplIterator DeprecatedValueListImpl::end()
{
    copyOnWrite();
    return ((const DeprecatedValueListImpl *)this)->end();
}
DeprecatedValueListImplNode *DeprecatedValueListImpl::lastNode()
{
    copyOnWrite();
    return ((const DeprecatedValueListImpl *)this)->lastNode();
}
DeprecatedValueListImplIterator DeprecatedValueListImpl::fromLast()
{
    copyOnWrite();
    return DeprecatedValueListImplIterator(lastNode());
}