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 _UNQIDX_HXX
20 : #define _UNQIDX_HXX
21 :
22 : #include "tools/toolsdllapi.h"
23 : #include <tools/solar.h>
24 : #include <tools/contnr.hxx>
25 : #include <map>
26 :
27 : #define UNIQUEINDEX_ENTRY_NOTFOUND CONTAINER_ENTRY_NOTFOUND
28 :
29 691 : class TOOLS_DLLPUBLIC SAL_WARN_UNUSED UniqueIndexImpl : public std::map<sal_uInt32, void*>
30 : {
31 : private:
32 : sal_uIntPtr nStartIndex;
33 : sal_uIntPtr nUniqIndex;
34 : sal_uIntPtr nCount;
35 :
36 : public:
37 691 : UniqueIndexImpl( sal_uIntPtr _nStartIndex = 0 )
38 : : std::map<sal_uInt32, void*>(),
39 691 : nStartIndex(_nStartIndex), nUniqIndex(_nStartIndex), nCount(0) {}
40 :
41 : sal_uIntPtr Insert( void* p );
42 : // insert value with key, replacing existing entry if necessary
43 : void Insert( sal_uIntPtr aIndex, void* p );
44 : void* Remove( sal_uIntPtr aIndex );
45 : void* Get( sal_uIntPtr aIndex ) const;
46 :
47 : sal_uIntPtr GetIndexOf( void* p ) const;
48 : sal_uIntPtr FirstIndex() const;
49 : sal_uIntPtr LastIndex() const;
50 : sal_uIntPtr NextIndex( sal_uIntPtr aCurrIndex ) const;
51 : };
52 :
53 : template<typename T>
54 691 : class UniqueIndex : private UniqueIndexImpl
55 : {
56 : public:
57 691 : UniqueIndex<T>( sal_uIntPtr _nStartIndex = 0 ) : UniqueIndexImpl(_nStartIndex) {}
58 :
59 1323 : sal_uIntPtr Insert(T* p) { return UniqueIndexImpl::Insert(p); }
60 : void Insert(sal_uIntPtr aIdx, T* p) { return UniqueIndexImpl::Insert(aIdx, p); }
61 5669 : T* Get(sal_uIntPtr idx) const { return static_cast<T*>( UniqueIndexImpl::Get(idx) ); }
62 1323 : T* Remove(sal_uIntPtr idx) { return static_cast<T*>( UniqueIndexImpl::Remove(idx) ); }
63 : sal_uIntPtr Count() const { return UniqueIndexImpl::size(); }
64 1447 : sal_uIntPtr GetIndexOf(T* p) const { return UniqueIndexImpl::GetIndexOf(p); }
65 :
66 : using UniqueIndexImpl::FirstIndex;
67 : using UniqueIndexImpl::LastIndex;
68 : using UniqueIndexImpl::NextIndex;
69 : };
70 :
71 : #endif
72 :
73 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|