paramxx  1.0.7
ParFile.h
1 #ifndef PARFILE_H
2 #define PARFILE_H
3 
4 // --8<--8<--8<--8<--
5 //
6 // Copyright (C) 2006 Smithsonian Astrophysical Observatory
7 //
8 // This file is part of paramxx
9 //
10 // paramxx is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU General Public License
12 // as published by the Free Software Foundation; either version 2
13 // of the License, or (at your option) any later version.
14 //
15 // paramxx is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 // GNU General Public License for more details.
19 //
20 // You should have received a copy of the GNU General Public License
21 // along with this program; if not, write to the
22 // Free Software Foundation, Inc.
23 // 51 Franklin Street, Fifth Floor
24 // Boston, MA 02110-1301, USA
25 //
26 // -->8-->8-->8-->8--
27 
28 #include <iostream>
29 
30 #include "Par.h"
31 #include "ParFilename.h"
32 
33 using namespace std;
34 
38 class ParFile {
39 
43  friend ostream& operator << ( ostream& os, ParFile& parFile ) {
44  parFile.print( os );
45  return os;
46  }
47 
51  friend ostream& operator << ( ostream& os, ParFile* parFile ) {
52  parFile->print( os );
53  return os;
54  }
55 
56 public:
57 
61  ~ParFile( );
62 
66  ParFile( ) : parameters( NULL ) { }
67 
78  ParFile( int argc, char** argv, const char* file=NULL )
79  throw ( ParFileException, Exception );
80 
85  string get_filename( ) { return parFilename.get_filename( ); }
86 
95  void init_ParFile( int argc, char** argv, const char* file=NULL )
96  throw ( ParFileException, Exception );
97 
99  Par* get_par( const char* name ) const throw ( ParFileException );
100 
107  void print( ostream& os ) const;
108 
115  bool pgetb( const char* name ) const throw ( ParFileException );
116 
123  double pgetd( const char* name ) const throw ( ParFileException );
124 
131  int pgeti( const char* name ) const throw ( ParFileException );
132 
139  long pgetl( const char* name ) const throw ( ParFileException );
140 
148  void pgetstr( const char* name, char result[], size_t size )
149  const throw ( ParFileException );
150 
157  string pgetstring( const char* name ) const throw ( ParFileException );
158 
160  void pget( const char* name, bool& result ) const throw ( ParFileException );
161 
163  void pget( const char* name, double& result ) const
164  throw ( ParFileException );
165 
167  void pget( const char* name, int& result ) const throw ( ParFileException );
168 
170  void pget( const char* name, long& result ) const throw ( ParFileException );
171 
173  void pget( const char* name, char result[], size_t ) const
174  throw ( ParFileException );
175 
177  void pget( const char* name, string& rult ) const throw ( ParFileException );
178 
184  int traverse( int (*fct)( Par* ) ) const;
185 
186  static int is_blank( const char* str );
187 
188  static int is_comment( const char* str, char delimit='#' );
189 
190 private:
191 
192  // Whether or not to querry the user, useful for interactive or batch mode.
193  bool return_on_error;
194 
195  // To look for the parameter file
196  ParFilename parFilename;
197 
198  // To hold the parameters in the paramter file parFilename.
199  Par** parameters;
200 
201  void get_mode_of_parameter_file( int argc, char** argv )
202  throw ( ParFileException );
203 
204  bool is_duplicate_cmdline_args( int argc, char** argv )
205  throw( ParFileException );
206 
207  bool is_parlist( string& cmdline_name, string& cmdline_value );
208 
209  void querry_user( Par* par, char* str );
210 
214  void read_ParFile( int argc, char** argv, const char* file )
215  throw ( ParFileException );
216 
217  void setpar( char* ) throw ( ParFileException, Exception );
218 
219  void set_return_on_error( const string& str );
220 
224  Par* search_name( const char* str ) const
225  throw ( ParFileException );
226 
230  ParFile( const ParFile& pf );
231 
235  ParFile& operator = ( const ParFile& pf );
236 
237 };
238 
249 #endif
Definition: Par.h:41
Definition: ParFileException.h:33
void print(ostream &os) const
Definition: ParFile.cc:370
STL namespace.
string get_filename()
Definition: ParFile.h:85
ParFile()
Definition: ParFile.h:66
Definition: ParFilename.h:44
Definition: ParFile.h:38