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 INCLUDED_UCB_CACHEMAPOBJECT1_HXX 29 #define INCLUDED_UCB_CACHEMAPOBJECT1_HXX 30 31 #include "osl/interlck.h" 32 #include "osl/mutex.hxx" 33 #include "rtl/ref.hxx" 34 #include "sal/types.h" 35 #include "salhelper/simplereferenceobject.hxx" 36 37 #ifndef INCLUDED_MAP 38 #include <map> 39 #define INCLUDED_MAP 40 #endif 41 #ifndef INCLUDED_MEMORY 42 #include <memory> 43 #define INCLUDED_MEMORY 44 #endif 45 46 namespace rtl { class OUString; } 47 namespace ucb { namespace cachemap { class Object1; } } 48 49 namespace ucb { namespace cachemap { 50 51 class ObjectContainer1: public salhelper::SimpleReferenceObject 52 { 53 public: 54 ObjectContainer1(); 55 56 virtual ~ObjectContainer1() SAL_THROW(()); 57 58 rtl::Reference< Object1 > get(rtl::OUString const & rKey); 59 60 private: 61 typedef std::map< rtl::OUString, Object1 * > Map; 62 63 Map m_aMap; 64 osl::Mutex m_aMutex; 65 66 void releaseElement(Object1 * pElement) SAL_THROW(()); 67 68 friend class Object1; // to access Map, releaseElement() 69 }; 70 71 class Object1 72 { 73 public: 74 inline void acquire() SAL_THROW(()) 75 { osl_incrementInterlockedCount(&m_nRefCount); } 76 77 inline void release() SAL_THROW(()) 78 { m_xContainer->releaseElement(this); } 79 80 private: 81 rtl::Reference< ObjectContainer1 > m_xContainer; 82 ObjectContainer1::Map::iterator m_aContainerIt; 83 oslInterlockedCount m_nRefCount; 84 85 inline Object1(rtl::Reference< ObjectContainer1 > const & rContainer); 86 87 inline ~Object1() SAL_THROW(()); 88 89 Object1(Object1 &); // not implemented 90 void operator =(Object1); // not implemented 91 92 friend class ObjectContainer1; 93 // to access m_aContainerIt, m_nRefCount, Object1(), ~Object1() 94 #if defined WNT 95 friend struct std::auto_ptr< Object1 >; // to access ~Object1() 96 // work around compiler bug... 97 #else // WNT 98 friend class std::auto_ptr< Object1 >; // to access ~Object1() 99 #endif // WNT 100 }; 101 102 } } 103 104 #endif // INCLUDED_UCB_CACHEMAPOBJECT1_HXX 105