summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/animator.cc5
-rw-r--r--src/animator.hh3
-rw-r--r--src/args.cc4
-rw-r--r--src/args.hh3
-rw-r--r--src/common.hh4
-rw-r--r--src/fake_monitor.cc5
-rw-r--r--src/fake_monitor.hh2
-rw-r--r--src/main.cc6
-rw-r--r--src/make_unique.hh15
-rw-r--r--src/monitor.cc8
-rw-r--r--src/monitor.hh2
-rw-r--r--src/poll_looper.cc4
-rw-r--r--src/poll_looper.hh4
-rw-r--r--src/x.cc10
-rw-r--r--src/x.hh5
15 files changed, 54 insertions, 26 deletions
diff --git a/src/animator.cc b/src/animator.cc
index 7ed412c..a0108c2 100644
--- a/src/animator.cc
+++ b/src/animator.cc
@@ -257,6 +257,7 @@ private:
} // namespace
// static
-Animator* Animator::create(std::shared_ptr<Looper> const& looper) {
- return new AnimatorImpl(looper);
+std::unique_ptr<Animator> Animator::create(
+ std::shared_ptr<Looper> const& looper) {
+ return std::make_unique<AnimatorImpl>(looper);
}
diff --git a/src/animator.hh b/src/animator.hh
index c8072ac..4f9253c 100644
--- a/src/animator.hh
+++ b/src/animator.hh
@@ -39,7 +39,8 @@ public:
virtual ~Animator() {}
- static Animator* create(std::shared_ptr<Looper> const& looper);
+ static std::unique_ptr<Animator> create(
+ std::shared_ptr<Looper> const& looper);
virtual void start(std::shared_ptr<Animation> const& animation,
AnimationObserver* observer) = 0;
diff --git a/src/args.cc b/src/args.cc
index 9b3e409..c4522f5 100644
--- a/src/args.cc
+++ b/src/args.cc
@@ -317,7 +317,7 @@ private:
} // namespace
// static
-Args* Args::create() {
- return new ArgsImpl();
+std::unique_ptr<Args> Args::create() {
+ return std::make_unique<ArgsImpl>();
}
diff --git a/src/args.hh b/src/args.hh
index 7f6d94b..6490182 100644
--- a/src/args.hh
+++ b/src/args.hh
@@ -2,6 +2,7 @@
#define ARGS_HH
#include <iostream>
+#include <memory>
#include <string>
#include <vector>
@@ -9,7 +10,7 @@ class Args {
public:
virtual ~Args() {}
- static Args* create();
+ static std::unique_ptr<Args> create();
virtual void add(char short_opt, std::string const& long_opt,
std::string const& argument, std::string const& help) = 0;
diff --git a/src/common.hh b/src/common.hh
index 14d9a2a..b372ac1 100644
--- a/src/common.hh
+++ b/src/common.hh
@@ -7,4 +7,8 @@
#include <assert.h>
+#if __cplusplus < 201402L
+#include "make_unique.hh"
+#endif
+
#endif // COMMON_HH
diff --git a/src/fake_monitor.cc b/src/fake_monitor.cc
index d2537ab..a444476 100644
--- a/src/fake_monitor.cc
+++ b/src/fake_monitor.cc
@@ -207,6 +207,7 @@ private:
} // namespace
// static
-Monitor* FakeMonitor::create(std::shared_ptr<Looper> const& looper) {
- return new FakeMonitorImpl(looper);
+std::unique_ptr<Monitor> FakeMonitor::create(
+ std::shared_ptr<Looper> const& looper) {
+ return std::make_unique<FakeMonitorImpl>(looper);
}
diff --git a/src/fake_monitor.hh b/src/fake_monitor.hh
index 836e082..bb5cdc9 100644
--- a/src/fake_monitor.hh
+++ b/src/fake_monitor.hh
@@ -5,7 +5,7 @@
class FakeMonitor : public Monitor {
public:
- static Monitor* create(std::shared_ptr<Looper> const& looper);
+ static std::unique_ptr<Monitor> create(std::shared_ptr<Looper> const& looper);
};
#endif // FAKE_MONITOR_HH
diff --git a/src/main.cc b/src/main.cc
index f259417..fdf2e61 100644
--- a/src/main.cc
+++ b/src/main.cc
@@ -223,9 +223,9 @@ public:
void connect(Args const* args) {
#if FAKE_MONITOR
- monitor_.reset(FakeMonitor::create(looper_));
+ monitor_ = FakeMonitor::create(looper_);
#else
- monitor_.reset(Monitor::create(looper_));
+ monitor_ = Monitor::create(looper_);
#endif
monitor_->add_observer(this);
monitor_->connect(args->arg("network", ""),
@@ -796,7 +796,7 @@ private:
void animate(Machine& machine) {
if (!animator_) return;
if (machine.animation) return;
- machine.animation.reset(new MachineAnimation(&machine));
+ machine.animation = std::make_unique<MachineAnimation>(&machine);
animator_->start(machine.animation, &machine);
}
diff --git a/src/make_unique.hh b/src/make_unique.hh
new file mode 100644
index 0000000..c5a1bbc
--- /dev/null
+++ b/src/make_unique.hh
@@ -0,0 +1,15 @@
+#ifndef MAKE_UNIQUE_HH
+#define MAKE_UNIQUE_HH
+
+#include <memory>
+
+namespace std {
+
+template<typename T, typename... Args>
+inline std::unique_ptr<T> make_unique(Args&&... args) {
+ return std::unique_ptr<T>(new T(std::forward<Args>(args)...));
+}
+
+} // namespace std
+
+#endif // MAKE_UNIQUE_HH
diff --git a/src/monitor.cc b/src/monitor.cc
index 152bac3..c665034 100644
--- a/src/monitor.cc
+++ b/src/monitor.cc
@@ -122,7 +122,8 @@ private:
if (channel_) return;
if (!discover_) {
- discover_.reset(new DiscoverSched(netname_, 2, hostname_, port_));
+ discover_ =
+ std::make_unique<DiscoverSched>(netname_, 2, hostname_, port_);
}
channel_.reset(discover_->try_get_scheduler());
@@ -417,6 +418,7 @@ Monitor::Machine const MonitorImpl::EMPTY;
} // namespace
// static
-Monitor* Monitor::create(std::shared_ptr<Looper> const& looper) {
- return new MonitorImpl(looper);
+std::unique_ptr<Monitor> Monitor::create(
+ std::shared_ptr<Looper> const& looper) {
+ return std::make_unique<MonitorImpl>(looper);
}
diff --git a/src/monitor.hh b/src/monitor.hh
index b7ddbea..14168f0 100644
--- a/src/monitor.hh
+++ b/src/monitor.hh
@@ -40,7 +40,7 @@ public:
virtual ~Monitor() {}
- static Monitor* create(std::shared_ptr<Looper> const& looper);
+ static std::unique_ptr<Monitor> create(std::shared_ptr<Looper> const& looper);
virtual void connect(std::string const& netname = std::string(),
std::string const& scheduler = std::string(),
diff --git a/src/poll_looper.cc b/src/poll_looper.cc
index 71788e0..5d689ea 100644
--- a/src/poll_looper.cc
+++ b/src/poll_looper.cc
@@ -244,6 +244,6 @@ private:
} // namespace
// static
-PollLooper* PollLooper::create() {
- return new PollLooperImpl();
+std::unique_ptr<PollLooper> PollLooper::create() {
+ return std::make_unique<PollLooperImpl>();
}
diff --git a/src/poll_looper.hh b/src/poll_looper.hh
index 16097fe..8f6038e 100644
--- a/src/poll_looper.hh
+++ b/src/poll_looper.hh
@@ -1,11 +1,13 @@
#ifndef POLL_LOOPER_HH
#define POLL_LOOPER_HH
+#include <memory>
+
#include "looper.hh"
class PollLooper : public Looper {
public:
- static PollLooper* create();
+ static std::unique_ptr<PollLooper> create();
virtual void run() = 0;
diff --git a/src/x.cc b/src/x.cc
index 3749f81..1be092a 100644
--- a/src/x.cc
+++ b/src/x.cc
@@ -123,7 +123,7 @@ private:
if (supported_ || !conn_) return;
ensure_cookies();
auto cookie = xcb_ewmh_get_supported(&ewmh_, screen_);
- supported_.reset(new xcb_ewmh_get_atoms_reply_t());
+ supported_ = std::make_unique<xcb_ewmh_get_atoms_reply_t>();
if (!xcb_ewmh_get_supported_reply(&ewmh_, cookie, supported_.get(),
nullptr)) {
conn_.reset();
@@ -140,13 +140,13 @@ private:
} // namespace
// static
-Atoms* Atoms::create(shared_connection const& conn) {
- return new AtomsImpl(conn);
+std::unique_ptr<Atoms> Atoms::create(shared_connection const& conn) {
+ return std::make_unique<AtomsImpl>(conn);
}
// static
-Ewmh* Ewmh::create(shared_connection const& conn, int screen) {
- return new EwmhImpl(conn, screen);
+std::unique_ptr<Ewmh> Ewmh::create(shared_connection const& conn, int screen) {
+ return std::make_unique<EwmhImpl>(conn, screen);
}
xcb_screen_t const* get_screen(xcb_connection_t* conn, int screen) {
diff --git a/src/x.hh b/src/x.hh
index 00751c2..27ac745 100644
--- a/src/x.hh
+++ b/src/x.hh
@@ -247,7 +247,7 @@ class Atoms {
public:
virtual ~Atoms() {}
- static Atoms* create(shared_connection const& conn);
+ static std::unique_ptr<Atoms> create(shared_connection const& conn);
virtual void preload(std::string const& name, bool create = true) = 0;
virtual xcb_atom_t get(std::string const& name, bool create = true) = 0;
@@ -262,7 +262,8 @@ class Ewmh {
public:
virtual ~Ewmh() {}
- static Ewmh* create(shared_connection const& conn, int screen);
+ static std::unique_ptr<Ewmh> create(
+ shared_connection const& conn, int screen);
virtual xcb_ewmh_connection_t* conn() = 0;
virtual bool supported(xcb_atom_t atom) = 0;