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 .
20 #ifndef INCLUDED_SD_SOURCE_UI_INC_TOOLS_SDGLOBALRESOURCECONTAINER_HXX
21 #define INCLUDED_SD_SOURCE_UI_INC_TOOLS_SDGLOBALRESOURCECONTAINER_HXX
25 #include <boost/shared_ptr.hpp>
26 #include <com/sun/star/uno/XInterface.hpp>
30 class SdGlobalResource
33 virtual ~SdGlobalResource() {};
36 /** The purpose of this container is to hold references to resources that
37 are globally available to all interested objects and to destroy them
38 when the sd module is destroyed. Examples for resources can be
39 containers of bitmaps or the container of master pages used by the
40 MasterPagesSelector objects in the task panel.
42 It works like a singleton in that there is one instance per sd module.
43 Resources can be added (by themselves or their owners) to the
44 container. The main task of the container is the destruction of all
45 resources that have been added to it.
47 As you may note, there is no method to get a resource from the
48 container. It is the task of the resource to provide other means of
51 The reason for this design is not to have to change the SdModule
52 destructor every time when there is a new resource. This is done by
53 reversing the dependency between module and resource: the resource knows
54 about the module--this container class to be more precisely--and tells
55 it to destroy the resource when the sd module is at the end of its
58 class SdGlobalResourceContainer
61 static SdGlobalResourceContainer
& Instance();
63 /** Add a resource to the container. The ownership of the resource is
64 transferred to the container. The resource is destroyed when the
65 container is destroyed, i.e. when the sd module is destroyed.
67 When in doubt, use the shared_ptr variant of this method.
69 void AddResource (::std::unique_ptr
<SdGlobalResource
> && pResource
);
71 /** Add a resource to the container. By using a shared_ptr and
72 releasing it only when the SgGlobalResourceContainer is destroyed
73 the given resource is kept alive at least that long. When at the
74 time of the destruction of SgGlobalResourceContainer no other
75 references exist the resource is destroyed as well.
77 void AddResource (::boost::shared_ptr
<SdGlobalResource
> pResource
);
79 /** Add a resource that is implemented as UNO object. Destruction
80 (when the sd modules is unloaded) is done by a) calling dispose()
81 when the XComponent is supported and by b) releasing the reference.
83 void AddResource (const css::uno::Reference
<css::uno::XInterface
>& rxResource
);
86 friend class ::SdModule
;
87 friend struct ::std::default_delete
<SdGlobalResourceContainer
>;
90 ::std::unique_ptr
<Implementation
> mpImpl
;
92 SdGlobalResourceContainer();
93 ~SdGlobalResourceContainer();
96 } // end of namespace sd
100 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */