X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=dali%2Fpublic-api%2Fcommon%2Fdali-vector.h;h=98fae3873cd9af9dc552c50d2cd619f303633f8f;hb=25c7ca5bc0a79e7aae41afec7796b8f9b0886e61;hp=30857f7466485e590ffaec935e6c865cd6201983;hpb=1ce3d69e13024fe8724b9c7231a3dfa724c154fc;p=platform%2Fcore%2Fuifw%2Fdali-core.git diff --git a/dali/public-api/common/dali-vector.h b/dali/public-api/common/dali-vector.h old mode 100644 new mode 100755 index 30857f7..98fae38 --- a/dali/public-api/common/dali-vector.h +++ b/dali/public-api/common/dali-vector.h @@ -1,8 +1,8 @@ -#ifndef __DALI_VECTOR_H__ -#define __DALI_VECTOR_H__ +#ifndef DALI_VECTOR_H +#define DALI_VECTOR_H /* - * Copyright (c) 2015 Samsung Electronics Co., Ltd. + * Copyright (c) 2019 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -21,6 +21,7 @@ // EXTERNAL INCLUDES #include #include +#include // uint32_t // INTERNAL INCLUDES #include @@ -28,9 +29,9 @@ #include /** - * @brief For DALi internal use asserts are enabled in debug builds. + * @brief For DALi internal use, asserts are enabled in debug builds. * - * For Application use asserts can be enabled manually. + * For Application use, asserts can be enabled manually. * @SINCE_1_0.0 */ #if defined( DEBUG_ENABLED ) @@ -58,7 +59,7 @@ namespace Dali * beginning of the first real item so that iterating the items is quick. * @SINCE_1_0.0 */ -class DALI_IMPORT_API VectorBase +class DALI_CORE_API VectorBase { public: // Typedefs @@ -76,7 +77,7 @@ protected: // Construction * @brief Destructor. * * Does not release the space. Derived class needs to call Release. - * Not virtual as should not be called directly and we do not want + * Not virtual as this should not be called directly and we do not want * a vtable for this class as it would unnecessarily increase size. * @SINCE_1_0.0 */ @@ -85,10 +86,10 @@ protected: // Construction public: // API /** - * @brief This method is inlined as its needed frequently for Vector::End() iterator. + * @brief This method is inlined as it's needed frequently for Vector::End() iterator. * * @SINCE_1_0.0 - * @return The count of elements in this vector. + * @return The count of elements in this vector */ SizeType Count() const { @@ -104,7 +105,7 @@ public: // API /** * @brief Gets the count of elements in this vector. * @SINCE_1_0.0 - * @return The count of elements in this vector. + * @return The count of elements in this vector */ SizeType Size() const { @@ -112,8 +113,9 @@ public: // API } /** - * @brief @ return If the vector is empty + * @brief @ return if the vector is empty. * @SINCE_1_0.0 + * @return True if the count of elements is empty */ bool Empty() const { @@ -123,12 +125,12 @@ public: // API /** * @brief Gets the capacity of this vector. * @SINCE_1_0.0 - * @return The capacity of this vector. + * @return The capacity of this vector */ SizeType Capacity() const; /** - * @brief Release the data. + * @brief Releases the data. * * Does not call destructors on objects held. * @SINCE_1_0.0 @@ -141,16 +143,16 @@ protected: // for Derived classes * @brief Helper to set the count. * * @SINCE_1_0.0 - * @param[in] count Number of elements in the vector. + * @param[in] count Number of elements in the vector */ void SetCount( SizeType count ); /** - * @brief Reserve space in the vector. + * @brief Reserves space in the vector. * * @SINCE_1_0.0 - * @param[in] count Count of elements to reserve. - * @param[in] elementSize Size of a single element. + * @param[in] count Count of elements to reserve + * @param[in] elementSize Size of a single element */ void Reserve( SizeType count, SizeType elementSize ); @@ -158,39 +160,39 @@ protected: // for Derived classes * @brief Copy a vector. * * @SINCE_1_0.0 - * @param[in] vector Vector to copy from. - * @param[in] elementSize Size of a single element. + * @param[in] vector Vector to copy from + * @param[in] elementSize Size of a single element */ void Copy( const VectorBase& vector, SizeType elementSize ); /** - * @brief Swap the contents of two vectors. + * @brief Swaps the contents of two vectors. * * @SINCE_1_0.0 - * @param[in] vector Vector to swap with. + * @param[in] vector Vector to swap with */ void Swap( VectorBase& vector ); /** - * @brief Erase an element. + * @brief Erases an element. * * Does not change capacity. * @SINCE_1_0.0 - * @param[in] address Adress to erase from. - * @param[in] elementSize Size to erase. + * @param[in] address Address to erase from + * @param[in] elementSize Size to erase * @pre Last element cannot be erased as there is nothing to move. */ void Erase( char* address, SizeType elementSize ); /** - * @brief Erase a range of elements. + * @brief Erases a range of elements. * * Does not change capacity. * @SINCE_1_0.0 - * @param[in] first Address to the first element to be erased. - * @param[in] last Address to the last element to be erased. - * @param[in] elementSize Size of one of the elements to be erased. - * @return Address pointing to the next element of the last one. + * @param[in] first Address to the first element to be erased + * @param[in] last Address to the last element to be erased + * @param[in] elementSize Size of one of the elements to be erased + * @return Address pointing to the next element of the last one */ char* Erase( char* first, char* last, SizeType elementSize ); @@ -200,15 +202,15 @@ protected: // for Derived classes * \e source and \e destination must not overlap. * * @SINCE_1_0.0 - * @param[in] destination Pointer to the destination address. - * @param[in] source Pointer to the source address. - * @param[in] numberOfBytes The number of bytes to be copied. + * @param[in] destination Pointer to the destination address + * @param[in] source Pointer to the source address + * @param[in] numberOfBytes The number of bytes to be copied */ void CopyMemory( char* destination, const char* source, size_t numberOfBytes ); private: - // not copiable as it does not know the size of elements + // not copyable as it does not know the size of elements VectorBase( const VectorBase& ); ///< Undefined @SINCE_1_0.0 VectorBase& operator=( const VectorBase& ); ///< Undefined @SINCE_1_0.0 @@ -218,6 +220,7 @@ protected: // Data }; +/// @cond internal /** * @brief Vector algorithm variant for trivial types. * @@ -249,8 +252,8 @@ protected: // API for deriving classes * @brief Copy vector contents. * * @SINCE_1_0.0 - * @param[in] rhs VectorBase object to copy from. - * @param[in] elementSize Size of the content. + * @param[in] rhs VectorBase object to copy from + * @param[in] elementSize Size of the content */ void Copy( const VectorBase& rhs, SizeType elementSize ) { @@ -265,11 +268,11 @@ protected: // API for deriving classes } /** - * @brief Reserve space in the vector. + * @brief Reserves space in the vector. * * @SINCE_1_0.0 - * @param[in] count Count of elements to reserve. - * @param[in] elementSize Size of a single element. + * @param[in] count Count of elements to reserve + * @param[in] elementSize Size of a single element */ void Reserve( SizeType count, SizeType elementSize ) { @@ -277,11 +280,11 @@ protected: // API for deriving classes } /** - * @brief Resize the vector. Does not change capacity. + * @brief Resizes the vector. Does not change capacity. * * @SINCE_1_0.0 - * @param[in] count Count to resize to. - * @param[in] elementSize Size of a single element. + * @param[in] count Count to resize to + * @param[in] elementSize Size of a single element */ void Resize( SizeType count, SizeType elementSize ) { @@ -290,9 +293,9 @@ protected: // API for deriving classes } /** - * @brief Clear the contents. + * @brief Clears the contents. * - * For simple types nothing to do. + * For simple types, nothing to do. * @SINCE_1_0.0 */ void Clear() @@ -304,7 +307,7 @@ protected: // API for deriving classes } /** - * @brief Release the vector. + * @brief Releases the vector. * @SINCE_1_0.0 */ void Release() @@ -313,41 +316,41 @@ protected: // API for deriving classes } /** - * @brief Erase an element. Does not change capacity. + * @brief Erases an element. Does not change capacity. * * @SINCE_1_0.0 - * @param[in] address Address to erase from. - * @param[in] elementSize Size to erase. + * @param[in] address Address to erase from + * @param[in] elementSize Size to erase */ - void Erase( char* address, SizeType elementSize ) + void Erase( uint8_t* address, SizeType elementSize ) { - VectorBase::Erase( address, elementSize ); + VectorBase::Erase( reinterpret_cast< char* >( address ), elementSize ); } /** - * @brief Erase a range of elements. Does not change capacity. + * @brief Erases a range of elements. Does not change capacity. * * @SINCE_1_0.0 - * @param[in] first Address to the first element to be erased. - * @param[in] last Address to the last element to be erased. - * @param[in] elementSize Size of one of the elements to be erased. - * @return Address pointing to the next element of the last one. + * @param[in] first Address to the first element to be erased + * @param[in] last Address to the last element to be erased + * @param[in] elementSize Size of one of the elements to be erased + * @return Address pointing to the next element of the last one */ - char* Erase( char* first, char* last, SizeType elementSize ) + uint8_t* Erase( uint8_t* first, uint8_t* last, SizeType elementSize ) { - return VectorBase::Erase( first, last, elementSize ); + return reinterpret_cast< uint8_t* >( VectorBase::Erase( reinterpret_cast< char* >( first ), reinterpret_cast< char *>( last ), elementSize ) ); } /** * @brief Inserts the given elements into the vector. * * @SINCE_1_0.0 - * @param[in] at Address where to insert the elements into the vector. - * @param[in] from Address to the first element to be inserted. - * @param[in] to Address to the last element to be inserted. - * @param[in] elementSize Size of one of the elements to be inserted. + * @param[in] at Address where to insert the elements into the vector + * @param[in] from Address to the first element to be inserted + * @param[in] to Address to the last element to be inserted + * @param[in] elementSize Size of one of the elements to be inserted */ - void Insert( char* at, char* from, char* to, SizeType elementSize ) + void Insert( uint8_t* at, uint8_t* from, uint8_t* to, SizeType elementSize ) { const SizeType size = to - from; const SizeType count = Count(); @@ -356,27 +359,29 @@ protected: // API for deriving classes if( newCount > Capacity() ) { // Calculate the at offset as the pointer is invalid after the Reserve() call. - std::size_t offset = at - reinterpret_cast( mData ); + std::size_t offset = at - reinterpret_cast( mData ); // need more space - Reserve( NextPowerOfTwo( newCount ), elementSize ); // reserve enough space to store at least the next power of two elements of the new required size. + Reserve( NextPowerOfTwo( static_cast( newCount ) ), elementSize ); // reserve enough space to store at least the next power of two elements of the new required size. // Set the new at pointer. - at = reinterpret_cast( mData ) + offset; + at = reinterpret_cast( mData ) + offset; } // set new count first as otherwise the debug assert will hit us SetCount( newCount ); // Move current items to a new position inside the vector. - CopyMemory( at + size, - at, - ( reinterpret_cast( mData ) + count * elementSize ) - at ); + CopyMemory( reinterpret_cast< char* >( at + size ), + reinterpret_cast< const char* >( at ), + ( reinterpret_cast( mData ) + count * elementSize ) - at ); // Copy the given items. - CopyMemory( at, from, size ); + CopyMemory( reinterpret_cast< char* >( at ), reinterpret_cast< const char* >( from ), size ); } }; +/// @endcond +/// @cond internal /** * @brief Vector algorithm variant for complex types. * @@ -394,12 +399,13 @@ private: ~VectorAlgorithms() { } }; +/// @endcond /** - * @brief Vector class with minimum space allocation when its empty. + * @brief Vector class with minimum space allocation when it's empty. * * @SINCE_1_0.0 - * @param type of the data that the vector holds. + * @param type The type of the data that the vector holds */ template< class T, bool IsTrivialType = TypeTraits::IS_TRIVIAL_TYPE == true > class Vector : public VectorAlgorithms< IsTrivialType > @@ -415,9 +421,13 @@ public: // API typedef const T* ConstIterator; ///< Const iterator @SINCE_1_0.0 typedef T ItemType; ///< Item type @SINCE_1_0.0 + /** + * @brief Enumeration for BaseType. + * @SINCE_1_0.0 + */ enum { - BaseType = IsTrivialType + BaseType = IsTrivialType ///< @SINCE_1_0.0 }; /** @@ -440,7 +450,7 @@ public: // API * @brief Copy constructor. * * @SINCE_1_0.0 - * @param[in] vector Vector to copy from. + * @param[in] vector Vector to copy from */ Vector( const Vector& vector ) { @@ -452,8 +462,8 @@ public: // API * @brief Assignment operator. * * @SINCE_1_0.0 - * @param[in] vector Vector to assign from. - * @return Reference to self for chaining. + * @param[in] vector Vector to assign from + * @return Reference to self for chaining */ Vector& operator=( const Vector& vector ) { @@ -467,7 +477,7 @@ public: // API /** * @brief Iterator to the beginning of the data. * @SINCE_1_0.0 - * @return Iterator to the beginning of the data. + * @return Iterator to the beginning of the data */ Iterator Begin() const { @@ -478,7 +488,7 @@ public: // API /** * @brief Iterator to the end of the data (one past last element). * @SINCE_1_0.0 - * @return Iterator to the end of the data (one past last element). + * @return Iterator to the end of the data (one past last element) */ Iterator End() const { @@ -488,10 +498,30 @@ public: // API } /** + * Support for C++11 Range-based for loop: for( item : container ). + * @SINCE_1_2.60 + * @return The start iterator + */ + Iterator begin() const + { + return Begin(); + } + + /** + * Support for C++11 Range-based for loop: for( item : container ). + * @SINCE_1_2.60 + * @return The end iterator + */ + Iterator end() const + { + return End(); + } + + /** * @brief Subscript operator. * @SINCE_1_0.0 - * @param[in] index Index of the element. - * @return Reference to the element for given index. + * @param[in] index Index of the element + * @return Reference to the element for given index * @pre Index must be in the vector's range. */ ItemType& operator[]( SizeType index ) @@ -503,9 +533,9 @@ public: // API /** * @brief Subscript operator. * @SINCE_1_0.0 - * @param[in] index of the element. - * @return reference to the element for given index. - * @pre index must be in the vector's range. + * @param[in] index Index of the element + * @return Reference to the element for given index + * @pre Index must be in the vector's range. */ const ItemType& operator[]( SizeType index ) const { @@ -517,14 +547,14 @@ public: // API } /** - * @brief Push back an element to the vector. + * @brief Pushes back an element to the vector. * * The underlying storage may be reallocated to provide space. * If this occurs, all pre-existing pointers into the vector will * become invalid. * * @SINCE_1_0.0 - * @param[in] element Element to be added. + * @param[in] element Element to be added */ void PushBack( const ItemType& element ) { @@ -542,7 +572,7 @@ public: // API } /** - *@brief Insert an element to the vector. + * @brief Inserts an element to the vector. * * Elements after \e at are moved one position to the right. * @@ -550,18 +580,17 @@ public: // API * If this occurs, all pre-existing pointers into the vector will * become invalid. * + * @SINCE_1_0.0 + * @param[in] at Iterator where to insert the elements into the vector + * @param[in] element An element to be added * @pre Iterator at must be in the vector's range ( Vector::Begin(), Vector::End() ). - * - * @param[in] at Iterator where to insert the elements into the vector. - * @param[in] element An element to be added. - *@SINCE_1_0.0 */ void Insert( Iterator at, const ItemType& element ) { DALI_ASSERT_VECTOR( ( at <= End() ) && ( at >= Begin() ) && "Iterator not inside vector" ); const SizeType size = sizeof( ItemType ); - char* address = const_cast( reinterpret_cast( &element ) ); - VectorAlgorithms::Insert( reinterpret_cast< char* >( at ), + uint8_t* address = const_cast( reinterpret_cast( &element ) ); + VectorAlgorithms::Insert( reinterpret_cast< uint8_t* >( at ), address, address + size, size ); @@ -577,9 +606,9 @@ public: // API * become invalid. * * @SINCE_1_0.0 - * @param[in] at Iterator where to insert the elements into the vector. - * @param[in] from Iterator to the first element to be inserted. - * @param[in] to Iterator to the last element to be inserted. + * @param[in] at Iterator where to insert the elements into the vector + * @param[in] from Iterator to the first element to be inserted + * @param[in] to Iterator to the last element to be inserted * @pre Iterator \e at must be in the vector's range ( Vector::Begin(), Vector::End() ). * @pre Iterators \e from and \e to must be valid iterators. * @pre Iterator \e from must not be grater than Iterator \e to. @@ -596,18 +625,18 @@ public: // API return; } - VectorAlgorithms::Insert( reinterpret_cast< char* >( at ), - reinterpret_cast< char* >( from ), - reinterpret_cast< char* >( to ), + VectorAlgorithms::Insert( reinterpret_cast< uint8_t* >( at ), + reinterpret_cast< uint8_t* >( from ), + reinterpret_cast< uint8_t* >( to ), sizeof( ItemType ) ); } /** - * @brief Reserve space in the vector. + * @brief Reserves space in the vector. * * Reserving less than current Capacity is a no-op. * @SINCE_1_0.0 - * @param[in] count Count of elements to reserve. + * @param[in] count Count of elements to reserve */ void Reserve( SizeType count ) { @@ -615,10 +644,10 @@ public: // API } /** - * @brief Resize the vector. Does not change capacity. + * @brief Resizes the vector. Does not change capacity. * * @SINCE_1_0.0 - * @param[in] count Count to resize to. + * @param[in] count Count to resize to */ void Resize( SizeType count ) { @@ -627,11 +656,11 @@ public: // API } /** - * @brief Resize the vector. Does not change capacity. + * @brief Resizes the vector. Does not change capacity. * * @SINCE_1_0.0 - * @param[in] count Count to resize to. - * @param[in] item An item to insert to the new indices. + * @param[in] count Count to resize to + * @param[in] item An item to insert to the new indices */ void Resize( SizeType count, const ItemType& item ) { @@ -654,13 +683,13 @@ public: // API } /** - * @brief Erase an element. + * @brief Erases an element. * * Does not change capacity. Other elements get moved. * * @SINCE_1_0.0 - * @param[in] iterator Iterator pointing to item to remove. - * @return Iterator pointing to next element. + * @param[in] iterator Iterator pointing to the item to remove + * @return Iterator pointing to next element * @pre Iterator \e iterator must be within the vector's range ( Vector::Begin(), Vector::End() - 1 ). * */ @@ -669,7 +698,7 @@ public: // API DALI_ASSERT_VECTOR( (iterator < End()) && (iterator >= Begin()) && "Iterator not inside vector" ); if( iterator < ( End() - 1u ) ) { - VectorAlgorithms::Erase( reinterpret_cast< char* >( iterator ), sizeof( ItemType ) ); + VectorAlgorithms::Erase( reinterpret_cast< uint8_t* >( iterator ), sizeof( ItemType ) ); } else { @@ -680,15 +709,15 @@ public: // API } /** - * @brief Erase a range of elements. + * @brief Erases a range of elements. * * Does not change capacity. Other elements get moved. * * @SINCE_1_0.0 - * @param[in] first Iterator to the first element to be erased. - * @param[in] last Iterator to the last element to be erased. + * @param[in] first Iterator to the first element to be erased + * @param[in] last Iterator to the last element to be erased * - * @return Iterator pointing to the next element of the last one. + * @return Iterator pointing to the next element of the last one * @pre Iterator \e first must be in the vector's range ( Vector::Begin(), Vector::End() ). * @pre Iterator \e last must be in the vector's range ( Vector::Begin(), Vector::End() ). * @pre Iterator \e first must not be grater than Iterator \e last. @@ -710,8 +739,8 @@ public: // API } else { - nextElement = reinterpret_cast( VectorAlgorithms::Erase( reinterpret_cast< char* >( first ), - reinterpret_cast< char* >( last ), + nextElement = reinterpret_cast( VectorAlgorithms::Erase( reinterpret_cast< uint8_t* >( first ), + reinterpret_cast< uint8_t* >( last ), sizeof( ItemType ) ) ); } @@ -721,12 +750,12 @@ public: // API /** * @brief Removes an element. * - * Does not maintain order. Swaps the element with end and + * Does not maintain order. Swaps the element with end and * decreases size by one. This is much faster than Erase so use * this in case order does not matter. Does not change capacity. * * @SINCE_1_0.0 - * @param[in] iterator Iterator pointing to item to remove. + * @param[in] iterator Iterator pointing to the item to remove * @pre Iterator \e iterator must be in the vector's range ( Vector::Begin(), Vector::End() - 1 ). * */ @@ -743,10 +772,10 @@ public: // API } /** - * @brief Swap the contents of two vectors. + * @brief Swaps the contents of two vectors. * * @SINCE_1_0.0 - * @param[in] vector Vector to swap with. + * @param[in] vector Vector to swap with */ void Swap( Vector& vector ) { @@ -754,7 +783,7 @@ public: // API } /** - * @brief Clear the contents of the vector. Keeps its capacity. + * @brief Clears the contents of the vector. Keeps its capacity. * @SINCE_1_0.0 */ void Clear() @@ -763,7 +792,7 @@ public: // API } /** - * @brief Release the memory that the vector holds. + * @brief Releases the memory that the vector holds. * @SINCE_1_0.0 */ void Release() @@ -777,4 +806,4 @@ public: // API */ } // namespace Dali -#endif /* __DALI_VECTOR_H__ */ +#endif // DALI_VECTOR_H