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