merge the formfield patch from ooo-build
[ooovba.git] / sw / qa / core / bigpointerarray-new.cxx
blobf687ab9ff3f7fb4e072e62c079cc31e61f24835a
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: bigpointerarray-new.cxx,v $
10 * $Revision: 1.4 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
34 #include "bparr.hxx"
35 #include <algorithm>
37 BigPtrArray::BigPtrArray()
39 //container_.reserve(1000);
42 ULONG BigPtrArray::Count() const
44 return container_.size();
47 void BigPtrArray::Move(ULONG fromPos, ULONG toPos)
49 DBG_ASSERT(fromPos < container_.size() && toPos < container_.size(), "BigPtrArray.Move precondition violation");
50 Insert(container_[fromPos], toPos);
51 Remove(toPos < fromPos ? fromPos + 1 : fromPos, 1);
54 void BigPtrArray::ForEach(ULONG fromPos, ULONG toPos, FnForEach fn, void* pArgs)
56 DBG_ASSERT(fromPos < toPos && fromPos < container_.size() && toPos < container_.size(), "BigPtrArray::ForEach precondition violation");
57 Container_t::const_iterator iter = container_.begin() + fromPos;
58 Container_t::const_iterator iter_end = container_.begin() + toPos;
59 for (/*no init*/; iter != iter_end; ++iter)
60 fn(*iter, pArgs);
63 void BigPtrArray::ForEach(FnForEach fn, void* pArgs)
65 Container_t::const_iterator iter = container_.begin();
66 Container_t::const_iterator iter_end = container_.end();
67 for ( /*no init*/; iter != iter_end; ++iter)
68 fn(*iter, pArgs);
71 ElementPtr BigPtrArray::operator[](ULONG pos) const
73 DBG_ASSERT(pos < container_.size(), "BigPtrArray::operator[] precondition violation");
74 return container_[pos];
77 void BigPtrArray::Insert(const ElementPtr& rElem, ULONG pos)
79 DBG_ASSERT(pos <= container_.size(), "BigPtrArray::Insert precondition violation");
81 rElem->pBigPtrArray_ = this;
82 rElem->pos_ = pos;
84 if (pos == container_.size())
85 container_.push_back(rElem);
86 else
88 container_.insert(container_.begin() + pos, rElem);
89 FixElementIndizes(container_.begin(), container_.end());
93 void BigPtrArray::Remove( ULONG pos, ULONG n )
95 DBG_ASSERT((pos < container_.size()) && ((container_.begin() + pos + n) < container_.end()), "BigPtrArray.Remove precondition violation")
96 container_.erase(container_.begin() + pos, container_.begin() + pos + n);
97 FixElementIndizes(container_.begin(), container_.end());
100 void BigPtrArray::Replace(ULONG pos, const ElementPtr& rElem)
102 DBG_ASSERT(pos < container_.size(), "BigPtrArray::Replace precondition violation");
103 rElem->pBigPtrArray_ = this;
104 rElem->pos_ = pos;
105 container_[pos] = rElem;
108 void BigPtrArray::FixElementIndizes(Container_t::const_iterator begin, Container_t::const_iterator end) const
110 Container_t::const_iterator iter = begin;
111 for (int i = 0; iter != end; ++iter, i++)
112 (*iter)->pos_ = i;