int TString::ToInt() const { if( !data ) return 0; int i; if( sscanf( data, "%d", &i ) == 1 ) return i; throw EConvertError( "Failed to convert string '" + *this + "' to an integer." ); }
double TString::ToDouble() const { if( !data ) return 0.0; double d; if( sscanf( data, "%le", &d ) == 1 ) return d; if( sscanf( data, "%lf", &d ) == 1 ) return d; if( sscanf( data, "%lg", &d ) == 1 ) return d; throw EConvertError( "Failed to convert string '" + *this + "' to a double." ); }
void tElipse::cargar(ifstream& archivo)throw (EConvertError){ string id; int aux; archivo >> id; archivo >> id;//Xini try{Xini = StrToInt(id.c_str());} catch(const EConvertError &E){ string a; getline(archivo,a); throw EConvertError("Error de lectura Xini ELIPSE");} archivo >> id;archivo >> id;//Yini try{Yini = StrToInt(id.c_str());} catch(const EConvertError &E){ string a; getline(archivo,a); throw EConvertError("Error de lectura Yini ELIPSE");} archivo >> id;archivo >> id;//Xfin try{Xfin = StrToInt(id.c_str());} catch(const EConvertError &E){ string a; getline(archivo,a); throw EConvertError("Error de lectura Xfin ELIPSE");} archivo >> id;archivo >> id;//Yfin try{Yfin = StrToInt(id.c_str());} catch(const EConvertError &E){ string a; getline(archivo,a); throw EConvertError("Error de lectura Yfin ELIPSE");} archivo >> id;archivo >> id;//Grosor try{grosor = StrToInt(id.c_str());} catch(const EConvertError &E){ string a; getline(archivo,a); throw EConvertError("Error de lectura Grosor ELIPSE");} archivo >> id;archivo >> id;//Color try{(int)color = StrToInt(id.c_str());} catch(const EConvertError &E){ string a; getline(archivo,a); throw EConvertError("Error de lectura Color ELIPSE");} archivo >> id;archivo >> id;//Relleno try{relleno = StrToInt(id.c_str());} catch(const EConvertError &E){throw EConvertError("Error de lectura Relleno ELIPSE");} }
//--------------------------------------------------------------------------- static void ConvertError(intptr_t ErrorID) { UnicodeString Msg = FMTLOAD(ErrorID, 0); throw EConvertError(Msg); }
void CTranscription::LoadMode(const char *filename) { int entries; size_t head, i; long l, r2tentries, t2rentries; FILE *f; char *b, *origb=0; bool version1; #ifdef SPY printf("CTranscription::LoadMode\n"); #endif try { f=fopen(filename, "r"); if(!f) throw EFileNotFound("Cannot load "+string(filename)); fseek(f, 0, SEEK_END); l=ftell(f); fseek(f, 0, SEEK_SET); b=(char *)malloc(l+1); origb=b; fread(b, l, 1, f); b[l]=0; fclose(f); for(i=0;i<256;i++) { mode.r2t.src[i]->clear(); mode.r2t.dest[i]->clear(); mode.r2t.prev[i]->clear(); mode.r2t.next[i]->clear(); mode.r2t.id[i]->clear(); mode.t2r.src[i]->clear(); mode.t2r.dest[i]->clear(); mode.t2r.prev[i]->clear(); mode.t2r.next[i]->clear(); mode.t2r.id[i]->clear(); } mode.path=ExtractFilePath(filename); mode.text=ExtractFileName(filename); #ifdef SPY printf("%s\n", filename); printf("%d bytes\n", l); // printf("%s\n", b); #endif if(string(b).substr(0,VERSION2TAG.size())==VERSION2TAG) version1=false; else version1=true; mode.version = version1 ? 1 : 2; if(!version1) { try { head=VERSION2TAG.size(); b+=head; i=string(b).find('\t')+1; head+=i; b+=i; i=string(b).find('\t')+1; head+=i; r2tentries=atol(string(b).substr(0,i-1).c_str()); #ifdef SPY printf("%d r2t\n", r2tentries); #endif if(!r2tentries) throw EConvertError(""); b+=i; i=string(b).find('\t')+1; head+=i; t2rentries=atol(string(b).substr(0,i-1).c_str()); #ifdef SPY printf("%d t2r\n", t2rentries); #endif b+=i; }catch(const EConvertError &) { throw EUnknownFormat("Unknown file format"); } } i=string(b).find('\t')+1; mode.comment=string(b).substr(0,i-1); if((b[i]!='0')&&(b[i]!='1')) throw EUnknownFormat("Unknown file format"); mode.casesens=b[i]=='1'; if(!mode.casesens) matchcase=&lowercase; else matchcase=&dummy; if(version1) i=72; else i=72-head; b+=i; entries=0; #ifdef SPY printf("R2T Entries:\n"); #endif do { #ifdef SPY printf("%d. ", entries+1); #endif if(!GetNextEntry(b, mode.r2t, &CTranscription::RomanHash)) break; entries++; }while((b-origb<l)&&((version1)||(entries!=r2tentries))); matchcase=&dummy;//unwanted for reverse transcription if(!version1) { if(entries!=r2tentries) throw EUnknownFormat("Unknown file format"); entries=0; #ifdef SPY printf("T2R Entries:\n"); #endif do { #ifdef SPY printf("%d. ", entries+1); #endif if(!GetNextEntry(b, mode.t2r, &CTranscription::TengHash)) break; entries++; }while((b-origb<l)&&(entries!=t2rentries)); if(entries!=t2rentries) throw EUnknownFormat("Unknown file format"); } else//version1 AutoReverse(); Optimize(mode.r2t); Optimize(mode.t2r); }catch(exception &e) { if(origb) free(origb); throw e; } if(origb) free(origb); }