#pragma once
+#include <type_traits>
+
#include <folly/wangle/channel/Pipeline.h>
namespace folly { namespace wangle {
template <class R, class W>
class StaticPipeline<R, W> : public Pipeline<R, W> {
protected:
- explicit StaticPipeline(bool) : Pipeline<R, W>() {}
+ explicit StaticPipeline(bool) : Pipeline<R, W>(true) {}
+};
+
+template <class Handler>
+class BaseWithOptional {
+ protected:
+ folly::Optional<Handler> handler_;
+};
+
+template <class Handler>
+class BaseWithoutOptional {
};
template <class R, class W, class Handler, class... Handlers>
class StaticPipeline<R, W, Handler, Handlers...>
- : public StaticPipeline<R, W, Handlers...> {
+ : public StaticPipeline<R, W, Handlers...>
+ , public std::conditional<std::is_abstract<Handler>::value,
+ BaseWithoutOptional<Handler>,
+ BaseWithOptional<Handler>>::type {
public:
template <class... HandlerArgs>
explicit StaticPipeline(HandlerArgs&&... handlers)
}
protected:
- typedef ContextImpl<Pipeline<R, W>, Handler> Context;
-
template <class HandlerArg, class... HandlerArgs>
StaticPipeline(
bool isFirst,
Handler
>::value>::type
setHandler(HandlerArg&& arg) {
- handler_.emplace(std::forward<HandlerArg>(arg));
- handlerPtr_ = std::shared_ptr<Handler>(&(*handler_), [](Handler*){});
+ BaseWithOptional<Handler>::handler_.emplace(std::forward<HandlerArg>(arg));
+ handlerPtr_ = std::shared_ptr<Handler>(&(*BaseWithOptional<Handler>::handler_), [](Handler*){});
}
template <class HandlerArg>
}
bool isFirst_;
- folly::Optional<Handler> handler_;
std::shared_ptr<Handler> handlerPtr_;
- ContextImpl<Pipeline<R, W>, Handler> ctx_;
+ typename ContextType<Handler, Pipeline<R, W>>::type ctx_;
};
}} // folly::wangle