diff --git a/CMakeLists.txt b/CMakeLists.txt index 6a365f30..4763965c 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -39,6 +39,7 @@ add_subdirectory(docs) # ---------------------------------------------------------------- # dependencies +xo_headeronly_dependency(${SELF_LIB} xo_reflectutil) xo_headeronly_dependency(${SELF_LIB} xo_flatstring) #xo_headeronly_dependency(${SELF_LIB} randomgen) # etc.. diff --git a/include/xo/ratio/ratio_reflect.hpp b/include/xo/ratio/ratio_reflect.hpp new file mode 100644 index 00000000..2d7e8da8 --- /dev/null +++ b/include/xo/ratio/ratio_reflect.hpp @@ -0,0 +1,25 @@ +/** @file ratio_reflect.hpp + * + * Author: Roland Conybeare + **/ + +#pragma once + +#include "xo/reflectutil/reflect_struct_info.hpp" +#include "ratio.hpp" +//#include + +namespace xo { + namespace reflect { + template + REFLECT_BASE_STRUCT_INFO_TBODY(xo::ratio::ratio, 2); + + template + REFLECT_STRUCT_MEMBER_INFO_TBODY(xo::ratio::ratio, 0, num); + + template + REFLECT_STRUCT_MEMBER_INFO_TBODY(xo::ratio::ratio, 1, den); + } +} + +/** end ratio_reflect.hpp **/ diff --git a/utest/CMakeLists.txt b/utest/CMakeLists.txt index 052961ec..2aac113a 100644 --- a/utest/CMakeLists.txt +++ b/utest/CMakeLists.txt @@ -3,6 +3,7 @@ set(SELF_EXE utest.ratio) set(SELF_SRCS ratio_utest_main.cpp + ratio_reflect.test.cpp ratio.test.cpp) if (ENABLE_TESTING) @@ -14,6 +15,7 @@ if (ENABLE_TESTING) # dependencies.. xo_self_headeronly_dependency(${SELF_EXE} xo_ratio) + xo_dependency(${SELF_EXE} reflect) xo_dependency(${SELF_EXE} randomgen) xo_dependency(${SELF_EXE} indentlog) xo_external_target_dependency(${SELF_EXE} Catch2 Catch2::Catch2) diff --git a/utest/ratio_reflect.test.cpp b/utest/ratio_reflect.test.cpp new file mode 100644 index 00000000..2e6b78ee --- /dev/null +++ b/utest/ratio_reflect.test.cpp @@ -0,0 +1,32 @@ +/* @file ratio_reflect.test.cpp */ + +#include "xo/ratio/ratio_reflect.hpp" +#include "xo/reflect/reflect_struct.hpp" +#include + +namespace xo { + namespace ut { + TEST_CASE("ratio_reflect", "[ratio][reflect]") { + using xo::reflect::reflect_struct; + using xo::reflect::TypeDescrBase; + using xo::reflect::TypeDescr; + using xo::ratio::ratio; + + /* verify ratio reflection */ + + TypeDescr td = reflect_struct>(); + + REQUIRE(td->is_struct()); + REQUIRE(td->metatype() == xo::reflect::Metatype::mt_struct); + REQUIRE(td->n_child(nullptr) == 2); + REQUIRE(td->struct_member(0).member_name() == "num"); + REQUIRE(td->struct_member(0).get_member_td()->short_name() == "long int"); + REQUIRE(td->struct_member(1).member_name() == "den"); + REQUIRE(td->struct_member(1).get_member_td()->short_name() == "long int"); + + TypeDescrBase::print_reflected_types(std::cerr); + } + } /*namespace ut*/ +} /*namespace xo*/ + +/* end ratio_reflect.test.cpp */