update dev300-m58
[ooovba.git] / ucb / workben / cachemap / cachemapobject1.cxx
blob03e29cec155a5b8a523d96cf30e6145c1abde673
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: cachemapobject1.cxx,v $
10 * $Revision: 1.4 $
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 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_ucb.hxx"
33 #include "cachemapobject1.hxx"
34 #include "osl/diagnose.h"
35 #include "osl/interlck.h"
36 #include "osl/mutex.hxx"
37 #include "rtl/ref.hxx"
38 #include "rtl/ustring.hxx"
40 #ifndef INCLUDED_MEMORY
41 #include <memory>
42 #define INCLUDED_MEMORY
43 #endif
45 using ucb::cachemap::Object1;
46 using ucb::cachemap::ObjectContainer1;
48 inline
49 Object1::Object1(rtl::Reference< ObjectContainer1 > const & rContainer):
50 m_xContainer(rContainer),
51 m_nRefCount(0)
53 OSL_ASSERT(m_xContainer.is());
56 inline Object1::~Object1() SAL_THROW(())
59 void ObjectContainer1::releaseElement(Object1 * pElement) SAL_THROW(())
61 OSL_ASSERT(pElement);
62 bool bDelete = false;
64 osl::MutexGuard aGuard(m_aMutex);
65 if (osl_decrementInterlockedCount(&pElement->m_nRefCount) == 0)
67 m_aMap.erase(pElement->m_aContainerIt);
68 bDelete = true;
71 if (bDelete)
72 delete pElement;
75 ObjectContainer1::ObjectContainer1()
78 ObjectContainer1::~ObjectContainer1() SAL_THROW(())
81 rtl::Reference< Object1 > ObjectContainer1::get(rtl::OUString const & rKey)
83 osl::MutexGuard aGuard(m_aMutex);
84 Map::iterator aIt(m_aMap.find(rKey));
85 if (aIt == m_aMap.end())
87 std::auto_ptr< Object1 > xElement(new Object1(this));
88 aIt = m_aMap.insert(Map::value_type(rKey, xElement.get())).first;
89 aIt->second->m_aContainerIt = aIt;
90 xElement.release();
92 return aIt->second;