From 1ec776130990009d93b54e54254f8d53626b065f Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Sat, 7 Mar 2015 03:20:28 +1100 Subject: [PATCH] region: add calls to debug::sanity --- region.cpp | 72 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 40 insertions(+), 32 deletions(-) diff --git a/region.cpp b/region.cpp index 296b6a1c..673b758c 100644 --- a/region.cpp +++ b/region.cpp @@ -31,7 +31,9 @@ template util::region::region (extent_t _extent): region (point_t::ORIGIN, _extent) -{ ; } +{ + debug::sanity (*this); +} //----------------------------------------------------------------------------- @@ -40,7 +42,9 @@ util::region::region (point_t _p, extent_t _e): p (_p), e (_e) -{ ; } +{ + debug::sanity (*this); +} //----------------------------------------------------------------------------- @@ -48,7 +52,9 @@ template util::region::region (point_t _a, point_t _b): region (_a, _b - _a) -{ ; } +{ + debug::sanity (*this); +} //----------------------------------------------------------------------------- @@ -65,7 +71,7 @@ util::region::region (position_type _p, size_type _e): region (point_t {_p}, extent_t {_e}) { - + debug::sanity (*this); } @@ -266,9 +272,7 @@ util::region util::region::inset (T mag) { // ensure we have enough space to inset - CHECK (std::all_of (std::begin (e.data), - std::end (e.data), - [mag] (auto i) { return i >= 2 * mag; })); + CHECK (min (e) >= 2 * mag); return { p + mag, @@ -346,18 +350,6 @@ util::region::operator== (region rhs) const } -//----------------------------------------------------------------------------- -template -void -util::region::sanity (void) const { - CHECK_GE (e.area (), 0); - - if (std::is_floating_point::value) { - CHECK_GE (min (e), 0); - } -} - - ///---------------------------------------------------------------------------- /// The largest specifiable finite region. /// @@ -388,18 +380,34 @@ util::operator<< (std::ostream &os, const util::region &rhs) { } -//----------------------------------------------------------------------------- -namespace util { -#define INSTANTIATE_S_T(S,T) \ - template struct region; \ - template std::ostream& operator<< (std::ostream&, const region&); +/////////////////////////////////////////////////////////////////////////////// +namespace debug { + template + struct validator { + static bool is_valid (const util::region &r) + { + CHECK_GE (r.area (), 0); + CHECK_GE (min (r.e), 0); -#define INSTANTIATE(T) \ - INSTANTIATE_S_T(2,T) \ - INSTANTIATE_S_T(3,T) - - INSTANTIATE(uint32_t) - INSTANTIATE(uint64_t) - INSTANTIATE(float) - INSTANTIATE(double) + return r.area () >= 0 && min (r.e) >= 0; + } + }; } + + +/////////////////////////////////////////////////////////////////////////////// +#define INSTANTIATE_S_T(S,T) \ +namespace util { \ + template struct region; \ + template std::ostream& operator<< (std::ostream&, const region&); \ +} \ +namespace debug { template struct debug::validator; } + +#define INSTANTIATE(T) \ +INSTANTIATE_S_T(2,T) \ +INSTANTIATE_S_T(3,T) + +INSTANTIATE(uint32_t) +INSTANTIATE(uint64_t) +INSTANTIATE(float) +INSTANTIATE(double)