Coverage Report

Created: 2026-02-14 09:37

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libreoffice/framework/source/inc/pattern/frame.hxx
Line
Count
Source
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
22
#include <com/sun/star/lang/XComponent.hpp>
23
#include <com/sun/star/lang/DisposedException.hpp>
24
#include <com/sun/star/util/CloseVetoException.hpp>
25
#include <com/sun/star/util/XCloseable.hpp>
26
27
// namespaces
28
29
namespace framework::pattern::frame{
30
31
/** @short  close (or dispose) the given resource.
32
33
    @descr  It try to close the given resource first.
34
            Delegating of the ownership can be influenced from
35
            outside. If closing isn't possible (because the
36
            needed interface isn't available) dispose() is tried instead.
37
            All possible exceptions are handled inside.
38
            So the user of this method has to look for the return value only.
39
40
    @attention  The given resource will not be cleared.
41
                But later using of it can produce an exception!
42
43
    @param  xResource
44
            the object, which should be closed here.
45
46
    @return [bool]
47
            sal_True if closing failed.
48
 */
49
inline bool closeIt(const css::uno::Reference< css::uno::XInterface >& xResource)
50
0
{
51
0
    css::uno::Reference< css::util::XCloseable > xClose  (xResource, css::uno::UNO_QUERY);
52
0
    css::uno::Reference< css::lang::XComponent > xDispose(xResource, css::uno::UNO_QUERY);
53
54
0
    try
55
0
    {
56
0
        if (xClose.is())
57
0
            xClose->close(false/*bDelegateOwnership*/);
58
0
        else
59
0
        if (xDispose.is())
60
0
            xDispose->dispose();
61
0
        else
62
0
            return false;
63
0
    }
64
0
    catch(const css::util::CloseVetoException&)
65
0
        { return false; }
66
0
    catch(const css::lang::DisposedException&)
67
0
        {} // disposed is closed is ...
68
0
    catch(const css::uno::RuntimeException&)
69
0
        { throw; } // should not be suppressed!
70
0
    catch(const css::uno::Exception&)
71
0
        { return false;  } // ??? We defined to return a boolean value instead of throwing exceptions...
72
                               // (OK: RuntimeExceptions should not be caught inside the core..)
73
74
0
    return true;
75
0
}
76
77
} // namespace framework::pattern::frame
78
79
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */