Author: adrianocrestani Date: Tue Jun 24 16:13:11 2008 New Revision: 671378
URL: http://svn.apache.org/viewvc?rev=671378&view=rev Log: -applying patch from TUSCANY-2439 on branch sdo-cpp-pre-2.1 Modified: tuscany/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.cpp tuscany/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.h tuscany/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeImpl.cpp Modified: tuscany/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.cpp URL: http://svn.apache.org/viewvc/tuscany/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.cpp?rev=671378&r1=671377&r2=671378&view=diff ============================================================================== --- tuscany/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.cpp (original) +++ tuscany/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.cpp Tue Jun 24 16:13:11 2008 @@ -20,6 +20,7 @@ #include <string.h> #include "commonj/sdo/SDODataConverter.h" #include "commonj/sdo/SDORuntimeException.h" +#include "commonj/sdo/TypeImpl.h" // Data type conversion code is currently spread across this class and @@ -640,12 +641,12 @@ case DataTypeInfo::TDTfloat: { - sprintf(buffer , "%.3e", sourceValue.Float); + sprintf(buffer , "%.*g", SDODataConverter::precision, sourceValue.Float); break; } case DataTypeInfo::TDTdouble: { - sprintf(buffer , "%.3Le", sourceValue.Double); + sprintf(buffer , "%.*Lg", SDODataConverter::precision, sourceValue.Double); break; } case DataTypeInfo::TDTSDODate: @@ -811,7 +812,7 @@ char tmpstr[SDODataConverter::MAX_TRANSIENT_SIZE]; unsigned int j = 0; - sprintf(tmpstr, "%.3e", sourceValue.Float); + sprintf(tmpstr, "%.*g", SDODataConverter::precision, sourceValue.Float); size_t tmplen = strlen(tmpstr); if ((tmplen > max_length) || (outptr == 0)) { @@ -829,7 +830,7 @@ char tmpstr[SDODataConverter::MAX_TRANSIENT_SIZE]; unsigned int j = 0; - sprintf(tmpstr, "%.3Le", sourceValue.Double); + sprintf(tmpstr, "%.*Lg", SDODataConverter::precision, sourceValue.Double); size_t tmplen = strlen(tmpstr); if ((tmplen > max_length) || (outptr == 0)) { @@ -1032,7 +1033,7 @@ char tmpstr[SDODataConverter::MAX_TRANSIENT_SIZE]; unsigned int j = 0; - sprintf(tmpstr, "%.3e", sourceValue.Float); + sprintf(tmpstr, "%.*g", SDODataConverter::precision, sourceValue.Float); size_t tmplen = strlen(tmpstr); if ((tmplen > max_length) || (outptr == 0)) { @@ -1050,7 +1051,7 @@ char tmpstr[SDODataConverter::MAX_TRANSIENT_SIZE]; unsigned int j = 0; - sprintf(tmpstr, "%.3Le", sourceValue.Double); + sprintf(tmpstr, "%.*Lg", SDODataConverter::precision, sourceValue.Double); size_t tmplen = strlen(tmpstr); if ((tmplen > max_length) || (outptr == 0)) { @@ -1126,5 +1127,6 @@ } } } + unsigned int SDODataConverter::precision = 6; } } Modified: tuscany/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.h URL: http://svn.apache.org/viewvc/tuscany/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.h?rev=671378&r1=671377&r2=671378&view=diff ============================================================================== --- tuscany/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.h (original) +++ tuscany/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/SDODataConverter.h Tue Jun 24 16:13:11 2008 @@ -18,7 +18,7 @@ /* $Rev$ $Date$ */ #ifndef _SDODATACONVERTER_H_ -#define _SDODATACONVERTOR_H_ +#define _SDODATACONVERTER_H_ #include "commonj/sdo/DataTypeInfo.h" #include "commonj/sdo/SDODate.h" @@ -69,6 +69,7 @@ const DataTypeInfo::TrueDataType& dataType, wchar_t* outptr, unsigned int max_length); + static unsigned int precision; private: // We sometimes need to convert primitive data types into an // equivalent string representation and for that we need a Modified: tuscany/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeImpl.cpp URL: http://svn.apache.org/viewvc/tuscany/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeImpl.cpp?rev=671378&r1=671377&r2=671378&view=diff ============================================================================== --- tuscany/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeImpl.cpp (original) +++ tuscany/branches/sdo-cpp-pre2.1/runtime/core/src/commonj/sdo/TypeImpl.cpp Tue Jun 24 16:13:11 2008 @@ -22,6 +22,7 @@ #include "commonj/sdo/Logger.h" #include "commonj/sdo/PropertyImpl.h" +#include "commonj/sdo/SDODataConverter.h" #include "commonj/sdo/TypeImpl.h" #include <iostream> @@ -2079,18 +2080,18 @@ wchar_t* fmt = new wchar_t[5]; fmt[0] = (wchar_t)'%'; fmt[1] = (wchar_t)'.'; - fmt[2] = (wchar_t)'3'; - fmt[3] = (wchar_t)'e'; + fmt[2] = (wchar_t)'*'; + fmt[3] = (wchar_t)'g'; fmt[4] = (wchar_t)0; #if defined(WIN32) || defined (_WINDOWS) - swprintf((wchar_t*)outval,fmt,*(long double*)value); + swprintf((wchar_t*)outval, fmt, SDODataConverter::precision, *(long double*)value); #else #if defined(NO_SWPRINTF) { int k; char *tmpbuf = new char[50]; wchar_t *tmpw = (wchar_t*)outval; - sprintf(tmpbuf,"%.3Le",*(long double*)value); + sprintf(tmpbuf, "%.*Lg", SDODataConverter::precision, *(long double*)value); for (k=0;k<strlen(tmpbuf);k++) { *(tmpw++) = (wchar_t)(tmpbuf[k]); @@ -2100,7 +2101,7 @@ } #else - swprintf((wchar_t*)outval, wcslen((wchar_t*)outval), fmt, *(long double*)value); + swprintf((wchar_t*)outval, wcslen((wchar_t*)outval), fmt, SDODataConverter::precision, *(long double*)value); #endif #endif delete fmt; @@ -2114,18 +2115,18 @@ wchar_t* fmt = new wchar_t[5]; fmt[0] = (wchar_t)'%'; fmt[1] = (wchar_t)'.'; - fmt[2] = (wchar_t)'3'; - fmt[3] = (wchar_t)'e'; + fmt[2] = (wchar_t)'*'; + fmt[3] = (wchar_t)'g'; fmt[4] = (wchar_t)0; #if defined(WIN32) || defined (_WINDOWS) - swprintf(outval,fmt,*(float*)value); + swprintf(outval, fmt, SDODataConverter::precision, *(float*)value); #else #if defined(NO_SWPRINTF) { int k; char *tmpbuf = new char[50]; wchar_t *tmpw = (wchar_t*)outval; - sprintf(tmpbuf,"%.3e",*(float*)value); + sprintf(tmpbuf, "%.*g", SDODataConverter::precision, *(float*)value); for (k=0;k<strlen(tmpbuf);k++) { *(tmpw++) = (wchar_t)(tmpbuf[k]); @@ -2134,7 +2135,7 @@ delete tmpbuf; } #else - swprintf(outval, wcslen(outval), fmt, *(float*)value); + swprintf(outval, wcslen(outval), fmt, SDODataConverter::precision, *(float*)value); #endif #endif delete fmt; @@ -2301,13 +2302,13 @@ case DoubleType: if (value == 0) return 0; if (max < MAX_DOUBLE_SIZE) return 0; - sprintf(outval,"%.3Le",*(long double*)value); + sprintf(outval, "%.*Lg", SDODataConverter::precision, *(long double*)value); return strlen(outval); case FloatType: if (value == 0) return 0; if (max < MAX_FLOAT_SIZE) return 0; - sprintf(outval,"%.3e",*(float*)value); + sprintf(outval, "%.*g", SDODataConverter::precision, *(float*)value); return strlen(outval); case OtherTypes: @@ -2485,7 +2486,7 @@ if (max < MAX_DOUBLE_SIZE) return 0; char* tmpstr = new char[MAX_DOUBLE_SIZE + 1]; - sprintf(tmpstr, "%.3Le", *(const long double*)value); + sprintf(tmpstr, "%.*Lg", SDODataConverter::precision, *(const long double*)value); outval = tmpstr; delete tmpstr; return outval.length(); @@ -2498,7 +2499,7 @@ if (max < MAX_FLOAT_SIZE) return 0; char* tmpstr = new char[MAX_FLOAT_SIZE + 1]; - sprintf(tmpstr, "%.3Le", *(const float*)value); + sprintf(tmpstr, "%.*g", SDODataConverter::precision, *(const float*)value); outval = tmpstr; delete tmpstr; return outval.length(); @@ -2591,7 +2592,7 @@ (*asstringbuf)[0] = 0; return *asstringbuf; } - sprintf(*asstringbuf,"%.3Le",*(long double*)value); + sprintf(*asstringbuf, "%.*Lg", SDODataConverter::precision, *(long double*)value); return *asstringbuf; case FloatType: @@ -2603,7 +2604,7 @@ (*asstringbuf)[0] = 0; return *asstringbuf; } - sprintf(*asstringbuf,"%.3e", *(float*)value); + sprintf(*asstringbuf, "%.*g", SDODataConverter::precision, *(float*)value); return *asstringbuf; case LongType:
