1 /************************************************************************* 2 * 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * Copyright 2000, 2010 Oracle and/or its affiliates. 6 * 7 * OpenOffice.org - a multi-platform office productivity suite 8 * 9 * This file is part of OpenOffice.org. 10 * 11 * OpenOffice.org is free software: you can redistribute it and/or modify 12 * it under the terms of the GNU Lesser General Public License version 3 13 * only, as published by the Free Software Foundation. 14 * 15 * OpenOffice.org is distributed in the hope that it will be useful, 16 * but WITHOUT ANY WARRANTY; without even the implied warranty of 17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 18 * GNU Lesser General Public License version 3 for more details 19 * (a copy is included in the LICENSE file that accompanied this code). 20 * 21 * You should have received a copy of the GNU Lesser General Public License 22 * version 3 along with OpenOffice.org. If not, see 23 * <http://www.openoffice.org/license.html> 24 * for a copy of the LGPLv3 License. 25 * 26 ************************************************************************/ 27 28 #ifndef SD_GLOBAL_RESOURCE_CONTAINER_HXX 29 #define SD_GLOBAL_RESOURCE_CONTAINER_HXX 30 31 #include "sdmod.hxx" 32 #include <memory> 33 #include <boost/shared_ptr.hpp> 34 #include <com/sun/star/uno/XInterface.hpp> 35 36 namespace css = ::com::sun::star; 37 38 namespace sd { 39 40 class SdGlobalResource 41 { 42 public: 43 virtual ~SdGlobalResource (void) {}; 44 }; 45 46 /** The purpose of this container is to hold references to resources that 47 are globally available to all interested objects and to destroy them 48 when the sd module is destroyed. Examples for resources can be 49 containers of bitmaps or the container of master pages used by the 50 MasterPagesSelector objects in the task panel. 51 52 It works like a singleton in that there is one instance per sd module. 53 Resources can be added (by themselves or their owners) to the 54 container. The main task of the container is the destruction of all 55 resources that have been added to it. 56 57 As you may note, there is no method to get a resource from the 58 container. It is the task of the resource to provide other means of 59 access to it. 60 61 The reason for this design is not to have to change the SdModule 62 destructor every time when there is a new resource. This is done by 63 reversing the dependency between module and resource: the resource knows 64 about the module--this container class to be more precisely--and tells 65 it to destroy the resource when the sd module is at the end of its 66 lifetime. 67 */ 68 class SdGlobalResourceContainer 69 { 70 public: 71 static SdGlobalResourceContainer& Instance (void); 72 73 /** Add a resource to the container. The ownership of the resource is 74 transferred to the container. The resource is destroyed when the 75 container is destroyed, i.e. when the sd module is destroyed. 76 77 When in doubt, use the shared_ptr variant of this method. 78 */ 79 void AddResource (::std::auto_ptr<SdGlobalResource> pResource); 80 81 /** Add a resource to the container. By using a shared_ptr and 82 releasing it only when the SgGlobalResourceContainer is destroyed 83 the given resource is kept alive at least that long. When at the 84 time of the destruction of SgGlobalResourceContainer no other 85 references exist the resource is destroyed as well. 86 */ 87 void AddResource (::boost::shared_ptr<SdGlobalResource> pResource); 88 89 /** Add a resource that is implemented as UNO object. Destruction 90 (when the sd modules is unloaded) is done by a) calling dispose() 91 when the XComponent is supported and by b) releasing the reference. 92 */ 93 void AddResource (const ::css::uno::Reference<css::uno::XInterface>& rxResource); 94 95 protected: 96 friend class ::SdModule; 97 friend class ::std::auto_ptr<SdGlobalResourceContainer>; 98 99 class Implementation; 100 ::std::auto_ptr<Implementation> mpImpl; 101 102 SdGlobalResourceContainer (void); 103 ~SdGlobalResourceContainer (void); 104 }; 105 106 } // end of namespace sd 107 108 #endif 109