2016-11-20 22:04:31 +00:00
|
|
|
#pragma once
|
|
|
|
|
2016-12-03 15:44:08 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
|
2016-11-20 22:04:31 +00:00
|
|
|
#include "common.hpp"
|
|
|
|
|
|
|
|
POLYBAR_NS
|
|
|
|
|
|
|
|
namespace factory_util {
|
2016-12-20 04:05:43 +00:00
|
|
|
namespace detail {
|
|
|
|
struct null_deleter {
|
|
|
|
template <typename T>
|
|
|
|
void operator()(T*) const {}
|
|
|
|
};
|
|
|
|
|
|
|
|
struct fd_deleter {
|
|
|
|
void operator()(int* fd) const {
|
|
|
|
if (fd != nullptr && *fd > 0) {
|
|
|
|
close(*fd);
|
|
|
|
}
|
2016-12-03 15:44:08 +00:00
|
|
|
}
|
2016-12-20 04:05:43 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
extern detail::null_deleter null_deleter;
|
|
|
|
extern detail::fd_deleter fd_deleter;
|
2016-12-03 15:44:08 +00:00
|
|
|
|
2016-12-05 19:41:00 +00:00
|
|
|
template <typename T, typename... Deps>
|
|
|
|
unique_ptr<T> unique(Deps&&... deps) {
|
|
|
|
return make_unique<T>(forward<Deps>(deps)...);
|
2016-11-20 22:04:31 +00:00
|
|
|
}
|
|
|
|
|
2016-12-05 19:41:00 +00:00
|
|
|
template <typename T, typename... Deps>
|
|
|
|
shared_ptr<T> shared(Deps&&... deps) {
|
|
|
|
return make_shared<T>(forward<Deps>(deps)...);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <class T, class... Deps>
|
|
|
|
shared_ptr<T> singleton(Deps&&... deps) {
|
2016-12-13 13:26:09 +00:00
|
|
|
static shared_ptr<T> instance{make_shared<T>(forward<Deps>(deps)...)};
|
2016-11-20 22:04:31 +00:00
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
POLYBAR_NS_END
|