#include #include #include "JLang/JSingleton.hh" #include "Jeep/JParser.hh" #include "Jeep/JMessage.hh" namespace { struct __A__ : public JLANG::JSingleton<__A__> { __A__() { std::cout << "__A__()"; ++count; } ~__A__() { std::cout << "~__A__()" << std::endl; } static int count; }; int __A__::count = 0; } /** * \file * * Example program to test JLANG::JSingleton class. * \author mdejong */ int main(int argc, char **argv) { using namespace std; int debug; try { JParser<> zap("Example program to test singleton."); zap['d'] = make_field(debug) = 3; zap(argc, argv); } catch(const exception &error) { FATAL(error.what() << endl); } using namespace JPP; cout << "Test of getInstance()" << endl; for (int i = 0; i != 5; ++i) { cout << "[" << i << "]" << ' ' << flush; __A__& a = __A__::getInstance(); cout << ' ' << a.count; cout << endl; } cout << "Test of constructor()" << endl; for (int i = 0; i != 5; ++i) { cout << "[" << i << "]" << ' ' << flush; __A__ a; cout << ' ' << a.count << ' '; } cout << "end of main" << endl; }