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_CACHEMAPOBJECT3_HXX
25 #define INCLUDED_UCB_CACHEMAPOBJECT3_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 Object3; } }
44 
45 namespace ucb { namespace cachemap {
46 
47 class ObjectContainer3: public salhelper::SimpleReferenceObject
48 {
49 public:
50     ObjectContainer3();
51 
52     virtual ~ObjectContainer3() SAL_THROW(());
53 
54     rtl::Reference< Object3 > get(rtl::OUString const & rKey);
55 
56 private:
57     typedef std::map< rtl::OUString, Object3 * > Map;
58 
59     Map m_aMap;
60     osl::Mutex m_aMutex;
61 
62     void releaseElement(Object3 * pElement) SAL_THROW(());
63 
64     friend class Object3; // to access Map, releaseElement()
65 };
66 
67 class Object3
68 {
69 public:
acquire()70     inline void acquire() SAL_THROW(())
71     { osl_incrementInterlockedCount(&m_nRefCount); }
72 
73     void release() SAL_THROW(());
74 
75 private:
76     rtl::Reference< ObjectContainer3 > m_xContainer;
77     ObjectContainer3::Map::iterator m_aContainerIt;
78     oslInterlockedCount m_nRefCount;
79 
80     inline Object3(rtl::Reference< ObjectContainer3 > const & rContainer);
81 
82     inline ~Object3() SAL_THROW(());
83 
84     Object3(Object3 &); // not implemented
85     void operator =(Object3); // not implemented
86 
87     friend class ObjectContainer3;
88         // to access m_aContainerIt, m_nRefCount, Object3(), ~Object3()
89 #if defined WNT
90     friend struct std::auto_ptr< Object3 >; // to access ~Object3()
91         // work around compiler bug...
92 #else // WNT
93     friend class std::auto_ptr< Object3 >; // to access ~Object3()
94 #endif // WNT
95 };
96 
97 } }
98 
99 #endif // INCLUDED_UCB_CACHEMAPOBJECT3_HXX
100