xo-object2: GCObjectConversion for double (via DFloat)

This commit is contained in:
Roland Conybeare 2026-01-25 10:13:22 -05:00
commit 6605b459f3
4 changed files with 76 additions and 3 deletions

View file

@ -1,6 +1,7 @@
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
find_dependency(reflect)
find_dependency(xo_gc)
find_dependency(xo_printable2)
find_dependency(subsys)

View file

@ -0,0 +1,29 @@
/** @file GCObjectConversion_DFloat.hpp
*
* @author Roland Conybeare, Jan 2026
**/
#pragma once
#include "DFloat.hpp"
#include "number/IGCObject_DFloat.hpp"
#include <xo/gc/GCObjectConversion.hpp>
namespace xo {
namespace scm {
template <>
struct GCObjectConversion<double> {
static_assert(std::is_same_v<double, DFloat::value_type>);
using AGCObject = xo::mm::AGCObject;
using AAllocator = xo::mm::AAllocator;
static obj<AGCObject> to_gco(obj<AAllocator> mm, const double & x);
static double from_gco(obj<AAllocator> mm, obj<AGCObject> gco);
};
} /*namespace scm*/
} /*namespace xo*/
/* end GCObjectConversion_DFloat.hpp */

View file

@ -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)

View file

@ -0,0 +1,41 @@
/** @file GCObjectConversion_DFloat.cpp
*
* @author Roland Conybeare, Jan 2026
**/
#include "number/GCObjectConversion_DFloat.hpp"
#include <xo/indentlog/print/tag.hpp>
namespace xo {
using xo::mm::AGCObject;
namespace scm {
obj<AGCObject>
GCObjectConversion<double>::to_gco(obj<AAllocator> mm,
const double & x)
{
return DFloat::box<AGCObject>(mm, x);
}
double
GCObjectConversion<double>::from_gco(obj<AAllocator> mm,
obj<AGCObject> gco)
{
(void)mm;
auto float_obj = obj<AGCObject,DFloat>::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 */