xref: /trunk/main/sw/qa/core/bigpointerarray-new.cxx (revision efeef26f)
1*efeef26fSAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*efeef26fSAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*efeef26fSAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*efeef26fSAndrew Rist  * distributed with this work for additional information
6*efeef26fSAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*efeef26fSAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*efeef26fSAndrew Rist  * "License"); you may not use this file except in compliance
9*efeef26fSAndrew Rist  * with the License.  You may obtain a copy of the License at
10*efeef26fSAndrew Rist  *
11*efeef26fSAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*efeef26fSAndrew Rist  *
13*efeef26fSAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*efeef26fSAndrew Rist  * software distributed under the License is distributed on an
15*efeef26fSAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*efeef26fSAndrew Rist  * KIND, either express or implied.  See the License for the
17*efeef26fSAndrew Rist  * specific language governing permissions and limitations
18*efeef26fSAndrew Rist  * under the License.
19*efeef26fSAndrew Rist  *
20*efeef26fSAndrew Rist  *************************************************************/
21*efeef26fSAndrew Rist 
22*efeef26fSAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_sw.hxx"
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include "bparr.hxx"
28cdf0e10cSrcweir #include <algorithm>
29cdf0e10cSrcweir 
BigPtrArray()30cdf0e10cSrcweir BigPtrArray::BigPtrArray()
31cdf0e10cSrcweir {
32cdf0e10cSrcweir     //container_.reserve(1000);
33cdf0e10cSrcweir }
34cdf0e10cSrcweir 
Count() const35cdf0e10cSrcweir sal_uLong BigPtrArray::Count() const
36cdf0e10cSrcweir {
37cdf0e10cSrcweir     return container_.size();
38cdf0e10cSrcweir }
39cdf0e10cSrcweir 
Move(sal_uLong fromPos,sal_uLong toPos)40cdf0e10cSrcweir void BigPtrArray::Move(sal_uLong fromPos, sal_uLong toPos)
41cdf0e10cSrcweir {
42cdf0e10cSrcweir 	DBG_ASSERT(fromPos < container_.size() && toPos < container_.size(), "BigPtrArray.Move precondition violation");
43cdf0e10cSrcweir     Insert(container_[fromPos], toPos);
44cdf0e10cSrcweir     Remove(toPos < fromPos ? fromPos + 1 : fromPos, 1);
45cdf0e10cSrcweir }
46cdf0e10cSrcweir 
ForEach(sal_uLong fromPos,sal_uLong toPos,FnForEach fn,void * pArgs)47cdf0e10cSrcweir void BigPtrArray::ForEach(sal_uLong fromPos, sal_uLong toPos, FnForEach fn, void* pArgs)
48cdf0e10cSrcweir {
49cdf0e10cSrcweir     DBG_ASSERT(fromPos < toPos && fromPos < container_.size() && toPos < container_.size(), "BigPtrArray::ForEach precondition violation");
50cdf0e10cSrcweir     Container_t::const_iterator iter = container_.begin() + fromPos;
51cdf0e10cSrcweir     Container_t::const_iterator iter_end = container_.begin() + toPos;
52cdf0e10cSrcweir     for (/*no init*/; iter != iter_end; ++iter)
53cdf0e10cSrcweir         fn(*iter, pArgs);
54cdf0e10cSrcweir }
55cdf0e10cSrcweir 
ForEach(FnForEach fn,void * pArgs)56cdf0e10cSrcweir void BigPtrArray::ForEach(FnForEach fn, void* pArgs)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir     Container_t::const_iterator iter = container_.begin();
59cdf0e10cSrcweir     Container_t::const_iterator iter_end = container_.end();
60cdf0e10cSrcweir     for ( /*no init*/; iter != iter_end; ++iter)
61cdf0e10cSrcweir         fn(*iter, pArgs);
62cdf0e10cSrcweir }
63cdf0e10cSrcweir 
operator [](sal_uLong pos) const64cdf0e10cSrcweir ElementPtr BigPtrArray::operator[](sal_uLong pos) const
65cdf0e10cSrcweir {
66cdf0e10cSrcweir     DBG_ASSERT(pos < container_.size(), "BigPtrArray::operator[] precondition violation");
67cdf0e10cSrcweir     return container_[pos];
68cdf0e10cSrcweir }
69cdf0e10cSrcweir 
Insert(const ElementPtr & rElem,sal_uLong pos)70cdf0e10cSrcweir void BigPtrArray::Insert(const ElementPtr& rElem, sal_uLong pos)
71cdf0e10cSrcweir {
72cdf0e10cSrcweir     DBG_ASSERT(pos <= container_.size(), "BigPtrArray::Insert precondition violation");
73cdf0e10cSrcweir 
74cdf0e10cSrcweir     rElem->pBigPtrArray_ = this;
75cdf0e10cSrcweir     rElem->pos_ = pos;
76cdf0e10cSrcweir 
77cdf0e10cSrcweir     if (pos == container_.size())
78cdf0e10cSrcweir         container_.push_back(rElem);
79cdf0e10cSrcweir     else
80cdf0e10cSrcweir     {
81cdf0e10cSrcweir         container_.insert(container_.begin() + pos, rElem);
82cdf0e10cSrcweir         FixElementIndizes(container_.begin(), container_.end());
83cdf0e10cSrcweir     }
84cdf0e10cSrcweir }
85cdf0e10cSrcweir 
Remove(sal_uLong pos,sal_uLong n)86cdf0e10cSrcweir void BigPtrArray::Remove( sal_uLong pos, sal_uLong n )
87cdf0e10cSrcweir {
88cdf0e10cSrcweir     DBG_ASSERT((pos < container_.size()) && ((container_.begin() + pos + n) < container_.end()), "BigPtrArray.Remove precondition violation")
89cdf0e10cSrcweir     container_.erase(container_.begin() + pos, container_.begin() + pos + n);
90cdf0e10cSrcweir     FixElementIndizes(container_.begin(), container_.end());
91cdf0e10cSrcweir }
92cdf0e10cSrcweir 
Replace(sal_uLong pos,const ElementPtr & rElem)93cdf0e10cSrcweir void BigPtrArray::Replace(sal_uLong pos, const ElementPtr& rElem)
94cdf0e10cSrcweir {
95cdf0e10cSrcweir     DBG_ASSERT(pos < container_.size(), "BigPtrArray::Replace precondition violation");
96cdf0e10cSrcweir     rElem->pBigPtrArray_ = this;
97cdf0e10cSrcweir     rElem->pos_ = pos;
98cdf0e10cSrcweir     container_[pos] = rElem;
99cdf0e10cSrcweir }
100cdf0e10cSrcweir 
FixElementIndizes(Container_t::const_iterator begin,Container_t::const_iterator end) const101cdf0e10cSrcweir void BigPtrArray::FixElementIndizes(Container_t::const_iterator begin, Container_t::const_iterator end) const
102cdf0e10cSrcweir {
103cdf0e10cSrcweir     Container_t::const_iterator iter = begin;
104cdf0e10cSrcweir     for (int i = 0; iter != end; ++iter, i++)
105cdf0e10cSrcweir         (*iter)->pos_ = i;
106cdf0e10cSrcweir }
107