Skip to content

Commit

Permalink
Removed void parameters in libprocess.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpark committed Jan 20, 2016
1 parent 93a5708 commit 05f9fb2
Show file tree
Hide file tree
Showing 19 changed files with 105 additions and 151 deletions.
34 changes: 17 additions & 17 deletions 3rdparty/libprocess/include/process/async.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,15 @@ namespace process {
// brittle).

template <typename F>
Future<typename result_of<F(void)>::type> async(
Future<typename result_of<F()>::type> async(
const F& f,
typename boost::disable_if<boost::is_void<typename result_of<F(void)>::type> >::type* = NULL); // NOLINT(whitespace/line_length)
typename boost::disable_if<boost::is_void<typename result_of<F()>::type> >::type* = NULL); // NOLINT(whitespace/line_length)


template <typename F>
Future<Nothing> async(
const F& f,
typename boost::enable_if<boost::is_void<typename result_of<F(void)>::type> >::type* = NULL); // NOLINT(whitespace/line_length)
typename boost::enable_if<boost::is_void<typename result_of<F()>::type> >::type* = NULL); // NOLINT(whitespace/line_length)


#define TEMPLATE(Z, N, DATA) \
Expand Down Expand Up @@ -77,9 +77,9 @@ class AsyncExecutorProcess : public Process<AsyncExecutorProcess>
AsyncExecutorProcess& operator=(const AsyncExecutorProcess&);

template <typename F>
typename result_of<F(void)>::type execute(
typename result_of<F()>::type execute(
const F& f,
typename boost::disable_if<boost::is_void<typename result_of<F(void)>::type> >::type* = NULL) // NOLINT(whitespace/line_length)
typename boost::disable_if<boost::is_void<typename result_of<F()>::type> >::type* = NULL) // NOLINT(whitespace/line_length)
{
terminate(self()); // Terminate process after function returns.
return f();
Expand All @@ -88,7 +88,7 @@ class AsyncExecutorProcess : public Process<AsyncExecutorProcess>
template <typename F>
Nothing execute(
const F& f,
typename boost::enable_if<boost::is_void<typename result_of<F(void)>::type> >::type* = NULL) // NOLINT(whitespace/line_length)
typename boost::enable_if<boost::is_void<typename result_of<F()>::type> >::type* = NULL) // NOLINT(whitespace/line_length)
{
terminate(self()); // Terminate process after function returns.
f();
Expand Down Expand Up @@ -128,14 +128,14 @@ class AsyncExecutor
private:
// Declare async functions as friends.
template <typename F>
friend Future<typename result_of<F(void)>::type> async(
friend Future<typename result_of<F()>::type> async(
const F& f,
typename boost::disable_if<boost::is_void<typename result_of<F(void)>::type> >::type*); // NOLINT(whitespace/line_length)
typename boost::disable_if<boost::is_void<typename result_of<F()>::type> >::type*); // NOLINT(whitespace/line_length)

template <typename F>
friend Future<Nothing> async(
const F& f,
typename boost::enable_if<boost::is_void<typename result_of<F(void)>::type> >::type*); // NOLINT(whitespace/line_length)
typename boost::enable_if<boost::is_void<typename result_of<F()>::type> >::type*); // NOLINT(whitespace/line_length)

#define TEMPLATE(Z, N, DATA) \
template <typename F, ENUM_PARAMS(N, typename A)> \
Expand Down Expand Up @@ -166,12 +166,12 @@ class AsyncExecutor
AsyncExecutor& operator=(const AsyncExecutor&);

