You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by ad...@apache.org on 2008/06/25 20:50:30 UTC

svn commit: r671633 - in /tuscany/cpp/sdo/runtime/core/src/commonj/sdo: SDODataConverter.cpp SDODataConverter.h TypeImpl.cpp

Author: adrianocrestani
Date: Wed Jun 25 11:50:30 2008
New Revision: 671633

URL: http://svn.apache.org/viewvc?rev=671633&view=rev
Log:
applying TUSCANY-2439 fix to the Native SDO repo

Modified:
    tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.cpp
    tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.h
    tuscany/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.cpp

Modified: tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.cpp
URL: http://svn.apache.org/viewvc/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.cpp?rev=671633&r1=671632&r2=671633&view=diff
==============================================================================
--- tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.cpp (original)
+++ tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.cpp Wed Jun 25 11:50:30 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
@@ -630,12 +631,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:
@@ -800,7 +801,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))
                {
@@ -818,7 +819,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))
                {
@@ -1019,7 +1020,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))
                {
@@ -1037,7 +1038,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))
                {
@@ -1111,5 +1112,6 @@
             }
          }
       }
+	  unsigned int SDODataConverter::precision = 6;
    }
 }

Modified: tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.h
URL: http://svn.apache.org/viewvc/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.h?rev=671633&r1=671632&r2=671633&view=diff
==============================================================================
--- tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.h (original)
+++ tuscany/cpp/sdo/runtime/core/src/commonj/sdo/SDODataConverter.h Wed Jun 25 11:50:30 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,9 @@
                                                 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/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.cpp
URL: http://svn.apache.org/viewvc/tuscany/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.cpp?rev=671633&r1=671632&r2=671633&view=diff
==============================================================================
--- tuscany/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.cpp (original)
+++ tuscany/cpp/sdo/runtime/core/src/commonj/sdo/TypeImpl.cpp Wed Jun 25 11:50:30 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>
@@ -2074,18 +2075,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]);
@@ -2095,7 +2096,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;
@@ -2109,18 +2110,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]);
@@ -2129,7 +2130,7 @@
                 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 @@
         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 @@
               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 @@
         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 @@
                 (*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 @@
                 (*asstringbuf)[0] = 0;
                 return *asstringbuf;
             }
-            sprintf(*asstringbuf,"%.3e", *(float*)value);
+            sprintf(*asstringbuf, "%.*g", SDODataConverter::precision, *(float*)value);
             return *asstringbuf;
 
         case LongType: