xref: /trunk/main/tools/inc/tools/contnr.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 #ifndef _CONTNR_HXX
24 #define _CONTNR_HXX
25 
26 #include "tools/toolsdllapi.h"
27 #include <tools/solar.h>
28 
29 #include <limits.h>
30 
31 class CBlock;
32 
33 // -------------
34 // - Container -
35 // -------------
36 
37 // Maximale Blockgroesse
38 #define CONTAINER_MAXBLOCKSIZE      ((sal_uInt16)0x3FF0)
39 
40 #define CONTAINER_APPEND            ULONG_MAX
41 #define CONTAINER_ENTRY_NOTFOUND    ULONG_MAX
42 
43 class TOOLS_DLLPUBLIC Container
44 {
45 private:
46     CBlock*     pFirstBlock;
47     CBlock*     pCurBlock;
48     CBlock*     pLastBlock;
49     sal_uInt16      nCurIndex;
50     sal_uInt16      nBlockSize;
51     sal_uInt16      nInitSize;
52     sal_uInt16      nReSize;
53     sal_uIntPtr       nCount;
54 
55     TOOLS_DLLPRIVATE void ImpCopyContainer(Container const *);
56 #if defined DBG_UTIL
57     TOOLS_DLLPRIVATE static char const * DbgCheckContainer(void const *);
58 #endif
59 
60 protected:
61 #ifdef _IMPCONT_HXX
62     void        ImpInsert( void* p, CBlock* pBlock, sal_uInt16 nIndex );
63     void*       ImpRemove( CBlock* pBlock, sal_uInt16 nIndex );
64     void*       ImpGetObject( sal_uIntPtr nIndex ) const;
65     void**      ImpGetOnlyNodes() const;
66 #endif
67     void**      GetObjectPtr( sal_uIntPtr nIndex );
68 
69 public:
70                 Container( sal_uInt16 nBlockSize,
71                            sal_uInt16 nInitSize,
72                            sal_uInt16 nReSize );
73                 Container( sal_uIntPtr nSize );
74                 Container( const Container& rContainer );
75                 ~Container();
76 
77     void        Insert( void* p );
78     void        Insert( void* p, sal_uIntPtr nIndex );
79     void        Insert( void* pNew, void* pOld );
80 
81     void*       Remove();
82     void*       Remove( sal_uIntPtr nIndex );
Remove(void * p)83     void*       Remove( void* p )
84                     { return Remove( GetPos( p ) ); }
85 
86     void*       Replace( void* p );
87     void*       Replace( void* p, sal_uIntPtr nIndex );
Replace(void * pNew,void * pOld)88     void*       Replace( void* pNew, void* pOld )
89                     { return Replace( pNew, GetPos( pOld ) ); }
90 
91     void        SetSize( sal_uIntPtr nNewSize );
GetSize() const92     sal_uIntPtr       GetSize() const { return nCount; }
93 
Count() const94     sal_uIntPtr       Count() const { return nCount; }
95     void        Clear();
96 
97     void*       GetCurObject() const;
98     sal_uIntPtr       GetCurPos() const;
99     void*       GetObject( sal_uIntPtr nIndex ) const;
100     sal_uIntPtr       GetPos( const void* p ) const;
101     sal_uIntPtr       GetPos( const void* p, sal_uIntPtr nStartIndex,
102                         sal_Bool bForward = sal_True ) const;
103 
104     void*       Seek( sal_uIntPtr nIndex );
Seek(void * p)105     void*       Seek( void* p ) { return Seek( GetPos( p ) ); }
106 
107     void*       First();
108     void*       Last();
109     void*       Next();
110     void*       Prev();
111 
112     Container&  operator =( const Container& rContainer );
113 
114     sal_Bool        operator ==( const Container& rContainer ) const;
operator !=(const Container & rContainer) const115     sal_Bool        operator !=( const Container& rContainer ) const
116                     { return !(Container::operator==( rContainer )); }
117 };
118 
119 #endif // _CONTNR_HXX
120