📄 vector.h
字号:
return buffer_[index]; } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::const_reference Vector<T, Allocator, false>::at(size_type index) const // {{{ { return buffer_[index]; } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::reference Vector<T, Allocator, false>::front() // {{{ { return buffer_[0]; } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::const_reference Vector<T, Allocator, false>::front() const // {{{ { return buffer_[0]; } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::reference Vector<T, Allocator, false>::back() // {{{ { return buffer_[size()-1]; } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::const_reference Vector<T, Allocator, false>::back() const // {{{ { return buffer_[size()-1]; } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::iterator Vector<T, Allocator, false>::begin() // {{{ { return buffer_; } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::const_iterator Vector<T, Allocator, false>::begin() const // {{{ { return buffer_; } // }}} template<typename T, typename Allocator> inline void Vector<T, Allocator, false>::clear() // {{{ { size_ = 0; } // }}} template<typename T, typename Allocator> inline bool Vector<T, Allocator, false>::empty() const // {{{ { return !size_; } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::iterator Vector<T, Allocator, false>::end() // {{{ { return buffer_ + size_; } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::const_iterator Vector<T, Allocator, false>::end() const // {{{ { return buffer_ + size_; } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::iterator Vector<T, Allocator, false>::erase(iterator itr) // {{{ { //TRACE("$W----- SINGLE ERASE -----\n"); // Check the element is within the active elements of the array. ASSERT( itr >= begin() ); ASSERT( itr < end() ); // Shift all elements from the erase point to the last filled element one // position towards the start of the container iterator oneAfter = itr+1; unsigned int iCopySize = PTR_DIFF( end(), oneAfter ); // Must use memmove because the areas can overlap. std::memmove( reinterpret_cast<char*>( itr ), reinterpret_cast<char*>( oneAfter ), iCopySize ); // Decrement count of elements in the container --size_; return itr; } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::iterator Vector<T, Allocator, false>::erase( iterator first, iterator last ) // {{{ { // Save pointer to element to be removed, as this after erasure this will // point to the element that was after the erased element before erasure unsigned int iCopySize = PTR_DIFF( end(), last ); // Check the range is within the active elements of the array. ASSERT( first >= begin() ); ASSERT( last <= end() ); // Must use memmove because the areas can overlap. std::memmove( reinterpret_cast<char*>( first ), reinterpret_cast<char*>( last ), iCopySize ); size_ -= ( last - first ); return first; } // }}} /** * expand - Although this implementation does not support automatic * resizing or reallocation, the interface is extended beyond that of * standard STL with this method that allows the maximum storage size * to be increased. This is an expensive operation, and involves the * use of the copy constructor, and Swap. Accordingly, in the event of * an allocation failure, the object will remain untouched, and a debug * ASSERT will be raised. * @param maxSize is a size_type that describes the number of objects * that we wish storage to be reserved for. If the max_size() of 'other' * is greater, then this size will be requested instead. The result will * be reflected by max_size(), and this should be checked against the * requested size and/or other.max_size() **BEFORE THE OBJECT IS USED**. * An assert is also included to trap memory allocation failure in debug * builds. */ template<typename T, typename Allocator> void Vector<T, Allocator, false>::expand(size_type maxSize) // {{{ { if (maxSize > max_size()) { Vector<T, Allocator, false> temp(*this, maxSize); if ( temp.max_size() == maxSize ) { Swap(temp); } else { TRACE("$R** Vector expansion FAILED when expanding from 0x%08x to 0x%08x **\n", max_size(), maxSize ); } } } // }}} /** * resize is a method that allows the 'size()' of the object to be altered. * It achieves this in two ways. If the size is greater than size_, the * elements upto size are constructed, and size is set accordingly. If * the newSize is less than size_, the elemnts between newSize and size_ are * destroyed, and the size_ is trimmed back. THIS OPERATION DOES NOT * RANGE CHECK MAX_SIZE - it is required that the user observes max_size. * @param newSize is a size_type that specifies the new size_ of the * object. */ template<typename T, typename Allocator> inline void Vector<T, Allocator, false>::resize( size_type newSize ) // {{{ { // set size to the new size - no ctor or dtor needed. ASSERT( newSize <= max_size() ); size_ = newSize; } // }}} /** * resize is a method that allows the 'size()' of the object to be altered. * It achieves this in two ways. If the size is greater than size_, the * elements upto size are constructed, and size is set accordingly. If * the newSize is less than size_, the elemnts between newSize and size_ are * destroyed, and the size_ is trimmed back. THIS OPERATION DOES NOT * RANGE CHECK MAX_SIZE - it is required that the user observes max_size. * @param newSize is a size_type that specifies the new size_ of the * object. * @param fill_value is a value_type that describes the value which should * be copied into the slots when size_ is increased. */ template<typename T, typename Allocator> void Vector<T, Allocator, false>::resize( size_type newSize, value_type fill_value ) // {{{ { ASSERT( newSize <= max_size() ); if ( newSize > size() ) { // then we want to fill the new slots... unsigned long iCount = newSize - size(); iterator pEntry = end(); do { *pEntry = fill_value; ++pEntry; } while ( --iCount ); } size_ = newSize; } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::iterator Vector<T, Allocator, false>::insert( iterator position, const_reference value) // {{{ { // Shift elements from the position pointed to by the iterator upto the last // in the container inclusive one position towards the end of the container ASSERT( size() < max_size() ); ASSERT( position >= begin() ); ASSERT( position <= end() ); unsigned int iCopySize = PTR_DIFF( end(), position ); // Must use memmove because the areas can overlap. std::memmove( reinterpret_cast<char*>( position + 1 ), reinterpret_cast<char*>( position ), iCopySize ); // Construct new object in memory pointed to by iterator - as is only a // pointer, just assign the value *position = value; // Increment count of elements in the container ++size_; return position; } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::iterator Vector<T, Allocator, false>::insert( iterator position, const_iterator first, const_iterator last ) // {{{ { // Shift elements from the position pointed to by the iterator upto the last // in the container inclusive one position towards the end of the container ASSERT( size() + last - first <= (signed int) max_size() ); ASSERT( position >= begin() ); ASSERT( position <= end() ); ASSERT( last >= first ); unsigned int iInsSize = PTR_DIFF( last, first ); unsigned int iCopySize = PTR_DIFF( end(), position ); // Must use memmove because the areas can overlap. std::memmove( reinterpret_cast<char*>( position ) + iInsSize, reinterpret_cast<char*>( position ), iCopySize ); // Construct new object in memory pointed to by iterator - as is only a // pointer, just assign the value std::memmove( reinterpret_cast<char*>( position ), reinterpret_cast<const char*>( first ), iInsSize ); // Increment count of elements in the container size_ += last - first; return position; } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::size_type Vector<T, Allocator, false>::max_size() const // {{{ { return maxSize_; } // }}} template<typename T, typename Allocator> inline void Vector<T, Allocator, false>::push_back(const_reference value) // {{{ { ASSERT( size() < max_size() ); // Construct new object in memory one position past current last element *end() = value; // Increment count of elements in the container ++size_; } // }}} template<typename T, typename Allocator> inline void Vector<T, Allocator, false>::pop_back() // {{{ { ASSERT( size() ); // Just decrement count of elements in the container --size_; } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::reverse_iterator Vector<T, Allocator, false>::rbegin() // {{{ { return reverse_iterator(end()); } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::const_reverse_iterator Vector<T, Allocator, false>::rbegin() const // {{{ { return const_reverse_iterator(end()); } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::reverse_iterator Vector<T, Allocator, false>::rend() // {{{ { return reverse_iterator(begin()); } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::const_reverse_iterator Vector<T, Allocator, false>::rend() const // {{{ { return const_reverse_iterator(begin()); } // }}} template<typename T, typename Allocator> inline typename Vector<T, Allocator, false>::size_type Vector<T, Allocator, false>::size() const // {{{ { return size_; } // }}} template<typename T, typename Allocator> inline void Vector<T, Allocator, false>::Swap(Vector<T, Allocator, false>& other) // {{{ { size_type temp = maxSize_; maxSize_ = other.maxSize_; other.maxSize_ = temp; temp = size_; size_ = other.size_; other.size_ = temp; T* tempBuffer = buffer_; buffer_ = other.buffer_; other.buffer_ = tempBuffer; } // }}}} // namespace oxsmei#endif // VECTOR_H
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -