InOutFramework.hpp

Go to the documentation of this file.
00001 #pragma ident "$Id: InOutFramework.hpp 1363 2008-08-21 02:55:57Z ocibu $"
00002 
00009 #ifndef INOUTFRAMEWORK_HPP
00010 #define INOUTFRAMEWORK_HPP
00011 
00012 //============================================================================
00013 //
00014 //  This file is part of GPSTk, the GPS Toolkit.
00015 //
00016 //  The GPSTk is free software; you can redistribute it and/or modify
00017 //  it under the terms of the GNU Lesser General Public License as published
00018 //  by the Free Software Foundation; either version 2.1 of the License, or
00019 //  any later version.
00020 //
00021 //  The GPSTk is distributed in the hope that it will be useful,
00022 //  but WITHOUT ANY WARRANTY; without even the implied warranty of
00023 //  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00024 //  GNU Lesser General Public License for more details.
00025 //
00026 //  You should have received a copy of the GNU Lesser General Public
00027 //  License along with GPSTk; if not, write to the Free Software Foundation,
00028 //  Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00029 //
00030 //  Copyright 2004, The University of Texas at Austin
00031 //
00032 //============================================================================
00033 
00034 //============================================================================
00035 //
00036 //This software developed by Applied Research Laboratories at the University of
00037 //Texas at Austin, under contract to an agency or agencies within the U.S.
00038 //Department of Defense. The U.S. Government retains all rights to use,
00039 //duplicate, distribute, disclose, or release this software.
00040 //
00041 //Pursuant to DoD Directive 523024
00042 //
00043 // DISTRIBUTION STATEMENT A: This software has been approved for public
00044 //                           release, distribution is unlimited.
00045 //
00046 //=============================================================================
00047 
00048 
00049 #include "LoopedFramework.hpp"
00050 
00051 
00052 namespace gpstk
00053 {
00054 
00057 
00070    template<class IType, class OType>
00071    class InOutFramework : public LoopedFramework
00072    {
00073    public:
00074 
00075 
00082       InOutFramework( const std::string& applName,
00083                       const std::string& applDesc )
00084          throw()
00085          : LoopedFramework(applName, applDesc)
00086       {};
00087 
00088 
00090       virtual ~InOutFramework() {};
00091 
00092 
00093       bool initialize( int argc,
00094                        char *argv[],
00095                        bool pretty = true )
00096          throw()
00097       {
00098          using std::ios;
00099 
00100          CommandOptionWithAnyArg
00101             inputOpt('i', "input",
00102                      "A file to take the input from. The default is stdin."),
00103             outputOpt('o', "output",
00104                       "A file to receive the output. The default is stdout.");
00105 
00106          if (!LoopedFramework::initialize(argc, argv, pretty))
00107             return false;
00108 
00109          if (inputOpt.getCount())
00110             inputFn = inputOpt.getValue()[0];
00111 
00112 
00113          if (inputFn=="-" || inputFn=="")
00114          {
00115             input.copyfmt(std::cin);
00116             input.clear(std::cin.rdstate());
00117             input.ios::rdbuf(std::cin.rdbuf());
00118             inputFn = "<stdin>";
00119          }
00120          else
00121          {
00122             input.open(inputFn.c_str(), std::ios::in);
00123          }
00124 
00125 
00126          if (!input)
00127          {
00128             std::cerr << "Could not open: " << inputFn << std::endl;
00129             return false;
00130          }
00131 
00132          if (outputOpt.getCount())
00133             outputFn = outputOpt.getValue()[0];
00134 
00135          if (outputFn=="-" || outputFn=="")
00136          {
00137             output.copyfmt(std::cout);
00138             output.clear(std::cout.rdstate());
00139             output.ios::rdbuf(std::cout.rdbuf());
00140             outputFn = "<stdout>";
00141          }
00142          else
00143          {
00144             output.open(outputFn.c_str(), std::ios::out);
00145          }
00146 
00147          if (!output)
00148          {
00149             std::cerr << "Could not open: " << outputFn << std::endl;
00150             return false;
00151          }
00152 
00153          if (debugLevel)
00154             std::cout << "Sending output to " << outputFn << std::endl
00155                       << "Reading input from " << inputFn << std::endl;
00156 
00157          return true;
00158       }  // End of method 'InOutFramework::initialize()'
00159 
00160 
00161       IType input;
00162 
00163       OType output;
00164 
00165       std::string inputFn, outputFn;
00166 
00167 
00168    private:
00169 
00170 
00171       // Do not allow the use of the default constructor.
00172       InOutFramework();
00173 
00174 
00175    }; // End of class 'InOutFramework'
00176 
00178 
00179 }  // End of namespace gpstk
00180 #endif   // INOUTFRAMEWORK_HPP

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