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 .
22 #include <cppuhelper/propshlp.hxx>
23 #include <osl/diagnose.h>
24 #include <osl/mutex.hxx>
28 class IPropertyArrayHelper
;
30 namespace com::sun::star::lang
35 namespace connectivity::mysqlc
37 /// @throws css::lang::DisposedException
38 void checkDisposed(bool _bThrow
);
40 template <class TYPE
> class OPropertyArrayUsageHelper
43 static sal_Int32 s_nRefCount
;
44 static ::cppu::IPropertyArrayHelper
* s_pProps
;
45 static ::osl::Mutex s_aMutex
;
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();
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.
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;
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
);
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 !");
91 template <class TYPE
>::cppu::IPropertyArrayHelper
* OPropertyArrayUsageHelper
<TYPE
>::getArrayHelper()
95 "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
98 ::osl::MutexGuard
aGuard(s_aMutex
);
101 s_pProps
= createArrayHelper();
102 OSL_ENSURE(s_pProps
, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper "
103 "returned nonsense !");
112 ::osl::Mutex m_aMutex
;
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
)
124 /// concat two sequences
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
);
144 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */