/*	XGSizeArray.cpp
 *
 *		This is the code to deal with objects which require no special
 *	assistance
 */

/*  YAAF - Yet another application framework
 *  Copyright (C) 1997, 1998 William Edward Woody
 *  
 *  This library is free software; you can redistribute it
 *  and/or modify it under the terms of the GNU Library
 *  General Public License as published by the Free Software
 *  Foundation; either version 2 of the License, or any
 *  later version.
 *  
 *  This library is distributed in the hope that it will be
 *  useful, but WITHOUT ANY WARRANTY; without even the implied
 *  warranty of MERCHANTABIILITY or FITNESS FOR A PARTICULAR
 *  PURPOSE. See the GNU Library General Public License for
 *  more details.
 *  
 *  You should have received a copy of the GNU Library General
 *  Public License along with this library; if not, write to the
 *  Free Software Foundation, Inc., 59 Temple Place - Suite 330,
 *  Boston, MA 02111-1307, USA.
 *  
 *  To contact the author, either e-mail me at woody@pandawave.com, 
 *	or write to
 *  
 *          William Edward Woody
 *          In Phase Consulting
 *          1545 Ard Eevin Avenue
 *          Glendale, CA 91202
 *
 *	Or visit us on the web at http://www.pandawave.com
 */

#include <XConfig.h>			// must be first to optimize compile on MSVC++
#include <string.h>
#include <XDynArray.h>

/************************************************************************/
/*																		*/
/*	Construction/Destruction											*/
/*																		*/
/************************************************************************/

/*	@F"XGSizeArray::XGSizeArray" @I
 *
 *		Creates an empty array of memory.
 */

XGSizeArray::XGSizeArray(size_t s)
{
	fArray = NULL;
	fSize = s;
}

/*	@F"XGSizeArray::~XGSizeArray" @I
 *
 *		Deletes me and releases the resources without calling any item
 *	destructors.
 */

XGSizeArray::~XGSizeArray()
{
	if (fArray) delete[] fArray;
}

/************************************************************************/
/*																		*/
/*	Copy operations														*/
/*																		*/
/************************************************************************/

/*	XGSizeArray::ChangeArray
 *
 *		Change the size of this array
 */

void XGSizeArray::ChangeArray(long newsize, long copy)
{
	unsigned char *array;
	
	if (newsize) array = new unsigned char[newsize * fSize];
	else array = NULL;
	if (copy) memcpy(array,fArray,fSize * copy);
	if (fArray) delete[] fArray;
	fArray = array;
}

/*	XGSizeArray::CopyArray
 *
 *		Copy array elements
 */

void XGSizeArray::CopyArray(long dest, long src)
{
	memcpy(fArray + dest * fSize, fArray + src * fSize, fSize);
}

/*	XGSizeArray::CopyElement
 *
 *		Copy a single element
 */

void XGSizeArray::CopyElement(long dest, const void *src)
{
	memcpy(fArray + dest * fSize, src, fSize);
}

/*	XGSizeArray::GetElement
 *
 *		Get an element
 */

void *XGSizeArray::GetElement(long i) const
{
	return (void *)(fArray + i * fSize);
}

