X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=inc%2FFBaseBuffer.h;h=a3476c891622f355ab6619fd3de1d1be44f953bc;hb=refs%2Ftags%2Faccepted%2Ftizen%2Fmobile%2F20140225.041703;hp=d52ce3a8e43a51c95af7210293df1d8e226fb676;hpb=b34ea5f0577dd444b1267fcf33438cf7baf95537;p=platform%2Fframework%2Fnative%2Fappfw.git diff --git a/inc/FBaseBuffer.h b/inc/FBaseBuffer.h index d52ce3a..a3476c8 100644 --- a/inc/FBaseBuffer.h +++ b/inc/FBaseBuffer.h @@ -20,7 +20,6 @@ * * This header file contains the declarations of the %Buffer classes. */ - #ifndef _FBASE_BUFFER_H_ #define _FBASE_BUFFER_H_ @@ -51,11 +50,11 @@ class ByteBuffer; * The following example demonstrates how to use the %Buffer class. * * @code - * + * * #include * * using namespace Tizen::Base; - * + * * void * MyClass::BufferSample(void) * { @@ -67,7 +66,7 @@ class ByteBuffer; * 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))); @@ -75,46 +74,46 @@ class ByteBuffer; * // 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 +template< class Type > class _OSP_EXPORT_ Buffer : public BufferBase { @@ -151,13 +150,13 @@ public: * * @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 & buffer) + result Construct(const Buffer< Type >& buffer) { TryReturn(null != buffer._pData, E_INVALID_ARG, ("[E_INVALID_ARG] The source buffer is not constructed.")); @@ -179,7 +178,7 @@ public: * @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() @@ -194,21 +193,21 @@ public: * * @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 @c 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, @@ -218,14 +217,14 @@ public: void* pTemp = null; int sizeofBufferData = sizeof(_BufferData); - Type* tempByte = const_cast (pBuffer + index); - __pArrayStart = reinterpret_cast (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); @@ -243,7 +242,7 @@ public: * * @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 { @@ -259,13 +258,13 @@ public: * @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 & buffer) const + bool operator ==(const Buffer< Type >& buffer) const { bool r = true; if (this == (void*) (&buffer)) @@ -295,14 +294,14 @@ public: * @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 & buffer) const + bool operator !=(const Buffer< Type >& buffer) const { return !(*this == buffer); } @@ -325,7 +324,7 @@ public: * @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, @@ -383,15 +382,15 @@ public: * } * @endcode */ - result CopyFrom(Buffer& buffer) + result CopyFrom(Buffer< Type >& buffer) { - TryReturn(this != static_cast (&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; @@ -406,11 +405,11 @@ public: * @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) { @@ -428,11 +427,11 @@ public: * * @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 { @@ -461,7 +460,7 @@ public: * 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) @@ -488,10 +487,10 @@ public: * @return An error code * @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, @@ -556,15 +555,15 @@ public: * } * @endcode */ - result ReadFrom(Buffer& buffer) + result ReadFrom(Buffer< Type >& buffer) { - TryReturn(this != static_cast (&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; @@ -578,7 +577,7 @@ public: * 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 @@ -604,7 +603,7 @@ public: * @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() @@ -635,7 +634,7 @@ public: * 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, + * @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. @@ -662,14 +661,14 @@ public: * @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 * SliceN(void) const + Buffer< Type >* SliceN(void) const { - Buffer * pBuffer = new Buffer (); + Buffer< Type >* pBuffer = new Buffer< Type >(); pBuffer->_pData = _pData; AddRef(); pBuffer->_capacity = GetRemaining(); @@ -703,7 +702,7 @@ public: * @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() @@ -711,7 +710,7 @@ public: virtual bool Equals(const Tizen::Base::Object& obj) const { bool out = false; - const Buffer * other = static_cast *>(&obj); + const Buffer< Type >* other = static_cast< const Buffer< Type >* >(&obj); if ((other == this) || (*other == *this)) { out = true; @@ -726,7 +725,7 @@ public: * @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 { @@ -736,7 +735,7 @@ public: 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; @@ -746,7 +745,7 @@ private: /** * This is the copy constructor for this class. */ - Buffer(const Buffer & buffer) + Buffer(const Buffer< Type >& buffer) { Construct(buffer); } @@ -754,7 +753,7 @@ private: /** * This is the assignment operator. */ - Buffer & operator =(const Buffer & buffer); + Buffer< Type >& operator =(const Buffer< Type >& buffer); /** * Returns the size of the type of this buffer. @@ -775,53 +774,53 @@ private: * The @c double buffer type * @since 2.0 */ -typedef Buffer DoubleBuffer; +typedef Buffer< double > DoubleBuffer; /** * The @c float buffer type * @since 2.0 */ -typedef Buffer FloatBuffer; +typedef Buffer< float > FloatBuffer; /** * The @c int buffer type * @since 2.0 */ -typedef Buffer IntBuffer; +typedef Buffer< int > IntBuffer; /** * The @c long buffer type * @since 2.0 */ -typedef Buffer LongBuffer; +typedef Buffer< long > LongBuffer; /** * The @c long @c long buffer type * @since 2.0 */ -typedef Buffer LongLongBuffer; +typedef Buffer< long long > LongLongBuffer; /** * The @c wchar_t buffer type * @since 2.0 */ -typedef Buffer WcharBuffer; +typedef Buffer< wchar_t > WcharBuffer; /** * The @c short buffer type * @since 2.0 */ -typedef Buffer ShortBuffer; +typedef Buffer< short > ShortBuffer; #ifdef _MSC_VER -template class _OSP_EXPORT_ Buffer ; -template class _OSP_EXPORT_ Buffer ; -template class _OSP_EXPORT_ Buffer ; -template class _OSP_EXPORT_ Buffer ; -template class _OSP_EXPORT_ Buffer ; -template class _OSP_EXPORT_ Buffer ; -template class _OSP_EXPORT_ Buffer ; +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