bump product version to 4.1.6.2
[LibreOffice.git] / unotools / source / misc / componentresmodule.cxx
blob8573fd611a677bf1e30adae4bdf6509c835feec5
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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 #include <unotools/componentresmodule.hxx>
22 #include <tools/resmgr.hxx>
23 #include <osl/diagnose.h>
24 #include <rtl/strbuf.hxx>
26 //........................................................................
27 namespace utl
29 //........................................................................
31 //====================================================================
32 //= OComponentResModuleImpl
33 //====================================================================
34 /** PIMPL-class for OComponentResourceModule
36 not threadsafe!
38 class OComponentResModuleImpl
40 private:
41 ResMgr* m_pResources;
42 bool m_bInitialized;
43 OString m_sResFilePrefix;
45 public:
46 OComponentResModuleImpl( const OString& _rResFilePrefix )
47 :m_pResources( NULL )
48 ,m_bInitialized( false )
49 ,m_sResFilePrefix( _rResFilePrefix )
53 ~OComponentResModuleImpl()
55 freeResManager();
58 /** releases our resource manager
60 void freeResManager();
62 /** retrieves our resource manager
64 ResMgr* getResManager();
66 private:
67 OComponentResModuleImpl(); // never implemented
68 OComponentResModuleImpl( const OComponentResModuleImpl& ); // never implemented
69 OComponentResModuleImpl& operator=( const OComponentResModuleImpl& ); // never implemented
72 //--------------------------------------------------------------------
73 void OComponentResModuleImpl::freeResManager()
75 delete m_pResources, m_pResources = NULL;
76 m_bInitialized = false;
79 //--------------------------------------------------------------------
80 ResMgr* OComponentResModuleImpl::getResManager()
82 if ( !m_pResources && !m_bInitialized )
84 // create a manager with a fixed prefix
85 OString aMgrName = m_sResFilePrefix;
87 m_pResources = ResMgr::CreateResMgr( aMgrName.getStr() );
88 OSL_ENSURE( m_pResources,
89 OStringBuffer( "OModuleImpl::getResManager: could not create the resource manager (file name: " )
90 .append(aMgrName)
91 .append(")!").getStr() );
93 m_bInitialized = sal_True;
95 return m_pResources;
98 //====================================================================
99 //= OComponentResourceModule
100 //====================================================================
101 //--------------------------------------------------------------------
102 OComponentResourceModule::OComponentResourceModule( const OString& _rResFilePrefix )
103 :BaseClass()
104 ,m_pImpl( new OComponentResModuleImpl( _rResFilePrefix ) )
108 //--------------------------------------------------------------------
109 OComponentResourceModule::~OComponentResourceModule()
113 //-------------------------------------------------------------------------
114 ResMgr* OComponentResourceModule::getResManager()
116 ::osl::MutexGuard aGuard( m_aMutex );
117 return m_pImpl->getResManager();
120 //--------------------------------------------------------------------------
121 void OComponentResourceModule::onFirstClient()
123 BaseClass::onFirstClient();
126 //--------------------------------------------------------------------------
127 void OComponentResourceModule::onLastClient()
129 m_pImpl->freeResManager();
130 BaseClass::onLastClient();
133 //........................................................................
134 } // namespace utl
135 //........................................................................
137 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */