xref: /trunk/main/store/source/object.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 #ifndef _STORE_OBJECT_HXX_
29 #define _STORE_OBJECT_HXX_
30 
31 #ifndef _SAL_TYPES_H_
32 #include "sal/types.h"
33 #endif
34 
35 #ifndef _RTL_REF_HXX_
36 #include "rtl/ref.hxx"
37 #endif
38 
39 #ifndef _OSL_INTERLCK_H_
40 #include "osl/interlck.h"
41 #endif
42 
43 namespace store
44 {
45 
46 /*========================================================================
47  *
48  * IStoreHandle interface.
49  *
50  *======================================================================*/
51 class IStoreHandle : public rtl::IReference
52 {
53 public:
54 	/** Replaces dynamic_cast type checking.
55 	 */
56 	virtual sal_Bool SAL_CALL isKindOf (sal_uInt32 nTypeId) = 0;
57 };
58 
59 
60 /** Template helper function as dynamic_cast replacement.
61  */
62 template<class store_handle_type>
63 store_handle_type * SAL_CALL query (
64 	IStoreHandle * pHandle, store_handle_type *);
65 
66 /*========================================================================
67  *
68  * OStoreObject interface.
69  *
70  *======================================================================*/
71 class OStoreObject : public store::IStoreHandle
72 {
73 	/** Template function specialization as dynamic_cast replacement.
74 	 */
75 	friend OStoreObject*
76 	SAL_CALL query<> (IStoreHandle *pHandle, OStoreObject*);
77 
78 public:
79 	/** Construction.
80 	 */
81 	OStoreObject (void);
82 
83 	/** Allocation.
84 	 */
85 	static void* operator new (size_t n);
86 	static void  operator delete (void *p, size_t);
87 
88 	/** IStoreHandle.
89 	 */
90 	virtual sal_Bool SAL_CALL isKindOf (sal_uInt32 nTypeId);
91 
92 	/** IReference.
93 	 */
94 	virtual oslInterlockedCount SAL_CALL acquire (void);
95 	virtual oslInterlockedCount SAL_CALL release (void);
96 
97 protected:
98 	/** Destruction.
99 	 */
100 	virtual ~OStoreObject (void);
101 
102 private:
103 	/** The IStoreHandle TypeId.
104 	 */
105 	static const sal_uInt32 m_nTypeId;
106 
107 	/** Representation.
108 	 */
109 	oslInterlockedCount m_nRefCount;
110 
111 	/** Not implemented.
112 	 */
113 	OStoreObject (const OStoreObject&);
114 	OStoreObject& operator= (const OStoreObject&);
115 };
116 
117 /** Template function specialization as dynamic_cast replacement.
118  */
119 template<> inline OStoreObject*
120 SAL_CALL query (IStoreHandle *pHandle, OStoreObject*)
121 {
122 	if (pHandle && pHandle->isKindOf (OStoreObject::m_nTypeId))
123 	{
124 		// Handle is kind of OStoreObject.
125 		return static_cast<OStoreObject*>(pHandle);
126 	}
127 	return 0;
128 }
129 
130 /*========================================================================
131  *
132  * The End.
133  *
134  *======================================================================*/
135 
136 } // namespace store
137 
138 #endif /* !_STORE_OBJECT_HXX_ */
139