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 
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>
28 
29 namespace comphelper
30 {
31 
32 template <typename TYPE> struct OPropertyArrayUsageHelperMutex
33  : public rtl::Static< ::osl::Mutex, OPropertyArrayUsageHelperMutex<TYPE> > {};
34 
35 template <class TYPE>
37 {
38 protected:
39  static sal_Int32 s_nRefCount;
40  static ::cppu::IPropertyArrayHelper* s_pProps;
41 
42 public:
45 
50 
51 protected:
58  virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const = 0;
59 };
60 
63 template <class TYPE>
65 {
66 protected:
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 
86 template<class TYPE>
88 
89 template<class TYPE>
91 
92 template <class TYPE>
94 {
95  ::osl::MutexGuard aGuard(OPropertyArrayUsageHelperMutex<TYPE>::get());
96  ++s_nRefCount;
97 }
98 
99 template <class TYPE>
101 {
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)
105  {
106  delete s_pProps;
107  s_pProps = nullptr;
108  }
109 }
110 
111 template <class TYPE>
113 {
114  OSL_ENSURE(s_nRefCount, "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
115  if (!s_pProps)
116  {
117  ::osl::MutexGuard aGuard(OPropertyArrayUsageHelperMutex<TYPE>::get());
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 
127 template <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: */
::cppu::IPropertyArrayHelper * s_pProps
Definition: proparrhlp.hxx:40
an OPropertyArrayUsageHelper which will create an OPropertyArrayAggregationHelper ...
Definition: proparrhlp.hxx:64
::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:91
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const
creates an OPropertyArrayAggregationHelper filled with properties for which's initialization fillProp...
Definition: proparrhlp.hxx:128
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 =0
used to implement the creation of the array helper which is shared amongst all instances of the class...