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