bump product version to 5.0.4.1
[LibreOffice.git] / mysqlc / source / mysqlc_subcomponent.hxx
blobb225e6754aa0b893a62df404551d89df4dd65f2b
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_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>
31 namespace cppu {
32 class IPropertyArrayHelper;
35 namespace com
37 namespace sun
39 namespace star
41 namespace lang
43 class XComponent;
49 namespace connectivity
51 namespace mysqlc
53 void release(oslInterlockedCount& _refCount,
54 ::cppu::OBroadcastHelper& rBHelper,
55 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xInterface,
56 ::com::sun::star::lang::XComponent* _pObject);
58 void checkDisposed(bool _bThrow) throw (::com::sun::star::lang::DisposedException);
60 template <class SELF, class WEAK> class OSubComponent
62 protected:
63 // the parent must support the tunnel implementation
64 ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface > m_xParent;
65 SELF* m_pDerivedImplementation;
67 public:
68 OSubComponent(
69 const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& _xParent,
70 SELF* _pDerivedImplementation)
71 :m_xParent(_xParent)
72 ,m_pDerivedImplementation(_pDerivedImplementation)
76 protected:
77 void dispose_ChildImpl()
79 ::osl::MutexGuard aGuard(m_pDerivedImplementation->rBHelper.rMutex);
80 m_xParent = NULL;
82 void relase_ChildImpl()
84 release(m_pDerivedImplementation->m_refCount,
85 m_pDerivedImplementation->rBHelper,
86 m_xParent,
87 m_pDerivedImplementation);
89 m_pDerivedImplementation->WEAK::release();
93 template <class TYPE>
94 class OPropertyArrayUsageHelper
96 protected:
97 static sal_Int32 s_nRefCount;
98 static ::cppu::IPropertyArrayHelper* s_pProps;
99 static ::osl::Mutex s_aMutex;
101 public:
102 OPropertyArrayUsageHelper();
103 virtual ~OPropertyArrayUsageHelper()
104 { // ARGHHHHHHH ..... would like to implement this in proparrhlp_impl.hxx (as we do with all other methods)
105 // but SUNPRO 5 compiler (linker) doesn't like this
106 ::osl::MutexGuard aGuard(s_aMutex);
107 OSL_ENSURE(s_nRefCount > 0, "OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !");
108 if (!--s_nRefCount)
110 delete s_pProps;
111 s_pProps = NULL;
115 /** call this in the getInfoHelper method of your derived class. The method returns the array helper of the
116 class, which is created if necessary.
118 ::cppu::IPropertyArrayHelper* getArrayHelper();
120 protected:
121 /** used to implement the creation of the array helper which is shared amongst all instances of the class.
122 This method needs to be implemented in derived classes.
123 <BR>
124 The method gets called with s_aMutex acquired.
125 <BR>
126 as long as IPropertyArrayHelper has no virtual destructor, the implementation of ~OPropertyArrayUsageHelper
127 assumes that you created an ::cppu::OPropertyArrayHelper when deleting s_pProps.
128 @return an pointer to the newly created array helper. Must not be NULL.
130 virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const = 0;
133 template<class TYPE>
134 sal_Int32 OPropertyArrayUsageHelper< TYPE >::s_nRefCount = 0;
136 template<class TYPE>
137 ::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper< TYPE >::s_pProps = NULL;
139 template<class TYPE>
140 ::osl::Mutex OPropertyArrayUsageHelper< TYPE >::s_aMutex;
142 template <class TYPE>
143 OPropertyArrayUsageHelper<TYPE>::OPropertyArrayUsageHelper()
145 ::osl::MutexGuard aGuard(s_aMutex);
146 ++s_nRefCount;
149 template <class TYPE>
150 ::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper<TYPE>::getArrayHelper()
152 OSL_ENSURE(s_nRefCount, "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
153 if (!s_pProps) {
154 ::osl::MutexGuard aGuard(s_aMutex);
155 if (!s_pProps) {
156 s_pProps = createArrayHelper();
157 OSL_ENSURE(s_pProps, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !");
160 return s_pProps;
163 class OBase_Mutex
165 public:
166 ::osl::Mutex m_aMutex;
169 namespace internal
171 template <class T>
172 void implCopySequence(const T* _pSource, T*& _pDest, sal_Int32 _nSourceLen)
174 for (sal_Int32 i=0; i<_nSourceLen; ++i, ++_pSource, ++_pDest)
175 *_pDest = *_pSource;
179 /// concat two sequences
180 template <class T>
181 ::com::sun::star::uno::Sequence<T> concatSequences(const ::com::sun::star::uno::Sequence<T>& _rLeft, const ::com::sun::star::uno::Sequence<T>& _rRight)
183 sal_Int32 nLeft(_rLeft.getLength()), nRight(_rRight.getLength());
184 const T* pLeft = _rLeft.getConstArray();
185 const T* pRight = _rRight.getConstArray();
187 sal_Int32 nReturnLen(nLeft + nRight);
188 ::com::sun::star::uno::Sequence<T> aReturn(nReturnLen);
189 T* pReturn = aReturn.getArray();
191 internal::implCopySequence(pLeft, pReturn, nLeft);
192 internal::implCopySequence(pRight, pReturn, nRight);
194 return aReturn;
199 #endif // INCLUDED_MYSQLC_SOURCE_MYSQLC_SUBCOMPONENT_HXX
201 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */