1*8b851043SAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*8b851043SAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*8b851043SAndrew Rist * or more contributor license agreements. See the NOTICE file
5*8b851043SAndrew Rist * distributed with this work for additional information
6*8b851043SAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*8b851043SAndrew Rist * to you under the Apache License, Version 2.0 (the
8*8b851043SAndrew Rist * "License"); you may not use this file except in compliance
9*8b851043SAndrew Rist * with the License. You may obtain a copy of the License at
10*8b851043SAndrew Rist *
11*8b851043SAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*8b851043SAndrew Rist *
13*8b851043SAndrew Rist * Unless required by applicable law or agreed to in writing,
14*8b851043SAndrew Rist * software distributed under the License is distributed on an
15*8b851043SAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*8b851043SAndrew Rist * KIND, either express or implied. See the License for the
17*8b851043SAndrew Rist * specific language governing permissions and limitations
18*8b851043SAndrew Rist * under the License.
19*8b851043SAndrew Rist *
20*8b851043SAndrew Rist *************************************************************/
21*8b851043SAndrew Rist
22*8b851043SAndrew Rist
23cdf0e10cSrcweir #ifndef _TOOLS_TABLE_HXX
24cdf0e10cSrcweir #define _TOOLS_TABLE_HXX
25cdf0e10cSrcweir
26cdf0e10cSrcweir #include "tools/toolsdllapi.h"
27cdf0e10cSrcweir #include <tools/solar.h>
28cdf0e10cSrcweir #include <tools/contnr.hxx>
29cdf0e10cSrcweir
30cdf0e10cSrcweir // ---------
31cdf0e10cSrcweir // - Table -
32cdf0e10cSrcweir // ---------
33cdf0e10cSrcweir
34cdf0e10cSrcweir #define TABLE_ENTRY_NOTFOUND CONTAINER_ENTRY_NOTFOUND
35cdf0e10cSrcweir
36cdf0e10cSrcweir class TOOLS_DLLPUBLIC Table : private Container
37cdf0e10cSrcweir {
38cdf0e10cSrcweir private:
39cdf0e10cSrcweir sal_uIntPtr nCount;
40cdf0e10cSrcweir //#if 0 // _SOLAR__PRIVATE
41cdf0e10cSrcweir TOOLS_DLLPRIVATE sal_uIntPtr ImplGetIndex( sal_uIntPtr nKey, sal_uIntPtr* pIndex = NULL ) const;
42cdf0e10cSrcweir //#endif
43cdf0e10cSrcweir public:
44cdf0e10cSrcweir Table( sal_uInt16 nInitSize = 16, sal_uInt16 nReSize = 16 );
Table(const Table & rTable)45cdf0e10cSrcweir Table( const Table& rTable ) : Container( rTable )
46cdf0e10cSrcweir { nCount = rTable.nCount; }
47cdf0e10cSrcweir
48cdf0e10cSrcweir sal_Bool Insert( sal_uIntPtr nKey, void* p );
49cdf0e10cSrcweir void* Remove( sal_uIntPtr nKey );
50cdf0e10cSrcweir void* Replace( sal_uIntPtr nKey, void* p );
51cdf0e10cSrcweir void* Get( sal_uIntPtr nKey ) const;
52cdf0e10cSrcweir
Clear()53cdf0e10cSrcweir void Clear() { Container::Clear(); nCount = 0; }
Count() const54cdf0e10cSrcweir sal_uIntPtr Count() const { return( nCount ); }
55cdf0e10cSrcweir
56cdf0e10cSrcweir void* GetCurObject() const;
GetCurKey() const57cdf0e10cSrcweir sal_uIntPtr GetCurKey() const { return (sal_uIntPtr)Container::GetCurObject(); }
58cdf0e10cSrcweir sal_uIntPtr GetKey( const void* p ) const;
59cdf0e10cSrcweir sal_Bool IsKeyValid( sal_uIntPtr nKey ) const;
60cdf0e10cSrcweir
GetObject(sal_uIntPtr nPos) const61cdf0e10cSrcweir void* GetObject( sal_uIntPtr nPos ) const
62cdf0e10cSrcweir { return Container::GetObject( (nPos*2)+1 ); }
GetObjectKey(sal_uIntPtr nPos) const63cdf0e10cSrcweir sal_uIntPtr GetObjectKey( sal_uIntPtr nPos ) const
64cdf0e10cSrcweir { return (sal_uIntPtr)Container::GetObject( nPos*2 ); }
65cdf0e10cSrcweir sal_uIntPtr GetUniqueKey( sal_uIntPtr nStartKey = 1 ) const;
66cdf0e10cSrcweir sal_uIntPtr SearchKey( sal_uIntPtr nKey, sal_uIntPtr* pPos = NULL ) const;
67cdf0e10cSrcweir
68cdf0e10cSrcweir void* Seek( sal_uIntPtr nKey );
69cdf0e10cSrcweir void* Seek( void* p );
70cdf0e10cSrcweir void* First();
71cdf0e10cSrcweir void* Last();
72cdf0e10cSrcweir void* Next();
73cdf0e10cSrcweir void* Prev();
74cdf0e10cSrcweir
75cdf0e10cSrcweir Table& operator =( const Table& rTable );
76cdf0e10cSrcweir
operator ==(const Table & rTable) const77cdf0e10cSrcweir sal_Bool operator ==( const Table& rTable ) const
78cdf0e10cSrcweir { return Container::operator ==( rTable ); }
operator !=(const Table & rTable) const79cdf0e10cSrcweir sal_Bool operator !=( const Table& rTable ) const
80cdf0e10cSrcweir { return Container::operator !=( rTable ); }
81cdf0e10cSrcweir };
82cdf0e10cSrcweir
operator =(const Table & r)83cdf0e10cSrcweir inline Table& Table::operator =( const Table& r )
84cdf0e10cSrcweir {
85cdf0e10cSrcweir Container::operator =( r );
86cdf0e10cSrcweir nCount = r.nCount;
87cdf0e10cSrcweir return *this;
88cdf0e10cSrcweir }
89cdf0e10cSrcweir
90cdf0e10cSrcweir // -----------------
91cdf0e10cSrcweir // - DECLARE_TABLE -
92cdf0e10cSrcweir // -----------------
93cdf0e10cSrcweir
94cdf0e10cSrcweir #define DECLARE_TABLE( ClassName, Type ) \
95cdf0e10cSrcweir class ClassName : private Table \
96cdf0e10cSrcweir { \
97cdf0e10cSrcweir public: \
98cdf0e10cSrcweir using Table::Clear; \
99cdf0e10cSrcweir using Table::Count; \
100cdf0e10cSrcweir using Table::GetCurKey; \
101cdf0e10cSrcweir using Table::GetObjectKey; \
102cdf0e10cSrcweir using Table::GetUniqueKey; \
103cdf0e10cSrcweir using Table::SearchKey; \
104cdf0e10cSrcweir using Table::IsKeyValid; \
105cdf0e10cSrcweir \
106cdf0e10cSrcweir ClassName( sal_uInt16 _nInitSize = 16, \
107cdf0e10cSrcweir sal_uInt16 _nReSize = 16 ) : \
108cdf0e10cSrcweir Table( _nInitSize, _nReSize ) {} \
109cdf0e10cSrcweir ClassName( const ClassName& rClassName ) : \
110cdf0e10cSrcweir Table( rClassName ) {} \
111cdf0e10cSrcweir \
112cdf0e10cSrcweir sal_Bool Insert( sal_uIntPtr nKey, Type p ) \
113cdf0e10cSrcweir { return Table::Insert( nKey, (void*)p ); } \
114cdf0e10cSrcweir Type Remove( sal_uIntPtr nKey ) \
115cdf0e10cSrcweir { return (Type)Table::Remove( nKey ); } \
116cdf0e10cSrcweir Type Replace( sal_uIntPtr nKey, Type p ) \
117cdf0e10cSrcweir { return (Type)Table::Replace( nKey, (void*)p ); } \
118cdf0e10cSrcweir Type Get( sal_uIntPtr nKey ) const \
119cdf0e10cSrcweir { return (Type)Table::Get( nKey ); } \
120cdf0e10cSrcweir \
121cdf0e10cSrcweir Type GetCurObject() const \
122cdf0e10cSrcweir { return (Type)Table::GetCurObject(); } \
123cdf0e10cSrcweir sal_uIntPtr GetKey( const Type p ) const \
124cdf0e10cSrcweir { return Table::GetKey( (const void*)p ); } \
125cdf0e10cSrcweir \
126cdf0e10cSrcweir Type GetObject( sal_uIntPtr nPos ) const \
127cdf0e10cSrcweir { return (Type)Table::GetObject( nPos ); } \
128cdf0e10cSrcweir \
129cdf0e10cSrcweir Type Seek( sal_uIntPtr nKey ) \
130cdf0e10cSrcweir { return (Type)Table::Seek( nKey ); } \
131cdf0e10cSrcweir Type Seek( Type p ) \
132cdf0e10cSrcweir { return (Type)Table::Seek( (void*)p ); } \
133cdf0e10cSrcweir Type First() { return (Type)Table::First(); } \
134cdf0e10cSrcweir Type Last() { return (Type)Table::Last(); } \
135cdf0e10cSrcweir Type Next() { return (Type)Table::Next(); } \
136cdf0e10cSrcweir Type Prev() { return (Type)Table::Prev(); } \
137cdf0e10cSrcweir \
138cdf0e10cSrcweir ClassName& operator =( const ClassName& rClassName ) \
139cdf0e10cSrcweir { Table::operator =( rClassName ); \
140cdf0e10cSrcweir return *this; } \
141cdf0e10cSrcweir \
142cdf0e10cSrcweir sal_Bool operator ==( const ClassName& rTable ) const \
143cdf0e10cSrcweir { return Table::operator ==( rTable ); } \
144cdf0e10cSrcweir sal_Bool operator !=( const ClassName& rTable ) const \
145cdf0e10cSrcweir { return Table::operator !=( rTable ); } \
146cdf0e10cSrcweir };
147cdf0e10cSrcweir
148cdf0e10cSrcweir #endif // _TOOLS_TABLE_HXX
149