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 .
23 #include <sal/types.h>
24 #include <o3tl/deleter.hxx>
26 namespace com::sun::star::uno
28 template <class interface_type
> class Reference
;
30 namespace com::sun::star::uno
37 class SdGlobalResource
40 virtual ~SdGlobalResource() COVERITY_NOEXCEPT_FALSE
{};
43 /** The purpose of this container is to hold references to resources that
44 are globally available to all interested objects and to destroy them
45 when the sd module is destroyed. Examples for resources can be
46 containers of bitmaps or the container of master pages used by the
47 MasterPagesSelector objects in the task panel.
49 It works like a singleton in that there is one instance per sd module.
50 Resources can be added (by themselves or their owners) to the
51 container. The main task of the container is the destruction of all
52 resources that have been added to it.
54 As you may note, there is no method to get a resource from the
55 container. It is the task of the resource to provide other means of
58 The reason for this design is not to have to change the SdModule
59 destructor every time when there is a new resource. This is done by
60 reversing the dependency between module and resource: the resource knows
61 about the module--this container class to be more precisely--and tells
62 it to destroy the resource when the sd module is at the end of its
65 class SdGlobalResourceContainer final
68 static SdGlobalResourceContainer
& Instance();
70 /** Add a resource to the container. The ownership of the resource is
71 transferred to the container. The resource is destroyed when the
72 container is destroyed, i.e. when the sd module is destroyed.
74 When in doubt, use the shared_ptr variant of this method.
76 void AddResource(::std::unique_ptr
<SdGlobalResource
> pResource
);
78 /** Add a resource to the container. By using a shared_ptr and
79 releasing it only when the SgGlobalResourceContainer is destroyed
80 the given resource is kept alive at least that long. When at the
81 time of the destruction of SgGlobalResourceContainer no other
82 references exist the resource is destroyed as well.
84 void AddResource(const std::shared_ptr
<SdGlobalResource
>& pResource
);
86 /** Add a resource that is implemented as UNO object. Destruction
87 (when the sd modules is unloaded) is done by a) calling dispose()
88 when the XComponent is supported and by b) releasing the reference.
90 void AddResource(const css::uno::Reference
<css::uno::XInterface
>& rxResource
);
93 friend class SdGlobalResourceContainerInstance
;
94 friend struct o3tl::default_delete
<SdGlobalResourceContainer
>;
97 ::std::unique_ptr
<Implementation
> mpImpl
;
99 SdGlobalResourceContainer();
100 ~SdGlobalResourceContainer();
103 } // end of namespace sd
105 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */