00001 #ifndef _PTYPE_LIST_H
00002 #define _PTYPE_LIST_H
00003
00004 #include "osl/ptype.h"
00005 #include "osl/ptypeTraits.h"
00006 #include <iosfwd>
00007 #include <boost/static_assert.hpp>
00008 namespace osl
00009 {
00011 namespace ptl{
00012
00013 class NullPtype{
00014 public:
00015 static void show(std::ostream& os);
00016 };
00017
00018 template<Ptype T,class U>
00019 struct PtypeList;
00020
00021 template<class T>
00022 struct IsPtypeList{
00023 static const bool isPtypeList=false;
00024 };
00025
00026 template<>
00027 struct IsPtypeList<NullPtype>{
00028 static const bool isPtypeList=true;
00029 };
00030
00031 template<Ptype T,class U>
00032 struct IsPtypeList<PtypeList<T,U> >{
00033 static const bool isPtypeList=true;
00034 };
00035
00036
00037 template<Ptype T,class U>
00038
00039 struct PtypeList{
00040 BOOST_STATIC_ASSERT(IsPtypeList<U>::isPtypeList);
00041 static const Ptype value=T;
00042 typedef U Tail;
00043 static void show(std::ostream& os);
00044 };
00045
00046
00047 #define PTYPELIST_1(T1) PtypeList<T1,NullPtype>
00048 #define PTYPELIST_2(T1,T2) PtypeList<T1,PTYPELIST_1(T2) >
00049 #define PTYPELIST_3(T1,T2,T3) PtypeList<T1,PTYPELIST_2(T2,T3) >
00050 #define PTYPELIST_4(T1,T2,T3,T4) PtypeList<T1,PTYPELIST_3(T2,T3,T4) >
00051 #define PTYPELIST_5(T1,T2,T3,T4,T5) PtypeList<T1,PTYPELIST_4(T2,T3,T4,T5) >
00052 #define PTYPELIST_6(T1,T2,T3,T4,T5,T6)\
00053 PtypeList<T1,PTYPELIST_5(T2,T3,T4,T5,T6) >
00054 #define PTYPELIST_7(T1,T2,T3,T4,T5,T6,T7)\
00055 PtypeList<T1,PTYPELIST_6(T2,T3,T4,T5,T6,T7) >
00056 #define PTYPELIST_8(T1,T2,T3,T4,T5,T6,T7,T8)\
00057 PtypeList<T1,PTYPELIST_7(T2,T3,T4,T5,T6,T7,T8) >
00058 #define PTYPELIST_9(T1,T2,T3,T4,T5,T6,T7,T8,T9)\
00059 PtypeList<T1,PTYPELIST_8(T2,T3,T4,T5,T6,T7,T8,T9) >
00060 #define PTYPELIST_10(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10)\
00061 PtypeList<T1,PTYPELIST_9(T2,T3,T4,T5,T6,T7,T8,T9,T10) >
00062 #define PTYPELIST_11(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11)\
00063 PtypeList<T1,PTYPELIST_10(T2,T3,T4,T5,T6,T7,T8,T9,T10,T11) >
00064 #define PTYPELIST_12(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12)\
00065 PtypeList<T1,PTYPELIST_11(T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12) >
00066 #define PTYPELIST_13(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13)\
00067 PtypeList<T1,PTYPELIST_12(T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13) >
00068 #define PTYPELIST_14(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14)\
00069 PtypeList<T1,PTYPELIST_13(T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14) >
00070 #define PTYPELIST_15(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15)\
00071 PtypeList<T1,PTYPELIST_14(T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15) >
00072 #define PTYPELIST_16(T1,T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16)\
00073 PtypeList<T1,PTYPELIST_15(T2,T3,T4,T5,T6,T7,T8,T9,T10,T11,T12,T13,T14,T15,T16) >
00074
00075 typedef PTYPELIST_16(PTYPE_EMPTY,PTYPE_EDGE,PPAWN,PLANCE,PKNIGHT,PSILVER,PBISHOP,PROOK,GOLD,KING,PAWN,LANCE,KNIGHT,SILVER,BISHOP,ROOK) PtypeListAll;
00076
00077
00081 template<class PTList,Ptype T>
00082 struct IsMember;
00083
00084 template<Ptype T>
00085 struct IsMember<NullPtype,T>{
00086 static const bool value=false;
00087 };
00088 template<Ptype T>
00089 const bool IsMember<NullPtype,T>::value;
00090
00091 template<Ptype T1,Ptype T2,class U>
00092 struct IsMember<PtypeList<T2,U>,T1 >{
00093 static const bool value=IsMember<U,T1>::value;
00094 };
00095 template<Ptype T1,Ptype T2,class U>
00096 const bool IsMember<PtypeList<T2,U>,T1 >::value;
00097
00098 template<Ptype T,class U>
00099 struct IsMember<PtypeList<T,U>,T >{
00100 static const bool value=true;
00101 };
00102 template<Ptype T,class U>
00103 const bool IsMember<PtypeList<T,U>,T >::value;
00104
00108 template<class PTList,class CheckPtype> struct Filter;
00109
00110 template<class CheckPtype>
00111 struct Filter<NullPtype,CheckPtype>{
00112 typedef NullPtype Result;
00113 };
00114
00115 template<Ptype T,class U,bool condition,class CheckPtype> struct FilterDispatch;
00116
00117 template<Ptype T,class U,class CheckPtype>
00118 struct FilterDispatch<T,U,true,CheckPtype>{
00119 typedef PtypeList<T,typename Filter<U,CheckPtype>::Result> Result;
00120 };
00121
00122 template<Ptype T,class U,class CheckPtype>
00123 struct FilterDispatch<T,U,false,CheckPtype>{
00124 typedef typename Filter<U,CheckPtype>::Result Result;
00125 };
00126
00127 template<Ptype T,class U,class CheckPtype >
00128 struct Filter< PtypeList<T,U>,CheckPtype>{
00129 typedef typename FilterDispatch<T,U,CheckPtype::template PtypeToBool<T>::value,CheckPtype>::Result Result;
00130 };
00131
00135 struct CheckIsBasic{
00136 template<Ptype T>
00137 struct PtypeToBool{
00138 static const bool value=PtypeTraits<T>::isBasic;
00139 };
00140 };
00141
00142 typedef Filter<PtypeListAll,CheckIsBasic>::Result PtypeListIsBasic;
00146 template<unsigned int moveMask>
00147 struct CheckHasMoveMask{
00148 template<Ptype T>
00149 struct PtypeToBool{
00150 static const bool value=(PtypeTraits<T>::moveMask & moveMask)!=0;
00151 };
00152 };
00153 }
00154
00155 };
00156
00157 #endif
00158
00159
00160
00161
00162