bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / mysqlc / mysqlc_subcomponent.hxx
blobd0847aedc5d6b99c606fdf87493a818aae793020
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 #pragma once
22 #include <cppuhelper/propshlp.hxx>
23 #include <osl/diagnose.h>
24 #include <osl/mutex.hxx>
26 namespace cppu
28 class IPropertyArrayHelper;
30 namespace com::sun::star::lang
32 class XComponent;
35 namespace connectivity::mysqlc
37 /// @throws css::lang::DisposedException
38 void checkDisposed(bool _bThrow);
40 template <class TYPE> class OPropertyArrayUsageHelper
42 protected:
43 static sal_Int32 s_nRefCount;
44 static ::cppu::IPropertyArrayHelper* s_pProps;
45 static ::osl::Mutex s_aMutex;
47 public:
48 OPropertyArrayUsageHelper();
49 virtual ~OPropertyArrayUsageHelper();
51 /** call this in the getInfoHelper method of your derived class. The method returns the array helper of the
52 class, which is created if necessary.
54 ::cppu::IPropertyArrayHelper* getArrayHelper();
56 protected:
57 /** used to implement the creation of the array helper which is shared amongst all instances of the class.
58 This method needs to be implemented in derived classes.
59 <BR>
60 The method gets called with s_aMutex acquired.
61 @return a pointer to the newly created array helper. Must not be NULL.
63 virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const = 0;
66 template <class TYPE> sal_Int32 OPropertyArrayUsageHelper<TYPE>::s_nRefCount = 0;
68 template <class TYPE>
69 ::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper<TYPE>::s_pProps = nullptr;
71 template <class TYPE>::osl::Mutex OPropertyArrayUsageHelper<TYPE>::s_aMutex;
73 template <class TYPE> OPropertyArrayUsageHelper<TYPE>::OPropertyArrayUsageHelper()
75 ::osl::MutexGuard aGuard(s_aMutex);
76 ++s_nRefCount;
79 template <class TYPE> OPropertyArrayUsageHelper<TYPE>::~OPropertyArrayUsageHelper()
81 ::osl::MutexGuard aGuard(s_aMutex);
82 OSL_ENSURE(s_nRefCount > 0, "OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper : "
83 "suspicious call : have a refcount of 0 !");
84 if (!--s_nRefCount)
86 delete s_pProps;
87 s_pProps = nullptr;
91 template <class TYPE>::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper<TYPE>::getArrayHelper()
93 OSL_ENSURE(
94 s_nRefCount,
95 "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
96 if (!s_pProps)
98 ::osl::MutexGuard aGuard(s_aMutex);
99 if (!s_pProps)
101 s_pProps = createArrayHelper();
102 OSL_ENSURE(s_pProps, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper "
103 "returned nonsense !");
106 return s_pProps;
109 class OBase_Mutex
111 public:
112 ::osl::Mutex m_aMutex;
115 namespace internal
117 template <class T> void implCopySequence(const T* _pSource, T*& _pDest, sal_Int32 _nSourceLen)
119 for (sal_Int32 i = 0; i < _nSourceLen; ++i, ++_pSource, ++_pDest)
120 *_pDest = *_pSource;
124 /// concat two sequences
125 template <class T>
126 css::uno::Sequence<T> concatSequences(const css::uno::Sequence<T>& _rLeft,
127 const css::uno::Sequence<T>& _rRight)
129 sal_Int32 nLeft(_rLeft.getLength()), nRight(_rRight.getLength());
130 const T* pLeft = _rLeft.getConstArray();
131 const T* pRight = _rRight.getConstArray();
133 sal_Int32 nReturnLen(nLeft + nRight);
134 css::uno::Sequence<T> aReturn(nReturnLen);
135 T* pReturn = aReturn.getArray();
137 internal::implCopySequence(pLeft, pReturn, nLeft);
138 internal::implCopySequence(pRight, pReturn, nRight);
140 return aReturn;
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */