Simple Application Framework  1
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Saf/App.h
Go to the documentation of this file.
00001 /*
00002     This file is part of Simple Application Framework (Saf) library.
00003     Copyright (C) 2010 - 2012 Ondrej Danek <ondrej.danek@gmail.com>
00004 
00005     This library is free software: you can redistribute it and/or modify
00006     it under the terms of the GNU General Public License as published 
00007     by the Free Software Foundation, either version 3 of the License, or
00008     (at your option) any later version.
00009 
00010     Saf is distributed in the hope that it will be useful,
00011     but WITHOUT ANY WARRANTY; without even the implied warranty of
00012     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013     GNU General Public License for more details.
00014 
00015     You should have received a copy of the GNU General Public License
00016     along with Simple Application Framework library. If not, 
00017     see <http://www.gnu.org/licenses/>.
00018 */
00019 
00028 #ifndef SAF_APP_H
00029 #define SAF_APP_H
00030 
00031 #include "Exception.h"
00032 #include "System/Log.h"
00033 #include "System/Environment.h"
00034 #include "Text/Format.h"
00035 #include "Globalization/Lang.h"
00036 
00040 #define SAF_IMPLEMENT_APP(APPCLASS) \
00041     int main (int argc, char **argv, char **envp)\
00042     {\
00043         try\
00044         {\
00045             Saf::System::Environment::Init(argc, argv, envp);\
00046             APPCLASS::Main();\
00047         }\
00048         catch (const Saf::Exception &e)\
00049         {\
00050             Saf::System::Log::Error(Saf::Text::Format(Globalization::Lang::Translate("Exception: {0}")) << e);\
00051             Saf::System::Environment::Exit(1);\
00052         }\
00053         catch (const std::exception &e)\
00054         {\
00055             Saf::System::Log::Error(Saf::Text::Format(Globalization::Lang::Translate("Exception: {0}")) << Saf::Text::String(e.what()));\
00056             Saf::System::Environment::Exit(1);\
00057         }\
00058         catch (...)\
00059         {\
00060             Saf::System::Log::Error(Saf::Globalization::Lang::Translate("Unknown exception caught - terminating application"));\
00061             Saf::System::Environment::Exit(1);\
00062         }\
00063         \
00064         return 0;\
00065     }
00066 
00067 #endif