//
-// Open Service Platform
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
*
* This header file contains the declarations of the %Buffer classes.
*/
-
#ifndef _FBASE_BUFFER_H_
#define _FBASE_BUFFER_H_
* The following example demonstrates how to use the %Buffer class.
*
* @code
- *
+ *
* #include <FBase.h>
*
* using namespace Tizen::Base;
- *
+ *
* void
* MyClass::BufferSample(void)
* {
* intBuf.Construct(BUFFER_SIZE_MAX);
*
* int intArray[] = {0,1,2,3,4,5,6,7,8,9};
- *
+ *
* // Copies all values from intArray to intBuffer instance
* // position = 10 (num of element copied)
* intBuf.SetArray(intArray, 0, (sizeof(intArray) / sizeof(int)));
* // Flips the buffer: The limit is set to the current position and
* // then the position is set to zero
* intBuf.Flip(); // position = 0, limit = 10
- *
+ *
* // Gets the number of elements between the current position and the limit
* int remaining = intBuf.GetRemaining();
- *
+ *
* // Initializes a doubleBuf with capacity(10) using Construct() method
* DoubleBuffer doubleBuf;
* doubleBuf.Construct(remaining);
- *
+ *
* // Reads and writes elements from the intBuf to the doubleBuf
* for (int i = 0; i < remaining; i++)
* {
* int value;
*
* // Demonstrates relative reading and writing
- *
+ *
* // Reads the value at the current position, and then increments the position
* intBuf.Get(value);
- *
+ *
* // Writes the value * 12.34 at the current position of the doubleBuf
* // and then increment the position
* doubleBuf.Set(value * 12.34);
- *
+ *
* // Now, positions of the intBuf and the doubleBuf have been incremented by one
* }
- *
+ *
* // Flips the doubleBuf
* doubleBuf.Flip();
* // Now, the doubleBuf's position = 0 and limit = 10
- *
+ *
* // Gets the remaining elements of the doubleBuf
* remaining = doubleBuf.GetRemaining();
- *
+ *
* // Gets the second double value with index
* double doubleValue;
* doubleBuf.Get(1, doubleValue); // 12.34
* }
- *
+ *
* @endcode
*/
-template<class Type>
+template< class Type >
class _OSP_EXPORT_ Buffer
: public BufferBase
{
/**
- * Initializes this instance of %Buffer which is a view of the specified buffer. @n
+ * Initializes this instance of %Buffer which is a view of the specified @c buffer. @n
* This is similar to a copy constructor.
*
* @since 2.0
*
- * @param[in] buffer The other %Buffer instance
+ * @param[in] buffer The other %Buffer instance
* @exception E_SUCCESS The method is successful.
* @exception E_INVALID_ARG The specified input parameter is invalid, or
* the source buffer is not constructed.
* @see Buffer()
*/
- result Construct(const Buffer <Type>& buffer)
+ result Construct(const Buffer< Type >& buffer)
{
TryReturn(null != buffer._pData, E_INVALID_ARG, ("[E_INVALID_ARG] The source buffer is not constructed."));
}
/**
- * Initializes this instance of %Buffer with the specified capacity.
+ * Initializes this instance of %Buffer with the specified @c capacity.
*
* @since 2.0
*
* @return An error code
- * @param[in] capacity The number of elements
+ * @param[in] capacity The number of elements
* @exception E_SUCCESS The method is successful.
* @exception E_INVALID_ARG The specified @c capacity is negative.
* @see Buffer()
*
* @since 2.0
*
- * @return An error code
- * @param[in] pBuffer The buffer which is shared
- * @param[in] index The starting index of the buffer from where the first @c byte value is read
- * @param[in] length The number of bytes to read from the given buffer @n This is a limit of this instance.
- * @param[in] capacity The capacity of this instance
- * @exception E_SUCCESS The method is successful.
- * @exception E_INVALID_ARG A specified input parameter is invalid, or
- * the @c pBuffer is @c null.
- * @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
- * the @c index is larger than the @c length.
+ * @return An error code
+ * @param[in] pBuffer The buffer which is shared
+ * @param[in] index The starting index of the buffer from where the first @c byte value is read
+ * @param[in] length The number of bytes to read from the given buffer @n This is a limit of this instance.
+ * @param[in] capacity The capacity of this instance
+ * @exception E_SUCCESS The method is successful.
+ * @exception E_INVALID_ARG A specified input parameter is invalid, or
+ * the @c pBuffer is @c null.
+ * @exception E_OUT_OF_RANGE The specified @c index is outside the bounds of the data structure, or
+ * the @c index is larger than the @c length.
*/
result Construct(const Type* pBuffer, int index, int length, int capacity)
{
TryReturn(pBuffer != null, E_INVALID_ARG, "[E_INVALID_ARG] The pBuffer is null.");
- TryReturn(index >= 0 && length >= 0 && capacity >=0, E_OUT_OF_RANGE,
+ TryReturn(index >= 0 && length >= 0 && capacity >= 0, E_OUT_OF_RANGE,
"[E_OUT_OF_RANGE] index(%d), length(%d) and capacity(%d) MUST be greater than or equal to 0.", index,
length, capacity);
TryReturn(index < capacity && length <= capacity && index + length <= capacity, E_OUT_OF_RANGE,
void* pTemp = null;
int sizeofBufferData = sizeof(_BufferData);
- Type* tempByte = const_cast <Type *> (pBuffer + index);
- __pArrayStart = reinterpret_cast <byte *> (tempByte);
+ Type* tempByte = const_cast< Type* >(pBuffer + index);
+ __pArrayStart = reinterpret_cast< byte* >(tempByte);
pTemp = malloc(sizeofBufferData);
TryReturn(pTemp != null, E_OUT_OF_MEMORY, "[E_OUT_OF_MEMORY]");
memset(pTemp, 0, sizeofBufferData);
- _pData = static_cast <_BufferData*>(pTemp);
+ _pData = static_cast< _BufferData* >(pTemp);
_pData->refCount = 1;
_pData->capacityInByte = capacity * sizeof(Type);
}
/**
- * This subscript operator returns the reference to the element indicated by the given index.
+ * This subscript operator returns the reference to the element indicated by the given @c index.
*
* @since 2.0
*
* @return A reference to the indexed element
* @param[in] index The index of the element @n
- * It must be less than the limit.
+ * It must be less than the limit.
*/
Type& operator [](int index) const
{
* @since 2.0
*
* @return @c true if the buffers being compared are equal, @n
- else @c false
+ * else @c false
* @param[in] buffer The buffer to compare with the current instance of %Buffer
- * @remarks This method returns @c true only if the two buffers have the same number of remaining elements @n
+ * @remarks This method returns @c true only if the two buffers have the same number of remaining elements @n
* and the two sequences of remaining elements are equal (considered independently of their starting positions).
- * @see Equals()
+ * @see Equals()
*/
- bool operator ==(const Buffer <Type>& buffer) const
+ bool operator ==(const Buffer< Type >& buffer) const
{
bool r = true;
if (this == (void*) (&buffer))
* @since 2.0
*
* @return @c true if the buffers are not equal, @n
- else @c false
+ * else @c false
* @param[in] buffer The buffer to compare with the current instance of %Buffer
- * @remarks This method returns @c false only if the two buffers being compared have the same @n
+ * @remarks This method returns @c false only if the two buffers being compared have the same @n
* number of remaining elements and the two sequences of remaining elements are equal @n
* (considered independently of their starting positions).
- * @see Equals()
+ * @see Equals()
*/
- bool operator !=(const Buffer <Type>& buffer) const
+ bool operator !=(const Buffer< Type >& buffer) const
{
return !(*this == buffer);
}
* @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow. @n
* The number of remaining bytes of the current buffer is less than
* the number of remaining bytes of the given buffer.
- * @remarks After the copy operation, the current (destination) buffer's position and the given
+ * @remarks After the copy operation, the current (destination) buffer's position and the given
* (source) buffer's position are incremented by the number of elements copied (the number
* of remaining elements of the given buffer). @n
* If the remaining part of the current instance is not less than the remaining part of the input instance,
* }
* @endcode
*/
- result CopyFrom(Buffer<Type>& buffer)
+ result CopyFrom(Buffer< Type >& buffer)
{
- TryReturn(this != static_cast <void*>(&buffer), E_INVALID_ARG,
+ TryReturn(this != static_cast< void* >(&buffer), E_INVALID_ARG,
"[E_INVALID_ARG] The source and target buffers are identical.");
int copyLength = buffer.GetRemaining();
TryReturn(GetRemaining() >= copyLength, E_OVERFLOW, "[E_OVERFLOW]");
memcpy(__pArrayStart + _position * sizeof(Type), buffer.__pArrayStart + buffer._position * sizeof(Type),
- copyLength * sizeof(Type));
+ copyLength * sizeof(Type));
_position += copyLength;
buffer._position += copyLength;
* @since 2.0
*
* @return An error code
- * @param[out] value The value at the current position
+ * @param[out] value The value at the current position
* @exception E_SUCCESS The method is successful.
* @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow. @n
- * The current position is greater than the limit.
- * @see Set()
+ * The current position is greater than the limit.
+ * @see Set()
*/
result Get(Type& value)
{
}
/**
- * Reads the value at the given index. @n
+ * Reads the value at the given @c index. @n
* Provides a way for absolute indexing and reading.
*
* @since 2.0
*
* @return An error code
* @param[in] index The index into the buffer from where the value is read
- * @param[out] value The value at the given index
+ * @param[out] value The value at the given index
* @exception E_SUCCESS The method is successful.
* @exception E_OUT_OF_RANGE The specified @c index is outside the bounds of the data structure. @n
- * The @c index is greater than the limit or less than @c 0.
- * @see Set()
+ * The @c index is greater than the limit or less than @c 0.
+ * @see Set()
*/
result Get(int index, Type& value) const
{
/**
- * Copies the specified range of values from the calling buffer to the specified destination array as per the given index of the array.
+ * Copies the specified range of values from the calling buffer to the specified destination array as per the given @c index of the array.
*
* @since 2.0
*
* the @c index or length is less than @c 0.
* @exception E_UNDERFLOW The operation (arithmetic/casting/conversion) has caused an underflow. @n
* The remaining elements of this buffer are smaller than @c length.
- * @remarks After the copy operation, the position is incremented by @c length.
+ * @remarks After the copy operation, the position is incremented by @c length.
* @see SetArray()
*/
result GetArray(Type* pArray, int index, int length)
* @since 2.0
*
* @return An error code
- * @param[in] buffer The source buffer from which bytes are read @n
+ * @param[in] buffer The source buffer from where the bytes are read @n
* It must not be this buffer.
- * @exception E_SUCCESS The method is successful.
+ * @exception E_SUCCESS The method is successful.
* @exception E_INVALID_ARG The specified input parameter is invalid. @n
* The given buffer is same as the current buffer instance.
- * @remarks After the copy operation, the current (destination) buffer's position and the given
+ * @remarks After the copy operation, the current (destination) buffer's position and the given
* (source) buffer's position are incremented by the number of elements copied (the smaller value
* between the number of elements remaining in the calling buffer and the source buffer). @n
* If there are more elements remaining in the calling buffer than elements remaining in the input instance,
* this method is equivalent to CopyFrom() method. If there are less remaining elements in the
- * calling buffer, the CopyFrom() method returns E_OVERFLOW and does not transfer
+ * calling buffer, the %CopyFrom() method returns @c E_OVERFLOW and does not transfer
* while this method copies the number of remaining elements of the current instance.
* @see CopyFrom()
*
* }
* @endcode
*/
- result ReadFrom(Buffer<Type>& buffer)
+ result ReadFrom(Buffer< Type >& buffer)
{
- TryReturn(this != static_cast <void*>(&buffer), E_INVALID_ARG,
+ TryReturn(this != static_cast< void* >(&buffer), E_INVALID_ARG,
"[E_INVALID_ARG] The source and target buffers are identical.");
int copyLength = (GetRemaining() < buffer.GetRemaining()) ? GetRemaining() : buffer.GetRemaining();
memcpy(__pArrayStart + _position * sizeof(Type), buffer.__pArrayStart + buffer._position * sizeof(Type),
- copyLength * sizeof(Type));
+ copyLength * sizeof(Type));
_position += copyLength;
buffer._position += copyLength;
/**
- * Writes the specified value into the current buffer instance at the current position,
+ * Writes the specified @c value into the current buffer instance at the current position,
* and then increments the position. @n
* Provides a way for relative indexing and writing.
*
- * @since 2.0
+ * @since 2.0
*
* @return An error code
* @param[in] value The value to write to the calling %Buffer
}
/**
- * Writes the specified value into the current instance of buffer at the given index. @n
+ * Writes the specified @c value into the current instance of buffer at the given @c index. @n
* Provides a way for absolute indexing and writing.
*
* @since 2.0
* @return An error code
* @param[in] index The index at which the value is written
* @param[in] value The value to write
- * @exception E_SUCCESS The method is successful.
+ * @exception E_SUCCESS The method is successful.
* @exception E_OUT_OF_RANGE The specified index is outside the bounds of the data structure, or
* the @c index is not smaller than the limit or less than @c 0.
* @see Get()
* @since 2.0
*
* @return An error code
- * @param[in] pArray A pointer to the array from which values are read
+ * @param[in] pArray A pointer to the array from where the values are read
* @param[in] index The starting index of the array
* @param[in] length The number of values read from the given array
* @exception E_SUCCESS The method is successful.
* the @c index or length is less than @c 0.
* @exception E_OVERFLOW The operation (arithmetic/casting/conversion) has caused an overflow. @n
* The remainder of this buffer is smaller than @c length.
- * @remarks This method copies @c length number of values from the source array,
- * starting from the given index in the array, into the calling
+ * @remarks This method copies @c length number of values from the source array,
+ * starting from the given @c index in the array, into the calling
* buffer, starting at the current position.
* After the copy operation, the position is incremented by @c length.
* @see GetArray()
* @since 2.0
*
* @return A pointer to the new buffer
- * @remarks The content of the new buffer starts at the current position of this instance of %Buffer.
+ * @remarks The content of the new buffer starts at the current position of this instance of %Buffer.
* The new buffer's position is @c 0, its capacity and limit is
* the number of bytes remaining in the current instance of %Buffer,
* and it is marked as undefined.
*/
- Buffer <Type>* SliceN(void) const
+ Buffer< Type >* SliceN(void) const
{
- Buffer <Type>* pBuffer = new Buffer <Type>();
+ Buffer< Type >* pBuffer = new Buffer< Type >();
pBuffer->_pData = _pData;
AddRef();
pBuffer->_capacity = GetRemaining();
* @return @c true if the input equals the calling %Buffer instance, @n
* else @c false
* @param[in] obj The object to compare with the calling %Buffer
- * @remarks This method returns @c true if and only if the specified object is also an instance of %Buffer class,
+ * @remarks This method returns @c true if and only if the specified object is also an instance of %Buffer class,
* the two buffers have the same number of remaining elements, and the two sequences of
* remaining elements are equal (considered independently of their starting positions).
* @see Tizen::Base::BufferBase::GetHashCode()
virtual bool Equals(const Tizen::Base::Object& obj) const
{
bool out = false;
- const Buffer <Type>* other = static_cast <const Buffer <Type>*>(&obj);
+ const Buffer< Type >* other = static_cast< const Buffer< Type >* >(&obj);
if ((other == this) || (*other == *this))
{
out = true;
* @since 2.0
*
* @return The hash value of the current instance
- * @remarks The hash code of a buffer depends only upon its remaining elements.
+ * @remarks The hash code of a buffer depends only upon its remaining elements.
*/
virtual int GetHashCode(void) const
{
int offset = _position * GetTypeSize();
for (int i = 0; i < len; ++i)
{
- hash = (hash<<5) - hash + (int) __pArrayStart[offset + (i * sizeof(int))];
+ hash = (hash << 5) - hash + (int) __pArrayStart[offset + (i * sizeof(int))];
}
return hash;
/**
* This is the copy constructor for this class.
*/
- Buffer(const Buffer <Type>& buffer)
+ Buffer(const Buffer< Type >& buffer)
{
Construct(buffer);
}
/**
* This is the assignment operator.
*/
- Buffer <Type>& operator =(const Buffer <Type>& buffer);
+ Buffer< Type >& operator =(const Buffer< Type >& buffer);
/**
* Returns the size of the type of this buffer.
/**
- * The @c double buffer type.
+ * The @c double buffer type
* @since 2.0
*/
-typedef Buffer <double> DoubleBuffer;
+typedef Buffer< double > DoubleBuffer;
/**
-* The @c float buffer type.
+* The @c float buffer type
* @since 2.0
*/
-typedef Buffer <float> FloatBuffer;
+typedef Buffer< float > FloatBuffer;
/**
-* The @c int buffer type.
+* The @c int buffer type
* @since 2.0
*/
-typedef Buffer <int> IntBuffer;
+typedef Buffer< int > IntBuffer;
/**
-* The @c long buffer type.
+* The @c long buffer type
* @since 2.0
*/
-typedef Buffer <long> LongBuffer;
+typedef Buffer< long > LongBuffer;
/**
-* The @c long @c long buffer type.
+* The @c long @c long buffer type
* @since 2.0
*/
-typedef Buffer <long long> LongLongBuffer;
+typedef Buffer< long long > LongLongBuffer;
/**
-* The @c wchar_t buffer type.
+* The @c wchar_t buffer type
* @since 2.0
*/
-typedef Buffer <wchar_t> WcharBuffer;
+typedef Buffer< wchar_t > WcharBuffer;
/**
-* The @c short buffer type.
+* The @c short buffer type
* @since 2.0
*/
-typedef Buffer <short> ShortBuffer;
+typedef Buffer< short > ShortBuffer;
#ifdef _MSC_VER
-template class _OSP_EXPORT_ Buffer <double>;
-template class _OSP_EXPORT_ Buffer <float>;
-template class _OSP_EXPORT_ Buffer <int>;
-template class _OSP_EXPORT_ Buffer <long>;
-template class _OSP_EXPORT_ Buffer <long long>;
-template class _OSP_EXPORT_ Buffer <wchar_t>;
-template class _OSP_EXPORT_ Buffer <short>;
+template class _OSP_EXPORT_ Buffer< double >;
+template class _OSP_EXPORT_ Buffer< float >;
+template class _OSP_EXPORT_ Buffer< int >;
+template class _OSP_EXPORT_ Buffer< long >;
+template class _OSP_EXPORT_ Buffer< long long >;
+template class _OSP_EXPORT_ Buffer< wchar_t >;
+template class _OSP_EXPORT_ Buffer< short >;
#endif
}} // Tizen::Base