• 软件测试技术
  • 软件测试博客
  • 软件测试视频
  • 开源软件测试技术
  • 软件测试论坛
  • 软件测试沙龙
  • 软件测试资料下载
  • 软件测试杂志
  • 软件测试人才招聘
    暂时没有公告

字号: | 推荐给好友 上一篇 | 下一篇

Loki库读解-为TypeList添足:最远基类、最近基类、类型的排序

发布: 2007-7-01 20:40 | 作者: admin | 来源: | 查看: 19次 | 进入软件测试论坛讨论

领测软件测试网

相对于TypeList源码,下面代码还是很简单的,就不多说废话了。

#ifndef TYPELIST_ADD_H
#define TYPELIST_ADD_H

//-------------------------------------------------------------------------------
//Loki库自己的SUPERSUBCLASS_STRICT在DevCpp下编译不过,lokiVC6port提供的版本同下。
//-------------------------------------------------------------------------------
#define SUPERSUBCLASS_STRICT_FIX(T, U) \
    (SUPERSUBCLASS(T, U) && \
    !::Loki::Conversion<const T *, const U *>::sameType)
   
//-------------------------------------------------------------------------------
//-------------------------------------------------------------------------------
template <class TList, class T> struct MostBased;

template <class T>
    struct MostBased<NullType, T>
{
    typedef T Result;
};

template <class Head, class Tail, class T>
    struct MostBased<Typelist<Head, Tail>, T>
{
private:
    typedef typename MostBased<Tail, T>::Result Candidate;
public:
    typedef typename Select<SUPERSUBCLASS(Head, Candidate),
            Head, Candidate>::Result Result;
};

//-------------------------------------------------------------------------       
//-------------------------------------------------------------------------
template <class Tlist, class T> struct NearestBased;

template <class Tlist, class T, class CurNearBase> struct NearestBasedHelper;

template <class Head, class Tail, class T, class CurNearBase>       
    struct NearestBasedHelper<Typelist<Head, Tail>, T, CurNearBase>
{
private:
    typedef typename Select< SUPERSUBCLASS_STRICT_FIX(Head, T) &&
                             SUPERSUBCLASS_STRICT_FIX(CurNearBase, Head),
                            Head, CurNearBase>::Result curnearbase;         //搜索处于两个类之间的类
public:                   
    typedef typename NearestBasedHelper<Tail, T, curnearbase>::Result Result;
};

template <class T, class CurNearBase>       
    struct NearestBasedHelper<NullType, T, CurNearBase>
{
    typedef CurNearBase Result;
};
       
template <class T>                             //保护对空TypeList发生操作。
struct NearestBased<NullType, T>
{
//    typedef T Result;
};

template <class Head, class Tail, class T>
    struct NearestBased<Typelist<Head, Tail>, T>
{
private:
    typedef MostBased<Typelist<Head, Tail>, T>::Result mostbased;   //找到最基类,然后夹杀法。
public:
    typedef typename NearestBasedHelper<Typelist<Head, Tail>, T, mostbased>::Result Result;
};

//-------------------------------------------------------------------------------
//排序完成后,派生类一定在它的基类前面。
//-------------------------------------------------------------------------------
template <class TList> struct Sort;

template <>
    struct Sort<NullType>
{
    typedef NullType Result;
};

template <class Head, class Tail>
    struct Sort<Typelist<Head, Tail> >
{
private:
    typedef typename MostDerived<Tail, Head>::Result             TheMostDerived;
    typedef typename Replace<Tail, TheMostDerived, Head>::Result L;
public:
    typedef Typelist<TheMostDerived, typename Sort<L>::Result>   Result;
   
};


#endif


延伸阅读

文章来源于领测软件测试网 https://www.ltesting.net/


关于领测软件测试网 | 领测软件测试网合作伙伴 | 广告服务 | 投稿指南 | 联系我们 | 网站地图 | 友情链接
版权所有(C) 2003-2010 TestAge(领测软件测试网)|领测国际科技(北京)有限公司|软件测试工程师培训网 All Rights Reserved
北京市海淀区中关村南大街9号北京理工科技大厦1402室 京ICP备2023014753号-2
技术支持和业务联系:info@testage.com.cn 电话:010-51297073

软件测试 | 领测国际ISTQBISTQB官网TMMiTMMi认证国际软件测试工程师认证领测软件测试网