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