00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _DECAF_UTIL_ARRAYS_H_
00019 #define _DECAF_UTIL_ARRAYS_H_
00020
00021 #include <decaf/lang/exceptions/NullPointerException.h>
00022 #include <decaf/lang/exceptions/IllegalArgumentException.h>
00023 #include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
00024
00025 namespace decaf {
00026 namespace util {
00027
00028 class Arrays {
00029 private:
00030
00031 Arrays( const Arrays& source );
00032 Arrays& operator= ( const Arrays& source );
00033
00034 private:
00035
00036 Arrays();
00037
00038 public:
00039
00040 virtual ~Arrays();
00041
00056 template< typename E>
00057 static void fill( E* array, int size, const E& value ) {
00058
00059 if( array == NULL ) {
00060 throw decaf::lang::exceptions::NullPointerException(
00061 __FILE__, __LINE__, "Array pointer given was NULL." );
00062 }
00063
00064 if( size < 0 ) {
00065 throw decaf::lang::exceptions::IllegalArgumentException(
00066 __FILE__, __LINE__, "Array size value given was negative." );
00067 }
00068
00069 for( int i = 0; i < size; ++i ) {
00070 array[i] = value;
00071 }
00072 }
00073
00094 template< typename E>
00095 static void fill( E* array, int size, int start, int end, const E& value ) {
00096
00097 if( array == NULL ) {
00098 throw decaf::lang::exceptions::NullPointerException(
00099 __FILE__, __LINE__, "Array pointer given was NULL." );
00100 }
00101
00102 if( size < 0 ) {
00103 throw decaf::lang::exceptions::IllegalArgumentException(
00104 __FILE__, __LINE__, "Array size value given was negative." );
00105 }
00106
00107 if( start > end ) {
00108 throw decaf::lang::exceptions::IllegalArgumentException(
00109 __FILE__, __LINE__, "The start index was greater than the end index." );
00110 }
00111
00112 if( start < 0 || end > size ) {
00113 throw decaf::lang::exceptions::IndexOutOfBoundsException(
00114 __FILE__, __LINE__, "The start index {%d} end index {%d} range is invalid.", start, end );
00115 }
00116
00117 for( int i = start; i < end; ++i ) {
00118 array[i] = value;
00119 }
00120 }
00121
00122 };
00123
00124 }}
00125
00126 #endif