MainAdapter.hpp

Go to the documentation of this file.
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 //  This file is part of GPSTk, the GPS Toolkit.
00014 //
00015 //  The GPSTk is free software; you can redistribute it and/or modify
00016 //  it under the terms of the GNU Lesser General Public License as published
00017 //  by the Free Software Foundation; either version 2.1 of the License, or
00018 //  any later version.
00019 //
00020 //  The GPSTk is distributed in the hope that it will be useful,
00021 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00022 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00023 //  GNU Lesser General Public License for more details.
00024 //
00025 //  You should have received a copy of the GNU Lesser General Public
00026 //  License along with GPSTk; if not, write to the Free Software Foundation,
00027 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00028 //
00029 //  Wei Yan - Chinese Academy of Sciences . 2009, 2010, 2011
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    }; // End of class 'MainAdapter'
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 }  // End of namespace gpstk
00099 
00100 
00101 #endif   // GPSTK_MAINADAPTER_HPP

Generated on Tue May 22 03:30:59 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1