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_MYSQLC_SOURCE_MYSQLC_SUBCOMPONENT_HXX
21 #define INCLUDED_MYSQLC_SOURCE_MYSQLC_SUBCOMPONENT_HXX
23 #include <com/sun/star/lang/DisposedException.hpp>
24 #include <cppuhelper/interfacecontainer.h>
25 #include <cppuhelper/propshlp.hxx>
26 #include <cppuhelper/supportsservice.hxx>
27 #include <cppuhelper/weak.hxx>
28 #include <osl/diagnose.h>
29 #include <osl/mutex.hxx>
32 class IPropertyArrayHelper
;
49 namespace connectivity
53 void release(oslInterlockedCount
& _refCount
,
54 ::cppu::OBroadcastHelper
& rBHelper
,
55 css::uno::Reference
< css::uno::XInterface
>& _xInterface
,
56 css::lang::XComponent
* _pObject
);
58 void checkDisposed(bool _bThrow
) throw (css::lang::DisposedException
);
60 template <class SELF
, class WEAK
> class OSubComponent
63 // the parent must support the tunnel implementation
64 css::uno::Reference
< css::uno::XInterface
> m_xParent
;
65 SELF
* m_pDerivedImplementation
;
69 const css::uno::Reference
< css::uno::XInterface
>& _xParent
,
70 SELF
* _pDerivedImplementation
)
72 ,m_pDerivedImplementation(_pDerivedImplementation
)
77 void dispose_ChildImpl()
79 ::osl::MutexGuard
aGuard(m_pDerivedImplementation
->rBHelper
.rMutex
);
82 void release_ChildImpl()
84 release(m_pDerivedImplementation
->m_refCount
,
85 m_pDerivedImplementation
->rBHelper
,
87 m_pDerivedImplementation
);
89 m_pDerivedImplementation
->WEAK::release();
94 class OPropertyArrayUsageHelper
97 static sal_Int32 s_nRefCount
;
98 static ::cppu::IPropertyArrayHelper
* s_pProps
;
99 static ::osl::Mutex s_aMutex
;
102 OPropertyArrayUsageHelper();
103 virtual ~OPropertyArrayUsageHelper();
105 /** call this in the getInfoHelper method of your derived class. The method returns the array helper of the
106 class, which is created if necessary.
108 ::cppu::IPropertyArrayHelper
* getArrayHelper();
111 /** used to implement the creation of the array helper which is shared amongst all instances of the class.
112 This method needs to be implemented in derived classes.
114 The method gets called with s_aMutex acquired.
115 @return an pointer to the newly created array helper. Must not be NULL.
117 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper() const = 0;
121 sal_Int32 OPropertyArrayUsageHelper
< TYPE
>::s_nRefCount
= 0;
124 ::cppu::IPropertyArrayHelper
* OPropertyArrayUsageHelper
< TYPE
>::s_pProps
= nullptr;
127 ::osl::Mutex OPropertyArrayUsageHelper
< TYPE
>::s_aMutex
;
129 template <class TYPE
>
130 OPropertyArrayUsageHelper
<TYPE
>::OPropertyArrayUsageHelper()
132 ::osl::MutexGuard
aGuard(s_aMutex
);
136 template <class TYPE
>
137 OPropertyArrayUsageHelper
<TYPE
>::~OPropertyArrayUsageHelper()
139 ::osl::MutexGuard
aGuard(s_aMutex
);
140 OSL_ENSURE(s_nRefCount
> 0, "OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !");
148 template <class TYPE
>
149 ::cppu::IPropertyArrayHelper
* OPropertyArrayUsageHelper
<TYPE
>::getArrayHelper()
151 OSL_ENSURE(s_nRefCount
, "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
153 ::osl::MutexGuard
aGuard(s_aMutex
);
155 s_pProps
= createArrayHelper();
156 OSL_ENSURE(s_pProps
, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !");
165 ::osl::Mutex m_aMutex
;
171 void implCopySequence(const T
* _pSource
, T
*& _pDest
, sal_Int32 _nSourceLen
)
173 for (sal_Int32 i
=0; i
<_nSourceLen
; ++i
, ++_pSource
, ++_pDest
)
178 /// concat two sequences
180 css::uno::Sequence
<T
> concatSequences(const css::uno::Sequence
<T
>& _rLeft
, const css::uno::Sequence
<T
>& _rRight
)
182 sal_Int32
nLeft(_rLeft
.getLength()), nRight(_rRight
.getLength());
183 const T
* pLeft
= _rLeft
.getConstArray();
184 const T
* pRight
= _rRight
.getConstArray();
186 sal_Int32
nReturnLen(nLeft
+ nRight
);
187 css::uno::Sequence
<T
> aReturn(nReturnLen
);
188 T
* pReturn
= aReturn
.getArray();
190 internal::implCopySequence(pLeft
, pReturn
, nLeft
);
191 internal::implCopySequence(pRight
, pReturn
, nRight
);
198 #endif // INCLUDED_MYSQLC_SOURCE_MYSQLC_SUBCOMPONENT_HXX
200 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */