#ifndef __JLANG__JBASECLASS__ #define __JLANG__JBASECLASS__ #include "JLang/JConversion.hh" #include "JLang/JTypeList.hh" /** * \file * * Auxiliary class to identify common base class in type list. * \author mdejong */ namespace JLANG {} namespace JPP { using namespace JLANG; } namespace JLANG { /** * Template class to test for polymorphism. */ template struct JBaseType_t { static const bool is_base = (JConversion::is_derived); //!< true if JBase_t is a base class of JDerived_t; else false }; /** * Template class to test for polymorphism. * * The class recursively tests whether both * - JBaseType::is_base; and * - JBaseType::is_base * evaluate to true. */ template struct JBaseType_t< JBase_t, JTypeList > { static const bool is_base = (JBaseType_t::is_base && JBaseType_t::is_base); }; /** * Terminator class of recursive JBaseType_t class. */ template struct JBaseType_t< JBase_t, JTypeList > { static const bool is_base = (JBaseType_t::is_base); }; /** * Template class to identify common base class. * * The parameter data_type corresponds to the common base class. */ template::is_base && JBaseType_t::is_base) > struct JBaseType { typedef JBase_t data_type; }; /** * Resursive scan for base class. */ template // downstream data type of downstream type list struct JBaseType, false> { typedef typename JBaseType, JTail_t>::data_type data_type; }; /** * Terminination class of resursive JBaseType class. */ template // upstream data type of downstream type list struct JBaseType, false> { typedef typename JBaseType::data_type data_type; }; /** * Template definition of class to look for base class in type list. * * The type of the base class is defined as data_type. */ template struct JBaseClass { typedef T data_type; }; /** * Template specialisation of class to look for base class in type list. */ template struct JBaseClass< JTypeList > { typedef typename JBaseType::data_type data_type; }; } #endif