activemq-cpp-3.9.5
ByteBuffer.h
Go to the documentation of this file.
1/*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#ifndef _DECAF_NIO_BYTEBUFFER_H_
19#define _DECAF_NIO_BYTEBUFFER_H_
20
21#include <decaf/nio/Buffer.h>
28
29namespace decaf{
30namespace nio{
31
32 class CharBuffer;
33 class DoubleBuffer;
34 class FloatBuffer;
35 class ShortBuffer;
36 class IntBuffer;
37 class LongBuffer;
38
97 class DECAF_API ByteBuffer : public Buffer,
98 public lang::Comparable<ByteBuffer> {
99 protected:
100
112
113 public:
114
115 virtual ~ByteBuffer() {}
116
120 virtual std::string toString() const;
121
136 ByteBuffer& get(std::vector<unsigned char> buffer);
137
167 ByteBuffer& get(unsigned char* buffer, int size, int offset, int length);
168
190
218 ByteBuffer& put(const unsigned char* buffer, int size, int offset, int length);
219
232 ByteBuffer& put(std::vector<unsigned char>& buffer);
233
234 public: // Abstract Methods
235
241 virtual bool isReadOnly() const = 0;
242
259 virtual unsigned char* array() = 0;
260
279 virtual int arrayOffset() const = 0;
280
290 virtual bool hasArray() const = 0;
291
305 virtual CharBuffer* asCharBuffer() const = 0;
306
321 virtual DoubleBuffer* asDoubleBuffer() const = 0;
322
337 virtual FloatBuffer* asFloatBuffer() const = 0;
338
353 virtual IntBuffer* asIntBuffer() const = 0;
354
369 virtual LongBuffer* asLongBuffer() const = 0;
370
385 virtual ShortBuffer* asShortBuffer() const = 0;
386
404 virtual ByteBuffer* asReadOnlyBuffer() const = 0;
405
424 virtual ByteBuffer& compact() = 0;
425
439 virtual ByteBuffer* duplicate() = 0;
440
450 virtual unsigned char get() const = 0;
451
463 virtual unsigned char get(int index) const = 0;
464
474 virtual char getChar() = 0;
475
487 virtual char getChar(int index) const = 0;
488
498 virtual double getDouble() = 0;
499
511 virtual double getDouble(int index) const = 0;
512
522 virtual float getFloat() = 0;
523
535 virtual float getFloat(int index) const = 0;
536
546 virtual long long getLong() = 0;
547
559 virtual long long getLong(int index) const = 0;
560
570 virtual int getInt() = 0;
571
583 virtual int getInt(int index) const = 0;
584
594 virtual short getShort() = 0;
595
607 virtual short getShort(int index) const = 0;
608
621 virtual ByteBuffer& put(unsigned char value) = 0;
622
635 virtual ByteBuffer& put(int index, unsigned char value) = 0;
636
650 virtual ByteBuffer& putChar(char value) = 0;
651
667 virtual ByteBuffer& putChar(int index, char value) = 0;
668
682 virtual ByteBuffer& putDouble(double value) = 0;
683
699 virtual ByteBuffer& putDouble(int index, double value) = 0;
700
714 virtual ByteBuffer& putFloat(float value) = 0;
715
731 virtual ByteBuffer& putFloat(int index, float value) = 0;
732
746 virtual ByteBuffer& putLong(long long value) = 0;
747
763 virtual ByteBuffer& putLong(int index, long long value) = 0;
764
778 virtual ByteBuffer& putInt(int value) = 0;
779
795 virtual ByteBuffer& putInt(int index, int value) = 0;
796
810 virtual ByteBuffer& putShort(short value) = 0;
811
827 virtual ByteBuffer& putShort(int index, short value) = 0;
828
842 virtual ByteBuffer* slice() const = 0;
843
844 public:
845 // Comparable
846
850 virtual int compareTo(const ByteBuffer& value) const;
851
855 virtual bool equals(const ByteBuffer& value) const;
856
860 virtual bool operator==(const ByteBuffer& value) const;
861
865 virtual bool operator<(const ByteBuffer& value) const;
866
867 public:
868
881
906 static ByteBuffer* wrap(unsigned char* array, int size, int offset, int length);
907
923 static ByteBuffer* wrap(std::vector<unsigned char>& buffer);
924
925 };
926
927}}
928
929#endif /*_DECAF_NIO_BYTEBUFFER_H_*/
This interface imposes a total ordering on the objects of each class that implements it.
Definition Comparable.h:33
virtual int capacity() const
Definition Buffer.h:145
Buffer(int capactiy)
virtual bool equals(const ByteBuffer &value) const
static ByteBuffer * allocate(int capacity)
Allocates a new byte buffer whose position will be zero its limit will be its capacity and its mark i...
virtual ByteBuffer & putLong(long long value)=0
Writes eight bytes containing the given value, into this buffer at the current position,...
virtual unsigned char get() const =0
Relative get method.
virtual CharBuffer * asCharBuffer() const =0
Creates a view of this byte buffer as a char buffer.
virtual ByteBuffer & putInt(int value)=0
Writes four bytes containing the given value, into this buffer at the current position,...
virtual int compareTo(const ByteBuffer &value) const
virtual double getDouble(int index) const =0
Reads eight bytes at the given index and returns it.
virtual ShortBuffer * asShortBuffer() const =0
Creates a view of this byte buffer as a short buffer.
ByteBuffer & get(unsigned char *buffer, int size, int offset, int length)
Relative bulk get method.
ByteBuffer(int capacity)
Creates a ByteBuffer object that has its backing array allocated internally and is then owned and del...
static ByteBuffer * wrap(std::vector< unsigned char > &buffer)
Wraps the passed STL Byte Vector in a ByteBuffer.
virtual ~ByteBuffer()
Definition ByteBuffer.h:115
virtual unsigned char * array()=0
Returns the byte array that backs this buffer.
virtual IntBuffer * asIntBuffer() const =0
Creates a view of this byte buffer as a int buffer.
virtual char getChar()=0
Reads the next byte at this buffer's current position, and then increments the position by one.
virtual ByteBuffer & putFloat(float value)=0
Writes four bytes containing the given value, into this buffer at the current position,...
virtual ByteBuffer & putShort(short value)=0
Writes two bytes containing the given value, into this buffer at the current position,...
ByteBuffer & get(std::vector< unsigned char > buffer)
Relative bulk get method.
virtual unsigned char get(int index) const =0
Absolute get method.
ByteBuffer & put(ByteBuffer &src)
This method transfers the bytes remaining in the given source buffer into this buffer.
virtual ByteBuffer & putShort(int index, short value)=0
Writes two bytes containing the given value, into this buffer at the given index.
virtual float getFloat()=0
Reads the next four bytes at this buffer's current position, and then increments the position by that...
virtual bool operator==(const ByteBuffer &value) const
virtual int getInt()=0
Reads the next four bytes at this buffer's current position, and then increments the position by that...
virtual bool isReadOnly() const =0
Tells whether or not this buffer is read-only.
virtual ByteBuffer & putDouble(int index, double value)=0
Writes eight bytes containing the given value, into this buffer at the given index.
virtual ByteBuffer & compact()=0
Compacts this buffer.
virtual ByteBuffer & putChar(int index, char value)=0
Writes one byte containing the given value, into this buffer at the given index.
virtual ByteBuffer & putFloat(int index, float value)=0
Writes four bytes containing the given value, into this buffer at the given index.
virtual long long getLong(int index) const =0
Reads eight bytes at the given index and returns it.
virtual bool hasArray() const =0
Tells whether or not this buffer is backed by an accessible byte array.
virtual int getInt(int index) const =0
Reads four bytes at the given index and returns it.
virtual ByteBuffer & putInt(int index, int value)=0
Writes four bytes containing the given value, into this buffer at the given index.
ByteBuffer & put(std::vector< unsigned char > &buffer)
This method transfers the entire content of the given source byte array into this buffer.
virtual ByteBuffer * asReadOnlyBuffer() const =0
Creates a new, read-only byte buffer that shares this buffer's content.
ByteBuffer & put(const unsigned char *buffer, int size, int offset, int length)
This method transfers bytes into this buffer from the given source array.
virtual int arrayOffset() const =0
Returns the offset within this buffer's backing array of the first element of the buffer.
virtual FloatBuffer * asFloatBuffer() const =0
Creates a view of this byte buffer as a float buffer.
virtual float getFloat(int index) const =0
Reads four bytes at the given index and returns it.
virtual long long getLong()=0
Reads the next eight bytes at this buffer's current position, and then increments the position by tha...
static ByteBuffer * wrap(unsigned char *array, int size, int offset, int length)
Wraps the passed buffer with a new ByteBuffer.
virtual char getChar(int index) const =0
Reads one byte at the given index and returns it.
virtual ByteBuffer & putLong(int index, long long value)=0
Writes eight bytes containing the given value, into this buffer at the given index.
virtual std::string toString() const
virtual ByteBuffer & putDouble(double value)=0
Writes eight bytes containing the given value, into this buffer at the current position,...
virtual short getShort()=0
Reads the next two bytes at this buffer's current position, and then increments the position by that ...
virtual ByteBuffer * duplicate()=0
Creates a new byte buffer that shares this buffer's content.
virtual ByteBuffer & put(unsigned char value)=0
Writes the given byte into this buffer at the current position, and then increments the position.
virtual ByteBuffer & putChar(char value)=0
Writes one byte containing the given value, into this buffer at the current position,...
virtual DoubleBuffer * asDoubleBuffer() const =0
Creates a view of this byte buffer as a double buffer.
virtual ByteBuffer & put(int index, unsigned char value)=0
Writes the given byte into this buffer at the given index.
virtual short getShort(int index) const =0
Reads two bytes at the given index and returns it.
virtual LongBuffer * asLongBuffer() const =0
Creates a view of this byte buffer as a long buffer.
virtual double getDouble()=0
Reads the next eight bytes at this buffer's current position, and then increments the position by tha...
virtual bool operator<(const ByteBuffer &value) const
virtual ByteBuffer * slice() const =0
Creates a new byte buffer whose content is a shared subsequence of this buffer's content.
This class defines four categories of operations upon character buffers:
Definition CharBuffer.h:68
This class defines four categories of operations upon double buffers:
Definition DoubleBuffer.h:53
This class defines four categories of operations upon float buffers:
Definition FloatBuffer.h:51
This class defines four categories of operations upon int buffers:
Definition IntBuffer.h:51
This class defines four categories of operations upon long long buffers:
Definition LongBuffer.h:51
This class defines four categories of operations upon short buffers:
Definition ShortBuffer.h:51
#define DECAF_API
Definition Config.h:29
Definition Readable.h:28
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition AprPool.h:25