LibreOffice Module comphelper (master) 1
proparrhlp.hxx
Go to the documentation of this file.
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
20#ifndef INCLUDED_COMPHELPER_PROPARRHLP_HXX
21#define INCLUDED_COMPHELPER_PROPARRHLP_HXX
22
25#include <mutex>
26#include <osl/diagnose.h>
27
28namespace comphelper
29{
30
31template <class TYPE>
33{
34protected:
35 static sal_Int32 s_nRefCount;
36 static ::cppu::IPropertyArrayHelper* s_pProps;
38 {
39 static std::mutex SINGLETON;
40 return SINGLETON;
41 }
42public:
45
50
51protected:
58 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const = 0;
59};
60
63template <class TYPE>
65{
66protected:
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;
78
83 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const;
84};
85
86template<class TYPE>
88
89template<class TYPE>
91
92template <class TYPE>
94{
95 std::unique_lock aGuard(theMutex());
96 ++s_nRefCount;
97}
98
99template <class TYPE>
101{
102 std::unique_lock aGuard(theMutex());
103 OSL_ENSURE(s_nRefCount > 0, "OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !");
104 if (!--s_nRefCount)
105 {
106 delete s_pProps;
107 s_pProps = nullptr;
108 }
109}
110
111template <class TYPE>
113{
114 OSL_ENSURE(s_nRefCount, "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
115 if (!s_pProps)
116 {
117 std::unique_lock aGuard(theMutex());
118 if (!s_pProps)
119 {
120 s_pProps = createArrayHelper();
121 OSL_ENSURE(s_pProps, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !");
122 }
123 }
124 return s_pProps;
125}
126
127template <class TYPE> inline
128::cppu::IPropertyArrayHelper* OAggregationArrayUsageHelper<TYPE>::createArrayHelper() const
129{
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);
135}
136
137}
138
139#endif // INCLUDED_COMPHELPER_PROPARRHLP_HXX
140
141/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
an OPropertyArrayUsageHelper which will create an OPropertyArrayAggregationHelper
Definition: proparrhlp.hxx:65
virtual void fillProperties(css::uno::Sequence< css::beans::Property > &_rProps, css::uno::Sequence< css::beans::Property > &_rAggregateProps) const =0
overwrite this in your derived class.
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const
creates an OPropertyArrayAggregationHelper filled with properties for which's initialization fillProp...
Definition: proparrhlp.hxx:128
::cppu::IPropertyArrayHelper * s_pProps
Definition: proparrhlp.hxx:36
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const =0
used to implement the creation of the array helper which is shared amongst all instances of the class...
::cppu::IPropertyArrayHelper * getArrayHelper()
call this in the getInfoHelper method of your derived class.
Definition: proparrhlp.hxx:112
#define DEFAULT_AGGREGATE_PROPERTY_ID
used for implementing a cppu::IPropertyArrayHelper for classes aggregating property sets
Definition: propagg.hxx:87
std::mutex mutex
Definition: random.cxx:41