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.cpp
19 * @brief This is the implementation for ByteBuffer class.
22 #include <FBaseByteBuffer.h>
23 #include <FBaseSysLog.h>
24 #include <unique_ptr.h>
26 static const byte DOUBLE_SIZE = sizeof(double);
27 static const byte FLOAT_SIZE = sizeof(float);
28 static const byte INT_SIZE = sizeof(int);
29 static const byte LONG_SIZE = sizeof(long);
30 static const byte LONGLONG_SIZE = sizeof(long long);
31 static const byte MCHAR_SIZE = sizeof(wchar_t);
32 static const byte SHORT_SIZE = sizeof(short);
34 namespace Tizen { namespace Base
37 ByteBuffer::ByteBuffer(void)
38 : __pByteBufferImpl(null)
42 ByteBuffer::~ByteBuffer(void)
47 ByteBuffer::Construct(const ByteBuffer& buffer)
49 SysTryReturn(NID_BASE, null != buffer._pData, E_INVALID_ARG, E_INVALID_ARG,
50 "[%s] The source buffer is not constructed.", GetErrorMessage(E_INVALID_ARG));
52 _capacity = buffer._capacity;
53 _position = buffer._position;
54 _limit = buffer._limit;
56 _pData = buffer._pData;
59 __pArrayStart = buffer.__pArrayStart;
65 ByteBuffer::Construct(int capacity)
67 result r = BufferBase::Construct(capacity);
70 SysLogException(NID_BASE, r, "[%s] Propagated.", GetErrorMessage(r));
77 ByteBuffer::Construct(const byte* pBuffer, int index, int length, int capacity)
79 SysTryReturn(NID_BASE, pBuffer != null, E_INVALID_ARG, E_INVALID_ARG, "[%s] The pBuffer is null.",
80 GetErrorMessage(E_INVALID_ARG));
81 SysTryReturn(NID_BASE, index >= 0 && length >= 0 && capacity >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
82 "[%s] index(%d), length(%d) and capacity(%d) MUST be greater than or equal to 0.",
83 GetErrorMessage(E_OUT_OF_RANGE), index, length, capacity);
84 SysTryReturn(NID_BASE, index < capacity && length <= capacity && index + length <= capacity,
85 E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index(%d), length(%d) and capacity(%d) MUST be greater than or equal to 0.",
86 GetErrorMessage(E_OUT_OF_RANGE), index, length, capacity);
89 int sizeofBufferData = sizeof(_BufferData);
91 __pArrayStart = const_cast< byte* >(pBuffer + index);
93 pTemp = malloc(sizeofBufferData);
94 SysTryReturn(NID_BASE, pTemp != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s]", GetErrorMessage(E_OUT_OF_MEMORY));
96 memset(pTemp, 0, sizeofBufferData);
97 _pData = static_cast< _BufferData* >(pTemp);
100 _pData->capacityInByte = capacity;
102 _capacity = capacity;
109 ByteBuffer::operator [](int index)
111 SysAssertf(index < _limit, "index out of range.\n");
112 SysAssertf(index >= 0, "index out of range.\n");
114 return __pArrayStart[index];
118 ByteBuffer::operator [](int index) const
120 return const_cast< ByteBuffer& >(*this)[index];
124 ByteBuffer::operator ==(const ByteBuffer& buffer) const
132 else if (GetRemaining() != buffer.GetRemaining())
138 for (int i = 0; i < GetRemaining(); ++i)
140 if (__pArrayStart[_position + i] != buffer.__pArrayStart[buffer._position + i])
152 ByteBuffer::operator !=(const ByteBuffer& buffer) const
154 return !(*this == buffer);
158 ByteBuffer::AsDoubleBufferN(void) const
160 std::unique_ptr< DoubleBuffer > pBuffer(new (std::nothrow) DoubleBuffer());
161 pBuffer->_pData = _pData;
163 pBuffer->_capacity = GetRemaining() / DOUBLE_SIZE;
164 pBuffer->_limit = pBuffer->_capacity;
165 if (pBuffer->_capacity > 0)
167 pBuffer->__pArrayStart = &__pArrayStart[_position];
170 return pBuffer.release();
174 ByteBuffer::AsFloatBufferN(void) const
176 std::unique_ptr< FloatBuffer > pBuffer(new (std::nothrow) FloatBuffer());
177 pBuffer->_pData = _pData;
179 pBuffer->_capacity = GetRemaining() / FLOAT_SIZE;
180 pBuffer->_limit = pBuffer->_capacity;
181 if (pBuffer->_capacity > 0)
183 pBuffer->__pArrayStart = &__pArrayStart[_position];
186 return pBuffer.release();
190 ByteBuffer::AsIntBufferN(void) const
192 std::unique_ptr< IntBuffer > pBuffer(new (std::nothrow) IntBuffer());
193 pBuffer->_pData = _pData;
195 pBuffer->_capacity = GetRemaining() / INT_SIZE;
196 pBuffer->_limit = pBuffer->_capacity;
197 if (pBuffer->_capacity > 0)
199 pBuffer->__pArrayStart = &__pArrayStart[_position];
202 return pBuffer.release();
206 ByteBuffer::AsLongBufferN(void) const
208 std::unique_ptr< LongBuffer > pBuffer(new (std::nothrow) LongBuffer());
209 pBuffer->_pData = _pData;
211 pBuffer->_capacity = GetRemaining() / LONG_SIZE;
212 pBuffer->_limit = pBuffer->_capacity;
213 if (pBuffer->_capacity > 0)
215 pBuffer->__pArrayStart = &__pArrayStart[_position];
218 return pBuffer.release();
222 ByteBuffer::AsLongLongBufferN(void) const
224 std::unique_ptr< LongLongBuffer > pBuffer(new (std::nothrow) LongLongBuffer());
225 pBuffer->_pData = _pData;
227 pBuffer->_capacity = GetRemaining() / LONGLONG_SIZE;
228 pBuffer->_limit = pBuffer->_capacity;
229 if (pBuffer->_capacity > 0)
231 pBuffer->__pArrayStart = &__pArrayStart[_position];
234 return pBuffer.release();
238 ByteBuffer::AsMcharBufferN(void) const
240 std::unique_ptr< McharBuffer > pBuffer(new (std::nothrow) McharBuffer());
241 pBuffer->_pData = _pData;
243 pBuffer->_capacity = GetRemaining() / MCHAR_SIZE;
244 pBuffer->_limit = pBuffer->_capacity;
245 if (pBuffer->_capacity > 0)
247 pBuffer->__pArrayStart = &__pArrayStart[_position];
250 return pBuffer.release();
254 ByteBuffer::AsWcharBufferN(void) const
256 std::unique_ptr< WcharBuffer > pBuffer(new (std::nothrow) WcharBuffer());
257 pBuffer->_pData = _pData;
259 pBuffer->_capacity = GetRemaining() / MCHAR_SIZE;
260 pBuffer->_limit = pBuffer->_capacity;
261 if (pBuffer->_capacity > 0)
263 pBuffer->__pArrayStart = &__pArrayStart[_position];
266 return pBuffer.release();
270 ByteBuffer::AsShortBufferN(void) const
272 std::unique_ptr< ShortBuffer > pBuffer(new (std::nothrow) ShortBuffer());
273 pBuffer->_pData = _pData;
275 pBuffer->_capacity = GetRemaining() / SHORT_SIZE;
276 pBuffer->_limit = pBuffer->_capacity;
277 if (pBuffer->_capacity > 0)
279 pBuffer->__pArrayStart = &__pArrayStart[_position];
282 return pBuffer.release();
286 ByteBuffer::CopyFrom(ByteBuffer& buffer)
288 SysTryReturn(NID_BASE, this != static_cast< void* >(&buffer), E_INVALID_ARG, E_INVALID_ARG,
289 "[%s] The source and target buffers are identical.", GetErrorMessage(E_INVALID_ARG));
290 int copyLength = buffer.GetRemaining();
291 SysTryReturn(NID_BASE,
292 GetRemaining() >= copyLength, E_OVERFLOW, E_OVERFLOW,
293 "[%s] The current buffer is smaller than the input buffer.", GetErrorMessage(E_OVERFLOW));
295 memcpy(__pArrayStart + _position, buffer.__pArrayStart + buffer._position, copyLength);
296 _position += copyLength;
297 buffer._position += copyLength;
303 ByteBuffer::GetArray(byte* pArray, int index, int length)
305 SysTryReturn(NID_BASE, null != pArray, E_INVALID_ARG, E_INVALID_ARG, "[%s] The pArray is null.",
306 GetErrorMessage(E_INVALID_ARG));
307 SysTryReturn(NID_BASE, index >= 0 && length >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
308 "[%s] Both of index(%d) and length(%d) MUST be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE),
310 SysTryReturn(NID_BASE, GetRemaining() >= length, E_UNDERFLOW, E_UNDERFLOW, "[%s]", GetErrorMessage(E_UNDERFLOW));
312 memcpy(pArray + index, __pArrayStart + _position, length);
319 ByteBuffer::GetByte(byte& value)
321 SysTryReturn(NID_BASE, _position < _limit, E_UNDERFLOW, E_UNDERFLOW,
322 "[%s] The current position is not smaller than the limit.", GetErrorMessage(E_UNDERFLOW));
324 value = __pArrayStart[_position++];
330 ByteBuffer::GetByte(int index, byte& value) const
332 SysTryReturn(NID_BASE, index < _limit && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
333 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the current limit(%d).", GetErrorMessage(E_OUT_OF_RANGE),
336 value = __pArrayStart[index];
342 ByteBuffer::GetDouble(double& value)
344 SysTryReturn(NID_BASE,
345 GetRemaining() >= DOUBLE_SIZE, E_UNDERFLOW, E_UNDERFLOW,
346 "[%s] The remaining bytes of this buffer are smaller than the size of double", GetErrorMessage(E_UNDERFLOW));
348 value = *reinterpret_cast< double* >(&__pArrayStart[_position]);
349 _position += DOUBLE_SIZE;
355 ByteBuffer::GetDouble(int index, double& value) const
357 SysTryReturn(NID_BASE,
358 index <= (_limit - DOUBLE_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
359 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of double(%d)'.",
360 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, DOUBLE_SIZE);
362 value = *reinterpret_cast< double* >(&__pArrayStart[index]);
368 ByteBuffer::GetFloat(float& value)
370 SysTryReturn(NID_BASE,
371 GetRemaining() >= FLOAT_SIZE, E_UNDERFLOW, E_UNDERFLOW,
372 "[%s] The remaining bytes of this buffer are smaller than the size of float.", GetErrorMessage(E_UNDERFLOW));
374 value = *reinterpret_cast< float* >(&__pArrayStart[_position]);
375 _position += FLOAT_SIZE;
381 ByteBuffer::GetFloat(int index, float& value) const
383 SysTryReturn(NID_BASE,
384 index <= (_limit - FLOAT_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
385 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of float(%d)'.",
386 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, FLOAT_SIZE);
388 value = *reinterpret_cast< float* >(&__pArrayStart[index]);
394 ByteBuffer::GetInt(int& value)
396 SysTryReturn(NID_BASE,
397 GetRemaining() >= INT_SIZE, E_UNDERFLOW, E_UNDERFLOW,
398 "[%s] The remaining bytes of this buffer are smaller than the size of int.", GetErrorMessage(E_UNDERFLOW));
400 value = *reinterpret_cast< int* >(&__pArrayStart[_position]);
401 _position += INT_SIZE;
407 ByteBuffer::GetInt(int index, int& value) const
409 SysTryReturn(NID_BASE,
410 index <= (_limit - INT_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
411 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of int(%d)'.",
412 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, INT_SIZE);
414 value = *reinterpret_cast< int* >(&__pArrayStart[index]);
420 ByteBuffer::GetLong(long& value)
422 SysTryReturn(NID_BASE,
423 GetRemaining() >= LONG_SIZE, E_UNDERFLOW, E_UNDERFLOW,
424 "[%s] The remaining bytes of this buffer are smaller than the size of long.", GetErrorMessage(E_UNDERFLOW));
426 value = *reinterpret_cast< long* >(&__pArrayStart[_position]);
427 _position += LONG_SIZE;
433 ByteBuffer::GetLong(int index, long& value) const
435 SysTryReturn(NID_BASE,
436 index <= (_limit - LONG_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
437 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of long(%d)'.",
438 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, LONG_SIZE);
440 value = *reinterpret_cast< long* >(&__pArrayStart[index]);
446 ByteBuffer::GetLongLong(long long& value)
448 SysTryReturn(NID_BASE,
449 GetRemaining() >= LONGLONG_SIZE, E_UNDERFLOW, E_UNDERFLOW,
450 "[%s] The remaining bytes of this buffer are smaller than the size of long long.", GetErrorMessage(E_UNDERFLOW));
452 value = *reinterpret_cast< long long* >(&__pArrayStart[_position]);
453 _position += LONGLONG_SIZE;
459 ByteBuffer::GetLongLong(int index, long long& value) const
461 SysTryReturn(NID_BASE,
462 index <= (_limit - LONGLONG_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
463 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of long long(%d)'.",
464 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, LONGLONG_SIZE);
466 value = *reinterpret_cast< long long* >(&__pArrayStart[index]);
472 ByteBuffer::GetMchar(wchar_t& value)
474 SysTryReturn(NID_BASE,
475 GetRemaining() >= MCHAR_SIZE, E_UNDERFLOW, E_UNDERFLOW,
476 "[%s] The remaining bytes of this buffer are smaller than the size of wchar_t.", GetErrorMessage(E_UNDERFLOW));
478 value = *reinterpret_cast< wchar_t* >(&__pArrayStart[_position]);
479 _position += MCHAR_SIZE;
485 ByteBuffer::GetWchar(wchar_t& value)
487 SysTryReturn(NID_BASE,
488 GetRemaining() >= MCHAR_SIZE, E_UNDERFLOW, E_UNDERFLOW,
489 "[%s] The remaining bytes of this buffer are smaller than the size of wchar_t.", GetErrorMessage(E_UNDERFLOW));
491 value = *reinterpret_cast< wchar_t* >(&__pArrayStart[_position]);
492 _position += MCHAR_SIZE;
498 ByteBuffer::GetMchar(int index, wchar_t& value) const
500 SysTryReturn(NID_BASE,
501 index <= (_limit - MCHAR_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
502 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of wchar_t(%d)'.",
503 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, MCHAR_SIZE);
505 value = *reinterpret_cast< wchar_t* >(&__pArrayStart[index]);
511 ByteBuffer::GetWchar(int index, wchar_t& value) const
513 SysTryReturn(NID_BASE,
514 index <= (_limit - MCHAR_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
515 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of wchar_t(%d)'.",
516 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, MCHAR_SIZE);
518 value = *reinterpret_cast< wchar_t* >(&__pArrayStart[index]);
524 ByteBuffer::GetShort(short& value)
526 SysTryReturn(NID_BASE,
527 GetRemaining() >= SHORT_SIZE, E_UNDERFLOW, E_UNDERFLOW,
528 "[%s] The remaining bytes of this buffer are smaller than the size of short.", GetErrorMessage(E_UNDERFLOW));
530 value = *reinterpret_cast< short* >(&__pArrayStart[_position]);
531 _position += SHORT_SIZE;
537 ByteBuffer::GetShort(int index, short& value) const
539 SysTryReturn(NID_BASE,
540 index <= (_limit - SHORT_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
541 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of short(%d)'.",
542 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, SHORT_SIZE);
544 value = *reinterpret_cast< short* >(&__pArrayStart[index]);
550 ByteBuffer::ReadFrom(ByteBuffer& buffer)
552 SysTryReturn(NID_BASE, this != static_cast< void* >(&buffer), E_INVALID_ARG, E_INVALID_ARG,
553 "[%s] The source and target buffers are identical.", GetErrorMessage(E_INVALID_ARG));
555 int copyLength = (GetRemaining() < buffer.GetRemaining()) ? GetRemaining() : buffer.GetRemaining();
556 memcpy(__pArrayStart + _position, buffer.__pArrayStart + buffer._position, copyLength);
557 _position += copyLength;
558 buffer._position += copyLength;
564 ByteBuffer::SetArray(const byte* pArray, int index, int length)
566 SysTryReturn(NID_BASE, null != pArray, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The pArray is null.");
567 SysTryReturn(NID_BASE, index >= 0 && length >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
568 "[%s] Both of index(%d) and length(%d) MUST be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE),
570 SysTryReturn(NID_BASE, GetRemaining() >= length, E_OVERFLOW, E_OVERFLOW, "[%s] The remaining bytes are smaller than length.",
571 GetErrorMessage(E_OVERFLOW));
573 memcpy(__pArrayStart + _position, pArray + index, length);
580 ByteBuffer::SetByte(byte value)
582 SysTryReturn(NID_BASE, _position < _limit, E_OVERFLOW, E_OVERFLOW,
583 "[%s] The current position is not smaller than the limit.", GetErrorMessage(E_OVERFLOW));
585 __pArrayStart[_position++] = value;
590 ByteBuffer::SetByte(int index, byte value)
592 SysTryReturn(NID_BASE, index < _limit && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
593 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the current limit(%d).",
594 GetErrorMessage(E_OUT_OF_RANGE), index, _limit);
596 __pArrayStart[index] = value;
601 ByteBuffer::SetDouble(double value)
603 SysTryReturn(NID_BASE,
604 GetRemaining() >= DOUBLE_SIZE, E_OVERFLOW, E_OVERFLOW,
605 "[%s] The remaining bytes of this buffer are smaller than size of double.", GetErrorMessage(E_OVERFLOW));
607 *reinterpret_cast< double* >(&__pArrayStart[_position]) = value;
608 _position += DOUBLE_SIZE;
614 ByteBuffer::SetDouble(int index, double value)
616 SysTryReturn(NID_BASE,
617 index <= (_limit - DOUBLE_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
618 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of double(%d)'.",
619 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, DOUBLE_SIZE);
621 *reinterpret_cast< double* >(&__pArrayStart[index]) = value;
627 ByteBuffer::SetFloat(float value)
629 SysTryReturn(NID_BASE,
630 GetRemaining() >= FLOAT_SIZE, E_OVERFLOW, E_OVERFLOW,
631 "[%s] The remaining bytes of this buffer are smaller than size of float.", GetErrorMessage(E_OVERFLOW));
633 *reinterpret_cast< float* >(&__pArrayStart[_position]) = value;
634 _position += FLOAT_SIZE;
640 ByteBuffer::SetFloat(int index, float value)
642 SysTryReturn(NID_BASE,
643 index <= (_limit - FLOAT_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
644 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of float(%d)'.",
645 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, FLOAT_SIZE);
647 *reinterpret_cast< float* >(&__pArrayStart[index]) = value;
653 ByteBuffer::SetInt(int value)
655 SysTryReturn(NID_BASE,
656 GetRemaining() >= INT_SIZE, E_OVERFLOW, E_OVERFLOW,
657 "[%s] The remaining bytes of this buffer are smaller than size of int.", GetErrorMessage(E_OVERFLOW));
659 *reinterpret_cast< int* >(&__pArrayStart[_position]) = value;
660 _position += INT_SIZE;
666 ByteBuffer::SetInt(int index, int value)
668 SysTryReturn(NID_BASE,
669 index <= (_limit - INT_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
670 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of int(%d)'.",
671 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, INT_SIZE);
673 *reinterpret_cast< int* >(&__pArrayStart[index]) = value;
679 ByteBuffer::SetLong(long value)
681 SysTryReturn(NID_BASE,
682 GetRemaining() >= LONG_SIZE, E_OVERFLOW, E_OVERFLOW,
683 "[%s] The remaining bytes of this buffer are smaller than size of long.", GetErrorMessage(E_OVERFLOW));
685 *reinterpret_cast< long* >(&__pArrayStart[_position]) = value;
686 _position += LONG_SIZE;
692 ByteBuffer::SetLong(int index, long value)
694 SysTryReturn(NID_BASE,
695 index <= (_limit - LONG_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
696 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of long(%d)'.",
697 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, LONG_SIZE);
699 *reinterpret_cast< long* >(&__pArrayStart[index]) = value;
705 ByteBuffer::SetLongLong(long long value)
707 SysTryReturn(NID_BASE,
708 GetRemaining() >= LONGLONG_SIZE, E_OVERFLOW, E_OVERFLOW,
709 "[%s] The remaining bytes of this buffer are smaller than size of long long.", GetErrorMessage(E_OVERFLOW));
711 *reinterpret_cast< long long* >(&__pArrayStart[_position]) = value;
712 _position += LONGLONG_SIZE;
718 ByteBuffer::SetLongLong(int index, long long value)
720 SysTryReturn(NID_BASE,
721 index <= (_limit - LONGLONG_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
722 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of long long(%d)'.",
723 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, LONGLONG_SIZE);
725 *reinterpret_cast< long long* >(&__pArrayStart[index]) = value;
731 ByteBuffer::SetMchar(wchar_t value)
733 SysTryReturn(NID_BASE,
734 GetRemaining() >= MCHAR_SIZE, E_OVERFLOW, E_OVERFLOW,
735 "[%s] The remaining bytes of this buffer are smaller than size of wchar_t.", GetErrorMessage(E_OVERFLOW));
737 *reinterpret_cast< wchar_t* >(&__pArrayStart[_position]) = value;
738 _position += MCHAR_SIZE;
744 ByteBuffer::SetWchar(wchar_t value)
746 SysTryReturn(NID_BASE,
747 GetRemaining() >= MCHAR_SIZE, E_OVERFLOW, E_OVERFLOW,
748 "[%s] The remaining bytes of this buffer are smaller than size of wchar_t.", GetErrorMessage(E_OVERFLOW));
750 *reinterpret_cast< wchar_t* >(&__pArrayStart[_position]) = value;
751 _position += MCHAR_SIZE;
757 ByteBuffer::SetMchar(int index, wchar_t value)
759 SysTryReturn(NID_BASE,
760 index <= (_limit - MCHAR_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
761 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of wchar_t(%d)'.",
762 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, MCHAR_SIZE);
764 *reinterpret_cast< wchar_t* >(&__pArrayStart[index]) = value;
770 ByteBuffer::SetWchar(int index, wchar_t value)
772 SysTryReturn(NID_BASE,
773 index <= (_limit - MCHAR_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
774 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of wchar_t(%d)'.",
775 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, MCHAR_SIZE);
777 *reinterpret_cast< wchar_t* >(&__pArrayStart[index]) = value;
783 ByteBuffer::SetShort(short value)
785 SysTryReturn(NID_BASE,
786 GetRemaining() >= SHORT_SIZE, E_OVERFLOW, E_OVERFLOW,
787 "[%s] The remaining bytes of this buffer are smaller than size of short.", GetErrorMessage(E_OVERFLOW));
789 *reinterpret_cast< short* >(&__pArrayStart[_position]) = value;
790 _position += SHORT_SIZE;
796 ByteBuffer::SetShort(int index, short value)
798 SysTryReturn(NID_BASE,
799 index <= (_limit - SHORT_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
800 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of short(%d)'.",
801 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, SHORT_SIZE);
803 *reinterpret_cast< short* >(&__pArrayStart[index]) = value;
809 ByteBuffer::SliceN(void) const
811 std::unique_ptr< ByteBuffer > pBuffer(new (std::nothrow) ByteBuffer());
812 pBuffer->_pData = _pData;
814 pBuffer->_capacity = GetRemaining();
815 pBuffer->_limit = pBuffer->_capacity;
816 if (pBuffer->_capacity > 0)
818 pBuffer->__pArrayStart = &__pArrayStart[_position];
821 return pBuffer.release();
825 ByteBuffer::GetPointer(void) const
827 return __pArrayStart;
831 ByteBuffer::GetPointer(void)
833 return __pArrayStart;
837 ByteBuffer::Equals(const Tizen::Base::Object& obj) const
840 const ByteBuffer* pOther = dynamic_cast< const ByteBuffer* >(&obj);
845 else if ((pOther == this) || (*pOther == *this))
854 ByteBuffer::GetHashCode(void) const
856 int len = GetRemaining() / sizeof(len);
859 int offset = _position;
860 for (int i = 0; i < len; ++i)
862 hash = (hash << 5) - hash + static_cast< int >(__pArrayStart[offset + (i * sizeof(hash))]);
869 ByteBuffer::GetTypeSize(void) const