/*---------------------------------------------------------------------------* Project: NintendoWare File: ut_TypeTraits.h Copyright (C)2009-2011 Nintendo/HAL Laboratory, Inc. All rights reserved. These coded instructions, statements, and computer programs contain proprietary information of Nintendo and/or its licensed developers and are protected by national and international copyright laws. They may not be disclosed to third parties or copied or duplicated in any form, in whole or in part, without the prior written consent of Nintendo. The content herein is highly confidential and should be handled accordingly. $Revision: 31311 $ *---------------------------------------------------------------------------*/ #ifndef NW_UT_TYPETRAITS_H_ #define NW_UT_TYPETRAITS_H_ namespace nw { namespace ut { /*---------------------------------------------------------------------------* internal *---------------------------------------------------------------------------*/ namespace internal { template struct integral_constant { static const TType value = Value; typedef TType value_type; }; typedef integral_constant TrueType; typedef integral_constant FalseType; template struct IfCond; template struct IfCond { typedef Then type; }; template struct IfCond { typedef Else type; }; struct True { char a; }; struct False { True a[2]; }; } /*---------------------------------------------------------------------------* declare_type_remove_template *---------------------------------------------------------------------------*/ #define NW_UT_DECLARE_TYPE_REMOVE_TEMPLATE_BASE_(name, ttype) \ template \ struct name \ { \ typedef ttype type; \ }; #define NW_UT_DECLARE_TYPE_REMOVE_TEMPLATE_(name, ttype, modifier) \ template \ struct name \ { \ typedef TType type; \ }; #define NW_UT_DECLARE_TYPE_REMOVE_TEMPLATE2_(name, ttype, modifier, ...) \ template \ struct name \ { \ typedef TType type; \ }; /*---------------------------------------------------------------------------* remove_bounds *---------------------------------------------------------------------------*/ NW_UT_DECLARE_TYPE_REMOVE_TEMPLATE_BASE_(remove_bounds, TType) NW_UT_DECLARE_TYPE_REMOVE_TEMPLATE_(remove_bounds, TType, TType[]) NW_UT_DECLARE_TYPE_REMOVE_TEMPLATE2_(remove_bounds, TType, TType[Size], TType, int Size) /*---------------------------------------------------------------------------* remove_const *---------------------------------------------------------------------------*/ NW_UT_DECLARE_TYPE_REMOVE_TEMPLATE_BASE_(remove_const, TType) NW_UT_DECLARE_TYPE_REMOVE_TEMPLATE_(remove_const, TType, const TType) /*---------------------------------------------------------------------------* remove_reference *---------------------------------------------------------------------------*/ NW_UT_DECLARE_TYPE_REMOVE_TEMPLATE_BASE_(remove_reference, TType) NW_UT_DECLARE_TYPE_REMOVE_TEMPLATE_(remove_reference, TType, TType&) /*---------------------------------------------------------------------------* remove_pointer *---------------------------------------------------------------------------*/ NW_UT_DECLARE_TYPE_REMOVE_TEMPLATE_BASE_(remove_pointer, TType) NW_UT_DECLARE_TYPE_REMOVE_TEMPLATE_(remove_pointer, TType, TType*) NW_UT_DECLARE_TYPE_REMOVE_TEMPLATE_(remove_pointer, TType, TType* const) /*---------------------------------------------------------------------------* Is_* *---------------------------------------------------------------------------*/ #define NW_TRAITS_SPEC0(Spec, Value) \ template <> \ struct Spec : public internal::integral_constant {}; #define NW_TRAITS_SPEC1(Spec, Value) \ template \ struct Spec : public internal::integral_constant {}; #define NW_TRAITS_SPEC2(Spec, Value) \ template \ struct Spec : public internal::integral_constant {}; #define NW_TRAITS_SPEC(Order, Traits, SpecialType, Value) \ NW_TRAITS_SPEC##Order(Traits, Value) \ NW_TRAITS_SPEC##Order(Traits, Value) \ NW_TRAITS_SPEC##Order(Traits, Value) \ NW_TRAITS_SPEC##Order(Traits, Value) /*---------------------------------------------------------------------------* IsArray *---------------------------------------------------------------------------*/ template struct IsArray : public internal::FalseType {}; template struct IsArray : public internal::TrueType {}; template struct IsArray : public internal::TrueType {}; /*---------------------------------------------------------------------------* IsPointer *---------------------------------------------------------------------------*/ template struct IsPointer : public internal::FalseType {}; NW_TRAITS_SPEC(1, IsPointer, Type*, true) /*---------------------------------------------------------------------------* IsSame *---------------------------------------------------------------------------*/ template struct IsSame : public internal::FalseType {}; template struct IsSame : public internal::TrueType {}; /*---------------------------------------------------------------------------* IsClass *---------------------------------------------------------------------------*/ template struct IsClass { template static internal::True test(int C::*); template static internal::False test(...); static const bool value = (sizeof(test(0)) == sizeof(internal::True)); }; /*---------------------------------------------------------------------------* _if *---------------------------------------------------------------------------*/ template struct If_ : public internal::IfCond {}; } // namespace ut } // namespace nw #endif // NW_UT_TYPETRAITS_H_