22 #if !defined(XALANVECTOR_HEADER_GUARD_1357924680)
23 #define XALANVECTOR_HEADER_GUARD_1357924680
46 XALAN_CPP_NAMESPACE_BEGIN
51 #pragma warning(disable: 4100)
56 XALAN_USING_XERCES(MemoryManager)
74 #if defined(XALAN_VCPP_USE_PTRIT)
95 #if defined(XALAN_HAS_STD_ITERATORS)
98 #elif defined(XALAN_RW_NO_CLASS_PARTIAL_SPEC)
101 XALAN_STD_QUALIFIER random_access_iterator_tag,
102 value_type> reverse_iterator_;
105 XALAN_STD_QUALIFIER random_access_iterator_tag,
106 const value_type> const_reverse_iterator_;
122 size_type initialAllocation =
size_type(0)) :
123 m_memoryManager(&theManager),
125 m_allocation(initialAllocation),
126 m_data(initialAllocation > 0 ? allocate(initialAllocation) : 0)
133 MemoryManager& theManager,
134 size_type initialAllocation =
size_type(0))
136 typedef XalanVector ThisType;
140 ThisType* theResult = theGuard.
get();
142 new (theResult) ThisType(theManager, initialAllocation);
150 const ThisType& theSource,
151 MemoryManager& theManager XALAN_DEFAULT_CONSTRUCTOR_MEMORY_MGR,
152 size_type theInitialAllocation =
size_type(0)) :
153 m_memoryManager(&theManager),
158 if (theSource.m_size > 0)
160 ThisType theTemp(theManager, local_max(theSource.m_size, theInitialAllocation));
167 else if (theInitialAllocation > 0)
169 m_data = allocate(theInitialAllocation);
171 m_allocation = theInitialAllocation;
178 const_iterator theFirst,
179 const_iterator theLast,
180 MemoryManager& theManager) :
181 m_memoryManager(&theManager),
187 ThisType theTemp(theManager);
189 theTemp.
insert(theTemp.
begin(), theFirst, theLast);
198 const_iterator theFirst,
199 const_iterator theLast,
200 MemoryManager& theManager)
202 typedef XalanVector ThisType;
206 ThisType* theResult = theGuard.
get();
208 new (theResult) ThisType(theFirst, theLast, theManager);
216 size_type theInsertSize,
217 const value_type& theData,
218 MemoryManager& theManager) :
219 m_memoryManager(&theManager),
224 ThisType theTemp(theManager);
226 theTemp.
insert(theTemp.
begin(), theInsertSize, theData);
237 if (m_allocation != 0)
239 destroy(begin(), end());
262 destroy(m_data[m_size]);
274 if (theFirst != theLast)
276 XALAN_STD_QUALIFIER copy(
281 shrinkCount(local_distance(theFirst, theLast));
292 return erase(position, position + 1);
297 iterator thePosition,
298 const_iterator theFirst,
299 const_iterator theLast)
303 assert(theFirst <= theLast);
304 assert(thePosition >= begin());
305 assert(thePosition <= end());
309 const size_type theInsertSize =
310 local_distance(theFirst, theLast);
312 if (theInsertSize == 0)
317 const size_type theTotalSize = size() + theInsertSize;
319 if (thePosition == end())
321 pointer thePointer = ensureCapacity(theTotalSize);
323 while (theFirst != theLast)
325 Constructor::construct(thePointer, *theFirst, *m_memoryManager);
334 if (theTotalSize > capacity())
336 assert (m_memoryManager != 0);
338 ThisType theTemp(*m_memoryManager, theTotalSize);
341 theTemp.
insert(theTemp.
end(), begin(), thePosition);
344 theTemp.
insert(theTemp.
end(), theFirst, theLast);
347 theTemp.
insert(theTemp.
end(), thePosition, end());
354 const iterator theOriginalEnd = end();
356 const size_type theRightSplitSize =
357 local_distance(thePosition, theOriginalEnd);
359 if (theRightSplitSize <= theInsertSize)
365 const const_iterator toInsertSplit = theFirst + theRightSplitSize;
366 const_iterator toInsertIter = toInsertSplit;
368 while (toInsertIter != theLast)
370 doPushBack(*toInsertIter);
376 toInsertIter = thePosition;
377 while (toInsertIter != theOriginalEnd)
379 doPushBack(*toInsertIter);
386 XALAN_STD_QUALIFIER copy(theFirst, toInsertSplit, thePosition);
393 const_iterator toMoveIter = end() - theInsertSize;
395 while (toMoveIter != theOriginalEnd)
397 doPushBack(*toMoveIter);
403 XALAN_STD_QUALIFIER copy_backward(thePosition, theOriginalEnd - theInsertSize, theOriginalEnd);
406 XALAN_STD_QUALIFIER copy(theFirst, theLast, thePosition);
416 iterator thePosition,
418 const value_type& theData)
422 const size_type theTotalSize = size() + theCount;
425 if (thePosition == end())
427 pointer thePointer = ensureCapacity(theTotalSize);
429 for (size_type index = 0; index < theCount; ++index)
431 Constructor::construct(thePointer, theData, *m_memoryManager);
439 if (theTotalSize > capacity())
441 assert ( m_memoryManager != 0 );
443 ThisType theTemp(*m_memoryManager, theTotalSize);
446 theTemp.
insert(theTemp.
end(), begin(), thePosition);
449 theTemp.
insert(theTemp.
end(), theCount, theData);
452 theTemp.
insert(theTemp.
end(), thePosition, end());
459 const iterator theOriginalEnd = end();
461 const size_type theRightSplitSize =
462 local_distance(thePosition, theOriginalEnd);
464 if (theRightSplitSize <= theCount)
470 for (size_type i = 0; i < (theCount - theRightSplitSize); ++i)
476 iterator toInsertIter = thePosition;
478 while (toInsertIter != theOriginalEnd)
480 doPushBack(*toInsertIter);
487 XALAN_STD_QUALIFIER fill(thePosition, thePosition + theRightSplitSize, theData);
494 const_iterator toMoveIter = end() - theCount;
496 while (toMoveIter != theOriginalEnd)
498 doPushBack(*toMoveIter);
504 XALAN_STD_QUALIFIER copy_backward(thePosition, theOriginalEnd - theCount, theOriginalEnd);
507 XALAN_STD_QUALIFIER fill(thePosition, thePosition + theCount, theData);
517 iterator thePosition,
518 const value_type& theData)
520 if (m_allocation > m_size)
522 insert(thePosition, 1, theData);
528 const size_type theDistance =
529 local_distance(begin(), thePosition);
531 insert(thePosition, 1, theData);
533 return begin() + theDistance;
539 const_iterator theFirst,
540 const_iterator theLast)
556 const_iterator(theFirst),
557 const_iterator(theLast));
563 const value_type& theData)
567 insert(theCount, theData);
583 return ~size_type(0);
589 const ConstructibleType defaultValue(*m_memoryManager);
591 resize(theSize, defaultValue.
value);
596 const value_type& theValue)
600 if (m_size > theSize)
602 shrinkToSize(theSize);
604 else if (m_size < theSize)
609 assert(m_allocation >= theSize);
611 const value_type*
const theEnd = m_data + theSize;
614 for (value_type* data = endPointer();
618 Constructor::construct(data, theValue, *m_memoryManager);
622 assert(m_size == theSize);
640 return m_size == 0 ?
true :
false;
648 if (theSize > m_allocation)
675 return m_data[m_size - 1];
681 return m_data[m_size - 1];
721 return reverse_iterator(end());
724 const_reverse_iterator
729 return const_reverse_iterator(end());
737 return reverse_iterator(begin());
740 const_reverse_iterator
745 return const_reverse_iterator(begin());
750 at(size_type theIndex)
752 if (theIndex >= m_size)
757 return m_data[theIndex];
761 at(size_type theIndex)
const
763 if (theIndex >= m_size)
768 return m_data[theIndex];
774 assert (theIndex < m_size);
776 return m_data[theIndex];
782 assert (theIndex < m_size);
784 return m_data[theIndex];
808 if (m_allocation < theRHS.m_size)
810 ThisType theTemp(theRHS,*m_memoryManager);
816 const_iterator theRHSCopyEnd = theRHS.
end();
818 if (m_size > theRHS.m_size)
821 shrinkToSize(theRHS.m_size);
823 else if (m_size < theRHS.m_size)
826 theRHS.
begin() + m_size;
835 XALAN_STD_QUALIFIER copy(
852 MemoryManager*
const theTempManager = m_memoryManager;
853 const size_type theTempLength = m_size;
854 const size_type theTempAllocation = m_allocation;
855 value_type*
const theTempData = m_data;
857 m_memoryManager = theOther.m_memoryManager;
858 m_size = theOther.m_size;
859 m_allocation = theOther.m_allocation;
860 m_data = theOther.m_data;
862 theOther.m_memoryManager = theTempManager;
863 theOther.m_size = theTempLength;
864 theOther.m_allocation = theTempAllocation;
865 theOther.m_data = theTempData;
873 return m_memoryManager;
879 assert (m_memoryManager != 0);
881 return *m_memoryManager;
894 value_type*
const theTemp = m_data;
912 assert(m_allocation >= m_size);
913 assert(m_data == 0 && m_allocation == 0 || m_data != 0 && m_allocation != 0);
919 const_iterator theFirst,
920 const_iterator theLast)
924 assert(theFirst <= theLast);
926 #if defined(XALAN_HAS_STD_DISTANCE)
927 return XALAN_STD_QUALIFIER distance(theFirst, theLast);
929 size_type theDistance;
931 XALAN_STD_QUALIFIER distance(theFirst, theLast, theDistance);
938 allocate(size_type size)
940 const size_type theBytesNeeded = size *
sizeof(value_type);
942 assert (m_memoryManager != 0);
944 void* pointer = m_memoryManager->allocate(theBytesNeeded);
946 assert(pointer != 0);
948 return (value_type*) pointer;
952 deallocate(value_type* pointer)
954 assert(m_memoryManager != 0);
956 m_memoryManager->deallocate(pointer);
961 destroy(value_type& theValue)
971 for(; theFirst != theLast; ++theFirst)
978 doPushBack(
const value_type& data)
982 if (m_size < m_allocation)
984 Constructor::construct(endPointer(), data, *m_memoryManager);
990 assert(m_size == m_allocation);
992 const size_type theNewSize = m_size == 0 ? 1 :
size_type((m_size * 1.6) + 0.5);
993 assert(theNewSize > m_size);
995 ThisType theTemp(*
this, *m_memoryManager, theNewSize);
997 theTemp.doPushBack(data);
1006 ensureCapacity(size_type theSize)
1008 if (theSize > capacity())
1013 return endPointer();
1017 doReserve(size_type theSize)
1021 assert(theSize > m_allocation);
1023 ThisType theTemp(*
this, *m_memoryManager, theSize);
1033 return m_data + m_size;
1039 return m_data + m_size;
1045 throw XALAN_STD_QUALIFIER out_of_range(
"");
1049 shrinkToSize(size_type theSize)
1051 assert(m_size > theSize);
1056 }
while (m_size > theSize);
1060 shrinkCount(size_type theCount)
1062 assert(m_size >= theCount);
1064 while (theCount > 0)
1077 return theLHS > theRHS ? theLHS : theRHS;
1080 #if defined(XALAN_DEVELOPMENT)
1082 XalanVector(
const XalanVector&);
1087 MemoryManager* m_memoryManager;
1091 size_type m_allocation;
1098 template <
class Type>
1104 theLHS.
swap(theRHS);
1109 template <
class Type>
1115 if (theLHS.
size() != theRHS.
size())
1119 else if (theLHS.
size() == 0)
1125 return XALAN_STD_QUALIFIER equal(theLHS.
begin(), theLHS.
end(), theRHS.
begin());
1131 template <
class Type>
1137 return !(theLHS == theRHS);
1142 template <
class Type>
1148 return XALAN_STD_QUALIFIER lexicographical_compare(
1157 template <
class Type>
1163 return !(theRHS < theLHS);
1168 template <
class Type>
1174 return theRHS < theLHS;
1179 template <
class Type>
1185 return !(theLHS < theRHS);
1190 #if defined(_MSC_VER)
1191 #pragma warning(pop)
1196 XALAN_CPP_NAMESPACE_END
1200 #endif // XALANVECTOR_HEADER_GUARD_1357924680