GpCoreTools/CoreApplication.h
Go to the documentation of this file.
00001 /***************************************************************************
00002 **
00003 **  This file is part of GpCoreTools.
00004 **
00005 **  This file may be distributed and/or modified under the terms of the
00006 **  GNU General Public License version 2 or 3 as published by the Free
00007 **  Software Foundation and appearing in the file LICENSE.GPL included
00008 **  in the packaging of this file.
00009 **
00010 **  This file is distributed in the hope that it will be useful, but WITHOUT
00011 **  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00012 **  FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
00013 **  more details.
00014 **
00015 **  You should have received a copy of the GNU General Public License
00016 **  along with this program. If not, see <http://www.gnu.org/licenses/>.
00017 **
00018 **  See http://www.geopsy.org for more information.
00019 **
00020 **  Created: 2009-07-01
00021 **  Authors:
00022 **    Marc Wathelet
00023 **    Marc Wathelet (LGIT, Grenoble, France)
00024 **
00025 ***************************************************************************/
00026 
00027 #ifndef COREAPPLICATION_H
00028 #define COREAPPLICATION_H
00029 
00030 #include <string>
00031 #include <errno.h>
00032 
00033 #include "GpCoreToolsDLLExport.h"
00034 
00035   namespace GpCoreTools {
00036 
00037   class ApplicationHelp;
00038 
00039   class GPCORETOOLS_EXPORT CoreApplication
00040   {
00041   public:
00042     CoreApplication(int & argc, char ** argv, ApplicationHelp * ( *help) (), bool reportBugs=true);
00043     virtual ~CoreApplication();
00044 
00045     virtual void close() {}
00046 
00047     static std::string version();
00048     static std::string version(const char * item);
00049     static std::string authors();
00050     static void exit(int exitCode);
00051 
00052     static bool checkOptionArg(int& i, int argc, char ** argv, bool mandatory=true);
00053     void showHelp(int& i, int argc, char ** argv, ApplicationHelp * ( *help) ());
00054 
00055     static CoreApplication * instance() {return _self;}
00056 
00057     static std::string getStdin();
00058     static std::string backTrace();
00059     static std::string backTraceBug();
00060     static void osSignal(int sigNum);
00061     int terminalRows() const;
00062     int terminalCols() const;
00063     const char * applicationName() const {return _applicationName.data();}
00064     void initInternalDebugger();
00065   protected:
00066     void setHelp(ApplicationHelp * h);
00067   private:
00068     void terminalSize() const;
00069     void reportBug();
00070 
00071     static CoreApplication * _self;
00072     std::string _applicationName;
00073     mutable int _terminalCols, _terminalRows;
00074     bool _reportBugs;
00075   };
00076 
00077   template <typename T>
00078   inline void unused(const T& x) {(void)x;}
00079 
00080 #define UNUSED(x) unused(x)
00081 
00082 } // namespace GpCoreTools
00083 
00084 #endif // COREAPPLICATION_H
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Defines