build fix
[LibreOffice.git] / include / tools / unqidx.hxx
blob2a83ed70ca72f78f6e6d0d17f859b169b09ab1c6
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 <map>
26 class SAL_WARN_UNUSED TOOLS_DLLPUBLIC UniqueIndexImpl
28 public:
29 typedef sal_uInt32 Index;
30 static Index const IndexNotFound = SAL_MAX_UINT32;
32 private:
33 std::map<Index, void*> maMap;
34 Index nUniqIndex;
36 public:
37 UniqueIndexImpl( Index nStartIndex = 0 )
38 : maMap(), nUniqIndex(nStartIndex) {}
40 Index Insert( void* p );
41 // insert value with key, replacing existing entry if necessary
42 void* Remove( Index aIndex );
43 void* Get( Index aIndex ) const;
45 Index GetIndexOf( void const* p ) const;
46 Index FirstIndex() const;
47 Index LastIndex() const;
48 Index NextIndex( Index aCurrIndex ) const;
51 template<typename T>
52 class UniqueIndex : private UniqueIndexImpl
54 public:
55 using UniqueIndexImpl::Index;
56 using UniqueIndexImpl::IndexNotFound;
58 UniqueIndex<T>( Index _nStartIndex = 0 ) : UniqueIndexImpl(_nStartIndex) {}
60 Index Insert(T* p) { return UniqueIndexImpl::Insert(p); }
61 T* Get(Index idx) const { return static_cast<T*>( UniqueIndexImpl::Get(idx) ); }
62 T* Remove(Index idx) { return static_cast<T*>( UniqueIndexImpl::Remove(idx) ); }
63 Index GetIndexOf(T* p) const { return UniqueIndexImpl::GetIndexOf(p); }
65 using UniqueIndexImpl::FirstIndex;
66 using UniqueIndexImpl::LastIndex;
67 using UniqueIndexImpl::NextIndex;
70 #endif
72 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */