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 <cppuhelper/propshlp.hxx>
24 #include <osl/diagnose.h>
25 #include <osl/mutex.hxx>
29 class IPropertyArrayHelper
;
31 namespace com::sun::star::lang
36 namespace connectivity::mysqlc
38 /// @throws css::lang::DisposedException
39 void checkDisposed(bool _bThrow
);
41 template <class TYPE
> class OPropertyArrayUsageHelper
44 static sal_Int32 s_nRefCount
;
45 static ::cppu::IPropertyArrayHelper
* s_pProps
;
46 static ::osl::Mutex s_aMutex
;
49 OPropertyArrayUsageHelper();
50 virtual ~OPropertyArrayUsageHelper();
52 /** call this in the getInfoHelper method of your derived class. The method returns the array helper of the
53 class, which is created if necessary.
55 ::cppu::IPropertyArrayHelper
* getArrayHelper();
58 /** used to implement the creation of the array helper which is shared amongst all instances of the class.
59 This method needs to be implemented in derived classes.
61 The method gets called with s_aMutex acquired.
62 @return a pointer to the newly created array helper. Must not be NULL.
64 virtual ::cppu::IPropertyArrayHelper
* createArrayHelper() const = 0;
67 template <class TYPE
> sal_Int32 OPropertyArrayUsageHelper
<TYPE
>::s_nRefCount
= 0;
70 ::cppu::IPropertyArrayHelper
* OPropertyArrayUsageHelper
<TYPE
>::s_pProps
= nullptr;
72 template <class TYPE
>::osl::Mutex OPropertyArrayUsageHelper
<TYPE
>::s_aMutex
;
74 template <class TYPE
> OPropertyArrayUsageHelper
<TYPE
>::OPropertyArrayUsageHelper()
76 ::osl::MutexGuard
aGuard(s_aMutex
);
80 template <class TYPE
> OPropertyArrayUsageHelper
<TYPE
>::~OPropertyArrayUsageHelper()
82 ::osl::MutexGuard
aGuard(s_aMutex
);
83 OSL_ENSURE(s_nRefCount
> 0, "OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper : "
84 "suspicious call : have a refcount of 0 !");
92 template <class TYPE
>::cppu::IPropertyArrayHelper
* OPropertyArrayUsageHelper
<TYPE
>::getArrayHelper()
96 "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
99 ::osl::MutexGuard
aGuard(s_aMutex
);
102 s_pProps
= createArrayHelper();
103 OSL_ENSURE(s_pProps
, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper "
104 "returned nonsense !");
113 ::osl::Mutex m_aMutex
;
118 template <class T
> void implCopySequence(const T
* _pSource
, T
*& _pDest
, sal_Int32 _nSourceLen
)
120 for (sal_Int32 i
= 0; i
< _nSourceLen
; ++i
, ++_pSource
, ++_pDest
)
125 /// concat two sequences
127 css::uno::Sequence
<T
> concatSequences(const css::uno::Sequence
<T
>& _rLeft
,
128 const css::uno::Sequence
<T
>& _rRight
)
130 sal_Int32
nLeft(_rLeft
.getLength()), nRight(_rRight
.getLength());
131 const T
* pLeft
= _rLeft
.getConstArray();
132 const T
* pRight
= _rRight
.getConstArray();
134 sal_Int32
nReturnLen(nLeft
+ nRight
);
135 css::uno::Sequence
<T
> aReturn(nReturnLen
);
136 T
* pReturn
= aReturn
.getArray();
138 internal::implCopySequence(pLeft
, pReturn
, nLeft
);
139 internal::implCopySequence(pRight
, pReturn
, nRight
);
145 #endif // INCLUDED_MYSQLC_SOURCE_MYSQLC_SUBCOMPONENT_HXX
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */