RealPar.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 <suplibxx/str.h>
00028
00029 #include "RealPar.h"
00030 #include "ParFile.h"
00031
00032 RealPar::RealPar( ParTxt& par ) throw ( ParFileException, Exception ) :
00033 Par( par ) {
00034
00035 try {
00036
00037 validate( parameter[ PARMINIMUM ] );
00038
00039 validate( parameter[ PARMAXIMUM ] );
00040
00041 validate( parameter[ PARVALUE ] );
00042
00043 between_limits( parameter[ PARVALUE ] );
00044
00045 } catch( ParFileException& pfe ) {
00046
00047 throw;
00048
00049 } catch( Exception& e ) {
00050
00051 throw;
00052
00053 }
00054
00055 }
00056
00057 void RealPar::between_limits( const string& str ) const
00058 throw ( ParFileException, Exception ) {
00059
00060 try {
00061
00062
00063 if ( is_indirrect( str ) )
00064 return;
00065
00066 char msg[ 256 ];
00067
00068
00069 if ( "" != parameter[ PARMINIMUM ] ) {
00070 double min =
00071 suplib::str2d( (const char*) parameter[ PARMINIMUM ].c_str( ) );
00072 double val = suplib::str2d( (const char*) str.c_str( ) );
00073 if ( val < min ) {
00074 not_between_limits( msg, "min", parameter[ PARMINIMUM ], "val",
00075 str );
00076 throw ParFileException( msg );
00077 }
00078 }
00079
00080
00081 if ( "" != parameter[ PARMAXIMUM ] ) {
00082 double max =
00083 suplib::str2d( (const char*) parameter[ PARMAXIMUM ].c_str( ) );
00084 double val = suplib::str2d( (const char*) str.c_str( ) );
00085 if ( val > max ) {
00086 not_between_limits( msg, "val", str, "max",
00087 parameter[ PARMAXIMUM ] );
00088 throw ParFileException( msg );
00089 }
00090 }
00091
00092 } catch( ParFileException& pfe ) {
00093 throw;
00094 } catch( Exception& e ) {
00095 throw;
00096 }
00097
00098 }
00099
00100 void RealPar::set_val( const string& str )
00101 throw ( ParFileException, Exception ) {
00102
00103 try {
00104
00105 string tmp( str );
00106
00107 validate( tmp );
00108
00109 between_limits( tmp );
00110
00111 parameter[ PARVALUE ] = str;
00112
00113 } catch ( ParFileException& pfe ) {
00114
00115 throw;
00116
00117 } catch( Exception& e ) {
00118
00119 throw;
00120
00121 }
00122
00123 }
00124
00125 void RealPar::validate( const string& str ) const throw ( ParFileException ) {
00126
00127 try {
00128
00129 if ( "" == str )
00130 return;
00131
00132 if ( Par::is_indirrect( str ) )
00133 return;
00134
00135 const char* ptr = (const char*) str.c_str( );
00136
00137 double result = suplib::str2d( ptr );
00138
00139 } catch( Exception& e ) {
00140
00141 string msg = e.get_message( );
00142 throw ParFileException( msg );
00143
00144 }
00145
00146 }