From 267c6f2ac71f92999e969232431ba04678e7437e Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Mon, 15 Apr 2024 07:54:39 +0200 Subject: Adding upstream version 4:24.2.0. Signed-off-by: Daniel Baumann --- include/cppuhelper/implbase.hxx | 186 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 186 insertions(+) create mode 100644 include/cppuhelper/implbase.hxx (limited to 'include/cppuhelper/implbase.hxx') diff --git a/include/cppuhelper/implbase.hxx b/include/cppuhelper/implbase.hxx new file mode 100644 index 0000000000..f2f08650ea --- /dev/null +++ b/include/cppuhelper/implbase.hxx @@ -0,0 +1,186 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + * + * This file incorporates work covered by the following license notice: + * + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed + * with this work for additional information regarding copyright + * ownership. The ASF licenses this file to you under the Apache + * License, Version 2.0 (the "License"); you may not use this file + * except in compliance with the License. You may obtain a copy of + * the License at http://www.apache.org/licenses/LICENSE-2.0 . + */ + +#ifndef INCLUDED_CPPUHELPER_IMPLBASE_HXX +#define INCLUDED_CPPUHELPER_IMPLBASE_HXX + +#include "sal/config.h" + +#include +#include + +#include "com/sun/star/lang/XTypeProvider.hpp" +#include "com/sun/star/uno/Any.h" +#include "com/sun/star/uno/Sequence.hxx" +#include "com/sun/star/uno/Type.h" +#include "cppuhelper/implbase_ex.hxx" +#include "cppuhelper/weak.hxx" +#include "rtl/instance.hxx" +#include "sal/types.h" + +#if defined LIBO_INTERNAL_ONLY + +// A replacement for ImplHelperN has deliberately been left out, as ImplHelperN +// is unlikely ever be a better choice than WeakImplHelper, so all their +// existing uses are probably confused and should use WeakImplHelper instead. +// +// Replacements for WeakAggImplHelperN and AggImplInheritanceHelperN have +// deliberately been left out, as the underlying aggregation mechanism is known +// broken in general and should not be used. + +namespace cppu { + +/// @cond INTERNAL + +namespace detail { + +template struct class_dataN { + sal_Int16 m_nTypes; + sal_Bool m_storedTypeRefs; + sal_Bool m_storedId; + sal_Int8 m_id[16]; + type_entry m_typeEntries[N + 1]; +}; + +template struct ImplClassData { + class_data * operator ()() { + static class_dataN s_cd = { + sizeof... (Ifc) + 1, false, false, {}, + { + { { Ifc::static_type }, + (reinterpret_cast( + static_cast(reinterpret_cast(16))) + - 16) + }..., + CPPUHELPER_DETAIL_TYPEENTRY(css::lang::XTypeProvider) + } + }; + return reinterpret_cast(&s_cd); + } +}; + +} + +/// @endcond + +/** Implementation helper implementing interfaces + css::uno::XInterface, css::lang::XTypeProvider, and + css::uno::XWeak (through cppu::OWeakObject). + + @derive + Inherit from this class giving your interface(s) to be implemented as + template argument(s). +*/ +template +class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE WeakImplHelper: + public OWeakObject, public css::lang::XTypeProvider, public Ifc... +{ + struct cd: + rtl::StaticAggregate< + class_data, detail::ImplClassData> + {}; + +protected: + WeakImplHelper() {} + + virtual ~WeakImplHelper() override {} + +public: + WeakImplHelper(WeakImplHelper const &) = default; + WeakImplHelper(WeakImplHelper &&) = default; + WeakImplHelper & operator =(WeakImplHelper const &) = default; + WeakImplHelper & operator =(WeakImplHelper &&) = default; + + css::uno::Any SAL_CALL queryInterface(css::uno::Type const & aType) override + { return WeakImplHelper_query(aType, cd::get(), this, this); } + + void SAL_CALL acquire() SAL_NOEXCEPT override { OWeakObject::acquire(); } + + void SAL_CALL release() SAL_NOEXCEPT override { OWeakObject::release(); } + + css::uno::Sequence SAL_CALL getTypes() override + { return WeakImplHelper_getTypes(cd::get()); } + + css::uno::Sequence SAL_CALL getImplementationId() override + { return css::uno::Sequence(); } +}; + +/** Implementation helper implementing interfaces + css::uno::XInterface and css::lang::XTypeProvider + inheriting from a BaseClass. + + All acquire() and release() calls are delegated to the BaseClass. Upon + queryInterface(), if a demanded interface is not supported by this class + directly, the request is delegated to the BaseClass. + + @attention + The BaseClass has to be complete in the sense that + css::uno::XInterface and css::lang::XTypeProvider are + implemented properly. + + @derive + Inherit from this class giving your additional interface(s) to be + implemented as template argument(s). +*/ +template +class SAL_NO_VTABLE SAL_DLLPUBLIC_TEMPLATE ImplInheritanceHelper: + public BaseClass, public Ifc... +{ + struct cd: + rtl::StaticAggregate< + class_data, detail::ImplClassData> + {}; + +protected: + template ImplInheritanceHelper(Arg &&... arg): + BaseClass(std::forward(arg)...) + {} + + virtual ~ImplInheritanceHelper() {} + +public: + ImplInheritanceHelper(ImplInheritanceHelper const &) = default; + ImplInheritanceHelper(ImplInheritanceHelper &&) = default; + ImplInheritanceHelper & operator =(ImplInheritanceHelper const &) = default; + ImplInheritanceHelper & operator =(ImplInheritanceHelper &&) = default; + + css::uno::Any SAL_CALL queryInterface(css::uno::Type const & aType) override + { + css::uno::Any ret(ImplHelper_queryNoXInterface(aType, cd::get(), this)); + return ret.hasValue() ? ret : BaseClass::queryInterface(aType); + } + + void SAL_CALL acquire() SAL_NOEXCEPT override { BaseClass::acquire(); } + + void SAL_CALL release() SAL_NOEXCEPT override { BaseClass::release(); } + + css::uno::Sequence SAL_CALL getTypes() override + { return ImplInhHelper_getTypes(cd::get(), BaseClass::getTypes()); } + + css::uno::Sequence SAL_CALL getImplementationId() override + { return css::uno::Sequence(); } +}; + +} + +#endif + +#endif + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ -- cgit v1.2.3