activemq-cpp-3.3.0

src/main/decaf/nio/ByteBuffer.h

Go to the documentation of this file.
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_NIO_BYTEBUFFER_H_
00019 #define _DECAF_NIO_BYTEBUFFER_H_
00020 
00021 #include <decaf/nio/Buffer.h>
00022 #include <decaf/lang/Comparable.h>
00023 #include <decaf/lang/exceptions/NullPointerException.h>
00024 #include <decaf/lang/exceptions/IndexOutOfBoundsException.h>
00025 #include <decaf/nio/BufferUnderflowException.h>
00026 #include <decaf/nio/BufferOverflowException.h>
00027 #include <decaf/nio/ReadOnlyBufferException.h>
00028 
00029 namespace decaf{
00030 namespace nio{
00031 
00032     class CharBuffer;
00033     class DoubleBuffer;
00034     class FloatBuffer;
00035     class ShortBuffer;
00036     class IntBuffer;
00037     class LongBuffer;
00038 
00097     class DECAF_API ByteBuffer : public Buffer,
00098                                  public lang::Comparable<ByteBuffer> {
00099     protected:
00100 
00111         ByteBuffer( int capacity );
00112 
00113     public:
00114 
00115         virtual ~ByteBuffer() {}
00116 
00120         virtual std::string toString() const;
00121 
00136         ByteBuffer& get( std::vector<unsigned char> buffer );
00137 
00167         ByteBuffer& get( unsigned char* buffer, int size, int offset, int length );
00168 
00189         ByteBuffer& put( ByteBuffer& src );
00190 
00218         ByteBuffer& put( const unsigned char* buffer, int size, int offset, int length );
00219 
00232         ByteBuffer& put( std::vector<unsigned char>& buffer );
00233 
00234     public:   // Abstract Methods
00235 
00241         virtual bool isReadOnly() const = 0;
00242 
00259         virtual unsigned char* array() = 0;
00260 
00279         virtual int arrayOffset() const = 0;
00280 
00290         virtual bool hasArray() const = 0;
00291 
00305         virtual CharBuffer* asCharBuffer() const = 0;
00306 
00321         virtual DoubleBuffer* asDoubleBuffer() const = 0;
00322 
00337         virtual FloatBuffer* asFloatBuffer() const = 0;
00338 
00353         virtual IntBuffer* asIntBuffer() const = 0;
00354 
00369         virtual LongBuffer* asLongBuffer() const = 0;
00370 
00385         virtual ShortBuffer* asShortBuffer() const = 0;
00386 
00404         virtual ByteBuffer* asReadOnlyBuffer() const = 0;
00405 
00424         virtual ByteBuffer& compact() = 0;
00425 
00439         virtual ByteBuffer* duplicate() = 0;
00440 
00450         virtual unsigned char get() const = 0;
00451 
00463         virtual unsigned char get( int index ) const = 0;
00464 
00474         virtual char getChar() = 0;
00475 
00487         virtual char getChar( int index ) const = 0;
00488 
00498         virtual double getDouble() = 0;
00499 
00511         virtual double getDouble( int index ) const = 0;
00512 
00522         virtual float getFloat() = 0;
00523 
00535         virtual float getFloat( int index ) const = 0;
00536 
00546         virtual long long getLong() = 0;
00547 
00559         virtual long long getLong( int index ) const = 0;
00560 
00570         virtual int getInt() = 0;
00571 
00583         virtual int getInt( int index ) const = 0;
00584 
00594         virtual short getShort() = 0;
00595 
00607         virtual short getShort( int index ) const = 0;
00608 
00621         virtual ByteBuffer& put( unsigned char value ) = 0;
00622 
00635         virtual ByteBuffer& put( int index, unsigned char value ) = 0;
00636 
00650         virtual ByteBuffer& putChar( char value ) = 0;
00651 
00667         virtual ByteBuffer& putChar( int index, char value ) = 0;
00668 
00682         virtual ByteBuffer& putDouble( double value ) = 0;
00683 
00699         virtual ByteBuffer& putDouble( int index, double value ) = 0;
00700 
00714         virtual ByteBuffer& putFloat( float value ) = 0;
00715 
00731         virtual ByteBuffer& putFloat( int index, float value ) = 0;
00732 
00746         virtual ByteBuffer& putLong( long long value ) = 0;
00747 
00763         virtual ByteBuffer& putLong( int index, long long value ) = 0;
00764 
00778         virtual ByteBuffer& putInt( int value ) = 0;
00779 
00795         virtual ByteBuffer& putInt( int index, int value ) = 0;
00796 
00810         virtual ByteBuffer& putShort( short value ) = 0;
00811 
00827         virtual ByteBuffer& putShort( int index, short value ) = 0;
00828 
00842         virtual ByteBuffer* slice() const = 0;
00843 
00844     public:  // Comparable
00845 
00849         virtual int compareTo( const ByteBuffer& value ) const;
00850 
00854         virtual bool equals( const ByteBuffer& value ) const;
00855 
00859         virtual bool operator==( const ByteBuffer& value ) const;
00860 
00864         virtual bool operator<( const ByteBuffer& value ) const;
00865 
00866     public:
00867 
00879         static ByteBuffer* allocate( int capacity );
00880 
00905         static ByteBuffer* wrap( unsigned char* array, int size, int offset, int length );
00906 
00922         static ByteBuffer* wrap( std::vector<unsigned char>& buffer );
00923 
00924     };
00925 
00926 }}
00927 
00928 #endif /*_DECAF_NIO_BYTEBUFFER_H_*/