activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tab...@apache.org
Subject svn commit: r770872 - in /activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang: Double.cpp Float.cpp
Date Sat, 02 May 2009 01:59:44 GMT
Author: tabish
Date: Sat May  2 00:39:33 2009
New Revision: 770872

URL: http://svn.apache.org/viewvc?rev=770872&view=rev
Log:
A couple of hacks to get the primitive value conversion code working, the code still doesn't
parse float and double values to spec.

Modified:
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Double.cpp
    activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Float.cpp

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Double.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Double.cpp?rev=770872&r1=770871&r2=770872&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Double.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Double.cpp Sat May  2 00:39:33
2009
@@ -18,6 +18,7 @@
 #include "Double.h"
 #include <decaf/lang/Long.h>
 #include <limits>
+#include <sstream>
 #include <string.h>
 
 using namespace std;
@@ -137,10 +138,22 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-double Double::parseDouble( DECAF_UNUSED const std::string value )
+double Double::parseDouble( const std::string value )
     throw ( exceptions::NumberFormatException ) {
 
-    return 0; // TODO
+    // TODO - This is not going to parse the formats we say we do.
+    float result = 0.0;
+    istringstream stream( value );
+    stream >> result;
+
+    // Not everything got read, meaning there wasn't just a number here.
+    if( !stream.eof() ) {
+        throw exceptions::NumberFormatException(
+            __FILE__, __LINE__,
+            "Failed to parse a valid float from input string: %s", value.c_str() );
+    }
+
+    return result;
 }
 
 ////////////////////////////////////////////////////////////////////////////////
@@ -229,8 +242,13 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////
-std::string Double::toString( DECAF_UNUSED double value ) {
-    return ""; //TODO
+std::string Double::toString( double value ) {
+
+    // TODO - This is not going to output to the format we say we do.
+    ostringstream stream;
+    stream << value;
+
+    return stream.str();
 }
 
 ////////////////////////////////////////////////////////////////////////////////

Modified: activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Float.cpp
URL: http://svn.apache.org/viewvc/activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Float.cpp?rev=770872&r1=770871&r2=770872&view=diff
==============================================================================
--- activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Float.cpp (original)
+++ activemq/activemq-cpp/trunk/activemq-cpp/src/main/decaf/lang/Float.cpp Sat May  2 00:39:33
2009
@@ -152,6 +152,14 @@
     float result = 0.0;
     istringstream stream( value );
     stream >> result;
+
+    // Not everything got read, meaning there wasn't just a number here.
+    if( !stream.eof() ) {
+        throw exceptions::NumberFormatException(
+            __FILE__, __LINE__,
+            "Failed to parse a valid float from input string: %s", value.c_str() );
+    }
+
     return result;
 }
 



Mime
View raw message