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 <sal/config.h>
14 
15 #include <cstdlib>
16 
17 #include <com/sun/star/uno/Exception.hpp>
18 #include <sal/log.hxx>
19 
20 namespace o3tl
21 {
26 template <typename T> struct default_delete
27 {
28  void operator()(T* p) noexcept
29  {
30 #if defined(__COVERITY__)
31  try
32  {
33  delete p;
34  }
35  catch (const css::uno::Exception& ex)
36  {
37  SAL_WARN("vcl.app", "Fatal exception: " << exceptionToString(ex));
38  std::terminate();
39  }
40  catch (const std::exception& e)
41  {
42  SAL_WARN("vcl.app", "Fatal exception: " << e.what());
43  std::terminate();
44  }
45 #else
46  delete p;
47 #endif
48  }
49 };
50 
52 {
53  void operator()(void* p) { std::free(p); }
54 };
55 
56 template <typename uniqueptr> void reset_preserve_ptr_during(uniqueptr& ptr)
57 {
58  // HACK: for the case where the dtor of the obj held by ptr will trigger
59  // functions which expect ptr to still be set during the dtor.
60  // e.g. SdrObject::GetBroadcaster() is called during the destructor
61  // in SdrEdgeObj::Notify(). So delete first, then clear the pointer
62  delete ptr.get();
63  (void)ptr.release();
64 }
65 }
66 
67 #endif
68 
69 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
void reset_preserve_ptr_during(uniqueptr &ptr)
Definition: deleter.hxx:56
void operator()(T *p) noexcept
Definition: deleter.hxx:28
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:26
void operator()(void *p)
Definition: deleter.hxx:53
void * p
#define SAL_WARN(area, stream)
typedef void(CALLTYPE *GetFuncDataPtr)(sal_uInt16 &nNo