Revert "jsdialogs: set LOKNotifier in Deck"
[LibreOffice.git] / include / comphelper / IdPropArrayHelper.hxx
blob34e403b3ab0ae62dedda64cc40ed908769001a5d
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_COMPHELPER_IDPROPARRAYHELPER_HXX
20 #define INCLUDED_COMPHELPER_IDPROPARRAYHELPER_HXX
22 #include <sal/config.h>
24 #include <map>
26 #include <osl/mutex.hxx>
27 #include <osl/diagnose.h>
28 #include <rtl/instance.hxx>
29 #include <cppuhelper/propshlp.hxx>
31 namespace comphelper
34 // OIdPropertyArrayUsageHelper
36 template <typename TYPE> struct OIdPropertyArrayUsageHelperMutex
37 : public rtl::Static< ::osl::Mutex, OIdPropertyArrayUsageHelperMutex<TYPE> > {};
39 typedef std::map< sal_Int32, ::cppu::IPropertyArrayHelper* > OIdPropertyArrayMap;
40 template <class TYPE>
41 class OIdPropertyArrayUsageHelper
43 protected:
44 static sal_Int32 s_nRefCount;
45 static OIdPropertyArrayMap* s_pMap;
47 public:
48 OIdPropertyArrayUsageHelper();
49 virtual ~OIdPropertyArrayUsageHelper()
51 ::osl::MutexGuard aGuard(OIdPropertyArrayUsageHelperMutex<TYPE>::get());
52 OSL_ENSURE(s_nRefCount > 0, "OIdPropertyArrayUsageHelper::~OIdPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !");
53 if (!--s_nRefCount)
55 // delete the element
56 for (auto const& elem : *s_pMap)
57 delete elem.second;
58 delete s_pMap;
59 s_pMap = nullptr;
63 /** call this in the getInfoHelper method of your derived class. The method returns the array helper of the
64 class, which is created if necessary.
66 ::cppu::IPropertyArrayHelper* getArrayHelper(sal_Int32 nId);
68 protected:
69 /** used to implement the creation of the array helper which is shared amongst all instances of the class.
70 This method needs to be implemented in derived classes.
71 <BR>
72 The method gets called with Mutex acquired.
73 @return a pointer to the newly created array helper. Must not be NULL.
75 virtual ::cppu::IPropertyArrayHelper* createArrayHelper(sal_Int32 nId) const = 0;
79 template<class TYPE>
80 sal_Int32 OIdPropertyArrayUsageHelper< TYPE >::s_nRefCount = 0;
82 template<class TYPE>
83 OIdPropertyArrayMap* OIdPropertyArrayUsageHelper< TYPE >::s_pMap = nullptr;
86 template <class TYPE>
87 OIdPropertyArrayUsageHelper<TYPE>::OIdPropertyArrayUsageHelper()
89 ::osl::MutexGuard aGuard(OIdPropertyArrayUsageHelperMutex<TYPE>::get());
90 // create the map if necessary
91 if (s_pMap == nullptr)
92 s_pMap = new OIdPropertyArrayMap;
93 ++s_nRefCount;
97 template <class TYPE>
98 ::cppu::IPropertyArrayHelper* OIdPropertyArrayUsageHelper<TYPE>::getArrayHelper(sal_Int32 nId)
100 OSL_ENSURE(s_nRefCount, "OIdPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
101 ::osl::MutexGuard aGuard(OIdPropertyArrayUsageHelperMutex<TYPE>::get());
102 // do we have the array already?
103 auto& rEntry = (*s_pMap)[nId];
104 if (!rEntry)
106 rEntry = createArrayHelper(nId);
107 OSL_ENSURE((*s_pMap)[nId], "OIdPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !");
109 return (*s_pMap)[nId];
112 #endif // INCLUDED_COMPHELPER_IDPROPARRAYHELPER_HXX
114 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */