xo-object2: APrintable+DFloat

This commit is contained in:
Roland Conybeare 2026-01-05 11:53:44 -05:00
commit e3711860f1
20 changed files with 175 additions and 42 deletions

View file

@ -65,10 +65,10 @@ macro(xo_cxx_toplevel_options2)
TARGET docs_${PROJECT_NAME}
PROPERTY targets "")
add_custom_target(idl_${PROJECT_NAME})
add_custom_target(share_${PROJECT_NAME})
set_property(
TARGET idl_${PROJECT_NAME}
PROPERTY path ${PROJECT_SOURCE_DIR}/idl)
TARGET share_${PROJECT_NAME}
PROPERTY path ${PROJECT_SOURCE_DIR})
endif()
endmacro()
@ -1677,9 +1677,7 @@ function(xo_add_genfacet)
${GF_OUTPUT_HPP_DIR}/${GF_OUTPUT_IMPL_SUBDIR}/R${GF_FACET}.hpp
${GF_OUTPUT_CPP_DIR}/I${GF_FACET}_Any.cpp)
message(STATUS "generatedFiles=${generatedFiles}")
message(ERROR "epic fail")
#message(STATUS "generatedFiles=${generatedFiles}")
# Build the genfacet command
add_custom_command(
@ -1704,6 +1702,7 @@ function(xo_add_genfacetimpl)
set(options "")
set(oneValueArgs
TARGET # Name for this generation target
FACET_DIR # facet directory
FACET # facet name
REPR # representation name
INPUT # Input .json5 file
@ -1754,6 +1753,7 @@ function(xo_add_genfacetimpl)
OUTPUT ${generatedFiles}
COMMAND ${GENFACET_EXECUTABLE}
--input ${GF_INPUT}
--facet-dir ${GF_FACET_DIR}
--output-hpp ${GF_OUTPUT_HPP_DIR}
--output-impl-hpp ${GF_OUTPUT_IMPL_SUBDIR}
--output-cpp ${GF_OUTPUT_CPP_DIR}

View file

@ -236,12 +236,15 @@ def gen_facet_impl(env,
# facet_includes: include section for AFoo.hpp:
# <xo/gc/GCObject.hpp>
facet_includes = facet_idl['includes']
#facet_includes = facet_idl['includes']
facet_includes = idl['includes']
# <xo/printable2/Printable.hpp>
# sequence
facet_detail_subdir = facet_idl['detail_subdir']
# xo - facet_ns1: outer namespace for facet [e.g. xo]
facet_ns1 = facet_idl['namespace1']
# scm - facet_ns2: nested namespace for facet [e.g. scm]
# facet_ns2: nested namespace for facet [print]
facet_ns2 = facet_idl['namespace2']
# Sequence - facet_name: facet name
@ -431,6 +434,8 @@ def gen_facet_impl(env,
def main():
parser = argparse.ArgumentParser()
parser.add_argument('--input', required=True, help='input IDL JSON5 file')
# --facet-dir: only with mode=implementation
parser.add_argument('--facet-dir', required=False, help='base dir for facet json')
# --output-impl-hpp: putting this in .json5, will be able to drop this.
parser.add_argument('--output-impl-hpp', required=True, help='.hpp detail subdir')
parser.add_argument('--output-hpp', required=True, help='.hpp output directory')
@ -485,7 +490,10 @@ def main():
#output_impl_hpp_dir=output_impl_hpp_dir,
output_cpp_dir=output_cpp_dir)
elif idl['mode'] == 'implementation':
facet_idl_fname = idl['facet_idl']
# idl: json5 for (iface, data) combination
# facet: json5 for abstract iface
facet_idl_fname = args.facet_dir + '/' + idl['facet_idl']
facet_idl = load_idl(facet_idl_fname)
gen_facet_impl(env=env,
@ -493,7 +501,7 @@ def main():
idl=idl,
facet_idl=facet_idl,
output_hpp_dir=output_hpp_dir,
output_impl_hpp_dir=output_impl_hpp_dir,
output_impl_hpp_subdir=output_impl_hpp_subdir,
output_cpp_dir=output_cpp_dir)
if __name__ == '__main__':

View file

@ -13,8 +13,9 @@
#pragma once
#include "{{facet_hpp_fname}}"
#include "{{facet_detail_subdir}}/{{iface_facet_xfer_hpp_fname}}"
{% for include_fname in facet_includes %}
#include {{include_fname}}
{% endfor %}
#include "{{data_repr_hpp_fname}}"
namespace {{repr_ns1}} { namespace {{repr_ns2}} { class {{iface_facet_repr}}; } }
@ -43,7 +44,7 @@ namespace {{repr_ns1}} {
///@{
{% endif %}
{% for ty in types %}
using {{ty.name}} = {{abstract_facet}}::{{ty.name}};
using {{ty.name}} = {{facet_ns1}}::{{facet_ns2}}::{{abstract_facet}}::{{ty.name}};
{% endfor %}
{% if using_dox %}
///@}

View file

@ -13,7 +13,9 @@
#pragma once
#include "{{abstract_facet_fname}}"
{% for include_fname in facet_includes %}
#include {{include_fname}}
{% endfor %}
namespace {{facet_ns1}} {
namespace {{facet_ns2}} {
@ -26,7 +28,10 @@ namespace {{facet_ns2}} {
/** @defgroup {{facet_ns2}}-{{facet_name_lc}}-xfer-type-traits **/
///@{
{% endif %}
/** actual implementation (not generated; often delegates to DRepr) **/
using Impl = {{iface_facet}}_DRepr;
/** integer identifying a type **/
using typeseq = {{abstract_facet}}::typeseq;
{% for ty in types %}
using {{ty.name}} = {{abstract_facet}}::{{ty.name}};
{% endfor %}
@ -45,7 +50,7 @@ namespace {{facet_ns2}} {
// from {{abstract_facet}}
// const methods
int32_t _typeseq() const noexcept override { return s_typeseq; }
typeseq _typeseq() const noexcept override { return s_typeseq; }
{% for md in const_methods %}
{{md.return_type}} {{md.name}}({{md.args | args}}) {{md | qualifiers}} override {
return I::{{md.name}}({{md.args | argnames}});
@ -73,7 +78,7 @@ namespace {{facet_ns2}} {
{% endif %}
/** typeseq for template parameter DRepr **/
static int32_t s_typeseq;
static typeseq s_typeseq;
/** true iff satisfies facet implementation **/
static bool _valid;
@ -83,7 +88,7 @@ namespace {{facet_ns2}} {
};
template <typename DRepr, typename {{iface_facet}}_DRepr>
int32_t
xo::facet::typeseq
{{iface_facet_xfer}}<DRepr, {{iface_facet}}_DRepr>::s_typeseq
= xo::facet::typeseq::id<DRepr>();

View file

@ -94,10 +94,10 @@ namespace xo {
PPDETAIL_ATOMIC(bool);
PPDETAIL_ATOMIC(char);
#ifdef __APPLE__
# ifdef __APPLE__
// unsigned long != std::uint64_t.
PPDETAIL_ATOMIC(unsigned long);
#endif
# endif
PPDETAIL_ATOMIC(std::int64_t);
PPDETAIL_ATOMIC(std::uint64_t);
PPDETAIL_ATOMIC(std::int32_t);

View file

@ -37,11 +37,12 @@ xo_add_genfacetimpl(
OUTPUT_CPP_DIR src/object2
)
get_target_property(xo_printable2_src_dir xo-printable2 xo_srcdir)
message(STATUS "xo_printable2_src_dir=${xo_printable_src_dir}")
get_target_property(xo_printable2_dir share_xo_printable2 path)
message(STATUS "xo_printable2_dir=${xo_printable2_dir}")
xo_add_genfacetimpl(
TARGET xo-object2-facetimpl-printable-float
FACET_DIR ${xo_printable2_dir}
FACET Printable
REPR Float
INPUT idl/IPrintable_DFloat.json5

View file

@ -1,7 +1,8 @@
@PACKAGE_INIT@
include(CMakeFindDependencyMacro)
#find_dependency(indentlog)
find_dependency(xo_alloc2)
find_dependency(xo_gc)
find_dependency(xo_printable2)
find_dependency(indentlog)
include("${CMAKE_CURRENT_LIST_DIR}/@PROJECT_NAME@Targets.cmake")
check_required_components("@PROJECT_NAME@")

View file

@ -1,8 +1,9 @@
{
mode: "implementation",
includes: [],
includes: [ "<xo/printable2/Printable.hpp>",
"<xo/printable2/detail/IPrintable_Xfer.hpp>" ],
namespace1: "xo",
namespace2: "print",
namespace2: "scm",
facet_idl: "idl/Printable.json5",
brief: "provide APrintable interface for DFloat",
using_doxygen: true,

View file

@ -1,6 +1,6 @@
{
mode: "implementation",
includes: [],
includes: [ "<xo/printable2/Printable.hpp>" ],
namespace1: "xo",
namespace2: "scm",
facet_idl: "idl/Sequence.json5",

View file

@ -6,11 +6,13 @@
#pragma once
#include <xo/alloc2/Allocator.hpp>
#include <xo/indentlog/print/ppindentinfo.hpp>
namespace xo {
namespace scm {
struct DFloat {
using AAllocator = xo::mm::AAllocator;
using ppindentinfo = xo::print::ppindentinfo;
explicit DFloat(double x) : value_{x} {}
@ -20,6 +22,8 @@ namespace xo {
double value() const noexcept { return value_; }
bool pretty(const ppindentinfo & ppii) const;
operator double() const noexcept { return value_; }
private:

View file

@ -0,0 +1,58 @@
/** @file IPrintable_DFloat.hpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IPrintable_DFloat.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/IPrintable_DFloat.json5]
**/
#pragma once
#include <xo/printable2/Printable.hpp>
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
#include "DFloat.hpp"
namespace xo { namespace scm { class IPrintable_DFloat; } }
namespace xo {
namespace facet {
template <>
struct FacetImplementation<xo::print::APrintable,
xo::scm::DFloat>
{
using ImplType = xo::print::IPrintable_Xfer
<xo::scm::DFloat,
xo::scm::IPrintable_DFloat>;
};
}
}
namespace xo {
namespace scm {
/** @class IPrintable_DFloat
**/
class IPrintable_DFloat {
public:
/** @defgroup scm-printable-dfloat-type-traits **/
///@{
using ppindentinfo = xo::print::APrintable::ppindentinfo;
///@}
/** @defgroup scm-printable-dfloat-methods **/
///@{
/** Pretty-printing support for this object.
See [xo-indentlog/xo/indentlog/pretty.hpp]
**/
static bool pretty(const DFloat & self, const ppindentinfo & ppii);
///@}
};
} /*namespace scm*/
} /*namespace xo*/
/* end */

View file

@ -7,12 +7,14 @@ set(SELF_SRCS
IGCObject_DList.cpp
ISequence_Any.cpp
ISequence_DList.cpp
IPrintable_DFloat.cpp
DList.cpp
DFloat.cpp
object2_register_types.cpp
)
xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 ${SELF_SRCS})
# note: deps here must also appear in cmake/xo_alloc2Config.cmake.in
# note: deps here must also appear in cmake/xo_object2Config.cmake.in
xo_dependency(${SELF_LIB} xo_gc)
#xo_dependency(${SELF_LIB} indentlog)
xo_dependency(${SELF_LIB} xo_printable2)
xo_dependency(${SELF_LIB} indentlog)

View file

@ -4,9 +4,11 @@
**/
#include "DFloat.hpp"
#include <xo/indentlog/print/pretty.hpp>
namespace xo {
using xo::facet::typeseq;
using xo::print::ppdetail_atomic;
namespace scm {
DFloat *
@ -18,6 +20,12 @@ namespace xo {
return new (mem) DFloat(x);
}
bool
DFloat::pretty(const ppindentinfo & ppii) const
{
return ppdetail_atomic<double>::print_pretty(ppii, value_);
}
} /*namespace scm*/
} /*namespace xo*/

View file

@ -0,0 +1,28 @@
/** @file IPrintable_DFloat.cpp
*
* Generated automagically from ingredients:
* 1. code generator:
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/IPrintable_DFloat.json5]
* 2. jinja2 template for abstract facet .hpp file:
* [iface_facet_any.hpp.j2]
* 3. idl for facet methods
* [idl/IPrintable_DFloat.json5]
**/
#include "IPrintable_DFloat.hpp"
namespace xo {
namespace scm {
auto
IPrintable_DFloat::pretty(const DFloat & self, const ppindentinfo & ppii) -> bool
{
return self.pretty(ppii);
}
} /*namespace scm*/
} /*namespace xo*/
/* end IPrintable_DFloat.cpp */

View file

@ -10,7 +10,14 @@
doc: [
"Trait for data types that support pretty-printing"
],
types: [],
types: [
// using ppindentinfo = xo::print::ppindentinfo
{
name: "ppindentinfo",
doc: ["dynamic pretty-printing state during layout"],
definition: "xo::print::ppindentinfo",
},
],
const_methods: [
// bool pretty(const ppindentinfo & ppii) const
{

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Printable.json5]
* 2. jinja2 template for facet .hpp file:

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Printable.json5]
* 2. jinja2 template for abstract facet .hpp file:
@ -35,6 +35,8 @@ public:
// types
/** integer identifying a type **/
using typeseq = xo::facet::typeseq;
/** dynamic pretty-printing state during layout **/
using ppindentinfo = xo::print::ppindentinfo;
///@}
/** @defgroup print-printable-methods **/
@ -43,7 +45,8 @@ public:
/** RTTI: unique id# for actual runtime data representation **/
virtual typeseq _typeseq() const noexcept = 0;
/** Pretty-printing support for this object.
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
See [xo-indentlog/xo/indentlog/pretty.hpp]
**/
virtual bool pretty(Copaque data, const ppindentinfo & ppii) = 0;
// nonconst methods
@ -66,4 +69,4 @@ using IPrintable_ImplType = xo::facet::FacetImplType<APrintable, DRepr>;
} /*namespace print*/
} /*namespace xo*/
/* */
/* */

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Printable.json5]
* 2. jinja2 template for abstract facet .hpp file:
@ -44,6 +44,7 @@ namespace print {
/** integer identifying a type **/
using typeseq = xo::facet::typeseq;
using ppindentinfo = APrintable::ppindentinfo;
///@}
/** @defgroup print-printable-any-methods **/
@ -70,7 +71,7 @@ namespace print {
///@}
public:
/** @defgraoup print-printable-any-member-vars **/
/** @defgroup print-printable-any-member-vars **/
///@{
static typeseq s_typeseq;

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Printable.json5]
* 2. jinja2 template for abstract facet .hpp file:
@ -13,7 +13,7 @@
#pragma once
#include "APrintable.hpp"
#include <xo/indentlog/print/ppindentinfo.hpp>
namespace xo {
namespace print {
@ -24,7 +24,11 @@ namespace print {
public:
/** @defgroup print-printable-xfer-type-traits **/
///@{
/** actual implementation (not generated; often delegates to DRepr) **/
using Impl = IPrintable_DRepr;
/** integer identifying a type **/
using typeseq = APrintable::typeseq;
using ppindentinfo = APrintable::ppindentinfo;
///@}
/** @defgroup print-printable-xfer-methods **/
@ -36,7 +40,7 @@ namespace print {
// from APrintable
// const methods
int32_t _typeseq() const noexcept override { return s_typeseq; }
typeseq _typeseq() const noexcept override { return s_typeseq; }
bool pretty(Copaque data, const ppindentinfo & ppii) override {
return I::pretty(_dcast(data), ppii);
}
@ -49,11 +53,11 @@ namespace print {
using I = Impl;
public:
/** @defgraoup print-printable-xfer-member-vars **/
/** @defgroup print-printable-xfer-member-vars **/
///@{
/** typeseq for template parameter DRepr **/
static int32_t s_typeseq;
static typeseq s_typeseq;
/** true iff satisfies facet implementation **/
static bool _valid;
@ -61,7 +65,7 @@ namespace print {
};
template <typename DRepr, typename IPrintable_DRepr>
int32_t
xo::facet::typeseq
IPrintable_Xfer<DRepr, IPrintable_DRepr>::s_typeseq
= xo::facet::typeseq::id<DRepr>();

View file

@ -2,7 +2,7 @@
*
* Generated automagically from ingredients:
* 1. code generator:
* [/home/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
* arguments:
* --input [idl/Printable.json5]
* 2. jinja2 template for abstract facet .hpp file:
@ -30,6 +30,7 @@ public:
///@{
using ObjectType = Object;
using DataPtr = Object::DataPtr;
using ppindentinfo = APrintable::ppindentinfo;
///@}
/** @defgroup print-printable-router-ctors **/