1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
| //! \file boostpp_test.cpp
//! @brief testing boost pp
#include <boost/static_assert.hpp>
#include <boost/preprocessor/arithmetic/inc.hpp>
#include <boost/preprocessor/comparison/not_equal.hpp>
#include <boost/preprocessor/repetition/for.hpp>
#include <boost/preprocessor/tuple/elem.hpp>
#include <boost/preprocessor/array/elem.hpp>
#include <boost/preprocessor/array/size.hpp>
#include <boost/preprocessor/cat.hpp>
#include <boost/preprocessor/repetition/repeat_from_to.hpp>
#include <boost/preprocessor/control/iif.hpp>
#include <boost/preprocessor/comparison/equal.hpp>
namespace kazu
{
template<typename typeT>
struct blast
{
typedef typeT scalar;
class vec2;
class vec3;
class vec4;
};
} //namespace kazu
template<typename typeT, int sizeT>
struct vec_struct;
//---------------------------------------------------------------------------
#define STRUCT_SIZE_ASSERT(x) BOOST_STATIC_ASSERT(1 < x && x <= 4)
#define VEC_POSITION_ARRAY (4, (x, y, z, w))
#define VEC_NUM_ARRAY (4, (_0, _1, _2, _3))
#define VEC_TEXCOORD_ARRAY (4, (s, t, u, v))
#define VEC_COLOR_ARRAY4 (4, (r, g, b, a))
#define VEC_COLOR_ARRAY2 (2, (i, a))
#define ELEMENT_ARRAYS (3, (VEC_POSITION_ARRAY, VEC_NUM_ARRAY, VEC_TEXCOORD_ARRAY))
#define COLOR_ARRAYS (VEC_COLOR_ARRAY2, VEC_COLOR_ARRAY4)
//---------------------------------------------------------------------------
#define GEN_STRUCT_REP_MACRO(z, n, param) \
BOOST_PP_TUPLE_ELEM(2, 0, param) \
BOOST_PP_ARRAY_ELEM(n, BOOST_PP_TUPLE_ELEM(2, 1, param)); \
//resolves to type array(n);
#define GEN_STRUCT(type, size, array) \
struct { \
BOOST_PP_REPEAT_FROM_TO( \
0, \
size, \
GEN_STRUCT_REP_MACRO, \
(type, array) \
) \
} \
//resolves to struct { type array(0); ... };
GEN_STRUCT(float, 3, VEC_POSITION_ARRAY); //resolves to struct { float x; float y; float z; };
//---------------------------------------------------------------------------
#define GEN_COLOR_STRUCT(type, size, colors) \
BOOST_PP_IIF( \
BOOST_PP_EQUAL(size, 2), \
GEN_STRUCT(type, size, \
BOOST_PP_TUPLE_ELEM(2, 0, colors)), \
GEN_STRUCT(type, size, \
BOOST_PP_TUPLE_ELEM(2, 1, colors)) \
) \
//--------------------------------------
#define GEN_UNION_REP_MACRO(z, n, param) \
GEN_STRUCT( \
BOOST_PP_TUPLE_ELEM(3, 0, param), \
BOOST_PP_TUPLE_ELEM(3, 1, param), \
BOOST_PP_ARRAY_ELEM(n, \
BOOST_PP_TUPLE_ELEM(3, 2, param) \
) \
); \
#define GEN_UNION(type, size, arrays, colors) \
union { \
type _a[size]; \
BOOST_PP_REPEAT_FROM_TO( \
0, \
BOOST_PP_ARRAY_SIZE(arrays), \
GEN_UNION_REP_MACRO, \
(type, size, arrays) \
) \
GEN_COLOR_STRUCT(type, size, colors); \
} \
GEN_UNION(float, 3, ELEMENT_ARRAYS, COLOR_ARRAYS);
GEN_UNION(float, 2, ELEMENT_ARRAYS, COLOR_ARRAYS);
//---------------------------------------------------------------------------
#define GEN_TPL_STRUCT(type, name, size, arrays, colors) \
struct name<type, size> { \
GEN_UNION(type, size, arrays, colors); \
} \
//---------------------------------------------------------------------------
template<typename typeT>
GEN_TPL_STRUCT(typeT, vec_struct, 2, ELEMENT_ARRAYS, COLOR_ARRAYS);
template<typename typeT>
GEN_TPL_STRUCT(typeT, vec_struct, 3, ELEMENT_ARRAYS, COLOR_ARRAYS);
template<typename typeT>
GEN_TPL_STRUCT(typeT, vec_struct, 4, ELEMENT_ARRAYS, COLOR_ARRAYS);
//---------------------------------------------------------------------------
#define GEN_TPL_CONCRETE_STRUCT(type, name, size, tpl) \
struct name##size : public tpl<type, size> \
template<typename typeT>
GEN_TPL_CONCRETE_STRUCT(kazu::blast<typeT>::scalar, kazu::blast<typeT>::vec, 2, vec_struct)
{
};
template<typename typeT>
GEN_TPL_CONCRETE_STRUCT(kazu::blast<typeT>::scalar, kazu::blast<typeT>::vec, 3, vec_struct)
{
};
template<typename typeT>
GEN_TPL_CONCRETE_STRUCT(kazu::blast<typeT>::scalar, kazu::blast<typeT>::vec, 4, vec_struct)
{
};
//---------------------------------------------------------------------------
static void test_it()
{
kazu::blast<float>::vec2 fv2;
fv2.x = 0.0f;
fv2.y = 1.0f;
}
//--------------------------------------------------------------------------- |
Partager