Version 5.4.3.2, tag libreoffice-5.4.3.2
[LibreOffice.git] / include / tools / unqidx.hxx
blob7b059adccbb78df32d565b185c09c127be581249
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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>
25 #include <map>
27 class SAL_WARN_UNUSED TOOLS_DLLPUBLIC UniqueIndexImpl
29 public:
30 struct IndexTagType {};
31 typedef o3tl::strong_int<sal_uInt32, IndexTagType> Index;
32 static Index const IndexNotFound;// = Index(SAL_MAX_UINT32);
34 private:
35 std::map<Index, void*> maMap;
36 Index nUniqIndex;
38 public:
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;
53 template<typename T>
54 class SAL_WARN_UNUSED UniqueIndex : private UniqueIndexImpl
56 public:
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;
72 #endif
74 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */