xo-procedure2 xo-object2: + polymorphic primitive support
This commit is contained in:
parent
7ab8d4e821
commit
eef4a1db5d
6 changed files with 74 additions and 3 deletions
|
|
@ -23,7 +23,7 @@ namespace xo {
|
|||
* fixed at construction time, but not part of type.
|
||||
* Can reallocate to change
|
||||
**/
|
||||
struct DArray {
|
||||
class DArray {
|
||||
public:
|
||||
/** @defgroup darray-types type traits **/
|
||||
///@{
|
||||
|
|
|
|||
|
|
@ -19,7 +19,7 @@ namespace xo {
|
|||
using AGCObject = xo::mm::AGCObject;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
|
||||
static obj<AGCObject> to_gco(obj<AAllocator> mm, const double & x);
|
||||
static obj<AGCObject> to_gco(obj<AAllocator> mm, double x);
|
||||
static double from_gco(obj<AAllocator> mm, obj<AGCObject> gco);
|
||||
};
|
||||
|
||||
|
|
|
|||
29
include/xo/object2/number/GCObjectConversion_DInteger.hpp
Normal file
29
include/xo/object2/number/GCObjectConversion_DInteger.hpp
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
/** @file GCObjectConversion_DInteger.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DInteger.hpp"
|
||||
#include "number/IGCObject_DInteger.hpp"
|
||||
#include <xo/gc/GCObjectConversion.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
template <>
|
||||
struct GCObjectConversion<long> {
|
||||
static_assert(std::is_same_v<long, DInteger::value_type>);
|
||||
|
||||
using AGCObject = xo::mm::AGCObject;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
|
||||
static obj<AGCObject> to_gco(obj<AAllocator> mm, long x);
|
||||
static long from_gco(obj<AAllocator> mm, obj<AGCObject> gco);
|
||||
};
|
||||
|
||||
}
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end GCObjectConversion_DInteger.hpp */
|
||||
|
|
@ -6,6 +6,7 @@ set(SELF_SRCS
|
|||
object2_register_types.cpp
|
||||
object2_register_facets.cpp
|
||||
GCObjectConversion_DFloat.cpp
|
||||
GCObjectConversion_DInteger.cpp
|
||||
IGCObject_DArray.cpp
|
||||
IGCObject_DFloat.cpp
|
||||
IGCObject_DBoolean.cpp
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@ namespace xo {
|
|||
|
||||
obj<AGCObject>
|
||||
GCObjectConversion<double>::to_gco(obj<AAllocator> mm,
|
||||
const double & x)
|
||||
double x)
|
||||
{
|
||||
return DFloat::box<AGCObject>(mm, x);
|
||||
}
|
||||
|
|
|
|||
41
src/object2/GCObjectConversion_DInteger.cpp
Normal file
41
src/object2/GCObjectConversion_DInteger.cpp
Normal file
|
|
@ -0,0 +1,41 @@
|
|||
/** @file GCObjectConversion_DInteger.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#include "number/GCObjectConversion_DInteger.hpp"
|
||||
#include <xo/indentlog/print/tag.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AGCObject;
|
||||
|
||||
namespace scm {
|
||||
|
||||
obj<AGCObject>
|
||||
GCObjectConversion<long>::to_gco(obj<AAllocator> mm,
|
||||
long x)
|
||||
{
|
||||
return DInteger::box<AGCObject>(mm, x);
|
||||
}
|
||||
|
||||
long
|
||||
GCObjectConversion<long>::from_gco(obj<AAllocator> mm,
|
||||
obj<AGCObject> gco)
|
||||
{
|
||||
(void)mm;
|
||||
|
||||
auto int_obj = obj<AGCObject,DInteger>::from(gco);
|
||||
|
||||
if (!int_obj) {
|
||||
throw std::runtime_error
|
||||
(tostr("Object obj found where Integer expected",
|
||||
xtag("obj", gco)));
|
||||
}
|
||||
|
||||
return int_obj.data()->value();
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end GCObjectConversion_DFloat.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue