activemq-cpp-3.9.5
ByteArrayAdapter.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_INTERNAL_UTIL_BYTEARRAYADAPTER_H_
19#define _DECAF_INTERNAL_UTIL_BYTEARRAYADAPTER_H_
20
27
28namespace decaf {
29namespace internal {
30namespace util {
31
44 private:
45
46 // Used to allow this adapter to view its array as the different
47 // types it supports
48 union Array {
49 unsigned char* bytes;
50 char* chars;
51 short* shorts;
52 int* ints;
53 long long* longs;
54 float* floats;
55 double* doubles;
56 };
57
58 // Buffer to read and write to, may be shared with other instances.
59 Array array;
60
61 // Size of the Buffer
62 int size;
63
64 // Whether this object owns the buffer
65 bool own;
66
67 public:
68
80
95 ByteArrayAdapter(unsigned char* array, int size, bool own = false);
96
111 ByteArrayAdapter(char* array, int size, bool own = false);
112
127 ByteArrayAdapter(double* array, int size, bool own = false);
128
143 ByteArrayAdapter(float* array, int size, bool own = false);
144
159 ByteArrayAdapter(long long* array, int size, bool own = false);
160
175 ByteArrayAdapter(int* array, int size, bool own = false);
176
191 ByteArrayAdapter(short* array, int size, bool own = false);
192
194
199 virtual int getCapacity() const {
200 return this->size;
201 }
202
207 virtual int getCharCapacity() const {
208 return this->size;
209 }
210
215 virtual int getDoubleCapacity() const {
216 return this->size / (int) sizeof(double);
217 }
218
223 virtual int getFloatCapacity() const {
224 return this->size / (int) sizeof(float);
225 }
226
231 virtual int getLongCapacity() const {
232 return this->size / (int) sizeof(long long);
233 }
234
239 virtual int getIntCapacity() const {
240 return this->size / (int) sizeof(int);
241 }
242
247 virtual int getShortCapacity() const {
248 return this->size / (int) sizeof(short);
249 }
250
256 virtual unsigned char* getByteArray() {
257 return this->array.bytes;
258 }
259
265 virtual char* getCharArray() {
266 return this->array.chars;
267 }
268
274 virtual short* getShortArray() {
275 return this->array.shorts;
276 }
277
283 virtual int* getIntArray() {
284 return this->array.ints;
285 }
286
292 virtual long long* getLongArray() {
293 return this->array.longs;
294 }
295
301 virtual double* getDoubleArray() {
302 return this->array.doubles;
303 }
304
310 virtual float* getFloatArray() {
311 return this->array.floats;
312 }
313
333 virtual void read(unsigned char* buffer, int size, int offset, int length) const;
334
355 virtual void write(unsigned char* buffer, int size, int offset, int length);
356
372 virtual void resize(int size);
373
377 virtual void clear();
378
390 unsigned char& operator[](int index);
391 const unsigned char& operator[](int index) const;
392
404 virtual unsigned char get(int index) const;
405
417 virtual char getChar(int index) const;
418
433 virtual double getDouble(int index) const;
434
446 virtual double getDoubleAt(int index) const;
447
462 virtual float getFloat(int index) const;
463
475 virtual float getFloatAt(int index) const;
476
491 virtual long long getLong(int index) const;
492
504 virtual long long getLongAt(int index) const;
505
520 virtual int getInt(int index) const;
521
533 virtual int getIntAt(int index) const;
534
549 virtual short getShort(int index) const;
550
562 virtual short getShortAt(int index) const;
563
580 virtual ByteArrayAdapter& put(int index, unsigned char value);
581
598 virtual ByteArrayAdapter& putChar(int index, char value);
599
616 virtual ByteArrayAdapter& putDouble(int index, double value);
617
632 virtual ByteArrayAdapter& putDoubleAt(int index, double value);
633
650 virtual ByteArrayAdapter& putFloat(int index, float value);
651
666 virtual ByteArrayAdapter& putFloatAt(int index, float value);
667
684 virtual ByteArrayAdapter& putLong(int index, long long value);
685
700 virtual ByteArrayAdapter& putLongAt(int index, long long value);
701
718 virtual ByteArrayAdapter& putInt(int index, int value);
719
734 virtual ByteArrayAdapter& putIntAt(int index, int value);
735
752 virtual ByteArrayAdapter& putShort(int index, short value);
753
768 virtual ByteArrayAdapter& putShortAt(int index, short value);
769
770 private:
771
772 void initialize(unsigned char* buffer, int size, bool own);
773
774 };
775
776}}}
777
778#endif /*_DECAF_INTERNAL_UTIL_BYTEARRAYADAPTER_H_*/
ByteArrayAdapter(int size)
Creates a byte array object that is allocated internally and is then owned and deleted when this obje...
virtual void read(unsigned char *buffer, int size, int offset, int length) const
Reads from the Byte array starting at the specified offset and reading the specified length.
virtual double getDoubleAt(int index) const
Reads eight bytes at the given byte index and returns it.
virtual void write(unsigned char *buffer, int size, int offset, int length)
Writes from the Byte array given, starting at the specified offset and writing the specified amount o...
virtual int getInt(int index) const
Reads four bytes at the given index and returns it.
ByteArrayAdapter(short *array, int size, bool own=false)
Creates a byte array object that wraps the given array.
virtual ByteArrayAdapter & put(int index, unsigned char value)
Writes the given byte into this buffer at the given index.
virtual long long * getLongArray()
Gets the pointer to the array we are wrapping.
Definition ByteArrayAdapter.h:292
ByteArrayAdapter(int size)
Creates a byte array object that is allocated internally and is then owned and deleted when this obje...
virtual void clear()
Clear all data from that Array, setting the underlying bytes to zero.
virtual short * getShortArray()
Gets the pointer to the array we are wrapping.
Definition ByteArrayAdapter.h:274
virtual unsigned char get(int index) const
Absolute get method.
virtual int getIntAt(int index) const
Reads four bytes at the given byte index and returns it.
virtual char * getCharArray()
Gets the pointer to the array we are wrapping.
Definition ByteArrayAdapter.h:265
const unsigned char & operator[](int index) const
virtual long long getLongAt(int index) const
Reads eight bytes at the given byte index and returns it.
virtual ByteArrayAdapter & putLong(int index, long long value)
Writes eight bytes containing the given value, into this buffer at the given index.
virtual int * getIntArray()
Gets the pointer to the array we are wrapping.
Definition ByteArrayAdapter.h:283
virtual float getFloatAt(int index) const
Reads four bytes at the given byte index and returns it.
virtual float getFloat(int index) const
Reads four bytes at the given index and returns it.
virtual ByteArrayAdapter & putDoubleAt(int index, double value)
Writes eight bytes containing the given value, into this buffer at the given byte index.
virtual int getShortCapacity() const
Gets the size of the underlying array as if it contains shorts.
Definition ByteArrayAdapter.h:247
virtual ByteArrayAdapter & putFloat(int index, float value)
Writes four bytes containing the given value, into this buffer at the given index.
virtual unsigned char * getByteArray()
Gets the pointer to the array we are wrapping.
Definition ByteArrayAdapter.h:256
unsigned char & operator[](int index)
Allows the ByteArrayAdapter to be indexed as a standard array.
ByteArrayAdapter(int *array, int size, bool own=false)
Creates a byte array object that wraps the given array.
ByteArrayAdapter(long long *array, int size, bool own=false)
Creates a byte array object that wraps the given array.
virtual char getChar(int index) const
Reads one byte at the given index and returns it.
ByteArrayAdapter(char *array, int size, bool own=false)
Creates a byte array object that wraps the given array.
virtual int getCharCapacity() const
Gets the size of the underlying array as if it contains chars.
Definition ByteArrayAdapter.h:207
virtual void resize(int size)
Resizes the underlying array to the new given size, preserving all the Data that was previously in th...
virtual short getShort(int index) const
Reads two bytes at the given index and returns it.
virtual double * getDoubleArray()
Gets the pointer to the array we are wrapping.
Definition ByteArrayAdapter.h:301
virtual float * getFloatArray()
Gets the pointer to the array we are wrapping.
Definition ByteArrayAdapter.h:310
ByteArrayAdapter(unsigned char *array, int size, bool own=false)
Creates a byte array object that wraps the given array.
virtual ByteArrayAdapter & putShortAt(int index, short value)
Writes two bytes containing the given value, into this buffer at the given byte index.
virtual ByteArrayAdapter & putDouble(int index, double value)
Writes eight bytes containing the given value, into this buffer at the given index.
ByteArrayAdapter(float *array, int size, bool own=false)
Creates a byte array object that wraps the given array.
virtual int getLongCapacity() const
Gets the size of the underlying array as if it contains doubles.
Definition ByteArrayAdapter.h:231
virtual ByteArrayAdapter & putFloatAt(int index, float value)
Writes four bytes containing the given value, into this buffer at the given byte index.
virtual long long getLong(int index) const
Reads eight bytes at the given index and returns it.
virtual int getIntCapacity() const
Gets the size of the underlying array as if it contains ints.
Definition ByteArrayAdapter.h:239
virtual ByteArrayAdapter & putChar(int index, char value)
Writes one byte containing the given value, into this buffer at the given index.
ByteArrayAdapter(double *array, int size, bool own=false)
Creates a byte array object that wraps the given array.
virtual ByteArrayAdapter & putShort(int index, short value)
Writes two bytes containing the given value, into this buffer at the given index.
virtual ByteArrayAdapter & putIntAt(int index, int value)
Writes four bytes containing the given value, into this buffer at the given byte index.
virtual int getFloatCapacity() const
Gets the size of the underlying array as if it contains doubles.
Definition ByteArrayAdapter.h:223
virtual double getDouble(int index) const
Reads eight bytes at the given index and returns it.
virtual ByteArrayAdapter & putLongAt(int index, long long value)
Writes eight bytes containing the given value, into this buffer at the given byte index.
virtual int getCapacity() const
Gets the size of the underlying array.
Definition ByteArrayAdapter.h:199
virtual int getDoubleCapacity() const
Gets the size of the underlying array as if it contains doubles.
Definition ByteArrayAdapter.h:215
virtual ByteArrayAdapter & putInt(int index, int value)
Writes four bytes containing the given value, into this buffer at the given index.
virtual short getShortAt(int index) const
Reads two bytes at the given byte index and returns it.
#define DECAF_API
Definition Config.h:29
Definition ByteArrayAdapter.h:30
Definition AprPool.h:26
Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements.
Definition AprPool.h:25