+ xo-numeric/ [WIP]
This commit is contained in:
parent
77546db923
commit
b8fd087319
13 changed files with 661 additions and 0 deletions
22
include/xo/numeric/Numeric.hpp
Normal file
22
include/xo/numeric/Numeric.hpp
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
/** @file Numeric.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/Numeric.json5]
|
||||
* 2. jinja2 template for facet .hpp file:
|
||||
* [facet.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/Numeric.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "detail/ANumeric.hpp"
|
||||
#include "detail/INumeric_Any.hpp"
|
||||
#include "detail/INumeric_Xfer.hpp"
|
||||
#include "detail/RNumeric.hpp"
|
||||
|
||||
|
||||
/* end Numeric.hpp */
|
||||
20
include/xo/numeric/NumericDispatch.hpp
Normal file
20
include/xo/numeric/NumericDispatch.hpp
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
/** @file NumericDispatch.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
class NumericDispatch {
|
||||
public:
|
||||
|
||||
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end NumericDispatch.hpp */
|
||||
44
include/xo/numeric/NumericOps.hpp
Normal file
44
include/xo/numeric/NumericOps.hpp
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
/** @file NumericOps.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Numeric.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
class INumericOps {
|
||||
public:
|
||||
using BinaryOp1 = obj<ANumeric> (*)(obj<AAllocator> mm, void * x, void * y);
|
||||
|
||||
public:
|
||||
explicit INumericOp9s(BinaryOp1 multiply) : multiply_{multiply} {}
|
||||
|
||||
/** multiply (x,y); allocate from mm **/
|
||||
BinaryOp1 multiply_;
|
||||
};
|
||||
|
||||
/** Convenience template. To use, provide implementation
|
||||
* for
|
||||
* _multiply() ...
|
||||
*
|
||||
**/
|
||||
template <typename DRepr1, typename DRepr2>
|
||||
class NumericOps : public INumericOps {
|
||||
public:
|
||||
using BinaryOp1_Impl = obj<ANumeric> (*)(obj<AAllocator> mm, DRepr1 * x, DRepr2 * y);
|
||||
|
||||
public:
|
||||
explicit NumericOps(BinaryOp1_Impl multiply)
|
||||
: INumericOps(reinterpret_cast<INumericOps::BinaryOp1>(multiply))
|
||||
{}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end NumericOps.hpp */
|
||||
|
||||
70
include/xo/numeric/detail/ANumeric.hpp
Normal file
70
include/xo/numeric/detail/ANumeric.hpp
Normal file
|
|
@ -0,0 +1,70 @@
|
|||
/** @file ANumeric.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/Numeric.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [abstract_facet.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/Numeric.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
// includes (via {facet_includes})
|
||||
#include <xo/facet/obj.hpp>
|
||||
#include <xo/facet/facet_implementation.hpp>
|
||||
#include <xo/facet/typeseq.hpp>
|
||||
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
using Copaque = const void *;
|
||||
using Opaque = void *;
|
||||
|
||||
/**
|
||||
Abstraction for a schematika numeric
|
||||
**/
|
||||
class ANumeric {
|
||||
public:
|
||||
/** @defgroup scm-numeric-type-traits **/
|
||||
///@{
|
||||
// types
|
||||
/** integer identifying a type **/
|
||||
using typeseq = xo::facet::typeseq;
|
||||
using Copaque = const void *;
|
||||
using Opaque = void *;
|
||||
///@}
|
||||
|
||||
/** @defgroup scm-numeric-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** RTTI: unique id# for actual runtime data representation **/
|
||||
virtual typeseq _typeseq() const noexcept = 0;
|
||||
/** destroy instance @p d; calls c++ dtor only for actual runtime type; does not recover memory **/
|
||||
virtual void _drop(Opaque d) const noexcept = 0;
|
||||
|
||||
// nonconst methods
|
||||
///@}
|
||||
}; /*ANumeric*/
|
||||
|
||||
/** Implementation INumeric_DRepr of ANumeric for state DRepr
|
||||
* should provide a specialization:
|
||||
*
|
||||
* template <>
|
||||
* struct xo::facet::FacetImplementation<ANumeric, DRepr> {
|
||||
* using Impltype = INumeric_DRepr;
|
||||
* };
|
||||
*
|
||||
* then INumeric_ImplType<DRepr> --> INumeric_DRepr
|
||||
**/
|
||||
template <typename DRepr>
|
||||
using INumeric_ImplType = xo::facet::FacetImplType<ANumeric, DRepr>;
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* ANumeric.hpp */
|
||||
87
include/xo/numeric/detail/INumeric_Any.hpp
Normal file
87
include/xo/numeric/detail/INumeric_Any.hpp
Normal file
|
|
@ -0,0 +1,87 @@
|
|||
/** @file INumeric_Any.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/Numeric.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/Numeric.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ANumeric.hpp"
|
||||
#include <xo/facet/obj.hpp>
|
||||
|
||||
namespace xo { namespace scm { class INumeric_Any; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
|
||||
template <>
|
||||
struct FacetImplementation<xo::scm::ANumeric,
|
||||
DVariantPlaceholder>
|
||||
{
|
||||
using ImplType = xo::scm::INumeric_Any;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
/** @class INumeric_Any
|
||||
* @brief ANumeric implementation for empty variant instance
|
||||
**/
|
||||
class INumeric_Any : public ANumeric {
|
||||
public:
|
||||
/** @defgroup scm-numeric-any-type-traits **/
|
||||
///@{
|
||||
|
||||
/** integer identifying a type **/
|
||||
using typeseq = xo::facet::typeseq;
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-numeric-any-methods **/
|
||||
///@{
|
||||
|
||||
const ANumeric * iface() const { return std::launder(this); }
|
||||
|
||||
// from ANumeric
|
||||
|
||||
// builtin methods
|
||||
typeseq _typeseq() const noexcept override { return s_typeseq; }
|
||||
[[noreturn]] void _drop(Opaque) const noexcept override { _fatal(); }
|
||||
|
||||
// const methods
|
||||
|
||||
// nonconst methods
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** @defgraoup scm-numeric-any-private-methods **/
|
||||
///@{
|
||||
|
||||
[[noreturn]] static void _fatal();
|
||||
|
||||
///@}
|
||||
|
||||
public:
|
||||
/** @defgroup scm-numeric-any-member-vars **/
|
||||
///@{
|
||||
|
||||
static typeseq s_typeseq;
|
||||
static bool _valid;
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm */
|
||||
} /*namespace xo */
|
||||
|
||||
/* INumeric_Any.hpp */
|
||||
79
include/xo/numeric/detail/INumeric_Xfer.hpp
Normal file
79
include/xo/numeric/detail/INumeric_Xfer.hpp
Normal file
|
|
@ -0,0 +1,79 @@
|
|||
/** @file INumeric_Xfer.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/Numeric.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/Numeric.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class INumeric_Xfer
|
||||
**/
|
||||
template <typename DRepr, typename INumeric_DRepr>
|
||||
class INumeric_Xfer : public ANumeric {
|
||||
public:
|
||||
/** @defgroup scm-numeric-xfer-type-traits **/
|
||||
///@{
|
||||
/** actual implementation (not generated; often delegates to DRepr) **/
|
||||
using Impl = INumeric_DRepr;
|
||||
/** integer identifying a type **/
|
||||
using typeseq = ANumeric::typeseq;
|
||||
///@}
|
||||
|
||||
/** @defgroup scm-numeric-xfer-methods **/
|
||||
///@{
|
||||
|
||||
static const DRepr & _dcast(Copaque d) { return *(const DRepr *)d; }
|
||||
static DRepr & _dcast(Opaque d) { return *(DRepr *)d; }
|
||||
|
||||
// from ANumeric
|
||||
|
||||
// builtin methods
|
||||
typeseq _typeseq() const noexcept override { return s_typeseq; }
|
||||
void _drop(Opaque d) const noexcept override { _dcast(d).~DRepr(); }
|
||||
|
||||
// const methods
|
||||
|
||||
// non-const methods
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
using I = Impl;
|
||||
|
||||
public:
|
||||
/** @defgroup scm-numeric-xfer-member-vars **/
|
||||
///@{
|
||||
|
||||
/** typeseq for template parameter DRepr **/
|
||||
static typeseq s_typeseq;
|
||||
/** true iff satisfies facet implementation **/
|
||||
static bool _valid;
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
template <typename DRepr, typename INumeric_DRepr>
|
||||
xo::facet::typeseq
|
||||
INumeric_Xfer<DRepr, INumeric_DRepr>::s_typeseq
|
||||
= xo::facet::typeseq::id<DRepr>();
|
||||
|
||||
template <typename DRepr, typename INumeric_DRepr>
|
||||
bool
|
||||
INumeric_Xfer<DRepr, INumeric_DRepr>::_valid
|
||||
= xo::facet::valid_facet_implementation<ANumeric,
|
||||
INumeric_Xfer>();
|
||||
|
||||
} /*namespace scm */
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end INumeric_Xfer.hpp */
|
||||
81
include/xo/numeric/detail/RNumeric.hpp
Normal file
81
include/xo/numeric/detail/RNumeric.hpp
Normal file
|
|
@ -0,0 +1,81 @@
|
|||
/** @file RNumeric.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/Numeric.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/Numeric.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "ANumeric.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
/** @class RNumeric
|
||||
**/
|
||||
template <typename Object>
|
||||
class RNumeric : public Object {
|
||||
private:
|
||||
using O = Object;
|
||||
|
||||
public:
|
||||
/** @defgroup scm-numeric-router-type-traits **/
|
||||
///@{
|
||||
using ObjectType = Object;
|
||||
using DataPtr = Object::DataPtr;
|
||||
using typeseq = xo::reflect::typeseq;
|
||||
///@}
|
||||
|
||||
/** @defgroup scm-numeric-router-ctors **/
|
||||
///@{
|
||||
RNumeric() {}
|
||||
RNumeric(Object::DataPtr data) : Object{std::move(data)} {}
|
||||
RNumeric(const ANumeric * iface, void * data)
|
||||
requires std::is_same_v<typename Object::DataType, xo::facet::DVariantPlaceholder>
|
||||
: Object(iface, data) {}
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-numeric-router-methods **/
|
||||
///@{
|
||||
|
||||
// explicit injected content
|
||||
|
||||
// builtin methods
|
||||
typeseq _typeseq() const noexcept { return O::iface()->_typeseq(); }
|
||||
void _drop() const noexcept { O::iface()->_drop(O::data()); }
|
||||
|
||||
// const methods
|
||||
|
||||
// non-const methods (still const in router!)
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-numeric-member-vars **/
|
||||
///@{
|
||||
|
||||
static bool _valid;
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
template <typename Object>
|
||||
bool
|
||||
RNumeric<Object>::_valid = xo::facet::valid_object_router<Object>();
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
namespace xo { namespace facet {
|
||||
template <typename Object>
|
||||
struct RoutingFor<xo::scm::ANumeric, Object> {
|
||||
using RoutingType = xo::scm::RNumeric<Object>;
|
||||
};
|
||||
} }
|
||||
|
||||
/* end RNumeric.hpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue