1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 #ifndef INCLUDED_UCB_CACHEMAPOBJECT1_HXX 25 #define INCLUDED_UCB_CACHEMAPOBJECT1_HXX 26 27 #include "osl/interlck.h" 28 #include "osl/mutex.hxx" 29 #include "rtl/ref.hxx" 30 #include "sal/types.h" 31 #include "salhelper/simplereferenceobject.hxx" 32 33 #ifndef INCLUDED_MAP 34 #include <map> 35 #define INCLUDED_MAP 36 #endif 37 #ifndef INCLUDED_MEMORY 38 #include <memory> 39 #define INCLUDED_MEMORY 40 #endif 41 42 namespace rtl { class OUString; } 43 namespace ucb { namespace cachemap { class Object1; } } 44 45 namespace ucb { namespace cachemap { 46 47 class ObjectContainer1: public salhelper::SimpleReferenceObject 48 { 49 public: 50 ObjectContainer1(); 51 52 virtual ~ObjectContainer1() SAL_THROW(()); 53 54 rtl::Reference< Object1 > get(rtl::OUString const & rKey); 55 56 private: 57 typedef std::map< rtl::OUString, Object1 * > Map; 58 59 Map m_aMap; 60 osl::Mutex m_aMutex; 61 62 void releaseElement(Object1 * pElement) SAL_THROW(()); 63 64 friend class Object1; // to access Map, releaseElement() 65 }; 66 67 class Object1 68 { 69 public: acquire()70 inline void acquire() SAL_THROW(()) 71 { osl_incrementInterlockedCount(&m_nRefCount); } 72 release()73 inline void release() SAL_THROW(()) 74 { m_xContainer->releaseElement(this); } 75 76 private: 77 rtl::Reference< ObjectContainer1 > m_xContainer; 78 ObjectContainer1::Map::iterator m_aContainerIt; 79 oslInterlockedCount m_nRefCount; 80 81 inline Object1(rtl::Reference< ObjectContainer1 > const & rContainer); 82 83 inline ~Object1() SAL_THROW(()); 84 85 Object1(Object1 &); // not implemented 86 void operator =(Object1); // not implemented 87 88 friend class ObjectContainer1; 89 // to access m_aContainerIt, m_nRefCount, Object1(), ~Object1() 90 #if defined WNT 91 friend struct std::auto_ptr< Object1 >; // to access ~Object1() 92 // work around compiler bug... 93 #else // WNT 94 friend class std::auto_ptr< Object1 >; // to access ~Object1() 95 #endif // WNT 96 }; 97 98 } } 99 100 #endif // INCLUDED_UCB_CACHEMAPOBJECT1_HXX 101