Branch data Line data Source code
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 : : #ifndef SD_GLOBAL_RESOURCE_CONTAINER_HXX
21 : : #define SD_GLOBAL_RESOURCE_CONTAINER_HXX
22 : :
23 : : #include "sdmod.hxx"
24 : : #include <memory>
25 : : #include <boost/shared_ptr.hpp>
26 : : #include <com/sun/star/uno/XInterface.hpp>
27 : :
28 : : namespace css = ::com::sun::star;
29 : :
30 : : namespace sd {
31 : :
32 : 154 : class SdGlobalResource
33 : : {
34 : : public:
35 [ - + ]: 154 : virtual ~SdGlobalResource (void) {};
36 : : };
37 : :
38 : : /** The purpose of this container is to hold references to resources that
39 : : are globally available to all interested objects and to destroy them
40 : : when the sd module is destroyed. Examples for resources can be
41 : : containers of bitmaps or the container of master pages used by the
42 : : MasterPagesSelector objects in the task panel.
43 : :
44 : : It works like a singleton in that there is one instance per sd module.
45 : : Resources can be added (by themselves or their owners) to the
46 : : container. The main task of the container is the destruction of all
47 : : resources that have been added to it.
48 : :
49 : : As you may note, there is no method to get a resource from the
50 : : container. It is the task of the resource to provide other means of
51 : : access to it.
52 : :
53 : : The reason for this design is not to have to change the SdModule
54 : : destructor every time when there is a new resource. This is done by
55 : : reversing the dependency between module and resource: the resource knows
56 : : about the module--this container class to be more precisely--and tells
57 : : it to destroy the resource when the sd module is at the end of its
58 : : lifetime.
59 : : */
60 : : class SdGlobalResourceContainer
61 : : {
62 : : public:
63 : : static SdGlobalResourceContainer& Instance (void);
64 : :
65 : : /** Add a resource to the container. The ownership of the resource is
66 : : transferred to the container. The resource is destroyed when the
67 : : container is destroyed, i.e. when the sd module is destroyed.
68 : :
69 : : When in doubt, use the shared_ptr variant of this method.
70 : : */
71 : : void AddResource (::std::auto_ptr<SdGlobalResource> pResource);
72 : :
73 : : /** Add a resource to the container. By using a shared_ptr and
74 : : releasing it only when the SgGlobalResourceContainer is destroyed
75 : : the given resource is kept alive at least that long. When at the
76 : : time of the destruction of SgGlobalResourceContainer no other
77 : : references exist the resource is destroyed as well.
78 : : */
79 : : void AddResource (::boost::shared_ptr<SdGlobalResource> pResource);
80 : :
81 : : /** Add a resource that is implemented as UNO object. Destruction
82 : : (when the sd modules is unloaded) is done by a) calling dispose()
83 : : when the XComponent is supported and by b) releasing the reference.
84 : : */
85 : : void AddResource (const ::css::uno::Reference<css::uno::XInterface>& rxResource);
86 : :
87 : : protected:
88 : : friend class ::SdModule;
89 : : friend class ::std::auto_ptr<SdGlobalResourceContainer>;
90 : :
91 : : class Implementation;
92 : : ::std::auto_ptr<Implementation> mpImpl;
93 : :
94 : : SdGlobalResourceContainer (void);
95 : : ~SdGlobalResourceContainer (void);
96 : : };
97 : :
98 : : } // end of namespace sd
99 : :
100 : : #endif
101 : :
102 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|