xo-object2: + DArray [WIP] + utest
This commit is contained in:
parent
5628d00c7c
commit
0a6f449b3b
5 changed files with 272 additions and 0 deletions
|
|
@ -12,6 +12,7 @@ set(SELF_SRCS
|
|||
IPrintable_DFloat.cpp
|
||||
IPrintable_DInteger.cpp
|
||||
IPrintable_DString.cpp
|
||||
DArray.cpp
|
||||
DList.cpp
|
||||
DFloat.cpp
|
||||
DInteger.cpp
|
||||
|
|
|
|||
53
xo-object2/src/object2/DArray.cpp
Normal file
53
xo-object2/src/object2/DArray.cpp
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
/** @file DArray.cpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#include "DArray.hpp"
|
||||
|
||||
namespace xo {
|
||||
using xo::mm::AGCObject;
|
||||
using xo::facet::typeseq;
|
||||
|
||||
namespace scm {
|
||||
DArray *
|
||||
DArray::empty(obj<AAllocator> mm,
|
||||
size_type cap)
|
||||
{
|
||||
assert(cap > 0);
|
||||
|
||||
DArray * result = nullptr;
|
||||
|
||||
if (cap > 0) {
|
||||
void * mem = mm.alloc(typeseq::id<DArray>(),
|
||||
sizeof(DArray) + cap * sizeof(obj<AGCObject>));
|
||||
|
||||
result = new (mem) DArray();
|
||||
|
||||
assert(result);
|
||||
|
||||
result->capacity_ = cap;
|
||||
result->size_ = 0;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
bool
|
||||
DArray::push_back(obj<AGCObject> elt) noexcept {
|
||||
if (size_ >= capacity_) {
|
||||
return false;
|
||||
} else {
|
||||
static_assert(!std::is_trivially_constructible_v<obj<AGCObject>>);
|
||||
|
||||
void * mem = &(elts_[size_]);
|
||||
|
||||
new (mem) obj<AGCObject>(elt);
|
||||
|
||||
++(this->size_);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
Loading…
Add table
Add a link
Reference in a new issue