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