xref: /AOO41X/main/tools/inc/impcont.hxx (revision 1ecadb572e7010ff3b3382ad9bf179dbc6efadbb)
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 
28 #ifndef _IMPCONT_HXX
29 #define _IMPCONT_HXX
30 
31 #include <tools/tools.h>
32 #include <tools/contnr.hxx>
33 
34 typedef void* PVOID;
35 
36 // ----------
37 // - CBlock -
38 // ----------
39 
40 class CBlock
41 {
42 private:
43     CBlock*         pPrev;              // Vorheriger Block
44     CBlock*         pNext;              // Naechster Block
45     sal_uInt16          nSize;              // Groesse des Blocks
46     sal_uInt16          nCount;             // Anzahl Pointer
47     void**          pNodes;             // Pointer auf die Daten
48 
49 #if defined DBG_UTIL
50     static char const * DbgCheckCBlock(void const *);
51 #endif
52 
53 public:
54                     // Fuer List-Container
55                     CBlock( sal_uInt16 nSize, CBlock* pPrev, CBlock* pNext );
56                     // Fuer Array-Container
57                     CBlock( sal_uInt16 nSize, CBlock* pPrev );
58                     // Copy-Ctor
59                     CBlock( const CBlock& r, CBlock* pPrev );
60                     ~CBlock();
61 
62     void            Insert( void* p, sal_uInt16 nIndex, sal_uInt16 nReSize );
63     CBlock*         Split( void* p, sal_uInt16 nIndex, sal_uInt16 nReSize );
64     void*           Remove( sal_uInt16 nIndex, sal_uInt16 nReSize );
65     void*           Replace( void* pNew, sal_uInt16 nIndex );
66 
67     void**          GetNodes() const { return pNodes; }
68     void**          GetObjectPtr( sal_uInt16 nIndex );
69     void*           GetObject( sal_uInt16 nIndex ) const;
70 
71     void            SetSize( sal_uInt16 nNewSize );
72 
73     sal_uInt16          GetSize() const               { return nCount; }
74     sal_uInt16          Count() const                 { return nCount; }
75     void            SetPrevBlock( CBlock* p )     { pPrev = p;     }
76     void            SetNextBlock( CBlock* p )     { pNext = p;     }
77     CBlock*         GetPrevBlock() const          { return pPrev;  }
78     CBlock*         GetNextBlock() const          { return pNext;  }
79     void            Reset()                       { nCount = 0;    }
80 
81 private:
82                     CBlock( const CBlock& r );
83 
84     friend class Container;
85 };
86 
87 /*************************************************************************
88 |*
89 |*    CBlock::GetObject()
90 |*
91 |*    Beschreibung      Gibt einen Pointer aus dem Block zurueck
92 |*    Ersterstellung    TH 17.09.91
93 |*    Letzte Aenderung  TH 17.09.91
94 |*
95 *************************************************************************/
96 
97 inline void* CBlock::GetObject( sal_uInt16 nIndex ) const
98 {
99     return pNodes[nIndex];
100 }
101 
102 /*************************************************************************
103 |*
104 |*    Container::ImpGetObject()
105 |*
106 |*    Beschreibung      Wir gehen davon aus, das Pointer in der Regel
107 |*                      sich im ersten Block befindet und schalten
108 |*                      deshalb eine Inline-Methode davor
109 |*    Ersterstellung    TH 02.07.93
110 |*    Letzte Aenderung  TH 02.07.93
111 |*
112 *************************************************************************/
113 
114 inline void* Container::ImpGetObject( sal_uIntPtr nIndex ) const
115 {
116     if ( pFirstBlock && (nIndex < pFirstBlock->Count()) )
117         // Item innerhalb des gefundenen Blocks zurueckgeben
118         return pFirstBlock->GetObject( (sal_uInt16)nIndex );
119     else
120         return GetObject( nIndex );
121 }
122 
123 /*************************************************************************
124 |*
125 |*    Container::ImpGetOnlyNodes()
126 |*
127 |*    Beschreibung      Wenn es nur einen Block gibt, wird davon
128 |*                      das Daten-Array zurueckgegeben
129 |*    Ersterstellung    TH 24.01.96
130 |*    Letzte Aenderung  TH 24.01.96
131 |*
132 *************************************************************************/
133 
134 // #i70651#: Prevent warnings on Mac OS X
135 #ifdef MACOSX
136 #pragma GCC system_header
137 #endif
138 
139 inline void** Container::ImpGetOnlyNodes() const
140 {
141     if ( (pFirstBlock == pLastBlock) && pFirstBlock )
142         return pFirstBlock->GetNodes();
143     else
144         return NULL;
145 }
146 
147 #endif // _IMPCONT_HXX
148