00001 #pragma ident "$Id: MainAdapter.hpp 2519 2011-03-02 04:29:28Z ocibu $"
00002
00008 #ifndef GPSTK_MAINADAPTER_HPP
00009 #define GPSTK_MAINADAPTER_HPP
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <iostream>
00035 #include "Exception.hpp"
00036
00037 namespace gpstk
00038 {
00039
00043
00048 template<typename T>
00049 class MainAdapter
00050 {
00051 public:
00052 virtual int run(int argc, char* argv[])
00053 {
00054 try
00055 {
00056 T program;
00057 if (!program.initialize(argc, argv, true)) return 0;
00058 if (!program.run()) return 1;
00059
00060 return 0;
00061 }
00062 catch(Exception& e)
00063 {
00064 std::cerr << "Problem: "<< e << std::endl;
00065 }
00066 catch(std::exception& e)
00067 {
00068 std::cerr << "Problem: "<< e.what() << std::endl;
00069 }
00070 catch(...)
00071 {
00072 std::cerr << "Problem: " << "Unknown error." << std::endl;
00073 }
00074
00075 return -1;
00076 }
00077
00078 };
00079
00080
00088
00089 #define GPSTK_START_MAIN(T) \
00090 int main(int argc, char* argv[]) \
00091 { \
00092 MainAdapter<T> M; \
00093 return M.run(argc,argv); \
00094 } \
00095
00096
00097
00098 }
00099
00100
00101 #endif // GPSTK_MAINADAPTER_HPP