summaryrefslogtreecommitdiffstats
path: root/cpp
diff options
context:
space:
mode:
authoradrianocrestani <adrianocrestani@13f79535-47bb-0310-9956-ffa450edef68>2008-06-25 18:50:30 +0000
committeradrianocrestani <adrianocrestani@13f79535-47bb-0310-9956-ffa450edef68>2008-06-25 18:50:30 +0000
commit8b7992d467853c38106a590cdcdfc0f8efb0ea9d (patch)
tree97971105ac557710d6bedab6a4431f8c84ead616 /cpp
parent22749e7c989f20f56cb9efef762d801a05b9a1d3 (diff)
applying TUSCANY-2439 fix to the Native SDO repo
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@671633 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'cpp')
-rw-r--r--cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.cpp14
-rw-r--r--cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.h5
-rw-r--r--cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.cpp33
3 files changed, 29 insertions, 23 deletions
diff --git a/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.cpp b/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.cpp
index 591e540a71..1211400fe3 100644
--- a/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.cpp
+++ b/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.cpp
@@ -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
@@ -630,12 +631,12 @@ namespace commonj
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:
@@ -800,7 +801,7 @@ namespace commonj
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))
{
@@ -818,7 +819,7 @@ namespace commonj
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))
{
@@ -1019,7 +1020,7 @@ namespace commonj
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))
{
@@ -1037,7 +1038,7 @@ namespace commonj
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))
{
@@ -1111,5 +1112,6 @@ namespace commonj
}
}
}
+ unsigned int SDODataConverter::precision = 6;
}
}
diff --git a/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.h b/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.h
index 640682392d..b4fd96d9fa 100644
--- a/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.h
+++ b/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.h
@@ -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,9 @@ namespace commonj
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
diff --git a/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.cpp b/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.cpp
index 1e456d9968..dc840a0d46 100644
--- a/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.cpp
+++ b/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.cpp
@@ -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>
@@ -2074,18 +2075,18 @@ namespace sdo{
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]);
@@ -2095,7 +2096,7 @@ namespace sdo{
}
#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;
@@ -2109,18 +2110,18 @@ namespace sdo{
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]);
@@ -2129,7 +2130,7 @@ namespace sdo{
delete tmpbuf;
}
#else
- swprintf(outval, wcslen(outval), fmt, *(float*)value);
+ swprintf(outval, wcslen(outval), fmt, SDODataConverter::precision, *(float*)value);
#endif
#endif
delete fmt;
@@ -2295,13 +2296,13 @@ unsigned int TypeImpl::convertToString(const SDOValue& sdoValue,
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:
@@ -2478,7 +2479,7 @@ unsigned int TypeImpl::convertToString(const SDOValue& sdoValue,
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();
@@ -2491,7 +2492,7 @@ unsigned int TypeImpl::convertToString(const SDOValue& sdoValue,
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();
@@ -2584,7 +2585,7 @@ unsigned int TypeImpl::convertToString(const SDOValue& sdoValue,
(*asstringbuf)[0] = 0;
return *asstringbuf;
}
- sprintf(*asstringbuf,"%.3Le",*(long double*)value);
+ sprintf(*asstringbuf, "%.*Lg", SDODataConverter::precision, *(long double*)value);
return *asstringbuf;
case FloatType:
@@ -2596,7 +2597,7 @@ unsigned int TypeImpl::convertToString(const SDOValue& sdoValue,
(*asstringbuf)[0] = 0;
return *asstringbuf;
}
- sprintf(*asstringbuf,"%.3e", *(float*)value);
+ sprintf(*asstringbuf, "%.*g", SDODataConverter::precision, *(float*)value);
return *asstringbuf;
case LongType: