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