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.
24 #ifndef _FBASE_BYTE_BUFFER_H_
25 #define _FBASE_BYTE_BUFFER_H_
27 #include <FBaseBufferBase.h>
28 #include <FBaseBuffer.h>
31 namespace Tizen { namespace Base
36 * @brief This class provides a contiguous sequence of the @c byte (@c unsigned @c char) built-in type.
40 * The %ByteBuffer class provides a means of encapsulating a sequence of bytes in memory. It defines
41 * methods to read and write all primitive built-in types (except @c bool), to and from a sequence of
42 * bytes. These methods read the size of primitive type bytes from a @c byte sequence and
43 * convert it to the actual primitive type.
45 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/buffer.htm">Buffer</a>.
47 * @see Tizen::Base::BufferBase
49 * The following example demonstrates how to use the %ByteBuffer class.
54 * using namespace Tizen::Base;
57 * MyClass::ByteBufferSample(void)
59 * // Defines the maximum buffer size : capacity
60 * const int BUFFER_SIZE_MAX = 1024;
62 * // Initializes a buf using the Construct method to the capacity
64 * buf.Construct(BUFFER_SIZE_MAX);
66 * // Copies five values into the buf
67 * for (int i = 0; i < 5; i++)
71 * // Writes byte b to the current position of the buf
72 * buf.SetByte(b); // The position is incremented by one
74 * // The position is moved to 5
78 * // Now, position = 0 and limit = 5
80 * // Reads bytes from the buf using "relative access method"
81 * while (buf.HasRemaining())
85 * // Reads byte b from the current position of the buf
86 * buf.GetByte(b); // The position is incremented by one
92 * // The buf's position = 0 and limit = capacity
94 * // Writes int values to the buf
95 * for (int i = 0; i < 5; i++)
97 * // Writes int value at the current position
98 * buf.SetInt(i); // The position is incremented by sizeof(int)
103 * // Now, position = 0 and limit = sizeof(int) * 5
105 * // Creates a new view, IntBuffer.
106 * // Capacity of intBuf = 5
107 * // The content of intBuf is from the buf's position to the buf's limit
108 * IntBuffer* pIntBuf = buf.AsIntBufferN();
110 * // Tests whether the change in view buffer(IntBuffer) is visible in original buffer(ByteBuffer)
111 * pIntBuf->Set(4, 9);
113 * // Reads int values from the buf using "absolute access method"
114 * for (int i = 0; i < 5; i++)
118 * // Reads int value from the buf with the specified index.
119 * buf.GetInt((i * sizeof(int)), out); // 0, 1, 2, 3, 9
120 * // The position is not changed
129 class _OSP_EXPORT_ ByteBuffer
135 * The object is not fully constructed after this constructor is called.
136 * For full construction, the Construct() method must be called right after calling this constructor.
140 * @remarks After creating an instance of the %ByteBuffer class, one of the Construct() methods must be called explicitly to initialize this instance.
146 * This destructor overrides Tizen::Base::Object::~Object().
150 virtual ~ByteBuffer(void);
153 * Initializes this instance of %ByteBuffer which is a view of the specified buffer. @n
154 * This is the copy constructor for the %ByteBuffer class.
158 * @param[in] buffer The %ByteBuffer instance used to initialize new object
159 * @exception E_SUCCESS The method is successful.
160 * @exception E_INVALID_ARG A specified input parameter is invalid, or
161 * the source buffer is not constructed.
164 result Construct(const ByteBuffer& buffer);
167 * Initializes this instance of %ByteBuffer with the specified @c capacity.
171 * @return An error code
172 * @param[in] capacity The number of elements
173 * @exception E_SUCCESS The method is successful.
174 * @exception E_INVALID_ARG A specified input parameter is invalid, or
175 * the specified @c capacity is negative.
178 result Construct(int capacity);
181 * Initializes this instance of %ByteBuffer with the specified @c buffer which is shared with this instance.
185 * @return An error code
186 * @param[in] pBuffer The buffer which is shared
187 * @param[in] index The starting index of the buffer from where the first @c byte value is read
188 * @param[in] length The number of bytes to read from the given buffer @n This is a limit of this instance.
189 * @param[in] capacity The capacity of this instance
190 * @exception E_SUCCESS The method is successful.
191 * @exception E_INVALID_ARG A specified input parameter is invalid, or
192 * the @c pBuffer is @c null.
193 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
194 * the @c index is larger than the @c length.
196 result Construct(const byte *pBuffer, int index, int length, int capacity);
199 * Gets the reference to the byte value at the specified index.
203 * @return A reference to the @c byte value
204 * @param[in] index The index of the @c byte value in the calling %ByteBuffer instance @n
205 * It must be less than the limit.
207 byte& operator [](int index);
210 * Gets the byte value at the specified index of const object.
214 * @return A value to the @c byte value
215 * @param[in] index The index of the @c byte value in the calling %ByteBuffer instance @n
216 * It must be less than the limit.
218 byte operator [](int index) const;
221 * Compares the two %ByteBuffer instances.
225 * @return @c true if the input buffer is equal to the calling %ByteBuffer instance, @n
227 * @param[in] buffer The %ByteBuffer instance to compare with the current instance
228 * @remarks This method returns @c true only if the two buffers have the same number of
229 * remaining elements, and the two sequences of remaining elements are equal
230 * (considered independently, irrespective of their starting positions).
233 bool operator ==(const ByteBuffer& buffer) const;
236 * Checks whether the current instance and the specified instance of %ByteBuffer are not equal.
240 * @return @c true if the two objects are not the same, @n
242 * @param[in] buffer The buffer to compare with the current instance
243 * @remarks This method returns @c false only if the two buffers being compared have the same
244 * number of remaining elements, and the two sequences of remaining elements are equal
245 * (considered independently, irrespective of their starting positions).
248 bool operator !=(const ByteBuffer& buffer) const;
251 * Creates a new @c double buffer view for the content of the byte buffer.
255 * @return DoubleBuffer A pointer to the current position of the calling object
256 * @remarks The content of the view buffer starts at the current position of the calling buffer.
257 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
258 * are equal to the remaining part of this buffer divided by the size of @c double.
259 * Any change to the byte buffer content is visible in the @c double buffer view, and vice versa.
261 DoubleBuffer* AsDoubleBufferN(void) const;
264 * Creates a new @c float buffer view for the content of the byte buffer.
268 * @return FloatBuffer A pointer to the current position of the calling buffer
269 * @remarks The content of the view buffer starts at the current position of the calling buffer.
270 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
271 * are equal to the remaining part of the calling buffer divided by the size of @c float.
272 * Any change to the byte buffer content is visible in the @c float buffer view, and vice versa.
274 FloatBuffer* AsFloatBufferN(void) const;
277 * Creates a new @c int buffer view for the content of the byte buffer.
281 * @return IntBuffer A pointer to the current position of the calling buffer
282 * @remarks The content of the view buffer starts at the current position of the calling buffer.
283 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
284 * are equal to the remaining part of calling buffer divided by the size of @c int.
285 * Any change to the byte buffer content is visible in the Int buffer view, and vice versa.
287 IntBuffer* AsIntBufferN(void) const;
290 * Creates a new @c long buffer view for the content of the byte buffer.
294 * @return LongBuffer A pointer to the current position of the calling buffer
295 * @remarks The content of the view buffer starts at the current position of this buffer.
296 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
297 * are equal to the remaining part of calling buffer divided by the size of @c long.
298 * Any change to the byte buffer content is visible in the @c long buffer view, and vice versa.
300 LongBuffer* AsLongBufferN(void) const;
303 * Creates a new @c long @c long buffer view for the content of the byte buffer.
307 * @return LongLongBuffer A pointer to the current position of the calling buffer
308 * @remarks The content of the view buffer starts at the current position of this buffer.
309 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
310 * are equal to the remaining part of calling buffer divided by the size of @c long.
311 * Any change to the byte buffer content is visible in the @c long @c long buffer view, and vice versa.
313 LongLongBuffer* AsLongLongBufferN(void) const;
317 * Creates a new @c mchar buffer view of the underlying content of the byte buffer.
319 * @brief <i> [Deprecated] </i>
320 * @deprecated This method is deprecated as @c mchar type is changed to @c wchar_t type.
321 * Instead of using this method, use the AsWcharBufferN() method.
324 * @return McharBuffer A pointer to the current position of the calling buffer
325 * @remarks The content of the view buffer starts at the current position of this buffer.
326 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
327 * are equal to the remaining part of the calling buffer divided by the size of @c long.
328 * Any change to the byte buffer content is visible in the @c mchar buffer view, and vice versa.
331 McharBuffer* AsMcharBufferN(void) const;
334 * Creates a new wchar Buffer view of the underlying content of the byte buffer.
338 * @return WcharBuffer pointer to the current position of the calling buffer
339 * @remarks The content of the view buffer start at the current position of this buffer. @n
340 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
341 * are equal to the remaining part of the calling buffer divided by the size of @c long. @n
342 * Any changes to the calling buffer's content (that is, the content of %ByteBuffer instance) @n
343 * are visible in the WcharBuffer view, and vice versa.
345 WcharBuffer* AsWcharBufferN(void) const;
348 * Creates a new @c short buffer view for the content of the byte buffer.
352 * @return ShortBuffer pointer to the current position of the calling buffer
353 * @remarks The content of the view buffer starts at the current position of this buffer.
354 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
355 * are equal to the remaining part of calling buffer divided by the size of @c long.
356 * Any change to the byte buffer content is visible in the @c short buffer view, and vice versa.
358 ShortBuffer* AsShortBufferN(void) const;
361 * Copies the remaining bytes of the input %ByteBuffer instance into the calling %ByteBuffer object. @n
362 * It returns E_OVERFLOW if the remaining bytes in the current instance are less
363 * than the remaining bytes in the input instance.
367 * @return An error code
368 * @param[in] buffer The source buffer from which bytes are read @n
369 * It must not be the calling object.
370 * @exception E_SUCCESS The method is successful.
371 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
372 * The source buffer is same as destination buffer,
373 * that is, the current instance of the buffer.
374 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow. @n
375 * The number of remaining bytes of the current buffer is smaller than
376 * the number of remaining bytes of the input buffer.
377 * @remarks After the copy operation, the current (destination) buffer's position and the given
378 * (source) buffer's positions are incremented by the number of bytes copied (the number of
379 * remaining bytes of the given buffer). @n
380 * If the remaining part of the current instance is greater than or equal to the remaining part of the input instance,
381 * the effect of this method and the ReadFrom(%ByteBuffer) method is the same. But when the remaining part of the
382 * current instance is less, the ReadFrom() method copies the number of remaining elements of the current
383 * instance while this method returns E_OVERFLOW and does not copy.
386 * The following example demonstrates how to use the %CopyFrom() method.
390 * // Creates instances of ByteBuffer to act as source and destination buffers
392 * ByteBuffer destBuf;
394 * // Declares an array of byte values
395 * byte pArray[] = {'A','B','C','D','E','F','G','H','I','J'};
397 * // Initializes the source array with a capacity of ten elements.
398 * srcBuf.Construct(10);
400 * // Copies the ten values from pArray starting at position 0 to the srcBuf
401 * // Now, srcBuf's position = 10
402 * srcBuf.SetArray(pArray, 0, 10);
404 * // Flips the buffer: The limit is set to the current position and
405 * // then the position is set to zero
406 * srcBuf.Flip(); // srcBuf's position = 0 and limit = 10
409 * destBuf.Construct(20);
411 * // Copies from the srcBuf to the destBuf
412 * // Now, srcBuf's position = 10, the destBuf's position = 10
413 * destBuf.CopyFrom(srcBuf);
417 * The following example has exactly the same effect as the above %CopyFrom() method.
421 * int copyNum = srcBuf.GetRemaining();
422 * for (int i = 0; i < copyNum; i++)
426 * // Reads from source buffer
427 * srcBuf.GetByte(b); // The srcBuf position is incremented by 1
429 * // Writes to destination buffer
430 * destBuf.SetByte(b); // The destBuf position is incremented by 1
435 result CopyFrom(ByteBuffer& buffer);
438 * Gets the specified number of bytes from the current instance of %ByteBuffer.
442 * @return An error code
443 * @param[out] pArray A pointer to the destination array into which the bytes are written
444 * @param[in] index The starting index in the array of the first byte to write
445 * @param[in] length The number of bytes to write to the given array
446 * @exception E_SUCCESS The method is successful.
447 * @exception E_INVALID_ARG A specified input parameter is invalid, or
448 * the @c pArray is @c null.
449 * @exception E_OUT_OF_RANGE A specified input parameter is invalid. @n
450 * The @c index or @c length is less than @c 0.
451 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
452 * the remaining bytes of this buffer are smaller than @c length.
453 * @remarks This method copies @c length bytes from the current instance of %ByteBuffer to the given array,
454 * starting at the current position and at the given index in the array.
455 * After the copy operation, the position is incremented by @c length bytes.
458 result GetArray(byte* pArray, int index, int length);
461 * Gets the @c byte value from the buffer at the current position, and then increments the position. @n
462 * Provides a way for relative indexing and reading.
466 * @return An error code
467 * @param[out] value The @c byte value at the current position in the %ByteBuffer instance
468 * @exception E_SUCCESS The method is successful.
469 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
470 * the current position is not smaller than the limit.
473 result GetByte(byte& value);
476 * Gets the @c byte value at the given index. @n
477 * Provides a way for absolute indexing and reading.
481 * @return An error code
482 * @param[in] index The index of the current %ByteBuffer instance, from which the byte is read
483 * @param[out] value The @c byte value at the given @c index
484 * @exception E_SUCCESS The method is successful.
485 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
486 * the @c index is not smaller than the limit or less than @c 0.
489 result GetByte(int index, byte& value) const;
492 * Gets the size of @c double number of bytes from the buffer at the current position, converts
493 * it to the corresponding @c double equivalent, and then increments the position. @n
494 * Provides a way for relative indexing and reading.
498 * @return An error code
499 * @param[out] value The @c double value at the current position in the %ByteBuffer instance
500 * @exception E_SUCCESS The method is successful.
501 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
502 * the remaining bytes of this buffer are smaller than the size of @c double.
503 * @remarks This method reads the next size of @c double number of bytes at the current position,
504 * composing it into a @c double value, and then increments the position by the size of @c double.
507 result GetDouble(double& value);
510 * Gets the size of @c double number of bytes at the given index and converts it to the equivalent @c double value. @n
511 * Provides a way for absolute indexing and reading.
515 * @return An error code
516 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
517 * @param[out] value The @c double value at the given index
518 * @exception E_SUCCESS The method is successful.
519 * @exception E_OUT_OF_RANGE The specified @c index is outside the bounds of the data structure, or
520 * the @c index is larger than the limit minus size of @c double or less than @c 0.
521 * @remarks This method reads size of @c double number of bytes at the given index,
522 * composing them into a @c double value.
525 result GetDouble(int index, double& value) const;
528 * Gets the size of @c float number of bytes from the buffer at the current position, converts
529 * it to the corresponding @c float equivalent, and then increments the position. @n
530 * Provides a way for relative indexing and reading.
534 * @return An error code
535 * @param[out] value The @c float value at the current position in the %ByteBuffer instance
536 * @exception E_SUCCESS The method is successful.
537 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
538 * the remaining bytes of this buffer are smaller than the size of @c float.
539 * @remarks This method reads the next size of @c float number of bytes at the current position,
540 * composing it into a @c float value, and then increments the position by the size of @c float.
543 result GetFloat(float& value);
546 * Gets the size of @c float number of bytes at the given index and converts it to equivalent @c float value. @n
547 * Provides a way for absolute indexing and reading.
551 * @return An error code
552 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
553 * @param[out] value The @c float value at the given index
554 * @exception E_SUCCESS The method is successful.
555 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
556 * the @c index is larger than the limit minus size of @c float or less than @c 0.
557 * @remarks This method reads the size of @c float number of bytes at the given index,
558 * composing it into a @c float value.
561 result GetFloat(int index, float& value) const;
564 * Gets the size of @c int number of bytes from the buffer at the current position, converts
565 * it to the corresponding @c int equivalent, and then increments the position. @n
566 * Provides a way for relative indexing and reading.
570 * @return An error code
571 * @param[out] value The @c int value at the current position in the %ByteBuffer instance
572 * @exception E_SUCCESS The method is successful.
573 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
574 * the remaining bytes of this buffer are smaller than the size of @c int.
575 * @remarks This method reads the next size of @c int number of bytes at the current position,
576 * composing them into an @c int value, and then increments the position by the size of @c int.
579 result GetInt(int& value);
582 * Gets the size of @c int number of bytes at the given index and converts it to the equivalent @c int value. @n
583 * Provides a way for absolute indexing and reading.
587 * @return An error code
588 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
589 * @param[out] value The @c int value at the given index
590 * @exception E_SUCCESS The method is successful.
591 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
592 * the @c index is larger than the limit minus size of @c int or negative.
593 * @remarks This method reads the size of @c int number of bytes at the given index,
594 * composing it into an @c int value.
597 result GetInt(int index, int& value) const;
600 * Gets the size of @c long number of bytes from the buffer at the current position, converts
601 * it to the corresponding @c long equivalent, and then increments the position. @n
602 * Provides a way for relative indexing and reading.
606 * @return An error code
607 * @param[out] value The @c long value at the current position in the %ByteBuffer instance
608 * @exception E_SUCCESS The method is successful.
609 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
610 * the remaining bytes of this buffer are smaller than the size of @c long.
611 * @remarks This method reads the next size of @c long number of bytes at the current position,
612 * composing it into a @c long value, and then increments the position by the size of @c long.
615 result GetLong(long& value);
618 * Gets the size of @c long number of bytes at the given index and converts it to equivalent @c long value. @n
619 * Provides a way for absolute indexing and reading.
623 * @return An error code
624 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
625 * @param[out] value The @c long value at the given index
626 * @exception E_SUCCESS The method is successful.
627 * @exception E_OUT_OF_RANGE The specified @c index is outside the bounds of the data structure, or
628 * the @c index is larger than the limit minus size of @c long or less than @c 0.
629 * @remarks This method reads the size of @c long number of bytes at the given index,
630 * composing it into a @c long value.
633 result GetLong(int index, long& value) const;
636 * Gets the size of @c long @c long number of bytes from the buffer at the current position, converts
637 * it to the corresponding @c long @c long equivalent, and then increments the position. @n
638 * Provides a way for relative indexing and reading.
642 * @return An error code
643 * @param[out] value The @c long @c long value at the current position in the %ByteBuffer instance
644 * @exception E_SUCCESS The method is successful.
645 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
646 * the remaining bytes of this buffer are smaller than the size of @c long @c long.
647 * @remarks This method reads the next size of @c long @c long number of bytes at the current position,
648 * composing it into a @c long @c long value, and then increments the position by the size of @c long @c long.
651 result GetLongLong(long long& value);
654 * 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
655 * Provides a way for absolute indexing and reading.
659 * @return An error code
660 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
661 * @param[out] value The @c long @c long value at the given index
662 * @exception E_SUCCESS The method is successful.
663 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
664 * the @c index is larger than the limit minus size of @c long @c long or less than @c 0.
665 * @remarks This method reads the size of @c long @c long number of bytes at the given index,
666 * composing it into a @c long @c long value.
669 result GetLongLong(int index, long long& value) const;
673 * Gets the size of @c wchar_t number of bytes from the buffer at the current position, converts
674 * it to the corresponding @c wchar_t equivalent, and then increments the position. @n
675 * Provides a way for relative indexing and reading.
677 * @brief <i> [Deprecated] </i>
678 * @deprecated This method is deprecated as @c mchar type is changed to @c wchar_t type.
679 * Instead of using this method, use the GetWchar(wchar_t& value) method.
682 * @return An error code
683 * @param[out] value The @c wchar_t value at the current position in the %ByteBuffer instance
684 * @exception E_SUCCESS The method is successful.
685 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
686 * the remaining bytes of this buffer are smaller than the size of @c wchar_t.
687 * @remarks This method reads the next size of @c wchar_t number of bytes at the current position,
688 * composing it into a @c wchar_t value, and then increments the position by the size of @c wchar_t.
692 result GetMchar(wchar_t& value);
695 * Gets the size of @c wchar_t number of bytes from the buffer at the current position, converts
696 * it to the corresponding @c wchar_t equivalent, and then increments the position. @n
697 * Provides a way for relative indexing and reading.
701 * @return An error code
702 * @param[out] value The @c wchar_t value at the current position in the %ByteBuffer instance
703 * @exception E_SUCCESS The method is successful.
704 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
705 * the remaining bytes of this buffer are smaller than the size of @c wchar_t.
706 * @remarks This method reads the next size of @c wchar_t number of bytes at the current position,
707 * composing it into a @c wchar_t value, and then increments the position by the size of @c wchar_t.
710 result GetWchar(wchar_t& value);
714 * Provides a way for absolute indexing and reading. @n
715 * It reads the size of @c wchar_t number of bytes at the given index and converts it to equivalent @c wchar_t value.
717 * @brief <i> [Deprecated] </i>
718 * @deprecated This method is deprecated as @c mchar type is changed to @c wchar_t type.
719 * Instead of using this method, use the GetWchar(int index, wchar_t& value) method.
722 * @return An error code
723 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
724 * @param[out] value The @c wchar_t value at the given index
725 * @exception E_SUCCESS The method is successful.
726 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
727 * the @c index is larger than the limit minus size of @c wchar_t or less than @c 0.
728 * @remarks This method reads the size of @c wchar_t number of bytes at the given index,
729 * composing it into a @c wchar_t value.
733 result GetMchar(int index, wchar_t& value) const;
736 * Provides a way for absolute indexing and reading. @n
737 * It reads the size of @c wchar_t number of bytes at the given index and converts it to equivalent @c wchar_t value.
741 * @return An error code
742 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
743 * @param[out] value The @c wchar_t value at the given index
744 * @exception E_SUCCESS The method is successful.
745 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
746 * the @c index is larger than the limit minus size of @c wchar_t or less than @c 0.
747 * @remarks This method reads the size of @c wchar_t number of bytes at the given index,
748 * composing it into a @c wchar_t value.
751 result GetWchar(int index, wchar_t& value) const;
754 * Gets the size of @c short number of bytes from the buffer at the current position, converts
755 * it to the corresponding @c short equivalent, and then increments the position. @n
756 * Provides a way for relative indexing and reading.
760 * @return An error code
761 * @param[out] value The @c short value at the current position in the %ByteBuffer instance
762 * @exception E_SUCCESS The method is successful.
763 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
764 * the remaining bytes of this buffer are smaller than the size of @c short.
765 * @remarks This method reads the next size of @c short number of bytes at the current position,
766 * composing it into a @c short value, and then increments the position by the size of @c short.
769 result GetShort(short& value);
772 * Gets the size of @c short number of bytes at the given index and converts it to the equivalent @c short value. @n
773 * Provides a way for absolute indexing and reading.
777 * @return An error code
778 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
779 * @param[out] value The @c short value at the given index
780 * @exception E_SUCCESS The method is successful.
781 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
782 * the @c index is larger than the limit minus size of @c short or less than @c 0.
783 * @remarks This method reads the size of @c short number of bytes at the given index,
784 * composing it into a @c short value.
787 result GetShort(int index, short& value) const;
790 * Copies the remaining bytes of the input %ByteBuffer instance into the calling %ByteBuffer instance
791 * if the remaining part of the current instance is greater than or equal to the remaining part of the input instance. @n
792 * Otherwise, the number of bytes copied is equal to the number of remaining elements of the current instance.
796 * @return An error code
797 * @param[in] buffer The source buffer from which bytes are read @n
798 * It must not be the calling %ByteBuffer instance.
799 * @exception E_SUCCESS The method is successful.
800 * @exception E_INVALID_ARG The specified input parameter is invalid.
802 * @remarks After the copy operation, the current (destination) buffer's position and the given
803 * (source) buffer's position are incremented by the number of elements copied (the lesser of
804 * the number of elements remaining in the current buffer and the given buffer). @n
805 * If the remaining part of the current instance is greater than or equal to the remaining part of the input instance,
806 * the effect of this method is the same as the CopyFrom() method. But when the remaining part of the
807 * current instance is less, the CopyFrom() method returns E_OVERFLOW and does not transfer;
808 * whereas this method copies the number of remaining elements of the current instance.
811 * The following example demonstrates how to use the %ReadFrom() method.
815 * // Creates instances of %ByteBuffer to act as source and destination buffers
817 * ByteBuffer destBuf;
819 * // Declares an array of byte values
820 * byte pArray[] = {'A','B','C','D','E','F','G','H','I','J'};
822 * // Initializes the source array with capacity of ten elements.
823 * srcBuf.Construct(10);
825 * // Copies the 10 values from pArray starting at position 0 to srcBuf
826 * // Now, srcBuf's position = 10
827 * srcBuf.SetArray(pArray, 0, 10);
829 * // Flips the buffer: The limit is set to the current position and
830 * // then the position is set to zero
831 * srcBuf.Flip(); // srcBuf's position = 0 and limit = 10
833 * // Initializes the destination buffer with capacity of ten elements
834 * destBuf.Construct(10);
836 * // Sets the limit of destBuf to 5
837 * destBuf.SetLimit(5);
839 * // Reads from the srcBuf to the destBuf
840 * // The destBuf's remaining is 5, smaller than the srcBuf's (10)
841 * // Therefore, five elements are transferred
842 * // srcBuf's position = 5, destBuf's position = 5
843 * destBuf.ReadFrom(srcBuf);
848 * The following example has exactly the same effect as the above %ReadFrom() method.
852 * int copyNum = (destBuf.GetRemaining() < srcBuf.GetRemaing())? destBuf.GetRemaining() : srcBuf.GetRemaining();
853 * for (int i = 0; i < copyNum; i++)
857 * // Reads from the source buffer
858 * srcBuf.GetByte(b); // The srcBuf position is incremented by 1
860 * // Writes to the destination buffer
861 * destBuf.SetByte(b); // The destBuf position is incremented by 1
867 result ReadFrom(ByteBuffer& buffer);
870 * Sets the @c byte values on the specified array to the current instance of %ByteBuffer.
874 * @return An error code
875 * @param[in] pArray The array from which bytes are read
876 * @param[in] index The starting index of the array from where the first @c byte value is read
877 * @param[in] length The number of bytes to read from the given array
878 * @exception E_SUCCESS The method is successful.
879 * @exception E_INVALID_ARG A specified input parameter is invalid, or
880 * the @c pArray is @c null.
881 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
882 * the @c index or length is less than @c 0.
883 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
884 * the remaining bytes are smaller than @c length.
885 * @remarks This method copies the specified number (@c length) of @c byte values into
886 * the calling object of buffer from the source array,
887 * starting from the current position, and at the given index in the array.
888 * After the copy operation, the position is incremented by @c length.
891 result SetArray(const byte* pArray, int index, int length);
894 * Sets the given @c byte value into the calling %ByteBuffer object
895 * at the current position, and then increments the position. @n
896 * Provides a way for relative indexing and writing.
900 * @return An error code
901 * @param[in] value The @c byte value to write to the current instance of %ByteBuffer
902 * @exception E_SUCCESS The method is successful.
903 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
904 * the current position is not smaller than the limit.
907 result SetByte(byte value);
910 * Sets the given @c byte value into the calling %ByteBuffer object at the specified index. @n
911 * Provides a way for absolute indexing and writing.
915 * @return An error code
916 * @param[in] index The index of the current instance of %ByteBuffer at which the byte is written
917 * @param[in] value The @c byte value to write
918 * @exception E_SUCCESS The method is successful.
919 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
920 * the @c index is not smaller than the limit or less than @c 0.
923 result SetByte(int index, byte value);
926 * Sets the given @c double value into the calling %ByteBuffer object
927 * at the current position, and then increments the position. @n
928 * Provides a way for relative indexing and writing.
932 * @return An error code
933 * @param[in] value The @c double value to write
934 * @exception E_SUCCESS The method is successful.
935 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
936 * the remaining bytes of this buffer are smaller than the size of @c double.
937 * @remarks This method writes the size of @c double number of bytes containing the given @c double value
938 * into the calling buffer, at the current position, and then increments the position by the size of @c double.
941 result SetDouble(double value);
944 * Sets the given @c float value into the calling %ByteBuffer object
945 * at the current position, and then increments the position. @n
946 * Provides a way for relative indexing and writing.
950 * @return An error code
951 * @param[in] value The @c float value to write
952 * @exception E_SUCCESS The method is successful.
953 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
954 * the remaining bytes of this buffer are smaller than the size of @c float.
955 * @remarks This method writes the size of @c float number of bytes containing the given @c float value
956 * into this buffer at the current position, and then increments the position by the size of @c float.
959 result SetFloat(float value);
962 * Sets the given @c int value into the calling %ByteBuffer instance at the current
963 * position, and then increments the position. @n
964 * Provides a way for relative indexing and writing.
968 * @return An error code
969 * @param[in] value The @c int value to write
970 * @exception E_SUCCESS The method is successful.
971 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
972 * the remaining bytes of this buffer are smaller than the size of @c int.
973 * @remarks This method writes the size of @c int number of bytes containing the given @c int value
974 * into this buffer at the current position, and then increments the position by the size of @c int.
977 result SetInt(int value);
980 * Sets the given @c long value into the calling %ByteBuffer instance at the current
981 * position, and then increments the position. @n
982 * Provides a way for relative indexing and writing.
986 * @return An error code
987 * @param[in] value The @c long value to write
988 * @exception E_SUCCESS The method is successful.
989 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
990 * the remaining bytes of this buffer are smaller than size of @c long.
991 * @remarks This method writes the size of @c long number of bytes containing the given @c long value
992 * into this buffer at the current position, and then increments the position by the size of @c long.
995 result SetLong(long value);
998 * Sets the given @c long @c long value into the calling %ByteBuffer object at the current
999 * position, and then increments the position. @n
1000 * Provides a way for relative indexing and writing.
1004 * @return An error code
1005 * @param[in] value The @c long @c long value to write
1006 * @exception E_SUCCESS The method is successful.
1007 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
1008 * the remaining bytes of this buffer are smaller than the size of @c long @c long.
1009 * @remarks This method writes the size of @c long @c long number of bytes containing the given @c long @c long value
1010 * into this buffer at the current position, and then increments the position by the size of @c long @c long.
1011 * @see GetLongLong()
1013 result SetLongLong(long long value);
1017 * Sets the given @c wchar_t value into the calling %ByteBuffer object at the current
1018 * position, and then increments the position. @n
1019 * Provides a way for relative indexing and writing.
1021 * @brief <i> [Deprecated] </i>
1022 * @deprecated This method is deprecated as @c mchar type is changed to @c wchar_t type.
1023 * Instead of using this method, use the SetWchar(wchar_t value) method.
1026 * @return An error code
1027 * @param[in] value The @c wchar_t value to write
1028 * @exception E_SUCCESS The method is successful.
1029 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
1030 * the remaining bytes of this buffer are smaller than size of @c wchar_t.
1031 * @remarks This method writes the size of @c wchar_t number of bytes containing the given @c wchar_t value
1032 * into this buffer at the current position, and then increments the position by the size of @c wchar_t.
1036 result SetMchar(wchar_t value);
1039 * Sets the given @c wchar_t value into the calling %ByteBuffer object at the current
1040 * position, and then increments the position. @n
1041 * Provides a way for relative indexing and writing.
1045 * @return An error code
1046 * @param[in] value The @c wchar_t value to write
1047 * @exception E_SUCCESS The method is successful.
1048 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
1049 * the remaining bytes of this buffer are smaller than size of @c wchar_t.
1050 * @remarks This method writes the size of @c wchar_t number of bytes containing the given @c wchar_t value
1051 * into this buffer at the current position, and then increments the position by the size of @c wchar_t.
1054 result SetWchar(wchar_t value);
1057 * Sets the given @c short value into the current instance of %ByteBuffer at the current
1058 * position, and then increments the position. @n
1059 * Provides a way for relative indexing and writing.
1063 * @return An error code
1064 * @param[in] value The @c short value to write
1065 * @exception E_SUCCESS The method is successful.
1066 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
1067 * the remaining bytes of this buffer are smaller than the size of @c short.
1068 * @remarks This method writes the size of @c short number of bytes containing the given @c short value
1069 * into this buffer at the current position, and then increments the position by the size of @c short.
1072 result SetShort(short value);
1075 * Sets a @c double value at the specified index of the current instance of %ByteBuffer. @n
1076 * Provides a way for absolute indexing and writing.
1080 * @return An error code
1081 * @param[in] index The index of current instance of %ByteBuffer at which the bytes are written
1082 * @param[in] value The @c double value to write
1083 * @exception E_SUCCESS The method is successful.
1084 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1085 * the @c index is larger than the limit minus the size of @c double or less than @c 0.
1086 * @remarks This method writes the size of @c double number of bytes containing the given @c double value
1087 * into this buffer at the given index.
1090 result SetDouble(int index, double value);
1093 * Sets a @c float value at the specified index of the calling %ByteBuffer object. @n
1094 * Provides a way for absolute indexing and writing.
1098 * @return An error code
1099 * @param[in] index The index of current instance of %ByteBuffer at which the bytes are written
1100 * @param[in] value The @c float value to write
1101 * @exception E_SUCCESS The method is successful.
1102 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1103 * the @c index is larger than the limit minus the size of @c float or less than @c 0.
1104 * @remarks This method writes the size of @c float number of bytes containing the given @c float value
1105 * into this buffer at the given index.
1108 result SetFloat(int index, float value);
1111 * Sets a @c int value at the specified index of the calling %ByteBuffer object. @n
1112 * Provides a way for absolute indexing and writing.
1116 * @return An error code
1117 * @param[in] index The index of current instance of %ByteBuffer at which the bytes are written
1118 * @param[in] value The @c int value to write
1119 * @exception E_SUCCESS The method is successful.
1120 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1121 * the @c index is larger than the limit minus size of @c int or less than @c 0.
1122 * @remarks This method writes the size of @c int number of bytes containing the given @c int value
1123 * into this buffer at the given index.
1126 result SetInt(int index, int value);
1129 * Sets a @c long value at the specified index of the calling %ByteBuffer object. @n
1130 * Provides a way for absolute indexing and writing.
1134 * @return An error code
1135 * @param[in] index The index at which the bytes are written
1136 * @param[in] value The @c long value to write
1137 * @exception E_SUCCESS The method is successful.
1138 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1139 * the @c index is larger than the limit minus the size of @c long or less than @c 0.
1140 * @remarks This method writes size of @c long number of bytes containing the given @c long value
1141 * into this buffer at the given index.
1144 result SetLong(int index, long value);
1147 * Sets a @c long @c long value at the specified index of the calling %ByteBuffer object. @n
1148 * Provides a way for absolute indexing and writing.
1152 * @return An error code
1153 * @param[in] index The index at which the bytes will be written
1154 * @param[in] value The @c long @c long value to write
1155 * @exception E_SUCCESS The method is successful.
1156 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1157 * the @c index is larger than the limit minus the size of @c long @c long or less than @c 0.
1158 * @remarks This method writes the size of @c long @c long number of bytes containing the given @c long @c long value
1159 * into this buffer at the given index.
1160 * @see GetLongLong()
1162 result SetLongLong(int index, long long value);
1166 * Sets a @c wchar_t value at the specified index of the calling %ByteBuffer object. @n
1167 * Provides a way for absolute indexing and writing.
1169 * @brief <i> [Deprecated] </i>
1170 * @deprecated This method is deprecated as @c mchar type is changed to @c wchar_t type.
1171 * Instead of using this method, use the SetWchar(int index, wchar_t value) method.
1174 * @return An error code
1175 * @param[in] index The index at which the bytes will be written
1176 * @param[in] value The @c wchar_t value to write
1177 * @exception E_SUCCESS The method is successful.
1178 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1179 * the @c index is larger than the limit minus the size of @c wchar_t or less than @c 0.
1180 * @remarks This method writes the size of @c wchar_t number of bytes containing the given @c wchar_t value
1181 * into this buffer at the given index.
1185 result SetMchar(int index, wchar_t value);
1188 * Sets a @c wchar_t value at the specified index of the calling %ByteBuffer object. @n
1189 * Provides a way for absolute indexing and writing.
1193 * @return An error code
1194 * @param[in] index The index at which the bytes will be written
1195 * @param[in] value The @c wchar_t value to write
1196 * @exception E_SUCCESS The method is successful.
1197 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1198 * the @c index is larger than the limit minus the size of @c wchar_t or less than @c 0.
1199 * @remarks This method writes the size of @c wchar_t number of bytes containing the given @c wchar_t value
1200 * into this buffer at the given index.
1203 result SetWchar(int index, wchar_t value);
1206 * Sets a @c short value at the specified index of the calling %ByteBuffer object. @n
1207 * Provides a way for absolute indexing and writing.
1211 * @return An error code
1212 * @param[in] index The index of at which the bytes are written
1213 * @param[in] value The @c short value to write
1214 * @exception E_SUCCESS The method is successful.
1215 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1216 * the @c index is larger than the limit minus the size of @c short or less than @c 0.
1217 * @remarks This method writes the size of @c short number of bytes containing the given @c short value
1218 * into this buffer at the given index.
1221 result SetShort(int index, short value);
1224 * Creates a new %ByteBuffer whose content is a shared portion of
1225 * the content of the calling %ByteBuffer object.
1229 * @return %ByteBuffer pointer to the current position of the calling object
1230 * @remarks The content of the new buffer starts at the current position of the calling %ByteBuffer object.
1231 * The new buffer's position is zero, its capacity and limit are
1232 * the number of bytes remaining of the current instance of %ByteBuffer,
1233 * and its mark is undefined.
1235 ByteBuffer* SliceN(void) const;
1238 * Gets the pointer to the raw array of the calling buffer. @n
1239 * If the capacity is zero, it returns @c null.
1243 * @return A pointer to the raw array of the calling buffer
1245 const byte* GetPointer(void) const;
1248 * Gets the pointer to the raw array of the calling buffer. @n
1249 * If the capacity is zero, it returns @c null.
1253 * @return A pointer(non-const) to the raw array of the calling buffer
1255 byte* GetPointer(void);
1258 * Compares the input Object with the calling %ByteBuffer instance.
1262 * @return @c true if the input object equals the calling %ByteBuffer instance, @n
1264 * @param[in] obj The object instance to compare with the calling object
1265 * @remarks This method returns @c true only if the specified object is also an instance of
1266 * the %ByteBuffer class, the two buffers have the same number of remaining elements, and the two
1267 * sequences of remaining elements are equal (considered independent of their starting positions).
1268 * @see Tizen::Base::BufferBase::GetHashCode()
1270 virtual bool Equals(const Tizen::Base::Object& obj) const;
1273 * Gets the hash value of the current instance.
1277 * @return The hash value of the current instance
1278 * @remarks The hash code of a buffer depends only upon its remaining elements.
1280 virtual int GetHashCode(void) const;
1284 * This copy constructor is intentionally declared as private to prohibit copying of objects by users.
1286 ByteBuffer(const ByteBuffer& buffer)
1287 :__pByteBufferImpl(null)
1293 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
1295 ByteBuffer& operator =(const ByteBuffer& buffer);
1298 * Returns the size of byte(1).
1300 * @return The size of byte(1)
1302 virtual int GetTypeSize(void) const;
1305 friend class _ByteBufferImpl;
1306 class _ByteBufferImpl * __pByteBufferImpl;
1312 #endif // _FBASE_BYTE_BUFFER_H_