Merge "Add Integration API to Create public event type" into devel/master
[platform/core/uifw/dali-core.git] / dali / public-api / common / dali-vector.h
1 #ifndef DALI_VECTOR_H
2 #define DALI_VECTOR_H
3
4 /*
5  * Copyright (c) 2020 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <cstddef>
23 #include <algorithm>
24 #include <cstdint> // uint32_t
25
26 // INTERNAL INCLUDES
27 #include <dali/public-api/common/dali-common.h>
28 #include <dali/public-api/common/type-traits.h>
29 #include <dali/public-api/math/math-utils.h>
30
31 /**
32  * @brief For DALi internal use, asserts are enabled in debug builds.
33  *
34  * For Application use, asserts can be enabled manually.
35  * @SINCE_1_0.0
36  */
37 #if defined( DEBUG_ENABLED )
38 #define ENABLE_VECTOR_ASSERTS
39 #endif
40
41 #if defined( ENABLE_VECTOR_ASSERTS )
42 #define DALI_ASSERT_VECTOR(cond) DALI_ASSERT_ALWAYS(cond)
43 #else
44 #define DALI_ASSERT_VECTOR(cond)
45 #endif
46
47 namespace Dali
48 {
49 /**
50  * @addtogroup dali_core_common
51  * @{
52  */
53
54 /**
55  * @brief Base class to handle the memory of simple vector.
56  *
57  * Memory layout is such that it has two std::size_t to hold the count
58  * and capacity of the vector. VectorBase::mData is adjusted so that it points to the
59  * beginning of the first real item so that iterating the items is quick.
60  * @SINCE_1_0.0
61  */
62 class DALI_CORE_API VectorBase
63 {
64 public: // Typedefs
65   using SizeType = std::size_t;
66
67 protected: // Construction
68
69   /**
70    * @brief Default constructor. Does not allocate space.
71    * @SINCE_1_0.0
72    */
73   VectorBase();
74
75   /**
76    * @brief Destructor.
77    *
78    * Does not release the space. Derived class needs to call Release.
79    * Not virtual as this should not be called directly and we do not want
80    * a vtable for this class as it would unnecessarily increase size.
81    * @SINCE_1_0.0
82    */
83   ~VectorBase();
84
85 public: // API
86
87   /**
88    * @brief This method is inlined as it's needed frequently for Vector::End() iterator.
89    *
90    * @SINCE_1_0.0
91    * @return The count of elements in this vector
92    */
93   SizeType Count() const
94   {
95     SizeType items = 0u;
96     if( mData )
97     {
98       SizeType* metadata = reinterpret_cast< SizeType* >( mData );
99       items = *(metadata - 1u);
100     }
101     return items;
102   }
103
104   /**
105    * @brief Gets the count of elements in this vector.
106    * @SINCE_1_0.0
107    * @return The count of elements in this vector
108    */
109   SizeType Size() const
110   {
111     return Count();
112   }
113
114   /**
115    * @brief @ return if the vector is empty.
116    * @SINCE_1_0.0
117    * @return True if the count of elements is empty
118    */
119   bool Empty() const
120   {
121     return Count() == 0u;
122   }
123
124   /**
125    * @brief Gets the capacity of this vector.
126    * @SINCE_1_0.0
127    * @return The capacity of this vector
128    */
129   SizeType Capacity() const;
130
131   /**
132    * @brief Releases the data.
133    *
134    * Does not call destructors on objects held.
135    * @SINCE_1_0.0
136    */
137   void Release();
138
139 protected: // for Derived classes
140
141   /**
142    * @brief Helper to set the count.
143    *
144    * @SINCE_1_0.0
145    * @param[in] count Number of elements in the vector
146    */
147   void SetCount( SizeType count );
148
149   /**
150    * @brief Reserves space in the vector.
151    *
152    * @SINCE_1_0.0
153    * @param[in] count Count of elements to reserve
154    * @param[in] elementSize Size of a single element
155    */
156   void Reserve( SizeType count, SizeType elementSize );
157
158   /**
159    * @brief Copy a vector.
160    *
161    * @SINCE_1_0.0
162    * @param[in] vector Vector to copy from
163    * @param[in] elementSize Size of a single element
164    */
165   void Copy( const VectorBase& vector, SizeType elementSize );
166
167   /**
168    * @brief Swaps the contents of two vectors.
169    *
170    * @SINCE_1_0.0
171    * @param[in] vector Vector to swap with
172    */
173   void Swap( VectorBase& vector );
174
175   /**
176    * @brief Erases an element.
177    *
178    * Does not change capacity.
179    * @SINCE_1_0.0
180    * @param[in] address Address to erase from
181    * @param[in] elementSize Size to erase
182    * @pre Last element cannot be erased as there is nothing to move.
183    */
184   void Erase( char* address, SizeType elementSize );
185
186   /**
187    * @brief Erases a range of elements.
188    *
189    * Does not change capacity.
190    * @SINCE_1_0.0
191    * @param[in] first Address to the first element to be erased
192    * @param[in] last Address to the last element to be erased
193    * @param[in] elementSize Size of one of the elements to be erased
194    * @return Address pointing to the next element of the last one
195    */
196   char* Erase( char* first, char* last, SizeType elementSize );
197
198   /**
199    * @brief Copies a number of bytes from \e source to \e destination.
200    *
201    * \e source and \e destination must not overlap.
202    *
203    * @SINCE_1_0.0
204    * @param[in] destination Pointer to the destination address
205    * @param[in] source Pointer to the source address
206    * @param[in] numberOfBytes The number of bytes to be copied
207    */
208   void CopyMemory( char* destination, const char* source, size_t numberOfBytes );
209
210 private:
211
212   // not copyable as it does not know the size of elements
213   VectorBase( const VectorBase& ) = delete; ///< Deleted copy constructor. @SINCE_1_0.0
214   VectorBase& operator=( const VectorBase& ) = delete; ///< Deleted copy assignment operator. @SINCE_1_0.0
215
216   // not movable as this is handled by deriving classes
217   VectorBase( VectorBase&& ) = delete; ///< Deleted move constructor. @SINCE_1_9.25
218   VectorBase& operator=( VectorBase&& ) = delete; ///< Deleted copy assignment operator. @SINCE_1_9.25
219
220 protected: // Data
221
222   void* mData; ///< Pointer to the data.
223
224 };
225
226 /// @cond internal
227 /**
228  * @brief Vector algorithm variant for trivial types.
229  *
230  * Trivial types do not need destructor or copy constructor called.
231  * @SINCE_1_0.0
232  */
233 template< bool IsTrivial >
234 class VectorAlgorithms : public VectorBase
235 {
236 protected: // API for deriving classes
237   using SizeType = VectorBase::SizeType;
238
239   /**
240    * @brief Empty constructor.
241    * @SINCE_1_0.0
242    */
243   VectorAlgorithms()
244   { }
245
246   /**
247    * @brief Empty destructor.
248    * @SINCE_1_0.0
249    */
250   ~VectorAlgorithms()
251   { }
252
253   /**
254    * @brief Copy vector contents.
255    *
256    * @SINCE_1_0.0
257    * @param[in] rhs VectorBase object to copy from
258    * @param[in] elementSize Size of the content
259    */
260   void Copy( const VectorBase& rhs, SizeType elementSize )
261   {
262     if( rhs.Capacity() > 0u )
263     {
264       VectorBase::Copy( rhs, elementSize );
265     }
266     else
267     {
268       VectorBase::Release();
269     }
270   }
271
272   /**
273    * @brief Reserves space in the vector.
274    *
275    * @SINCE_1_0.0
276    * @param[in] count Count of elements to reserve
277    * @param[in] elementSize Size of a single element
278    */
279   void Reserve( SizeType count, SizeType elementSize )
280   {
281     VectorBase::Reserve( count, elementSize );
282   }
283
284   /**
285    * @brief Resizes the vector. Does not change capacity.
286    *
287    * @SINCE_1_0.0
288    * @param[in] count Count to resize to
289    * @param[in] elementSize Size of a single element
290    */
291   void Resize( SizeType count, SizeType elementSize )
292   {
293     // reserve will copy old elements as well
294     Reserve( count, elementSize );
295   }
296
297   /**
298    * @brief Clears the contents.
299    *
300    * For simple types, nothing to do.
301    * @SINCE_1_0.0
302    */
303   void Clear()
304   {
305     if( mData )
306     {
307       VectorBase::SetCount( 0u );
308     }
309   }
310
311   /**
312    * @brief Releases the vector.
313    * @SINCE_1_0.0
314    */
315   void Release()
316   {
317     VectorBase::Release();
318   }
319
320   /**
321    * @brief Erases an element. Does not change capacity.
322    *
323    * @SINCE_1_0.0
324    * @param[in] address Address to erase from
325    * @param[in] elementSize Size to erase
326    */
327   void Erase( uint8_t* address, SizeType elementSize )
328   {
329     VectorBase::Erase( reinterpret_cast< char* >( address ), elementSize );
330   }
331
332   /**
333    * @brief Erases a range of elements. Does not change capacity.
334    *
335    * @SINCE_1_0.0
336    * @param[in] first Address to the first element to be erased
337    * @param[in] last Address to the last element to be erased
338    * @param[in] elementSize Size of one of the elements to be erased
339    * @return Address pointing to the next element of the last one
340    */
341   uint8_t* Erase( uint8_t* first, uint8_t* last, SizeType elementSize )
342   {
343     return reinterpret_cast< uint8_t* >( VectorBase::Erase( reinterpret_cast< char* >( first ), reinterpret_cast< char *>( last ), elementSize ) );
344   }
345
346   /**
347    * @brief Inserts the given elements into the vector.
348    *
349    * @SINCE_1_0.0
350    * @param[in] at Address where to insert the elements into the vector
351    * @param[in] from Address to the first element to be inserted
352    * @param[in] to Address to the last element to be inserted
353    * @param[in] elementSize Size of one of the elements to be inserted
354    */
355   void Insert( uint8_t* at, uint8_t* from, uint8_t* to, SizeType elementSize )
356   {
357     const SizeType size = to - from;
358     const SizeType count = Count();
359     const SizeType newCount = count + size / elementSize;
360
361     if( newCount > Capacity() )
362     {
363       // Calculate the at offset as the pointer is invalid after the Reserve() call.
364       std::size_t offset = at - reinterpret_cast<uint8_t*>( mData );
365
366       // need more space
367       Reserve( NextPowerOfTwo( static_cast<uint32_t>( newCount ) ), elementSize ); // reserve enough space to store at least the next power of two elements of the new required size.
368
369       // Set the new at pointer.
370       at = reinterpret_cast<uint8_t*>( mData ) + offset;
371     }
372     // set new count first as otherwise the debug assert will hit us
373     SetCount( newCount );
374
375     // Move current items to a new position inside the vector.
376     CopyMemory( reinterpret_cast< char* >( at + size ),
377                 reinterpret_cast< const char* >( at ),
378                 ( reinterpret_cast<uint8_t*>( mData ) + count * elementSize ) - at );
379
380     // Copy the given items.
381     CopyMemory( reinterpret_cast< char* >( at ), reinterpret_cast< const char* >( from ), size );
382   }
383 };
384 /// @endcond
385
386 /// @cond internal
387 /**
388  * @brief Vector algorithm variant for complex types.
389  *
390  * Not yet supported so will lead to compile error
391  * as constructor and destructor are private.
392  * TODO add support for this variant.
393  * @SINCE_1_0.0
394  */
395 template<>
396 class VectorAlgorithms< false > : public VectorBase
397 {
398 private:
399   VectorAlgorithms()
400   { }
401   ~VectorAlgorithms()
402   { }
403 };
404 /// @endcond
405
406 /**
407  * @brief Vector class with minimum space allocation when it's empty.
408  *
409  * @SINCE_1_0.0
410  * @param type The type of the data that the vector holds
411  */
412 template< class T, bool IsTrivialType = TypeTraits<T>::IS_TRIVIAL_TYPE == true >
413 class Vector : public VectorAlgorithms< IsTrivialType >
414 {
415 public: // API
416
417   /**
418    * @brief Type definitions.
419    * @SINCE_1_0.0
420    */
421   using SizeType      = VectorBase::SizeType; ///< Size type @SINCE_1_0.0
422   using Iterator      = T*;                   ///< Most simple Iterator is a pointer @SINCE_1_0.0
423   using ConstIterator = const T*;             ///< Const iterator @SINCE_1_0.0
424   using ItemType      = T;                    ///< Item type @SINCE_1_0.0
425
426   /**
427    * @brief Enumeration for BaseType.
428    * @SINCE_1_0.0
429    */
430   enum
431   {
432     BaseType = IsTrivialType ///< @SINCE_1_0.0
433   };
434
435   /**
436    * @brief Default constructor. Does not allocate any space.
437    * @SINCE_1_0.0
438    */
439   Vector()
440   { }
441
442   /**
443    * @brief Destructor. Releases the allocated space.
444    * @SINCE_1_0.0
445    */
446   ~Vector()
447   {
448     Release();
449   }
450
451   /**
452    * @brief Copy constructor.
453    *
454    * @SINCE_1_0.0
455    * @param[in] vector Vector to copy from
456    */
457   Vector( const Vector& vector )
458   {
459     // reuse copy assignment
460     operator=( vector );
461   }
462
463   /**
464    * @brief Default move constructor.
465    *
466    * @SINCE_1_9.25
467    * @param[in] vector Vector to move
468    */
469   Vector( Vector&& vector )
470   {
471     // reuse move assignment
472     operator=( std::move( vector ) );
473   }
474
475   /**
476    * @brief Assignment operator.
477    *
478    * @SINCE_1_0.0
479    * @param[in] vector Vector to assign from
480    * @return Reference to self for chaining
481    */
482   Vector& operator=( const Vector& vector )
483   {
484     if( this != &vector )
485     {
486       VectorAlgorithms<BaseType>::Copy( vector, sizeof( ItemType ) );
487     }
488     return *this;
489   }
490
491   /**
492    * @brief Default move assignment operator.
493    *
494    * @SINCE_1_9.25
495    * @param[in] vector Vector to move
496    */
497   Vector& operator=( Vector&& vector )
498   {
499     if( this != &vector )
500     {
501       if( VectorBase::mData )
502       {
503         Release();
504       }
505       VectorBase::mData = vector.mData;
506       vector.mData = nullptr;
507     }
508     return *this;
509   }
510
511   /**
512    * @brief Iterator to the beginning of the data.
513    * @SINCE_1_0.0
514    * @return Iterator to the beginning of the data
515    */
516   Iterator Begin() const
517   {
518     ItemType* address = reinterpret_cast<ItemType*>( VectorBase::mData );
519     return address;
520   }
521
522   /**
523    * @brief Iterator to the end of the data (one past last element).
524    * @SINCE_1_0.0
525    * @return Iterator to the end of the data (one past last element)
526    */
527   Iterator End() const
528   {
529     ItemType* address = reinterpret_cast<ItemType*>( VectorBase::mData );
530     address += VectorBase::Count();
531     return address;
532   }
533
534   /**
535    * Support for C++11 Range-based for loop: for( item : container ).
536    * @SINCE_1_2.60
537    * @return The start iterator
538    */
539   Iterator begin() const
540   {
541     return Begin();
542   }
543
544   /**
545    * Support for C++11 Range-based for loop: for( item : container ).
546    * @SINCE_1_2.60
547    * @return The end iterator
548    */
549   Iterator end() const
550   {
551     return End();
552   }
553
554   /**
555    * @brief Subscript operator.
556    * @SINCE_1_0.0
557    * @param[in] index Index of the element
558    * @return Reference to the element for given index
559    * @pre Index must be in the vector's range.
560    */
561   ItemType& operator[]( SizeType index )
562   {
563     // reuse the const version
564     return const_cast< ItemType& >( const_cast< const Vector< ItemType >& >( *this )[ index ] );
565   }
566
567   /**
568    * @brief Subscript operator.
569    * @SINCE_1_0.0
570    * @param[in] index Index of the element
571    * @return Reference to the element for given index
572    * @pre Index must be in the vector's range.
573    */
574   const ItemType& operator[]( SizeType index ) const
575   {
576     DALI_ASSERT_VECTOR( VectorBase::mData && "Vector is empty" );
577     DALI_ASSERT_VECTOR( index < VectorBase::Count() && "Index out of bounds" );
578     ItemType* address = reinterpret_cast<ItemType*>( VectorBase::mData );
579     address += index;
580     return *address;
581   }
582
583   /**
584    * @brief Pushes back an element to the vector.
585    *
586    * The underlying storage may be reallocated to provide space.
587    * If this occurs, all pre-existing pointers into the vector will
588    * become invalid.
589    *
590    * @SINCE_1_0.0
591    * @param[in] element Element to be added
592    */
593   void PushBack( const ItemType& element )
594   {
595     const SizeType count = VectorBase::Count();
596     const SizeType newCount = count + 1u;
597     const SizeType capacity = VectorBase::Capacity();
598     if( newCount > capacity )
599     {
600       // need more space
601       Reserve( newCount << 1u ); // reserve double the current count
602     }
603     // set new count first as otherwise the debug assert will hit us
604     VectorBase::SetCount( newCount );
605     operator[]( count ) = element;
606   }
607
608   /**
609    * @brief Inserts an element to the vector.
610    *
611    * Elements after \e at are moved one position to the right.
612    *
613    * The underlying storage may be reallocated to provide space.
614    * If this occurs, all pre-existing pointers into the vector will
615    * become invalid.
616    *
617    * @SINCE_1_0.0
618    * @param[in] at Iterator where to insert the elements into the vector
619    * @param[in] element An element to be added
620    * @pre Iterator at must be in the vector's range ( Vector::Begin(), Vector::End() ).
621    */
622   void Insert( Iterator at, const ItemType& element )
623   {
624     DALI_ASSERT_VECTOR( ( at <= End() ) && ( at >= Begin() ) && "Iterator not inside vector" );
625     const SizeType size = sizeof( ItemType );
626     uint8_t* address = const_cast<uint8_t*>( reinterpret_cast<const uint8_t*>( &element ) );
627     VectorAlgorithms<BaseType>::Insert( reinterpret_cast< uint8_t* >( at ),
628                                         address,
629                                         address + size,
630                                         size );
631   }
632
633   /**
634    * @brief Inserts the given elements into the vector.
635    *
636    * Elements after \e at are moved the number of given elements positions to the right.
637    *
638    * The underlying storage may be reallocated to provide space.
639    * If this occurs, all pre-existing pointers into the vector will
640    * become invalid.
641    *
642    * @SINCE_1_0.0
643    * @param[in] at Iterator where to insert the elements into the vector
644    * @param[in] from Iterator to the first element to be inserted
645    * @param[in] to Iterator to the last element to be inserted
646    * @pre Iterator \e at must be in the vector's range ( Vector::Begin(), Vector::End() ).
647    * @pre Iterators \e from and \e to must be valid iterators.
648    * @pre Iterator \e from must not be grater than Iterator \e to.
649    *
650    */
651   void Insert( Iterator at, Iterator from, Iterator to )
652   {
653     DALI_ASSERT_VECTOR( ( at <= End() ) && ( at >= Begin() ) && "Iterator not inside vector" );
654     DALI_ASSERT_VECTOR( ( from <= to ) && "from address can't be greater than to" );
655
656     if( from == to )
657     {
658       // nothing to copy.
659       return;
660     }
661
662     VectorAlgorithms<BaseType>::Insert( reinterpret_cast< uint8_t* >( at ),
663                                         reinterpret_cast< uint8_t* >( from ),
664                                         reinterpret_cast< uint8_t* >( to ),
665                                         sizeof( ItemType ) );
666   }
667
668   /**
669    * @brief Reserves space in the vector.
670    *
671    * Reserving less than current Capacity is a no-op.
672    * @SINCE_1_0.0
673    * @param[in] count Count of elements to reserve
674    */
675   void Reserve( SizeType count )
676   {
677     VectorAlgorithms<BaseType>::Reserve( count, sizeof( ItemType ) );
678   }
679
680   /**
681    * @brief Resizes the vector. Does not change capacity.
682    *
683    * @SINCE_1_0.0
684    * @param[in] count Count to resize to
685    */
686   void Resize( SizeType count )
687   {
688     ItemType item = ItemType();
689     Resize(count, item);
690   }
691
692   /**
693    * @brief Resizes the vector without initializing the data.
694    *
695    * Can be used as a data container for reading whole file content.
696    * @SINCE_1_9.27
697    * @param[in] count Count to resize to
698    */
699   void ResizeUninitialized( SizeType count )
700   {
701     Reserve( count );
702     VectorBase::SetCount( count );
703   }
704
705   /**
706    * @brief Resizes the vector. Does not change capacity.
707    *
708    * @SINCE_1_0.0
709    * @param[in] count Count to resize to
710    * @param[in] item An item to insert to the new indices
711    */
712   void Resize( SizeType count, const ItemType& item )
713   {
714     const SizeType oldCount = VectorBase::Count();
715     if( count <= oldCount )
716     {
717       // getting smaller so just set count
718       VectorBase::SetCount( count );
719     }
720     else
721     {
722       // remember how many new items get added
723       SizeType newItems = count - oldCount;
724       Reserve( count );
725       for( ; newItems > 0u; --newItems )
726       {
727         PushBack( item );
728       }
729     }
730   }
731
732   /**
733    * @brief Erases an element.
734    *
735    * Does not change capacity. Other elements get moved.
736    *
737    * @SINCE_1_0.0
738    * @param[in] iterator Iterator pointing to the item to remove
739    * @return Iterator pointing to next element
740    * @pre Iterator \e iterator must be within the vector's range ( Vector::Begin(), Vector::End() - 1 ).
741    *
742    */
743   Iterator Erase( Iterator iterator )
744   {
745     DALI_ASSERT_VECTOR( (iterator < End()) && (iterator >= Begin()) && "Iterator not inside vector" );
746     if( iterator < ( End() - 1u ) )
747     {
748       VectorAlgorithms<BaseType>::Erase( reinterpret_cast< uint8_t* >( iterator ), sizeof( ItemType ) );
749     }
750     else
751     {
752       // just remove the element
753       Remove( iterator );
754     }
755     return iterator;
756   }
757
758   /**
759    * @brief Erases a range of elements.
760    *
761    * Does not change capacity. Other elements get moved.
762    *
763    * @SINCE_1_0.0
764    * @param[in] first Iterator to the first element to be erased
765    * @param[in] last Iterator to the last element to be erased
766    *
767    * @return Iterator pointing to the next element of the last one
768    * @pre Iterator \e first must be in the vector's range ( Vector::Begin(), Vector::End() ).
769    * @pre Iterator \e last must be in the vector's range ( Vector::Begin(), Vector::End() ).
770    * @pre Iterator \e first must not be grater than Iterator \e last.
771    *
772    */
773   Iterator Erase( Iterator first, Iterator last )
774   {
775     DALI_ASSERT_VECTOR( ( first <= End() ) && ( first >= Begin() ) && "Iterator not inside vector" );
776     DALI_ASSERT_VECTOR( ( last <= End() ) && ( last >= Begin() ) && "Iterator not inside vector" );
777     DALI_ASSERT_VECTOR( ( first <= last ) && "first iterator greater than last" );
778
779     Iterator nextElement;
780
781     if( last == End() )
782     {
783       // Erase up to the end.
784       VectorBase::SetCount( VectorBase::Count() - ( last - first ) );
785       nextElement = End();
786     }
787     else
788     {
789       nextElement = reinterpret_cast<Iterator>( VectorAlgorithms<BaseType>::Erase( reinterpret_cast< uint8_t* >( first ),
790                                                                                    reinterpret_cast< uint8_t* >( last ),
791                                                                                    sizeof( ItemType ) ) );
792     }
793
794     return nextElement;
795   }
796
797   /**
798    * @brief Removes an element.
799    *
800    * Does not maintain order. Swaps the element with end and
801    * decreases size by one.  This is much faster than Erase so use
802    * this in case order does not matter. Does not change capacity.
803    *
804    * @SINCE_1_0.0
805    * @param[in] iterator Iterator pointing to the item to remove
806    * @pre Iterator \e iterator must be in the vector's range ( Vector::Begin(), Vector::End() - 1 ).
807    *
808    */
809   void Remove( Iterator iterator )
810   {
811     DALI_ASSERT_VECTOR( (iterator < End()) && (iterator >= Begin()) && "Iterator not inside vector" );
812
813     Iterator last = End() - 1u;
814     if( last > iterator )
815     {
816       std::swap( *iterator, *last );
817     }
818     VectorBase::SetCount( VectorBase::Count() - 1u );
819   }
820
821   /**
822    * @brief Swaps the contents of two vectors.
823    *
824    * @SINCE_1_0.0
825    * @param[in] vector Vector to swap with
826    */
827   void Swap( Vector& vector )
828   {
829     VectorBase::Swap( vector );
830   }
831
832   /**
833    * @brief Clears the contents of the vector. Keeps its capacity.
834    * @SINCE_1_0.0
835    */
836   void Clear()
837   {
838     VectorAlgorithms<BaseType>::Clear();
839   }
840
841   /**
842    * @brief Releases the memory that the vector holds.
843    * @SINCE_1_0.0
844    */
845   void Release()
846   {
847     VectorAlgorithms<BaseType>::Release();
848   }
849 };
850
851 /**
852  * @}
853  */
854 } // namespace Dali
855
856 #endif // DALI_VECTOR_H