Skip to content
Projeler
Gruplar
Parçacıklar
Yardım
Yükleniyor...
Oturum aç / Kaydol
Gezinmeyi değiştir
C
core
Proje
Proje
Ayrıntılar
Etkinlik
Cycle Analytics
Depo (repository)
Depo (repository)
Dosyalar
Kayıtlar (commit)
Dallar (branch)
Etiketler
Katkıda bulunanlar
Grafik
Karşılaştır
Grafikler
Konular (issue)
0
Konular (issue)
0
Liste
Pano
Etiketler
Kilometre Taşları
Birleştirme (merge) Talepleri
0
Birleştirme (merge) Talepleri
0
CI / CD
CI / CD
İş akışları (pipeline)
İşler
Zamanlamalar
Grafikler
Paketler
Paketler
Wiki
Wiki
Parçacıklar
Parçacıklar
Üyeler
Üyeler
Collapse sidebar
Close sidebar
Etkinlik
Grafik
Grafikler
Yeni bir konu (issue) oluştur
İşler
Kayıtlar (commit)
Konu (issue) Panoları
Kenar çubuğunu aç
LibreOffice
core
Commits
89fa7eab
Kaydet (Commit)
89fa7eab
authored
May 20, 2011
tarafından
Caolán McNamara
Dosyalara gözat
Seçenekler
Dosyalara Gözat
İndir
Eposta Yamaları
Sade Fark
add a template for dtoring on desktop::termination
üst
1c2fb22c
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
69 additions
and
17 deletions
+69
-17
scoped_disposing_ptr.hxx
comphelper/inc/comphelper/scoped_disposing_ptr.hxx
+69
-17
No files found.
comphelper/inc/comphelper/scoped_disposing_ptr.hxx
Dosyayı görüntüle @
89fa7eab
...
@@ -33,25 +33,28 @@
...
@@ -33,25 +33,28 @@
#include <boost/scoped_ptr.hpp>
#include <boost/scoped_ptr.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/lang/XComponent.hpp>
#include <com/sun/star/frame/XDesktop.hpp>
#include <stdio.h>
// for locking SolarMutex: svapp + mutex
#include <vcl/svapp.hxx>
#include <osl/mutex.hxx>
namespace
comphelper
namespace
comphelper
{
{
//Similar to boost::scoped_ptr, except additionally releases the ptr on
rComponent::disposing
//Similar to boost::scoped_ptr, except additionally releases the ptr on
XComponent::disposing and/or XTerminateListener::notifyTermination if supported
template
<
class
T
>
class
scoped_disposing_ptr
:
private
boost
::
noncopyable
template
<
class
T
>
class
scoped_disposing_ptr
:
private
boost
::
noncopyable
{
{
private
:
private
:
boost
::
scoped_ptr
<
T
>
m_aItem
;
boost
::
scoped_ptr
<
T
>
m_aItem
;
::
com
::
sun
::
star
::
uno
::
Reference
<
::
com
::
sun
::
star
::
lang
::
XEventListener
>
m_xDisposing
Listener
;
::
com
::
sun
::
star
::
uno
::
Reference
<
::
com
::
sun
::
star
::
frame
::
XTerminateListener
>
m_xTerminate
Listener
;
public
:
public
:
scoped_disposing_ptr
(
const
::
com
::
sun
::
star
::
uno
::
Reference
<
::
com
::
sun
::
star
::
lang
::
XComponent
>
&
rComponent
,
T
*
p
=
0
)
scoped_disposing_ptr
(
const
::
com
::
sun
::
star
::
uno
::
Reference
<
::
com
::
sun
::
star
::
lang
::
XComponent
>
&
rComponent
,
T
*
p
=
0
)
:
m_aItem
(
p
)
:
m_aItem
(
p
)
{
{
m_x
DisposingListener
=
new
DisposingListener
(
rComponent
,
m_aItem
);
m_x
TerminateListener
=
new
TerminateListener
(
rComponent
,
*
this
);
}
}
void
reset
(
T
*
p
=
0
)
v
irtual
v
oid
reset
(
T
*
p
=
0
)
{
{
m_aItem
.
reset
(
p
);
m_aItem
.
reset
(
p
);
}
}
...
@@ -81,42 +84,91 @@ public:
...
@@ -81,42 +84,91 @@ public:
reset
();
reset
();
}
}
private
:
private
:
class
DisposingListener
:
public
::
cppu
::
WeakImplHelper1
<
::
com
::
sun
::
star
::
lang
::
XEvent
Listener
>
class
TerminateListener
:
public
::
cppu
::
WeakImplHelper1
<
::
com
::
sun
::
star
::
frame
::
XTerminate
Listener
>
{
{
private
:
private
:
::
com
::
sun
::
star
::
uno
::
Reference
<
::
com
::
sun
::
star
::
lang
::
XComponent
>
m_xComponent
;
::
com
::
sun
::
star
::
uno
::
Reference
<
::
com
::
sun
::
star
::
lang
::
XComponent
>
m_xComponent
;
boost
::
scoped
_ptr
<
T
>&
m_rItem
;
scoped_disposing
_ptr
<
T
>&
m_rItem
;
public
:
public
:
Disposing
Listener
(
const
::
com
::
sun
::
star
::
uno
::
Reference
<
::
com
::
sun
::
star
::
lang
::
XComponent
>
&
rComponent
,
Terminate
Listener
(
const
::
com
::
sun
::
star
::
uno
::
Reference
<
::
com
::
sun
::
star
::
lang
::
XComponent
>
&
rComponent
,
boost
::
scoped
_ptr
<
T
>&
rItem
)
:
m_xComponent
(
rComponent
),
m_rItem
(
rItem
)
scoped_disposing
_ptr
<
T
>&
rItem
)
:
m_xComponent
(
rComponent
),
m_rItem
(
rItem
)
{
{
if
(
m_xComponent
.
is
())
if
(
m_xComponent
.
is
())
m_xComponent
->
addEventListener
(
this
);
{
::
com
::
sun
::
star
::
uno
::
Reference
<
::
com
::
sun
::
star
::
frame
::
XDesktop
>
xDesktop
(
m_xComponent
,
::
com
::
sun
::
star
::
uno
::
UNO_QUERY
);
if
(
xDesktop
.
is
())
xDesktop
->
addTerminateListener
(
this
);
else
m_xComponent
->
addEventListener
(
this
);
}
}
}
~
Disposing
Listener
()
~
Terminate
Listener
()
{
{
if
(
m_xComponent
.
is
()
)
if
(
m_xComponent
.
is
()
)
m_xComponent
->
removeEventListener
(
this
);
{
::
com
::
sun
::
star
::
uno
::
Reference
<
::
com
::
sun
::
star
::
frame
::
XDesktop
>
xDesktop
(
m_xComponent
,
::
com
::
sun
::
star
::
uno
::
UNO_QUERY
);
if
(
xDesktop
.
is
())
xDesktop
->
removeTerminateListener
(
this
);
else
m_xComponent
->
removeEventListener
(
this
);
}
}
}
private
:
private
:
// XEventListener
// XEventListener
virtual
void
SAL_CALL
disposing
(
::
com
::
sun
::
star
::
lang
::
EventObject
const
&
rEvt
)
virtual
void
SAL_CALL
disposing
(
const
::
com
::
sun
::
star
::
lang
::
EventObject
&
rEvt
)
throw
(
::
com
::
sun
::
star
::
uno
::
RuntimeException
)
throw
(
::
com
::
sun
::
star
::
uno
::
RuntimeException
)
{
{
bool
shutDown
=
(
rEvt
.
Source
==
m_xComponent
);
bool
shutDown
=
(
rEvt
.
Source
==
m_xComponent
);
if
(
shutDown
&&
m_xComponent
.
is
()
)
if
(
shutDown
&&
m_xComponent
.
is
()
)
{
{
m_xComponent
->
removeEventListener
(
this
);
::
com
::
sun
::
star
::
uno
::
Reference
<
::
com
::
sun
::
star
::
frame
::
XDesktop
>
xDesktop
(
m_xComponent
,
::
com
::
sun
::
star
::
uno
::
UNO_QUERY
);
if
(
xDesktop
.
is
())
xDesktop
->
removeTerminateListener
(
this
);
else
m_xComponent
->
removeEventListener
(
this
);
m_xComponent
.
clear
();
m_xComponent
.
clear
();
}
}
if
(
shutDown
)
if
(
shutDown
)
m_rItem
.
reset
();
m_rItem
.
reset
();
}
}
};
// XTerminateListener
virtual
void
SAL_CALL
queryTermination
(
const
::
com
::
sun
::
star
::
lang
::
EventObject
&
)
throw
(
::
com
::
sun
::
star
::
frame
::
TerminationVetoException
,
::
com
::
sun
::
star
::
uno
::
RuntimeException
)
{
}
virtual
void
SAL_CALL
notifyTermination
(
const
::
com
::
sun
::
star
::
lang
::
EventObject
&
rEvt
)
throw
(
::
com
::
sun
::
star
::
uno
::
RuntimeException
)
{
disposing
(
rEvt
);
}
};
};
//Something like an OutputDevice requires the SolarMutex to be taken before use
//for threadsafety. The user can ensure this, except in the case of its dtor
//being called from reset due to a terminate on the XComponent being called
//from an aribitrary thread
template
<
class
T
>
class
scoped_disposing_solar_mutex_reset_ptr
:
public
scoped_disposing_ptr
<
T
>
{
public
:
scoped_disposing_solar_mutex_reset_ptr
(
const
::
com
::
sun
::
star
::
uno
::
Reference
<
::
com
::
sun
::
star
::
lang
::
XComponent
>
&
rComponent
,
T
*
p
=
0
)
:
scoped_disposing_ptr
<
T
>
(
rComponent
,
p
)
{
}
virtual
void
reset
(
T
*
p
=
0
)
{
SolarMutexGuard
aGuard
;
scoped_disposing_ptr
<
T
>::
reset
(
p
);
}
};
};
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment