//
-// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
* @file FBaseByteBuffer.cpp
* @brief This is the implementation for ByteBuffer class.
*/
-
#include <new>
#include <FBaseByteBuffer.h>
#include <FBaseSysLog.h>
#include <unique_ptr.h>
-
static const byte DOUBLE_SIZE = sizeof(double);
static const byte FLOAT_SIZE = sizeof(float);
static const byte INT_SIZE = sizeof(int);
}
result
-ByteBuffer::Construct(const byte *pBuffer, int index, int length, int capacity)
+ByteBuffer::Construct(const byte* pBuffer, int index, int length, int capacity)
{
SysTryReturn(NID_BASE, pBuffer != null, E_INVALID_ARG, E_INVALID_ARG, "[%s] The pBuffer is null.",
GetErrorMessage(E_INVALID_ARG));
void* pTemp = null;
int sizeofBufferData = sizeof(_BufferData);
- __pArrayStart = const_cast<byte *> (pBuffer + index);
+ __pArrayStart = const_cast< byte* >(pBuffer + index);
pTemp = malloc(sizeofBufferData);
SysTryReturn(NID_BASE, pTemp != null, E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "[%s]", GetErrorMessage(E_OUT_OF_MEMORY));
memset(pTemp, 0, sizeofBufferData);
- _pData = static_cast <_BufferData*>(pTemp);
+ _pData = static_cast< _BufferData* >(pTemp);
_pData->refCount = 1;
_pData->capacityInByte = capacity;
byte
ByteBuffer::operator [](int index) const
{
- return const_cast<ByteBuffer&>(*this)[index];
+ return const_cast< ByteBuffer& >(*this)[index];
}
bool
DoubleBuffer*
ByteBuffer::AsDoubleBufferN(void) const
{
- std::unique_ptr<DoubleBuffer> pBuffer(new (std::nothrow) DoubleBuffer());
+ std::unique_ptr< DoubleBuffer > pBuffer(new (std::nothrow) DoubleBuffer());
pBuffer->_pData = _pData;
AddRef();
pBuffer->_capacity = GetRemaining() / DOUBLE_SIZE;
FloatBuffer*
ByteBuffer::AsFloatBufferN(void) const
{
- std::unique_ptr<FloatBuffer> pBuffer(new (std::nothrow) FloatBuffer());
+ std::unique_ptr< FloatBuffer > pBuffer(new (std::nothrow) FloatBuffer());
pBuffer->_pData = _pData;
AddRef();
pBuffer->_capacity = GetRemaining() / FLOAT_SIZE;
IntBuffer*
ByteBuffer::AsIntBufferN(void) const
{
- std::unique_ptr<IntBuffer> pBuffer(new (std::nothrow) IntBuffer());
+ std::unique_ptr< IntBuffer > pBuffer(new (std::nothrow) IntBuffer());
pBuffer->_pData = _pData;
AddRef();
pBuffer->_capacity = GetRemaining() / INT_SIZE;
LongBuffer*
ByteBuffer::AsLongBufferN(void) const
{
- std::unique_ptr<LongBuffer> pBuffer(new (std::nothrow) LongBuffer());
+ std::unique_ptr< LongBuffer > pBuffer(new (std::nothrow) LongBuffer());
pBuffer->_pData = _pData;
AddRef();
pBuffer->_capacity = GetRemaining() / LONG_SIZE;
LongLongBuffer*
ByteBuffer::AsLongLongBufferN(void) const
{
- std::unique_ptr<LongLongBuffer> pBuffer(new (std::nothrow) LongLongBuffer());
+ std::unique_ptr< LongLongBuffer > pBuffer(new (std::nothrow) LongLongBuffer());
pBuffer->_pData = _pData;
AddRef();
pBuffer->_capacity = GetRemaining() / LONGLONG_SIZE;
McharBuffer*
ByteBuffer::AsMcharBufferN(void) const
{
- std::unique_ptr<McharBuffer> pBuffer(new (std::nothrow) McharBuffer());
+ std::unique_ptr< McharBuffer > pBuffer(new (std::nothrow) McharBuffer());
pBuffer->_pData = _pData;
AddRef();
pBuffer->_capacity = GetRemaining() / MCHAR_SIZE;
WcharBuffer*
ByteBuffer::AsWcharBufferN(void) const
{
- std::unique_ptr<WcharBuffer> pBuffer(new (std::nothrow) WcharBuffer());
+ std::unique_ptr< WcharBuffer > pBuffer(new (std::nothrow) WcharBuffer());
pBuffer->_pData = _pData;
AddRef();
pBuffer->_capacity = GetRemaining() / MCHAR_SIZE;
ShortBuffer*
ByteBuffer::AsShortBufferN(void) const
{
- std::unique_ptr<ShortBuffer> pBuffer(new (std::nothrow) ShortBuffer());
+ std::unique_ptr< ShortBuffer > pBuffer(new (std::nothrow) ShortBuffer());
pBuffer->_pData = _pData;
AddRef();
pBuffer->_capacity = GetRemaining() / SHORT_SIZE;
result
ByteBuffer::CopyFrom(ByteBuffer& buffer)
{
- SysTryReturn(NID_BASE, this != static_cast <void*>(&buffer), E_INVALID_ARG, E_INVALID_ARG,
+ SysTryReturn(NID_BASE, this != static_cast< void* >(&buffer), E_INVALID_ARG, E_INVALID_ARG,
"[%s] The source and target buffers are identical.", GetErrorMessage(E_INVALID_ARG));
int copyLength = buffer.GetRemaining();
SysTryReturn(NID_BASE,
GetRemaining() >= DOUBLE_SIZE, E_UNDERFLOW, E_UNDERFLOW,
"[%s] The remaining bytes of this buffer are smaller than the size of double", GetErrorMessage(E_UNDERFLOW));
- value = *reinterpret_cast <double*>(&__pArrayStart[_position]);
+ value = *reinterpret_cast< double* >(&__pArrayStart[_position]);
_position += DOUBLE_SIZE;
return E_SUCCESS;
"[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of double(%d)'.",
GetErrorMessage(E_OUT_OF_RANGE), index, _limit, DOUBLE_SIZE);
- value = *reinterpret_cast <double*>(&__pArrayStart[index]);
+ value = *reinterpret_cast< double* >(&__pArrayStart[index]);
return E_SUCCESS;
}
GetRemaining() >= FLOAT_SIZE, E_UNDERFLOW, E_UNDERFLOW,
"[%s] The remaining bytes of this buffer are smaller than the size of float.", GetErrorMessage(E_UNDERFLOW));
- value = *reinterpret_cast <float*>(&__pArrayStart[_position]);
+ value = *reinterpret_cast< float* >(&__pArrayStart[_position]);
_position += FLOAT_SIZE;
return E_SUCCESS;
"[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of float(%d)'.",
GetErrorMessage(E_OUT_OF_RANGE), index, _limit, FLOAT_SIZE);
- value = *reinterpret_cast <float*>(&__pArrayStart[index]);
+ value = *reinterpret_cast< float* >(&__pArrayStart[index]);
return E_SUCCESS;
}
GetRemaining() >= INT_SIZE, E_UNDERFLOW, E_UNDERFLOW,
"[%s] The remaining bytes of this buffer are smaller than the size of int.", GetErrorMessage(E_UNDERFLOW));
- value = *reinterpret_cast <int*>(&__pArrayStart[_position]);
+ value = *reinterpret_cast< int* >(&__pArrayStart[_position]);
_position += INT_SIZE;
return E_SUCCESS;
"[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of int(%d)'.",
GetErrorMessage(E_OUT_OF_RANGE), index, _limit, INT_SIZE);
- value = *reinterpret_cast <int*>(&__pArrayStart[index]);
+ value = *reinterpret_cast< int* >(&__pArrayStart[index]);
return E_SUCCESS;
}
GetRemaining() >= LONG_SIZE, E_UNDERFLOW, E_UNDERFLOW,
"[%s] The remaining bytes of this buffer are smaller than the size of long.", GetErrorMessage(E_UNDERFLOW));
- value = *reinterpret_cast <long*>(&__pArrayStart[_position]);
+ value = *reinterpret_cast< long* >(&__pArrayStart[_position]);
_position += LONG_SIZE;
return E_SUCCESS;
"[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of long(%d)'.",
GetErrorMessage(E_OUT_OF_RANGE), index, _limit, LONG_SIZE);
- value = *reinterpret_cast <long*>(&__pArrayStart[index]);
+ value = *reinterpret_cast< long* >(&__pArrayStart[index]);
return E_SUCCESS;
}
GetRemaining() >= LONGLONG_SIZE, E_UNDERFLOW, E_UNDERFLOW,
"[%s] The remaining bytes of this buffer are smaller than the size of long long.", GetErrorMessage(E_UNDERFLOW));
- value = *reinterpret_cast <long long*>(&__pArrayStart[_position]);
+ value = *reinterpret_cast< long long* >(&__pArrayStart[_position]);
_position += LONGLONG_SIZE;
return E_SUCCESS;
"[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of long long(%d)'.",
GetErrorMessage(E_OUT_OF_RANGE), index, _limit, LONGLONG_SIZE);
- value = *reinterpret_cast <long long*>(&__pArrayStart[index]);
+ value = *reinterpret_cast< long long* >(&__pArrayStart[index]);
return E_SUCCESS;
}
GetRemaining() >= MCHAR_SIZE, E_UNDERFLOW, E_UNDERFLOW,
"[%s] The remaining bytes of this buffer are smaller than the size of wchar_t.", GetErrorMessage(E_UNDERFLOW));
- value = *reinterpret_cast <wchar_t*>(&__pArrayStart[_position]);
+ value = *reinterpret_cast< wchar_t* >(&__pArrayStart[_position]);
_position += MCHAR_SIZE;
return E_SUCCESS;
GetRemaining() >= MCHAR_SIZE, E_UNDERFLOW, E_UNDERFLOW,
"[%s] The remaining bytes of this buffer are smaller than the size of wchar_t.", GetErrorMessage(E_UNDERFLOW));
- value = *reinterpret_cast <wchar_t*>(&__pArrayStart[_position]);
+ value = *reinterpret_cast< wchar_t* >(&__pArrayStart[_position]);
_position += MCHAR_SIZE;
return E_SUCCESS;
"[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of wchar_t(%d)'.",
GetErrorMessage(E_OUT_OF_RANGE), index, _limit, MCHAR_SIZE);
- value = *reinterpret_cast <wchar_t*>(&__pArrayStart[index]);
+ value = *reinterpret_cast< wchar_t* >(&__pArrayStart[index]);
return E_SUCCESS;
}
"[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of wchar_t(%d)'.",
GetErrorMessage(E_OUT_OF_RANGE), index, _limit, MCHAR_SIZE);
- value = *reinterpret_cast <wchar_t*>(&__pArrayStart[index]);
+ value = *reinterpret_cast< wchar_t* >(&__pArrayStart[index]);
return E_SUCCESS;
}
GetRemaining() >= SHORT_SIZE, E_UNDERFLOW, E_UNDERFLOW,
"[%s] The remaining bytes of this buffer are smaller than the size of short.", GetErrorMessage(E_UNDERFLOW));
- value = *reinterpret_cast <short*>(&__pArrayStart[_position]);
+ value = *reinterpret_cast< short* >(&__pArrayStart[_position]);
_position += SHORT_SIZE;
return E_SUCCESS;
"[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of short(%d)'.",
GetErrorMessage(E_OUT_OF_RANGE), index, _limit, SHORT_SIZE);
- value = *reinterpret_cast <short*>(&__pArrayStart[index]);
+ value = *reinterpret_cast< short* >(&__pArrayStart[index]);
return E_SUCCESS;
}
result
ByteBuffer::ReadFrom(ByteBuffer& buffer)
{
- SysTryReturn(NID_BASE, this != static_cast <void*>(&buffer), E_INVALID_ARG, E_INVALID_ARG,
+ SysTryReturn(NID_BASE, this != static_cast< void* >(&buffer), E_INVALID_ARG, E_INVALID_ARG,
"[%s] The source and target buffers are identical.", GetErrorMessage(E_INVALID_ARG));
int copyLength = (GetRemaining() < buffer.GetRemaining()) ? GetRemaining() : buffer.GetRemaining();
GetRemaining() >= DOUBLE_SIZE, E_OVERFLOW, E_OVERFLOW,
"[%s] The remaining bytes of this buffer are smaller than size of double.", GetErrorMessage(E_OVERFLOW));
- *reinterpret_cast <double*>(&__pArrayStart[_position]) = value;
+ *reinterpret_cast< double* >(&__pArrayStart[_position]) = value;
_position += DOUBLE_SIZE;
return E_SUCCESS;
"[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of double(%d)'.",
GetErrorMessage(E_OUT_OF_RANGE), index, _limit, DOUBLE_SIZE);
- *reinterpret_cast <double*>(&__pArrayStart[index]) = value;
+ *reinterpret_cast< double* >(&__pArrayStart[index]) = value;
return E_SUCCESS;
}
GetRemaining() >= FLOAT_SIZE, E_OVERFLOW, E_OVERFLOW,
"[%s] The remaining bytes of this buffer are smaller than size of float.", GetErrorMessage(E_OVERFLOW));
- *reinterpret_cast <float*>(&__pArrayStart[_position]) = value;
+ *reinterpret_cast< float* >(&__pArrayStart[_position]) = value;
_position += FLOAT_SIZE;
return E_SUCCESS;
"[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of float(%d)'.",
GetErrorMessage(E_OUT_OF_RANGE), index, _limit, FLOAT_SIZE);
- *reinterpret_cast <float*>(&__pArrayStart[index]) = value;
+ *reinterpret_cast< float* >(&__pArrayStart[index]) = value;
return E_SUCCESS;
}
GetRemaining() >= INT_SIZE, E_OVERFLOW, E_OVERFLOW,
"[%s] The remaining bytes of this buffer are smaller than size of int.", GetErrorMessage(E_OVERFLOW));
- *reinterpret_cast <int*>(&__pArrayStart[_position]) = value;
+ *reinterpret_cast< int* >(&__pArrayStart[_position]) = value;
_position += INT_SIZE;
return E_SUCCESS;
"[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of int(%d)'.",
GetErrorMessage(E_OUT_OF_RANGE), index, _limit, INT_SIZE);
- *reinterpret_cast <int*>(&__pArrayStart[index]) = value;
+ *reinterpret_cast< int* >(&__pArrayStart[index]) = value;
return E_SUCCESS;
}
GetRemaining() >= LONG_SIZE, E_OVERFLOW, E_OVERFLOW,
"[%s] The remaining bytes of this buffer are smaller than size of long.", GetErrorMessage(E_OVERFLOW));
- *reinterpret_cast <long*>(&__pArrayStart[_position]) = value;
+ *reinterpret_cast< long* >(&__pArrayStart[_position]) = value;
_position += LONG_SIZE;
return E_SUCCESS;
"[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of long(%d)'.",
GetErrorMessage(E_OUT_OF_RANGE), index, _limit, LONG_SIZE);
- *reinterpret_cast <long*>(&__pArrayStart[index]) = value;
+ *reinterpret_cast< long* >(&__pArrayStart[index]) = value;
return E_SUCCESS;
}
GetRemaining() >= LONGLONG_SIZE, E_OVERFLOW, E_OVERFLOW,
"[%s] The remaining bytes of this buffer are smaller than size of long long.", GetErrorMessage(E_OVERFLOW));
- *reinterpret_cast <long long*>(&__pArrayStart[_position]) = value;
+ *reinterpret_cast< long long* >(&__pArrayStart[_position]) = value;
_position += LONGLONG_SIZE;
return E_SUCCESS;
"[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of long long(%d)'.",
GetErrorMessage(E_OUT_OF_RANGE), index, _limit, LONGLONG_SIZE);
- *reinterpret_cast <long long*>(&__pArrayStart[index]) = value;
+ *reinterpret_cast< long long* >(&__pArrayStart[index]) = value;
return E_SUCCESS;
}
GetRemaining() >= MCHAR_SIZE, E_OVERFLOW, E_OVERFLOW,
"[%s] The remaining bytes of this buffer are smaller than size of wchar_t.", GetErrorMessage(E_OVERFLOW));
- *reinterpret_cast <wchar_t*>(&__pArrayStart[_position]) = value;
+ *reinterpret_cast< wchar_t* >(&__pArrayStart[_position]) = value;
_position += MCHAR_SIZE;
return E_SUCCESS;
GetRemaining() >= MCHAR_SIZE, E_OVERFLOW, E_OVERFLOW,
"[%s] The remaining bytes of this buffer are smaller than size of wchar_t.", GetErrorMessage(E_OVERFLOW));
- *reinterpret_cast <wchar_t*>(&__pArrayStart[_position]) = value;
+ *reinterpret_cast< wchar_t* >(&__pArrayStart[_position]) = value;
_position += MCHAR_SIZE;
return E_SUCCESS;
"[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of wchar_t(%d)'.",
GetErrorMessage(E_OUT_OF_RANGE), index, _limit, MCHAR_SIZE);
- *reinterpret_cast <wchar_t*>(&__pArrayStart[index]) = value;
+ *reinterpret_cast< wchar_t* >(&__pArrayStart[index]) = value;
return E_SUCCESS;
}
"[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of wchar_t(%d)'.",
GetErrorMessage(E_OUT_OF_RANGE), index, _limit, MCHAR_SIZE);
- *reinterpret_cast <wchar_t*>(&__pArrayStart[index]) = value;
+ *reinterpret_cast< wchar_t* >(&__pArrayStart[index]) = value;
return E_SUCCESS;
}
GetRemaining() >= SHORT_SIZE, E_OVERFLOW, E_OVERFLOW,
"[%s] The remaining bytes of this buffer are smaller than size of short.", GetErrorMessage(E_OVERFLOW));
- *reinterpret_cast <short*>(&__pArrayStart[_position]) = value;
+ *reinterpret_cast< short* >(&__pArrayStart[_position]) = value;
_position += SHORT_SIZE;
return E_SUCCESS;
"[%s] The index(%d) MUST be greater than or equal to 0, and less then the 'current limit(%d) - size of short(%d)'.",
GetErrorMessage(E_OUT_OF_RANGE), index, _limit, SHORT_SIZE);
- *reinterpret_cast <short*>(&__pArrayStart[index]) = value;
+ *reinterpret_cast< short* >(&__pArrayStart[index]) = value;
return E_SUCCESS;
}
ByteBuffer*
ByteBuffer::SliceN(void) const
{
- std::unique_ptr<ByteBuffer> pBuffer(new (std::nothrow) ByteBuffer());
+ std::unique_ptr< ByteBuffer > pBuffer(new (std::nothrow) ByteBuffer());
pBuffer->_pData = _pData;
AddRef();
pBuffer->_capacity = GetRemaining();
ByteBuffer::Equals(const Tizen::Base::Object& obj) const
{
bool out = false;
- const ByteBuffer* pOther = dynamic_cast <const ByteBuffer*>(&obj);
+ const ByteBuffer* pOther = dynamic_cast< const ByteBuffer* >(&obj);
if (pOther == null)
{
out = false;
int offset = _position;
for (int i = 0; i < len; ++i)
{
- hash = (hash << 5) - hash + static_cast <int>(__pArrayStart[offset + (i * sizeof(hash))]);
+ hash = (hash << 5) - hash + static_cast< int >(__pArrayStart[offset + (i * sizeof(hash))]);
}
return hash;