bump product version to 7.2.5.1
[LibreOffice.git] / connectivity / source / drivers / firebird / SubComponent.hxx
blobbea5d76d423d06f4d388866d1284a03147af62b4
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
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 { class IPropertyArrayHelper; }
27 namespace com::sun::star::lang { class XComponent; }
29 namespace connectivity::firebird
31 /// @throws css::lang::DisposedException
32 void checkDisposed(bool _bThrow);
35 template <class TYPE>
36 class OPropertyArrayUsageHelper
38 protected:
39 static sal_Int32 s_nRefCount;
40 static ::cppu::IPropertyArrayHelper* s_pProps;
41 static ::osl::Mutex s_aMutex;
43 public:
44 OPropertyArrayUsageHelper();
45 virtual ~OPropertyArrayUsageHelper();
47 /** call this in the getInfoHelper method of your derived class. The method returns the array helper of the
48 class, which is created if necessary.
50 ::cppu::IPropertyArrayHelper* getArrayHelper();
52 protected:
53 /** used to implement the creation of the array helper which is shared amongst all instances of the class.
54 This method needs to be implemented in derived classes.
55 <BR>
56 The method gets called with s_aMutex acquired.
57 @return a pointer to the newly created array helper. Must not be NULL.
59 virtual ::cppu::IPropertyArrayHelper* createArrayHelper( ) const = 0;
62 template<class TYPE>
63 sal_Int32 OPropertyArrayUsageHelper< TYPE >::s_nRefCount = 0;
65 template<class TYPE>
66 ::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper< TYPE >::s_pProps = nullptr;
68 template<class TYPE>
69 ::osl::Mutex OPropertyArrayUsageHelper< TYPE >::s_aMutex;
72 template <class TYPE>
73 OPropertyArrayUsageHelper<TYPE>::OPropertyArrayUsageHelper()
75 ::osl::MutexGuard aGuard(s_aMutex);
76 ++s_nRefCount;
80 template <class TYPE>
81 OPropertyArrayUsageHelper<TYPE>::~OPropertyArrayUsageHelper()
83 ::osl::MutexGuard aGuard(s_aMutex);
84 OSL_ENSURE(s_nRefCount > 0, "OPropertyArrayUsageHelper::~OPropertyArrayUsageHelper : suspicious call : have a refcount of 0 !");
85 if (!--s_nRefCount)
87 delete s_pProps;
88 s_pProps = nullptr;
93 template <class TYPE>
94 ::cppu::IPropertyArrayHelper* OPropertyArrayUsageHelper<TYPE>::getArrayHelper()
96 OSL_ENSURE(s_nRefCount, "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 returned nonsense !");
106 return s_pProps;
111 /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */