xo-procedure2: + printable support for Primitive<Fn>
This commit is contained in:
parent
31aaddb7af
commit
2f40959a01
8 changed files with 190 additions and 2 deletions
|
|
@ -55,6 +55,7 @@ xo_add_genfacetimpl(
|
|||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-procedure2-facetimpl-procedure-primitive_gco_2_gco_gco
|
||||
FACET_PKG xo_procedure2
|
||||
|
|
@ -78,6 +79,18 @@ xo_add_genfacetimpl(
|
|||
OUTPUT_CPP_DIR src/procedure2
|
||||
)
|
||||
|
||||
# note: manual target; generated code committed to git
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-procedure2-facetimpl-printable-primitive_gco_2_gco_gco
|
||||
FACET_PKG xo_printable2
|
||||
FACET Printable
|
||||
REPR Primitive_gco_2_gco_gco
|
||||
INPUT idl/IPrintable_DPrimitive_gco_2_gco_gco.json5
|
||||
OUTPUT_HPP_DIR include/xo/procedure2
|
||||
OUTPUT_IMPL_SUBDIR detail
|
||||
OUTPUT_CPP_DIR src/procedure2
|
||||
)
|
||||
|
||||
add_subdirectory(src/procedure2)
|
||||
add_subdirectory(utest)
|
||||
|
||||
|
|
|
|||
19
xo-procedure2/idl/IPrintable_DPrimitive_gco_2_gco_gco.json5
Normal file
19
xo-procedure2/idl/IPrintable_DPrimitive_gco_2_gco_gco.json5
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
includes: [
|
||||
"<xo/printable2/Printable.hpp>",
|
||||
"<xo/printable2/detail/IPrintable_Xfer.hpp>",
|
||||
// "<xo/procedure2/RuntimeContext.hpp>",
|
||||
// "<xo/procedure2/detail/IRuntimeContext_Xfer.hpp>",
|
||||
// "<xo/procedure2/Procedure.hpp>",
|
||||
// "<xo/procedure2/detail/IProcedure_Xfer.hpp>",
|
||||
],
|
||||
local_types: [ ],
|
||||
namespace1: "xo",
|
||||
namespace2: "scm",
|
||||
facet_idl: "idl/Printable.json5",
|
||||
brief: "provide APrintable interface for DPrimitive (gco x gco) -> gco",
|
||||
using_doxygen: true,
|
||||
repr: "DPrimitive_gco_2_gco_gco",
|
||||
doc: [ "implement APrintable for DPrimitive (gco x gco) -> gco" ],
|
||||
}
|
||||
|
|
@ -9,6 +9,7 @@
|
|||
#include <xo/object2/DArray.hpp>
|
||||
#include <xo/gc/GCObjectConversion.hpp>
|
||||
#include <xo/gc/GCObject.hpp>
|
||||
#include <xo/reflect/Reflect.hpp>
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
|
||||
|
|
@ -58,14 +59,22 @@ namespace xo {
|
|||
template <typename Fn>
|
||||
class Primitive {
|
||||
public:
|
||||
using Traits = detail::PmFnTraits<Fn>;
|
||||
|
||||
using ACollector = xo::mm::ACollector;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using AGCObject = xo::mm::AGCObject;
|
||||
using DArray = xo::scm::DArray;
|
||||
using Traits = detail::PmFnTraits<Fn>;
|
||||
using Reflect = xo::reflect::Reflect;
|
||||
using TypeDescr = xo::reflect::TypeDescr;
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
|
||||
public:
|
||||
Primitive(std::string_view name, Fn fn) : name_{name}, fn_{fn} {}
|
||||
Primitive(std::string_view name, Fn fn) : name_{name},
|
||||
fn_td_{Reflect::require<Fn>()},
|
||||
fn_{fn} {}
|
||||
|
||||
TypeDescr fn_td() const noexcept { return fn_td_; }
|
||||
|
||||
bool is_nary() const noexcept { return false; }
|
||||
static constexpr std::int32_t n_args() noexcept { return Traits::n_args; }
|
||||
|
|
@ -75,6 +84,12 @@ namespace xo {
|
|||
std::make_index_sequence<Traits::n_args>{});
|
||||
}
|
||||
|
||||
/** @defgroup scm-primitive-printable-facet **/
|
||||
///@{
|
||||
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
///@}
|
||||
/** @defgroup scm-primitive-gcobject-facet **/
|
||||
///@{
|
||||
std::size_t shallow_size() const noexcept;
|
||||
|
|
@ -107,10 +122,29 @@ namespace xo {
|
|||
private:
|
||||
/** name of this primitive **/
|
||||
std::string_view name_;
|
||||
|
||||
/** type description for function
|
||||
* Note that this type description will have additional first argument
|
||||
* for obj<ARuntimeContext>
|
||||
**/
|
||||
TypeDescr fn_td_;
|
||||
|
||||
/** function implementation **/
|
||||
Fn fn_;
|
||||
}; /*Primitive*/
|
||||
|
||||
template <typename Fn>
|
||||
bool
|
||||
Primitive<Fn>::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
return ppii.pps()->pretty_struct
|
||||
(ppii,
|
||||
"Primitive<Fn>",
|
||||
refrtag("name", name_),
|
||||
refrtag("td", fn_td_),
|
||||
refrtag("fn", fn_));
|
||||
}
|
||||
|
||||
template <typename Fn>
|
||||
std::size_t
|
||||
Primitive<Fn>::shallow_size() const noexcept {
|
||||
|
|
|
|||
|
|
@ -0,0 +1,62 @@
|
|||
/** @file IPrintable_DPrimitive_gco_2_gco_gco.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DPrimitive_gco_2_gco_gco.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DPrimitive_gco_2_gco_gco.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Printable.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DPrimitive_gco_2_gco_gco.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DPrimitive_gco_2_gco_gco; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DPrimitive_gco_2_gco_gco>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DPrimitive_gco_2_gco_gco,
|
||||
xo::scm::IPrintable_DPrimitive_gco_2_gco_gco>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IPrintable_DPrimitive_gco_2_gco_gco
|
||||
**/
|
||||
class IPrintable_DPrimitive_gco_2_gco_gco {
|
||||
public:
|
||||
/** @defgroup scm-printable-dprimitive_gco_2_gco_gco-type-traits **/
|
||||
///@{
|
||||
using ppindentinfo = xo::print::APrintable::ppindentinfo;
|
||||
using Copaque = xo::print::APrintable::Copaque;
|
||||
using Opaque = xo::print::APrintable::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-printable-dprimitive_gco_2_gco_gco-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** Pretty-printing support for this object.
|
||||
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
|
||||
static bool pretty(const DPrimitive_gco_2_gco_gco & self, const ppindentinfo & ppii);
|
||||
|
||||
// non-const methods
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -12,6 +12,7 @@ set(SELF_SRCS
|
|||
DPrimitive.cpp
|
||||
IGCObject_DPrimitive_gco_2_gco_gco.cpp
|
||||
IProcedure_DPrimitive_gco_2_gco_gco.cpp
|
||||
IPrintable_DPrimitive_gco_2_gco_gco.cpp
|
||||
# Add source files here, e.g.:
|
||||
# procedure2.cpp
|
||||
)
|
||||
|
|
|
|||
|
|
@ -0,0 +1,28 @@
|
|||
/** @file IPrintable_DPrimitive_gco_2_gco_gco.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2-claude1/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DPrimitive_gco_2_gco_gco.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DPrimitive_gco_2_gco_gco.json5]
|
||||
**/
|
||||
|
||||
#include "detail/IPrintable_DPrimitive_gco_2_gco_gco.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IPrintable_DPrimitive_gco_2_gco_gco::pretty(const DPrimitive_gco_2_gco_gco & self, const ppindentinfo & ppii) -> bool
|
||||
{
|
||||
return self.pretty(ppii);
|
||||
}
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IPrintable_DPrimitive_gco_2_gco_gco.cpp */
|
||||
|
|
@ -8,14 +8,17 @@
|
|||
|
||||
#include "DPrimitive_gco_2_gco_gco.hpp"
|
||||
#include "detail/IGCObject_DPrimitive_gco_2_gco_gco.hpp"
|
||||
#include "detail/IPrintable_DPrimitive_gco_2_gco_gco.hpp"
|
||||
|
||||
#include <xo/gc/GCObject.hpp>
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/facet/FacetRegistry.hpp>
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
|
||||
namespace xo {
|
||||
using xo::facet::FacetRegistry;
|
||||
using xo::facet::typeseq;
|
||||
using xo::print::APrintable;
|
||||
|
||||
namespace scm {
|
||||
bool
|
||||
|
|
@ -26,6 +29,7 @@ namespace xo {
|
|||
FacetRegistry::register_impl<ARuntimeContext, DSimpleRcx>();
|
||||
|
||||
FacetRegistry::register_impl<AGCObject, DPrimitive_gco_2_gco_gco>();
|
||||
FacetRegistry::register_impl<APrintable, DPrimitive_gco_2_gco_gco>();
|
||||
|
||||
log && log(xtag("DSimpleRcx.tseq", typeseq::id<DSimpleRcx>()));
|
||||
log && log(xtag("DPrimitive_gco_2_gco_gco.tseq", typeseq::id<DPrimitive_gco_2_gco_gco>()));
|
||||
|
|
|
|||
|
|
@ -7,13 +7,17 @@
|
|||
#include <xo/procedure2/init_primitives.hpp>
|
||||
#include <xo/procedure2/DSimpleRcx.hpp>
|
||||
#include <xo/procedure2/detail/IRuntimeContext_DSimpleRcx.hpp>
|
||||
#include <xo/procedure2/detail/IPrintable_DPrimitive_gco_2_gco_gco.hpp>
|
||||
#include <xo/object2/DFloat.hpp>
|
||||
#include <xo/object2/DInteger.hpp>
|
||||
#include <xo/object2/DArray.hpp>
|
||||
#include <xo/object2/number/IGCObject_DFloat.hpp>
|
||||
#include <xo/object2/number/IGCObject_DInteger.hpp>
|
||||
#include <xo/alloc2/arena/IAllocator_DArena.hpp>
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/indentlog/scope.hpp>
|
||||
#include <catch2/catch.hpp>
|
||||
#include <sstream>
|
||||
|
||||
namespace xo {
|
||||
using xo::scm::Primitives;
|
||||
|
|
@ -22,12 +26,17 @@ namespace xo {
|
|||
using xo::scm::DFloat;
|
||||
using xo::scm::DInteger;
|
||||
using xo::scm::DArray;
|
||||
using xo::scm::DPrimitive_gco_2_gco_gco;
|
||||
using xo::mm::AAllocator;
|
||||
using xo::mm::AGCObject;
|
||||
using xo::mm::DArena;
|
||||
using xo::mm::ArenaConfig;
|
||||
using xo::print::APrintable;
|
||||
using xo::print::ppstate_standalone;
|
||||
using xo::print::ppconfig;
|
||||
using xo::facet::with_facet;
|
||||
using xo::facet::obj;
|
||||
using xo::scope;
|
||||
|
||||
namespace ut {
|
||||
static InitEvidence s_init = InitSubsys<S_procedure2_tag>::require();
|
||||
|
|
@ -111,6 +120,24 @@ namespace xo {
|
|||
REQUIRE(result_float.data()->value() == 21.0);
|
||||
}
|
||||
|
||||
TEST_CASE("DPrimitive-pretty", "[procedure2][DPrimitive][pp]")
|
||||
{
|
||||
scope log(XO_DEBUG(false));
|
||||
|
||||
std::stringstream ss;
|
||||
ppconfig ppc;
|
||||
ppstate_standalone pps(&ss, 0, &ppc);
|
||||
|
||||
obj<APrintable,DPrimitive_gco_2_gco_gco> prim_pr(&Primitives::s_mul_gco_gco_pm);
|
||||
pps.pretty(prim_pr);
|
||||
|
||||
std::string output = ss.str();
|
||||
|
||||
log && log(output);
|
||||
|
||||
CHECK(output.find("_mul") != std::string::npos);
|
||||
}
|
||||
|
||||
} /*namespace ut*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue