|
Boost-Commit : |
Subject: [Boost-commit] svn:boost r76913 - sandbox/e_float/libs/e_float/src/utility
From: e_float_at_[hidden]
Date: 2012-02-06 14:24:34
Author: christopher_kormanyos
Date: 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
New Revision: 76913
URL: http://svn.boost.org/trac/boost/changeset/76913
Log:
- Cleaned up utility classes (mostly order of access controls).
Text files modified:
sandbox/e_float/libs/e_float/src/utility/util_alternating_sum.h | 18 ++++++------
sandbox/e_float/libs/e_float/src/utility/util_coefficient_expansion.h | 31 ++++++++++----------
sandbox/e_float/libs/e_float/src/utility/util_find_root_base.h | 11 +++----
sandbox/e_float/libs/e_float/src/utility/util_find_root_bisect.h | 15 ++++------
sandbox/e_float/libs/e_float/src/utility/util_find_root_newton_raphson.h | 18 ++++-------
sandbox/e_float/libs/e_float/src/utility/util_function.h | 20 ++++--------
sandbox/e_float/libs/e_float/src/utility/util_function_derivative.h | 59 +++++++++++++--------------------------
sandbox/e_float/libs/e_float/src/utility/util_function_operation.h | 15 +++------
sandbox/e_float/libs/e_float/src/utility/util_interpolate.h | 4 ++
sandbox/e_float/libs/e_float/src/utility/util_noncopyable.h | 4 --
sandbox/e_float/libs/e_float/src/utility/util_numeric_cast.h | 6 ++-
sandbox/e_float/libs/e_float/src/utility/util_point.h | 10 ++++--
sandbox/e_float/libs/e_float/src/utility/util_power_x_pow_n.h | 3 +
sandbox/e_float/libs/e_float/src/utility/util_ranged_function_operation.h | 13 +++-----
sandbox/e_float/libs/e_float/src/utility/util_timer.h | 2
sandbox/e_float/libs/e_float/src/utility/util_trapezoid.h | 22 ++++++++++----
16 files changed, 112 insertions(+), 139 deletions(-)
Modified: sandbox/e_float/libs/e_float/src/utility/util_alternating_sum.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/utility/util_alternating_sum.h (original)
+++ sandbox/e_float/libs/e_float/src/utility/util_alternating_sum.h 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
@@ -13,17 +13,11 @@
namespace Util
{
- template<typename T1, typename T2 = T1> struct alternating_sum
+ template<typename T1,
+ typename T2 = T1>
+ struct alternating_sum
{
- private:
-
- const alternating_sum& operator=(const alternating_sum&);
-
- bool b_neg_term;
- const T2 initial;
-
public:
-
alternating_sum(const bool b_neg = false, const T2& init = T2(0)) : b_neg_term(b_neg),
initial (init) { }
@@ -33,6 +27,12 @@
b_neg_term = !b_neg_term;
return the_sum + initial;
}
+
+ private:
+ bool b_neg_term;
+ const T2 initial;
+
+ const alternating_sum& operator=(const alternating_sum&);
};
}
Modified: sandbox/e_float/libs/e_float/src/utility/util_coefficient_expansion.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/utility/util_coefficient_expansion.h (original)
+++ sandbox/e_float/libs/e_float/src/utility/util_coefficient_expansion.h 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
@@ -13,23 +13,10 @@
namespace Util
{
- template<typename T1, typename T2 = T1> struct coefficient_expansion
+ template<typename T1,
+ typename T2 = T1>
+ struct coefficient_expansion
{
- private:
-
- const T1 x_expand;
- T1 x_expand_pow_k;
-
- private:
-
- const coefficient_expansion& operator=(const coefficient_expansion&);
-
- static const T2& one_t2(void)
- {
- static const T2 val_t2(1);
- return val_t2;
- }
-
public:
coefficient_expansion(const T1& expand, const T2& init = one_t2()) : x_expand (expand),
@@ -43,6 +30,18 @@
return sum + ck_x_pow_k;
}
+
+ private:
+ const T1 x_expand;
+ T1 x_expand_pow_k;
+
+ const coefficient_expansion& operator=(const coefficient_expansion&);
+
+ static const T2& one_t2(void)
+ {
+ static const T2 val_t2(1);
+ return val_t2;
+ }
};
}
Modified: sandbox/e_float/libs/e_float/src/utility/util_find_root_base.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/utility/util_find_root_base.h (original)
+++ sandbox/e_float/libs/e_float/src/utility/util_find_root_base.h 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
@@ -15,17 +15,16 @@
namespace Util
{
- template<typename T> class FindRootBase : public RangedFunctionOperation<T>
+ template<typename T>
+ class FindRootBase : public RangedFunctionOperation<T>
{
+ public:
+ virtual ~FindRootBase() { }
+
protected:
-
FindRootBase(const T& lo,
const T& hi,
const T& tol) : RangedFunctionOperation<T>(lo, hi, tol) { }
-
- public:
-
- virtual ~FindRootBase() { }
};
}
Modified: sandbox/e_float/libs/e_float/src/utility/util_find_root_bisect.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/utility/util_find_root_bisect.h (original)
+++ sandbox/e_float/libs/e_float/src/utility/util_find_root_bisect.h 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
@@ -11,25 +11,22 @@
#ifndef _UTIL_FIND_ROOT_BISECT_2009_10_31_H_
#define _UTIL_FIND_ROOT_BISECT_2009_10_31_H_
- #include <utility/util_find_root_base.h>
- #include <boost/e_float/e_float.hpp>
+ #include "util_find_root_base.h"
namespace Util
{
- template<typename T> class FindRootBisect : public FindRootBase<T>
+ template<typename T>
+ class FindRootBisect : public FindRootBase<T>
{
+ public:
+ virtual ~FindRootBisect() { }
+
protected:
-
FindRootBisect(const T& lo,
const T& hi,
const T& tol) : FindRootBase<T>(lo, hi, tol) { }
- public:
-
- virtual ~FindRootBisect() { }
-
private:
-
virtual T my_operation(void) const
{
// Bisection method as described in Numerical Recipes in C++ 2nd Ed., chapter 9.1.
Modified: sandbox/e_float/libs/e_float/src/utility/util_find_root_newton_raphson.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/utility/util_find_root_newton_raphson.h (original)
+++ sandbox/e_float/libs/e_float/src/utility/util_find_root_newton_raphson.h 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
@@ -15,24 +15,20 @@
namespace Util
{
- template<typename T> class FindRootNewtonRaphson : public FindRootBase<T>
+ template<typename T>
+ class FindRootNewtonRaphson : public FindRootBase<T>
{
- protected:
-
- FindRootNewtonRaphson(const T& lo,
- const T& hi,
- const T& tol) : FindRootBase<T>(lo, hi, tol) { }
-
public:
-
virtual ~FindRootNewtonRaphson() { }
- public:
-
void function_derivative(const T& x, T& f, T& d) const { my_function_derivative(x, f, d); }
- private:
+ protected:
+ FindRootNewtonRaphson(const T& lo,
+ const T& hi,
+ const T& tol) : FindRootBase<T>(lo, hi, tol) { }
+ private:
virtual void my_function_derivative(const T& x, T& f, T& d) const = 0;
virtual T my_operation(void) const
Modified: sandbox/e_float/libs/e_float/src/utility/util_function.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/utility/util_function.h (original)
+++ sandbox/e_float/libs/e_float/src/utility/util_function.h 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
@@ -13,28 +13,22 @@
namespace Util
{
- template<typename T> class Function
+ template<typename T>
+ class Function
{
- private:
+ public:
+ virtual ~Function() { }
- const Function& operator=(const Function&);
- Function(const Function&);
+ T function(const T& x) const { return my_function(x); }
protected:
-
Function() { }
- public:
-
- virtual ~Function() { }
-
private:
-
virtual T my_function(const T&) const = 0;
- public:
-
- T function(const T& x) const { return my_function(x); }
+ const Function& operator=(const Function&);
+ Function(const Function&);
};
}
Modified: sandbox/e_float/libs/e_float/src/utility/util_function_derivative.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/utility/util_function_derivative.h (original)
+++ sandbox/e_float/libs/e_float/src/utility/util_function_derivative.h 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
@@ -14,56 +14,24 @@
#include <string>
#include <sstream>
- #include <utility/util_function_operation.h>
- #include <utility/util_lexical_cast.h>
+ #include "util_function_operation.h"
+ #include "util_lexical_cast.h"
+ #include "util_numeric_cast.h"
namespace Util
{
- template<typename T> class FunctionDerivative : public FunctionOperation<T>
+ template<typename T>
+ class FunctionDerivative : public FunctionOperation<T>
{
- private:
-
- static const T& my_tol(void)
- {
- static bool is_init = false;
-
- static T val_tol;
-
- if(!is_init)
- {
- is_init = true;
-
- // Set the default tolerance to be approximately 10^[-(digits10 * 1.15)/5].
- static const double tx = (static_cast<double>(std::numeric_limits<T>::digits10) * 1.15) / 5.0;
- static const std::size_t tn = static_cast<std::size_t>(tx + 0.5);
-
- std::stringstream ss;
-
- ss << "1E-" + Util::lexical_cast(tn);
-
- ss >> val_tol;
- }
-
- static const T the_tol = val_tol;
-
- return the_tol;
- }
+ public:
+ virtual ~FunctionDerivative() { }
protected:
-
const T my_x;
const T my_dx;
- protected:
-
FunctionDerivative(const T& x, const T& dx = my_tol()) : my_x(x), my_dx(dx) { }
- public:
-
- virtual ~FunctionDerivative() { }
-
- protected:
-
virtual T my_operation(void) const
{
FunctionOperation<T>::op_ok = true;
@@ -84,6 +52,19 @@
return ((fifteen_m1 - six_m2) + m3) / ten_dx1;
}
+
+ private:
+ static const T& my_tol(void)
+ {
+ // Set the default tolerance to be approximately 10^[-(digits10 * 1.15)/5].
+ static const double tx = (static_cast<double>(std::numeric_limits<T>::digits10) * 1.15) / 5.0;
+ static const std::size_t tn = static_cast<std::size_t>(tx + 0.5);
+
+ static const std::string str_tol("1E-" + Util::lexical_cast(tn));
+ static const T val_tol(Util::numeric_cast<T>(str_tol));
+
+ return val_tol;
+ }
};
}
Modified: sandbox/e_float/libs/e_float/src/utility/util_function_operation.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/utility/util_function_operation.h (original)
+++ sandbox/e_float/libs/e_float/src/utility/util_function_operation.h 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
@@ -15,24 +15,19 @@
namespace Util
{
- template<typename T> class FunctionOperation : public Function<T>
+ template<typename T>
+ class FunctionOperation : public Function<T>
{
- protected:
-
- mutable bool op_ok;
-
- protected:
-
- FunctionOperation() : op_ok(false) { }
-
public:
-
virtual ~FunctionOperation() { }
bool success(void) const { return op_ok; }
T operation(void) const { return my_operation(); }
protected:
+ mutable bool op_ok;
+
+ FunctionOperation() : op_ok(false) { }
virtual T my_operation(void) const = 0;
};
Modified: sandbox/e_float/libs/e_float/src/utility/util_interpolate.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/utility/util_interpolate.h (original)
+++ sandbox/e_float/libs/e_float/src/utility/util_interpolate.h 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
@@ -18,7 +18,9 @@
namespace Util
{
- template<typename T1, typename T2 = T1> struct linear_interpolate
+ template<typename T1,
+ typename T2 = T1>
+ struct linear_interpolate
{
static T2 interpolate(const T1& x, const std::vector<Util::point<T1, T2> >& points)
{
Modified: sandbox/e_float/libs/e_float/src/utility/util_noncopyable.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/utility/util_noncopyable.h (original)
+++ sandbox/e_float/libs/e_float/src/utility/util_noncopyable.h 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
@@ -17,12 +17,10 @@
class noncopyable
{
protected:
-
noncopyable() {}
- virtual ~noncopyable() {}
+ ~noncopyable() {}
private: // emphasize the following members are private
-
noncopyable(const noncopyable&);
const noncopyable& operator=(const noncopyable&);
};
Modified: sandbox/e_float/libs/e_float/src/utility/util_numeric_cast.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/utility/util_numeric_cast.h (original)
+++ sandbox/e_float/libs/e_float/src/utility/util_numeric_cast.h 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
@@ -16,7 +16,8 @@
namespace Util
{
- template<typename T> inline T numeric_cast(const std::string& str)
+ template<typename T>
+ inline T numeric_cast(const std::string& str)
{
std::stringstream ss;
ss << str;
@@ -25,7 +26,8 @@
return t;
}
- template<typename T> inline T numeric_cast(const char* const s)
+ template<typename T>
+ inline T numeric_cast(const char* const s)
{
std::stringstream ss;
ss << s;
Modified: sandbox/e_float/libs/e_float/src/utility/util_point.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/utility/util_point.h (original)
+++ sandbox/e_float/libs/e_float/src/utility/util_point.h 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
@@ -13,7 +13,9 @@
namespace Util
{
- template<typename T1, typename T2 = T1> struct point
+ template<typename T1,
+ typename T2 = T1>
+ struct point
{
T1 x;
T2 y;
@@ -21,9 +23,11 @@
point(const T1& X = T1(), const T2& Y = T2()) : x(X), y(Y) { }
};
- template<typename T1, typename T2> bool inline operator<(const point<T1, T2>& left, const point<T1, T2>& right)
+ template<typename T1,
+ typename T2>
+ inline bool operator<(const point<T1, T2>& left, const point<T1, T2>& right)
{
- return left.x < right.x;
+ return (left.x < right.x);
}
}
Modified: sandbox/e_float/libs/e_float/src/utility/util_power_x_pow_n.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/utility/util_power_x_pow_n.h (original)
+++ sandbox/e_float/libs/e_float/src/utility/util_power_x_pow_n.h 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
@@ -13,7 +13,8 @@
namespace Util
{
- template<typename T> inline T x_pow_n_template(const T& t, const INT64 p)
+ template<typename T>
+ inline T x_pow_n_template(const T& t, const INT64 p)
{
// Compute the pure power of typename T t^p. Binary splitting of the power is
// used. The resulting computational complexity has the order of log2[abs(p)].
Modified: sandbox/e_float/libs/e_float/src/utility/util_ranged_function_operation.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/utility/util_ranged_function_operation.h (original)
+++ sandbox/e_float/libs/e_float/src/utility/util_ranged_function_operation.h 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
@@ -15,25 +15,22 @@
namespace Util
{
- template<typename T> class RangedFunctionOperation : public FunctionOperation<T>
+ template<typename T>
+ class RangedFunctionOperation : public FunctionOperation<T>
{
- protected:
+ public:
+ virtual ~RangedFunctionOperation() { }
+ protected:
const T xlo;
const T xhi;
const T eps;
- protected:
-
RangedFunctionOperation(const T& lo,
const T& hi,
const T& tol) : xlo(lo),
xhi(hi),
eps(tol) { }
-
- public:
-
- virtual ~RangedFunctionOperation() { }
};
}
Modified: sandbox/e_float/libs/e_float/src/utility/util_timer.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/utility/util_timer.h (original)
+++ sandbox/e_float/libs/e_float/src/utility/util_timer.h 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
@@ -15,7 +15,7 @@
namespace Util
{
- struct timer : private noncopyable
+ struct timer : private Util::noncopyable
{
public:
timer(const double ofs = 0.0) : offset(ofs),
Modified: sandbox/e_float/libs/e_float/src/utility/util_trapezoid.h
==============================================================================
--- sandbox/e_float/libs/e_float/src/utility/util_trapezoid.h (original)
+++ sandbox/e_float/libs/e_float/src/utility/util_trapezoid.h 2012-02-06 14:24:33 EST (Mon, 06 Feb 2012)
@@ -11,22 +11,30 @@
#ifndef _UTIL_TRAPEZOID_2008_09_06_H_
#define _UTIL_TRAPEZOID_2008_09_06_H_
+ #include <limits>
#include "util_ranged_function_operation.h"
+ #include "util_lexical_cast.h"
+ #include "util_numeric_cast.h"
namespace Util
{
- template<typename T> class RecursiveTrapezoidRule : public RangedFunctionOperation<T>
+ template<typename T>
+ class RecursiveTrapezoidRule : public RangedFunctionOperation<T>
{
- protected:
+ public:
+ virtual ~RecursiveTrapezoidRule() { }
+ protected:
RecursiveTrapezoidRule(const T& lo, const T& hi, const T& tol) : RangedFunctionOperation<T>(lo, hi, tol) { }
- public:
-
- virtual ~RecursiveTrapezoidRule() { }
+ static const T& my_tol(void)
+ {
+ static const std::string str_tol("1E-" + Util::lexical_cast(std::numeric_limits<T>::digits10 / 2));
+ static const T val(Util::numeric_cast<T>(str_tol));
+ return val;
+ }
private:
-
virtual T my_operation(void) const
{
INT32 n = static_cast<INT32>(1);
@@ -58,7 +66,7 @@
const T ratio = I0 / I;
const T delta = ((ratio > one) ? (ratio - one) : (one - ratio));
- if((k > static_cast<INT32>(2)) && delta < RangedFunctionOperation<T>::eps)
+ if((k > static_cast<INT32>(3)) && (delta < RangedFunctionOperation<T>::eps))
{
FunctionOperation<T>::op_ok = true;
break;
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