build fix
[LibreOffice.git] / connectivity / source / drivers / firebird / SubComponent.hxx
blob609c07a9249c3a3920a72b5eeb33f792c1815bce
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_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_SUBCOMPONENT_HXX
21 #define INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_SUBCOMPONENT_HXX
23 #include <cppuhelper/interfacecontainer.h>
24 #include <cppuhelper/propshlp.hxx>
25 #include <cppuhelper/weak.hxx>
26 #include <osl/diagnose.h>
27 #include <osl/mutex.hxx>
29 #include <com/sun/star/lang/DisposedException.hpp>
31 namespace cppu {
32 class IPropertyArrayHelper;
35 namespace com
37 namespace sun
39 namespace star
41 namespace lang
43 class XComponent;
48 namespace connectivity
51 namespace firebird
53 void release(oslInterlockedCount& _refCount,
54 ::cppu::OBroadcastHelper& rBHelper,
55 css::uno::Reference< css::uno::XInterface >& _xInterface,
56 css::lang::XComponent* _pObject);
58 void checkDisposed(bool _bThrow) throw ( css::lang::DisposedException );
61 template <class TYPE>
62 class OPropertyArrayUsageHelper
64 protected:
65 static sal_Int32 s_nRefCount;
66 static ::cppu::IPropertyArrayHelper* s_pProps;
67 static ::osl::Mutex s_aMutex;
69 public:
70 OPropertyArrayUsageHelper();
71 virtual ~OPropertyArrayUsageHelper();
73 /** call this in the getInfoHelper method of your derived class. The method returns the array helper of the
74 class, which is created if necessary.
76 ::cppu::IPropertyArrayHelper* getArrayHelper();
78 protected:
79 /** used to implement the creation of the array helper which is shared amongst all instances of the class.
80 This method needs to be implemented in derived classes.
81 <BR>
82 The method gets called with s_aMutex acquired.
83 @return an pointer to the newly created array helper. Must not be NULL.
85 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const = 0;
88 template<class TYPE>
89 sal_Int32 OPropertyArrayUsageHelper< TYPE >::s_nRefCount = 0;
91 template<class TYPE>
92 ::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper< TYPE >::s_pProps = nullptr;
94 template<class TYPE>
95 ::osl::Mutex OPropertyArrayUsageHelper< TYPE >::s_aMutex;
98 template <class TYPE>
99 OPropertyArrayUsageHelper<TYPE>::OPropertyArrayUsageHelper()
101 ::osl::MutexGuard aGuard(s_aMutex);
102 ++s_nRefCount;
106 template <class TYPE>
107 OPropertyArrayUsageHelper<TYPE>::~OPropertyArrayUsageHelper()
109 ::osl::MutexGuard aGuard(s_aMutex);
110 OSL_ENSURE(s_nRefCount > 0, "OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !");
111 if (!--s_nRefCount)
113 delete s_pProps;
114 s_pProps = nullptr;
119 template <class TYPE>
120 ::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper<TYPE>::getArrayHelper()
122 OSL_ENSURE(s_nRefCount, "OPropertyArrayUsageHelper::getArrayHelper : suspicious call : have a refcount of 0 !");
123 if (!s_pProps)
125 ::osl::MutexGuard aGuard(s_aMutex);
126 if (!s_pProps)
128 s_pProps = createArrayHelper();
129 OSL_ENSURE(s_pProps, "OPropertyArrayUsageHelper::getArrayHelper : createArrayHelper returned nonsense !");
132 return s_pProps;
137 #endif // INCLUDED_CONNECTIVITY_SOURCE_DRIVERS_FIREBIRD_SUBCOMPONENT_HXX
139 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */