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 _SD_SIMPLEREFERENCECOMPONENT_HXX_
25 #define _SD_SIMPLEREFERENCECOMPONENT_HXX_
26 
27 #include "osl/interlck.h"
28 #include "sal/types.h"
29 
30 #include <cstddef>
31 #include <new>
32 
33 #include <sddllapi.h>
34 
35 namespace sd {
36 
37 /** A simple base implementation for reference-counted components.
38 	acts like sal::SimpleReferenceObject but calls the virtual disposing()
39 	methods before the ref count switches from 1 to zero.
40  */
41 class SimpleReferenceComponent
42 {
43 public:
44     SimpleReferenceComponent();
45 
46     /** @ATTENTION
47         The results are undefined if, for any individual instance of
48         SimpleReferenceComponent, the total number of calls to acquire() exceeds
49         the total number of calls to release() by a platform dependent amount
50         (which, hopefully, is quite large).
51      */
52     SD_DLLPUBLIC void acquire();
53     SD_DLLPUBLIC void release();
54 
55 	void Dispose();
56 
isDisposed() const57 	bool isDisposed() const { return mbDisposed; }
58 
59     /** see general class documentation
60      */
61     static void * operator new(std::size_t nSize) SAL_THROW((std::bad_alloc));
62 
63     /** see general class documentation
64      */
65     static void * operator new(std::size_t nSize,
66                                std::nothrow_t const & rNothrow)
67        ;
68 
69     /** see general class documentation
70      */
71     static void operator delete(void * pPtr);
72 
73     /** see general class documentation
74      */
75     static void operator delete(void * pPtr, std::nothrow_t const & rNothrow)
76        ;
77 
78 protected:
79 	virtual void disposing();
80 
81     virtual ~SimpleReferenceComponent();
82 
83 private:
84     oslInterlockedCount m_nCount;
85 
86     /** not implemented
87         @internal
88      */
89     SimpleReferenceComponent(SimpleReferenceComponent &);
90 
91     /** not implemented
92         @internal
93      */
94     void operator =(SimpleReferenceComponent);
95 
96     /** not implemented (see general class documentation)
97         @internal
98      */
99     static void * operator new[](std::size_t);
100 
101     /** not implemented (see general class documentation)
102         @internal
103      */
104     static void operator delete[](void * pPtr);
105 
106 	bool mbDisposed;
107 };
108 
109 }
110 
111 #endif // _SALHELPER_SimpleReferenceComponent_HXX_
112