Exemplo n.º 1
0
ERRORCODE SplitArray::read(StorageDevicePtr device)
{
    ERRORCODE error = ERRORCODE_None;

    Array OldArray(OldSize());
    if ((error = OldArray.read(device)) != ERRORCODE_None)
    {
        return error;
    }

    if ((error = set_array_size(OldArray.count())) != ERRORCODE_None)
    {
        return error;
    }

    LPBYTE lpOldData, lpNewData;

    lpOldData = (LPBYTE)OldArray.get_element(0);
    lpNewData = (LPBYTE)data;

    for (int i = 0; i < OldArray.count(); i++)
    {
        memcpy(lpNewData, lpOldData, OldSize());
        memset(lpNewData + OldSize(), 0, SizeDifference());
        lpNewData += NewSize();
        lpOldData += OldSize();
    }
    return error;
}
Exemplo n.º 2
0
ERRORCODE Array::delete_element(SHORT which)
{
	SHORT new_count;

/* Normalize. */

	which -= first;

/* Validate the parameter. */

	if (which < 0 || which >= element_count)
	{
		return ERRORCODE_BadParameter;
	}

/* Move data down if we need to. */

	new_count = element_count-1;

	if (new_count != which)
	{
		LPSTR dst = ((LPSTR)data) + which*element_size,
				src = dst + element_size;

	/* "which" is not the last one. */

		memcpy(dst, src, (new_count-which)*element_size);
	}

/* Resize the array to take up less space. */

	return set_array_size(new_count);
}
Exemplo n.º 3
0
ERRORCODE Array::assign(const Array far &array)
{
	ERRORCODE error;

/* Free any data we have. */

	set_array_size(0);

/* Copy the static portion. */

	first = array.first;
	element_size = array.element_size;

/* Allocate the new data. */

	if ((error = set_array_size(array.element_count)) == ERRORCODE_None
			&& data != NULL
 			&& array.data != NULL)
	{
	/* Copy the data. */
		memcpy(data, array.data, array_byte_size());
	}
	return error;
}
Exemplo n.º 4
0
ERRORCODE Array::insert_element(VOIDPTR element, SHORT where)
{
	SHORT old_count = element_count;
	ERRORCODE error;

/* Normalize. */

	where -= first;

/* Validate where. */

	if (where < 0 || where > element_count)
	{
		return ERRORCODE_BadParameter;
	}

/*
// Set the new array size.
// After this call, "element_count" will be set to the new size.
// Watch out!
*/

	if ((error = set_array_size(element_count+1)) == ERRORCODE_None)
	{
	/* Move the data if need be. */

		LPSTR new_slot = ((LPSTR)data) + where*element_size,
				dst_slot = new_slot + element_size;

		if (where != old_count)
		{
		/* Must move some data. Use the function which handles overlap. */
			memmove(dst_slot, new_slot, (old_count - where)*element_size);
		}

	/* Insert the new element. */

		memcpy(new_slot, element, element_size);
	}
	return error;
}
Exemplo n.º 5
0
VOID Array::empty_array()
{
	set_array_size(0);
}