Revert "jsdialogs: set LOKNotifier in Deck"
[LibreOffice.git] / include / comphelper / proparrhlp.hxx
bloba53b718c26972bdcd45f1ce4ff1c04a2e9fd94f2
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 .
20 #ifndef INCLUDED_COMPHELPER_PROPARRHLP_HXX
21 #define INCLUDED_COMPHELPER_PROPARRHLP_HXX
23 #include <comphelper/propagg.hxx>
24 #include <cppuhelper/propshlp.hxx>
25 #include <osl/mutex.hxx>
26 #include <osl/diagnose.h>
27 #include <rtl/instance.hxx>
29 namespace comphelper
32 template <typename TYPE> struct OPropertyArrayUsageHelperMutex
33 : public rtl::Static< ::osl::Mutex, OPropertyArrayUsageHelperMutex<TYPE> > {};
35 template <class TYPE>
36 class OPropertyArrayUsageHelper
38 protected:
39 static sal_Int32 s_nRefCount;
40 static ::cppu::IPropertyArrayHelper* s_pProps;
42 public:
43 OPropertyArrayUsageHelper();
44 virtual ~OPropertyArrayUsageHelper();
46 /** call this in the getInfoHelper method of your derived class. The method returns the array helper of the
47 class, which is created if necessary.
49 ::cppu::IPropertyArrayHelper* getArrayHelper();
51 protected:
52 /** used to implement the creation of the array helper which is shared amongst all instances of the class.
53 This method needs to be implemented in derived classes.
54 <BR>
55 The method gets called with Mutex acquired.
56 @return a pointer to the newly created array helper. Must not be NULL.
58 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const = 0;
61 /** an OPropertyArrayUsageHelper which will create an OPropertyArrayAggregationHelper
63 template <class TYPE>
64 class OAggregationArrayUsageHelper: public OPropertyArrayUsageHelper<TYPE>
66 protected:
67 /** overwrite this in your derived class. initialize the two sequences with your and your aggregate's
68 properties.
69 <BR>
70 The method gets called with Mutex acquired.
71 @param _rProps out parameter to be filled with the property descriptions of your own class
72 @param _rAggregateProps out parameter to be filled with the properties of your aggregate.
74 virtual void fillProperties(
75 css::uno::Sequence< css::beans::Property >& /* [out] */ _rProps,
76 css::uno::Sequence< css::beans::Property >& /* [out] */ _rAggregateProps
77 ) const = 0;
79 /** creates an OPropertyArrayAggregationHelper filled with properties for which's initialization
80 fillProperties is called. getInfoService and getFirstAggregateId may be overwritten to determine
81 the additional parameters of the OPropertyArrayAggregationHelper.
83 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
86 template<class TYPE>
87 sal_Int32 OPropertyArrayUsageHelper< TYPE >::s_nRefCount = 0;
89 template<class TYPE>
90 ::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper< TYPE >::s_pProps = nullptr;
92 template <class TYPE>
93 OPropertyArrayUsageHelper<TYPE>::OPropertyArrayUsageHelper()
95 ::osl::MutexGuard aGuard(OPropertyArrayUsageHelperMutex<TYPE>::get());
96 ++s_nRefCount;
99 template <class TYPE>
100 OPropertyArrayUsageHelper<TYPE>::~OPropertyArrayUsageHelper()
102 ::osl::MutexGuard aGuard(OPropertyArrayUsageHelperMutex<TYPE>::get());
103 OSL_ENSURE(s_nRefCount > 0, "OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !");
104 if (!--s_nRefCount)
106 delete s_pProps;
107 s_pProps = nullptr;
111 template <class TYPE>
112 ::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper<TYPE>::getArrayHelper()
114 OSL_ENSURE(s_nRefCount, "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
115 if (!s_pProps)
117 ::osl::MutexGuard aGuard(OPropertyArrayUsageHelperMutex<TYPE>::get());
118 if (!s_pProps)
120 s_pProps = createArrayHelper();
121 OSL_ENSURE(s_pProps, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !");
124 return s_pProps;
127 template <class TYPE> inline
128 ::cppu::IPropertyArrayHelper* OAggregationArrayUsageHelper<TYPE>::createArrayHelper() const
130 css::uno::Sequence< css::beans::Property > aProps;
131 css::uno::Sequence< css::beans::Property > aAggregateProps;
132 fillProperties(aProps, aAggregateProps);
133 OSL_ENSURE(aProps.hasElements(), "OAggregationArrayUsageHelper::createArrayHelper : fillProperties returned nonsense !");
134 return new OPropertyArrayAggregationHelper(aProps, aAggregateProps, nullptr, DEFAULT_AGGREGATE_PROPERTY_ID);
139 #endif // INCLUDED_COMPHELPER_PROPARRHLP_HXX
141 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */