Exemple #1
0
/*! \relates XsArray
	\brief Appends the \a other list to thisArray list
	\param other The list to append to thisArray list. \a other may point to thisArray list
*/
void XsArray_append(void* thisPtr, void const* other)
{
	XsSize i;
	XsArray* thisArray = (XsArray*) thisPtr;
	XsArray const* otherArray = (XsArray const*) other;

	if (otherArray->m_size == 0)
		return;

	if (otherArray == thisArray)
	{
		if (thisArray->m_size + thisArray->m_size > thisArray->m_reserved)
			XsArray_reserve(thisArray, thisArray->m_size + thisArray->m_size);	// maybe reserve more here?

		for (i=0; i<thisArray->m_size; ++i)
			thisArray->m_descriptor->itemCopy(elemAt(thisArray->m_data, i+thisArray->m_size), elemAt(thisArray->m_data, i));

		*((XsSize*) &thisArray->m_size) = thisArray->m_size + thisArray->m_size;
		return;
	}

	if (thisArray->m_size == 0)
	{
		XsArray_copy(thisArray, otherArray);
		return;
	}

	if (thisArray->m_size + otherArray->m_size > thisArray->m_reserved)
		XsArray_reserve(thisArray, thisArray->m_size + otherArray->m_size);	// maybe reserve more here?

	for (i=0; i<otherArray->m_size; ++i)
		thisArray->m_descriptor->itemCopy(elemAt(thisArray->m_data, i+thisArray->m_size), elemAt(otherArray->m_data, i));

	*((XsSize*) &thisArray->m_size) = thisArray->m_size + otherArray->m_size;
}
Exemple #2
0
/*! \brief This function determines the size of \a src and copies the contents to the object after
	converting it from a unicode string to a multibyte character string.
*/
void XsString_assignWCharArray(XsString* thisPtr, const wchar_t* src)
{
	if (src)
	{
#ifdef WIN32
		int unicodeLength = lstrlenW( src ); // Convert all UNICODE characters
		int required = WideCharToMultiByte(CP_UTF8, 0, src, unicodeLength, NULL, 0, NULL, NULL);
		if (required != -1 && required > 0)
		{
			if ((XsSize)required+1 > thisPtr->m_reserved)
				XsArray_reserve(thisPtr, required+1);
			WideCharToMultiByte(CP_UTF8, 0, src, unicodeLength, thisPtr->m_data, required+1, NULL, NULL); //lint !e534
			thisPtr->m_data[required] = '\0';
			*((XsSize*) &thisPtr->m_size) = required+1;
			return;
		}
#else
		size_t required = wcstombs(0, src, 0);
		if (required != (size_t) -1 && required > 0)
		{
			if ((XsSize)required+1 > thisPtr->m_reserved)
				XsArray_reserve(thisPtr, required+1);
			wcstombs(thisPtr->m_data, src, required+1);	//lint !e534
			*((XsSize*) &thisPtr->m_size) = required+1;
			return;
		}
#endif
	}
	XsArray_assign(thisPtr, 0, 0);
}
Exemple #3
0
/*! \relates XsArray
	\brief Resizes the existing list to \a count items
	\details This function will keep the data of the remaining items intact.
	\param count the number of items the list should have
	\sa XsArray_reserve \sa XsArray_assign
*/
void XsArray_resize(void* thisPtr, XsSize count)
{
	XsArray* thisArray = (XsArray*) thisPtr;
	if (thisArray->m_size == count)
		return;
	if (thisArray->m_size == 0)
	{
		XsArray_assign(thisArray, count, 0);
		return;
	}
	if (count < thisArray->m_size)
	{
		XsArray_erase(thisArray, count, thisArray->m_size - count);
		return;
	}
	if (count > thisArray->m_reserved)
		XsArray_reserve(thisArray, count);
	*((XsSize*) &thisArray->m_size) = count;
}
Exemple #4
0
/*!	\relates XsFile
	\brief Reads a full line from the file
	\param line The result of the read
	\returns XRV_OK if a line could be read
*/
XsResultValue XsFile_getline(struct XsFile *thisPtr, struct XsString *line)
{
	int b;
	XsResultValue ok = XRV_ENDOFFILE;

	XsString_erase(line, 0, line->m_size);
	XsArray_reserve(line, 256);

	b = fgetc(thisPtr->m_handle);
	if (b != -1)
		ok = XRV_OK;

	while (b != -1)
	{
		XsString_push_back(line, (char)b);
		if (b == '\n')
			break;
		b = fgetc(thisPtr->m_handle);
	}
	return ok;
}
Exemple #5
0
/*! \relates XsArray
	\brief Insert \a count items from \a src at \a index in the array
	\param index The index to use for inserting. Anything beyond the end of the array (ie. -1) will
	append to the actual end of the array.
	\param count The number of items to insert
	\param src The items to insert, may not be 0 unless count is 0
*/
void XsArray_insert(void* thisPtr, XsSize index, XsSize count, void const* src)
{
	XsSize s;
	XsArray* thisArray = (XsArray*) thisPtr;
	int i,d = (int) count;
	if (thisArray->m_size + count > thisArray->m_reserved)
		XsArray_reserve(thisArray, ((thisArray->m_size + count)*3)/2);		// we reserve 50% more space here to handle multiple sequential insertions efficiently

	// fix index if beyond end of list
	if (index > thisArray->m_size)
		index = thisArray->m_size;

	// move items to the back by swapping
	for (i = ((int)thisArray->m_size)-1; i >= (int) index; --i)
		thisArray->m_descriptor->itemSwap(elemAt(thisArray->m_data, i), elemAt(thisArray->m_data, i+d));

	// copy items to the array
	for (s = 0; s < count; ++s)
		thisArray->m_descriptor->itemCopy(elemAt(thisArray->m_data, s+index), elemAt(src, s));

	// update size
	*((XsSize*) &thisArray->m_size) = thisArray->m_size + count;
}