1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 #ifndef _TOOLS_TABLE_HXX 28 #define _TOOLS_TABLE_HXX 29 30 #include "tools/toolsdllapi.h" 31 #include <tools/solar.h> 32 #include <tools/contnr.hxx> 33 34 // --------- 35 // - Table - 36 // --------- 37 38 #define TABLE_ENTRY_NOTFOUND CONTAINER_ENTRY_NOTFOUND 39 40 class TOOLS_DLLPUBLIC Table : private Container 41 { 42 private: 43 sal_uIntPtr nCount; 44 //#if 0 // _SOLAR__PRIVATE 45 TOOLS_DLLPRIVATE sal_uIntPtr ImplGetIndex( sal_uIntPtr nKey, sal_uIntPtr* pIndex = NULL ) const; 46 //#endif 47 public: 48 Table( sal_uInt16 nInitSize = 16, sal_uInt16 nReSize = 16 ); 49 Table( const Table& rTable ) : Container( rTable ) 50 { nCount = rTable.nCount; } 51 52 sal_Bool Insert( sal_uIntPtr nKey, void* p ); 53 void* Remove( sal_uIntPtr nKey ); 54 void* Replace( sal_uIntPtr nKey, void* p ); 55 void* Get( sal_uIntPtr nKey ) const; 56 57 void Clear() { Container::Clear(); nCount = 0; } 58 sal_uIntPtr Count() const { return( nCount ); } 59 60 void* GetCurObject() const; 61 sal_uIntPtr GetCurKey() const { return (sal_uIntPtr)Container::GetCurObject(); } 62 sal_uIntPtr GetKey( const void* p ) const; 63 sal_Bool IsKeyValid( sal_uIntPtr nKey ) const; 64 65 void* GetObject( sal_uIntPtr nPos ) const 66 { return Container::GetObject( (nPos*2)+1 ); } 67 sal_uIntPtr GetObjectKey( sal_uIntPtr nPos ) const 68 { return (sal_uIntPtr)Container::GetObject( nPos*2 ); } 69 sal_uIntPtr GetUniqueKey( sal_uIntPtr nStartKey = 1 ) const; 70 sal_uIntPtr SearchKey( sal_uIntPtr nKey, sal_uIntPtr* pPos = NULL ) const; 71 72 void* Seek( sal_uIntPtr nKey ); 73 void* Seek( void* p ); 74 void* First(); 75 void* Last(); 76 void* Next(); 77 void* Prev(); 78 79 Table& operator =( const Table& rTable ); 80 81 sal_Bool operator ==( const Table& rTable ) const 82 { return Container::operator ==( rTable ); } 83 sal_Bool operator !=( const Table& rTable ) const 84 { return Container::operator !=( rTable ); } 85 }; 86 87 inline Table& Table::operator =( const Table& r ) 88 { 89 Container::operator =( r ); 90 nCount = r.nCount; 91 return *this; 92 } 93 94 // ----------------- 95 // - DECLARE_TABLE - 96 // ----------------- 97 98 #define DECLARE_TABLE( ClassName, Type ) \ 99 class ClassName : private Table \ 100 { \ 101 public: \ 102 using Table::Clear; \ 103 using Table::Count; \ 104 using Table::GetCurKey; \ 105 using Table::GetObjectKey; \ 106 using Table::GetUniqueKey; \ 107 using Table::SearchKey; \ 108 using Table::IsKeyValid; \ 109 \ 110 ClassName( sal_uInt16 _nInitSize = 16, \ 111 sal_uInt16 _nReSize = 16 ) : \ 112 Table( _nInitSize, _nReSize ) {} \ 113 ClassName( const ClassName& rClassName ) : \ 114 Table( rClassName ) {} \ 115 \ 116 sal_Bool Insert( sal_uIntPtr nKey, Type p ) \ 117 { return Table::Insert( nKey, (void*)p ); } \ 118 Type Remove( sal_uIntPtr nKey ) \ 119 { return (Type)Table::Remove( nKey ); } \ 120 Type Replace( sal_uIntPtr nKey, Type p ) \ 121 { return (Type)Table::Replace( nKey, (void*)p ); } \ 122 Type Get( sal_uIntPtr nKey ) const \ 123 { return (Type)Table::Get( nKey ); } \ 124 \ 125 Type GetCurObject() const \ 126 { return (Type)Table::GetCurObject(); } \ 127 sal_uIntPtr GetKey( const Type p ) const \ 128 { return Table::GetKey( (const void*)p ); } \ 129 \ 130 Type GetObject( sal_uIntPtr nPos ) const \ 131 { return (Type)Table::GetObject( nPos ); } \ 132 \ 133 Type Seek( sal_uIntPtr nKey ) \ 134 { return (Type)Table::Seek( nKey ); } \ 135 Type Seek( Type p ) \ 136 { return (Type)Table::Seek( (void*)p ); } \ 137 Type First() { return (Type)Table::First(); } \ 138 Type Last() { return (Type)Table::Last(); } \ 139 Type Next() { return (Type)Table::Next(); } \ 140 Type Prev() { return (Type)Table::Prev(); } \ 141 \ 142 ClassName& operator =( const ClassName& rClassName ) \ 143 { Table::operator =( rClassName ); \ 144 return *this; } \ 145 \ 146 sal_Bool operator ==( const ClassName& rTable ) const \ 147 { return Table::operator ==( rTable ); } \ 148 sal_Bool operator !=( const ClassName& rTable ) const \ 149 { return Table::operator !=( rTable ); } \ 150 }; 151 152 #endif // _TOOLS_TABLE_HXX 153