From 99ba406b4d1d0b202e7ee5ca1cf1256f367565a0 Mon Sep 17 00:00:00 2001 From: Danny Robson Date: Fri, 6 Mar 2015 01:15:52 +1100 Subject: [PATCH] coord: move base coord class into main namespace --- colour.hpp | 6 +- detail/coord.hpp => coord.hpp | 118 +++++++++++++++++----------------- extent.hpp | 6 +- point.hpp | 6 +- vector.hpp | 6 +- 5 files changed, 72 insertions(+), 70 deletions(-) rename detail/coord.hpp => coord.hpp (82%) diff --git a/colour.hpp b/colour.hpp index ac6b5ac8..32061391 100644 --- a/colour.hpp +++ b/colour.hpp @@ -20,7 +20,7 @@ #ifndef __UTIL_COLOUR_HPP #define __UTIL_COLOUR_HPP -#include "detail/coord.hpp" +#include "coord.hpp" #include "json/tree.hpp" @@ -29,8 +29,8 @@ namespace util { /// An RGBA colour POD type. template - struct colour : public detail::coord<4,T,detail::rgba> { - using detail::coord<4,T,detail::rgba>::coord; + struct colour : public coord<4,T,detail::rgba> { + using coord<4,T,detail::rgba>::coord; static const colour WHITE; static const colour BLACK; diff --git a/detail/coord.hpp b/coord.hpp similarity index 82% rename from detail/coord.hpp rename to coord.hpp index 2d4517e3..c22994d5 100644 --- a/detail/coord.hpp +++ b/coord.hpp @@ -20,8 +20,8 @@ #ifndef __UTIL_COORD_HPP #define __UTIL_COORD_HPP -#include "../preprocessor.hpp" -#include "../platform.hpp" +#include "platform.hpp" +#include "preprocessor.hpp" #include #include @@ -30,10 +30,6 @@ #include namespace util { - template class point; - template class extent; - template class vector; - namespace detail { /////////////////////////////////////////////////////////////////////// // tags for accessor names @@ -207,58 +203,64 @@ namespace util { coord_base<4,T,tags...> ({ v0, v1, v2, v3 }) { ; } }; - - ///////////////////////////////////////////////////////////////////////// - template - struct coord : public coord_init { - static_assert (S > 0, "coord dimensions must be strictly positive"); - - typedef T value_type; - static constexpr size_t dimension = S; - static constexpr size_t elements = S; - - size_t size (void) const { return S; } - - // constructors - using coord_init::coord_init; - coord () = default; - - explicit coord (T v) - { std::fill (std::begin (this->data), std::end (this->data), v); } - - coord (const coord &rhs) = default; - coord& operator= (const coord &rhs) = default; - - // element accessors - T& operator[] (size_t i) { return this->data[i]; } - T operator[] (size_t i) const { return this->data[i]; } - - const T* begin (void) const { return std::begin (this->data); } - const T* end (void) const { return std::end (this->data); } - - T* begin (void) { return std::begin (this->data); } - T* end (void) { return std::end (this->data); } - }; - - - /////////////////////////////////////////////////////////////////////// - template < - size_t S, - typename T, - template class A, - template class B - > - struct coord_traits { }; - - - template struct coord_traits { typedef extent result; }; - template struct coord_traits { typedef extent result; }; - template struct coord_traits { typedef point result; }; - template struct coord_traits { typedef point result; }; - template struct coord_traits { typedef vector result; }; } + ///////////////////////////////////////////////////////////////////////// + template + struct coord : public detail::coord_init { + static_assert (S > 0, "coord dimensions must be strictly positive"); + + typedef T value_type; + static constexpr size_t dimension = S; + static constexpr size_t elements = S; + + size_t size (void) const { return S; } + + // constructors + using detail::coord_init::coord_init; + coord () = default; + + explicit coord (T v) + { std::fill (std::begin (this->data), std::end (this->data), v); } + + coord (const coord &rhs) = default; + coord& operator= (const coord &rhs) = default; + + // element accessors + T& operator[] (size_t i) { return this->data[i]; } + T operator[] (size_t i) const { return this->data[i]; } + + const T* begin (void) const { return std::begin (this->data); } + const T* end (void) const { return std::end (this->data); } + + T* begin (void) { return std::begin (this->data); } + T* end (void) { return std::end (this->data); } + }; + + + /////////////////////////////////////////////////////////////////////// + // operation traits + template class point; + template class extent; + template class vector; + + template < + size_t S, + typename T, + template class A, + template class B + > + struct coord_traits { }; + + + template struct coord_traits { typedef extent result; }; + template struct coord_traits { typedef extent result; }; + template struct coord_traits { typedef point result; }; + template struct coord_traits { typedef point result; }; + template struct coord_traits { typedef vector result; }; + + /////////////////////////////////////////////////////////////////////////// // vector operators #define ELEMENT_OP(OP) \ @@ -268,10 +270,10 @@ namespace util { template class A, \ template class B \ > \ - typename detail::coord_traits::result \ + typename coord_traits::result \ operator OP (A a, B b) \ { \ - typename detail::coord_traits::result out; \ + typename coord_traits::result out; \ for (size_t i = 0; i < S; ++i) \ out[i] = a[i] OP b[i]; \ return out; \ @@ -283,7 +285,7 @@ namespace util { template class A, \ template class B \ > \ - typename detail::coord_traits::result& \ + typename coord_traits::result& \ operator PASTE(OP,=) (A& a, B b) \ { \ for (size_t i = 0; i < S; ++i) \ diff --git a/extent.hpp b/extent.hpp index 62723d19..3ee9d631 100644 --- a/extent.hpp +++ b/extent.hpp @@ -20,7 +20,7 @@ #ifndef __UTIL_EXTENT_HPP #define __UTIL_EXTENT_HPP -#include "detail/coord.hpp" +#include "coord.hpp" #include "vector.hpp" #include @@ -30,9 +30,9 @@ namespace util { * A pure two-dimensional size, without positioning */ template - struct extent : public detail::coord + struct extent : public coord { - using detail::coord::coord; + using coord::coord; extent () = default; extent (vector); diff --git a/point.hpp b/point.hpp index 6bd94454..d4285a1c 100644 --- a/point.hpp +++ b/point.hpp @@ -22,7 +22,7 @@ #include "extent.hpp" #include "vector.hpp" -#include "detail/coord.hpp" +#include "coord.hpp" #include #include @@ -32,9 +32,9 @@ namespace util { /// An n-dimensional position in space. template - struct point : public detail::coord + struct point : public coord { - using detail::coord::coord; + using coord::coord; // point operators template typename std::common_type::type distance (const point &) const; diff --git a/vector.hpp b/vector.hpp index f1ec03c5..70838e9c 100644 --- a/vector.hpp +++ b/vector.hpp @@ -21,7 +21,7 @@ #define __UTIL_VECTOR_HPP #include "json/tree.hpp" -#include "detail/coord.hpp" +#include "coord.hpp" #include #include @@ -29,8 +29,8 @@ namespace util { template - struct vector : public detail::coord { - using detail::coord::coord; + struct vector : public coord { + using coord::coord; bool is_zero (void) const;