refactor: + xo-stringtable2 w/ DString impl
This commit is contained in:
parent
c8a76d23bd
commit
00a22e81c0
21 changed files with 12 additions and 1406 deletions
|
|
@ -33,10 +33,6 @@ set(SELF_SRCS
|
|||
IGCObject_DBoolean.cpp
|
||||
IPrintable_DBoolean.cpp
|
||||
|
||||
DString.cpp
|
||||
IGCObject_DString.cpp
|
||||
IPrintable_DString.cpp
|
||||
|
||||
DDictionary.cpp
|
||||
IGCObject_DDictionary.cpp
|
||||
IPrintable_DDictionary.cpp
|
||||
|
|
@ -50,6 +46,7 @@ xo_add_shared_library4(${SELF_LIB} ${PROJECT_NAME}Targets ${PROJECT_VERSION} 1 $
|
|||
# note: deps here must also appear in cmake/xo_object2Config.cmake.in
|
||||
xo_dependency(${SELF_LIB} reflect)
|
||||
xo_dependency(${SELF_LIB} xo_gc)
|
||||
xo_dependency(${SELF_LIB} xo_stringtable2)
|
||||
xo_dependency(${SELF_LIB} xo_printable2)
|
||||
xo_dependency(${SELF_LIB} subsys)
|
||||
xo_dependency(${SELF_LIB} indentlog)
|
||||
|
|
|
|||
|
|
@ -1,187 +0,0 @@
|
|||
/** @file DString.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#include "DString.hpp"
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include <xo/indentlog/print/pretty.hpp>
|
||||
#include <algorithm>
|
||||
#include <cstring>
|
||||
|
||||
namespace xo {
|
||||
using xo::reflect::typeseq;
|
||||
using xo::print::ppdetail_atomic;
|
||||
|
||||
namespace scm {
|
||||
DString *
|
||||
DString::empty(obj<AAllocator> mm,
|
||||
size_type cap)
|
||||
{
|
||||
assert(cap > 0);
|
||||
|
||||
DString * result = nullptr;
|
||||
|
||||
if (cap > 0) {
|
||||
void * mem = mm.alloc(typeseq::id<DString>(),
|
||||
sizeof(DString) + cap);
|
||||
|
||||
result = new (mem) DString();
|
||||
|
||||
assert(result);
|
||||
|
||||
result->capacity_ = cap;
|
||||
result->size_ = 0;
|
||||
if (cap > 0) {
|
||||
result->chars_[0] = '\0';
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
DString *
|
||||
DString::from_cstr(obj<AAllocator> mm,
|
||||
const char * cstr)
|
||||
{
|
||||
size_type len = std::strlen(cstr);
|
||||
size_type cap = len + 1;
|
||||
|
||||
void * mem = mm.alloc(typeseq::id<DString>(),
|
||||
sizeof(DString) + cap);
|
||||
|
||||
DString * result = new (mem) DString();
|
||||
result->capacity_ = cap;
|
||||
result->size_ = len;
|
||||
std::memcpy(result->chars_, cstr, cap);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
DString *
|
||||
DString::_from_view_aux(obj<AAllocator> mm,
|
||||
std::string_view sv,
|
||||
bool suballoc_flag)
|
||||
{
|
||||
size_type len = sv.size();
|
||||
size_type cap = len + 1;
|
||||
|
||||
auto tseq = typeseq::id<DString>();
|
||||
void * mem = nullptr;
|
||||
size_type mem_z = sizeof(DString) + cap;
|
||||
|
||||
if (suballoc_flag)
|
||||
mem = mm.sub_alloc(mem_z, false /*!complete_flag*/);
|
||||
else
|
||||
mem = mm.alloc(tseq, mem_z);
|
||||
|
||||
DString * result = new (mem) DString();
|
||||
|
||||
result->capacity_ = cap;
|
||||
result->size_ = len;
|
||||
std::memcpy(result->chars_, sv.data(), len);
|
||||
result->chars_[len] = '\0';
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
DString *
|
||||
DString::from_view(obj<AAllocator> mm,
|
||||
std::string_view sv)
|
||||
{
|
||||
return _from_view_aux(mm, sv, false /*!suballoc_flag*/);
|
||||
}
|
||||
|
||||
DString *
|
||||
DString::from_str(obj<AAllocator> mm,
|
||||
const std::string & str)
|
||||
{
|
||||
return _from_view_aux(mm,
|
||||
std::string_view(str),
|
||||
false /*!suballoc_flag*/);
|
||||
}
|
||||
|
||||
DString *
|
||||
DString::from_view_suballoc(obj<AAllocator> mm,
|
||||
std::string_view sv)
|
||||
{
|
||||
return _from_view_aux(mm, sv, true /*suballoc_flag*/);
|
||||
}
|
||||
|
||||
DString *
|
||||
DString::clone(obj<AAllocator> mm, const DString * src)
|
||||
{
|
||||
size_type cap = src->capacity_;
|
||||
|
||||
void * mem = mm.alloc(typeseq::id<DString>(),
|
||||
sizeof(DString) + cap);
|
||||
|
||||
DString * result = new (mem) DString();
|
||||
result->capacity_ = cap;
|
||||
result->size_ = src->size_;
|
||||
std::memcpy(result->chars_, src->chars_, cap);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
DString &
|
||||
DString::assign(const DString & other)
|
||||
{
|
||||
size_type n = std::min(other.size_, capacity_ - 1);
|
||||
std::memcpy(chars_, other.chars_, n);
|
||||
chars_[n] = '\0';
|
||||
size_ = n;
|
||||
|
||||
return *this;
|
||||
}
|
||||
|
||||
int
|
||||
DString::compare(const DString & lhs, const DString & rhs) noexcept
|
||||
{
|
||||
return ::strcmp(lhs.chars_, rhs.chars_);
|
||||
}
|
||||
|
||||
auto
|
||||
DString::fixup_size() noexcept -> size_type
|
||||
{
|
||||
this->chars_[capacity_ - 1] = '\0';
|
||||
this->size_ = ::strlen(chars_);
|
||||
return this->size_;
|
||||
}
|
||||
|
||||
auto
|
||||
DString::shallow_size() const noexcept -> size_type
|
||||
{
|
||||
return sizeof(DString) + capacity_;
|
||||
}
|
||||
|
||||
DString *
|
||||
DString::shallow_copy(obj<AAllocator> mm) const noexcept
|
||||
{
|
||||
DString * copy = (DString *)mm.alloc_copy((std::byte *)this);
|
||||
|
||||
if (copy) {
|
||||
copy->capacity_ = capacity_;
|
||||
copy->size_ = size_;
|
||||
::memcpy(copy->chars_, chars_, capacity_);
|
||||
}
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
auto
|
||||
DString::forward_children(obj<ACollector>) noexcept -> size_type
|
||||
{
|
||||
return shallow_size();
|
||||
}
|
||||
|
||||
bool
|
||||
DString::pretty(const ppindentinfo & ppii) const
|
||||
{
|
||||
return ppdetail_atomic<const char *>::print_pretty(ppii, &(chars_[0]));
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end DString.cpp */
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
/** @file IGCObject_DString.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DString.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObject_DString.json5]
|
||||
**/
|
||||
|
||||
#include "string/IGCObject_DString.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IGCObject_DString::shallow_size(const DString & self) noexcept -> size_type
|
||||
{
|
||||
return self.shallow_size();
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DString::shallow_copy(const DString & self, obj<AAllocator> mm) noexcept -> Opaque
|
||||
{
|
||||
return self.shallow_copy(mm);
|
||||
}
|
||||
|
||||
auto
|
||||
IGCObject_DString::forward_children(DString & self, obj<ACollector> gc) noexcept -> size_type
|
||||
{
|
||||
return self.forward_children(gc);
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IGCObject_DString.cpp */
|
||||
|
|
@ -1,28 +0,0 @@
|
|||
/** @file IPrintable_DString.cpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DString.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_any.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DString.json5]
|
||||
**/
|
||||
|
||||
#include "string/IPrintable_DString.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
auto
|
||||
IPrintable_DString::pretty(const DString & self, const ppindentinfo & ppii) -> bool
|
||||
{
|
||||
return self.pretty(ppii);
|
||||
}
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end IPrintable_DString.cpp */
|
||||
|
|
@ -6,7 +6,8 @@
|
|||
#include "init_object2.hpp"
|
||||
#include "object2_register_facets.hpp"
|
||||
#include "object2_register_types.hpp"
|
||||
#include <xo/gc/CollectorTypeRegistry.hpp>
|
||||
#include <xo/stringtable2/init_stringtable2.hpp>
|
||||
#include <xo/alloc2/CollectorTypeRegistry.hpp>
|
||||
#include <xo/alloc2/init_alloc2.hpp>
|
||||
|
||||
namespace xo {
|
||||
|
|
@ -29,6 +30,7 @@ namespace xo {
|
|||
|
||||
/* direct subsystem deps for xo-object2/ */
|
||||
retval ^= InitSubsys<S_alloc2_tag>::require();
|
||||
retval ^= InitSubsys<S_stringtable2_tag>::require();
|
||||
|
||||
/* xo-expression2/'s own initialization code */
|
||||
retval ^= Subsystem::provide<S_object2_tag>("object2", &init);
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@
|
|||
#include <xo/object2/Boolean.hpp>
|
||||
#include <xo/object2/Integer.hpp>
|
||||
#include <xo/object2/Float.hpp>
|
||||
#include <xo/object2/String.hpp>
|
||||
#include <xo/stringtable2/String.hpp>
|
||||
|
||||
#include <xo/printable2/detail/APrintable.hpp>
|
||||
#include <xo/alloc2/alloc/AAllocator.hpp>
|
||||
|
|
@ -70,7 +70,6 @@ namespace xo {
|
|||
log && log(xtag("DBoolean.tseq", typeseq::id<DBoolean>()));
|
||||
log && log(xtag("DFloat.tseq", typeseq::id<DFloat>()));
|
||||
log && log(xtag("DInteger.tseq", typeseq::id<DInteger>()));
|
||||
log && log(xtag("DString.tseq", typeseq::id<DString>()));
|
||||
log && log(xtag("DArray.tseq", typeseq::id<DArray>()));
|
||||
log && log(xtag("DDictionary.tseq", typeseq::id<DDictionary>()));
|
||||
log && log(xtag("DRuntimeError.tseq", typeseq::id<DRuntimeError>()));
|
||||
|
|
|
|||
|
|
@ -36,8 +36,6 @@ namespace xo {
|
|||
|
||||
ok &= gc.install_type(impl_for<AGCObject, DInteger>());
|
||||
|
||||
ok &= gc.install_type(impl_for<AGCObject, DString>());
|
||||
|
||||
ok &= gc.install_type(impl_for<AGCObject, DList>());
|
||||
|
||||
ok &= gc.install_type(impl_for<AGCObject, DArray>());
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue