Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
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/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
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 .
18 : */
19 : #ifndef INCLUDED_TOOLS_UNQIDX_HXX
20 : #define INCLUDED_TOOLS_UNQIDX_HXX
21 :
22 : #include <tools/toolsdllapi.h>
23 : #include <tools/contnr.hxx>
24 : #include <map>
25 :
26 : #define UNIQUEINDEX_ENTRY_NOTFOUND CONTAINER_ENTRY_NOTFOUND
27 :
28 843 : class TOOLS_DLLPUBLIC SAL_WARN_UNUSED UniqueIndexImpl
29 : {
30 : private:
31 : std::map<sal_uInt32, void*> maMap;
32 : sal_uIntPtr nStartIndex;
33 : sal_uIntPtr nUniqIndex;
34 : sal_uIntPtr nCount;
35 :
36 : public:
37 843 : UniqueIndexImpl( sal_uIntPtr _nStartIndex = 0 )
38 : : maMap(),
39 843 : nStartIndex(_nStartIndex), nUniqIndex(_nStartIndex), nCount(0) {}
40 :
41 4179 : size_t size() const { return maMap.size(); }
42 :
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;
48 :
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;
53 : };
54 :
55 : template<typename T>
56 843 : class UniqueIndex : private UniqueIndexImpl
57 : {
58 : public:
59 843 : UniqueIndex<T>( sal_uIntPtr _nStartIndex = 0 ) : UniqueIndexImpl(_nStartIndex) {}
60 :
61 1205 : sal_uIntPtr Insert(T* p) { return UniqueIndexImpl::Insert(p); }
62 0 : void Insert(sal_uIntPtr aIdx, T* p) { return UniqueIndexImpl::Insert(aIdx, p); }
63 3400 : T* Get(sal_uIntPtr idx) const { return static_cast<T*>( UniqueIndexImpl::Get(idx) ); }
64 779 : T* Remove(sal_uIntPtr idx) { return static_cast<T*>( UniqueIndexImpl::Remove(idx) ); }
65 0 : sal_uIntPtr Count() const { return UniqueIndexImpl::size(); }
66 891 : sal_uIntPtr GetIndexOf(T* p) const { return UniqueIndexImpl::GetIndexOf(p); }
67 :
68 : using UniqueIndexImpl::FirstIndex;
69 : using UniqueIndexImpl::LastIndex;
70 : using UniqueIndexImpl::NextIndex;
71 : };
72 :
73 : #endif
74 :
75 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|