1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
19 #ifndef INCLUDED_TOOLS_UNQIDX_HXX
20 #define INCLUDED_TOOLS_UNQIDX_HXX
22 #include <tools/toolsdllapi.h>
23 #include <tools/contnr.hxx>
26 #define UNIQUEINDEX_ENTRY_NOTFOUND CONTAINER_ENTRY_NOTFOUND
28 class TOOLS_DLLPUBLIC SAL_WARN_UNUSED UniqueIndexImpl
31 std::map
<sal_uInt32
, void*> maMap
;
32 sal_uIntPtr nStartIndex
;
33 sal_uIntPtr nUniqIndex
;
37 UniqueIndexImpl( sal_uIntPtr _nStartIndex
= 0 )
39 nStartIndex(_nStartIndex
), nUniqIndex(_nStartIndex
), nCount(0) {}
41 size_t size() const { return maMap
.size(); }
43 sal_uIntPtr
Insert( void* p
);
44 // insert value with key, replacing existing entry if necessary
45 void Insert( sal_uIntPtr aIndex
, void* p
);
46 void* Remove( sal_uIntPtr aIndex
);
47 void* Get( sal_uIntPtr aIndex
) const;
49 sal_uIntPtr
GetIndexOf( void* p
) const;
50 sal_uIntPtr
FirstIndex() const;
51 sal_uIntPtr
LastIndex() const;
52 sal_uIntPtr
NextIndex( sal_uIntPtr aCurrIndex
) const;
56 class UniqueIndex
: private UniqueIndexImpl
59 UniqueIndex
<T
>( sal_uIntPtr _nStartIndex
= 0 ) : UniqueIndexImpl(_nStartIndex
) {}
61 sal_uIntPtr
Insert(T
* p
) { return UniqueIndexImpl::Insert(p
); }
62 void Insert(sal_uIntPtr aIdx
, T
* p
) { return UniqueIndexImpl::Insert(aIdx
, p
); }
63 T
* Get(sal_uIntPtr idx
) const { return static_cast<T
*>( UniqueIndexImpl::Get(idx
) ); }
64 T
* Remove(sal_uIntPtr idx
) { return static_cast<T
*>( UniqueIndexImpl::Remove(idx
) ); }
65 sal_uIntPtr
Count() const { return UniqueIndexImpl::size(); }
66 sal_uIntPtr
GetIndexOf(T
* p
) const { return UniqueIndexImpl::GetIndexOf(p
); }
68 using UniqueIndexImpl::FirstIndex
;
69 using UniqueIndexImpl::LastIndex
;
70 using UniqueIndexImpl::NextIndex
;
75 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */