Bump version to 4.3-4
[LibreOffice.git] / unotools / source / misc / componentresmodule.cxx
blob5d6fc7644ee089790bc87ef1d3ee9dc62e22b3e3
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 <boost/noncopyable.hpp>
23 #include <tools/resmgr.hxx>
24 #include <osl/diagnose.h>
25 #include <rtl/strbuf.hxx>
27 namespace utl
30 //= OComponentResModuleImpl
32 /** PIMPL-class for OComponentResourceModule
34 not threadsafe!
36 class OComponentResModuleImpl: private boost::noncopyable
38 private:
39 ResMgr* m_pResources;
40 bool m_bInitialized;
41 OString m_sResFilePrefix;
43 public:
44 OComponentResModuleImpl( const OString& _rResFilePrefix )
45 :m_pResources( NULL )
46 ,m_bInitialized( false )
47 ,m_sResFilePrefix( _rResFilePrefix )
51 ~OComponentResModuleImpl()
53 freeResManager();
56 /** releases our resource manager
58 void freeResManager();
60 /** retrieves our resource manager
62 ResMgr* getResManager();
65 void OComponentResModuleImpl::freeResManager()
67 delete m_pResources, m_pResources = NULL;
68 m_bInitialized = false;
71 ResMgr* OComponentResModuleImpl::getResManager()
73 if ( !m_pResources && !m_bInitialized )
75 // create a manager with a fixed prefix
76 OString aMgrName = m_sResFilePrefix;
78 m_pResources = ResMgr::CreateResMgr( aMgrName.getStr() );
79 OSL_ENSURE( m_pResources,
80 OStringBuffer( "OModuleImpl::getResManager: could not create the resource manager (file name: " )
81 .append(aMgrName)
82 .append(")!").getStr() );
84 m_bInitialized = true;
86 return m_pResources;
89 //= OComponentResourceModule
91 OComponentResourceModule::OComponentResourceModule( const OString& _rResFilePrefix )
92 :BaseClass()
93 ,m_pImpl( new OComponentResModuleImpl( _rResFilePrefix ) )
97 OComponentResourceModule::~OComponentResourceModule()
101 ResMgr* OComponentResourceModule::getResManager()
103 ::osl::MutexGuard aGuard( m_aMutex );
104 return m_pImpl->getResManager();
107 void OComponentResourceModule::onFirstClient()
109 BaseClass::onFirstClient();
112 void OComponentResourceModule::onLastClient()
114 m_pImpl->freeResManager();
115 BaseClass::onLastClient();
118 } // namespace utl
120 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */