57#ifndef __SmallVector_H
58#define __SmallVector_H
74 template<
class T1,
class T2>
75 inline _Scalar_ptr_iterator_tag _Ptr_cat(T1 **, T2 **) {
76 _Scalar_ptr_iterator_tag _Cat;
80 template<
class T1,
class T2>
81 inline _Scalar_ptr_iterator_tag _Ptr_cat(T1*
const *, T2 **) {
82 _Scalar_ptr_iterator_tag _Cat;
99 template <>
struct isPodLike<signed char> {
static const bool value =
true; };
104 template <>
struct isPodLike<unsigned short> {
static const bool value =
true; };
111 template<
typename T,
typename U>
155 void grow_pod(
size_t MinSizeInBytes,
size_t TSize);
162 template <
typename T>
237 template <
typename T,
bool isPodLike>
251 template<
typename It1,
typename It2>
253 std::uninitialized_copy(I, E, Dest);
262 template <
typename T,
bool isPodLike>
264 size_t CurCapacity = this->
capacity();
265 size_t CurSize = this->
size();
266 size_t NewCapacity = 2*CurCapacity + 1;
267 if (NewCapacity < MinSize)
268 NewCapacity = MinSize;
269 T *NewElts =
static_cast<T*
>(malloc(NewCapacity*
sizeof(T)));
281 this->
setEnd(NewElts+CurSize);
289 template <
typename T>
299 template<
typename It1,
typename It2>
302 std::uninitialized_copy(I, E, Dest);
307 template<
typename T1,
typename T2>
312 memcpy(Dest, I, (E-I)*
sizeof(T));
317 void grow(
size_t MinSize = 0) {
318 this->
grow_pod(MinSize*
sizeof(T),
sizeof(T));
326 template <
typename T>
356 if (N < this->
size()) {
359 }
else if (N > this->
size()) {
368 if (N < this->
size()) {
371 }
else if (N > this->
size()) {
387 new (this->
end()) T(Elt);
401 T Result = this->
back();
410 template<
typename in_iter>
411 void append(in_iter in_start, in_iter in_end) {
412 size_type NumInputs = std::distance(in_start, in_end);
420 std::uninitialized_copy(in_start, in_end, this->
end());
432 std::uninitialized_fill_n(this->
end(), NumInputs, Elt);
436 void assign(
unsigned NumElts,
const T &Elt) {
447 std::copy(I+1, this->
end(), I);
464 if (I == this->
end()) {
466 return this->
end()-1;
471 new (this->
end()) T(this->
back());
474 std::copy_backward(I, this->
end()-1, this->
end());
478 size_t EltNo = I-this->
begin();
480 I = this->
begin()+EltNo;
485 if (I == this->
end()) {
487 return this->
end()-1;
491 size_t InsertElt = I - this->
begin();
494 reserve(
static_cast<unsigned>(this->
size() + NumToInsert));
497 I = this->
begin()+InsertElt;
503 if (
size_t(this->
end()-I) >= NumToInsert) {
504 T *OldEnd = this->
end();
508 std::copy_backward(I, OldEnd-NumToInsert, OldEnd);
510 std::fill_n(I, NumToInsert, Elt);
518 T *OldEnd = this->
end();
520 size_t NumOverwritten = OldEnd-I;
524 std::fill_n(I, NumOverwritten, Elt);
527 std::uninitialized_fill_n(OldEnd, NumToInsert-NumOverwritten, Elt);
531 template<
typename ItTy>
533 if (I == this->
end()) {
535 return this->
end()-1;
538 size_t NumToInsert = std::distance(From, To);
540 size_t InsertElt = I - this->
begin();
543 reserve(
static_cast<unsigned>(this->
size() + NumToInsert));
546 I = this->
begin()+InsertElt;
552 if (
size_t(this->
end()-I) >= NumToInsert) {
553 T *OldEnd = this->
end();
557 std::copy_backward(I, OldEnd-NumToInsert, OldEnd);
559 std::copy(From, To, I);
567 T *OldEnd = this->
end();
569 size_t NumOverwritten = OldEnd-I;
573 for (; NumOverwritten > 0; --NumOverwritten) {
587 if (this->
size() != RHS.
size())
return false;
591 return !(*
this == RHS);
595 return std::lexicographical_compare(this->
begin(), this->
end(),
621 template <
typename T>
623 if (
this == &RHS)
return;
632 if (RHS.
size() > this->capacity())
638 size_t NumShared = this->
size();
639 if (NumShared > RHS.
size()) NumShared = RHS.
size();
640 for (
unsigned i = 0; i !=
static_cast<unsigned>(NumShared); ++i)
645 size_t EltDiff = this->
size() - RHS.
size();
650 }
else if (RHS.
size() > this->size()) {
651 size_t EltDiff = RHS.
size() - this->
size();
659 template <
typename T>
663 if (
this == &RHS)
return *
this;
667 size_t RHSSize = RHS.
size();
668 size_t CurSize = this->
size();
669 if (CurSize >= RHSSize) {
675 NewEnd = this->
begin();
693 }
else if (CurSize) {
700 this->
begin()+CurSize);
716 template <
typename T,
unsigned N>
723 MinUs = (
static_cast<unsigned int>(
sizeof(T))*N +
724 static_cast<unsigned int>(
sizeof(
U)) - 1) /
725 static_cast<unsigned int>(
sizeof(
U)),
730 NumInlineEltsElts =
MinUs > 1 ? (
MinUs - 1) : 1,
734 NumTsAvailable = (NumInlineEltsElts+1)*static_cast<unsigned int>(sizeof(
U))/
735 static_cast<unsigned int>(sizeof(T))
749 template<
typename ItTy>
781 template<
typename ItTy>
807 template<
typename T,
unsigned N>
union Ogre::SmallVectorBase::U FirstEl
SmallVectorBase(size_t Size)
size_t size_in_bytes() const
size_in_bytes - This returns size()*sizeof(T).
bool isSmall() const
isSmall - Return true if this is a smallvector which has not had dynamic memory allocated for it.
size_t capacity_in_bytes() const
capacity_in_bytes - This returns capacity()*sizeof(T).
void grow_pod(size_t MinSizeInBytes, size_t TSize)
grow_pod - This is an implementation of the grow() method which only works
SmallVectorImpl - This class consists of common code factored out of the SmallVector class to reduce ...
SuperClass::size_type size_type
void push_back(const T &Elt)
bool operator!=(const SmallVectorImpl &RHS) const
void assign(unsigned NumElts, const T &Elt)
iterator erase(iterator S, iterator E)
iterator erase(iterator I)
iterator insert(iterator I, size_type NumToInsert, const T &Elt)
bool operator<(const SmallVectorImpl &RHS) const
const SmallVectorImpl & operator=(const SmallVectorImpl &RHS)
void resize(unsigned N, const T &NV)
void set_size(unsigned N)
set_size - Set the array size to
static void construct_range(T *S, T *E, const T &Elt)
SuperClass::iterator iterator
SmallVectorTemplateBase< T, isPodLike< T >::value > SuperClass
iterator insert(iterator I, const T &Elt)
bool operator==(const SmallVectorImpl &RHS) const
void append(in_iter in_start, in_iter in_end)
append - Add the specified range to the end of the SmallVector.
iterator insert(iterator I, ItTy From, ItTy To)
void swap(SmallVectorImpl &RHS)
void append(size_type NumInputs, const T &Elt)
append - Add the specified range to the end of the SmallVector.
SmallVectorImpl(unsigned N)
SmallVectorImpl(const SmallVectorImpl &)
static void uninitialized_copy(It1 I, It1 E, It2 Dest)
uninitialized_copy - Copy the range [I, E) onto the uninitialized memory starting with "Dest",...
void grow(size_t MinSize=0)
grow - double the size of the allocated memory, guaranteeing space for at least one more element or M...
SmallVectorTemplateBase(size_t Size)
static void uninitialized_copy(T1 *I, T1 *E, T2 *Dest)
uninitialized_copy - Copy the range [I, E) onto the uninitialized memory starting with "Dest",...
static void destroy_range(T *, T *)
static void destroy_range(T *S, T *E)
static void uninitialized_copy(It1 I, It1 E, It2 Dest)
uninitialized_copy - Copy the range [I, E) onto the uninitialized memory starting with "Dest",...
SmallVectorTemplateBase(size_t Size)
void grow(size_t MinSize=0)
grow - double the size of the allocated memory, guaranteeing space for at least one more element or M...
const_pointer data() const
data - Return a pointer to the vector's buffer, even if empty().
SmallVectorTemplateCommon(size_t Size)
pointer data()
data - Return a pointer to the vector's buffer, even if empty().
std::reverse_iterator< const_iterator > const_reverse_iterator
const_reverse_iterator rbegin() const
ptrdiff_t difference_type
const_reverse_iterator rend() const
const_reference front() const
const_iterator end() const
const_reference back() const
size_t capacity() const
capacity - Return the total number of elements in the currently allocated buffer.
size_type max_size() const
const_iterator begin() const
const_reference operator[](unsigned idx) const
reference operator[](unsigned idx)
reverse_iterator rbegin()
std::reverse_iterator< iterator > reverse_iterator
const T & const_reference
const_iterator capacity_ptr() const
SmallVector(ItTy S, ItTy E)
SmallVector & operator=(const SmallVectorImpl< T > &RHS)
SmallVector(const SmallVector &RHS)
SmallVector(unsigned Size, const T &Value=T())
SmallVector - This is a 'vector' (really, a variable-sized array), optimized for the case when the ar...
const SmallVector & operator=(const SmallVector &RHS)
SmallVector(ItTy S, ItTy E)
U InlineElts[NumInlineEltsElts]
SmallVectorImpl< T >::U U
SmallVector(const SmallVector &RHS)
SmallVector(unsigned Size, const T &Value=T())
void swap(Ogre::SmallVectorImpl< T > &LHS, Ogre::SmallVectorImpl< T > &RHS)
Implement std::swap in terms of SmallVector swap.