1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 // MARKER(update_precomp.py): autogen include statement, do not remove 29 #include "precompiled_sw.hxx" 30 31 #include "bparr.hxx" 32 #include <algorithm> 33 34 BigPtrArray::BigPtrArray() 35 { 36 //container_.reserve(1000); 37 } 38 39 sal_uLong BigPtrArray::Count() const 40 { 41 return container_.size(); 42 } 43 44 void BigPtrArray::Move(sal_uLong fromPos, sal_uLong toPos) 45 { 46 DBG_ASSERT(fromPos < container_.size() && toPos < container_.size(), "BigPtrArray.Move precondition violation"); 47 Insert(container_[fromPos], toPos); 48 Remove(toPos < fromPos ? fromPos + 1 : fromPos, 1); 49 } 50 51 void BigPtrArray::ForEach(sal_uLong fromPos, sal_uLong toPos, FnForEach fn, void* pArgs) 52 { 53 DBG_ASSERT(fromPos < toPos && fromPos < container_.size() && toPos < container_.size(), "BigPtrArray::ForEach precondition violation"); 54 Container_t::const_iterator iter = container_.begin() + fromPos; 55 Container_t::const_iterator iter_end = container_.begin() + toPos; 56 for (/*no init*/; iter != iter_end; ++iter) 57 fn(*iter, pArgs); 58 } 59 60 void BigPtrArray::ForEach(FnForEach fn, void* pArgs) 61 { 62 Container_t::const_iterator iter = container_.begin(); 63 Container_t::const_iterator iter_end = container_.end(); 64 for ( /*no init*/; iter != iter_end; ++iter) 65 fn(*iter, pArgs); 66 } 67 68 ElementPtr BigPtrArray::operator[](sal_uLong pos) const 69 { 70 DBG_ASSERT(pos < container_.size(), "BigPtrArray::operator[] precondition violation"); 71 return container_[pos]; 72 } 73 74 void BigPtrArray::Insert(const ElementPtr& rElem, sal_uLong pos) 75 { 76 DBG_ASSERT(pos <= container_.size(), "BigPtrArray::Insert precondition violation"); 77 78 rElem->pBigPtrArray_ = this; 79 rElem->pos_ = pos; 80 81 if (pos == container_.size()) 82 container_.push_back(rElem); 83 else 84 { 85 container_.insert(container_.begin() + pos, rElem); 86 FixElementIndizes(container_.begin(), container_.end()); 87 } 88 } 89 90 void BigPtrArray::Remove( sal_uLong pos, sal_uLong n ) 91 { 92 DBG_ASSERT((pos < container_.size()) && ((container_.begin() + pos + n) < container_.end()), "BigPtrArray.Remove precondition violation") 93 container_.erase(container_.begin() + pos, container_.begin() + pos + n); 94 FixElementIndizes(container_.begin(), container_.end()); 95 } 96 97 void BigPtrArray::Replace(sal_uLong pos, const ElementPtr& rElem) 98 { 99 DBG_ASSERT(pos < container_.size(), "BigPtrArray::Replace precondition violation"); 100 rElem->pBigPtrArray_ = this; 101 rElem->pos_ = pos; 102 container_[pos] = rElem; 103 } 104 105 void BigPtrArray::FixElementIndizes(Container_t::const_iterator begin, Container_t::const_iterator end) const 106 { 107 Container_t::const_iterator iter = begin; 108 for (int i = 0; iter != end; ++iter, i++) 109 (*iter)->pos_ = i; 110 } 111