|
activemq-cpp-3.3.0
|
00001 /* 00002 * Licensed to the Apache Software Foundation (ASF) under one or more 00003 * contributor license agreements. See the NOTICE file distributed with 00004 * this work for additional information regarding copyright ownership. 00005 * The ASF licenses this file to You under the Apache License, Version 2.0 00006 * (the "License"); you may not use this file except in compliance with 00007 * the License. You may obtain a copy of the License at 00008 * 00009 * http://www.apache.org/licenses/LICENSE-2.0 00010 * 00011 * Unless required by applicable law or agreed to in writing, software 00012 * distributed under the License is distributed on an "AS IS" BASIS, 00013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 00014 * See the License for the specific language governing permissions and 00015 * limitations under the License. 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 /* _DECAF_UTIL_ARRAYS_H_ */