#include <iostream>
#include <loki/Singleton.h>
using namespace std;
using namespace Loki;
class runtime
{
public:
runtime() { cout << "runtime instantiated" << endl; start(); }
~runtime() { cout << "runtime destroyed" << endl; }
void start() { start_time_ = time(NULL); }
time_t get_running_time() { return time(NULL) - start_time_; }
private:
time_t start_time_;
};
typedef SingletonHolder
<
runtime, CreateUsingNew, SingletonWithLongevity
> running_time;
inline unsigned int GetLongevity(runtime*) {return 2;}
class logging
{
public:
logging() { cout << "logging instantiated" << endl; }
~logging()
{
cout << running_time::Instance().get_running_time()
<< ": " << "logging destroyed" << endl;
}
void log(const string& msg)
{
cout << running_time::Instance().get_running_time()
<< ": " << msg << endl;
}
private:
time_t start_time_;
};
typedef SingletonHolder
<
logging, CreateUsingNew, SingletonWithLongevity
> logger;
inline unsigned int GetLongevity(logging*) {return 1;}
int main()
{
logger::Instance();
running_time::Instance();
logging& l = logger::Instance();
l.log("hello");
return 0;
}