template <typename F>
Future<typename result_of<F(void)>::type> execute(
Future<typename result_of<F()>::type> execute(
const F& f,
typename boost::disable_if<boost::is_void<typename result_of<F(void)>::type> >::type* = NULL) // NOLINT(whitespace/line_length)
typename boost::disable_if<boost::is_void<typename result_of<F()>::type> >::type* = NULL) // NOLINT(whitespace/line_length)
{
// Need to disambiguate overloaded method.
typename result_of<F(void)>::type(AsyncExecutorProcess::*method)(const F&, typename boost::disable_if<boost::is_void<typename result_of<F(void)>::type> >::type*) = // NOLINT(whitespace/line_length)
typename result_of<F()>::type(AsyncExecutorProcess::*method)(const F&, typename boost::disable_if<boost::is_void<typename result_of<F()>::type> >::type*) = // NOLINT(whitespace/line_length)
&AsyncExecutorProcess::execute<F>;

return dispatch(process, method, f, (void*) NULL);
Expand All @@ -180,10 +180,10 @@ class AsyncExecutor
template <typename F>
Future<Nothing> execute(
const F& f,
typename boost::enable_if<boost::is_void<typename result_of<F(void)>::type> >::type* = NULL) // NOLINT(whitespace/line_length)
typename boost::enable_if<boost::is_void<typename result_of<F()>::type> >::type* = NULL) // NOLINT(whitespace/line_length)
{
// Need to disambiguate overloaded method.
Nothing(AsyncExecutorProcess::*method)(const F&, typename boost::enable_if<boost::is_void<typename result_of<F(void)>::type> >::type*) = // NOLINT(whitespace/line_length)
Nothing(AsyncExecutorProcess::*method)(const F&, typename boost::enable_if<boost::is_void<typename result_of<F()>::type> >::type*) = // NOLINT(whitespace/line_length)
&AsyncExecutorProcess::execute<F>;

return dispatch(process, method, f, (void*) NULL);
Expand Down Expand Up @@ -225,9 +225,9 @@ class AsyncExecutor

// Provides an abstraction for asynchronously executing a function.
template <typename F>
Future<typename result_of<F(void)>::type> async(
Future<typename result_of<F()>::type> async(
const F& f,
typename boost::disable_if<boost::is_void<typename result_of<F(void)>::type> >::type*) // NOLINT(whitespace/line_length)
typename boost::disable_if<boost::is_void<typename result_of<F()>::type> >::type*) // NOLINT(whitespace/line_length)
{
return AsyncExecutor().execute(f);
}
Expand All @@ -236,7 +236,7 @@ Future<typename result_of<F(void)>::type> async(
template <typename F>
Future<Nothing> async(
const F& f,
typename boost::enable_if<boost::is_void<typename result_of<F(void)>::type> >::type*) // NOLINT(whitespace/line_length)
typename boost::enable_if<boost::is_void<typename result_of<F()>::type> >::type*) // NOLINT(whitespace/line_length)
{
return AsyncExecutor().execute(f);
}
Expand Down
2 changes: 1 addition & 1 deletion 3rdparty/libprocess/include/process/clock.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class Clock

static Timer timer(
const Duration& duration,
const lambda::function<void(void)>& thunk);
const lambda::function<void()>& thunk);

static bool cancel(const Timer& timer);

