diff --git a/xo-object2/cmake/xo_object2Config.cmake.in b/xo-object2/cmake/xo_object2Config.cmake.in index 36d3bb62..6773adb7 100644 --- a/xo-object2/cmake/xo_object2Config.cmake.in +++ b/xo-object2/cmake/xo_object2Config.cmake.in @@ -1,6 +1,7 @@ @PACKAGE_INIT@ include(CMakeFindDependencyMacro) +find_dependency(reflect) find_dependency(xo_gc) find_dependency(xo_printable2) find_dependency(subsys) diff --git a/xo-object2/include/xo/object2/number/GCObjectConversion_DFloat.hpp b/xo-object2/include/xo/object2/number/GCObjectConversion_DFloat.hpp new file mode 100644 index 00000000..8ce4b2b6 --- /dev/null +++ b/xo-object2/include/xo/object2/number/GCObjectConversion_DFloat.hpp @@ -0,0 +1,29 @@ +/** @file GCObjectConversion_DFloat.hpp + * + * @author Roland Conybeare, Jan 2026 + **/ + +#pragma once + +#include "DFloat.hpp" +#include "number/IGCObject_DFloat.hpp" +#include + +namespace xo { + namespace scm { + + template <> + struct GCObjectConversion { + static_assert(std::is_same_v); + + using AGCObject = xo::mm::AGCObject; + using AAllocator = xo::mm::AAllocator; + + static obj to_gco(obj mm, const double & x); + static double from_gco(obj mm, obj gco); + }; + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end GCObjectConversion_DFloat.hpp */ diff --git a/xo-object2/src/object2/CMakeLists.txt b/xo-object2/src/object2/CMakeLists.txt index 430e50c2..2902a4ee 100644 --- a/xo-object2/src/object2/CMakeLists.txt +++ b/xo-object2/src/object2/CMakeLists.txt @@ -2,6 +2,10 @@ set(SELF_LIB xo_object2) set(SELF_SRCS + init_object2.cpp + object2_register_types.cpp + object2_register_facets.cpp + GCObjectConversion_DFloat.cpp IGCObject_DArray.cpp IGCObject_DFloat.cpp IGCObject_DBoolean.cpp @@ -22,13 +26,11 @@ set(SELF_SRCS DInteger.cpp DBoolean.cpp DString.cpp - init_object2.cpp - object2_register_types.cpp - object2_register_facets.cpp ) xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS}) # note: deps here must also appear in cmake/xo_object2Config.cmake.in +xo_dependency(${SELF_LIB} reflect) xo_dependency(${SELF_LIB} xo_gc) xo_dependency(${SELF_LIB} xo_printable2) xo_dependency(${SELF_LIB} subsys) diff --git a/xo-object2/src/object2/GCObjectConversion_DFloat.cpp b/xo-object2/src/object2/GCObjectConversion_DFloat.cpp new file mode 100644 index 00000000..a99c68ce --- /dev/null +++ b/xo-object2/src/object2/GCObjectConversion_DFloat.cpp @@ -0,0 +1,41 @@ +/** @file GCObjectConversion_DFloat.cpp + * + * @author Roland Conybeare, Jan 2026 + **/ + +#include "number/GCObjectConversion_DFloat.hpp" +#include + +namespace xo { + using xo::mm::AGCObject; + + namespace scm { + + obj + GCObjectConversion::to_gco(obj mm, + const double & x) + { + return DFloat::box(mm, x); + } + + double + GCObjectConversion::from_gco(obj mm, + obj gco) + { + (void)mm; + + auto float_obj = obj::from(gco); + + if (!float_obj) { + throw std::runtime_error + (tostr("Object obj found where Float expected", + xtag("obj", gco))); + } + + return float_obj.data()->value(); + } + + } /*namespace scm*/ +} /*namespace xo*/ + +/* end GCObjectConversion_DFloat.cpp */