ParFile.h

00001 #ifndef PARFILE_H
00002 #define PARFILE_H
00003 
00004 // --8<--8<--8<--8<--
00005 //
00006 // Copyright (C) 2006 Smithsonian Astrophysical Observatory
00007 //
00008 // This file is part of paramxx
00009 //
00010 // paramxx is free software; you can redistribute it and/or
00011 // modify it under the terms of the GNU General Public License
00012 // as published by the Free Software Foundation; either version 2
00013 // of the License, or (at your option) any later version.
00014 //
00015 // paramxx is distributed in the hope that it will be useful,
00016 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00017 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00018 // GNU General Public License for more details.
00019 //
00020 // You should have received a copy of the GNU General Public License
00021 // along with this program; if not, write to the 
00022 //       Free Software Foundation, Inc. 
00023 //       51 Franklin Street, Fifth Floor
00024 //       Boston, MA  02110-1301, USA
00025 //
00026 // -->8-->8-->8-->8--
00027 
00028 #include <iostream>
00029 
00030 #include "Par.h"
00031 #include "ParFilename.h"
00032 
00033 using namespace std;
00034 
00038 class ParFile {
00039 
00043   friend ostream& operator << ( ostream& os, ParFile& parFile ) {
00044     parFile.print( os );
00045     return os;
00046   }
00047 
00051   friend ostream& operator << ( ostream& os, ParFile* parFile ) {
00052     parFile->print( os );
00053     return os;
00054   }
00055 
00056 public:
00057 
00061   ~ParFile( );
00062 
00066   ParFile( ) : parameters( NULL ) { }
00067 
00078   ParFile( int argc, char** argv, const char* file=NULL )
00079     throw ( ParFileException, Exception );
00080 
00085   string get_filename( ) { return parFilename.get_filename( ); }
00086 
00095   void init_ParFile( int argc, char** argv, const char* file=NULL )
00096     throw ( ParFileException, Exception );
00097 
00099   Par* get_par( const char* name ) const throw ( ParFileException );
00100 
00107   void print( ostream& os ) const;
00108 
00115   bool pgetb( const char* name ) const throw ( ParFileException );
00116 
00123   double pgetd( const char* name ) const throw ( ParFileException );
00124 
00131   int pgeti( const char* name ) const throw ( ParFileException );
00132 
00139   long pgetl( const char* name ) const throw ( ParFileException );
00140 
00148   void pgetstr( const char* name, char result[], size_t size )
00149      const throw ( ParFileException );
00150 
00157   string pgetstring( const char* name ) const throw ( ParFileException );
00158 
00160   void pget( const char* name, bool& result ) const throw ( ParFileException );
00161 
00163   void pget( const char* name, double& result ) const
00164     throw ( ParFileException );
00165 
00167   void pget( const char* name, int& result ) const throw ( ParFileException );
00168 
00170   void pget( const char* name, long& result ) const throw ( ParFileException );
00171 
00173   void pget( const char* name, char result[], size_t ) const
00174     throw ( ParFileException );
00175 
00177   void pget( const char* name, string& rult ) const throw ( ParFileException );
00178 
00184   int traverse( int (*fct)( Par* ) ) const;
00185 
00186   static int is_blank( const char* str );
00187 
00188   static int is_comment( const char* str, char delimit='#' );
00189 
00190 private:
00191 
00192   // Whether or not to querry the user, useful for interactive or batch mode.
00193   bool          return_on_error;
00194 
00195   // To look for the parameter file
00196   ParFilename parFilename;
00197 
00198   // To hold the parameters in the paramter file parFilename.
00199   Par** parameters;
00200 
00201   void get_mode_of_parameter_file( int argc, char** argv )
00202     throw ( ParFileException );
00203 
00204   bool is_duplicate_cmdline_args( int argc, char** argv )
00205     throw( ParFileException );
00206 
00207   bool is_parlist( string& cmdline_name, string& cmdline_value );
00208 
00209   void querry_user( Par* par, char* str );
00210 
00214   void read_ParFile( int argc, char** argv, const char* file )
00215     throw ( ParFileException );
00216 
00217   void setpar( char* ) throw ( ParFileException, Exception );
00218 
00219   void set_return_on_error( const string& str );
00220 
00224   Par* search_name( const char* str ) const
00225     throw ( ParFileException );
00226 
00230   ParFile( const ParFile& pf );
00231 
00235   ParFile& operator = ( const ParFile& pf );
00236 
00237 };
00238 
00249 #endif

Generated on Thu Oct 2 17:54:19 2008 for paramxx by  doxygen 1.5.6