00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef SGE_MATH_BASIC_SEQUENCE_HPP_INCLUDED
00022 #define SGE_MATH_BASIC_SEQUENCE_HPP_INCLUDED
00023
00024 #include "../config.h"
00025 #include "../array_facade.hpp"
00026 #include "../no_initialization_tag.hpp"
00027 #ifndef SGE_HAVE_VARIADIC_TEMPLATES
00028 #include <boost/static_assert.hpp>
00029 #include <boost/preprocessor/enum_params.hpp>
00030 #include <boost/preprocessor/repetition/repeat.hpp>
00031 #include <boost/preprocessor/arithmetic/add.hpp>
00032 #endif
00033 #include <boost/array.hpp>
00034 #include <iosfwd>
00035 #include <cstddef>
00036
00037 #if !defined(SGE_HAVE_VARIADIC_TEMPLATES) && !defined(SGE_MATH_VECTOR_MAX_SIZE)
00038 #define SGE_MATH_BASIC_SEQUENCE_MAX_SIZE 4
00039 #endif
00040
00041 namespace sge
00042 {
00043 namespace math
00044 {
00045
00046 namespace detail
00047 {
00048 typedef std::size_t dim_type;
00049 }
00050
00051 template<
00052 typename T,
00053 detail::dim_type Dim,
00054 template<typename, detail::dim_type> class Policy>
00055 class basic_sequence
00056 : public array_facade<
00057 basic_sequence<T, Dim, Policy>,
00058 detail::dim_type,
00059 T&,
00060 T*,
00061 T*,
00062 T const*>,
00063 public Policy<T, Dim> {
00064 private:
00065 typedef array_facade<
00066 basic_sequence<T, Dim, Policy>,
00067 detail::dim_type,
00068 T&,
00069 T*,
00070 T*,
00071 T const*> base_type;
00072 public:
00073 typedef T value_type;
00074 typedef typename base_type::reference reference;
00075 typedef typename base_type::const_reference const_reference;
00076 typedef typename base_type::pointer pointer;
00077 typedef typename base_type::const_pointer const_pointer;
00078 typedef std::ptrdiff_t difference_type;
00079 typedef typename base_type::size_type size_type;
00080 typedef typename base_type::iterator iterator;
00081 typedef typename base_type::const_iterator const_iterator;
00082 typedef typename base_type::reverse_iterator reverse_iterator;
00083 typedef typename base_type::const_reverse_iterator const_reverse_iterator;
00084
00085 explicit basic_sequence(
00086 no_initialization_tag);
00087
00088 #ifdef SGE_HAVE_VARIADIC_TEMPLATES
00089 template<typename... Args>
00090 explicit basic_sequence(
00091 Args... args);
00092 #else
00093 #define SGE_MATH_BASIC_SEQUENCE_CTOR_DECL(z, n, text)\
00094 basic_sequence(\
00095 BOOST_PP_ENUM_PARAMS(\
00096 BOOST_PP_ADD(n,1),\
00097 T const& param));
00098 BOOST_PP_REPEAT(SGE_MATH_BASIC_SEQUENCE_MAX_SIZE, SGE_MATH_BASIC_SEQUENCE_CTOR_DECL, void)
00099
00100 #undef SGE_MATH_BASIC_SEQUENCE_CTOR_DECL
00101 #endif
00102
00103 #define SGE_MATH_BINARY_OP_ASSIGN_DECL(x) \
00104 basic_sequence & operator x ( \
00105 basic_sequence const &r);
00106
00107 SGE_MATH_BINARY_OP_ASSIGN_DECL(+=)
00108 SGE_MATH_BINARY_OP_ASSIGN_DECL(-=)
00109 SGE_MATH_BINARY_OP_ASSIGN_DECL(*=)
00110 SGE_MATH_BINARY_OP_ASSIGN_DECL(/=)
00111 SGE_MATH_BINARY_OP_ASSIGN_DECL(%=)
00112
00113 #undef SGE_MATH_BINARY_OP_ASSIGN_DECL
00114
00115 #define SGE_MATH_BINARY_OP_SCALAR_ASSIGN_DECL(x) \
00116 basic_sequence & operator x ( \
00117 const_reference r);
00118
00119 SGE_MATH_BINARY_OP_SCALAR_ASSIGN_DECL(+=)
00120 SGE_MATH_BINARY_OP_SCALAR_ASSIGN_DECL(-=)
00121 SGE_MATH_BINARY_OP_SCALAR_ASSIGN_DECL(*=)
00122 SGE_MATH_BINARY_OP_SCALAR_ASSIGN_DECL(/=)
00123 SGE_MATH_BINARY_OP_SCALAR_ASSIGN_DECL(%=)
00124
00125 #undef SGE_MATH_BINARY_OP_SCALAR_ASSIGN_DECL
00126
00127 pointer data();
00128 const_pointer data() const;
00129
00130 size_type size() const;
00131 private:
00132 #ifdef SGE_HAVE_VARIADIC_TEMPLATES
00133 template<typename... Args>
00134 void init(
00135 const_reference arg1,
00136 Args... args);
00137
00138 template<typename... Args>
00139 void init_where(
00140 size_type pos,
00141 const_reference arg1,
00142 Args... args);
00143
00144 void init_where(
00145 size_type pos,
00146 const_reference arg);
00147 #endif
00148
00149 typedef boost::array<
00150 value_type,
00151 Dim> internal_type;
00152 internal_type data_;
00153 };
00154
00155 #define SGE_MATH_UNARY_OP_DECL(x) \
00156 template< \
00157 typename T, \
00158 detail::dim_type Dim, \
00159 template<typename, detail::dim_type> class Policy> \
00160 basic_sequence<T, Dim, Policy> \
00161 operator x( \
00162 basic_sequence<T, Dim, Policy> l);
00163
00164 SGE_MATH_UNARY_OP_DECL(+)
00165 SGE_MATH_UNARY_OP_DECL(-)
00166
00167 #undef SGE_MATH_UNARY_OP_DECL
00168
00169 #define SGE_MATH_BINARY_OP_DECL(x) \
00170 template< \
00171 typename T, \
00172 detail::dim_type Dim, \
00173 template<typename, detail::dim_type> class Policy> \
00174 basic_sequence<T, Dim, Policy> operator x ( \
00175 basic_sequence<T, Dim, Policy> l, \
00176 basic_sequence<T, Dim, Policy> const &r);
00177
00178 SGE_MATH_BINARY_OP_DECL(+)
00179 SGE_MATH_BINARY_OP_DECL(-)
00180 SGE_MATH_BINARY_OP_DECL(*)
00181 SGE_MATH_BINARY_OP_DECL(/)
00182 SGE_MATH_BINARY_OP_DECL(%)
00183
00184 #undef SGE_MATH_BINARY_OP_DECL
00185
00186 #define SGE_MATH_BINARY_OP_SCALAR_DECL(x) \
00187 template< \
00188 typename T, \
00189 detail::dim_type Dim, \
00190 template<typename, detail::dim_type> class Policy> \
00191 basic_sequence<T, Dim, Policy> operator x ( \
00192 basic_sequence<T, Dim, Policy> l, \
00193 typename basic_sequence<T, Dim, Policy>::const_reference r);
00194
00195 SGE_MATH_BINARY_OP_SCALAR_DECL(+)
00196 SGE_MATH_BINARY_OP_SCALAR_DECL(-)
00197 SGE_MATH_BINARY_OP_SCALAR_DECL(*)
00198 SGE_MATH_BINARY_OP_SCALAR_DECL(/)
00199 SGE_MATH_BINARY_OP_SCALAR_DECL(%)
00200
00201 #undef SGE_MATH_BINARY_OP_SCALAR_DECL
00202
00203 #define SGE_MATH_BINARY_OP_SCALAR_LEFT_DECL(x) \
00204 template< \
00205 typename T, \
00206 detail::dim_type Dim, \
00207 template<typename, detail::dim_type> class Policy> \
00208 basic_sequence<T, Dim, Policy> operator x ( \
00209 typename basic_sequence<T, Dim, Policy>::const_reference l, \
00210 basic_sequence<T, Dim, Policy> r);
00211
00212 SGE_MATH_BINARY_OP_SCALAR_LEFT_DECL(+)
00213 SGE_MATH_BINARY_OP_SCALAR_LEFT_DECL(-)
00214 SGE_MATH_BINARY_OP_SCALAR_LEFT_DECL(*)
00215
00216 #undef SGE_MATH_BINARY_OP_SCALAR_LEFT_DECL
00217
00218 template<
00219 typename T,
00220 detail::dim_type Dim,
00221 template<typename, detail::dim_type> class Policy> \
00222 bool operator==(
00223 basic_sequence<T, Dim, Policy> const &,
00224 basic_sequence<T, Dim, Policy> const &);
00225
00226 template<
00227 typename T,
00228 detail::dim_type Dim,
00229 template<typename, detail::dim_type> class Policy> \
00230 bool operator!=(
00231 basic_sequence<T, Dim, Policy> const &,
00232 basic_sequence<T, Dim, Policy> const &);
00233
00234 template<
00235 typename D,
00236 typename S,
00237 detail::dim_type Dim,
00238 template<typename, detail::dim_type> class Policy> \
00239 basic_sequence<D, Dim, Policy>
00240 structure_cast(basic_sequence<S, Dim, Policy> const &);
00241
00242 template<
00243 typename CharT,
00244 typename CharTraits,
00245 typename T,
00246 detail::dim_type Dim,
00247 template<typename, detail::dim_type> class Policy>
00248 std::basic_ostream<CharT, CharTraits> &
00249 operator << (
00250 std::basic_ostream<CharT, CharTraits> &,
00251 basic_sequence<T, Dim, Policy> const &);
00252
00253 }
00254 }
00255
00256 #endif