|
activemq-cpp-3.4.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_INTERNAL_UTIL_BYTEARRAYADAPTER_H_ 00019 #define _DECAF_INTERNAL_UTIL_BYTEARRAYADAPTER_H_ 00020 00021 #include <decaf/lang/exceptions/InvalidStateException.h> 00022 #include <decaf/lang/exceptions/IllegalArgumentException.h> 00023 #include <decaf/lang/exceptions/IndexOutOfBoundsException.h> 00024 #include <decaf/lang/exceptions/NullPointerException.h> 00025 #include <decaf/nio/BufferUnderflowException.h> 00026 #include <decaf/nio/BufferOverflowException.h> 00027 00028 namespace decaf{ 00029 namespace internal{ 00030 namespace util{ 00031 00043 class DECAF_API ByteArrayAdapter { 00044 private: 00045 00046 // Used to allow this adapter to view its array as the different 00047 // types it supports 00048 union Array { 00049 unsigned char* bytes; 00050 char* chars; 00051 short* shorts; 00052 int* ints; 00053 long long* longs; 00054 float* floats; 00055 double* doubles; 00056 }; 00057 00058 // Buffer to read and write to, may be shared with other instances. 00059 Array array; 00060 00061 // Size of the Buffer 00062 int size; 00063 00064 // Whether this object owns the buffer 00065 bool own; 00066 00067 public: 00068 00079 ByteArrayAdapter( int size ); 00080 00095 ByteArrayAdapter( unsigned char* array, int size, bool own = false ); 00096 00111 ByteArrayAdapter( char* array, int size, bool own = false ); 00112 00127 ByteArrayAdapter( double* array, int size, bool own = false ); 00128 00143 ByteArrayAdapter( float* array, int size, bool own = false ); 00144 00159 ByteArrayAdapter( long long* array, int size, bool own = false ); 00160 00175 ByteArrayAdapter( int* array, int size, bool own = false ); 00176 00191 ByteArrayAdapter( short* array, int size, bool own = false ); 00192 00193 virtual ~ByteArrayAdapter(); 00194 00199 virtual int getCapacity() const { 00200 return this->size; 00201 } 00202 00207 virtual int getCharCapacity() const { 00208 return this->size; 00209 } 00210 00215 virtual int getDoubleCapacity() const { 00216 return this->size / (int)sizeof( double ); 00217 } 00218 00223 virtual int getFloatCapacity() const { 00224 return this->size / (int)sizeof( float ); 00225 } 00226 00231 virtual int getLongCapacity() const { 00232 return this->size / (int)sizeof( long long ); 00233 } 00234 00239 virtual int getIntCapacity() const { 00240 return this->size / (int)sizeof( int ); 00241 } 00242 00247 virtual int getShortCapacity() const { 00248 return this->size / (int)sizeof( short ); 00249 } 00250 00256 virtual unsigned char* getByteArray() { 00257 return this->array.bytes; 00258 } 00259 00265 virtual char* getCharArray() { 00266 return this->array.chars; 00267 } 00268 00274 virtual short* getShortArray() { 00275 return this->array.shorts; 00276 } 00277 00283 virtual int* getIntArray() { 00284 return this->array.ints; 00285 } 00286 00292 virtual long long* getLongArray() { 00293 return this->array.longs; 00294 } 00295 00301 virtual double* getDoubleArray() { 00302 return this->array.doubles; 00303 } 00304 00310 virtual float* getFloatArray() { 00311 return this->array.floats; 00312 } 00313 00333 virtual void read( unsigned char* buffer, int size, int offset, int length ) const; 00334 00355 virtual void write( unsigned char* buffer, int size, int offset, int length ); 00356 00372 virtual void resize( int size ); 00373 00377 virtual void clear() throw(); 00378 00390 unsigned char& operator[]( int index ); 00391 const unsigned char& operator[]( int index ) const; 00392 00404 virtual unsigned char get( int index ) const; 00405 00417 virtual char getChar( int index ) const; 00418 00433 virtual double getDouble( int index ) const; 00434 00446 virtual double getDoubleAt( int index ) const; 00447 00462 virtual float getFloat( int index ) const; 00463 00475 virtual float getFloatAt( int index ) const; 00476 00491 virtual long long getLong( int index ) const; 00492 00504 virtual long long getLongAt( int index ) const; 00505 00520 virtual int getInt( int index ) const; 00521 00533 virtual int getIntAt( int index ) const; 00534 00549 virtual short getShort( int index ) const; 00550 00562 virtual short getShortAt( int index ) const; 00563 00580 virtual ByteArrayAdapter& put( int index, unsigned char value ); 00581 00598 virtual ByteArrayAdapter& putChar( int index, char value ); 00599 00616 virtual ByteArrayAdapter& putDouble( int index, double value ); 00617 00632 virtual ByteArrayAdapter& putDoubleAt( int index, double value ); 00633 00650 virtual ByteArrayAdapter& putFloat( int index, float value ); 00651 00666 virtual ByteArrayAdapter& putFloatAt( int index, float value ); 00667 00684 virtual ByteArrayAdapter& putLong( int index, long long value ); 00685 00700 virtual ByteArrayAdapter& putLongAt( int index, long long value ); 00701 00718 virtual ByteArrayAdapter& putInt( int index, int value ); 00719 00734 virtual ByteArrayAdapter& putIntAt( int index, int value ); 00735 00752 virtual ByteArrayAdapter& putShort( int index, short value ); 00753 00768 virtual ByteArrayAdapter& putShortAt( int index, short value ); 00769 00770 private: 00771 00772 void initialize( unsigned char* buffer, int size, bool own ); 00773 00774 }; 00775 00776 }}} 00777 00778 #endif /*_DECAF_INTERNAL_UTIL_BYTEARRAYADAPTER_H_*/