nss: upgrade to release 3.73
[LibreOffice.git] / connectivity / source / drivers / mysqlc / mysqlc_subcomponent.hxx
blob6d1c078010247333216823e6fcfba9078825f21c
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 <cppuhelper/propshlp.hxx>
24 #include <osl/diagnose.h>
25 #include <osl/mutex.hxx>
27 namespace cppu
29 class IPropertyArrayHelper;
31 namespace com::sun::star::lang
33 class XComponent;
36 namespace connectivity::mysqlc
38 /// @throws css::lang::DisposedException
39 void checkDisposed(bool _bThrow);
41 template <class TYPE> class OPropertyArrayUsageHelper
43 protected:
44 static sal_Int32 s_nRefCount;
45 static ::cppu::IPropertyArrayHelper* s_pProps;
46 static ::osl::Mutex s_aMutex;
48 public:
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();
57 protected:
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.
60 <BR>
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;
69 template <class TYPE>
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);
77 ++s_nRefCount;
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 !");
85 if (!--s_nRefCount)
87 delete s_pProps;
88 s_pProps = nullptr;
92 template <class TYPE>::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper<TYPE>::getArrayHelper()
94 OSL_ENSURE(
95 s_nRefCount,
96 "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
97 if (!s_pProps)
99 ::osl::MutexGuard aGuard(s_aMutex);
100 if (!s_pProps)
102 s_pProps = createArrayHelper();
103 OSL_ENSURE(s_pProps, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper "
104 "returned nonsense !");
107 return s_pProps;
110 class OBase_Mutex
112 public:
113 ::osl::Mutex m_aMutex;
116 namespace internal
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)
121 *_pDest = *_pSource;
125 /// concat two sequences
126 template <class T>
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);
141 return aReturn;
145 #endif // INCLUDED_MYSQLC_SOURCE_MYSQLC_SUBCOMPONENT_HXX
147 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */