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