#include #include #include "JLang/JBaseClass.hh" #include "JLang/JTypeList.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { struct __A__ { static char get() { return 'A'; } }; struct __B__ : public __A__ { static char get() { return 'B'; } }; struct __C__ : public __A__ { static char get() { return 'C'; } }; struct __D__ : public __A__ { static char get() { return 'D'; } }; } /** * \file * * Example program to test JLANG::JBaseClass class. * \author mdejong */ int main(int argc, char **argv) { using namespace std; int debug; try { JParser<> zap("Example program to test selection of base class."); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } using namespace JPP; typedef JTYPELIST<__A__, __B__, __C__, __D__>::typelist typelistABCD; typedef JTYPELIST<__B__, __A__, __C__, __D__>::typelist typelistBACD; typedef JTYPELIST<__B__, __C__, __A__, __D__>::typelist typelistBCAD; typedef JTYPELIST<__B__, __C__, __D__, __A__>::typelist typelistBCDA; DEBUG("A,B,C,D <- A? " << (JBaseType_t<__A__, typelistABCD>::is_base) << endl); DEBUG("A,B,C,D <- B? " << (JBaseType_t<__B__, typelistABCD>::is_base) << endl); DEBUG("A,B,C,D -> " << JBaseClass::data_type::get() << endl); DEBUG("B,A,C,D -> " << JBaseClass::data_type::get() << endl); DEBUG("B,C,A,D -> " << JBaseClass::data_type::get() << endl); DEBUG("B,C,D,A -> " << JBaseClass::data_type::get() << endl); DEBUG("B -> " << JBaseClass< JTypeList<__B__> >::data_type::get() << endl); ASSERT(JBaseClass::data_type::get() == __A__::get()); ASSERT(JBaseClass::data_type::get() == __A__::get()); ASSERT(JBaseClass::data_type::get() == __A__::get()); ASSERT(JBaseClass::data_type::get() == __A__::get()); ASSERT(JBaseClass< JTypeList<__B__> >::data_type::get() == __B__::get()); /* typedef JTYPELIST<__B__, __C__, __D__>::typelist typelist; typedef JBaseClass::data_type data_type; // will give compiler error (as should be) */ return 0; }