paramxx  1.0.7
Par.h
1 #ifndef PAR_H
2 #define PAR_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 #include <string>
30 #include <cstring>
31 #include <vector>
32 
33 using namespace std;
34 
35 #include "ParFileException.h"
36 #include "ParTxt.h"
37 
41 class Par {
42 
46  friend ostream& operator << ( ostream& os, Par& par ) {
47  par.print( os );
48  return os;
49  }
50 
54  friend ostream& operator << ( ostream& os, Par* par ) {
55  par->print( os );
56  return os;
57  }
58 
59 public:
60 
64  enum ParFileDelimit { DELIMIT=',' };
65 
69  enum ParType { PARNAME,
75  PARPROMPT
76  };
77 
78  enum ParamMode { AUTOS='a', BATCH='b', hIDDEN='h',
79  HIDDEN='H', QUERRY='q', LEARN='l' };
80 
81  enum ParamType { BOOLEAN='b', COMMENT='c', INTEGER='i',
82  REAL='r', STRING='s' };
83 
84  enum NumTokens { NUMTOKENS=7 };
85 
89  virtual ~Par( void ) { };
90 
94  Par( void ) { }
95 
96  Par( ParTxt& par );
97 
98  int check_value( const char* str ) const;
99 
105  virtual void plist( ostream& os ) const;
106 
110  string get_name( void ) const { return parameter[ PARNAME ]; }
111 
115  string get_mode( void ) const { return parameter[ PARMODE ]; }
116 
120  string get_prompt( void ) const { return parameter[ PARPROMPT ]; }
121 
122  string get_value( void ) const { return parameter[ PARVALUE ]; }
123 
124  static int my_tokenize( char* str, char* delimit, char*** tokens )
125  throw ( Exception );
126  static void delete_tokens( char** ptr );
127 
132  virtual bool pgetb( void ) const throw ( ParFileException );
134 
139  virtual double pgetd( void ) const throw ( ParFileException );
141 
142  virtual int pgeti( void ) const throw ( ParFileException );
144 
145  virtual long pgetl( void ) const throw ( ParFileException );
147 
148  virtual void pgetstr( char result[], size_t size ) const
149  throw ( ParFileException );
151 
152  virtual string pgetstring( void ) const throw ( ParFileException );
154 
158  virtual void print( ostream& os ) const;
159 
160  virtual void set_val( const string& str )
161  throw ( ParFileException, Exception );
162 
163  static bool is_indirrect( const string& str, char delimit=')' );
164 
165 protected:
166 
167  vector< string > parameter;
168 
169  void not_between_limits( char str[],
170  const char* left, const string& left_val,
171  const char* right, const string& right_val ) const;
172 
173 private:
174 
175  static int count_tokens( char* str, char* delimit ) throw ( Exception );
176  static void print_tokens( char* str, char** str_argv, ostream& os );
177  static char* save_string( char* str ) throw ( Exception );
178 
183  virtual void between_limits( const string& str ) const
184  throw ( ParFileException, Exception );
185 
190  void pget_wrong_type( char[], const char* ) const;
191 
192  virtual void validate( const string& ) const throw ( ParFileException );
194 
195 };
196 
197 #endif
virtual void print(ostream &os) const
only defined in StringPar
Definition: Par.cc:189
Definition: Par.h:41
Definition: ParFileException.h:33
Definition: Par.h:73
Definition: Par.h:71
STL namespace.
string get_prompt(void) const
Definition: Par.h:120
ParFileDelimit
Definition: Par.h:64
Definition: Par.h:70
string get_mode(void) const
Definition: Par.h:115
virtual ~Par(void)
Definition: Par.h:89
Par(void)
Definition: Par.h:94
ParType
Definition: Par.h:69
Definition: Par.h:72
A class to handle the Param library specific string manipulation.
Definition: ParTxt.h:31
Definition: Par.h:74
string get_name(void) const
Definition: Par.h:110