xref: /trunk/main/vos/inc/vos/refobj.hxx (revision cdf0e10c)
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 
29 #ifndef _VOS_REFOBJ_HXX_
30 #define _VOS_REFOBJ_HXX_
31 
32 /**
33 	ORefObj<T>
34 
35 	template type to implement handle/body behaviour
36 	with reference-counting.
37 */
38 
39 #	include <vos/refernce.hxx>
40 #ifndef _VOS_DIAGNOSE_HXX_
41 #	include <vos/diagnose.hxx>
42 #endif
43 
44 namespace vos
45 {
46 
47 template <class T>
48 class ORefObj : public IReference
49 {
50 public:
51 	ORefObj(const T& Obj);
52 
53 	inline ~ORefObj();
54 
55 	virtual RefCount SAL_CALL acquire()
56 		{ return (m_RefCount.acquire()); }
57 	virtual RefCount SAL_CALL release()
58 		{ return (m_RefCount.release()); }
59 	virtual RefCount SAL_CALL referenced() const
60 		{ return (m_RefCount.referenced()); }
61 
62 	T& SAL_CALL operator=(const T& Obj);
63 
64 	SAL_CALL operator T&();
65 	SAL_CALL operator const T&() const;
66 
67 	T& SAL_CALL operator() ();
68 	const T& SAL_CALL operator() () const;
69 
70 	const	T& SAL_CALL getObj() const;
71 	T& SAL_CALL getObj();
72 
73 protected:
74 	T	      m_Obj;
75 	ORefCount m_RefCount;
76 
77 private:
78 	ORefObj(const ORefObj<T>& handle);
79 	ORefObj<T>& SAL_CALL operator= (const ORefObj<T>& handle);
80 };
81 
82 // include template implementation
83 #include <vos/refobj.inl>
84 
85 }
86 
87 
88 #endif // _VOS_REF_HXX_
89 
90