xref: /aoo4110/main/sfx2/inc/sfx2/minstack.hxx (revision b1cdbd2c)
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 #ifndef _SFXMINSTACK_HXX
24 #define _SFXMINSTACK_HXX
25 
26 //ASDBG #ifndef _SFXMINARRAY_HXX
27 #include <sfx2/minarray.hxx>
28 
29 #define DECL_OBJSTACK( ARR, T, nI, nG ) \
30 DECL_OBJARRAY( ARR##arr_, T, nI, nG ); \
31 class ARR: private ARR##arr_ \
32 { \
33 public: \
34 	ARR( sal_uInt8 nInitSize = nI, sal_uInt8 nGrowSize = nG ): \
35 		ARR##arr_( nInitSize, nGrowSize ) \
36     {} \
37 \
38 	ARR( const ARR& rOrig ): \
39 		ARR##arr_( rOrig ) \
40     {} \
41 \
42 	sal_uInt16		Count() const { return ARR##arr_::Count(); } \
43 	void		Push( const T& rElem ) { Append( rElem ); } \
44 	const T& Top( sal_uInt16 nLevel = 0 ) const \
45                 { return (*this)[Count()-nLevel-1]; } \
46 	const T& Bottom() const { return (*this)[0]; } \
47 	T		 Pop(); \
48 	void		Clear() { ARR##arr_::Clear(); } \
49 	sal_Bool		Contains( const T& rItem ) const \
50 				{ return ARR##arr_::Contains( rItem ); } \
51 }
52 
53 #define IMPL_OBJSTACK( ARR, T ) \
54 IMPL_OBJARRAY( ARR##arr_, T ); \
55 \
56 T ARR::Pop() \
57 {	T aRet = (*this)[Count()-1]; \
58     Remove( Count()-1, 1 ); \
59     return aRet; \
60 }
61 
62 #define DECL_PTRSTACK( ARR, T, nI, nG ) \
63 DECL_PTRARRAY( ARR##arr_, T, nI, nG ) \
64 class ARR: private ARR##arr_ \
65 { \
66 public: \
67 	ARR( sal_uInt8 nInitSize = nI, sal_uInt8 nGrowSize = nG ): \
68 		ARR##arr_( nInitSize, nGrowSize ) \
69     {} \
70 \
71 	ARR( const ARR& rOrig ): \
72 		ARR##arr_( rOrig ) \
73     {} \
74 \
75 	sal_uInt16		Count() const { return ARR##arr_::Count(); } \
76 	void		Push( T rElem ) { Append( rElem ); } \
77     sal_Bool        Replace( T rOldElem, T rNewElem ) \
78                 { return ARR##arr_::Replace( rOldElem, rNewElem ); } \
79 	T			Top( sal_uInt16 nLevel = 0 ) const \
80                 { return (*this)[Count()-nLevel-1]; } \
81 	T			Bottom() const { return (*this)[0]; } \
82 	T			Pop() \
83 				{	T aRet = (*this)[Count()-1]; \
84                     Remove( Count()-1, 1 ); \
85                     return aRet; \
86                 } \
87 	T*		 operator*() \
88                 { return &(*this)[Count()-1]; } \
89 	void		Clear() { ARR##arr_::Clear(); } \
90 	sal_Bool		Contains( const T pItem ) const \
91 				{ return ARR##arr_::Contains( pItem ); } \
92 }
93 
94 #endif
95 
96