LibreOffice Module connectivity (master) 1
mysqlc_subcomponent.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
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/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
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 .
18 */
19
20#pragma once
21
23#include <osl/diagnose.h>
24#include <osl/mutex.hxx>
25
26namespace cppu
27{
28class IPropertyArrayHelper;
29}
31{
32class XComponent;
33}
34
36{
38void checkDisposed(bool _bThrow);
39
40template <class TYPE> class OPropertyArrayUsageHelper
41{
42protected:
43 static sal_Int32 s_nRefCount;
44 static ::cppu::IPropertyArrayHelper* s_pProps;
45 static ::osl::Mutex s_aMutex;
46
47public:
50
55
56protected:
63 virtual ::cppu::IPropertyArrayHelper* createArrayHelper() const = 0;
64};
65
66template <class TYPE> sal_Int32 OPropertyArrayUsageHelper<TYPE>::s_nRefCount = 0;
67
68template <class TYPE>
70
71template <class TYPE>::osl::Mutex OPropertyArrayUsageHelper<TYPE>::s_aMutex;
72
74{
75 ::osl::MutexGuard aGuard(s_aMutex);
76 ++s_nRefCount;
77}
78
80{
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)
85 {
86 delete s_pProps;
87 s_pProps = nullptr;
88 }
89}
90
91template <class TYPE>::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper<TYPE>::getArrayHelper()
92{
93 OSL_ENSURE(
94 s_nRefCount,
95 "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
96 if (!s_pProps)
97 {
98 ::osl::MutexGuard aGuard(s_aMutex);
99 if (!s_pProps)
100 {
101 s_pProps = createArrayHelper();
102 OSL_ENSURE(s_pProps, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper "
103 "returned nonsense !");
104 }
105 }
106 return s_pProps;
107}
108
109namespace internal
110{
111template <class T> void implCopySequence(const T* _pSource, T*& _pDest, sal_Int32 _nSourceLen)
112{
113 for (sal_Int32 i = 0; i < _nSourceLen; ++i, ++_pSource, ++_pDest)
114 *_pDest = *_pSource;
115}
116}
117
119template <class T>
120css::uno::Sequence<T> concatSequences(const css::uno::Sequence<T>& _rLeft,
121 const css::uno::Sequence<T>& _rRight)
122{
123 sal_Int32 nLeft(_rLeft.getLength()), nRight(_rRight.getLength());
124 const T* pLeft = _rLeft.getConstArray();
125 const T* pRight = _rRight.getConstArray();
126
127 sal_Int32 nReturnLen(nLeft + nRight);
128 css::uno::Sequence<T> aReturn(nReturnLen);
129 T* pReturn = aReturn.getArray();
130
131 internal::implCopySequence(pLeft, pReturn, nLeft);
132 internal::implCopySequence(pRight, pReturn, nRight);
133
134 return aReturn;
135}
136}
137
138/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
::cppu::IPropertyArrayHelper * getArrayHelper()
call this in the getInfoHelper method of your derived class.
virtual ::cppu::IPropertyArrayHelper * createArrayHelper() const =0
used to implement the creation of the array helper which is shared amongst all instances of the class...
void implCopySequence(const T *_pSource, T *&_pDest, sal_Int32 _nSourceLen)
void checkDisposed(bool _bThrow)
css::uno::Sequence< T > concatSequences(const css::uno::Sequence< T > &_rLeft, const css::uno::Sequence< T > &_rRight)
concat two sequences
int i