Date: Friday, January 27, 2006 @ 13:22:12
  Author: marc
    Path: /cvsroot/carob/carob/src

Modified: ParameterStatement.cpp (1.10 -> 1.11)

Added floating-point FPoneShotFilter for float and double : now handling 
+-infinity() CAROB-31


------------------------+
 ParameterStatement.cpp |   42 +++++++++++++++++++++++++++++++++++++++++-
 1 files changed, 41 insertions(+), 1 deletion(-)


Index: carob/src/ParameterStatement.cpp
diff -u carob/src/ParameterStatement.cpp:1.10 
carob/src/ParameterStatement.cpp:1.11
--- carob/src/ParameterStatement.cpp:1.10       Fri Jan 27 12:48:24 2006
+++ carob/src/ParameterStatement.cpp    Fri Jan 27 13:22:12 2006
@@ -223,6 +223,44 @@
   };
 };
 
+template<class FP>
+class FPoneShotFilter
+{
+  basic_ostream<wchar_t>& wrapped_stream;
+public:
+  FPoneShotFilter(basic_ostream<wchar_t>& s) : wrapped_stream(s) { } ;
+  basic_ostream<wchar_t>&
+ // this is the actual filtering operator
+  operator<< (FP value)
+  { 
+    // too bad Standard C and Java could not agree on the same string :-(
+    if (value == std::numeric_limits<FP>::infinity())
+      wrapped_stream << L"Infinity"; // see java.lang.(Float|Double)#toString()
+    else if (value == -std::numeric_limits<FP>::infinity())
+      wrapped_stream << L"-Infinity"; 
+    // TODO: catch NaNs
+    else
+      wrapped_stream << value;
+    // then return the underlying stream (we filter only once!)
+    return wrapped_stream;
+  }
+};
+
+template<>
+class oneShotFilter<double, wchar_t> : public FPoneShotFilter<double>
+{
+public:
+  oneShotFilter(basic_ostream<wchar_t>& s) : FPoneShotFilter<double>(s) { } ;
+};
+
+template<>
+class oneShotFilter<float, wchar_t> : public FPoneShotFilter<float>
+{
+public:
+  oneShotFilter(basic_ostream<wchar_t>& s) : FPoneShotFilter<float>(s) { } ;
+};
+
+
 } // namespace CarobNS
 
   //// end of template filters ////
@@ -236,7 +274,9 @@
     throw DriverException(L"Parameter index out of range.");
     
   // As an optimization, we could make this stream a member.
-  // That would just require a member lock for thread-safety
+  // That would require
+  // - a member lock for thread-safety
+  // - carefully checking that streamSettings<T1>() does not step on 
streamSettings<T2>() toes
   std::wostringstream buffer;
 
 

_______________________________________________
Carob-commits mailing list
[email protected]
https://forge.continuent.org/mailman/listinfo/carob-commits

Reply via email to