BasicFramework.cpp

Go to the documentation of this file.
00001 #pragma ident "$Id: BasicFramework.cpp 2459 2010-09-08 03:35:51Z yanweignss $"
00002 
00008 //============================================================================
00009 //
00010 //  This file is part of GPSTk, the GPS Toolkit.
00011 //
00012 //  The GPSTk is free software; you can redistribute it and/or modify
00013 //  it under the terms of the GNU Lesser General Public License as published
00014 //  by the Free Software Foundation; either version 2.1 of the License, or
00015 //  any later version.
00016 //
00017 //  The GPSTk is distributed in the hope that it will be useful,
00018 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00019 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00020 //  GNU Lesser General Public License for more details.
00021 //
00022 //  You should have received a copy of the GNU Lesser General Public
00023 //  License along with GPSTk; if not, write to the Free Software Foundation,
00024 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00025 //
00026 //  Copyright 2004, The University of Texas at Austin
00027 //
00028 //============================================================================
00029 
00030 //============================================================================
00031 //
00032 //This software developed by Applied Research Laboratories at the University of
00033 //Texas at Austin, under contract to an agency or agencies within the U.S.
00034 //Department of Defense. The U.S. Government retains all rights to use,
00035 //duplicate, distribute, disclose, or release this software.
00036 //
00037 //Pursuant to DoD Directive 523024
00038 //
00039 // DISTRIBUTION STATEMENT A: This software has been approved for public
00040 //                           release, distribution is unlimited.
00041 //
00042 //=============================================================================
00043 
00044 
00045 #include "Exception.hpp"
00046 #include "BasicFramework.hpp"
00047 #include "StringUtils.hpp"
00048 
00049 
00050 namespace gpstk
00051 {
00052 
00053    using namespace std;
00054 
00055 
00056    BasicFramework :: BasicFramework( const string& applName,
00057                                      const string& applDesc )
00058       throw()
00059          : debugLevel(0),
00060            verboseLevel(0),
00061            argv0(applName),
00062            appDesc(applDesc),
00063            debugOption('d', "debug", "Increase debug level"),
00064            verboseOption('v', "verbose", "Increase verbosity"),
00065            helpOption('h', "help", "Print help usage")
00066    {} // End of constructor 'BasicFramework::BasicFramework()'
00067 
00068 
00069 
00070    bool BasicFramework :: initialize( int argc,
00071                                       char *argv[],
00072                                       bool pretty )
00073       throw()
00074    {
00075 
00076          // Creating the parser here ensures that all the subclasses'
00077          // option objects are constructed.
00078       CommandOptionParser cop(appDesc);
00079 
00080       cop.parseOptions(argc, argv);
00081 
00082       if (helpOption.getCount())
00083       {
00084          cop.displayUsage(cerr, pretty);
00085          return false;
00086       }
00087 
00088       if (cop.hasErrors())
00089       {
00090          cop.dumpErrors(cerr);
00091          cop.displayUsage(cerr, pretty);
00092          return false;
00093       }
00094 
00095       debugLevel = debugOption.getCount();
00096       verboseLevel = verboseOption.getCount();
00097 
00098       return true;
00099 
00100    }  // End of method 'BasicFramework::initialize()'
00101 
00102        
00103    bool BasicFramework :: initialize( std::string cmdLine,
00104                                       bool pretty )
00105       throw()
00106    {
00107       std::vector<std::string> vArgs;
00108       vArgs.clear();
00109 
00110       std::string cmd(cmdLine);
00111       while(cmd.length())
00112       {
00113          vArgs.push_back(StringUtils::stripFirstWord(cmd));
00114       }
00115 
00116       int argc = vArgs.size();
00117       char** argv = new char*[argc];
00118       if(!argv)
00119       {
00120          return false;
00121       }
00122 
00123       for(int i=0; i<argc; i++)
00124       {
00125          argv[i] = &vArgs[i][0];
00126       }
00127 
00128       bool state = initialize(argc, argv, pretty);
00129 
00130       // delete memory *char[]
00131       delete[] argv;
00132 
00133       return state;
00134 
00135    }  // End of method 'BasicFramework::initialize()'
00136 
00137 
00138    bool BasicFramework :: run()
00139       throw()
00140    {
00141 
00142       try
00143       {
00144          completeProcessing();
00145       }
00146       catch (Exception& exc)
00147       {
00148          cerr << exc;
00149          return false;
00150       }
00151       catch (...)
00152       {
00153          cerr << "Caught unknown exception" << endl;
00154          return false;
00155       }
00156 
00157       shutDown();
00158 
00159       return true;
00160 
00161    }  // End of method 'BasicFramework::run()'
00162 
00163 
00164 
00165    void BasicFramework :: completeProcessing()
00166    {
00167       additionalSetup();
00168 
00169       spinUp();
00170 
00171       process();
00172 
00173    }  // End of method 'BasicFramework::completeProcessing()'
00174 
00175 
00176 }  // End of namespace gpstk

Generated on Fri Feb 3 03:30:58 2012 for GPS ToolKit Software Library by  doxygen 1.3.9.1