2015-04-20 17:51:00 +10:00
|
|
|
#include "introspection.hpp"
|
|
|
|
#include "tap.hpp"
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// simple test struct of scalars
|
|
|
|
struct foo
|
|
|
|
{
|
|
|
|
int a;
|
|
|
|
float b;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
|
|
|
// define introspection data
|
2018-08-05 14:42:02 +10:00
|
|
|
namespace cruft
|
2015-04-20 17:51:00 +10:00
|
|
|
{
|
|
|
|
template <>
|
|
|
|
struct type<foo>
|
|
|
|
{
|
|
|
|
typedef std::tuple<
|
|
|
|
field<foo,int,&foo::a>,
|
|
|
|
field<foo,float,&foo::b>
|
|
|
|
> fields;
|
|
|
|
};
|
|
|
|
|
|
|
|
template <> const std::string field<foo,int,&foo::a>::name = "a";
|
|
|
|
template <> const std::string field<foo,float,&foo::b>::name = "b";
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2015-05-01 02:49:19 +10:00
|
|
|
int main ()
|
2015-04-20 17:51:00 +10:00
|
|
|
{
|
2018-08-05 14:42:02 +10:00
|
|
|
cruft::TAP::logger tap;
|
2015-04-20 17:51:00 +10:00
|
|
|
|
2015-05-01 02:49:19 +10:00
|
|
|
// Ensure tuples are mapped to themselves with type_tuple::type
|
|
|
|
{
|
|
|
|
using src_t = std::tuple<int>;
|
2018-08-05 14:42:02 +10:00
|
|
|
using dst_t = typename cruft::type_tuple<src_t>::type;
|
2015-05-01 02:49:19 +10:00
|
|
|
|
|
|
|
tap.expect (std::is_same<src_t, dst_t>::value, "static identity type_tuple");
|
|
|
|
}
|
|
|
|
|
|
|
|
// Check member extraction from a simple POD structure.
|
|
|
|
{
|
|
|
|
foo d_foo { 7, 42.0 };
|
2018-08-05 14:42:02 +10:00
|
|
|
auto f_tuple = cruft::as_tuple (d_foo);
|
2015-05-01 02:49:19 +10:00
|
|
|
|
2018-08-05 14:42:02 +10:00
|
|
|
tap.expect (cruft::equal (d_foo.a, std::get<0> (f_tuple)) &&
|
|
|
|
cruft::equal (d_foo.b, std::get<1> (f_tuple)),
|
2015-05-01 02:49:19 +10:00
|
|
|
"dynamic member access after conversion to tuple");
|
|
|
|
}
|
2017-05-22 13:55:21 +10:00
|
|
|
|
|
|
|
return tap.status ();
|
2015-04-20 17:51:00 +10:00
|
|
|
}
|