2 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 // Licensed under the Apache License, Version 2.0 (the License);
5 // you may not use this file except in compliance with the License.
6 // You may obtain a copy of the License at
8 // http://www.apache.org/licenses/LICENSE-2.0
10 // Unless required by applicable law or agreed to in writing, software
11 // distributed under the License is distributed on an "AS IS" BASIS,
12 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 // See the License for the specific language governing permissions and
14 // limitations under the License.
18 * @file FBaseByteBuffer.h
19 * @brief This is the header file for the %ByteBuffer class.
21 * This header file contains the declarations of the %ByteBuffer class.
23 #ifndef _FBASE_BYTE_BUFFER_H_
24 #define _FBASE_BYTE_BUFFER_H_
26 #include <FBaseBufferBase.h>
27 #include <FBaseBuffer.h>
30 namespace Tizen { namespace Base
35 * @brief This class provides a contiguous sequence of the @c byte (@c unsigned @c char) built-in type.
39 * The %ByteBuffer class provides a means of encapsulating a sequence of bytes in memory. It defines
40 * methods to read and write all primitive built-in types (except @c bool), to and from a sequence of
41 * bytes. These methods read the size of primitive type bytes from a @c byte sequence and
42 * convert it to the actual primitive type.
44 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/buffer.htm">Buffer</a>.
46 * @see Tizen::Base::BufferBase
48 * The following example demonstrates how to use the %ByteBuffer class.
53 * using namespace Tizen::Base;
56 * MyClass::ByteBufferSample(void)
58 * // Defines the maximum buffer size : capacity
59 * const int BUFFER_SIZE_MAX = 1024;
61 * // Initializes a buf using the Construct method to the capacity
63 * buf.Construct(BUFFER_SIZE_MAX);
65 * // Copies five values into the buf
66 * for (int i = 0; i < 5; i++)
70 * // Writes byte b to the current position of the buf
71 * buf.SetByte(b); // The position is incremented by one
73 * // The position is moved to 5
77 * // Now, position = 0 and limit = 5
79 * // Reads bytes from the buf using "relative access method"
80 * while (buf.HasRemaining())
84 * // Reads byte b from the current position of the buf
85 * buf.GetByte(b); // The position is incremented by one
91 * // The buf's position = 0 and limit = capacity
93 * // Writes int values to the buf
94 * for (int i = 0; i < 5; i++)
96 * // Writes int value at the current position
97 * buf.SetInt(i); // The position is incremented by sizeof(int)
102 * // Now, position = 0 and limit = sizeof(int) * 5
104 * // Creates a new view, IntBuffer.
105 * // Capacity of intBuf = 5
106 * // The content of intBuf is from the buf's position to the buf's limit
107 * IntBuffer* pIntBuf = buf.AsIntBufferN();
109 * // Tests whether the change in view buffer(IntBuffer) is visible in original buffer(ByteBuffer)
110 * pIntBuf->Set(4, 9);
112 * // Reads int values from the buf using "absolute access method"
113 * for (int i = 0; i < 5; i++)
117 * // Reads int value from the buf with the specified index.
118 * buf.GetInt((i * sizeof(int)), out); // 0, 1, 2, 3, 9
119 * // The position is not changed
128 class _OSP_EXPORT_ ByteBuffer
134 * The object is not fully constructed after this constructor is called.
135 * For full construction, the Construct() method must be called right after calling this constructor.
139 * @remarks After creating an instance of the %ByteBuffer class, one of the Construct() methods must be called explicitly to initialize this instance.
145 * This destructor overrides Tizen::Base::Object::~Object().
149 virtual ~ByteBuffer(void);
152 * Initializes this instance of %ByteBuffer which is a view of the specified buffer. @n
153 * This is the copy constructor for the %ByteBuffer class.
157 * @param[in] buffer The %ByteBuffer instance used to initialize new object
158 * @exception E_SUCCESS The method is successful.
159 * @exception E_INVALID_ARG A specified input parameter is invalid, or
160 * the source buffer is not constructed.
163 result Construct(const ByteBuffer& buffer);
166 * Initializes this instance of %ByteBuffer with the specified @c capacity.
170 * @return An error code
171 * @param[in] capacity The number of elements
172 * @exception E_SUCCESS The method is successful.
173 * @exception E_INVALID_ARG A specified input parameter is invalid, or
174 * the specified @c capacity is negative.
177 result Construct(int capacity);
180 * Initializes this instance of %ByteBuffer with the specified @c buffer which is shared with this instance.
184 * @return An error code
185 * @param[in] pBuffer The buffer which is shared
186 * @param[in] index The starting index of the buffer from where the first @c byte value is read
187 * @param[in] length The number of bytes to read from the given buffer @n This is a limit of this instance.
188 * @param[in] capacity The capacity of this instance
189 * @exception E_SUCCESS The method is successful.
190 * @exception E_INVALID_ARG A specified input parameter is invalid, or
191 * the @c pBuffer is @c null.
192 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
193 * the @c index is larger than the @c length.
195 result Construct(const byte* pBuffer, int index, int length, int capacity);
198 * Gets the reference to the byte value at the specified index.
202 * @return A reference to the @c byte value
203 * @param[in] index The index of the @c byte value in the calling %ByteBuffer instance @n
204 * It must be less than the limit.
206 byte& operator [](int index);
209 * Gets the byte value at the specified index of const object.
213 * @return A value to the @c byte value
214 * @param[in] index The index of the @c byte value in the calling %ByteBuffer instance @n
215 * It must be less than the limit.
217 byte operator [](int index) const;
220 * Compares the two %ByteBuffer instances.
224 * @return @c true if the input buffer is equal to the calling %ByteBuffer instance, @n
226 * @param[in] buffer The %ByteBuffer instance to compare with the current instance
227 * @remarks This method returns @c true only if the two buffers have the same number of
228 * remaining elements, and the two sequences of remaining elements are equal
229 * (considered independently, irrespective of their starting positions).
232 bool operator ==(const ByteBuffer& buffer) const;
235 * Checks whether the current instance and the specified instance of %ByteBuffer are not equal.
239 * @return @c true if the two objects are not the same, @n
241 * @param[in] buffer The buffer to compare with the current instance
242 * @remarks This method returns @c false only if the two buffers being compared have the same
243 * number of remaining elements, and the two sequences of remaining elements are equal
244 * (considered independently, irrespective of their starting positions).
247 bool operator !=(const ByteBuffer& buffer) const;
250 * Creates a new @c double buffer view for the content of the byte buffer.
254 * @return DoubleBuffer A pointer to the current position of the calling object
255 * @remarks The content of the view buffer starts at the current position of the calling buffer.
256 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
257 * are equal to the remaining part of this buffer divided by the size of @c double.
258 * Any change to the byte buffer content is visible in the @c double buffer view, and vice versa.
260 DoubleBuffer* AsDoubleBufferN(void) const;
263 * Creates a new @c float buffer view for the content of the byte buffer.
267 * @return FloatBuffer A pointer to the current position of the calling buffer
268 * @remarks The content of the view buffer starts at the current position of the calling buffer.
269 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
270 * are equal to the remaining part of the calling buffer divided by the size of @c float.
271 * Any change to the byte buffer content is visible in the @c float buffer view, and vice versa.
273 FloatBuffer* AsFloatBufferN(void) const;
276 * Creates a new @c int buffer view for the content of the byte buffer.
280 * @return IntBuffer A pointer to the current position of the calling buffer
281 * @remarks The content of the view buffer starts at the current position of the calling buffer.
282 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
283 * are equal to the remaining part of calling buffer divided by the size of @c int.
284 * Any change to the byte buffer content is visible in the Int buffer view, and vice versa.
286 IntBuffer* AsIntBufferN(void) const;
289 * Creates a new @c long buffer view for the content of the byte buffer.
293 * @return LongBuffer A pointer to the current position of the calling buffer
294 * @remarks The content of the view buffer starts at the current position of this buffer.
295 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
296 * are equal to the remaining part of calling buffer divided by the size of @c long.
297 * Any change to the byte buffer content is visible in the @c long buffer view, and vice versa.
299 LongBuffer* AsLongBufferN(void) const;
302 * Creates a new @c long @c long buffer view for the content of the byte buffer.
306 * @return LongLongBuffer A pointer to the current position of the calling buffer
307 * @remarks The content of the view buffer starts at the current position of this buffer.
308 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
309 * are equal to the remaining part of calling buffer divided by the size of @c long.
310 * Any change to the byte buffer content is visible in the @c long @c long buffer view, and vice versa.
312 LongLongBuffer* AsLongLongBufferN(void) const;
316 * Creates a new @c mchar buffer view of the underlying content of the byte buffer.
318 * @brief <i> [Deprecated] </i>
319 * @deprecated This method is deprecated as @c mchar type is changed to @c wchar_t type.
320 * Instead of using this method, use the AsWcharBufferN() method.
323 * @return McharBuffer A pointer to the current position of the calling buffer
324 * @remarks The content of the view buffer starts at the current position of this buffer.
325 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
326 * are equal to the remaining part of the calling buffer divided by the size of @c long.
327 * Any change to the byte buffer content is visible in the @c mchar buffer view, and vice versa.
330 McharBuffer* AsMcharBufferN(void) const;
333 * Creates a new wchar Buffer view of the underlying content of the byte buffer.
337 * @return WcharBuffer pointer to the current position of the calling buffer
338 * @remarks The content of the view buffer start at the current position of this buffer. @n
339 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
340 * are equal to the remaining part of the calling buffer divided by the size of @c long. @n
341 * Any changes to the calling buffer's content (that is, the content of %ByteBuffer instance) @n
342 * are visible in the WcharBuffer view, and vice versa.
344 WcharBuffer* AsWcharBufferN(void) const;
347 * Creates a new @c short buffer view for the content of the byte buffer.
351 * @return ShortBuffer pointer to the current position of the calling buffer
352 * @remarks The content of the view buffer starts at the current position of this buffer.
353 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
354 * are equal to the remaining part of calling buffer divided by the size of @c long.
355 * Any change to the byte buffer content is visible in the @c short buffer view, and vice versa.
357 ShortBuffer* AsShortBufferN(void) const;
360 * Copies the remaining bytes of the input %ByteBuffer instance into the calling %ByteBuffer object. @n
361 * It returns E_OVERFLOW if the remaining bytes in the current instance are less
362 * than the remaining bytes in the input instance.
366 * @return An error code
367 * @param[in] buffer The source buffer from which bytes are read @n
368 * It must not be the calling object.
369 * @exception E_SUCCESS The method is successful.
370 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
371 * The source buffer is same as destination buffer,
372 * that is, the current instance of the buffer.
373 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow. @n
374 * The number of remaining bytes of the current buffer is smaller than
375 * the number of remaining bytes of the input buffer.
376 * @remarks After the copy operation, the current (destination) buffer's position and the given
377 * (source) buffer's positions are incremented by the number of bytes copied (the number of
378 * remaining bytes of the given buffer). @n
379 * If the remaining part of the current instance is greater than or equal to the remaining part of the input instance,
380 * the effect of this method and the ReadFrom(%ByteBuffer) method is the same. But when the remaining part of the
381 * current instance is less, the ReadFrom() method copies the number of remaining elements of the current
382 * instance while this method returns E_OVERFLOW and does not copy.
385 * The following example demonstrates how to use the %CopyFrom() method.
389 * // Creates instances of ByteBuffer to act as source and destination buffers
391 * ByteBuffer destBuf;
393 * // Declares an array of byte values
394 * byte pArray[] = {'A','B','C','D','E','F','G','H','I','J'};
396 * // Initializes the source array with a capacity of ten elements.
397 * srcBuf.Construct(10);
399 * // Copies the ten values from pArray starting at position 0 to the srcBuf
400 * // Now, srcBuf's position = 10
401 * srcBuf.SetArray(pArray, 0, 10);
403 * // Flips the buffer: The limit is set to the current position and
404 * // then the position is set to zero
405 * srcBuf.Flip(); // srcBuf's position = 0 and limit = 10
408 * destBuf.Construct(20);
410 * // Copies from the srcBuf to the destBuf
411 * // Now, srcBuf's position = 10, the destBuf's position = 10
412 * destBuf.CopyFrom(srcBuf);
416 * The following example has exactly the same effect as the above %CopyFrom() method.
420 * int copyNum = srcBuf.GetRemaining();
421 * for (int i = 0; i < copyNum; i++)
425 * // Reads from source buffer
426 * srcBuf.GetByte(b); // The srcBuf position is incremented by 1
428 * // Writes to destination buffer
429 * destBuf.SetByte(b); // The destBuf position is incremented by 1
434 result CopyFrom(ByteBuffer& buffer);
437 * Gets the specified number of bytes from the current instance of %ByteBuffer.
441 * @return An error code
442 * @param[out] pArray A pointer to the destination array into which the bytes are written
443 * @param[in] index The starting index in the array of the first byte to write
444 * @param[in] length The number of bytes to write to the given array
445 * @exception E_SUCCESS The method is successful.
446 * @exception E_INVALID_ARG A specified input parameter is invalid, or
447 * the @c pArray is @c null.
448 * @exception E_OUT_OF_RANGE A specified input parameter is invalid. @n
449 * The @c index or @c length is less than @c 0.
450 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
451 * the remaining bytes of this buffer are smaller than @c length.
452 * @remarks This method copies @c length bytes from the current instance of %ByteBuffer to the given array,
453 * starting at the current position and at the given index in the array.
454 * After the copy operation, the position is incremented by @c length bytes.
457 result GetArray(byte* pArray, int index, int length);
460 * Gets the @c byte value from the buffer at the current position, and then increments the position. @n
461 * Provides a way for relative indexing and reading.
465 * @return An error code
466 * @param[out] value The @c byte value at the current position in the %ByteBuffer instance
467 * @exception E_SUCCESS The method is successful.
468 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
469 * the current position is not smaller than the limit.
472 result GetByte(byte& value);
475 * Gets the @c byte value at the given index. @n
476 * Provides a way for absolute indexing and reading.
480 * @return An error code
481 * @param[in] index The index of the current %ByteBuffer instance, from which the byte is read
482 * @param[out] value The @c byte value at the given @c index
483 * @exception E_SUCCESS The method is successful.
484 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
485 * the @c index is not smaller than the limit or less than @c 0.
488 result GetByte(int index, byte& value) const;
491 * Gets the size of @c double number of bytes from the buffer at the current position, converts
492 * it to the corresponding @c double equivalent, and then increments the position. @n
493 * Provides a way for relative indexing and reading.
497 * @return An error code
498 * @param[out] value The @c double value at the current position in the %ByteBuffer instance
499 * @exception E_SUCCESS The method is successful.
500 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
501 * the remaining bytes of this buffer are smaller than the size of @c double.
502 * @remarks This method reads the next size of @c double number of bytes at the current position,
503 * composing it into a @c double value, and then increments the position by the size of @c double.
506 result GetDouble(double& value);
509 * Gets the size of @c double number of bytes at the given index and converts it to the equivalent @c double value. @n
510 * Provides a way for absolute indexing and reading.
514 * @return An error code
515 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
516 * @param[out] value The @c double value at the given index
517 * @exception E_SUCCESS The method is successful.
518 * @exception E_OUT_OF_RANGE The specified @c index is outside the bounds of the data structure, or
519 * the @c index is larger than the limit minus size of @c double or less than @c 0.
520 * @remarks This method reads size of @c double number of bytes at the given index,
521 * composing them into a @c double value.
524 result GetDouble(int index, double& value) const;
527 * Gets the size of @c float number of bytes from the buffer at the current position, converts
528 * it to the corresponding @c float equivalent, and then increments the position. @n
529 * Provides a way for relative indexing and reading.
533 * @return An error code
534 * @param[out] value The @c float value at the current position in the %ByteBuffer instance
535 * @exception E_SUCCESS The method is successful.
536 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
537 * the remaining bytes of this buffer are smaller than the size of @c float.
538 * @remarks This method reads the next size of @c float number of bytes at the current position,
539 * composing it into a @c float value, and then increments the position by the size of @c float.
542 result GetFloat(float& value);
545 * Gets the size of @c float number of bytes at the given index and converts it to equivalent @c float value. @n
546 * Provides a way for absolute indexing and reading.
550 * @return An error code
551 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
552 * @param[out] value The @c float value at the given index
553 * @exception E_SUCCESS The method is successful.
554 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
555 * the @c index is larger than the limit minus size of @c float or less than @c 0.
556 * @remarks This method reads the size of @c float number of bytes at the given index,
557 * composing it into a @c float value.
560 result GetFloat(int index, float& value) const;
563 * Gets the size of @c int number of bytes from the buffer at the current position, converts
564 * it to the corresponding @c int equivalent, and then increments the position. @n
565 * Provides a way for relative indexing and reading.
569 * @return An error code
570 * @param[out] value The @c int value at the current position in the %ByteBuffer instance
571 * @exception E_SUCCESS The method is successful.
572 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
573 * the remaining bytes of this buffer are smaller than the size of @c int.
574 * @remarks This method reads the next size of @c int number of bytes at the current position,
575 * composing them into an @c int value, and then increments the position by the size of @c int.
578 result GetInt(int& value);
581 * Gets the size of @c int number of bytes at the given index and converts it to the equivalent @c int value. @n
582 * Provides a way for absolute indexing and reading.
586 * @return An error code
587 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
588 * @param[out] value The @c int value at the given index
589 * @exception E_SUCCESS The method is successful.
590 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
591 * the @c index is larger than the limit minus size of @c int or negative.
592 * @remarks This method reads the size of @c int number of bytes at the given index,
593 * composing it into an @c int value.
596 result GetInt(int index, int& value) const;
599 * Gets the size of @c long number of bytes from the buffer at the current position, converts
600 * it to the corresponding @c long equivalent, and then increments the position. @n
601 * Provides a way for relative indexing and reading.
605 * @return An error code
606 * @param[out] value The @c long value at the current position in the %ByteBuffer instance
607 * @exception E_SUCCESS The method is successful.
608 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
609 * the remaining bytes of this buffer are smaller than the size of @c long.
610 * @remarks This method reads the next size of @c long number of bytes at the current position,
611 * composing it into a @c long value, and then increments the position by the size of @c long.
614 result GetLong(long& value);
617 * Gets the size of @c long number of bytes at the given index and converts it to equivalent @c long value. @n
618 * Provides a way for absolute indexing and reading.
622 * @return An error code
623 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
624 * @param[out] value The @c long value at the given index
625 * @exception E_SUCCESS The method is successful.
626 * @exception E_OUT_OF_RANGE The specified @c index is outside the bounds of the data structure, or
627 * the @c index is larger than the limit minus size of @c long or less than @c 0.
628 * @remarks This method reads the size of @c long number of bytes at the given index,
629 * composing it into a @c long value.
632 result GetLong(int index, long& value) const;
635 * Gets the size of @c long @c long number of bytes from the buffer at the current position, converts
636 * it to the corresponding @c long @c long equivalent, and then increments the position. @n
637 * Provides a way for relative indexing and reading.
641 * @return An error code
642 * @param[out] value The @c long @c long value at the current position in the %ByteBuffer instance
643 * @exception E_SUCCESS The method is successful.
644 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
645 * the remaining bytes of this buffer are smaller than the size of @c long @c long.
646 * @remarks This method reads the next size of @c long @c long number of bytes at the current position,
647 * composing it into a @c long @c long value, and then increments the position by the size of @c long @c long.
650 result GetLongLong(long long& value);
653 * Gets the size of @c long @c long number of bytes at the given index and converts it to the equivalent @c long @c long value. @n
654 * Provides a way for absolute indexing and reading.
658 * @return An error code
659 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
660 * @param[out] value The @c long @c long value at the given index
661 * @exception E_SUCCESS The method is successful.
662 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
663 * the @c index is larger than the limit minus size of @c long @c long or less than @c 0.
664 * @remarks This method reads the size of @c long @c long number of bytes at the given index,
665 * composing it into a @c long @c long value.
668 result GetLongLong(int index, long long& value) const;
672 * Gets the size of @c wchar_t number of bytes from the buffer at the current position, converts
673 * it to the corresponding @c wchar_t equivalent, and then increments the position. @n
674 * Provides a way for relative indexing and reading.
676 * @brief <i> [Deprecated] </i>
677 * @deprecated This method is deprecated as @c mchar type is changed to @c wchar_t type.
678 * Instead of using this method, use the GetWchar(wchar_t& value) method.
681 * @return An error code
682 * @param[out] value The @c wchar_t value at the current position in the %ByteBuffer instance
683 * @exception E_SUCCESS The method is successful.
684 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
685 * the remaining bytes of this buffer are smaller than the size of @c wchar_t.
686 * @remarks This method reads the next size of @c wchar_t number of bytes at the current position,
687 * composing it into a @c wchar_t value, and then increments the position by the size of @c wchar_t.
691 result GetMchar(wchar_t& value);
694 * Gets the size of @c wchar_t number of bytes from the buffer at the current position, converts
695 * it to the corresponding @c wchar_t equivalent, and then increments the position. @n
696 * Provides a way for relative indexing and reading.
700 * @return An error code
701 * @param[out] value The @c wchar_t value at the current position in the %ByteBuffer instance
702 * @exception E_SUCCESS The method is successful.
703 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
704 * the remaining bytes of this buffer are smaller than the size of @c wchar_t.
705 * @remarks This method reads the next size of @c wchar_t number of bytes at the current position,
706 * composing it into a @c wchar_t value, and then increments the position by the size of @c wchar_t.
709 result GetWchar(wchar_t& value);
713 * Provides a way for absolute indexing and reading. @n
714 * It reads the size of @c wchar_t number of bytes at the given index and converts it to equivalent @c wchar_t value.
716 * @brief <i> [Deprecated] </i>
717 * @deprecated This method is deprecated as @c mchar type is changed to @c wchar_t type.
718 * Instead of using this method, use the GetWchar(int index, wchar_t& value) method.
721 * @return An error code
722 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
723 * @param[out] value The @c wchar_t value at the given index
724 * @exception E_SUCCESS The method is successful.
725 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
726 * the @c index is larger than the limit minus size of @c wchar_t or less than @c 0.
727 * @remarks This method reads the size of @c wchar_t number of bytes at the given index,
728 * composing it into a @c wchar_t value.
732 result GetMchar(int index, wchar_t& value) const;
735 * Provides a way for absolute indexing and reading. @n
736 * It reads the size of @c wchar_t number of bytes at the given index and converts it to equivalent @c wchar_t value.
740 * @return An error code
741 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
742 * @param[out] value The @c wchar_t value at the given index
743 * @exception E_SUCCESS The method is successful.
744 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
745 * the @c index is larger than the limit minus size of @c wchar_t or less than @c 0.
746 * @remarks This method reads the size of @c wchar_t number of bytes at the given index,
747 * composing it into a @c wchar_t value.
750 result GetWchar(int index, wchar_t& value) const;
753 * Gets the size of @c short number of bytes from the buffer at the current position, converts
754 * it to the corresponding @c short equivalent, and then increments the position. @n
755 * Provides a way for relative indexing and reading.
759 * @return An error code
760 * @param[out] value The @c short value at the current position in the %ByteBuffer instance
761 * @exception E_SUCCESS The method is successful.
762 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
763 * the remaining bytes of this buffer are smaller than the size of @c short.
764 * @remarks This method reads the next size of @c short number of bytes at the current position,
765 * composing it into a @c short value, and then increments the position by the size of @c short.
768 result GetShort(short& value);
771 * Gets the size of @c short number of bytes at the given index and converts it to the equivalent @c short value. @n
772 * Provides a way for absolute indexing and reading.
776 * @return An error code
777 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
778 * @param[out] value The @c short value at the given index
779 * @exception E_SUCCESS The method is successful.
780 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
781 * the @c index is larger than the limit minus size of @c short or less than @c 0.
782 * @remarks This method reads the size of @c short number of bytes at the given index,
783 * composing it into a @c short value.
786 result GetShort(int index, short& value) const;
789 * Copies the remaining bytes of the input %ByteBuffer instance into the calling %ByteBuffer instance
790 * if the remaining part of the current instance is greater than or equal to the remaining part of the input instance. @n
791 * Otherwise, the number of bytes copied is equal to the number of remaining elements of the current instance.
795 * @return An error code
796 * @param[in] buffer The source buffer from which bytes are read @n
797 * It must not be the calling %ByteBuffer instance.
798 * @exception E_SUCCESS The method is successful.
799 * @exception E_INVALID_ARG The specified input parameter is invalid.
801 * @remarks After the copy operation, the current (destination) buffer's position and the given
802 * (source) buffer's position are incremented by the number of elements copied (the lesser of
803 * the number of elements remaining in the current buffer and the given buffer). @n
804 * If the remaining part of the current instance is greater than or equal to the remaining part of the input instance,
805 * the effect of this method is the same as the CopyFrom() method. But when the remaining part of the
806 * current instance is less, the CopyFrom() method returns E_OVERFLOW and does not transfer;
807 * whereas this method copies the number of remaining elements of the current instance.
810 * The following example demonstrates how to use the %ReadFrom() method.
814 * // Creates instances of %ByteBuffer to act as source and destination buffers
816 * ByteBuffer destBuf;
818 * // Declares an array of byte values
819 * byte pArray[] = {'A','B','C','D','E','F','G','H','I','J'};
821 * // Initializes the source array with capacity of ten elements.
822 * srcBuf.Construct(10);
824 * // Copies the 10 values from pArray starting at position 0 to srcBuf
825 * // Now, srcBuf's position = 10
826 * srcBuf.SetArray(pArray, 0, 10);
828 * // Flips the buffer: The limit is set to the current position and
829 * // then the position is set to zero
830 * srcBuf.Flip(); // srcBuf's position = 0 and limit = 10
832 * // Initializes the destination buffer with capacity of ten elements
833 * destBuf.Construct(10);
835 * // Sets the limit of destBuf to 5
836 * destBuf.SetLimit(5);
838 * // Reads from the srcBuf to the destBuf
839 * // The destBuf's remaining is 5, smaller than the srcBuf's (10)
840 * // Therefore, five elements are transferred
841 * // srcBuf's position = 5, destBuf's position = 5
842 * destBuf.ReadFrom(srcBuf);
847 * The following example has exactly the same effect as the above %ReadFrom() method.
851 * int copyNum = (destBuf.GetRemaining() < srcBuf.GetRemaing())? destBuf.GetRemaining() : srcBuf.GetRemaining();
852 * for (int i = 0; i < copyNum; i++)
856 * // Reads from the source buffer
857 * srcBuf.GetByte(b); // The srcBuf position is incremented by 1
859 * // Writes to the destination buffer
860 * destBuf.SetByte(b); // The destBuf position is incremented by 1
866 result ReadFrom(ByteBuffer& buffer);
869 * Sets the @c byte values on the specified array to the current instance of %ByteBuffer.
873 * @return An error code
874 * @param[in] pArray The array from which bytes are read
875 * @param[in] index The starting index of the array from where the first @c byte value is read
876 * @param[in] length The number of bytes to read from the given array
877 * @exception E_SUCCESS The method is successful.
878 * @exception E_INVALID_ARG A specified input parameter is invalid, or
879 * the @c pArray is @c null.
880 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
881 * the @c index or length is less than @c 0.
882 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
883 * the remaining bytes are smaller than @c length.
884 * @remarks This method copies the specified number (@c length) of @c byte values into
885 * the calling object of buffer from the source array,
886 * starting from the current position, and at the given index in the array.
887 * After the copy operation, the position is incremented by @c length.
890 result SetArray(const byte* pArray, int index, int length);
893 * Sets the given @c byte value into the calling %ByteBuffer object
894 * at the current position, and then increments the position. @n
895 * Provides a way for relative indexing and writing.
899 * @return An error code
900 * @param[in] value The @c byte value to write to the current instance of %ByteBuffer
901 * @exception E_SUCCESS The method is successful.
902 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
903 * the current position is not smaller than the limit.
906 result SetByte(byte value);
909 * Sets the given @c byte value into the calling %ByteBuffer object at the specified index. @n
910 * Provides a way for absolute indexing and writing.
914 * @return An error code
915 * @param[in] index The index of the current instance of %ByteBuffer at which the byte is written
916 * @param[in] value The @c byte value to write
917 * @exception E_SUCCESS The method is successful.
918 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
919 * the @c index is not smaller than the limit or less than @c 0.
922 result SetByte(int index, byte value);
925 * Sets the given @c double value into the calling %ByteBuffer object
926 * at the current position, and then increments the position. @n
927 * Provides a way for relative indexing and writing.
931 * @return An error code
932 * @param[in] value The @c double value to write
933 * @exception E_SUCCESS The method is successful.
934 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
935 * the remaining bytes of this buffer are smaller than the size of @c double.
936 * @remarks This method writes the size of @c double number of bytes containing the given @c double value
937 * into the calling buffer, at the current position, and then increments the position by the size of @c double.
940 result SetDouble(double value);
943 * Sets the given @c float value into the calling %ByteBuffer object
944 * at the current position, and then increments the position. @n
945 * Provides a way for relative indexing and writing.
949 * @return An error code
950 * @param[in] value The @c float value to write
951 * @exception E_SUCCESS The method is successful.
952 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
953 * the remaining bytes of this buffer are smaller than the size of @c float.
954 * @remarks This method writes the size of @c float number of bytes containing the given @c float value
955 * into this buffer at the current position, and then increments the position by the size of @c float.
958 result SetFloat(float value);
961 * Sets the given @c int value into the calling %ByteBuffer instance at the current
962 * position, and then increments the position. @n
963 * Provides a way for relative indexing and writing.
967 * @return An error code
968 * @param[in] value The @c int value to write
969 * @exception E_SUCCESS The method is successful.
970 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
971 * the remaining bytes of this buffer are smaller than the size of @c int.
972 * @remarks This method writes the size of @c int number of bytes containing the given @c int value
973 * into this buffer at the current position, and then increments the position by the size of @c int.
976 result SetInt(int value);
979 * Sets the given @c long value into the calling %ByteBuffer instance at the current
980 * position, and then increments the position. @n
981 * Provides a way for relative indexing and writing.
985 * @return An error code
986 * @param[in] value The @c long value to write
987 * @exception E_SUCCESS The method is successful.
988 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
989 * the remaining bytes of this buffer are smaller than size of @c long.
990 * @remarks This method writes the size of @c long number of bytes containing the given @c long value
991 * into this buffer at the current position, and then increments the position by the size of @c long.
994 result SetLong(long value);
997 * Sets the given @c long @c long value into the calling %ByteBuffer object at the current
998 * position, and then increments the position. @n
999 * Provides a way for relative indexing and writing.
1003 * @return An error code
1004 * @param[in] value The @c long @c long value to write
1005 * @exception E_SUCCESS The method is successful.
1006 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
1007 * the remaining bytes of this buffer are smaller than the size of @c long @c long.
1008 * @remarks This method writes the size of @c long @c long number of bytes containing the given @c long @c long value
1009 * into this buffer at the current position, and then increments the position by the size of @c long @c long.
1010 * @see GetLongLong()
1012 result SetLongLong(long long value);
1016 * Sets the given @c wchar_t value into the calling %ByteBuffer object at the current
1017 * position, and then increments the position. @n
1018 * Provides a way for relative indexing and writing.
1020 * @brief <i> [Deprecated] </i>
1021 * @deprecated This method is deprecated as @c mchar type is changed to @c wchar_t type.
1022 * Instead of using this method, use the SetWchar(wchar_t value) method.
1025 * @return An error code
1026 * @param[in] value The @c wchar_t value to write
1027 * @exception E_SUCCESS The method is successful.
1028 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
1029 * the remaining bytes of this buffer are smaller than size of @c wchar_t.
1030 * @remarks This method writes the size of @c wchar_t number of bytes containing the given @c wchar_t value
1031 * into this buffer at the current position, and then increments the position by the size of @c wchar_t.
1035 result SetMchar(wchar_t value);
1038 * Sets the given @c wchar_t value into the calling %ByteBuffer object at the current
1039 * position, and then increments the position. @n
1040 * Provides a way for relative indexing and writing.
1044 * @return An error code
1045 * @param[in] value The @c wchar_t value to write
1046 * @exception E_SUCCESS The method is successful.
1047 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
1048 * the remaining bytes of this buffer are smaller than size of @c wchar_t.
1049 * @remarks This method writes the size of @c wchar_t number of bytes containing the given @c wchar_t value
1050 * into this buffer at the current position, and then increments the position by the size of @c wchar_t.
1053 result SetWchar(wchar_t value);
1056 * Sets the given @c short value into the current instance of %ByteBuffer at the current
1057 * position, and then increments the position. @n
1058 * Provides a way for relative indexing and writing.
1062 * @return An error code
1063 * @param[in] value The @c short value to write
1064 * @exception E_SUCCESS The method is successful.
1065 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
1066 * the remaining bytes of this buffer are smaller than the size of @c short.
1067 * @remarks This method writes the size of @c short number of bytes containing the given @c short value
1068 * into this buffer at the current position, and then increments the position by the size of @c short.
1071 result SetShort(short value);
1074 * Sets a @c double value at the specified index of the current instance of %ByteBuffer. @n
1075 * Provides a way for absolute indexing and writing.
1079 * @return An error code
1080 * @param[in] index The index of current instance of %ByteBuffer at which the bytes are written
1081 * @param[in] value The @c double value to write
1082 * @exception E_SUCCESS The method is successful.
1083 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1084 * the @c index is larger than the limit minus the size of @c double or less than @c 0.
1085 * @remarks This method writes the size of @c double number of bytes containing the given @c double value
1086 * into this buffer at the given index.
1089 result SetDouble(int index, double value);
1092 * Sets a @c float value at the specified index of the calling %ByteBuffer object. @n
1093 * Provides a way for absolute indexing and writing.
1097 * @return An error code
1098 * @param[in] index The index of current instance of %ByteBuffer at which the bytes are written
1099 * @param[in] value The @c float value to write
1100 * @exception E_SUCCESS The method is successful.
1101 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1102 * the @c index is larger than the limit minus the size of @c float or less than @c 0.
1103 * @remarks This method writes the size of @c float number of bytes containing the given @c float value
1104 * into this buffer at the given index.
1107 result SetFloat(int index, float value);
1110 * Sets a @c int value at the specified index of the calling %ByteBuffer object. @n
1111 * Provides a way for absolute indexing and writing.
1115 * @return An error code
1116 * @param[in] index The index of current instance of %ByteBuffer at which the bytes are written
1117 * @param[in] value The @c int value to write
1118 * @exception E_SUCCESS The method is successful.
1119 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1120 * the @c index is larger than the limit minus size of @c int or less than @c 0.
1121 * @remarks This method writes the size of @c int number of bytes containing the given @c int value
1122 * into this buffer at the given index.
1125 result SetInt(int index, int value);
1128 * Sets a @c long value at the specified index of the calling %ByteBuffer object. @n
1129 * Provides a way for absolute indexing and writing.
1133 * @return An error code
1134 * @param[in] index The index at which the bytes are written
1135 * @param[in] value The @c long value to write
1136 * @exception E_SUCCESS The method is successful.
1137 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1138 * the @c index is larger than the limit minus the size of @c long or less than @c 0.
1139 * @remarks This method writes size of @c long number of bytes containing the given @c long value
1140 * into this buffer at the given index.
1143 result SetLong(int index, long value);
1146 * Sets a @c long @c long value at the specified index of the calling %ByteBuffer object. @n
1147 * Provides a way for absolute indexing and writing.
1151 * @return An error code
1152 * @param[in] index The index at which the bytes will be written
1153 * @param[in] value The @c long @c long value to write
1154 * @exception E_SUCCESS The method is successful.
1155 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1156 * the @c index is larger than the limit minus the size of @c long @c long or less than @c 0.
1157 * @remarks This method writes the size of @c long @c long number of bytes containing the given @c long @c long value
1158 * into this buffer at the given index.
1159 * @see GetLongLong()
1161 result SetLongLong(int index, long long value);
1165 * Sets a @c wchar_t value at the specified index of the calling %ByteBuffer object. @n
1166 * Provides a way for absolute indexing and writing.
1168 * @brief <i> [Deprecated] </i>
1169 * @deprecated This method is deprecated as @c mchar type is changed to @c wchar_t type.
1170 * Instead of using this method, use the SetWchar(int index, wchar_t value) method.
1173 * @return An error code
1174 * @param[in] index The index at which the bytes will be written
1175 * @param[in] value The @c wchar_t value to write
1176 * @exception E_SUCCESS The method is successful.
1177 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1178 * the @c index is larger than the limit minus the size of @c wchar_t or less than @c 0.
1179 * @remarks This method writes the size of @c wchar_t number of bytes containing the given @c wchar_t value
1180 * into this buffer at the given index.
1184 result SetMchar(int index, wchar_t value);
1187 * Sets a @c wchar_t value at the specified index of the calling %ByteBuffer object. @n
1188 * Provides a way for absolute indexing and writing.
1192 * @return An error code
1193 * @param[in] index The index at which the bytes will be written
1194 * @param[in] value The @c wchar_t value to write
1195 * @exception E_SUCCESS The method is successful.
1196 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1197 * the @c index is larger than the limit minus the size of @c wchar_t or less than @c 0.
1198 * @remarks This method writes the size of @c wchar_t number of bytes containing the given @c wchar_t value
1199 * into this buffer at the given index.
1202 result SetWchar(int index, wchar_t value);
1205 * Sets a @c short value at the specified index of the calling %ByteBuffer object. @n
1206 * Provides a way for absolute indexing and writing.
1210 * @return An error code
1211 * @param[in] index The index of at which the bytes are written
1212 * @param[in] value The @c short value to write
1213 * @exception E_SUCCESS The method is successful.
1214 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1215 * the @c index is larger than the limit minus the size of @c short or less than @c 0.
1216 * @remarks This method writes the size of @c short number of bytes containing the given @c short value
1217 * into this buffer at the given index.
1220 result SetShort(int index, short value);
1223 * Creates a new %ByteBuffer whose content is a shared portion of
1224 * the content of the calling %ByteBuffer object.
1228 * @return %ByteBuffer pointer to the current position of the calling object
1229 * @remarks The content of the new buffer starts at the current position of the calling %ByteBuffer object.
1230 * The new buffer's position is zero, its capacity and limit are
1231 * the number of bytes remaining of the current instance of %ByteBuffer,
1232 * and its mark is undefined.
1234 ByteBuffer* SliceN(void) const;
1237 * Gets the pointer to the raw array of the calling buffer. @n
1238 * If the capacity is zero, it returns @c null.
1242 * @return A pointer to the raw array of the calling buffer
1244 const byte* GetPointer(void) const;
1247 * Gets the pointer to the raw array of the calling buffer. @n
1248 * If the capacity is zero, it returns @c null.
1252 * @return A pointer(non-const) to the raw array of the calling buffer
1254 byte* GetPointer(void);
1257 * Compares the input Object with the calling %ByteBuffer instance.
1261 * @return @c true if the input object equals the calling %ByteBuffer instance, @n
1263 * @param[in] obj The object instance to compare with the calling object
1264 * @remarks This method returns @c true only if the specified object is also an instance of
1265 * the %ByteBuffer class, the two buffers have the same number of remaining elements, and the two
1266 * sequences of remaining elements are equal (considered independent of their starting positions).
1267 * @see Tizen::Base::BufferBase::GetHashCode()
1269 virtual bool Equals(const Tizen::Base::Object& obj) const;
1272 * Gets the hash value of the current instance.
1276 * @return The hash value of the current instance
1277 * @remarks The hash code of a buffer depends only upon its remaining elements.
1279 virtual int GetHashCode(void) const;
1283 * This copy constructor is intentionally declared as private to prohibit copying of objects by users.
1285 ByteBuffer(const ByteBuffer& buffer)
1286 : __pByteBufferImpl(null)
1292 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
1294 ByteBuffer& operator =(const ByteBuffer& buffer);
1297 * Returns the size of byte(1).
1299 * @return The size of byte(1)
1301 virtual int GetTypeSize(void) const;
1304 friend class _ByteBufferImpl;
1305 class _ByteBufferImpl* __pByteBufferImpl;
1311 #endif // _FBASE_BYTE_BUFFER_H_