xo-objectd2 xo-printable xo-facet: pp working for List(Integer)
Also streamline facet switching
This commit is contained in:
parent
9ce465e84f
commit
09ee3a20ac
23 changed files with 508 additions and 27 deletions
|
|
@ -5,11 +5,32 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include <xo/indentlog/print/ppindentinfo.hpp>
|
||||
#include <cstdint>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
using DInteger = std::int64_t;
|
||||
struct DInteger {
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
|
||||
explicit DInteger(long x) : value_{x} {}
|
||||
|
||||
/** allocate boxed value @p x using memory from @p mm **/
|
||||
static DInteger * make(obj<AAllocator> mm,
|
||||
long x);
|
||||
|
||||
double value() const noexcept { return value_; }
|
||||
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
operator long() const noexcept { return value_; }
|
||||
|
||||
private:
|
||||
/** boxed integer value **/
|
||||
long value_;
|
||||
};
|
||||
} /*nmaespace obj*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,7 @@
|
|||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
// TODO: consider renaming to DCons
|
||||
struct DList {
|
||||
using size_type = std::size_t;
|
||||
using AGCObject = xo::mm::AGCObject;
|
||||
|
|
@ -22,8 +23,27 @@ namespace xo {
|
|||
DList(xo::obj<AGCObject> h,
|
||||
DList * r) : head_{h}, rest_{r} {}
|
||||
|
||||
template <typename AConsFacet = AGCObject>
|
||||
static obj<AConsFacet,DList> nil();
|
||||
|
||||
/** shortcut for
|
||||
* cons(mm, cdr, cdr.data())
|
||||
**/
|
||||
template <typename AConsFacet = AGCObject, typename ACdrFacet = AGCObject>
|
||||
static obj<AConsFacet,DList> cons(obj<AAllocator> mm,
|
||||
obj<AGCObject> car,
|
||||
obj<ACdrFacet,DList> cdr);
|
||||
|
||||
/** sentinel for null list **/
|
||||
static DList * null();
|
||||
static DList * _nil();
|
||||
|
||||
/** list with first element @p car,
|
||||
* followed by contents of list @p cdr.
|
||||
* Shares structure with @p cdr
|
||||
**/
|
||||
static DList * _cons(obj<AAllocator> mm,
|
||||
obj<AGCObject> car,
|
||||
DList * cdr);
|
||||
|
||||
/** list with one element @p h1, allocated from @p mm **/
|
||||
static DList * list(obj<AAllocator> mm,
|
||||
|
|
@ -51,6 +71,22 @@ namespace xo {
|
|||
DList * rest_ = nullptr;
|
||||
};
|
||||
|
||||
template <typename AConsFacet>
|
||||
obj<AConsFacet,DList>
|
||||
DList::nil()
|
||||
{
|
||||
return obj<AConsFacet,DList>(DList::_nil());
|
||||
}
|
||||
|
||||
template <typename AConsFacet, typename ACdrFacet>
|
||||
obj<AConsFacet,DList>
|
||||
DList::cons(obj<AAllocator> mm,
|
||||
obj<AGCObject> car,
|
||||
obj<ACdrFacet,DList> cdr)
|
||||
{
|
||||
return obj<AConsFacet,DList>(DList::_cons(mm, car, cdr.data()));
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
|
|
|
|||
57
xo-object2/include/xo/object2/IPrintable_DInteger.hpp
Normal file
57
xo-object2/include/xo/object2/IPrintable_DInteger.hpp
Normal file
|
|
@ -0,0 +1,57 @@
|
|||
/** @file IPrintable_DInteger.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/home/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DInteger.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DInteger.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DInteger.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DInteger; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DInteger>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DInteger,
|
||||
xo::scm::IPrintable_DInteger>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IPrintable_DInteger
|
||||
**/
|
||||
class IPrintable_DInteger {
|
||||
public:
|
||||
/** @defgroup scm-printable-dinteger-type-traits **/
|
||||
///@{
|
||||
using ppindentinfo = xo::print::APrintable::ppindentinfo;
|
||||
///@}
|
||||
/** @defgroup scm-printable-dinteger-methods **/
|
||||
///@{
|
||||
/** Pretty-printing support for this object.
|
||||
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
|
||||
static bool pretty(const DInteger & self, const ppindentinfo & ppii);
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -54,4 +54,4 @@ See [xo-indentlog/xo/indentlog/pretty.hpp] **/
|
|||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
/* end */
|
||||
|
|
|
|||
|
|
@ -13,6 +13,9 @@ namespace xo {
|
|||
* Return true iff all types register successfully.
|
||||
**/
|
||||
bool object2_register_types(obj<xo::mm::ACollector> gc);
|
||||
|
||||
/** Register object2 (facet,impl) combinations with FacetRegistry **/
|
||||
bool object2_register_facets();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue