cpp_photon/include/entrypoint.hpp

69 lines
1.7 KiB
C++
Raw Normal View History

2005-02-07 02:00:48 +00:00
//This file is part of Photon (http://photon.sourceforge.net)
//Copyright (C) 2004-2005 James Turk
//
// Author:
// James Turk (jpt2433@rit.edu)
//
// Version:
2005-07-19 01:31:37 +00:00
// $Id: entrypoint.hpp,v 1.6 2005/07/19 01:31:37 cozman Exp $
2005-02-07 02:00:48 +00:00
2005-02-13 22:12:02 +00:00
#ifndef PHOTON_ENTRYPOINT_HPP
#define PHOTON_ENTRYPOINT_HPP
2005-02-07 02:00:48 +00:00
2005-02-13 22:12:02 +00:00
#include "Log.hpp"
2005-02-07 02:00:48 +00:00
2005-07-19 01:31:37 +00:00
// Title: Entrypoint
// Macro: ENTRYPOINT
// A macro which is used to specify the class containing the entrypoint.
// For example, if the class PongGame is the class derived from <Application>
// which implements main, in the file defining PongGame it is important to
// include ENTRYPOINT(PongGame) so that the entry point becomes PongGame::main.
2005-02-07 02:00:48 +00:00
2005-03-15 19:21:51 +00:00
#define ENTRYPOINT(className) int main(int argc, const char** argv) \
2005-02-07 02:00:48 +00:00
{ return photon::mainclass<className>(argc,argv); }
namespace photon
{
2005-05-15 02:50:52 +00:00
// function which does all the work of ENTRYPOINT
2005-02-07 02:00:48 +00:00
template<class App>
2005-03-15 19:21:51 +00:00
int mainclass(int argc, const char** argv)
2005-02-07 02:00:48 +00:00
{
2005-07-19 01:31:37 +00:00
// logging of uncaught exceptions to console
2005-05-15 02:50:52 +00:00
Log log;
log.addSink(LogSinkPtr(new photon::ConsoleSink("out")));
2005-02-07 02:00:48 +00:00
try
{
2005-05-15 02:50:52 +00:00
App::setInitOptions(argv[0]);
2005-03-15 19:21:51 +00:00
App app;
2005-07-19 01:31:37 +00:00
// push arguments into StrVec
2005-02-07 02:00:48 +00:00
StrVec args;
for(int i=0; i < argc; ++i)
2005-03-15 19:21:51 +00:00
{
2005-02-07 02:00:48 +00:00
args.push_back(argv[i]);
2005-03-15 19:21:51 +00:00
}
2005-07-19 01:31:37 +00:00
// hand arguments to Application::main and return what main returns
return app.main(args);
2005-02-07 02:00:48 +00:00
}
2005-07-19 01:31:37 +00:00
catch(Exception &e) // log exceptions as errors (wow that's confusing)
2005-02-07 02:00:48 +00:00
{
2005-05-15 02:50:52 +00:00
log.error() << e;
2005-07-19 01:31:37 +00:00
return 1;
2005-02-07 02:00:48 +00:00
}
2005-07-19 01:31:37 +00:00
catch(Error &e) // log errors as critical errors
2005-02-07 02:00:48 +00:00
{
2005-05-15 02:50:52 +00:00
log.critical() << e;
2005-02-07 02:00:48 +00:00
return 1;
}
}
}
2005-02-13 22:12:02 +00:00
#endif //PHOTON_ENTRYPOINT_HPP