Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #ifndef _SD_SIMPLEREFERENCECOMPONENT_HXX_
30 : : #define _SD_SIMPLEREFERENCECOMPONENT_HXX_
31 : :
32 : : #include "osl/interlck.h"
33 : : #include "sal/types.h"
34 : :
35 : : #include <cstddef>
36 : : #include <new>
37 : :
38 : : #include <sddllapi.h>
39 : :
40 : : namespace sd {
41 : :
42 : : /** A simple base implementation for reference-counted components.
43 : : acts like sal::SimpleReferenceObject but calls the virtual disposing()
44 : : methods before the ref count switches from 1 to zero.
45 : : */
46 : : class SimpleReferenceComponent
47 : : {
48 : : public:
49 : : SimpleReferenceComponent();
50 : :
51 : : /** @ATTENTION
52 : : The results are undefined if, for any individual instance of
53 : : SimpleReferenceComponent, the total number of calls to acquire() exceeds
54 : : the total number of calls to release() by a platform dependent amount
55 : : (which, hopefully, is quite large).
56 : : */
57 : : SD_DLLPUBLIC void acquire();
58 : : SD_DLLPUBLIC void release();
59 : :
60 : : void Dispose();
61 : :
62 : 0 : bool isDisposed() const { return mbDisposed; }
63 : :
64 : : /** see general class documentation
65 : : */
66 : : static void * operator new(std::size_t nSize) SAL_THROW((std::bad_alloc));
67 : :
68 : : /** see general class documentation
69 : : */
70 : : static void * operator new(std::size_t nSize,
71 : : std::nothrow_t const & rNothrow)
72 : : ;
73 : :
74 : : /** see general class documentation
75 : : */
76 : : static void operator delete(void * pPtr);
77 : :
78 : : /** see general class documentation
79 : : */
80 : : static void operator delete(void * pPtr, std::nothrow_t const & rNothrow)
81 : : ;
82 : :
83 : : protected:
84 : : virtual void disposing();
85 : :
86 : : virtual ~SimpleReferenceComponent();
87 : :
88 : : private:
89 : : oslInterlockedCount m_nCount;
90 : :
91 : : /** not implemented
92 : : @internal
93 : : */
94 : : SimpleReferenceComponent(SimpleReferenceComponent &);
95 : :
96 : : /** not implemented
97 : : @internal
98 : : */
99 : : void operator =(SimpleReferenceComponent);
100 : :
101 : : /** not implemented (see general class documentation)
102 : : @internal
103 : : */
104 : : static void * operator new[](std::size_t);
105 : :
106 : : /** not implemented (see general class documentation)
107 : : @internal
108 : : */
109 : : static void operator delete[](void * pPtr);
110 : :
111 : : bool mbDisposed;
112 : : };
113 : :
114 : : }
115 : :
116 : : #endif // _SALHELPER_SimpleReferenceComponent_HXX_
117 : :
118 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|