xref: /trunk/main/tools/inc/tools/list.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 _LIST_HXX
25 #define _LIST_HXX
26 
27 #include <tools/solar.h>
28 #include <tools/contnr.hxx>
29 
30 // --------
31 // - List -
32 // --------
33 
34 #define LIST_APPEND           CONTAINER_APPEND
35 #define LIST_ENTRY_NOTFOUND   CONTAINER_ENTRY_NOTFOUND
36 
37 class List : private Container
38 {
39 public:
40 			using Container::Insert;
41             using Container::Remove;
42             using Container::Replace;
43             using Container::Clear;
44             using Container::Count;
45             using Container::GetCurObject;
46             using Container::GetCurPos;
47             using Container::GetObject;
48             using Container::GetPos;
49             using Container::Seek;
50             using Container::First;
51             using Container::Last;
52             using Container::Next;
53             using Container::Prev;
54 
List(sal_uInt16 _nInitSize=16,sal_uInt16 _nReSize=16)55             List( sal_uInt16 _nInitSize = 16, sal_uInt16 _nReSize = 16 ) :
56                 Container( 1024, _nInitSize, _nReSize ) {}
List(sal_uInt16 _nBlockSize,sal_uInt16 _nInitSize,sal_uInt16 _nReSize)57             List( sal_uInt16 _nBlockSize, sal_uInt16 _nInitSize, sal_uInt16 _nReSize ) :
58                 Container( _nBlockSize, _nInitSize, _nReSize ) {}
List(const List & rList)59             List( const List& rList ) : Container( rList ) {}
60 
operator =(const List & rList)61     List&   operator =( const List& rList )
62                 { Container::operator =( rList ); return *this; }
63 
operator ==(const List & rList) const64     sal_Bool    operator ==( const List& rList ) const
65                 { return Container::operator ==( rList ); }
operator !=(const List & rList) const66     sal_Bool    operator !=( const List& rList ) const
67                 { return Container::operator !=( rList ); }
68 };
69 
70 // ----------------
71 // - DECLARE_LIST -
72 // ----------------
73 
74 #define DECLARE_LIST( ClassName, Type )                                 \
75 class ClassName : private List                                          \
76 {                                                                       \
77 public:                                                                 \
78                 using List::Clear;                                      \
79                 using List::Count;                                      \
80                 using List::GetCurPos;                                  \
81 																		\
82                 ClassName( sal_uInt16 _nInitSize = 16,                      \
83                            sal_uInt16 _nReSize = 16 ) :                     \
84                     List( _nInitSize, _nReSize ) {}                     \
85                 ClassName( sal_uInt16 _nBlockSize, sal_uInt16 _nInitSize,       \
86                            sal_uInt16 _nReSize ) :                          \
87                     List( _nBlockSize, _nInitSize, _nReSize ) {}        \
88                 ClassName( const ClassName& rClassName ) :              \
89                     List( rClassName ) {}                               \
90                                                                         \
91     void        Insert( Type p, sal_uIntPtr nIndex )                          \
92                     { List::Insert( (void*)p, nIndex ); }               \
93     void        Insert( Type p )                                        \
94                     { List::Insert( (void*)p ); }                       \
95     void        Insert( Type pNew, Type pOld )                          \
96                     { List::Insert( (void*)pNew, (void*)pOld ); }       \
97     Type        Remove()                                                \
98                     { return (Type)List::Remove(); }                    \
99     Type        Remove( sal_uIntPtr nIndex )                                  \
100                     { return (Type)List::Remove( nIndex ); }            \
101     Type        Remove( Type p )                                        \
102                     { return (Type)List::Remove( (void*)p ); }          \
103     Type        Replace( Type p )                                       \
104                     { return (Type)List::Replace( (void*)p ); }         \
105     Type        Replace( Type p, sal_uIntPtr nIndex )                         \
106                     { return (Type)List::Replace( (void*)p, nIndex ); } \
107     Type        Replace( Type pNew, Type pOld )                         \
108                     { return (Type)List::Replace( (void*)pNew,          \
109                                                   (void*)pOld ); }      \
110                                                                         \
111     Type        GetCurObject() const                                    \
112                     { return (Type)List::GetCurObject(); }              \
113     Type        GetObject( sal_uIntPtr nIndex ) const                         \
114                     { return (Type)List::GetObject( nIndex ); }         \
115     sal_uIntPtr       GetPos( const Type p ) const                            \
116                     { return List::GetPos( (const void*)p ); }          \
117     sal_uIntPtr       GetPos( const Type p, sal_uIntPtr nStartIndex,                \
118                         sal_Bool bForward = sal_True ) const                    \
119                     { return List::GetPos( (const void*)p, nStartIndex, \
120                                            bForward ); }                \
121                                                                         \
122     Type        Seek( sal_uIntPtr nIndex )                                    \
123                     { return (Type)List::Seek( nIndex ); }              \
124     Type        Seek( void* p ) { return (Type)List::Seek( p ); }       \
125     Type        First()         { return (Type)List::First(); }         \
126     Type        Last()          { return (Type)List::Last(); }          \
127     Type        Next()          { return (Type)List::Next(); }          \
128     Type        Prev()          { return (Type)List::Prev(); }          \
129                                                                         \
130     ClassName&  operator =( const ClassName& rClassName )               \
131                     { List::operator =( rClassName ); return *this; }   \
132                                                                         \
133     sal_Bool        operator ==( const ClassName& rList ) const             \
134                     { return List::operator ==( rList ); }              \
135     sal_Bool        operator !=( const ClassName& rList ) const             \
136                     { return List::operator !=( rList ); }              \
137 };
138 
139 #endif // _LIST_HXX
140