2015-04-20 17:51:00 +10:00
|
|
|
#include "introspection.hpp"
|
2019-04-16 10:17:53 +10:00
|
|
|
#include "std.hpp"
|
|
|
|
|
2015-04-20 17:51:00 +10:00
|
|
|
#include "tap.hpp"
|
2019-04-16 10:17:53 +10:00
|
|
|
#include <iostream>
|
2015-04-20 17:51:00 +10:00
|
|
|
|
2019-04-16 10:17:53 +10:00
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-04-20 17:51:00 +10:00
|
|
|
// simple test struct of scalars
|
|
|
|
struct foo
|
|
|
|
{
|
|
|
|
int a;
|
|
|
|
float b;
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
//-----------------------------------------------------------------------------
|
2019-04-16 10:17:53 +10:00
|
|
|
namespace bar {
|
|
|
|
struct qux {
|
|
|
|
short c;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-28 13:48:45 +10:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
|
|
|
template <typename ValueT>
|
|
|
|
struct templated_with_type { ValueT inner; };
|
|
|
|
|
|
|
|
|
|
|
|
template <int ValueV>
|
|
|
|
struct templated_with_value { };
|
|
|
|
|
|
|
|
|
|
|
|
enum enumeration_t { FOO };
|
|
|
|
|
|
|
|
template <enumeration_t EnumV>
|
|
|
|
struct templated_with_enum { };
|
|
|
|
|
|
|
|
|
2019-04-16 10:17:53 +10:00
|
|
|
///////////////////////////////////////////////////////////////////////////////
|
2015-04-20 17:51:00 +10:00
|
|
|
// 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
|
|
|
|
2019-04-16 10:17:53 +10:00
|
|
|
tap.expect_eq (cruft::view (cruft::type_name<i08> ()), "i08", "i08 type_name");
|
|
|
|
tap.expect_eq (cruft::view (cruft::type_name<i16> ()), "i16", "i16 type_name");
|
|
|
|
tap.expect_eq (cruft::view (cruft::type_name<i32> ()), "i32", "i32 type_name");
|
|
|
|
tap.expect_eq (cruft::view (cruft::type_name<i64> ()), "i64", "i64 type_name");
|
|
|
|
|
|
|
|
tap.expect_eq (cruft::view (cruft::type_name<u08> ()), "u08", "u08 type_name");
|
|
|
|
tap.expect_eq (cruft::view (cruft::type_name<u16> ()), "u16", "u16 type_name");
|
|
|
|
tap.expect_eq (cruft::view (cruft::type_name<u32> ()), "u32", "u32 type_name");
|
|
|
|
tap.expect_eq (cruft::view (cruft::type_name<u64> ()), "u64", "u64 type_name");
|
|
|
|
|
|
|
|
tap.expect_eq (cruft::view (cruft::type_name<f32> ()), "f32", "f32 type_name");
|
|
|
|
tap.expect_eq (cruft::view (cruft::type_name<f64> ()), "f64", "f64 type_name");
|
|
|
|
|
|
|
|
tap.expect_eq (cruft::view (cruft::type_name<foo> ()), "foo", "struct type_name");
|
|
|
|
tap.expect_eq (cruft::view (cruft::type_name<bar::qux> ()), "qux", "namespaced struct type_name");
|
|
|
|
|
2019-05-28 13:48:45 +10:00
|
|
|
tap.expect_eq (
|
|
|
|
cruft::type_name<templated_with_type<int>> (),
|
|
|
|
std::string_view {"templated_with_type<int>"},
|
|
|
|
"templated_with_type"
|
|
|
|
);
|
|
|
|
|
|
|
|
tap.expect_eq (
|
|
|
|
cruft::type_name<templated_with_value<-1>> (),
|
|
|
|
std::string_view {"templated_with_value<-1>"},
|
|
|
|
"templated_with_value"
|
|
|
|
);
|
|
|
|
|
|
|
|
tap.expect_eq (
|
|
|
|
cruft::type_name<templated_with_enum<FOO>> (),
|
|
|
|
std::string_view {"templated_with_enum<FOO>"},
|
|
|
|
"templated_with_enum"
|
|
|
|
);
|
|
|
|
|
2017-05-22 13:55:21 +10:00
|
|
|
return tap.status ();
|
2015-04-20 17:51:00 +10:00
|
|
|
}
|