19 #if !defined(XALANVECTOR_HEADER_GUARD_1357924680) 20 #define XALANVECTOR_HEADER_GUARD_1357924680 42 XALAN_CPP_NAMESPACE_BEGIN
48 #pragma warning(disable: 4100) 57 template <
class Type,
class ConstructionTraits = MemoryManagedConstructionTraits<Type> >
71 #if defined(XALAN_VCPP_USE_PTRIT) 92 #if defined(XALAN_HAS_STD_ITERATORS) 95 #elif defined(XALAN_RW_NO_CLASS_PARTIAL_SPEC) 96 typedef XALAN_STD_QUALIFIER random_access_iterator_tag iterator_category;
127 size_type initialAllocation =
size_type(0)) :
128 m_memoryManager(&theManager),
130 m_allocation(initialAllocation),
131 m_data(initialAllocation > 0 ? allocate(initialAllocation) : 0)
138 MemoryManager& theManager,
139 size_type initialAllocation =
size_type(0))
145 ThisType*
const theResult =
146 new (theGuard.get())
ThisType(theManager, initialAllocation);
154 const ThisType& theSource,
155 MemoryManager& theManager XALAN_DEFAULT_CONSTRUCTOR_MEMMGR,
156 size_type theInitialAllocation =
size_type(0)) :
157 m_memoryManager(&theManager),
162 if (theSource.m_size > 0)
164 ThisType theTemp(theManager, local_max(theSource.m_size, theInitialAllocation));
171 else if (theInitialAllocation > 0)
173 m_data = allocate(theInitialAllocation);
175 m_allocation = theInitialAllocation;
182 const_iterator theFirst,
183 const_iterator theLast,
184 MemoryManager& theManager) :
185 m_memoryManager(&theManager),
191 ThisType theTemp(theManager);
193 theTemp.
insert(theTemp.
begin(), theFirst, theLast);
202 const_iterator theFirst,
203 const_iterator theLast,
204 MemoryManager& theManager)
210 ThisType*
const theResult =
211 new (theGuard.get())
ThisType(theFirst, theLast, theManager);
219 size_type theInsertSize,
220 const value_type& theData,
221 MemoryManager& theManager) :
222 m_memoryManager(&theManager),
227 ThisType theTemp(theManager);
229 theTemp.
insert(theTemp.
begin(), theInsertSize, theData);
240 if (m_allocation != 0)
265 destroy(m_data[m_size]);
277 if (theFirst != theLast)
279 XALAN_STD_QUALIFIER copy(
284 shrinkCount(local_distance(theFirst, theLast));
295 return erase(position, position + 1);
300 iterator thePosition,
301 const_iterator theFirst,
302 const_iterator theLast)
306 assert(theFirst <= theLast);
307 assert(thePosition >=
begin());
308 assert(thePosition <=
end());
312 const size_type theInsertSize =
313 local_distance(theFirst, theLast);
315 if (theInsertSize == 0)
320 const size_type theTotalSize =
size() + theInsertSize;
322 if (thePosition ==
end())
324 pointer thePointer = ensureCapacity(theTotalSize);
326 while (theFirst != theLast)
328 Constructor::construct(thePointer, *theFirst, *m_memoryManager);
339 assert (m_memoryManager != 0);
341 ThisType theTemp(*m_memoryManager, theTotalSize);
347 theTemp.
insert(theTemp.
end(), theFirst, theLast);
357 const iterator theOriginalEnd =
end();
359 const size_type theRightSplitSize =
360 local_distance(thePosition, theOriginalEnd);
362 if (theRightSplitSize <= theInsertSize)
368 const const_iterator toInsertSplit = theFirst + theRightSplitSize;
369 const_iterator toInsertIter = toInsertSplit;
371 while (toInsertIter != theLast)
373 doPushBack(*toInsertIter);
379 toInsertIter = thePosition;
380 while (toInsertIter != theOriginalEnd)
382 doPushBack(*toInsertIter);
389 XALAN_STD_QUALIFIER copy(theFirst, toInsertSplit, thePosition);
396 const_iterator toMoveIter =
end() - theInsertSize;
398 while (toMoveIter != theOriginalEnd)
400 doPushBack(*toMoveIter);
406 XALAN_STD_QUALIFIER copy_backward(thePosition, theOriginalEnd - theInsertSize, theOriginalEnd);
409 XALAN_STD_QUALIFIER copy(theFirst, theLast, thePosition);
419 iterator thePosition,
421 const value_type& theData)
425 const size_type theTotalSize =
size() + theCount;
428 if (thePosition ==
end())
430 pointer thePointer = ensureCapacity(theTotalSize);
432 for (size_type index = 0; index < theCount; ++index)
434 Constructor::construct(thePointer, theData, *m_memoryManager);
444 assert ( m_memoryManager != 0 );
446 ThisType theTemp(*m_memoryManager, theTotalSize);
452 theTemp.
insert(theTemp.
end(), theCount, theData);
462 const iterator theOriginalEnd =
end();
464 const size_type theRightSplitSize =
465 local_distance(thePosition, theOriginalEnd);
467 if (theRightSplitSize <= theCount)
473 for (size_type i = 0; i < (theCount - theRightSplitSize); ++i)
479 iterator toInsertIter = thePosition;
481 while (toInsertIter != theOriginalEnd)
483 doPushBack(*toInsertIter);
490 XALAN_STD_QUALIFIER fill(thePosition, thePosition + theRightSplitSize, theData);
497 const_iterator toMoveIter =
end() - theCount;
499 while (toMoveIter != theOriginalEnd)
501 doPushBack(*toMoveIter);
507 XALAN_STD_QUALIFIER copy_backward(thePosition, theOriginalEnd - theCount, theOriginalEnd);
510 XALAN_STD_QUALIFIER fill(thePosition, thePosition + theCount, theData);
520 iterator thePosition,
521 const value_type& theData)
523 if (m_allocation > m_size)
525 insert(thePosition, 1, theData);
531 const size_type theDistance =
532 local_distance(
begin(), thePosition);
534 insert(thePosition, 1, theData);
536 return begin() + theDistance;
542 const_iterator theFirst,
543 const_iterator theLast)
566 const value_type& theData)
570 insert(theCount, theData);
586 return ~size_type(0);
592 const ConstructibleType defaultValue(*m_memoryManager);
594 resize(theSize, defaultValue.value);
600 const value_type& theValue)
604 if (m_size > theSize)
606 shrinkToSize(theSize);
608 else if (m_size < theSize)
613 assert(m_allocation >= theSize);
615 const value_type*
const theEnd = m_data + theSize;
618 for (value_type* data = endPointer();
622 Constructor::construct(data, theValue, *m_memoryManager);
626 assert(m_size == theSize);
644 return m_size == 0 ? true :
false;
652 if (theSize > m_allocation)
679 return m_data[m_size - 1];
685 return m_data[m_size - 1];
728 const_reverse_iterator
744 const_reverse_iterator
754 at(size_type theIndex)
756 if (theIndex >= m_size)
761 return m_data[theIndex];
765 at(size_type theIndex)
const 767 if (theIndex >= m_size)
772 return m_data[theIndex];
778 assert (theIndex < m_size);
780 return m_data[theIndex];
786 assert (theIndex < m_size);
788 return m_data[theIndex];
812 if (m_allocation < theRHS.m_size)
814 ThisType theTemp(theRHS,*m_memoryManager);
820 const_iterator theRHSCopyEnd = theRHS.
end();
822 if (m_size > theRHS.m_size)
825 shrinkToSize(theRHS.m_size);
827 else if (m_size < theRHS.m_size)
832 theRHS.
begin() + m_size;
841 XALAN_STD_QUALIFIER copy(
858 MemoryManager*
const theTempManager = m_memoryManager;
859 const size_type theTempLength = m_size;
860 const size_type theTempAllocation = m_allocation;
861 value_type*
const theTempData = m_data;
863 m_memoryManager = theOther.m_memoryManager;
864 m_size = theOther.m_size;
865 m_allocation = theOther.m_allocation;
866 m_data = theOther.m_data;
868 theOther.m_memoryManager = theTempManager;
869 theOther.m_size = theTempLength;
870 theOther.m_allocation = theTempAllocation;
871 theOther.m_data = theTempData;
879 assert (m_memoryManager != 0);
881 return *m_memoryManager;
887 assert (m_memoryManager != 0);
889 return *m_memoryManager;
902 value_type*
const theTemp = m_data;
920 assert(m_allocation >= m_size);
922 (m_data == 0 && m_allocation == 0) ||
923 (m_data != 0 && m_allocation != 0));
929 const_iterator theFirst,
930 const_iterator theLast)
934 assert(theFirst <= theLast);
936 #if defined(XALAN_HAS_STD_DISTANCE) 937 return XALAN_STD_QUALIFIER distance(theFirst, theLast);
941 XALAN_STD_QUALIFIER distance(theFirst, theLast, theDistance);
948 allocate(size_type
size)
950 const size_type theBytesNeeded = size *
sizeof(
value_type);
952 assert (m_memoryManager != 0);
954 void* pointer = m_memoryManager->allocate(theBytesNeeded);
956 assert(pointer != 0);
962 deallocate(value_type* pointer)
964 assert(m_memoryManager != 0);
966 m_memoryManager->deallocate(pointer);
971 destroy(value_type& theValue)
981 for(; theFirst != theLast; ++theFirst)
988 grow(
const value_type& data)
992 assert(m_size != 0 && m_size == m_allocation);
994 const size_type theNewSize =
size_type((m_size * 1.6) + 0.5);
995 assert(theNewSize > m_size);
997 ThisType theTemp(*
this, *m_memoryManager, theNewSize);
999 theTemp.doPushBack(data);
1007 construct_back(
const value_type& data)
1011 assert(m_size < m_allocation);
1013 Constructor::construct(
1024 init(
const value_type& data)
1028 assert(m_size == 0 && m_allocation == 0);
1030 m_data = allocate(1);
1034 construct_back(data);
1040 doPushBack(
const value_type& data)
1044 if (m_size < m_allocation)
1046 construct_back(data);
1048 else if (m_size == 0)
1061 ensureCapacity(size_type theSize)
1068 return endPointer();
1072 doReserve(size_type theSize)
1076 assert(theSize > m_allocation);
1078 ThisType theTemp(*
this, *m_memoryManager, theSize);
1088 return m_data + m_size;
1094 return m_data + m_size;
1100 throw XALAN_STD_QUALIFIER out_of_range(
"");
1104 shrinkToSize(size_type theSize)
1106 assert(m_size > theSize);
1111 }
while (m_size > theSize);
1115 shrinkCount(size_type theCount)
1117 assert(m_size >= theCount);
1119 while (theCount > 0)
1132 return theLHS > theRHS ? theLHS : theRHS;
1135 #if defined(XALAN_DEVELOPMENT) 1142 MemoryManager* m_memoryManager;
1146 size_type m_allocation;
1153 template <
class Type>
1159 theLHS.
swap(theRHS);
1164 template <
class Type>
1170 if (theLHS.
size() != theRHS.
size())
1174 else if (theLHS.
size() == 0)
1180 return XALAN_STD_QUALIFIER equal(theLHS.
begin(), theLHS.
end(), theRHS.
begin());
1186 template <
class Type>
1192 return !(theLHS == theRHS);
1197 template <
class Type>
1203 return XALAN_STD_QUALIFIER lexicographical_compare(
1212 template <
class Type>
1218 return !(theRHS < theLHS);
1223 template <
class Type>
1229 return theRHS < theLHS;
1234 template <
class Type>
1240 return !(theLHS < theRHS);
1245 #if defined(_MSC_VER) 1246 #pragma warning(pop) 1251 XALAN_CPP_NAMESPACE_END
1255 #endif // XALANVECTOR_HEADER_GUARD_1357924680
bool operator==(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
reference at(size_type theIndex)
const_iterator end() const
const value_type * const_iterator
void assign(const_iterator theFirst, const_iterator theLast)
reverse_iterator rbegin()
size_type capacity() const
MemoryManager & getMemoryManager()
const_reverse_iterator rbegin() const
void resize(size_type theSize, const value_type &theValue)
#define XALAN_DEFAULT_CONSTRUCTOR_MEMMGR
XalanVector< value_type, ConstructionTraits > ThisType
ThisType & operator=(const ThisType &theRHS)
const_reference operator[](size_type theIndex) const
bool operator<=(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
void resize(size_type theSize)
ConstructionTraits::Constructor Constructor
void insert(iterator thePosition, size_type theCount, const value_type &theData)
void push_back(const value_type &data)
const value_type & const_reference
XalanVector(const ThisType &theSource, MemoryManager &theManager XALAN_DEFAULT_CONSTRUCTOR_MEMMGR, size_type theInitialAllocation=size_type(0))
XalanVector(size_type theInsertSize, const value_type &theData, MemoryManager &theManager)
bool operator!=(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
iterator erase(iterator position)
void assign(iterator theFirst, iterator theLast)
XalanVector(const_iterator theFirst, const_iterator theLast, MemoryManager &theManager)
ptrdiff_t difference_type
void insert(iterator thePosition, const_iterator theFirst, const_iterator theLast)
iterator insert(iterator thePosition, const value_type &theData)
XALAN_STD_QUALIFIER reverse_iterator< iterator, value_type > reverse_iterator_
bool operator>=(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
void reserve(size_type theSize)
bool operator<(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
const_reverse_iterator_ const_reverse_iterator
iterator erase(iterator theFirst, iterator theLast)
reverse_iterator_ reverse_iterator
void assign(size_type theCount, const value_type &theData)
bool operator>(const XalanVector< Type > &theLHS, const XalanVector< Type > &theRHS)
const MemoryManager & getMemoryManager() const
const_iterator begin() const
const value_type * const_pointer
static XalanVector * create(const_iterator theFirst, const_iterator theLast, MemoryManager &theManager)
void swap(ThisType &theOther)
static XalanVector * create(MemoryManager &theManager, size_type initialAllocation=size_type(0))
Constructor::ConstructableType ConstructibleType
const_reference at(size_type theIndex) const
XalanVector(MemoryManager &theManager XALAN_DEFAULT_CONSTRUCTOR_MEMMGR, size_type initialAllocation=size_type(0))
XALAN_CPP_NAMESPACE_BEGIN XALAN_USING_XERCES(Locator)
const_reference back() const
XALAN_STD_QUALIFIER reverse_iterator< const_iterator, value_type, const_reference > const_reverse_iterator_
const_reference front() const
const_reverse_iterator rend() const
reference operator[](size_type theIndex)
size_type max_size() const