mirror of
https://git.lyx.org/repos/lyx.git
synced 2024-11-22 10:00:33 +00:00
Move Trackable class to Server.h
This commit is contained in:
parent
4f0981e7bb
commit
d9e455b61a
@ -55,7 +55,6 @@
|
||||
#include "support/lassert.h"
|
||||
#include "support/lstrings.h"
|
||||
#include "support/os.h"
|
||||
#include "support/signals.h"
|
||||
|
||||
#include <iostream>
|
||||
|
||||
|
20
src/Server.h
20
src/Server.h
@ -14,8 +14,7 @@
|
||||
#ifndef SERVER_H
|
||||
#define SERVER_H
|
||||
|
||||
#include "support/signals.h"
|
||||
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
|
||||
#ifdef _WIN32
|
||||
@ -30,6 +29,21 @@ namespace lyx {
|
||||
class Server;
|
||||
|
||||
|
||||
/// A small utility to track the lifetime of an object.
|
||||
class Trackable {
|
||||
public:
|
||||
Trackable() : p_(std::make_shared<int>(0)) {}
|
||||
Trackable(Trackable const &) : Trackable() {}
|
||||
Trackable(Trackable &&) : Trackable() {}
|
||||
Trackable & operator=(Trackable const &) { return *this; }
|
||||
Trackable & operator=(Trackable &&) { return *this; }
|
||||
// This weak pointer lets you know if the parent object has been destroyed
|
||||
std::weak_ptr<void> p() const { return p_; }
|
||||
private:
|
||||
std::shared_ptr<void> const p_;
|
||||
};
|
||||
|
||||
|
||||
/** This class manages the pipes used for communicating with clients.
|
||||
Usage: Initialize with pipe-filename-base, client class to receive
|
||||
messages, and callback-function that will be called with the messages.
|
||||
@ -191,7 +205,7 @@ private:
|
||||
bool deferred_loading_;
|
||||
|
||||
/// Track object's liveness
|
||||
support::Trackable tracker_;
|
||||
Trackable tracker_;
|
||||
};
|
||||
|
||||
|
||||
|
@ -14,38 +14,12 @@
|
||||
|
||||
#include <nod.hpp>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace lyx {
|
||||
|
||||
using nod::signal;
|
||||
using nod::connection;
|
||||
using nod::scoped_connection;
|
||||
|
||||
namespace support {
|
||||
|
||||
/// A small utility to use with signals2::slot_type::track_foreign when the
|
||||
/// parent object is not handled by a shared_ptr, or to track the lifetime of an
|
||||
/// object. Using Trackable to track lifetimes is less thread-safe than tracking
|
||||
/// their parents directly with a shared_ptr as recommended by signals2, but it
|
||||
/// makes it easier for transitioning old code. (Essentially because Trackable
|
||||
/// will not prevent the deletion of the parent by a concurrent thread.)
|
||||
class Trackable {
|
||||
public:
|
||||
Trackable() : p_(std::make_shared<int>(0)) {}
|
||||
Trackable(Trackable const &) : Trackable() {}
|
||||
Trackable(Trackable &&) : Trackable() {}
|
||||
Trackable & operator=(Trackable const &) { return *this; }
|
||||
Trackable & operator=(Trackable &&) { return *this; }
|
||||
// This weak pointer lets you know if the parent object has been destroyed
|
||||
std::weak_ptr<void> p() const { return p_; }
|
||||
private:
|
||||
std::shared_ptr<void> const p_;
|
||||
};
|
||||
|
||||
} // namespace support
|
||||
|
||||
} // namespace lyx
|
||||
|
||||
|
||||
#endif
|
||||
|
Loading…
Reference in New Issue
Block a user