00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef _DECAF_INTERNAL_NIO_BYTEBUFFER_H_
00019 #define _DECAF_INTERNAL_NIO_BYTEBUFFER_H_
00020
00021 #include <decaf/nio/ByteBuffer.h>
00022 #include <decaf/lang/exceptions/NullPointerException.h>
00023 #include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
00024 #include <decaf/lang/exceptions/IllegalArgumentException.h>
00025 #include <decaf/nio/BufferUnderflowException.h>
00026 #include <decaf/nio/BufferOverflowException.h>
00027 #include <decaf/nio/ReadOnlyBufferException.h>
00028 #include <decaf/internal/util/ByteArrayAdapter.h>
00029
00030 #include <decaf/nio/CharBuffer.h>
00031 #include <decaf/nio/DoubleBuffer.h>
00032 #include <decaf/nio/FloatBuffer.h>
00033 #include <decaf/nio/ShortBuffer.h>
00034 #include <decaf/nio/IntBuffer.h>
00035 #include <decaf/nio/LongBuffer.h>
00036
00037 #include <decaf/lang/Pointer.h>
00038
00039 namespace decaf{
00040 namespace internal{
00041 namespace nio{
00042
00043 using decaf::internal::util::ByteArrayAdapter;
00044
00104 class DECAF_API ByteArrayBuffer : public decaf::nio::ByteBuffer {
00105 private:
00106
00107
00108 decaf::lang::Pointer<ByteArrayAdapter> _array;
00109
00110
00111 int offset;
00112
00113
00114 int length;
00115
00116
00117 bool readOnly;
00118
00119 public:
00120
00133 ByteArrayBuffer( int capacity, bool readOnly = false );
00134
00153 ByteArrayBuffer( unsigned char* array, int size, int offset, int length,
00154 bool readOnly = false );
00155
00173 ByteArrayBuffer( const decaf::lang::Pointer<ByteArrayAdapter>& array,
00174 int offset, int length, bool readOnly = false );
00175
00184 ByteArrayBuffer( const ByteArrayBuffer& other );
00185
00186 virtual ~ByteArrayBuffer();
00187
00188 public:
00189
00193 virtual bool isReadOnly() const {
00194 return this->readOnly;
00195 }
00196
00200 virtual unsigned char* array();
00201
00205 virtual int arrayOffset() const;
00206
00210 virtual bool hasArray() const { return true; }
00211
00212 public:
00213
00217 virtual decaf::nio::CharBuffer* asCharBuffer() const { return NULL; }
00218
00222 virtual decaf::nio::DoubleBuffer* asDoubleBuffer() const { return NULL; }
00223
00227 virtual decaf::nio::FloatBuffer* asFloatBuffer() const { return NULL; }
00228
00232 virtual decaf::nio::IntBuffer* asIntBuffer() const { return NULL; }
00233
00237 virtual decaf::nio::LongBuffer* asLongBuffer() const { return NULL; }
00238
00242 virtual decaf::nio::ShortBuffer* asShortBuffer() const { return NULL; }
00243
00247 virtual ByteArrayBuffer* asReadOnlyBuffer() const;
00248
00252 virtual ByteArrayBuffer& compact();
00253
00257 virtual ByteArrayBuffer* duplicate();
00258
00262 virtual unsigned char get() const;
00263
00267 virtual unsigned char get( int index ) const;
00268
00272 virtual char getChar() {
00273 return (char)this->get();
00274 }
00275
00279 virtual char getChar( int index ) const {
00280
00281 return (char)this->get( index );
00282 }
00283
00287 virtual double getDouble();
00288
00292 virtual double getDouble( int index ) const;
00293
00297 virtual float getFloat();
00298
00302 virtual float getFloat( int index ) const;
00303
00307 virtual long long getLong();
00308
00312 virtual long long getLong( int index ) const;
00313
00317 virtual int getInt();
00318
00322 virtual int getInt( int index ) const;
00323
00327 virtual short getShort();
00328
00332 virtual short getShort( int index ) const;
00333
00337 virtual ByteArrayBuffer& put( unsigned char value );
00338
00342 virtual ByteArrayBuffer& put( int index, unsigned char value );
00343
00347 virtual ByteArrayBuffer& putChar( char value );
00348
00352 virtual ByteArrayBuffer& putChar( int index, char value );
00353
00357 virtual ByteArrayBuffer& putDouble( double value );
00358
00362 virtual ByteArrayBuffer& putDouble( int index, double value );
00363
00367 virtual ByteArrayBuffer& putFloat( float value );
00368
00372 virtual ByteArrayBuffer& putFloat( int index, float value );
00373
00377 virtual ByteArrayBuffer& putLong( long long value );
00378
00382 virtual ByteArrayBuffer& putLong( int index, long long value );
00383
00387 virtual ByteArrayBuffer& putInt( int value );
00388
00392 virtual ByteArrayBuffer& putInt( int index, int value );
00393
00397 virtual ByteArrayBuffer& putShort( short value );
00398
00402 virtual ByteArrayBuffer& putShort( int index, short value );
00403
00407 virtual ByteArrayBuffer* slice() const;
00408
00409 protected:
00410
00417 virtual void setReadOnly( bool value ) {
00418 this->readOnly = value;
00419 }
00420
00421 };
00422
00423 }}}
00424
00425 #endif