Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef INCLUDED_STORE_SOURCE_OBJECT_HXX
21 : #define INCLUDED_STORE_SOURCE_OBJECT_HXX
22 :
23 : #include "sal/types.h"
24 : #include "rtl/ref.hxx"
25 : #include "osl/interlck.h"
26 : #include "salhelper/simplereferenceobject.hxx"
27 :
28 : namespace store
29 : {
30 :
31 : /*========================================================================
32 : *
33 : * IStoreHandle interface.
34 : *
35 : *======================================================================*/
36 3862 : class IStoreHandle : public virtual salhelper::SimpleReferenceObject
37 : {
38 : public:
39 : /** Replaces dynamic_cast type checking.
40 : */
41 : virtual bool isKindOf (sal_uInt32 nTypeId) = 0;
42 :
43 : protected:
44 3846 : virtual ~IStoreHandle() {}
45 : };
46 :
47 : /** Template helper function as dynamic_cast replacement.
48 : */
49 : template<class store_handle_type>
50 : store_handle_type * SAL_CALL query (
51 : IStoreHandle * pHandle, store_handle_type *);
52 :
53 : /*========================================================================
54 : *
55 : * OStoreObject interface.
56 : *
57 : *======================================================================*/
58 : class OStoreObject : public store::IStoreHandle
59 : {
60 : /** Template function specialization as dynamic_cast replacement.
61 : */
62 : friend OStoreObject*
63 : SAL_CALL query<> (IStoreHandle *pHandle, OStoreObject*);
64 :
65 : public:
66 : /** Construction.
67 : */
68 3862 : OStoreObject() : m_nRefCount(0) {}
69 :
70 : /** IStoreHandle.
71 : */
72 : virtual bool isKindOf (sal_uInt32 nTypeId) SAL_OVERRIDE;
73 :
74 : protected:
75 : /** Destruction.
76 : */
77 3846 : virtual ~OStoreObject() {}
78 :
79 : private:
80 : /** The IStoreHandle TypeId.
81 : */
82 : static const sal_uInt32 m_nTypeId;
83 :
84 : /** Representation.
85 : */
86 : oslInterlockedCount m_nRefCount;
87 :
88 : /** Not implemented.
89 : */
90 : OStoreObject (const OStoreObject&);
91 : OStoreObject& operator= (const OStoreObject&);
92 : };
93 :
94 : /** Template function specialization as dynamic_cast replacement.
95 : */
96 : template<> inline OStoreObject*
97 : SAL_CALL query (IStoreHandle *pHandle, OStoreObject*)
98 : {
99 : if (pHandle && pHandle->isKindOf (OStoreObject::m_nTypeId))
100 : {
101 : // Handle is kind of OStoreObject.
102 : return static_cast<OStoreObject*>(pHandle);
103 : }
104 : return 0;
105 : }
106 :
107 : /*========================================================================
108 : *
109 : * The End.
110 : *
111 : *======================================================================*/
112 :
113 : } // namespace store
114 :
115 : #endif // INCLUDED_STORE_SOURCE_OBJECT_HXX
116 :
117 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|