LibreOffice Module o3tl (master)  1
deleter.hxx
Go to the documentation of this file.
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 
10 #ifndef INCLUDED_O3TL_DELETER_HXX
11 #define INCLUDED_O3TL_DELETER_HXX
12 
13 #include <com/sun/star/uno/Exception.hpp>
14 #include <sal/log.hxx>
15 
16 namespace o3tl {
17 
22 template<typename T> struct default_delete
23 {
24  void operator() (T* p) noexcept
25  {
26 #if defined(__COVERITY__)
27  try
28  {
29  delete p;
30  }
31  catch (const css::uno::Exception&)
32  {
33  SAL_WARN("vcl.app", "Fatal exception: " << exceptionToString(ex));
34  std::terminate();
35  }
36  catch (const std::exception& e)
37  {
38  SAL_WARN("vcl.app", "Fatal exception: " << e.what());
39  std::terminate();
40  }
41 #else
42  delete p;
43 #endif
44  }
45 };
46 
47 template<typename uniqueptr> void reset_preserve_ptr_during(uniqueptr& ptr)
48 {
49  // HACK: for the case where the dtor of the obj held by ptr will trigger
50  // functions which expect ptr to still be set during the dtor.
51  // e.g. SdrObject::GetBroadcaster() is called during the destructor
52  // in SdrEdgeObj::Notify(). So delete first, then clear the pointer
53  delete ptr.get();
54  (void)ptr.release();
55 }
56 
57 }
58 
59 #endif
60 
61 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void reset_preserve_ptr_during(uniqueptr &ptr)
Definition: deleter.hxx:47
void operator()(T *p) noexcept
Definition: deleter.hxx:24
OString exceptionToString(const css::uno::Any &caught)
To markup std::unique_ptr that coverity warns might throw exceptions which won't throw in practice...
Definition: deleter.hxx:22
void * p
#define SAL_WARN(area, stream)
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo