BoolPar.cc
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025 #include <stdlib.h>
00026
00027 #include "BoolPar.h"
00028
00029 static const char* yep[] = { "yes", "y", "1", NULL };
00030 static const char* nope[] = { "no", "n", "0", NULL };
00031
00032 BoolPar::BoolPar( ParTxt& par ) throw ( ParFileException ) : Par( par ) {
00033
00034 try {
00035
00036 validate( parameter[ PARMINIMUM ] );
00037
00038 validate( parameter[ PARMAXIMUM ] );
00039
00040 validate( parameter[ PARVALUE ] );
00041
00042 } catch( ParFileException& pfe ) {
00043 throw;
00044 }
00045
00046 }
00047
00048 void BoolPar::between_limits( const string& str ) const
00049 throw ( ParFileException, Exception ) {
00050
00051 try {
00052 validate( str );
00053 } catch( ParFileException& pfe ) {
00054 throw;
00055 }
00056
00057 }
00058
00059 bool BoolPar::pgetb( void ) const throw ( ParFileException ) {
00060
00061 size_t ii = 0;
00062 while( yep[ ii ] )
00063 if ( parameter[ PARVALUE ] == yep[ ii++ ] )
00064 return true;
00065
00066 ii = 0;
00067 while( nope[ ii ] ) {
00068 if ( parameter[ PARVALUE ] == nope[ ii++ ] ) {
00069 return false;
00070 }
00071 }
00072
00073 throw ParFileException( "BoolPar::pgetb( ) : Unable to get the value "
00074 "for parameter " + parameter[ PARNAME ] );
00075
00076 }
00077
00078 void BoolPar::set_val( const string& str ) throw ( ParFileException,
00079 Exception ) {
00080
00081 try {
00082 validate( str );
00083 parameter[ PARVALUE ] = str;
00084 } catch( ParFileException& pfe ) {
00085 throw;
00086 } catch( Exception& e ) {
00087 throw;
00088 }
00089
00090 }
00091
00092 void BoolPar::validate( const string& str ) const throw ( ParFileException ) {
00093
00094 if ( Par::is_indirrect( str ) )
00095 return;
00096
00097 if ( "" == str )
00098 return;
00099
00100 size_t ii = 0;
00101 while( yep[ ii ] )
00102 if ( str == yep[ ii++ ] )
00103 return;
00104
00105 ii = 0;
00106 while( nope[ ii ] )
00107 if ( str == nope[ ii++ ] )
00108 return;
00109
00110 throw ParFileException( "BoolPar::validate( " + str + " ) : Ivalid arg\n" );
00111
00112 }