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 #ifndef _BPARR_HXX 29 #define _BPARR_HXX 30 31 #include <tools/solar.h> 32 #include <tools/debug.hxx> 33 34 #include <deque> 35 36 class BigPtrArray; 37 38 /** Base class for container entries 39 */ 40 class BigPtrEntry 41 { 42 friend class BigPtrArray; 43 BigPtrArray* pBigPtrArray_; 44 sal_uLong pos_; 45 46 protected: 47 BigPtrEntry() : pBigPtrArray_(0), pos_(0) 48 {} 49 50 virtual ~BigPtrEntry() 51 {} 52 53 sal_uLong GetPos() const 54 { 55 return pos_; 56 } 57 58 BigPtrArray& GetArray() const 59 { 60 return *pBigPtrArray_; 61 } 62 }; 63 64 typedef BigPtrEntry* ElementPtr; 65 typedef sal_Bool (*FnForEach)(const ElementPtr&, void* pArgs); 66 67 /** A container abstraction 68 */ 69 class BigPtrArray 70 { 71 public: 72 typedef std::deque<ElementPtr> Container_t; 73 74 public: 75 /** 76 */ 77 BigPtrArray(); 78 79 /** Return the number of entries inserted 80 into the array 81 */ 82 sal_uLong Count() const; 83 84 /** Insert an Element into the array at a certain 85 position 86 87 @param rElem 88 [in] the element 89 90 @param pos 91 [in] the position where to insert the element. 92 93 @pre (pos >= 0 && pos <= BigPtrArray.Count()) 94 @post (((oldCount + 1) == BigPtrArray.Count()) && BigPtrArray[pos] == rElem) 95 */ 96 void Insert(const ElementPtr& rElem, sal_uLong pos); 97 98 /** Remove a specified number of elements starting at a certain position. 99 100 @param pos 101 [in] the position where to start removing elements 102 103 @param n 104 [in] the number of elements to remove 105 106 @pre (pos < BigPtrArray.Count() && n <= BigPtrArray.Count()) 107 @post ((oldCount - n) == BigPtrArray.Count()) 108 */ 109 void Remove(sal_uLong pos, sal_uLong n = 1); 110 111 /** Move an entry from a certain position to another on. 112 113 @param from 114 [in] 115 116 @param to 117 [in] 118 */ 119 void Move(sal_uLong fromPos, sal_uLong toPos); 120 121 /** Replace an entry at a certain position 122 123 @param pos 124 [in] the position of the entry 125 126 @param rElem 127 [in] the new entry 128 129 @pre pos < BigPtrArray.Count() 130 @post (oldCount == BigPtrArray.Count() && BigPtrArray[pos] == rElem) 131 */ 132 void Replace(sal_uLong pos, const ElementPtr& rElem); 133 134 /** Get the entry at a certain index 135 136 @param pos 137 [in] the position of the entry 138 139 @pre pos < BigPtrArray.Count() 140 */ 141 ElementPtr operator[](sal_uLong pos) const; 142 143 /** 144 */ 145 void ForEach(FnForEach fn, void* pArgs = NULL); 146 147 /** 148 */ 149 void ForEach(sal_uLong fromPos, sal_uLong toPos, FnForEach fn, void* pArgs = NULL); 150 151 private: 152 153 void FixElementIndizes(Container_t::const_iterator begin, Container_t::const_iterator end) const; 154 155 private: 156 Container_t container_; 157 }; 158 159 #endif 160