2010-12-04 16:14:34 +00:00
/********************************************************
* Array . h *
* *
* XFX Array class definition file *
* Contains array helper methods *
* Copyright <EFBFBD> XFX Team . All Rights Reserved *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
# ifndef _SYSTEM_ARRAY_
# define _SYSTEM_ARRAY_
2012-03-29 22:02:43 +00:00
# include "FrameworkResources.h"
2011-01-16 00:47:37 +00:00
# include <System/Collections/Generic/Interfaces.h>
using namespace System : : Collections : : Generic ;
2012-03-29 22:02:43 +00:00
# include <sassert.h>
2011-11-07 01:29:50 +00:00
2010-12-04 16:14:34 +00:00
namespace System
{
class Array
{
public :
2011-01-16 00:47:37 +00:00
template < class T >
2011-11-07 01:29:50 +00:00
static int BinarySearch ( T array [ ] , int index , int length , T value , IComparer < T > * comparer )
{
return - 1 ;
}
2010-12-04 16:14:34 +00:00
template < class T >
2011-11-07 01:29:50 +00:00
static void Clear ( T array [ ] , int index , int length )
{
for ( int i = index ; i < ( index + length ) ; i + + )
{
array [ i ] = null ;
}
}
2010-12-04 16:14:34 +00:00
template < class T >
2011-11-07 01:29:50 +00:00
static void Copy ( T sourceArray [ ] , int sourceIndex , T destinationArray [ ] , int destinationIndex , int length )
{
2012-03-29 22:02:43 +00:00
sassert ( sourceArray ! = null , " " ) ;
2011-11-07 01:29:50 +00:00
2012-03-29 22:02:43 +00:00
sassert ( destinationArray ! = null , " " ) ;
2011-11-07 01:29:50 +00:00
2012-03-29 22:02:43 +00:00
sassert ( sourceIndex > = 0 , " " ) ;
//printf("ARGUMENT_OUT_OF_RANGE in function %s, at line %i in file %s, argument \"%s\": %s\n", __FUNCTION__, __LINE__, __FILE__, "sourceIndex must be 0 or greater");
2011-11-07 01:29:50 +00:00
2012-03-29 22:02:43 +00:00
sassert ( destinationIndex > = 0 , " " ) ;
2011-11-07 01:29:50 +00:00
2012-03-29 22:02:43 +00:00
//printf("ARGUMENT_OUT_OF_RANGE in function %s, at line %i in file %s, argument \"%s\": %s\n", __FUNCTION__, __LINE__, __FILE__, "destinationIndex must be 0 or greater");
/*if((sourceIndex + length) > Length(sourceArray))
2011-11-07 01:29:50 +00:00
{
# if DEBUG
printf ( " ARGUMENT in function %s, at line %i in file %s \n " , __FUNCTION__ , __LINE__ , __FILE__ ) ;
# endif
return ;
}
if ( ( destinationIndex + length ) > Length ( destinationArray ) )
{
# if DEBUG
printf ( " ARGUMENT in function %s, at line %i in file %s \n " , __FUNCTION__ , __LINE__ , __FILE__ ) ;
# endif
return ;
2012-03-29 22:02:43 +00:00
} */
2011-11-07 01:29:50 +00:00
for ( int i = sourceIndex , j = destinationIndex ; i < ( sourceIndex + length ) ; i + + , j + + )
{
destinationArray [ j ] = sourceArray [ i ] ;
}
}
2010-12-04 16:14:34 +00:00
template < class T >
2012-03-29 22:02:43 +00:00
static int IndexOf ( const T array [ ] , const T value , const int startIndex , const int count )
2011-11-07 01:29:50 +00:00
{
2012-03-29 22:02:43 +00:00
for ( int i = startIndex ; i < count ; i + + )
2011-11-07 01:29:50 +00:00
{
2012-03-29 22:02:43 +00:00
if ( array [ i ] = = value )
return i ;
2011-11-07 01:29:50 +00:00
}
2012-03-29 22:02:43 +00:00
return - 1 ;
2011-11-07 01:29:50 +00:00
}
2011-03-07 19:14:57 +00:00
template < class T >
2011-11-07 01:29:50 +00:00
static void Reverse ( T array [ ] , int index , int length )
{
2012-03-29 22:02:43 +00:00
sassert ( array ! = null , " " ) ;
//if ((Length(array) - index) < length)
//printf("ARGUMENT in function %s, at line %i in file %s: %s\n", __FUNCTION__, __LINE__, __FILE__, "Offset and length were out of bounds for the array or count is greater than the number of elements from index to the end of the source collection.");
2011-11-07 01:29:50 +00:00
int num = index ;
int num2 = ( index + length ) - 1 ;
while ( num < num2 )
{
T obj2 = array [ num ] ;
array [ num ] = array [ num2 ] ;
array [ num2 ] = obj2 ;
num + + ;
num2 - - ;
}
}
2010-12-04 16:14:34 +00:00
} ;
}
# endif //_SYSTEM_ARRAY_