C/C++教程

licode 源码之pipline 分析

本文主要是介绍licode 源码之pipline 分析,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!

template <class Handler>
 struct ContextType {
   typedef typename std::conditional<
    Handler::dir == HandlerDir::BOTH,
    ContextImpl<Handler>,
    typename std::conditional<
      Handler::dir == HandlerDir::IN,
      InboundContextImpl<Handler>,
      OutboundContextImpl<Handler>
    >::type>::type
  type;
};  

上面的代码乍一看仿佛很难,但是仔细研究一下也不过如此哈,首先我们要知道 std::conditional 是什么意思,该函数的官方解释为根据判断条件定义type 为何类型,如果判断条件为true,则type定义为第二个参数类型,否则为第三个参数类型。

  延伸到ContextType  上来解释就是如果模板Handler的dir是BOTH,则参数类型为 ContextImpl<Handler> ,否则调用 typename std::conditional<
      Handler::dir == HandlerDir::IN,
      InboundContextImpl<Handler>,
      OutboundContextImpl<Handler>
    >::type  和上面分析的流程一样,到此 ContextType 的type 就有三种可能,如果dir 为IN 则为 InboundContextImpl<Handler> 如果为OUT 则为OutboundContextImpl<Handler>,如果为BOTH 则为ContextImpl<Handler>

这篇关于licode 源码之pipline 分析的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!