Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r54858 - sandbox/numeric_adaptor/boost/numeric_adaptor
From: bruno.lalande_at_[hidden]
Date: 2009-07-10 10:47:50


Author: bruno.lalande
Date: 2009-07-10 10:47:49 EDT (Fri, 10 Jul 2009)
New Revision: 54858
URL: http://svn.boost.org/trac/boost/changeset/54858

Log:
All policies functions now work directly on a policy. numeric_adaptor no longer has to know about the nested value.
Text files modified:
   sandbox/numeric_adaptor/boost/numeric_adaptor/cln_policy.hpp | 13 ++++++-------
   sandbox/numeric_adaptor/boost/numeric_adaptor/default_policy.hpp | 18 +++++++++---------
   sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_policy.hpp | 22 ++++++++--------------
   sandbox/numeric_adaptor/boost/numeric_adaptor/ieee_policy.hpp | 14 ++++----------
   sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp | 32 +++++++++-----------------------
   5 files changed, 36 insertions(+), 63 deletions(-)

Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/cln_policy.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/cln_policy.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/cln_policy.hpp 2009-07-10 10:47:49 EDT (Fri, 10 Jul 2009)
@@ -33,20 +33,19 @@
     typedef cln::cl_F value_type;
 
     template <typename FromType>
- static inline void set(value_type& value, FromType const& v)
+ static inline void set(cln_policy& p, FromType const& v)
     {
         // Conversions from the C built-in type `double' are provided for the
         // classes cl_DF, cl_F, cl_R, cl_N and cl_number
- value = cln::cl_float(v, cln::float_format(256));
+ p.value = cln::cl_float(v, cln::float_format(256));
     }
 
- static inline void set(value_type& value, std::string const& v)
+ static inline void set(cln_policy& p, std::string const& v)
     {
         // CLN documentation 4.1.3 + 5.1 ("A precision specifier of the form prec may be appended")
         std::string copy(v);
         copy += "_256";
- value = copy.c_str();
- //value = cln::cl_float(atof(v.c_str()), cln::float_format(256));
+ p.value = copy.c_str();
     }
 
     static inline void abs(cln_policy& r, cln_policy const& a)
@@ -87,7 +86,7 @@
 
 
     template <typename ToType>
- static inline ToType big_numeric_cast(value_type const& b)
+ static inline ToType big_numeric_cast(cln_policy const& b)
     {
         /*
             Conversions from the classes cl_I, cl_RA, cl_SF, cl_FF,
@@ -103,7 +102,7 @@
             0 is returned. If abs(x) is too large (overflow),
             an IEEE infinity is returned.
         */
- return ToType(double_approx(b));
+ return ToType(double_approx(b.value));
     }
 
 };

Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/default_policy.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/default_policy.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/default_policy.hpp 2009-07-10 10:47:49 EDT (Fri, 10 Jul 2009)
@@ -53,43 +53,43 @@
     static inline void cos(default_policy& r, default_policy const& a)
     {
         double d = Derived::template big_numeric_cast<double>(static_cast<const Derived&>(a));
- Derived::set(r.value, std::cos(d));
+ Derived::set(static_cast<Derived&>(r), std::cos(d));
     }
 
     static inline void sin(default_policy& r, default_policy const& a)
     {
         double d = Derived::template big_numeric_cast<double>(static_cast<const Derived&>(a));
- Derived::set(r.value, std::sin(d));
+ Derived::set(static_cast<Derived&>(r), std::sin(d));
     }
 
     static inline void tan(default_policy& r, default_policy const& a)
     {
         double d = Derived::template big_numeric_cast<double>(static_cast<const Derived&>(a));
- Derived::set(r.value, std::tan(d));
+ Derived::set(static_cast<Derived&>(r), std::tan(d));
     }
 
     static inline void atan(default_policy& r, default_policy const& a)
     {
         double d = Derived::template big_numeric_cast<double>(static_cast<const Derived&>(a));
- Derived::set(r.value, std::atan(d));
+ Derived::set(static_cast<Derived&>(r), std::atan(d));
     }
 
     static inline void sqrt(default_policy& r, default_policy const& a)
     {
         double d = Derived::template big_numeric_cast<double>(static_cast<const Derived&>(a));
- Derived::set(r.value, std::sqrt(d));
+ Derived::set(static_cast<Derived&>(r), std::sqrt(d));
     }
 
     // Default use the comparison operators
- static inline int compare(T const& a, T const& b)
+ static inline int compare(default_policy const& a, default_policy const& b)
     {
- return a < b ? -1 : a > b ? 1 : 0;
+ return a.value < b.value ? -1 : a.value > b.value ? 1 : 0;
     }
 
- static inline std::string as_string(T const& a)
+ static inline std::string as_string(default_policy const& a)
     {
         std::ostringstream out;
- out << std::setprecision(20) << a;
+ out << std::setprecision(20) << a.value;
         return out.str();
     }
 

Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_policy.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_policy.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/gmp_policy.hpp 2009-07-10 10:47:49 EDT (Fri, 10 Jul 2009)
@@ -38,14 +38,14 @@
     }
 
     template <typename OtherType>
- static inline void set(value_type& value, const OtherType& v)
+ static inline void set(gmp_policy& p, const OtherType& v)
     {
- mpf_set_d(value, v);
+ mpf_set_d(p.value, v);
     }
 
- static inline void set(value_type& value, const std::string& v)
+ static inline void set(gmp_policy& p, const std::string& v)
     {
- mpf_set_str(value, v.c_str(), 10);
+ mpf_set_str(p.value, v.c_str(), 10);
     }
 
 
@@ -119,23 +119,17 @@
 
 
     template <typename OtherType>
- static inline OtherType big_numeric_cast(value_type const& b)
- {
- return mpf_get_d(b);
- }
-
- template <typename OtherType>
     static inline OtherType big_numeric_cast(gmp_policy const& b)
     {
         return mpf_get_d(b.value);
     }
 
 
- static inline std::string as_string(value_type const& a)
+ static inline std::string as_string(gmp_policy const& a)
     {
         mp_exp_t exponent;
         static char s[1024];
- mpf_get_str (s, &exponent, 10, sizeof(s) - 1, a);
+ mpf_get_str (s, &exponent, 10, sizeof(s) - 1, a.value);
 
         std::string out;
         out.reserve(100);
@@ -155,9 +149,9 @@
     }
 
 
- static inline int compare(value_type const& a, value_type const& b)
+ static inline int compare(gmp_policy const& a, gmp_policy const& b)
     {
- return mpf_cmp(a, b);
+ return mpf_cmp(a.value, b.value);
     }
 };
 

Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/ieee_policy.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/ieee_policy.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/ieee_policy.hpp 2009-07-10 10:47:49 EDT (Fri, 10 Jul 2009)
@@ -32,11 +32,11 @@
     typedef T value_type;
 
     template <typename OtherType>
- static inline void set(value_type& value, OtherType const& v)
- { value = v; } //boost::numeric_cast<T>(v); }
+ static inline void set(ieee_policy& p, OtherType const& v)
+ { p.value = v; } //boost::numeric_cast<T>(v); }
 
- static inline void set(value_type& value, std::string const& v)
- { value = boost::lexical_cast<T>(v); }
+ static inline void set(ieee_policy& p, std::string const& v)
+ { p.value = boost::lexical_cast<T>(v); }
 
     static inline void abs(ieee_policy& r, ieee_policy const& a)
     { r.value = std::abs(a.value); }
@@ -47,12 +47,6 @@
     }
 
     template <typename OtherType>
- static inline OtherType big_numeric_cast(value_type const& v)
- {
- return boost::numeric_cast<OtherType>(v);
- }
-
- template <typename OtherType>
     static inline OtherType big_numeric_cast(ieee_policy const& v)
     {
         return boost::numeric_cast<OtherType>(v.value);

Modified: sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp
==============================================================================
--- sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp (original)
+++ sandbox/numeric_adaptor/boost/numeric_adaptor/numeric_adaptor.hpp 2009-07-10 10:47:49 EDT (Fri, 10 Jul 2009)
@@ -53,63 +53,56 @@
     // Constructor from a string
     inline numeric_adaptor(std::string const& v)
     {
- Policy::set(Policy::value, v);
+ Policy::set(*this, v);
     }
 
     inline numeric_adaptor(const char* v)
     {
- Policy::set(Policy::value, std::string(v));
+ Policy::set(*this, std::string(v));
     }
 
     // Constructor with a normal IEEE type
     template <typename FromType>
     inline numeric_adaptor(FromType const& v)
     {
- Policy::template set<FromType>(Policy::value, v);
- }
-
- // Assignment from other value
- inline numeric_adaptor<Policy> operator=(numeric_adaptor<Policy> const& v)
- {
- Policy::copy(v.value, Policy::value);
- return *this;
+ Policy::template set<FromType>(*this, v);
     }
 
     // Assignment from normal IEEE type
     template <typename FromType>
     inline numeric_adaptor<Policy> operator=(FromType const& v)
     {
- Policy::template set<FromType>(Policy::value, v);
+ Policy::template set<FromType>(*this, v);
         return *this;
     }
 
     template <class ToType>
     inline ToType big_numeric_cast()
     {
- return Policy::template big_numeric_cast<ToType>(Policy::value);
+ return Policy::template big_numeric_cast<ToType>(*this);
     }
 
     // tuple/fusion/variant-like get template function
     inline operator std::string()
     {
- return Policy::as_string(Policy::value);
+ return Policy::as_string(*this);
     }
 
 
     // Comparisons
     inline bool operator<(numeric_adaptor<Policy> const& other) const
     {
- return Policy::compare(Policy::value, other.value) < 0;
+ return Policy::compare(*this, other) < 0;
     }
 
     inline bool operator>(numeric_adaptor<Policy> const& other) const
     {
- return Policy::compare(Policy::value, other.value) > 0;
+ return Policy::compare(*this, other) > 0;
     }
 
     inline bool operator==(numeric_adaptor<Policy> const& other) const
     {
- return Policy::compare(Policy::value, other.value) == 0;
+ return Policy::compare(*this, other) == 0;
     }
 
     // Operators
@@ -179,13 +172,6 @@
         Policy::neg(r, n);
         return r;
     }
-
- // Construct from a policy-type. Bool (or any other signature changing parameter)
- // is necessary for cases where type == OtherType
- inline numeric_adaptor<Policy>(typename Policy::value_type const& v, bool)
- {
- Policy::copy(v, Policy::value);
- }
 };
 
 


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk