xref: /trunk/main/tools/inc/tools/stack.hxx (revision 8b851043)
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 _STACK_HXX
25 #define _STACK_HXX
26 
27 #include <tools/contnr.hxx>
28 
29 // ---------
30 // - Stack -
31 // ---------
32 
33 #define STACK_ENTRY_NOTFOUND   CONTAINER_ENTRY_NOTFOUND
34 
35 class Stack : private Container
36 {
37 public:
38 			using Container::Clear;
39 			using Container::Count;
40 			using Container::GetObject;
41 			using Container::GetPos;
42 
Stack(sal_uInt16 _nInitSize=16,sal_uInt16 _nReSize=16)43             Stack( sal_uInt16 _nInitSize = 16, sal_uInt16 _nReSize = 16 ) :
44                 Container( CONTAINER_MAXBLOCKSIZE, _nInitSize, _nReSize ) {}
Stack(const Stack & rStack)45             Stack( const Stack& rStack ) : Container( rStack ) {}
46 
Push(void * p)47     void    Push( void* p ) { Container::Insert( p, CONTAINER_APPEND ); }
Pop()48     void*   Pop()           { return Container::Remove( Count()-1 ); }
Top() const49     void*   Top() const     { return Container::GetObject( Count()-1 ); }
50 
operator =(const Stack & rStack)51     Stack&  operator =( const Stack& rStack )
52                 { Container::operator =( rStack ); return *this; }
53 
operator ==(const Stack & rStack) const54     sal_Bool    operator ==( const Stack& rStack ) const
55                 { return Container::operator ==( rStack ); }
operator !=(const Stack & rStack) const56     sal_Bool    operator !=( const Stack& rStack ) const
57                 { return Container::operator !=( rStack ); }
58 };
59 
60 // -----------------
61 // - DECLARE_STACK -
62 // -----------------
63 
64 #define DECLARE_STACK( ClassName, Type )                            \
65 class ClassName : private Stack                                     \
66 {                                                                   \
67 public:                                                             \
68 				using Stack::Clear;									\
69 				using Stack::Count;									\
70                                                                     \
71                 ClassName( sal_uInt16 _nInitSize = 16,                  \
72                        sal_uInt16 _nReSize = 16 ) :                     \
73                     Stack( _nInitSize, _nReSize ) {}                \
74                 ClassName( const ClassName& rClassName ) :          \
75                     Stack( rClassName ) {}                          \
76                                                                     \
77     void        Push( Type p ) { Stack::Push( (void*)p ); }         \
78     Type        Pop()          { return (Type)Stack::Pop(); }       \
79     Type        Top() const    { return (Type)Stack::Top(); }       \
80                                                                     \
81     Type        GetObject( sal_uIntPtr nIndex ) const                     \
82                     { return (Type)Stack::GetObject( nIndex ); }    \
83     sal_uIntPtr       GetPos( const Type p ) const                        \
84                     { return Stack::GetPos( (const void*)p ); }     \
85     sal_uIntPtr       GetPos( const Type p, sal_uIntPtr nStartIndex,            \
86                         sal_Bool bForward = sal_True ) const                \
87                     { return Stack::GetPos( (const void*)p,         \
88                                             nStartIndex,            \
89                                             bForward ); }           \
90                                                                     \
91     ClassName&  operator =( const ClassName& rClassName )           \
92                     { Stack::operator =( rClassName );              \
93                       return *this; }                               \
94                                                                     \
95     sal_Bool        operator ==( const ClassName& rStack ) const        \
96                     { return Stack::operator ==( rStack ); }        \
97     sal_Bool        operator !=( const ClassName& rStack ) const        \
98                     { return Stack::operator !=( rStack ); }        \
99 };
100 
101 #endif  // _STACK_HXX
102