1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
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>
30 class IPropertyArrayHelper
;
36 template <typename TYPE
> struct OPropertyArrayUsageHelperMutex
37 : public rtl::Static
< ::osl::Mutex
, OPropertyArrayUsageHelperMutex
<TYPE
> > {};
40 class OPropertyArrayUsageHelper
43 static sal_Int32 s_nRefCount
;
44 static ::cppu::IPropertyArrayHelper
* s_pProps
;
47 OPropertyArrayUsageHelper();
48 virtual ~OPropertyArrayUsageHelper()
49 { // ARGHHHHHHH ..... would like to implement this after the class
50 // definition (as we do with all other methods) but SUNPRO 5 compiler
51 // (linker) doesn't like this
52 ::osl::MutexGuard
aGuard(OPropertyArrayUsageHelperMutex
<TYPE
>::get());
53 OSL_ENSURE(s_nRefCount
> 0, "OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !");
61 /** call this in the getInfoHelper method of your derived class. The method returns the array helper of the
62 class, which is created if necessary.
64 ::cppu::IPropertyArrayHelper
* getArrayHelper();
67 /** used to implement the creation of the array helper which is shared amongst all instances of the class.
68 This method needs to be implemented in derived classes.
70 The method gets called with Mutex acquired.
72 as long as IPropertyArrayHelper has no virtual destructor, the implementation of ~OPropertyArrayUsageHelper
73 assumes that you created an ::cppu::OPropertyArrayHelper when deleting s_pProps.
74 @return an pointer to the newly created array helper. Must not be NULL.
76 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const = 0;
79 /** a OPropertyArrayUsageHelper which will create an OPropertyArrayAggregationHelper
82 class OAggregationArrayUsageHelper
: public OPropertyArrayUsageHelper
<TYPE
>
85 /** overwrite this in your derived class. initialize the two sequences with your and your aggregate's
88 The method gets called with Mutex acquired.
89 @param _rProps out parameter to be filled with the property descriptions of your own class
90 @param _rAggregateProps out parameter to be filled with the properties of your aggregate.
92 virtual void fillProperties(
93 css::uno::Sequence
< css::beans::Property
>& /* [out] */ _rProps
,
94 css::uno::Sequence
< css::beans::Property
>& /* [out] */ _rAggregateProps
97 /** creates an OPropertyArrayAggregationHelper filled with properties for which's initialization
98 fillProperties is called. getInfoService and getFirstAggregateId may be overwritten to determine
99 the additional parameters of the OPropertyArrayAggregationHelper.
101 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper( ) const;
103 /** the return value is used for the construction of the OPropertyArrayAggregationHelper.
104 Beware of the lifetime of the returned object, as it has to exist 'til the last instance
107 virtual IPropertyInfoService
* getInfoService() const { return nullptr; }
109 /** the return value is used for the construction of the OPropertyArrayAggregationHelper.
111 virtual sal_Int32
getFirstAggregateId() const { return DEFAULT_AGGREGATE_PROPERTY_ID
; }
115 sal_Int32 OPropertyArrayUsageHelper
< TYPE
>::s_nRefCount
= 0;
118 ::cppu::IPropertyArrayHelper
* OPropertyArrayUsageHelper
< TYPE
>::s_pProps
= nullptr;
120 template <class TYPE
>
121 OPropertyArrayUsageHelper
<TYPE
>::OPropertyArrayUsageHelper()
123 ::osl::MutexGuard
aGuard(OPropertyArrayUsageHelperMutex
<TYPE
>::get());
127 template <class TYPE
>
128 ::cppu::IPropertyArrayHelper
* OPropertyArrayUsageHelper
<TYPE
>::getArrayHelper()
130 OSL_ENSURE(s_nRefCount
, "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
133 ::osl::MutexGuard
aGuard(OPropertyArrayUsageHelperMutex
<TYPE
>::get());
136 s_pProps
= createArrayHelper();
137 OSL_ENSURE(s_pProps
, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !");
143 template <class TYPE
> inline
144 ::cppu::IPropertyArrayHelper
* OAggregationArrayUsageHelper
<TYPE
>::createArrayHelper() const
146 css::uno::Sequence
< css::beans::Property
> aProps
;
147 css::uno::Sequence
< css::beans::Property
> aAggregateProps
;
148 fillProperties(aProps
, aAggregateProps
);
149 OSL_ENSURE(aProps
.getLength(), "OAggregationArrayUsageHelper::createArrayHelper : fillProperties returned nonsense !");
150 return new OPropertyArrayAggregationHelper(aProps
, aAggregateProps
, getInfoService(), getFirstAggregateId());
155 #endif // INCLUDED_COMPHELPER_PROPARRHLP_HXX
157 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */