xref: /aoo41x/main/sw/qa/core/bigpointerarray-new.hxx (revision 1d2dbeb0)
1*1d2dbeb0SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*1d2dbeb0SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*1d2dbeb0SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*1d2dbeb0SAndrew Rist  * distributed with this work for additional information
6*1d2dbeb0SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*1d2dbeb0SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*1d2dbeb0SAndrew Rist  * "License"); you may not use this file except in compliance
9*1d2dbeb0SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*1d2dbeb0SAndrew Rist  *
11*1d2dbeb0SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*1d2dbeb0SAndrew Rist  *
13*1d2dbeb0SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*1d2dbeb0SAndrew Rist  * software distributed under the License is distributed on an
15*1d2dbeb0SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*1d2dbeb0SAndrew Rist  * KIND, either express or implied.  See the License for the
17*1d2dbeb0SAndrew Rist  * specific language governing permissions and limitations
18*1d2dbeb0SAndrew Rist  * under the License.
19*1d2dbeb0SAndrew Rist  *
20*1d2dbeb0SAndrew Rist  *************************************************************/
21*1d2dbeb0SAndrew Rist 
22*1d2dbeb0SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef _BPARR_HXX
25cdf0e10cSrcweir #define _BPARR_HXX
26cdf0e10cSrcweir 
27cdf0e10cSrcweir #include <tools/solar.h>
28cdf0e10cSrcweir #include <tools/debug.hxx>
29cdf0e10cSrcweir 
30cdf0e10cSrcweir #include <deque>
31cdf0e10cSrcweir 
32cdf0e10cSrcweir class BigPtrArray;
33cdf0e10cSrcweir 
34cdf0e10cSrcweir /** Base class for container entries
35cdf0e10cSrcweir */
36cdf0e10cSrcweir class BigPtrEntry
37cdf0e10cSrcweir {
38cdf0e10cSrcweir 	friend class BigPtrArray;
39cdf0e10cSrcweir 	BigPtrArray* pBigPtrArray_;
40cdf0e10cSrcweir     sal_uLong pos_;
41cdf0e10cSrcweir 
42cdf0e10cSrcweir protected:
BigPtrEntry()43cdf0e10cSrcweir 	BigPtrEntry() : pBigPtrArray_(0), pos_(0)
44cdf0e10cSrcweir     {}
45cdf0e10cSrcweir 
~BigPtrEntry()46cdf0e10cSrcweir 	virtual ~BigPtrEntry()
47cdf0e10cSrcweir     {}
48cdf0e10cSrcweir 
GetPos() const49cdf0e10cSrcweir 	sal_uLong GetPos() const
50cdf0e10cSrcweir     {
51cdf0e10cSrcweir         return pos_;
52cdf0e10cSrcweir     }
53cdf0e10cSrcweir 
GetArray() const54cdf0e10cSrcweir 	BigPtrArray& GetArray() const
55cdf0e10cSrcweir     {
56cdf0e10cSrcweir         return *pBigPtrArray_;
57cdf0e10cSrcweir     }
58cdf0e10cSrcweir };
59cdf0e10cSrcweir 
60cdf0e10cSrcweir typedef BigPtrEntry* ElementPtr;
61cdf0e10cSrcweir typedef sal_Bool (*FnForEach)(const ElementPtr&, void* pArgs);
62cdf0e10cSrcweir 
63cdf0e10cSrcweir /** A container abstraction
64cdf0e10cSrcweir */
65cdf0e10cSrcweir class BigPtrArray
66cdf0e10cSrcweir {
67cdf0e10cSrcweir public:
68cdf0e10cSrcweir     typedef std::deque<ElementPtr> Container_t;
69cdf0e10cSrcweir 
70cdf0e10cSrcweir public:
71cdf0e10cSrcweir     /**
72cdf0e10cSrcweir     */
73cdf0e10cSrcweir 	BigPtrArray();
74cdf0e10cSrcweir 
75cdf0e10cSrcweir     /** Return the number of entries inserted
76cdf0e10cSrcweir         into the array
77cdf0e10cSrcweir     */
78cdf0e10cSrcweir 	sal_uLong Count() const;
79cdf0e10cSrcweir 
80cdf0e10cSrcweir     /** Insert an Element into the array at a certain
81cdf0e10cSrcweir         position
82cdf0e10cSrcweir 
83cdf0e10cSrcweir         @param rElem
84cdf0e10cSrcweir         [in] the element
85cdf0e10cSrcweir 
86cdf0e10cSrcweir         @param pos
87cdf0e10cSrcweir         [in] the position where to insert the element.
88cdf0e10cSrcweir 
89cdf0e10cSrcweir         @pre (pos >= 0 && pos <= BigPtrArray.Count())
90cdf0e10cSrcweir         @post (((oldCount + 1) == BigPtrArray.Count()) && BigPtrArray[pos] == rElem)
91cdf0e10cSrcweir     */
92cdf0e10cSrcweir 	void Insert(const ElementPtr& rElem, sal_uLong pos);
93cdf0e10cSrcweir 
94cdf0e10cSrcweir     /** Remove a specified number of elements starting at a certain position.
95cdf0e10cSrcweir 
96cdf0e10cSrcweir         @param pos
97cdf0e10cSrcweir         [in] the position where to start removing elements
98cdf0e10cSrcweir 
99cdf0e10cSrcweir         @param n
100cdf0e10cSrcweir         [in] the number of elements to remove
101cdf0e10cSrcweir 
102cdf0e10cSrcweir         @pre (pos < BigPtrArray.Count() && n <= BigPtrArray.Count())
103cdf0e10cSrcweir         @post ((oldCount - n) == BigPtrArray.Count())
104cdf0e10cSrcweir     */
105cdf0e10cSrcweir 	void Remove(sal_uLong pos, sal_uLong n = 1);
106cdf0e10cSrcweir 
107cdf0e10cSrcweir     /** Move an entry from a certain position to another on.
108cdf0e10cSrcweir 
109cdf0e10cSrcweir         @param from
110cdf0e10cSrcweir         [in]
111cdf0e10cSrcweir 
112cdf0e10cSrcweir         @param to
113cdf0e10cSrcweir         [in]
114cdf0e10cSrcweir     */
115cdf0e10cSrcweir 	void Move(sal_uLong fromPos, sal_uLong toPos);
116cdf0e10cSrcweir 
117cdf0e10cSrcweir     /** Replace an entry at a certain position
118cdf0e10cSrcweir 
119cdf0e10cSrcweir         @param pos
120cdf0e10cSrcweir         [in] the position of the entry
121cdf0e10cSrcweir 
122cdf0e10cSrcweir         @param rElem
123cdf0e10cSrcweir         [in] the new entry
124cdf0e10cSrcweir 
125cdf0e10cSrcweir         @pre pos < BigPtrArray.Count()
126cdf0e10cSrcweir         @post (oldCount == BigPtrArray.Count() && BigPtrArray[pos] == rElem)
127cdf0e10cSrcweir     */
128cdf0e10cSrcweir 	void Replace(sal_uLong pos, const ElementPtr& rElem);
129cdf0e10cSrcweir 
130cdf0e10cSrcweir     /** Get the entry at a certain index
131cdf0e10cSrcweir 
132cdf0e10cSrcweir         @param pos
133cdf0e10cSrcweir         [in] the position of the entry
134cdf0e10cSrcweir 
135cdf0e10cSrcweir         @pre pos < BigPtrArray.Count()
136cdf0e10cSrcweir     */
137cdf0e10cSrcweir 	ElementPtr operator[](sal_uLong pos) const;
138cdf0e10cSrcweir 
139cdf0e10cSrcweir     /**
140cdf0e10cSrcweir     */
141cdf0e10cSrcweir 	void ForEach(FnForEach fn, void* pArgs = NULL);
142cdf0e10cSrcweir 
143cdf0e10cSrcweir     /**
144cdf0e10cSrcweir     */
145cdf0e10cSrcweir 	void ForEach(sal_uLong fromPos, sal_uLong toPos, FnForEach fn, void* pArgs = NULL);
146cdf0e10cSrcweir 
147cdf0e10cSrcweir private:
148cdf0e10cSrcweir 
149cdf0e10cSrcweir     void FixElementIndizes(Container_t::const_iterator begin, Container_t::const_iterator end) const;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir private:
152cdf0e10cSrcweir     Container_t container_;
153cdf0e10cSrcweir };
154cdf0e10cSrcweir 
155cdf0e10cSrcweir #endif
156