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>
22 #include <decaf/lang/Comparable.h>
28 
29 namespace decaf{
30 namespace 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 
111  ByteBuffer(int capacity);
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 
189  ByteBuffer& put(ByteBuffer& src);
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 
880  static ByteBuffer* allocate(int capacity);
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_*/
A container for data of a specific primitive type.
Definition: Buffer.h:125
This class defines six categories of operations upon byte buffers:
Definition: ByteBuffer.h:97
This class defines four categories of operations upon float buffers:
Definition: FloatBuffer.h:50
This class defines four categories of operations upon short buffers:
Definition: ShortBuffer.h:50
This class defines four categories of operations upon character buffers:
Definition: CharBuffer.h:65
This class defines four categories of operations upon long long buffers:
Definition: LongBuffer.h:50
This class defines four categories of operations upon double buffers:
Definition: DoubleBuffer.h:52
#define DECAF_API
Definition: Config.h:29
bool operator==(const ArrayPointer< T > &left, const U *right)
Definition: ArrayPointer.h:379
virtual ~ByteBuffer()
Definition: ByteBuffer.h:115
This interface imposes a total ordering on the objects of each class that implements it...
Definition: Comparable.h:33
This class defines four categories of operations upon int buffers:
Definition: IntBuffer.h:50
bool operator<(const std::string &left, const String &right)