xo-gc xo-object2 xo-facet: builds w/ ISequence,Dlist
This commit is contained in:
parent
519df04e34
commit
afc44e71fa
26 changed files with 717 additions and 75 deletions
|
|
@ -27,6 +27,16 @@ xo_add_genfacet(
|
|||
OUTPUT_CPP_DIR src/object2
|
||||
)
|
||||
|
||||
xo_add_genfacetimpl(
|
||||
TARGET xo-object2-facetimpl-sequence-list
|
||||
FACET Sequence
|
||||
REPR List
|
||||
INPUT idl/ISequence_DList.json5
|
||||
OUTPUT_HPP_DIR include/xo/object2
|
||||
OUTPUT_IMPL_SUBDIR sequence
|
||||
OUTPUT_CPP_DIR src/object2
|
||||
)
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
|
||||
# must complete definition of expression lib before configuring examples
|
||||
|
|
|
|||
12
xo-object2/idl/ISequence_DList.json5
Normal file
12
xo-object2/idl/ISequence_DList.json5
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
{
|
||||
mode: "implementation",
|
||||
includes: [],
|
||||
namespace1: "xo",
|
||||
namespace2: "scm",
|
||||
facet_idl: "idl/Sequence.json5",
|
||||
brief: "provide ASequence interface for DList state",
|
||||
using_doxygen: true,
|
||||
repr: "DList",
|
||||
doc: [ "doc for something or other"
|
||||
],
|
||||
}
|
||||
|
|
@ -1,8 +1,10 @@
|
|||
{
|
||||
mode: "facet",
|
||||
includes: ["<xo/gc/GCObject.hpp>"],
|
||||
namespace1: "xo",
|
||||
namespace2: "scm",
|
||||
facet: "Sequence",
|
||||
detail_subdir: "sequence",
|
||||
brief: "an ordered collection of variants",
|
||||
using_doxygen: true,
|
||||
doc: [
|
||||
|
|
|
|||
|
|
@ -11,13 +11,23 @@ namespace xo {
|
|||
namespace scm {
|
||||
|
||||
struct DList {
|
||||
using size_type = std::size_t;
|
||||
using AGCObject = xo::mm::AGCObject;
|
||||
|
||||
DList(xo::obj<AGCObject> h,
|
||||
xo::obj<AGCObject> r) : head_{h}, rest_{r} {}
|
||||
DList * r) : head_{h}, rest_{r} {}
|
||||
|
||||
/** DList length is at least 1 **/
|
||||
bool is_empty() const noexcept { return false; };
|
||||
/** DList models a finite sequence **/
|
||||
bool is_finite() const noexcept { return true; };
|
||||
/** return number of elements in this DList **/
|
||||
size_type size() const noexcept;
|
||||
/** return element at 0-based index @p ix **/
|
||||
obj<AGCObject> at(size_type ix) const;
|
||||
|
||||
obj<AGCObject> head_;
|
||||
obj<AGCObject> rest_;
|
||||
DList * rest_ = nullptr;
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <xo/gc/Collector.hpp>
|
||||
#include <xo/alloc2/alloc/AAllocator.hpp>
|
||||
#include <xo/gc/detail/AGCObject.hpp>
|
||||
#include <xo/gc/detail/IGCObject_Xfer.hpp>
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
#include <xo/gc/Collector.hpp>
|
||||
#include "xo/alloc2/alloc/AAllocator.hpp"
|
||||
#include <xo/gc/detail/AGCObject.hpp>
|
||||
#include <xo/gc/detail/IGCObject_Xfer.hpp>
|
||||
|
|
|
|||
|
|
@ -13,6 +13,19 @@
|
|||
#include "DList.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm { struct IGCObject_DList; }
|
||||
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::mm::AGCObject,
|
||||
xo::scm::DList>
|
||||
{
|
||||
using ImplType = xo::mm::IGCObject_Xfer
|
||||
<xo::scm::DList,
|
||||
xo::scm::IGCObject_DList>;
|
||||
};
|
||||
}
|
||||
|
||||
namespace scm {
|
||||
/* changes here coordinate with:
|
||||
* IGCObject_XFer
|
||||
|
|
|
|||
61
xo-object2/include/xo/object2/ISequence_DList.hpp
Normal file
61
xo-object2/include/xo/object2/ISequence_DList.hpp
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/** @file ISequence_DList.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISequence_DList.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ISequence_DList.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Sequence.hpp"
|
||||
#include "sequence/ISequence_Xfer.hpp"
|
||||
#include "DList.hpp"
|
||||
|
||||
namespace xo { namespace scm { class ISequence_DList; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::scm::ASequence,
|
||||
xo::scm::DList>
|
||||
{
|
||||
using ImplType = xo::scm::ISequence_Xfer
|
||||
<xo::scm::DList,
|
||||
xo::scm::ISequence_DList>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class ISequence_DList
|
||||
**/
|
||||
class ISequence_DList {
|
||||
public:
|
||||
/** @defgroup scm-sequence-dlist-type-traits **/
|
||||
///@{
|
||||
using size_type = ASequence::size_type;
|
||||
using AGCObject = ASequence::AGCObject;
|
||||
///@}
|
||||
/** @defgroup scm-sequence-dlist-methods **/
|
||||
///@{
|
||||
/** true iff sequence is empty **/
|
||||
static bool is_empty(const DList & self) noexcept;
|
||||
/** true iff sequence is finite **/
|
||||
static bool is_finite(const DList & self) noexcept;
|
||||
/** return element @p index of this sequence **/
|
||||
static obj<AGCObject> at(const DList & self, size_type index);
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -6,9 +6,12 @@ set(SELF_SRCS
|
|||
IGCObject_DInteger.cpp
|
||||
IGCObject_DList.cpp
|
||||
ISequence_Any.cpp
|
||||
ISequence_DList.cpp
|
||||
DList.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
|
||||
xo_dependency(${SELF_LIB} xo_gc)
|
||||
#xo_dependency(${SELF_LIB} indentlog)
|
||||
#add_dependencies(${SELF_LIB} xo-object2-facetimpl-sequence-list)
|
||||
|
|
|
|||
54
xo-object2/src/object2/DList.cpp
Normal file
54
xo-object2/src/object2/DList.cpp
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/** @file DList.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Dec 2025
|
||||
**/
|
||||
|
||||
#include "DList.hpp"
|
||||
#include <xo/indentlog/print/tag.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
DList::size() const noexcept -> size_type
|
||||
{
|
||||
const DList * l = this;
|
||||
|
||||
size_type z = 0;
|
||||
|
||||
while (l) {
|
||||
++z;
|
||||
l = l->rest_;
|
||||
}
|
||||
|
||||
return z;
|
||||
}
|
||||
|
||||
auto
|
||||
DList::at(size_type index) const -> obj<AGCObject>
|
||||
{
|
||||
size_type ix = index;
|
||||
const DList * l = this;
|
||||
|
||||
while (l->rest_ && (ix > 0)) {
|
||||
--ix;
|
||||
l = l->rest_;
|
||||
}
|
||||
|
||||
if (ix > 0) {
|
||||
assert(l == nullptr);
|
||||
|
||||
throw std::runtime_error
|
||||
(tostr("DList::at: out-of-range index where [0..z) expected",
|
||||
xtag("index", index),
|
||||
xtag("z", this->size())));
|
||||
}
|
||||
|
||||
assert(l);
|
||||
|
||||
return l->head_;
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DList.cpp */
|
||||
|
|
@ -6,7 +6,9 @@
|
|||
#include "IGCObject_DList.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AGCObject;
|
||||
using xo::mm::AAllocator;
|
||||
using xo::facet::with_facet;
|
||||
using xo::facet::obj;
|
||||
using std::size_t;
|
||||
|
||||
|
|
@ -33,8 +35,11 @@ namespace xo {
|
|||
IGCObject_DList::forward_children(DList & src,
|
||||
obj<ACollector> gc) noexcept
|
||||
{
|
||||
gc.forward_inplace(&src.head_);
|
||||
gc.forward_inplace(&src.rest_);
|
||||
gc.forward_inplace(src.head_.iface(), (void **)&(src.head_.data_));
|
||||
|
||||
//auto rest = with_facet<AGCObject>::mkobj(src.rest_);
|
||||
xo::facet::FacetImplementation<xo::mm::AGCObject, DList>::ImplType iface;
|
||||
gc.forward_inplace(&iface, (void **)(&src.rest_));
|
||||
|
||||
return shallow_size(src);
|
||||
}
|
||||
|
|
|
|||
40
xo-object2/src/object2/ISequence_DList.cpp
Normal file
40
xo-object2/src/object2/ISequence_DList.cpp
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
/** @file ISequence_DList.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [/Users/roland/proj/xo-umbrella2/xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/ISequence_DList.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/ISequence_DList.json5]
|
||||
**/
|
||||
|
||||
#include "ISequence_DList.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
ISequence_DList::is_empty(const DList & self) noexcept -> bool
|
||||
{
|
||||
return self.is_empty();
|
||||
}
|
||||
|
||||
auto
|
||||
ISequence_DList::is_finite(const DList & self) noexcept -> bool
|
||||
{
|
||||
return self.is_finite();
|
||||
}
|
||||
|
||||
auto
|
||||
ISequence_DList::at(const DList & self, size_type index) -> obj<AGCObject>
|
||||
{
|
||||
return self.at(index);
|
||||
}
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end ISequence_DList.cpp */
|
||||
Loading…
Add table
Add a link
Reference in a new issue