#include #include #include #include #include "JLang/JTemplate.hh" #include "JLang/JTypeList.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { struct __A__ : public std::string { __A__() {} __A__(const char* buffer) : std::string(buffer) {} }; struct __B__ : public __A__ { __B__() {} __B__(const char* buffer) : __A__(buffer) {} }; struct __C__ : public __B__ { __C__() {} __C__(const char* buffer) : __B__(buffer) {} }; } /** * \file * * Example program to test JLANG::JTemplate class. * \author mdejong */ int main(int argc, char **argv) { using namespace std; int debug; try { JParser<> zap("Example program to test object referencing."); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } using namespace JPP; { JTemplate object; object = string("aap"); object.set(string("noot")); // exact match object.set("mies"); // implicit cast through std::string object.get() += " says "; // exact match //object.get(); // gives compiler error object->append("\"hello world\""); // smart pointer cout << object << endl; } { class JTemplate_t : public JTemplate::typelist> {}; JTemplate_t object; object.get() = "abc"; // exact match object.get() = -1; // exact match object.get() = -0.99; // exact match //object.set("hello world"); // gives compiler error object.set(string("aap noot mies")); // exact match object.set("hello world"); // allow cast object.set(777); // exact match object.set(123.456f); // exact match //object.set(123.456); // gives compiler error (argument is double) cout << object << endl; } { JTemplate::typelist> object; object.get<__A__>() = "a"; // exact match object.get<__B__>() = "b"; // exact match object.get<__C__>() = "c"; // exact match cout << object.get<__C__>() // exact match << " == " << object.get<__A__, true>() // first match << endl; } }