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 <sal/types.h>
23 #include <tools/toolsdllapi.h>
24 #include <o3tl/strong_int.hxx>
27 class SAL_WARN_UNUSED TOOLS_DLLPUBLIC UniqueIndexImpl
30 struct IndexTagType
{};
31 typedef o3tl::strong_int
<sal_uInt32
, IndexTagType
> Index
;
32 static Index
const IndexNotFound
;// = Index(SAL_MAX_UINT32);
35 std::map
<Index
, void*> maMap
;
39 UniqueIndexImpl( Index nStartIndex
= Index(0) )
40 : maMap(), nUniqIndex(nStartIndex
) {}
42 Index
Insert( void* p
);
43 // insert value with key, replacing existing entry if necessary
44 void* Remove( Index aIndex
);
45 void* Get( Index aIndex
) const;
47 Index
GetIndexOf( void const* p
) const;
48 Index
FirstIndex() const;
49 Index
LastIndex() const;
50 Index
NextIndex( Index aCurrIndex
) const;
54 class SAL_WARN_UNUSED UniqueIndex
: private UniqueIndexImpl
57 using UniqueIndexImpl::Index
;
58 using UniqueIndexImpl::IndexNotFound
;
60 UniqueIndex
<T
>( Index _nStartIndex
= Index(0) ) : UniqueIndexImpl(_nStartIndex
) {}
62 Index
Insert(T
* p
) { return UniqueIndexImpl::Insert(p
); }
63 T
* Get(Index idx
) const { return static_cast<T
*>( UniqueIndexImpl::Get(idx
) ); }
64 T
* Remove(Index idx
) { return static_cast<T
*>( UniqueIndexImpl::Remove(idx
) ); }
65 Index
GetIndexOf(T
* p
) const { return UniqueIndexImpl::GetIndexOf(p
); }
67 using UniqueIndexImpl::FirstIndex
;
68 using UniqueIndexImpl::LastIndex
;
69 using UniqueIndexImpl::NextIndex
;
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */