]> git.lyx.org Git - lyx.git/blob - src/support/signals.h
Make tab movement visible (#10733)
[lyx.git] / src / support / signals.h
1 // -*- C++ -*-
2 /**
3  * \file signals.h
4  * This file is part of LyX, the document processor.
5  * Licence details can be found in the file COPYING.
6  *
7  * \author Guillaume Munch
8  *
9  * Full author contact details are available in file CREDITS.
10  */
11
12 #ifndef LYX_SIGNALS_H
13 #define LYX_SIGNALS_H
14
15 #include "boost/signals2.hpp"
16
17 #include <memory>
18
19 namespace lyx {
20
21 namespace signals2 = ::boost::signals2;
22
23 namespace support {
24
25 /// A small utility to use with signals2::slot_type::track_foreign when the
26 /// parent object is not handled by a shared_ptr, or to track the lifetime of an
27 /// object. Using Trackable to track lifetimes is less thread-safe than tracking
28 /// their parents directly with a shared_ptr as recommended by signals2, but it
29 /// makes it easier for transitioning old code. (Essentially because Trackable
30 /// will not prevent the deletion of the parent by a concurrent thread.)
31 class Trackable {
32 public:
33         Trackable() : p_(std::make_shared<int>(0)) {}
34         Trackable(Trackable const &) : Trackable() {}
35         Trackable(Trackable &&) : Trackable() {}
36         Trackable & operator=(Trackable const &) { return *this; }
37         Trackable & operator=(Trackable &&) { return *this; }
38         // This weak pointer lets you know if the parent object has been destroyed
39         std::weak_ptr<void> p() const { return p_; }
40 private:
41         std::shared_ptr<void> const p_;
42 };
43
44 } // namespace support
45
46 } // namespace lyx
47
48
49 #endif