xref: /trunk/main/tools/inc/tools/unqid.hxx (revision 8b851043)
1*8b851043SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3*8b851043SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4*8b851043SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5*8b851043SAndrew Rist  * distributed with this work for additional information
6*8b851043SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7*8b851043SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8*8b851043SAndrew Rist  * "License"); you may not use this file except in compliance
9*8b851043SAndrew Rist  * with the License.  You may obtain a copy of the License at
10*8b851043SAndrew Rist  *
11*8b851043SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12*8b851043SAndrew Rist  *
13*8b851043SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14*8b851043SAndrew Rist  * software distributed under the License is distributed on an
15*8b851043SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*8b851043SAndrew Rist  * KIND, either express or implied.  See the License for the
17*8b851043SAndrew Rist  * specific language governing permissions and limitations
18*8b851043SAndrew Rist  * under the License.
19*8b851043SAndrew Rist  *
20*8b851043SAndrew Rist  *************************************************************/
21*8b851043SAndrew Rist 
22*8b851043SAndrew Rist 
23cdf0e10cSrcweir #ifndef _UNQID_HXX
24cdf0e10cSrcweir #define _UNQID_HXX
25cdf0e10cSrcweir 
26cdf0e10cSrcweir #include "tools/toolsdllapi.h"
27cdf0e10cSrcweir #include <tools/unqidx.hxx>
28cdf0e10cSrcweir 
29cdf0e10cSrcweir // ---------------
30cdf0e10cSrcweir // - ImpUniqueId -
31cdf0e10cSrcweir // ---------------
32cdf0e10cSrcweir 
33cdf0e10cSrcweir struct ImpUniqueId
34cdf0e10cSrcweir {
35cdf0e10cSrcweir     sal_uIntPtr    nId;
36cdf0e10cSrcweir     sal_uInt16   nRefCount;
ReleaseImpUniqueId37cdf0e10cSrcweir     void     Release()
38cdf0e10cSrcweir              {
39cdf0e10cSrcweir                 nRefCount--;
40cdf0e10cSrcweir                 if( 0 == nRefCount )
41cdf0e10cSrcweir                     delete this;
42cdf0e10cSrcweir              }
43cdf0e10cSrcweir };
44cdf0e10cSrcweir 
45cdf0e10cSrcweir // ------------
46cdf0e10cSrcweir // - UniqueId -
47cdf0e10cSrcweir // ------------
48cdf0e10cSrcweir 
49cdf0e10cSrcweir class UniqueIdContainer;
50cdf0e10cSrcweir class UniqueItemId
51cdf0e10cSrcweir {
52cdf0e10cSrcweir     friend class UniqueIdContainer;
53cdf0e10cSrcweir     ImpUniqueId*    pId;
54cdf0e10cSrcweir 
UniqueItemId(ImpUniqueId * pIdP)55cdf0e10cSrcweir                     UniqueItemId( ImpUniqueId * pIdP )
56cdf0e10cSrcweir                         { pId = pIdP; pId->nRefCount++; }
57cdf0e10cSrcweir public:
UniqueItemId()58cdf0e10cSrcweir                     UniqueItemId() { pId = NULL; }
UniqueItemId(const UniqueItemId & rId)59cdf0e10cSrcweir                     UniqueItemId( const UniqueItemId & rId )
60cdf0e10cSrcweir                         { pId = rId.pId; if( pId ) pId->nRefCount++; }
~UniqueItemId()61cdf0e10cSrcweir                     ~UniqueItemId()
62cdf0e10cSrcweir                         { if( pId ) pId->Release(); }
operator =(const UniqueItemId & rId)63cdf0e10cSrcweir     UniqueItemId&   operator = ( const UniqueItemId & rId )
64cdf0e10cSrcweir                         {
65cdf0e10cSrcweir                             if( rId.pId ) rId.pId->nRefCount++;
66cdf0e10cSrcweir                             if( pId ) pId->Release();
67cdf0e10cSrcweir                             pId = rId.pId;
68cdf0e10cSrcweir                             return *this;
69cdf0e10cSrcweir                         }
GetId() const70cdf0e10cSrcweir     sal_uIntPtr           GetId() const { return pId ? pId->nId : 0; }
71cdf0e10cSrcweir };
72cdf0e10cSrcweir 
73cdf0e10cSrcweir // ---------------------
74cdf0e10cSrcweir // - UniqueIdContainer -
75cdf0e10cSrcweir // ---------------------
76cdf0e10cSrcweir 
77cdf0e10cSrcweir class TOOLS_DLLPUBLIC UniqueIdContainer : private UniqueIndex
78cdf0e10cSrcweir {
79cdf0e10cSrcweir     sal_uInt16              nCollectCount;
80cdf0e10cSrcweir 
81cdf0e10cSrcweir public: // Irgend etwas mit protected falsch
82cdf0e10cSrcweir     void                Clear( sal_Bool bAll );
83cdf0e10cSrcweir     UniqueItemId        CreateIdProt( sal_uIntPtr nId );
84cdf0e10cSrcweir 
85cdf0e10cSrcweir public:
UniqueIdContainer(sal_uIntPtr _nStartIndex,sal_uIntPtr _nInitSize=16,sal_uIntPtr _nReSize=16)86cdf0e10cSrcweir                         UniqueIdContainer( sal_uIntPtr _nStartIndex,
87cdf0e10cSrcweir                                            sal_uIntPtr _nInitSize = 16,
88cdf0e10cSrcweir                                            sal_uIntPtr _nReSize = 16 )
89cdf0e10cSrcweir 							: UniqueIndex( _nStartIndex, _nInitSize, _nReSize )
90cdf0e10cSrcweir 							, nCollectCount( 0 )
91cdf0e10cSrcweir 							{}
92cdf0e10cSrcweir                         UniqueIdContainer( const UniqueIdContainer& );
93cdf0e10cSrcweir 
~UniqueIdContainer()94cdf0e10cSrcweir                         ~UniqueIdContainer()
95cdf0e10cSrcweir                             { Clear( sal_True ); }
96cdf0e10cSrcweir     UniqueIdContainer&  operator = ( const UniqueIdContainer & );
97cdf0e10cSrcweir 
IsIndexValid(sal_uIntPtr nIndex) const98cdf0e10cSrcweir     sal_Bool                IsIndexValid( sal_uIntPtr nIndex ) const
99cdf0e10cSrcweir                             { return UniqueIndex::IsIndexValid( nIndex ); }
100cdf0e10cSrcweir 
101cdf0e10cSrcweir     UniqueItemId        CreateId();
102cdf0e10cSrcweir     static UniqueItemId CreateFreeId( sal_uIntPtr nId ); // freies Id
103cdf0e10cSrcweir };
104cdf0e10cSrcweir 
105cdf0e10cSrcweir #endif // _UNQID_HXX
106