Expand Down
42 changes: 12 additions & 30 deletions 3rdparty/libprocess/include/process/defer.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,29 +32,21 @@ namespace process {
// First, definitions of defer for methods returning void:

template <typename T>
Deferred<void(void)> defer(
const PID<T>& pid,
void (T::*method)(void))
Deferred<void()> defer(const PID<T>& pid, void (T::*method)())
{
return Deferred<void(void)>([=]() {
dispatch(pid, method);
});
return Deferred<void()>([=]() { dispatch(pid, method); });
}


template <typename T>
Deferred<void(void)> defer(
const Process<T>& process,
void (T::*method)(void))
Deferred<void()> defer(const Process<T>& process, void (T::*method)())
{
return defer(process.self(), method);
}


template <typename T>
Deferred<void(void)> defer(
const Process<T>* process,
void (T::*method)(void))
Deferred<void()> defer(const Process<T>* process, void (T::*method)())
{
return defer(process->self(), method);
}
Expand Down Expand Up @@ -111,24 +103,19 @@ Deferred<void(void)> defer(
// Next, definitions of defer for methods returning future:

template <typename R, typename T>
Deferred<Future<R>(void)>
defer(const PID<T>& pid, Future<R> (T::*method)(void))
Deferred<Future<R>()> defer(const PID<T>& pid, Future<R> (T::*method)())
{
return Deferred<Future<R>(void)>([=]() {
return dispatch(pid, method);
});
return Deferred<Future<R>()>([=]() { return dispatch(pid, method); });
}

template <typename R, typename T>
Deferred<Future<R>(void)>
defer(const Process<T>& process, Future<R> (T::*method)(void))
Deferred<Future<R>()> defer(const Process<T>& process, Future<R> (T::*method)())
{
return defer(process.self(), method);
}

template <typename R, typename T>
Deferred<Future<R>(void)>
defer(const Process<T>* process, Future<R> (T::*method)(void))
Deferred<Future<R>()> defer(const Process<T>* process, Future<R> (T::*method)())
{
return defer(process->self(), method);
}
Expand Down Expand Up @@ -181,24 +168,19 @@ defer(const Process<T>* process, Future<R> (T::*method)(void))
// Finaly, definitions of defer for methods returning a value:

template <typename R, typename T>
Deferred<Future<R>(void)>
defer(const PID<T>& pid, R (T::*method)(void))
Deferred<Future<R>()> defer(const PID<T>& pid, R (T::*method)())
{
return Deferred<Future<R>(void)>([=]() {
return dispatch(pid, method);
});
return Deferred<Future<R>()>([=]() { return dispatch(pid, method); });
}

template <typename R, typename T>
Deferred<Future<R>(void)>
defer(const Process<T>& process, R (T::*method)(void))
Deferred<Future<R>()> defer(const Process<T>& process, R (T::*method)())
{
return defer(process.self(), method);
}

template <typename R, typename T>
Deferred<Future<R>(void)>
defer(const Process<T>* process, R (T::*method)(void))
Deferred<Future<R>()> defer(const Process<T>* process, R (T::*method)())
{
return defer(process->self(), method);
}
Expand Down
12 changes: 6 additions & 6 deletions 3rdparty/libprocess/include/process/deferred.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,16 @@ struct Deferred : std::function<F>
// TODO(benh): Consider removing these in favor of having these
// functions return _Deferred.
template <typename T>
friend Deferred<void(void)>
defer(const PID<T>& pid, void (T::*method)(void));
friend Deferred<void()>
defer(const PID<T>& pid, void (T::*method)());

template <typename R, typename T>
friend Deferred<Future<R>(void)>
defer(const PID<T>& pid, Future<R> (T::*method)(void));
friend Deferred<Future<R>()>
defer(const PID<T>& pid, Future<R> (T::*method)());

template <typename R, typename T>
friend Deferred<Future<R>(void)>
defer(const PID<T>& pid, R (T::*method)(void));
friend Deferred<Future<R>()>
defer(const PID<T>& pid, R (T::*method)());

/*implicit*/ Deferred(const std::function<F>& f) : std::function<F>(f) {}
};
Expand Down
48 changes: 12 additions & 36 deletions 3rdparty/libprocess/include/process/dispatch.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,9 +77,7 @@ void dispatch(
// First, definitions of dispatch for methods returning void:

template <typename T>
void dispatch(
const PID<T>& pid,
void (T::*method)())
void dispatch(const PID<T>& pid, void (T::*method)())
{
std::shared_ptr<std::function<void(ProcessBase*)>> f(
new std::function<void(ProcessBase*)>(
Expand All @@ -94,17 +92,13 @@ void dispatch(
}

template <typename T>
void dispatch(
const Process<T>& process,
void (T::*method)())
void dispatch(const Process<T>& process, void (T::*method)())
{
dispatch(process.self(), method);
}

template <typename T>
void dispatch(
const Process<T>* process,
void (T::*method)())
void dispatch(const Process<T>* process, void (T::*method)())
{
dispatch(process->self(), method);
}
Expand Down Expand Up @@ -162,9 +156,7 @@ void dispatch(
// Next, definitions of methods returning a future:

template <typename R, typename T>
Future<R> dispatch(
const PID<T>& pid,
Future<R> (T::*method)())
Future<R> dispatch(const PID<T>& pid, Future<R> (T::*method)())
{
std::shared_ptr<Promise<R>> promise(new Promise<R>());

Expand All @@ -183,17 +175,13 @@ Future<R> dispatch(
}

template <typename R, typename T>
Future<R> dispatch(
const Process<T>& process,
Future<R> (T::*method)(void))
Future<R> dispatch(const Process<T>& process, Future<R> (T::*method)())
{
return dispatch(process.self(), method);
}

template <typename R, typename T>
Future<R> dispatch(
const Process<T>* process,
Future<R> (T::*method)(void))
Future<R> dispatch(const Process<T>* process, Future<R> (T::*method)())
{
return dispatch(process->self(), method);
}
Expand Down Expand Up @@ -255,9 +243,7 @@ Future<R> dispatch(
// Next, definitions of methods returning a value.

template <typename R, typename T>
Future<R> dispatch(
const PID<T>& pid,
R (T::*method)(void))
Future<R> dispatch(const PID<T>& pid, R (T::*method)())
{
std::shared_ptr<Promise<R>> promise(new Promise<R>());

Expand All @@ -276,17 +262,13 @@ Future<R> dispatch(
}

template <typename R, typename T>
Future<R> dispatch(
const Process<T>& process,
R (T::*method)())
Future<R> dispatch(const Process<T>& process, R (T::*method)())
{
return dispatch(process.self(), method);
}

template <typename R, typename T>
Future<R> dispatch(
const Process<T>* process,
R (T::*method)())
Future<R> dispatch(const Process<T>* process, R (T::*method)())
{
return dispatch(process->self(), method);
}
Expand Down Expand Up @@ -345,9 +327,7 @@ Future<R> dispatch(
#undef TEMPLATE


inline void dispatch(
const UPID& pid,
const std::function<void()>& f)
inline void dispatch(const UPID& pid, const std::function<void()>& f)
{
std::shared_ptr<std::function<void(ProcessBase*)>> f_(
new std::function<void(ProcessBase*)>(
Expand All @@ -360,9 +340,7 @@ inline void dispatch(


template <typename R>
Future<R> dispatch(
const UPID& pid,
const std::function<Future<R>()>& f)
Future<R> dispatch(const UPID& pid, const std::function<Future<R>()>& f)
{
std::shared_ptr<Promise<R>> promise(new Promise<R>());

Expand All @@ -379,9 +357,7 @@ Future<R> dispatch(


template <typename R>
Future<R> dispatch(
const UPID& pid,
const std::function<R()>& f)
Future<R> dispatch(const UPID& pid, const std::function<R()>& f)
{
std::shared_ptr<Promise<R>> promise(new Promise<R>());

Expand Down
4 changes: 2 additions & 2 deletions 3rdparty/libprocess/include/process/future.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -151,10 +151,10 @@ class Future

// Type of the callback functions that can get invoked when the
// future gets set, fails, or is discarded.
typedef lambda::function<void(void)> DiscardCallback;
typedef lambda::function<void()> DiscardCallback;
typedef lambda::function<void(const T&)> ReadyCallback;
typedef lambda::function<void(const std::string&)> FailedCallback;
typedef lambda::function<void(void)> DiscardedCallback;
typedef lambda::function<void()> DiscardedCallback;
typedef lambda::function<void(const Future<T>&)> AnyCallback;

// Installs callbacks for the specified events and returns a const
Expand Down
11 changes: 4 additions & 7 deletions 3rdparty/libprocess/include/process/metrics/gauge.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ class Gauge : public Metric
// 'name' is the unique name for the instance of Gauge being constructed.
// It will be the key exposed in the JSON endpoint.
// 'f' is the deferred object called when the Metric value is requested.
Gauge(const std::string& name,
const Deferred<Future<double> (void)>& f)
: Metric(name, None()),
data(new Data(f)) {}
Gauge(const std::string& name, const Deferred<Future<double>()>& f)
: Metric(name, None()), data(new Data(f)) {}

virtual ~Gauge() {}

Expand All @@ -43,10 +41,9 @@ class Gauge : public Metric
private:
struct Data
{
explicit Data(const Deferred<Future<double> (void)>& _f)
: f(_f) {}
explicit Data(const Deferred<Future<double>()>& _f) : f(_f) {}

const Deferred<Future<double> (void)> f;
const Deferred<Future<double>()> f;
};

std::shared_ptr<Data> data;
Expand Down
Loading

0 comments on commit 05f9fb2

Please sign in to comment.