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.cpp
20 * @brief This is the implementation for ByteBuffer class.
24 #include <FBaseByteBuffer.h>
25 #include <FBaseSysLog.h>
26 #include <unique_ptr.h>
29 static const byte DOUBLE_SIZE = sizeof(double);
30 static const byte FLOAT_SIZE = sizeof(float);
31 static const byte INT_SIZE = sizeof(int);
32 static const byte LONG_SIZE = sizeof(long);
33 static const byte LONGLONG_SIZE = sizeof(long long);
34 static const byte MCHAR_SIZE = sizeof(wchar_t);
35 static const byte SHORT_SIZE = sizeof(short);
37 namespace Tizen { namespace Base
40 ByteBuffer::ByteBuffer(void)
41 : __pByteBufferImpl(null)
45 ByteBuffer::~ByteBuffer(void)
50 ByteBuffer::Construct(const ByteBuffer& buffer)
52 SysTryReturn(NID_BASE, null != buffer._pData, E_INVALID_ARG, E_INVALID_ARG,
53 "[%s] The source buffer is not constructed.", GetErrorMessage(E_INVALID_ARG));
55 _capacity = buffer._capacity;
56 _position = buffer._position;
57 _limit = buffer._limit;
59 _pData = buffer._pData;
62 __pArrayStart = buffer.__pArrayStart;
68 ByteBuffer::Construct(int capacity)
70 result r = BufferBase::Construct(capacity);
73 SysLogException(NID_BASE, r, "[%s] Propagated.", GetErrorMessage(r));
80 ByteBuffer::Construct(const byte *pBuffer, int index, int length, int capacity)
82 SysTryReturn(NID_BASE, pBuffer != null, E_INVALID_ARG, E_INVALID_ARG, "[%s] The pBuffer is null.",
83 GetErrorMessage(E_INVALID_ARG));
84 SysTryReturn(NID_BASE, index >= 0 && length >= 0 && capacity >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
85 "[%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);
87 SysTryReturn(NID_BASE, index < capacity && length <= capacity && index + length <= capacity,
88 E_OUT_OF_RANGE, E_OUT_OF_RANGE, "[%s] index(%d), length(%d) and capacity(%d) MUST be greater than or equal to 0.",
89 GetErrorMessage(E_OUT_OF_RANGE), index, length, capacity);
92 int sizeofBufferData = sizeof(_BufferData);
94 __pArrayStart = const_cast<byte *> (pBuffer + index);
96 pTemp = malloc(sizeofBufferData);
97 SysTryReturn(NID_BASE, pTemp != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s]", GetErrorMessage(E_OUT_OF_MEMORY));
99 memset(pTemp, 0, sizeofBufferData);
100 _pData = static_cast <_BufferData*>(pTemp);
102 _pData->refCount = 1;
103 _pData->capacityInByte = capacity;
105 _capacity = capacity;
112 ByteBuffer::operator [](int index)
114 SysAssertf(index < _limit, "index out of range.\n");
115 SysAssertf(index >= 0, "index out of range.\n");
117 return __pArrayStart[index];
121 ByteBuffer::operator [](int index) const
123 return const_cast<ByteBuffer&>(*this)[index];
127 ByteBuffer::operator ==(const ByteBuffer& buffer) const
135 else if (GetRemaining() != buffer.GetRemaining())
141 for (int i = 0; i < GetRemaining(); ++i)
143 if (__pArrayStart[_position + i] != buffer.__pArrayStart[buffer._position + i])
155 ByteBuffer::operator !=(const ByteBuffer& buffer) const
157 return !(*this == buffer);
161 ByteBuffer::AsDoubleBufferN(void) const
163 std::unique_ptr<DoubleBuffer> pBuffer(new (std::nothrow) DoubleBuffer());
164 pBuffer->_pData = _pData;
166 pBuffer->_capacity = GetRemaining() / DOUBLE_SIZE;
167 pBuffer->_limit = pBuffer->_capacity;
168 if (pBuffer->_capacity > 0)
170 pBuffer->__pArrayStart = &__pArrayStart[_position];
173 return pBuffer.release();
177 ByteBuffer::AsFloatBufferN(void) const
179 std::unique_ptr<FloatBuffer> pBuffer(new (std::nothrow) FloatBuffer());
180 pBuffer->_pData = _pData;
182 pBuffer->_capacity = GetRemaining() / FLOAT_SIZE;
183 pBuffer->_limit = pBuffer->_capacity;
184 if (pBuffer->_capacity > 0)
186 pBuffer->__pArrayStart = &__pArrayStart[_position];
189 return pBuffer.release();
193 ByteBuffer::AsIntBufferN(void) const
195 std::unique_ptr<IntBuffer> pBuffer(new (std::nothrow) IntBuffer());
196 pBuffer->_pData = _pData;
198 pBuffer->_capacity = GetRemaining() / INT_SIZE;
199 pBuffer->_limit = pBuffer->_capacity;
200 if (pBuffer->_capacity > 0)
202 pBuffer->__pArrayStart = &__pArrayStart[_position];
205 return pBuffer.release();
209 ByteBuffer::AsLongBufferN(void) const
211 std::unique_ptr<LongBuffer> pBuffer(new (std::nothrow) LongBuffer());
212 pBuffer->_pData = _pData;
214 pBuffer->_capacity = GetRemaining() / LONG_SIZE;
215 pBuffer->_limit = pBuffer->_capacity;
216 if (pBuffer->_capacity > 0)
218 pBuffer->__pArrayStart = &__pArrayStart[_position];
221 return pBuffer.release();
225 ByteBuffer::AsLongLongBufferN(void) const
227 std::unique_ptr<LongLongBuffer> pBuffer(new (std::nothrow) LongLongBuffer());
228 pBuffer->_pData = _pData;
230 pBuffer->_capacity = GetRemaining() / LONGLONG_SIZE;
231 pBuffer->_limit = pBuffer->_capacity;
232 if (pBuffer->_capacity > 0)
234 pBuffer->__pArrayStart = &__pArrayStart[_position];
237 return pBuffer.release();
241 ByteBuffer::AsMcharBufferN(void) const
243 std::unique_ptr<McharBuffer> pBuffer(new (std::nothrow) McharBuffer());
244 pBuffer->_pData = _pData;
246 pBuffer->_capacity = GetRemaining() / MCHAR_SIZE;
247 pBuffer->_limit = pBuffer->_capacity;
248 if (pBuffer->_capacity > 0)
250 pBuffer->__pArrayStart = &__pArrayStart[_position];
253 return pBuffer.release();
257 ByteBuffer::AsWcharBufferN(void) const
259 std::unique_ptr<WcharBuffer> pBuffer(new (std::nothrow) WcharBuffer());
260 pBuffer->_pData = _pData;
262 pBuffer->_capacity = GetRemaining() / MCHAR_SIZE;
263 pBuffer->_limit = pBuffer->_capacity;
264 if (pBuffer->_capacity > 0)
266 pBuffer->__pArrayStart = &__pArrayStart[_position];
269 return pBuffer.release();
273 ByteBuffer::AsShortBufferN(void) const
275 std::unique_ptr<ShortBuffer> pBuffer(new (std::nothrow) ShortBuffer());
276 pBuffer->_pData = _pData;
278 pBuffer->_capacity = GetRemaining() / SHORT_SIZE;
279 pBuffer->_limit = pBuffer->_capacity;
280 if (pBuffer->_capacity > 0)
282 pBuffer->__pArrayStart = &__pArrayStart[_position];
285 return pBuffer.release();
289 ByteBuffer::CopyFrom(ByteBuffer& buffer)
291 SysTryReturn(NID_BASE, this != static_cast <void*>(&buffer), E_INVALID_ARG, E_INVALID_ARG,
292 "[%s] The source and target buffers are identical.", GetErrorMessage(E_INVALID_ARG));
293 int copyLength = buffer.GetRemaining();
294 SysTryReturn(NID_BASE,
295 GetRemaining() >= copyLength, E_OVERFLOW, E_OVERFLOW,
296 "[%s] The current buffer is smaller than the input buffer.", GetErrorMessage(E_OVERFLOW));
298 memcpy(__pArrayStart + _position, buffer.__pArrayStart + buffer._position, copyLength);
299 _position += copyLength;
300 buffer._position += copyLength;
306 ByteBuffer::GetArray(byte* pArray, int index, int length)
308 SysTryReturn(NID_BASE, null != pArray, E_INVALID_ARG, E_INVALID_ARG, "[%s] The pArray is null.",
309 GetErrorMessage(E_INVALID_ARG));
310 SysTryReturn(NID_BASE, index >= 0 && length >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
311 "[%s] Both of index(%d) and length(%d) MUST be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE),
313 SysTryReturn(NID_BASE, GetRemaining() >= length, E_UNDERFLOW, E_UNDERFLOW, "[%s]", GetErrorMessage(E_UNDERFLOW));
315 memcpy(pArray + index, __pArrayStart + _position, length);
322 ByteBuffer::GetByte(byte& value)
324 SysTryReturn(NID_BASE, _position < _limit, E_UNDERFLOW, E_UNDERFLOW,
325 "[%s] The current position is not smaller than the limit.", GetErrorMessage(E_UNDERFLOW));
327 value = __pArrayStart[_position++];
333 ByteBuffer::GetByte(int index, byte& value) const
335 SysTryReturn(NID_BASE, index < _limit && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
336 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the current limit(%d).", GetErrorMessage(E_OUT_OF_RANGE),
339 value = __pArrayStart[index];
345 ByteBuffer::GetDouble(double& value)
347 SysTryReturn(NID_BASE,
348 GetRemaining() >= DOUBLE_SIZE, E_UNDERFLOW, E_UNDERFLOW,
349 "[%s] The remaining bytes of this buffer are smaller than the size of double", GetErrorMessage(E_UNDERFLOW));
351 value = *reinterpret_cast <double*>(&__pArrayStart[_position]);
352 _position += DOUBLE_SIZE;
358 ByteBuffer::GetDouble(int index, double& value) const
360 SysTryReturn(NID_BASE,
361 index <= (_limit - DOUBLE_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
362 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of double(%d)'.",
363 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, DOUBLE_SIZE);
365 value = *reinterpret_cast <double*>(&__pArrayStart[index]);
371 ByteBuffer::GetFloat(float& value)
373 SysTryReturn(NID_BASE,
374 GetRemaining() >= FLOAT_SIZE, E_UNDERFLOW, E_UNDERFLOW,
375 "[%s] The remaining bytes of this buffer are smaller than the size of float.", GetErrorMessage(E_UNDERFLOW));
377 value = *reinterpret_cast <float*>(&__pArrayStart[_position]);
378 _position += FLOAT_SIZE;
384 ByteBuffer::GetFloat(int index, float& value) const
386 SysTryReturn(NID_BASE,
387 index <= (_limit - FLOAT_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
388 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of float(%d)'.",
389 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, FLOAT_SIZE);
391 value = *reinterpret_cast <float*>(&__pArrayStart[index]);
397 ByteBuffer::GetInt(int& value)
399 SysTryReturn(NID_BASE,
400 GetRemaining() >= INT_SIZE, E_UNDERFLOW, E_UNDERFLOW,
401 "[%s] The remaining bytes of this buffer are smaller than the size of int.", GetErrorMessage(E_UNDERFLOW));
403 value = *reinterpret_cast <int*>(&__pArrayStart[_position]);
404 _position += INT_SIZE;
410 ByteBuffer::GetInt(int index, int& value) const
412 SysTryReturn(NID_BASE,
413 index <= (_limit - INT_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
414 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of int(%d)'.",
415 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, INT_SIZE);
417 value = *reinterpret_cast <int*>(&__pArrayStart[index]);
423 ByteBuffer::GetLong(long& value)
425 SysTryReturn(NID_BASE,
426 GetRemaining() >= LONG_SIZE, E_UNDERFLOW, E_UNDERFLOW,
427 "[%s] The remaining bytes of this buffer are smaller than the size of long.", GetErrorMessage(E_UNDERFLOW));
429 value = *reinterpret_cast <long*>(&__pArrayStart[_position]);
430 _position += LONG_SIZE;
436 ByteBuffer::GetLong(int index, long& value) const
438 SysTryReturn(NID_BASE,
439 index <= (_limit - LONG_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
440 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of long(%d)'.",
441 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, LONG_SIZE);
443 value = *reinterpret_cast <long*>(&__pArrayStart[index]);
449 ByteBuffer::GetLongLong(long long& value)
451 SysTryReturn(NID_BASE,
452 GetRemaining() >= LONGLONG_SIZE, E_UNDERFLOW, E_UNDERFLOW,
453 "[%s] The remaining bytes of this buffer are smaller than the size of long long.", GetErrorMessage(E_UNDERFLOW));
455 value = *reinterpret_cast <long long*>(&__pArrayStart[_position]);
456 _position += LONGLONG_SIZE;
462 ByteBuffer::GetLongLong(int index, long long& value) const
464 SysTryReturn(NID_BASE,
465 index <= (_limit - LONGLONG_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
466 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of long long(%d)'.",
467 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, LONGLONG_SIZE);
469 value = *reinterpret_cast <long long*>(&__pArrayStart[index]);
475 ByteBuffer::GetMchar(wchar_t& value)
477 SysTryReturn(NID_BASE,
478 GetRemaining() >= MCHAR_SIZE, E_UNDERFLOW, E_UNDERFLOW,
479 "[%s] The remaining bytes of this buffer are smaller than the size of wchar_t.", GetErrorMessage(E_UNDERFLOW));
481 value = *reinterpret_cast <wchar_t*>(&__pArrayStart[_position]);
482 _position += MCHAR_SIZE;
488 ByteBuffer::GetWchar(wchar_t& value)
490 SysTryReturn(NID_BASE,
491 GetRemaining() >= MCHAR_SIZE, E_UNDERFLOW, E_UNDERFLOW,
492 "[%s] The remaining bytes of this buffer are smaller than the size of wchar_t.", GetErrorMessage(E_UNDERFLOW));
494 value = *reinterpret_cast <wchar_t*>(&__pArrayStart[_position]);
495 _position += MCHAR_SIZE;
501 ByteBuffer::GetMchar(int index, wchar_t& value) const
503 SysTryReturn(NID_BASE,
504 index <= (_limit - MCHAR_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
505 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of wchar_t(%d)'.",
506 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, MCHAR_SIZE);
508 value = *reinterpret_cast <wchar_t*>(&__pArrayStart[index]);
514 ByteBuffer::GetWchar(int index, wchar_t& value) const
516 SysTryReturn(NID_BASE,
517 index <= (_limit - MCHAR_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
518 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of wchar_t(%d)'.",
519 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, MCHAR_SIZE);
521 value = *reinterpret_cast <wchar_t*>(&__pArrayStart[index]);
527 ByteBuffer::GetShort(short& value)
529 SysTryReturn(NID_BASE,
530 GetRemaining() >= SHORT_SIZE, E_UNDERFLOW, E_UNDERFLOW,
531 "[%s] The remaining bytes of this buffer are smaller than the size of short.", GetErrorMessage(E_UNDERFLOW));
533 value = *reinterpret_cast <short*>(&__pArrayStart[_position]);
534 _position += SHORT_SIZE;
540 ByteBuffer::GetShort(int index, short& value) const
542 SysTryReturn(NID_BASE,
543 index <= (_limit - SHORT_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
544 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of short(%d)'.",
545 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, SHORT_SIZE);
547 value = *reinterpret_cast <short*>(&__pArrayStart[index]);
553 ByteBuffer::ReadFrom(ByteBuffer& buffer)
555 SysTryReturn(NID_BASE, this != static_cast <void*>(&buffer), E_INVALID_ARG, E_INVALID_ARG,
556 "[%s] The source and target buffers are identical.", GetErrorMessage(E_INVALID_ARG));
558 int copyLength = (GetRemaining() < buffer.GetRemaining()) ? GetRemaining() : buffer.GetRemaining();
559 memcpy(__pArrayStart + _position, buffer.__pArrayStart + buffer._position, copyLength);
560 _position += copyLength;
561 buffer._position += copyLength;
567 ByteBuffer::SetArray(const byte* pArray, int index, int length)
569 SysTryReturn(NID_BASE, null != pArray, E_INVALID_ARG, E_INVALID_ARG, "[E_INVALID_ARG] The pArray is null.");
570 SysTryReturn(NID_BASE, index >= 0 && length >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
571 "[%s] Both of index(%d) and length(%d) MUST be greater than or equal to 0.", GetErrorMessage(E_OUT_OF_RANGE),
573 SysTryReturn(NID_BASE, GetRemaining() >= length, E_OVERFLOW, E_OVERFLOW, "[%s] The remaining bytes are smaller than length.",
574 GetErrorMessage(E_OVERFLOW));
576 memcpy(__pArrayStart + _position, pArray + index, length);
583 ByteBuffer::SetByte(byte value)
585 SysTryReturn(NID_BASE, _position < _limit, E_OVERFLOW, E_OVERFLOW,
586 "[%s] The current position is not smaller than the limit.", GetErrorMessage(E_OVERFLOW));
588 __pArrayStart[_position++] = value;
593 ByteBuffer::SetByte(int index, byte value)
595 SysTryReturn(NID_BASE, index < _limit && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
596 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the current limit(%d).",
597 GetErrorMessage(E_OUT_OF_RANGE), index, _limit);
599 __pArrayStart[index] = value;
604 ByteBuffer::SetDouble(double value)
606 SysTryReturn(NID_BASE,
607 GetRemaining() >= DOUBLE_SIZE, E_OVERFLOW, E_OVERFLOW,
608 "[%s] The remaining bytes of this buffer are smaller than size of double.", GetErrorMessage(E_OVERFLOW));
610 *reinterpret_cast <double*>(&__pArrayStart[_position]) = value;
611 _position += DOUBLE_SIZE;
617 ByteBuffer::SetDouble(int index, double value)
619 SysTryReturn(NID_BASE,
620 index <= (_limit - DOUBLE_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
621 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of double(%d)'.",
622 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, DOUBLE_SIZE);
624 *reinterpret_cast <double*>(&__pArrayStart[index]) = value;
630 ByteBuffer::SetFloat(float value)
632 SysTryReturn(NID_BASE,
633 GetRemaining() >= FLOAT_SIZE, E_OVERFLOW, E_OVERFLOW,
634 "[%s] The remaining bytes of this buffer are smaller than size of float.", GetErrorMessage(E_OVERFLOW));
636 *reinterpret_cast <float*>(&__pArrayStart[_position]) = value;
637 _position += FLOAT_SIZE;
643 ByteBuffer::SetFloat(int index, float value)
645 SysTryReturn(NID_BASE,
646 index <= (_limit - FLOAT_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
647 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of float(%d)'.",
648 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, FLOAT_SIZE);
650 *reinterpret_cast <float*>(&__pArrayStart[index]) = value;
656 ByteBuffer::SetInt(int value)
658 SysTryReturn(NID_BASE,
659 GetRemaining() >= INT_SIZE, E_OVERFLOW, E_OVERFLOW,
660 "[%s] The remaining bytes of this buffer are smaller than size of int.", GetErrorMessage(E_OVERFLOW));
662 *reinterpret_cast <int*>(&__pArrayStart[_position]) = value;
663 _position += INT_SIZE;
669 ByteBuffer::SetInt(int index, int value)
671 SysTryReturn(NID_BASE,
672 index <= (_limit - INT_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
673 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of int(%d)'.",
674 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, INT_SIZE);
676 *reinterpret_cast <int*>(&__pArrayStart[index]) = value;
682 ByteBuffer::SetLong(long value)
684 SysTryReturn(NID_BASE,
685 GetRemaining() >= LONG_SIZE, E_OVERFLOW, E_OVERFLOW,
686 "[%s] The remaining bytes of this buffer are smaller than size of long.", GetErrorMessage(E_OVERFLOW));
688 *reinterpret_cast <long*>(&__pArrayStart[_position]) = value;
689 _position += LONG_SIZE;
695 ByteBuffer::SetLong(int index, long value)
697 SysTryReturn(NID_BASE,
698 index <= (_limit - LONG_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
699 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of long(%d)'.",
700 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, LONG_SIZE);
702 *reinterpret_cast <long*>(&__pArrayStart[index]) = value;
708 ByteBuffer::SetLongLong(long long value)
710 SysTryReturn(NID_BASE,
711 GetRemaining() >= LONGLONG_SIZE, E_OVERFLOW, E_OVERFLOW,
712 "[%s] The remaining bytes of this buffer are smaller than size of long long.", GetErrorMessage(E_OVERFLOW));
714 *reinterpret_cast <long long*>(&__pArrayStart[_position]) = value;
715 _position += LONGLONG_SIZE;
721 ByteBuffer::SetLongLong(int index, long long value)
723 SysTryReturn(NID_BASE,
724 index <= (_limit - LONGLONG_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
725 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of long long(%d)'.",
726 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, LONGLONG_SIZE);
728 *reinterpret_cast <long long*>(&__pArrayStart[index]) = value;
734 ByteBuffer::SetMchar(wchar_t value)
736 SysTryReturn(NID_BASE,
737 GetRemaining() >= MCHAR_SIZE, E_OVERFLOW, E_OVERFLOW,
738 "[%s] The remaining bytes of this buffer are smaller than size of wchar_t.", GetErrorMessage(E_OVERFLOW));
740 *reinterpret_cast <wchar_t*>(&__pArrayStart[_position]) = value;
741 _position += MCHAR_SIZE;
747 ByteBuffer::SetWchar(wchar_t value)
749 SysTryReturn(NID_BASE,
750 GetRemaining() >= MCHAR_SIZE, E_OVERFLOW, E_OVERFLOW,
751 "[%s] The remaining bytes of this buffer are smaller than size of wchar_t.", GetErrorMessage(E_OVERFLOW));
753 *reinterpret_cast <wchar_t*>(&__pArrayStart[_position]) = value;
754 _position += MCHAR_SIZE;
760 ByteBuffer::SetMchar(int index, wchar_t value)
762 SysTryReturn(NID_BASE,
763 index <= (_limit - MCHAR_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
764 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of wchar_t(%d)'.",
765 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, MCHAR_SIZE);
767 *reinterpret_cast <wchar_t*>(&__pArrayStart[index]) = value;
773 ByteBuffer::SetWchar(int index, wchar_t value)
775 SysTryReturn(NID_BASE,
776 index <= (_limit - MCHAR_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
777 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of wchar_t(%d)'.",
778 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, MCHAR_SIZE);
780 *reinterpret_cast <wchar_t*>(&__pArrayStart[index]) = value;
786 ByteBuffer::SetShort(short value)
788 SysTryReturn(NID_BASE,
789 GetRemaining() >= SHORT_SIZE, E_OVERFLOW, E_OVERFLOW,
790 "[%s] The remaining bytes of this buffer are smaller than size of short.", GetErrorMessage(E_OVERFLOW));
792 *reinterpret_cast <short*>(&__pArrayStart[_position]) = value;
793 _position += SHORT_SIZE;
799 ByteBuffer::SetShort(int index, short value)
801 SysTryReturn(NID_BASE,
802 index <= (_limit - SHORT_SIZE) && index >= 0, E_OUT_OF_RANGE, E_OUT_OF_RANGE,
803 "[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of short(%d)'.",
804 GetErrorMessage(E_OUT_OF_RANGE), index, _limit, SHORT_SIZE);
806 *reinterpret_cast <short*>(&__pArrayStart[index]) = value;
812 ByteBuffer::SliceN(void) const
814 std::unique_ptr<ByteBuffer> pBuffer(new (std::nothrow) ByteBuffer());
815 pBuffer->_pData = _pData;
817 pBuffer->_capacity = GetRemaining();
818 pBuffer->_limit = pBuffer->_capacity;
819 if (pBuffer->_capacity > 0)
821 pBuffer->__pArrayStart = &__pArrayStart[_position];
824 return pBuffer.release();
828 ByteBuffer::GetPointer(void) const
830 return __pArrayStart;
834 ByteBuffer::Equals(const Tizen::Base::Object& obj) const
837 const ByteBuffer* pOther = dynamic_cast <const ByteBuffer*>(&obj);
842 else if ((pOther == this) || (*pOther == *this))
851 ByteBuffer::GetHashCode(void) const
853 int len = GetRemaining() / sizeof(len);
856 int offset = _position;
857 for (int i = 0; i < len; ++i)
859 hash = (hash << 5) - hash + static_cast <int>(__pArrayStart[offset + (i * sizeof(hash))]);
866 ByteBuffer::GetTypeSize(void) const