2 // Open Service Platform
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
19 * @file FBaseByteBuffer.h
20 * @brief This is the header file for the %ByteBuffer class.
22 * This header file contains the declarations of the %ByteBuffer class.
25 #ifndef _FBASE_BYTE_BUFFER_H_
26 #define _FBASE_BYTE_BUFFER_H_
28 #include <FBaseBufferBase.h>
29 #include <FBaseBuffer.h>
32 namespace Tizen { namespace Base
37 * @brief This class provides a contiguous sequence of the @c byte (@c unsigned @c char) built-in type.
41 * The %ByteBuffer class provides a means of encapsulating a sequence of bytes in memory. It defines
42 * methods to read and write all primitive built-in types (except @c bool), to and from a sequence of
43 * bytes. These methods read the size of primitive type bytes from a @c byte sequence and
44 * convert it to the actual primitive type.
46 * For more information on the class features, see <a href="../org.tizen.native.appprogramming/html/guide/base/buffer.htm">Buffer</a>.
48 * @see Tizen::Base::BufferBase
50 * The following example demonstrates how to use the %ByteBuffer class.
55 * using namespace Tizen::Base;
58 * MyClass::ByteBufferSample(void)
60 * // Defines the maximum buffer size : capacity
61 * const int BUFFER_SIZE_MAX = 1024;
63 * // Initializes a buf using the Construct method to the capacity
65 * buf.Construct(BUFFER_SIZE_MAX);
67 * // Copies five values into the buf
68 * for (int i = 0; i < 5; i++)
72 * // Writes byte b to the current position of the buf
73 * buf.SetByte(b); // The position is incremented by one
75 * // The position is moved to 5
79 * // Now, position = 0 and limit = 5
81 * // Reads bytes from the buf using "relative access method"
82 * while (buf.HasRemaining())
86 * // Reads byte b from the current position of the buf
87 * buf.GetByte(b); // The position is incremented by one
93 * // The buf's position = 0 and limit = capacity
95 * // Writes int values to the buf
96 * for (int i = 0; i < 5; i++)
98 * // Writes int value at the current position
99 * buf.SetInt(i); // The position is incremented by sizeof(int)
104 * // Now, position = 0 and limit = sizeof(int) * 5
106 * // Creates a new view, IntBuffer.
107 * // Capacity of intBuf = 5
108 * // The content of intBuf is from the buf's position to the buf's limit
109 * IntBuffer* pIntBuf = buf.AsIntBufferN();
111 * // Tests whether the change in view buffer(IntBuffer) is visible in original buffer(ByteBuffer)
112 * pIntBuf->Set(4, 9);
114 * // Reads int values from the buf using "absolute access method"
115 * for (int i = 0; i < 5; i++)
119 * // Reads int value from the buf with the specified index.
120 * buf.GetInt((i * sizeof(int)), out); // 0, 1, 2, 3, 9
121 * // The position is not changed
130 class _OSP_EXPORT_ ByteBuffer
136 * The object is not fully constructed after this constructor is called.
137 * For full construction, the Construct() method must be called right after calling this constructor.
141 * @remarks After creating an instance of the %ByteBuffer class, one of the Construct() methods must be called explicitly to initialize this instance.
147 * This destructor overrides Tizen::Base::Object::~Object().
151 virtual ~ByteBuffer(void);
154 * Initializes this instance of %ByteBuffer which is a view of the specified buffer. @n
155 * This is the copy constructor for the %ByteBuffer class.
159 * @param[in] buffer The %ByteBuffer instance used to initialize new object
160 * @exception E_SUCCESS The method is successful.
161 * @exception E_INVALID_ARG A specified input parameter is invalid, or
162 * the source buffer is not constructed.
165 result Construct(const ByteBuffer& buffer);
168 * Initializes this instance of %ByteBuffer with the specified @c capacity.
172 * @return An error code
173 * @param[in] capacity The number of elements
174 * @exception E_SUCCESS The method is successful.
175 * @exception E_INVALID_ARG A specified input parameter is invalid, or
176 * the specified @c capacity is negative.
179 result Construct(int capacity);
182 * Initializes this instance of %ByteBuffer with the specified @c buffer which is shared with this instance.
186 * @return An error code
187 * @param[in] pBuffer The buffer which is shared
188 * @param[in] index The starting index of the buffer from where the first @c byte value is read
189 * @param[in] length The number of bytes to read from the given buffer @n This is a limit of this instance.
190 * @param[in] capacity The capacity of this instance
191 * @exception E_SUCCESS The method is successful.
192 * @exception E_INVALID_ARG A specified input parameter is invalid, or
193 * the @c pBuffer is @c null.
194 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
195 * the @c index is larger than the @c length.
197 result Construct(const byte *pBuffer, int index, int length, int capacity);
200 * Gets the reference to the byte value at the specified index.
204 * @return A reference to the @c byte value
205 * @param[in] index The index of the @c byte value in the calling %ByteBuffer instance @n
206 * It must be less than the limit.
208 byte& operator [](int index);
211 * Gets the byte value at the specified index of const object.
215 * @return A value to the @c byte value
216 * @param[in] index The index of the @c byte value in the calling %ByteBuffer instance @n
217 * It must be less than the limit.
219 byte operator [](int index) const;
222 * Compares the two %ByteBuffer instances.
226 * @return @c true if the input buffer is equal to the calling %ByteBuffer instance, @n
228 * @param[in] buffer The %ByteBuffer instance to compare with the current instance
229 * @remarks This method returns @c true only if the two buffers have the same number of
230 * remaining elements, and the two sequences of remaining elements are equal
231 * (considered independently, irrespective of their starting positions).
234 bool operator ==(const ByteBuffer& buffer) const;
237 * Checks whether the current instance and the specified instance of %ByteBuffer are not equal.
241 * @return @c true if the two objects are not the same, @n
243 * @param[in] buffer The buffer to compare with the current instance
244 * @remarks This method returns @c false only if the two buffers being compared have the same
245 * number of remaining elements, and the two sequences of remaining elements are equal
246 * (considered independently, irrespective of their starting positions).
249 bool operator !=(const ByteBuffer& buffer) const;
252 * Creates a new @c double buffer view for the content of the byte buffer.
256 * @return DoubleBuffer A pointer to the current position of the calling object
257 * @remarks The content of the view buffer starts at the current position of the calling buffer.
258 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
259 * are equal to the remaining part of this buffer divided by the size of @c double.
260 * Any change to the byte buffer content is visible in the @c double buffer view, and vice versa.
262 DoubleBuffer* AsDoubleBufferN(void) const;
265 * Creates a new @c float buffer view for the content of the byte buffer.
269 * @return FloatBuffer A pointer to the current position of the calling buffer
270 * @remarks The content of the view buffer starts at the current position of the calling buffer.
271 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
272 * are equal to the remaining part of the calling buffer divided by the size of @c float.
273 * Any change to the byte buffer content is visible in the @c float buffer view, and vice versa.
275 FloatBuffer* AsFloatBufferN(void) const;
278 * Creates a new @c int buffer view for the content of the byte buffer.
282 * @return IntBuffer A pointer to the current position of the calling buffer
283 * @remarks The content of the view buffer starts at the current position of the calling buffer.
284 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
285 * are equal to the remaining part of calling buffer divided by the size of @c int.
286 * Any change to the byte buffer content is visible in the Int buffer view, and vice versa.
288 IntBuffer* AsIntBufferN(void) const;
291 * Creates a new @c long buffer view for the content of the byte buffer.
295 * @return LongBuffer A pointer to the current position of the calling buffer
296 * @remarks The content of the view buffer starts at the current position of this buffer.
297 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
298 * are equal to the remaining part of calling buffer divided by the size of @c long.
299 * Any change to the byte buffer content is visible in the @c long buffer view, and vice versa.
301 LongBuffer* AsLongBufferN(void) const;
304 * Creates a new @c long @c long buffer view for the content of the byte buffer.
308 * @return LongLongBuffer A pointer to the current position of the calling buffer
309 * @remarks The content of the view buffer starts at the current position of this buffer.
310 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
311 * are equal to the remaining part of calling buffer divided by the size of @c long.
312 * Any change to the byte buffer content is visible in the @c long @c long buffer view, and vice versa.
314 LongLongBuffer* AsLongLongBufferN(void) const;
318 * Creates a new @c mchar buffer view of the underlying content of the byte buffer.
320 * @brief <i> [Deprecated] </i>
321 * @deprecated This method is deprecated as @c mchar type is changed to @c wchar_t type.
322 * Instead of using this method, use the AsWcharBufferN() method.
325 * @return McharBuffer A pointer to the current position of the calling buffer
326 * @remarks The content of the view buffer starts at the current position of this buffer.
327 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
328 * are equal to the remaining part of the calling buffer divided by the size of @c long.
329 * Any change to the byte buffer content is visible in the @c mchar buffer view, and vice versa.
332 McharBuffer* AsMcharBufferN(void) const;
335 * Creates a new wchar Buffer view of the underlying content of the byte buffer.
339 * @return WcharBuffer pointer to the current position of the calling buffer
340 * @remarks The content of the view buffer start at the current position of this buffer. @n
341 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
342 * are equal to the remaining part of the calling buffer divided by the size of @c long. @n
343 * Any changes to the calling buffer's content (that is, the content of %ByteBuffer instance) @n
344 * are visible in the WcharBuffer view, and vice versa.
346 WcharBuffer* AsWcharBufferN(void) const;
349 * Creates a new @c short buffer view for the content of the byte buffer.
353 * @return ShortBuffer pointer to the current position of the calling buffer
354 * @remarks The content of the view buffer starts at the current position of this buffer.
355 * The new buffer's position is zero, the mark is undefined, and the capacity and limit
356 * are equal to the remaining part of calling buffer divided by the size of @c long.
357 * Any change to the byte buffer content is visible in the @c short buffer view, and vice versa.
359 ShortBuffer* AsShortBufferN(void) const;
362 * Copies the remaining bytes of the input %ByteBuffer instance into the calling %ByteBuffer object. @n
363 * It returns E_OVERFLOW if the remaining bytes in the current instance are less
364 * than the remaining bytes in the input instance.
368 * @return An error code
369 * @param[in] buffer The source buffer from which bytes are read @n
370 * It must not be the calling object.
371 * @exception E_SUCCESS The method is successful.
372 * @exception E_INVALID_ARG A specified input parameter is invalid. @n
373 * The source buffer is same as destination buffer,
374 * that is, the current instance of the buffer.
375 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow. @n
376 * The number of remaining bytes of the current buffer is smaller than
377 * the number of remaining bytes of the input buffer.
378 * @remarks After the copy operation, the current (destination) buffer's position and the given
379 * (source) buffer's positions are incremented by the number of bytes copied (the number of
380 * remaining bytes of the given buffer). @n
381 * If the remaining part of the current instance is greater than or equal to the remaining part of the input instance,
382 * the effect of this method and the ReadFrom(%ByteBuffer) method is the same. But when the remaining part of the
383 * current instance is less, the ReadFrom() method copies the number of remaining elements of the current
384 * instance while this method returns E_OVERFLOW and does not copy.
387 * The following example demonstrates how to use the %CopyFrom() method.
391 * // Creates instances of ByteBuffer to act as source and destination buffers
393 * ByteBuffer destBuf;
395 * // Declares an array of byte values
396 * byte pArray[] = {'A','B','C','D','E','F','G','H','I','J'};
398 * // Initializes the source array with a capacity of ten elements.
399 * srcBuf.Construct(10);
401 * // Copies the ten values from pArray starting at position 0 to the srcBuf
402 * // Now, srcBuf's position = 10
403 * srcBuf.SetArray(pArray, 0, 10);
405 * // Flips the buffer: The limit is set to the current position and
406 * // then the position is set to zero
407 * srcBuf.Flip(); // srcBuf's position = 0 and limit = 10
410 * destBuf.Construct(20);
412 * // Copies from the srcBuf to the destBuf
413 * // Now, srcBuf's position = 10, the destBuf's position = 10
414 * destBuf.CopyFrom(srcBuf);
418 * The following example has exactly the same effect as the above %CopyFrom() method.
422 * int copyNum = srcBuf.GetRemaining();
423 * for (int i = 0; i < copyNum; i++)
427 * // Reads from source buffer
428 * srcBuf.GetByte(b); // The srcBuf position is incremented by 1
430 * // Writes to destination buffer
431 * destBuf.SetByte(b); // The destBuf position is incremented by 1
436 result CopyFrom(ByteBuffer& buffer);
439 * Gets the specified number of bytes from the current instance of %ByteBuffer.
443 * @return An error code
444 * @param[out] pArray A pointer to the destination array into which the bytes are written
445 * @param[in] index The starting index in the array of the first byte to write
446 * @param[in] length The number of bytes to write to the given array
447 * @exception E_SUCCESS The method is successful.
448 * @exception E_INVALID_ARG A specified input parameter is invalid, or
449 * the @c pArray is @c null.
450 * @exception E_OUT_OF_RANGE A specified input parameter is invalid. @n
451 * The @c index or @c length is less than @c 0.
452 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
453 * the remaining bytes of this buffer are smaller than @c length.
454 * @remarks This method copies @c length bytes from the current instance of %ByteBuffer to the given array,
455 * starting at the current position and at the given index in the array.
456 * After the copy operation, the position is incremented by @c length bytes.
459 result GetArray(byte* pArray, int index, int length);
462 * Gets the @c byte value from the buffer at the current position, and then increments the position. @n
463 * Provides a way for relative indexing and reading.
467 * @return An error code
468 * @param[out] value The @c byte value at the current position in the %ByteBuffer instance
469 * @exception E_SUCCESS The method is successful.
470 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
471 * the current position is not smaller than the limit.
474 result GetByte(byte& value);
477 * Gets the @c byte value at the given index. @n
478 * Provides a way for absolute indexing and reading.
482 * @return An error code
483 * @param[in] index The index of the current %ByteBuffer instance, from which the byte is read
484 * @param[out] value The @c byte value at the given @c index
485 * @exception E_SUCCESS The method is successful.
486 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
487 * the @c index is not smaller than the limit or less than @c 0.
490 result GetByte(int index, byte& value) const;
493 * Gets the size of @c double number of bytes from the buffer at the current position, converts
494 * it to the corresponding @c double equivalent, and then increments the position. @n
495 * Provides a way for relative indexing and reading.
499 * @return An error code
500 * @param[out] value The @c double value at the current position in the %ByteBuffer instance
501 * @exception E_SUCCESS The method is successful.
502 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
503 * the remaining bytes of this buffer are smaller than the size of @c double.
504 * @remarks This method reads the next size of @c double number of bytes at the current position,
505 * composing it into a @c double value, and then increments the position by the size of @c double.
508 result GetDouble(double& value);
511 * Gets the size of @c double number of bytes at the given index and converts it to the equivalent @c double value. @n
512 * Provides a way for absolute indexing and reading.
516 * @return An error code
517 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
518 * @param[out] value The @c double value at the given index
519 * @exception E_SUCCESS The method is successful.
520 * @exception E_OUT_OF_RANGE The specified @c index is outside the bounds of the data structure, or
521 * the @c index is larger than the limit minus size of @c double or less than @c 0.
522 * @remarks This method reads size of @c double number of bytes at the given index,
523 * composing them into a @c double value.
526 result GetDouble(int index, double& value) const;
529 * Gets the size of @c float number of bytes from the buffer at the current position, converts
530 * it to the corresponding @c float equivalent, and then increments the position. @n
531 * Provides a way for relative indexing and reading.
535 * @return An error code
536 * @param[out] value The @c float value at the current position in the %ByteBuffer instance
537 * @exception E_SUCCESS The method is successful.
538 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
539 * the remaining bytes of this buffer are smaller than the size of @c float.
540 * @remarks This method reads the next size of @c float number of bytes at the current position,
541 * composing it into a @c float value, and then increments the position by the size of @c float.
544 result GetFloat(float& value);
547 * Gets the size of @c float number of bytes at the given index and converts it to equivalent @c float value. @n
548 * Provides a way for absolute indexing and reading.
552 * @return An error code
553 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
554 * @param[out] value The @c float value at the given index
555 * @exception E_SUCCESS The method is successful.
556 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
557 * the @c index is larger than the limit minus size of @c float or less than @c 0.
558 * @remarks This method reads the size of @c float number of bytes at the given index,
559 * composing it into a @c float value.
562 result GetFloat(int index, float& value) const;
565 * Gets the size of @c int number of bytes from the buffer at the current position, converts
566 * it to the corresponding @c int equivalent, and then increments the position. @n
567 * Provides a way for relative indexing and reading.
571 * @return An error code
572 * @param[out] value The @c int value at the current position in the %ByteBuffer instance
573 * @exception E_SUCCESS The method is successful.
574 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
575 * the remaining bytes of this buffer are smaller than the size of @c int.
576 * @remarks This method reads the next size of @c int number of bytes at the current position,
577 * composing them into an @c int value, and then increments the position by the size of @c int.
580 result GetInt(int& value);
583 * Gets the size of @c int number of bytes at the given index and converts it to the equivalent @c int value. @n
584 * Provides a way for absolute indexing and reading.
588 * @return An error code
589 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
590 * @param[out] value The @c int value at the given index
591 * @exception E_SUCCESS The method is successful.
592 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
593 * the @c index is larger than the limit minus size of @c int or negative.
594 * @remarks This method reads the size of @c int number of bytes at the given index,
595 * composing it into an @c int value.
598 result GetInt(int index, int& value) const;
601 * Gets the size of @c long number of bytes from the buffer at the current position, converts
602 * it to the corresponding @c long equivalent, and then increments the position. @n
603 * Provides a way for relative indexing and reading.
607 * @return An error code
608 * @param[out] value The @c long value at the current position in the %ByteBuffer instance
609 * @exception E_SUCCESS The method is successful.
610 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
611 * the remaining bytes of this buffer are smaller than the size of @c long.
612 * @remarks This method reads the next size of @c long number of bytes at the current position,
613 * composing it into a @c long value, and then increments the position by the size of @c long.
616 result GetLong(long& value);
619 * Gets the size of @c long number of bytes at the given index and converts it to equivalent @c long value. @n
620 * Provides a way for absolute indexing and reading.
624 * @return An error code
625 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
626 * @param[out] value The @c long value at the given index
627 * @exception E_SUCCESS The method is successful.
628 * @exception E_OUT_OF_RANGE The specified @c index is outside the bounds of the data structure, or
629 * the @c index is larger than the limit minus size of @c long or less than @c 0.
630 * @remarks This method reads the size of @c long number of bytes at the given index,
631 * composing it into a @c long value.
634 result GetLong(int index, long& value) const;
637 * Gets the size of @c long @c long number of bytes from the buffer at the current position, converts
638 * it to the corresponding @c long @c long equivalent, and then increments the position. @n
639 * Provides a way for relative indexing and reading.
643 * @return An error code
644 * @param[out] value The @c long @c long value at the current position in the %ByteBuffer instance
645 * @exception E_SUCCESS The method is successful.
646 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
647 * the remaining bytes of this buffer are smaller than the size of @c long @c long.
648 * @remarks This method reads the next size of @c long @c long number of bytes at the current position,
649 * composing it into a @c long @c long value, and then increments the position by the size of @c long @c long.
652 result GetLongLong(long long& value);
655 * 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
656 * Provides a way for absolute indexing and reading.
660 * @return An error code
661 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
662 * @param[out] value The @c long @c long value at the given index
663 * @exception E_SUCCESS The method is successful.
664 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
665 * the @c index is larger than the limit minus size of @c long @c long or less than @c 0.
666 * @remarks This method reads the size of @c long @c long number of bytes at the given index,
667 * composing it into a @c long @c long value.
670 result GetLongLong(int index, long long& value) const;
674 * Gets the size of @c wchar_t number of bytes from the buffer at the current position, converts
675 * it to the corresponding @c wchar_t equivalent, and then increments the position. @n
676 * Provides a way for relative indexing and reading.
678 * @brief <i> [Deprecated] </i>
679 * @deprecated This method is deprecated as @c mchar type is changed to @c wchar_t type.
680 * Instead of using this method, use the GetWchar(wchar_t& value) method.
683 * @return An error code
684 * @param[out] value The @c wchar_t value at the current position in the %ByteBuffer instance
685 * @exception E_SUCCESS The method is successful.
686 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
687 * the remaining bytes of this buffer are smaller than the size of @c wchar_t.
688 * @remarks This method reads the next size of @c wchar_t number of bytes at the current position,
689 * composing it into a @c wchar_t value, and then increments the position by the size of @c wchar_t.
693 result GetMchar(wchar_t& value);
696 * Gets the size of @c wchar_t number of bytes from the buffer at the current position, converts
697 * it to the corresponding @c wchar_t equivalent, and then increments the position. @n
698 * Provides a way for relative indexing and reading.
702 * @return An error code
703 * @param[out] value The @c wchar_t value at the current position in the %ByteBuffer instance
704 * @exception E_SUCCESS The method is successful.
705 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
706 * the remaining bytes of this buffer are smaller than the size of @c wchar_t.
707 * @remarks This method reads the next size of @c wchar_t number of bytes at the current position,
708 * composing it into a @c wchar_t value, and then increments the position by the size of @c wchar_t.
711 result GetWchar(wchar_t& value);
715 * Provides a way for absolute indexing and reading. @n
716 * It reads the size of @c wchar_t number of bytes at the given index and converts it to equivalent @c wchar_t value.
718 * @brief <i> [Deprecated] </i>
719 * @deprecated This method is deprecated as @c mchar type is changed to @c wchar_t type.
720 * Instead of using this method, use the GetWchar(int index, wchar_t& value) method.
723 * @return An error code
724 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
725 * @param[out] value The @c wchar_t value at the given index
726 * @exception E_SUCCESS The method is successful.
727 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
728 * the @c index is larger than the limit minus size of @c wchar_t or less than @c 0.
729 * @remarks This method reads the size of @c wchar_t number of bytes at the given index,
730 * composing it into a @c wchar_t value.
734 result GetMchar(int index, wchar_t& value) const;
737 * Provides a way for absolute indexing and reading. @n
738 * It reads the size of @c wchar_t number of bytes at the given index and converts it to equivalent @c wchar_t value.
742 * @return An error code
743 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
744 * @param[out] value The @c wchar_t value at the given index
745 * @exception E_SUCCESS The method is successful.
746 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
747 * the @c index is larger than the limit minus size of @c wchar_t or less than @c 0.
748 * @remarks This method reads the size of @c wchar_t number of bytes at the given index,
749 * composing it into a @c wchar_t value.
752 result GetWchar(int index, wchar_t& value) const;
755 * Gets the size of @c short number of bytes from the buffer at the current position, converts
756 * it to the corresponding @c short equivalent, and then increments the position. @n
757 * Provides a way for relative indexing and reading.
761 * @return An error code
762 * @param[out] value The @c short value at the current position in the %ByteBuffer instance
763 * @exception E_SUCCESS The method is successful.
764 * @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow, or
765 * the remaining bytes of this buffer are smaller than the size of @c short.
766 * @remarks This method reads the next size of @c short number of bytes at the current position,
767 * composing it into a @c short value, and then increments the position by the size of @c short.
770 result GetShort(short& value);
773 * Gets the size of @c short number of bytes at the given index and converts it to the equivalent @c short value. @n
774 * Provides a way for absolute indexing and reading.
778 * @return An error code
779 * @param[in] index The index of the current %ByteBuffer instance, from which the bytes are read
780 * @param[out] value The @c short value at the given index
781 * @exception E_SUCCESS The method is successful.
782 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
783 * the @c index is larger than the limit minus size of @c short or less than @c 0.
784 * @remarks This method reads the size of @c short number of bytes at the given index,
785 * composing it into a @c short value.
788 result GetShort(int index, short& value) const;
791 * Copies the remaining bytes of the input %ByteBuffer instance into the calling %ByteBuffer instance
792 * if the remaining part of the current instance is greater than or equal to the remaining part of the input instance. @n
793 * Otherwise, the number of bytes copied is equal to the number of remaining elements of the current instance.
797 * @return An error code
798 * @param[in] buffer The source buffer from which bytes are read @n
799 * It must not be the calling %ByteBuffer instance.
800 * @exception E_SUCCESS The method is successful.
801 * @exception E_INVALID_ARG The specified input parameter is invalid.
803 * @remarks After the copy operation, the current (destination) buffer's position and the given
804 * (source) buffer's position are incremented by the number of elements copied (the lesser of
805 * the number of elements remaining in the current buffer and the given buffer). @n
806 * If the remaining part of the current instance is greater than or equal to the remaining part of the input instance,
807 * the effect of this method is the same as the CopyFrom() method. But when the remaining part of the
808 * current instance is less, the CopyFrom() method returns E_OVERFLOW and does not transfer;
809 * whereas this method copies the number of remaining elements of the current instance.
812 * The following example demonstrates how to use the %ReadFrom() method.
816 * // Creates instances of %ByteBuffer to act as source and destination buffers
818 * ByteBuffer destBuf;
820 * // Declares an array of byte values
821 * byte pArray[] = {'A','B','C','D','E','F','G','H','I','J'};
823 * // Initializes the source array with capacity of ten elements.
824 * srcBuf.Construct(10);
826 * // Copies the 10 values from pArray starting at position 0 to srcBuf
827 * // Now, srcBuf's position = 10
828 * srcBuf.SetArray(pArray, 0, 10);
830 * // Flips the buffer: The limit is set to the current position and
831 * // then the position is set to zero
832 * srcBuf.Flip(); // srcBuf's position = 0 and limit = 10
834 * // Initializes the destination buffer with capacity of ten elements
835 * destBuf.Construct(10);
837 * // Sets the limit of destBuf to 5
838 * destBuf.SetLimit(5);
840 * // Reads from the srcBuf to the destBuf
841 * // The destBuf's remaining is 5, smaller than the srcBuf's (10)
842 * // Therefore, five elements are transferred
843 * // srcBuf's position = 5, destBuf's position = 5
844 * destBuf.ReadFrom(srcBuf);
849 * The following example has exactly the same effect as the above %ReadFrom() method.
853 * int copyNum = (destBuf.GetRemaining() < srcBuf.GetRemaing())? destBuf.GetRemaining() : srcBuf.GetRemaining();
854 * for (int i = 0; i < copyNum; i++)
858 * // Reads from the source buffer
859 * srcBuf.GetByte(b); // The srcBuf position is incremented by 1
861 * // Writes to the destination buffer
862 * destBuf.SetByte(b); // The destBuf position is incremented by 1
868 result ReadFrom(ByteBuffer& buffer);
871 * Sets the @c byte values on the specified array to the current instance of %ByteBuffer.
875 * @return An error code
876 * @param[in] pArray The array from which bytes are read
877 * @param[in] index The starting index of the array from where the first @c byte value is read
878 * @param[in] length The number of bytes to read from the given array
879 * @exception E_SUCCESS The method is successful.
880 * @exception E_INVALID_ARG A specified input parameter is invalid, or
881 * the @c pArray is @c null.
882 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
883 * the @c index or length is less than @c 0.
884 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
885 * the remaining bytes are smaller than @c length.
886 * @remarks This method copies the specified number (@c length) of @c byte values into
887 * the calling object of buffer from the source array,
888 * starting from the current position, and at the given index in the array.
889 * After the copy operation, the position is incremented by @c length.
892 result SetArray(const byte* pArray, int index, int length);
895 * Sets the given @c byte value into the calling %ByteBuffer object
896 * at the current position, and then increments the position. @n
897 * Provides a way for relative indexing and writing.
901 * @return An error code
902 * @param[in] value The @c byte value to write to the current instance of %ByteBuffer
903 * @exception E_SUCCESS The method is successful.
904 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
905 * the current position is not smaller than the limit.
908 result SetByte(byte value);
911 * Sets the given @c byte value into the calling %ByteBuffer object at the specified index. @n
912 * Provides a way for absolute indexing and writing.
916 * @return An error code
917 * @param[in] index The index of the current instance of %ByteBuffer at which the byte is written
918 * @param[in] value The @c byte value to write
919 * @exception E_SUCCESS The method is successful.
920 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
921 * the @c index is not smaller than the limit or less than @c 0.
924 result SetByte(int index, byte value);
927 * Sets the given @c double value into the calling %ByteBuffer object
928 * at the current position, and then increments the position. @n
929 * Provides a way for relative indexing and writing.
933 * @return An error code
934 * @param[in] value The @c double value to write
935 * @exception E_SUCCESS The method is successful.
936 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
937 * the remaining bytes of this buffer are smaller than the size of @c double.
938 * @remarks This method writes the size of @c double number of bytes containing the given @c double value
939 * into the calling buffer, at the current position, and then increments the position by the size of @c double.
942 result SetDouble(double value);
945 * Sets the given @c float value into the calling %ByteBuffer object
946 * at the current position, and then increments the position. @n
947 * Provides a way for relative indexing and writing.
951 * @return An error code
952 * @param[in] value The @c float value to write
953 * @exception E_SUCCESS The method is successful.
954 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
955 * the remaining bytes of this buffer are smaller than the size of @c float.
956 * @remarks This method writes the size of @c float number of bytes containing the given @c float value
957 * into this buffer at the current position, and then increments the position by the size of @c float.
960 result SetFloat(float value);
963 * Sets the given @c int value into the calling %ByteBuffer instance at the current
964 * position, and then increments the position. @n
965 * Provides a way for relative indexing and writing.
969 * @return An error code
970 * @param[in] value The @c int value to write
971 * @exception E_SUCCESS The method is successful.
972 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
973 * the remaining bytes of this buffer are smaller than the size of @c int.
974 * @remarks This method writes the size of @c int number of bytes containing the given @c int value
975 * into this buffer at the current position, and then increments the position by the size of @c int.
978 result SetInt(int value);
981 * Sets the given @c long value into the calling %ByteBuffer instance at the current
982 * position, and then increments the position. @n
983 * Provides a way for relative indexing and writing.
987 * @return An error code
988 * @param[in] value The @c long value to write
989 * @exception E_SUCCESS The method is successful.
990 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
991 * the remaining bytes of this buffer are smaller than size of @c long.
992 * @remarks This method writes the size of @c long number of bytes containing the given @c long value
993 * into this buffer at the current position, and then increments the position by the size of @c long.
996 result SetLong(long value);
999 * Sets the given @c long @c long value into the calling %ByteBuffer object at the current
1000 * position, and then increments the position. @n
1001 * Provides a way for relative indexing and writing.
1005 * @return An error code
1006 * @param[in] value The @c long @c long value to write
1007 * @exception E_SUCCESS The method is successful.
1008 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
1009 * the remaining bytes of this buffer are smaller than the size of @c long @c long.
1010 * @remarks This method writes the size of @c long @c long number of bytes containing the given @c long @c long value
1011 * into this buffer at the current position, and then increments the position by the size of @c long @c long.
1012 * @see GetLongLong()
1014 result SetLongLong(long long value);
1018 * Sets the given @c wchar_t value into the calling %ByteBuffer object at the current
1019 * position, and then increments the position. @n
1020 * Provides a way for relative indexing and writing.
1022 * @brief <i> [Deprecated] </i>
1023 * @deprecated This method is deprecated as @c mchar type is changed to @c wchar_t type.
1024 * Instead of using this method, use the SetWchar(wchar_t value) method.
1027 * @return An error code
1028 * @param[in] value The @c wchar_t value to write
1029 * @exception E_SUCCESS The method is successful.
1030 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
1031 * the remaining bytes of this buffer are smaller than size of @c wchar_t.
1032 * @remarks This method writes the size of @c wchar_t number of bytes containing the given @c wchar_t value
1033 * into this buffer at the current position, and then increments the position by the size of @c wchar_t.
1037 result SetMchar(wchar_t value);
1040 * Sets the given @c wchar_t value into the calling %ByteBuffer object at the current
1041 * position, and then increments the position. @n
1042 * Provides a way for relative indexing and writing.
1046 * @return An error code
1047 * @param[in] value The @c wchar_t value to write
1048 * @exception E_SUCCESS The method is successful.
1049 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
1050 * the remaining bytes of this buffer are smaller than size of @c wchar_t.
1051 * @remarks This method writes the size of @c wchar_t number of bytes containing the given @c wchar_t value
1052 * into this buffer at the current position, and then increments the position by the size of @c wchar_t.
1055 result SetWchar(wchar_t value);
1058 * Sets the given @c short value into the current instance of %ByteBuffer at the current
1059 * position, and then increments the position. @n
1060 * Provides a way for relative indexing and writing.
1064 * @return An error code
1065 * @param[in] value The @c short value to write
1066 * @exception E_SUCCESS The method is successful.
1067 * @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow, or
1068 * the remaining bytes of this buffer are smaller than the size of @c short.
1069 * @remarks This method writes the size of @c short number of bytes containing the given @c short value
1070 * into this buffer at the current position, and then increments the position by the size of @c short.
1073 result SetShort(short value);
1076 * Sets a @c double value at the specified index of the current instance of %ByteBuffer. @n
1077 * Provides a way for absolute indexing and writing.
1081 * @return An error code
1082 * @param[in] index The index of current instance of %ByteBuffer at which the bytes are written
1083 * @param[in] value The @c double value to write
1084 * @exception E_SUCCESS The method is successful.
1085 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1086 * the @c index is larger than the limit minus the size of @c double or less than @c 0.
1087 * @remarks This method writes the size of @c double number of bytes containing the given @c double value
1088 * into this buffer at the given index.
1091 result SetDouble(int index, double value);
1094 * Sets a @c float value at the specified index of the calling %ByteBuffer object. @n
1095 * Provides a way for absolute indexing and writing.
1099 * @return An error code
1100 * @param[in] index The index of current instance of %ByteBuffer at which the bytes are written
1101 * @param[in] value The @c float value to write
1102 * @exception E_SUCCESS The method is successful.
1103 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1104 * the @c index is larger than the limit minus the size of @c float or less than @c 0.
1105 * @remarks This method writes the size of @c float number of bytes containing the given @c float value
1106 * into this buffer at the given index.
1109 result SetFloat(int index, float value);
1112 * Sets a @c int value at the specified index of the calling %ByteBuffer object. @n
1113 * Provides a way for absolute indexing and writing.
1117 * @return An error code
1118 * @param[in] index The index of current instance of %ByteBuffer at which the bytes are written
1119 * @param[in] value The @c int value to write
1120 * @exception E_SUCCESS The method is successful.
1121 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1122 * the @c index is larger than the limit minus size of @c int or less than @c 0.
1123 * @remarks This method writes the size of @c int number of bytes containing the given @c int value
1124 * into this buffer at the given index.
1127 result SetInt(int index, int value);
1130 * Sets a @c long value at the specified index of the calling %ByteBuffer object. @n
1131 * Provides a way for absolute indexing and writing.
1135 * @return An error code
1136 * @param[in] index The index at which the bytes are written
1137 * @param[in] value The @c long value to write
1138 * @exception E_SUCCESS The method is successful.
1139 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1140 * the @c index is larger than the limit minus the size of @c long or less than @c 0.
1141 * @remarks This method writes size of @c long number of bytes containing the given @c long value
1142 * into this buffer at the given index.
1145 result SetLong(int index, long value);
1148 * Sets a @c long @c long value at the specified index of the calling %ByteBuffer object. @n
1149 * Provides a way for absolute indexing and writing.
1153 * @return An error code
1154 * @param[in] index The index at which the bytes will be written
1155 * @param[in] value The @c long @c long value to write
1156 * @exception E_SUCCESS The method is successful.
1157 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1158 * the @c index is larger than the limit minus the size of @c long @c long or less than @c 0.
1159 * @remarks This method writes the size of @c long @c long number of bytes containing the given @c long @c long value
1160 * into this buffer at the given index.
1161 * @see GetLongLong()
1163 result SetLongLong(int index, long long value);
1167 * Sets a @c wchar_t value at the specified index of the calling %ByteBuffer object. @n
1168 * Provides a way for absolute indexing and writing.
1170 * @brief <i> [Deprecated] </i>
1171 * @deprecated This method is deprecated as @c mchar type is changed to @c wchar_t type.
1172 * Instead of using this method, use the SetWchar(int index, wchar_t value) method.
1175 * @return An error code
1176 * @param[in] index The index at which the bytes will be written
1177 * @param[in] value The @c wchar_t value to write
1178 * @exception E_SUCCESS The method is successful.
1179 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1180 * the @c index is larger than the limit minus the size of @c wchar_t or less than @c 0.
1181 * @remarks This method writes the size of @c wchar_t number of bytes containing the given @c wchar_t value
1182 * into this buffer at the given index.
1186 result SetMchar(int index, wchar_t value);
1189 * Sets a @c wchar_t value at the specified index of the calling %ByteBuffer object. @n
1190 * Provides a way for absolute indexing and writing.
1194 * @return An error code
1195 * @param[in] index The index at which the bytes will be written
1196 * @param[in] value The @c wchar_t value to write
1197 * @exception E_SUCCESS The method is successful.
1198 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1199 * the @c index is larger than the limit minus the size of @c wchar_t or less than @c 0.
1200 * @remarks This method writes the size of @c wchar_t number of bytes containing the given @c wchar_t value
1201 * into this buffer at the given index.
1204 result SetWchar(int index, wchar_t value);
1207 * Sets a @c short value at the specified index of the calling %ByteBuffer object. @n
1208 * Provides a way for absolute indexing and writing.
1212 * @return An error code
1213 * @param[in] index The index of at which the bytes are written
1214 * @param[in] value The @c short value to write
1215 * @exception E_SUCCESS The method is successful.
1216 * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
1217 * the @c index is larger than the limit minus the size of @c short or less than @c 0.
1218 * @remarks This method writes the size of @c short number of bytes containing the given @c short value
1219 * into this buffer at the given index.
1222 result SetShort(int index, short value);
1225 * Creates a new %ByteBuffer whose content is a shared portion of
1226 * the content of the calling %ByteBuffer object.
1230 * @return %ByteBuffer pointer to the current position of the calling object
1231 * @remarks The content of the new buffer starts at the current position of the calling %ByteBuffer object.
1232 * The new buffer's position is zero, its capacity and limit are
1233 * the number of bytes remaining of the current instance of %ByteBuffer,
1234 * and its mark is undefined.
1236 ByteBuffer* SliceN(void) const;
1239 * Gets the pointer to the raw array of the calling buffer. @n
1240 * If the capacity is zero, it returns @c null.
1244 * @return A pointer to the raw array of the calling buffer
1246 const byte* GetPointer(void) const;
1249 * Gets the pointer to the raw array of the calling buffer. @n
1250 * If the capacity is zero, it returns @c null.
1254 * @return A pointer(non-const) to the raw array of the calling buffer
1256 byte* GetPointer(void);
1259 * Compares the input Object with the calling %ByteBuffer instance.
1263 * @return @c true if the input object equals the calling %ByteBuffer instance, @n
1265 * @param[in] obj The object instance to compare with the calling object
1266 * @remarks This method returns @c true only if the specified object is also an instance of
1267 * the %ByteBuffer class, the two buffers have the same number of remaining elements, and the two
1268 * sequences of remaining elements are equal (considered independent of their starting positions).
1269 * @see Tizen::Base::BufferBase::GetHashCode()
1271 virtual bool Equals(const Tizen::Base::Object& obj) const;
1274 * Gets the hash value of the current instance.
1278 * @return The hash value of the current instance
1279 * @remarks The hash code of a buffer depends only upon its remaining elements.
1281 virtual int GetHashCode(void) const;
1285 * This copy constructor is intentionally declared as private to prohibit copying of objects by users.
1287 ByteBuffer(const ByteBuffer& buffer)
1288 :__pByteBufferImpl(null)
1294 * The implementation of this copy assignment operator is intentionally blank and declared as private to prohibit copying of objects.
1296 ByteBuffer& operator =(const ByteBuffer& buffer);
1299 * Returns the size of byte(1).
1301 * @return The size of byte(1)
1303 virtual int GetTypeSize(void) const;
1306 friend class _ByteBufferImpl;
1307 class _ByteBufferImpl * __pByteBufferImpl;
1313 #endif // _FBASE_BYTE_BUFFER_H_