xref: /aoo4110/main/tools/inc/tools/table.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 _TOOLS_TABLE_HXX
24 #define _TOOLS_TABLE_HXX
25 
26 #include "tools/toolsdllapi.h"
27 #include <tools/solar.h>
28 #include <tools/contnr.hxx>
29 
30 // ---------
31 // - Table -
32 // ---------
33 
34 #define TABLE_ENTRY_NOTFOUND   CONTAINER_ENTRY_NOTFOUND
35 
36 class TOOLS_DLLPUBLIC Table : private Container
37 {
38 private:
39 	sal_uIntPtr	nCount;
40 //#if 0 // _SOLAR__PRIVATE
41 	TOOLS_DLLPRIVATE sal_uIntPtr	ImplGetIndex( sal_uIntPtr nKey, sal_uIntPtr* pIndex = NULL ) const;
42 //#endif
43 public:
44 			Table( sal_uInt16 nInitSize = 16, sal_uInt16 nReSize = 16 );
Table(const Table & rTable)45 			Table( const Table& rTable ) : Container( rTable )
46 				{ nCount = rTable.nCount; }
47 
48 	sal_Bool	Insert( sal_uIntPtr nKey, void* p );
49 	void*	Remove( sal_uIntPtr nKey );
50 	void*	Replace( sal_uIntPtr nKey, void* p );
51 	void*	Get( sal_uIntPtr nKey ) const;
52 
Clear()53 	void	Clear() { Container::Clear(); nCount = 0; }
Count() const54 	sal_uIntPtr	Count() const { return( nCount ); }
55 
56 	void*	GetCurObject() const;
GetCurKey() const57 	sal_uIntPtr	GetCurKey() const { return (sal_uIntPtr)Container::GetCurObject(); }
58 	sal_uIntPtr	GetKey( const void* p ) const;
59 	sal_Bool	IsKeyValid( sal_uIntPtr nKey ) const;
60 
GetObject(sal_uIntPtr nPos) const61 	void*	GetObject( sal_uIntPtr nPos ) const
62 				{ return Container::GetObject( (nPos*2)+1 ); }
GetObjectKey(sal_uIntPtr nPos) const63 	sal_uIntPtr	GetObjectKey( sal_uIntPtr nPos ) const
64 				{ return (sal_uIntPtr)Container::GetObject( nPos*2 ); }
65 	sal_uIntPtr	GetUniqueKey( sal_uIntPtr nStartKey = 1 ) const;
66 	sal_uIntPtr	SearchKey( sal_uIntPtr nKey, sal_uIntPtr* pPos = NULL ) const;
67 
68 	void*	Seek( sal_uIntPtr nKey );
69 	void*	Seek( void* p );
70 	void*	First();
71 	void*	Last();
72 	void*	Next();
73 	void*	Prev();
74 
75 	Table&	operator =( const Table& rTable );
76 
operator ==(const Table & rTable) const77 	sal_Bool	operator ==( const Table& rTable ) const
78 				{ return Container::operator ==( rTable ); }
operator !=(const Table & rTable) const79 	sal_Bool	operator !=( const Table& rTable ) const
80 				{ return Container::operator !=( rTable ); }
81 };
82 
operator =(const Table & r)83 inline Table& Table::operator =( const Table& r )
84 {
85 	Container::operator =( r );
86 	nCount = r.nCount;
87 	return *this;
88 }
89 
90 // -----------------
91 // - DECLARE_TABLE -
92 // -----------------
93 
94 #define DECLARE_TABLE( ClassName, Type )								\
95 class ClassName : private Table 										\
96 {																		\
97 public: 																\
98 				using Table::Clear;										\
99 				using Table::Count;	    								\
100 				using Table::GetCurKey;									\
101 				using Table::GetObjectKey;								\
102 				using Table::GetUniqueKey;								\
103 				using Table::SearchKey;									\
104 				using Table::IsKeyValid;								\
105 																		\
106 				ClassName( sal_uInt16 _nInitSize = 16,						\
107 						   sal_uInt16 _nReSize = 16 ) : 					\
108 					Table( _nInitSize, _nReSize ) {}					\
109 				ClassName( const ClassName& rClassName ) :				\
110 					Table( rClassName ) {}								\
111 																		\
112 	sal_Bool		Insert( sal_uIntPtr nKey, Type p )							\
113 					{ return Table::Insert( nKey, (void*)p ); } 		\
114 	Type		Remove( sal_uIntPtr nKey )									\
115 					{ return (Type)Table::Remove( nKey ); } 			\
116 	Type		Replace( sal_uIntPtr nKey, Type p )							\
117 					{ return (Type)Table::Replace( nKey, (void*)p ); }	\
118 	Type		Get( sal_uIntPtr nKey ) const 								\
119 					{ return (Type)Table::Get( nKey ); }				\
120 																		\
121 	Type		GetCurObject() const									\
122 					{ return (Type)Table::GetCurObject(); } 			\
123 	sal_uIntPtr		GetKey( const Type p ) const							\
124 					{ return Table::GetKey( (const void*)p ); } 		\
125 																		\
126 	Type		GetObject( sal_uIntPtr nPos ) const							\
127 					{ return (Type)Table::GetObject( nPos ); }			\
128 																		\
129 	Type		Seek( sal_uIntPtr nKey )										\
130 					{ return (Type)Table::Seek( nKey ); }				\
131 	Type		Seek( Type p )											\
132 					{ return (Type)Table::Seek( (void*)p ); }			\
133 	Type		First() { return (Type)Table::First(); }				\
134 	Type		Last()	{ return (Type)Table::Last(); } 				\
135 	Type		Next()	{ return (Type)Table::Next(); } 				\
136 	Type		Prev()	{ return (Type)Table::Prev(); } 				\
137 																		\
138 	ClassName&	operator =( const ClassName& rClassName )				\
139 					{ Table::operator =( rClassName );					\
140 					  return *this; }									\
141 																		\
142 	sal_Bool		operator ==( const ClassName& rTable ) const			\
143 					{ return Table::operator ==( rTable ); }			\
144 	sal_Bool		operator !=( const ClassName& rTable ) const			\
145 					{ return Table::operator !=( rTable ); }			\
146 };
147 
148 #endif // _TOOLS_TABLE_HXX
149