xo-XXX -> .xo-XXX (prep subrepo)
This commit is contained in:
parent
2342dc02a2
commit
cf0bd4d975
2105 changed files with 0 additions and 0 deletions
|
|
@ -1,346 +0,0 @@
|
|||
/** @file DString.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include <xo/alloc2/GCObjectVisitor.hpp>
|
||||
#include <xo/facet/obj.hpp>
|
||||
#include <xo/indentlog/print/ppindentinfo.hpp>
|
||||
#include <string_view>
|
||||
#include <functional>
|
||||
#include <cstdint>
|
||||
//#include <cstdio>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class DString
|
||||
* @brief String implementation with gc hooks
|
||||
*
|
||||
* String implementation for Schematika.
|
||||
* Size-prefixed and null-terminated.
|
||||
* Note however that string length != size for utf-8.
|
||||
*
|
||||
* Uses flexible array for chars,
|
||||
* with string contents in memory immediately
|
||||
* following the DString itself
|
||||
**/
|
||||
struct DString {
|
||||
public:
|
||||
/** @defgroup dstring-types type traits **/
|
||||
///@{
|
||||
/** character traits for this DString **/
|
||||
using traits_type = std::char_traits<char>;
|
||||
/** type of each character in this DString **/
|
||||
using value_type = char;
|
||||
/** type for string index / size **/
|
||||
using size_type = std::uint32_t;
|
||||
/** representation for a read/write iterator **/
|
||||
using iterator = char *;
|
||||
/** representation for a readonly iterator **/
|
||||
using const_iterator = const char *;
|
||||
/** xo allocator **/
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
/** object visitor (garbage collector proxy) **/
|
||||
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
|
||||
/** visitor hint **/
|
||||
using VisitReason = xo::mm::VisitReason;
|
||||
/** ppindentinfo for APrintable **/
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
///@}
|
||||
/** @defgroup dstring-ctors constructors **/
|
||||
///@{
|
||||
|
||||
/** default ctor **/
|
||||
DString() = default;
|
||||
|
||||
/** not simply copyable, because of flexible array.
|
||||
* Need allocator
|
||||
**/
|
||||
DString(const DString &) = delete;
|
||||
|
||||
/** create empty string with space for @p cap chars
|
||||
* (including null terminator).
|
||||
* Use memory from allocator @p mm
|
||||
**/
|
||||
static DString * empty(obj<AAllocator> mm,
|
||||
size_type cap);
|
||||
|
||||
/** create string containing a copy of null-terminated @p cstr.
|
||||
* Use memory from allocator @p mm
|
||||
**/
|
||||
static DString * from_cstr(obj<AAllocator> mm,
|
||||
const char * cstr);
|
||||
|
||||
/** create string containing a copy of @p sv.
|
||||
* Use memory from allocator @p mm.
|
||||
**/
|
||||
static DString * from_view(obj<AAllocator> mm,
|
||||
std::string_view sv);
|
||||
|
||||
/** create string containing a copy @p str.
|
||||
* Use memory from allocator @p mm.
|
||||
**/
|
||||
static DString * from_str(obj<AAllocator> mm,
|
||||
const std::string & str);
|
||||
|
||||
/** create string containing a copy of @p sv.
|
||||
* Use memory from allocator @p mm via sub_alloc.
|
||||
* (load-bearing for StringTable)
|
||||
**/
|
||||
static DString * from_view_suballoc(obj<AAllocator> mm,
|
||||
std::string_view sv);
|
||||
|
||||
/** clone existing string **/
|
||||
static DString * clone(obj<AAllocator> mm,
|
||||
const DString * src);
|
||||
|
||||
#ifdef NOT_YET
|
||||
/** **/
|
||||
static DString * concat(obj<AAllocator> mm,
|
||||
DString * s1,
|
||||
DString * s2);
|
||||
#endif
|
||||
|
||||
/** create string using printf-style formatting.
|
||||
* Use memory from allocator @p mm with capacity @p cap.
|
||||
* Truncates if result exceeds capacity.
|
||||
* @return pointer to newly created DString
|
||||
**/
|
||||
template <typename... Args>
|
||||
static DString * printf(obj<AAllocator> mm,
|
||||
size_type cap,
|
||||
const char * fmt,
|
||||
Args&&... args);
|
||||
|
||||
///@}
|
||||
/** @defgroup dstring-access access methods **/
|
||||
///@{
|
||||
|
||||
/** get writeable access to string representation.
|
||||
* Caller responsible for calling fixup() if string length modified
|
||||
**/
|
||||
char * data() noexcept { return chars_; }
|
||||
|
||||
/** return char at position @p pos in this string, counting from zero.
|
||||
* Does not check bounds. Undefined behavior if @p pos = @ref capacity_
|
||||
**/
|
||||
char & operator[](size_type pos) noexcept { return chars_[pos]; }
|
||||
const char & operator[](size_type pos) const noexcept { return chars_[pos]; }
|
||||
|
||||
size_type capacity() const noexcept { return capacity_; }
|
||||
size_type size() const noexcept { return size_; }
|
||||
const char * chars() const noexcept { return chars_; }
|
||||
|
||||
///@}
|
||||
/** @defgroup dstring-iterators iterators **/
|
||||
///@{
|
||||
iterator begin() noexcept { return &chars_[0]; }
|
||||
iterator end() noexcept { return &chars_[size_]; }
|
||||
|
||||
const_iterator cbegin() const noexcept { return &chars_[0]; }
|
||||
const_iterator cend() const noexcept { return &chars_[size_]; }
|
||||
const_iterator begin() const noexcept { return cbegin(); }
|
||||
const_iterator end() const noexcept { return cend(); }
|
||||
|
||||
///@}
|
||||
/** @defgroup dstring-assign assignment **/
|
||||
///@{
|
||||
|
||||
/** put string into empty state **/
|
||||
void clear() noexcept { size_ = 0; chars_[0] = '\0'; }
|
||||
|
||||
/** replace contents with @p other, or prefix of up to @p capacity - 1 chars **/
|
||||
DString & assign(const DString & other);
|
||||
///@}
|
||||
/** @defgroup dstring-general general methods **/
|
||||
///@{
|
||||
|
||||
/** format string into this DString using printf-style formatting.
|
||||
* Truncates if result exceeds capacity.
|
||||
* @return number of characters written (excluding null terminator)
|
||||
**/
|
||||
template <typename... Args>
|
||||
size_type sprintf(const char * fmt, Args&&... args) {
|
||||
int n;
|
||||
if constexpr (sizeof...(Args) == 0) {
|
||||
n = std::snprintf(chars_, capacity_, "%s", fmt);
|
||||
} else {
|
||||
n = std::snprintf(chars_, capacity_, fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
if (n < 0) {
|
||||
size_ = 0;
|
||||
chars_[0] = '\0';
|
||||
} else {
|
||||
size_ = (n < static_cast<int>(capacity_)) ? n : capacity_ - 1;
|
||||
}
|
||||
return size_;
|
||||
}
|
||||
|
||||
/** lexicographically compare two strings.
|
||||
* @return <0 if lhs < rhs, 0 if equal, >0 if lhs > rhs
|
||||
**/
|
||||
static int compare(const DString & lhs, const DString & rhs) noexcept;
|
||||
|
||||
/** compute hash of string contents **/
|
||||
std::size_t hash() const noexcept {
|
||||
return std::hash<std::string_view>{}(std::string_view(chars_, size_));
|
||||
}
|
||||
|
||||
// TODO - behave like std::string, to the extent feasible
|
||||
// insert
|
||||
// insert_range
|
||||
// erase
|
||||
// push_back
|
||||
// append
|
||||
// append_range
|
||||
// operator+=
|
||||
// replace
|
||||
// replace_with_range
|
||||
// copy
|
||||
// find
|
||||
// rfind
|
||||
// find_first_of
|
||||
// find_first_not_of
|
||||
// find_last_of
|
||||
// find_last_not_of
|
||||
// starts_with
|
||||
// end_with
|
||||
// contains
|
||||
// substr
|
||||
|
||||
/** recalculate string size if string contents modified without
|
||||
* through side effects
|
||||
**/
|
||||
size_type fixup_size() noexcept;
|
||||
|
||||
///@}
|
||||
/** @defgroup dstring-conversion-operators conversion operators **/
|
||||
///@{
|
||||
|
||||
operator std::string_view() const noexcept { return std::string_view(chars_); }
|
||||
|
||||
/** @brief conversion oeprator to C-style string.
|
||||
*
|
||||
* Example
|
||||
* @code
|
||||
* DString s = ...;
|
||||
* ::strcmp(s, "obey...");
|
||||
* @endcode
|
||||
**/
|
||||
operator const char * () const noexcept { return &(chars_[0]); }
|
||||
|
||||
///@}
|
||||
/** @defgroup dstring-printable-methods printable facet methods **/
|
||||
///@{
|
||||
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
///@}
|
||||
/** @defgroup dstring-gcobject-methods gcobject facet methods **/
|
||||
///@{
|
||||
|
||||
/** clone string, using memory from allocator @p mm **/
|
||||
DString * gco_shallow_move(obj<AGCObjectVisitor> gc) noexcept;
|
||||
|
||||
/** fixup child pointers (trivial for DString, no children)
|
||||
* note: cref so we can use forward decl
|
||||
**/
|
||||
void visit_gco_children(VisitReason reason, obj<AGCObjectVisitor> gc) noexcept;
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** @defgroup dstring-impl-methods implementation methods **/
|
||||
///@{
|
||||
|
||||
/** create instance from view @p sv, using memory from @p mm.
|
||||
* @p suballoc_flag chooses whether to use alloc() or suballoc().
|
||||
* Load-bearing for StringTable
|
||||
**/
|
||||
static DString * _from_view_aux(obj<AAllocator> mm,
|
||||
std::string_view sv,
|
||||
bool suballoc_flag);
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** @defgroup dstring-instance-variables instance variables **/
|
||||
///@{
|
||||
|
||||
/** extent of @ref chars_ array **/
|
||||
size_type capacity_ = 0;
|
||||
/** null terminator at @c chars_[size_] **/
|
||||
size_type size_ = 0;
|
||||
/** string contents **/
|
||||
char chars_[];
|
||||
|
||||
///@}
|
||||
};
|
||||
|
||||
/** create string using printf-style formatting.
|
||||
* Use memory from allocator @p mm with capacity @p cap.
|
||||
* Truncates if result exceeds capacity.
|
||||
* @return pointer to newly created DString
|
||||
**/
|
||||
template <typename... Args>
|
||||
DString * DString::printf(obj<AAllocator> mm,
|
||||
size_type cap,
|
||||
const char * fmt,
|
||||
Args&&... args)
|
||||
{
|
||||
DString * result = DString::empty(mm, cap);
|
||||
if (result) {
|
||||
result->sprintf(fmt, std::forward<Args>(args)...);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
inline std::ostream & operator<<(std::ostream & os, const DString * x) {
|
||||
if (x) {
|
||||
os << std::string_view(*x);
|
||||
} else {
|
||||
os << "nullptr";
|
||||
}
|
||||
return os;
|
||||
}
|
||||
|
||||
inline bool operator==(const DString & lhs, const DString & rhs) {
|
||||
return DString::compare(lhs, rhs) == 0;
|
||||
}
|
||||
|
||||
inline bool operator!=(const DString & lhs, const DString & rhs) {
|
||||
return DString::compare(lhs, rhs) != 0;
|
||||
}
|
||||
|
||||
inline bool operator<(const DString & lhs, const DString & rhs) {
|
||||
return DString::compare(lhs, rhs) < 0;
|
||||
}
|
||||
|
||||
inline bool operator<=(const DString & lhs, const DString & rhs) {
|
||||
return DString::compare(lhs, rhs) <= 0;
|
||||
}
|
||||
|
||||
inline bool operator>(const DString & lhs, const DString & rhs) {
|
||||
return DString::compare(lhs, rhs) > 0;
|
||||
}
|
||||
|
||||
inline bool operator>=(const DString & lhs, const DString & rhs) {
|
||||
return DString::compare(lhs, rhs) >= 0;
|
||||
}
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
namespace std {
|
||||
template <>
|
||||
struct hash<xo::scm::DString> {
|
||||
std::size_t operator()(const xo::scm::DString & x) const noexcept {
|
||||
return x.hash();
|
||||
}
|
||||
};
|
||||
} /*namespace std*/
|
||||
|
||||
/* end DString.hpp */
|
||||
|
|
@ -1,142 +0,0 @@
|
|||
/** @file DUniqueString.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <xo/stringtable2/DString.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class DUniqueString
|
||||
* @brief unique immutable string
|
||||
*
|
||||
* A DUniqueString is an immutable string stored in a shared StringTable.
|
||||
* Follows that DUniqueStrings at different memory locations
|
||||
* have different contents.
|
||||
*
|
||||
* DUniqueString instances will be created by StringTable (see also).
|
||||
* Application code will not allocate them directly.
|
||||
*
|
||||
* Needs to be gc-aware so that collector knows what to do when it encounters
|
||||
* a obj<AGCObject> with a DUnqiueString data pointer; such instances
|
||||
* will not be allocated from GC memory
|
||||
**/
|
||||
class DUniqueString {
|
||||
public:
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using ACollector = xo::mm::ACollector;
|
||||
using AGCObjectVisitor = xo::mm::AGCObjectVisitor;
|
||||
using VisitReason = xo::mm::VisitReason;
|
||||
using size_type = DString::size_type;
|
||||
using ppindentinfo = xo::print::ppindentinfo;
|
||||
|
||||
/* Memory model for a DUniqueString allocated via xo allocator
|
||||
*
|
||||
* 0 8 16 20 24 24+z
|
||||
* v v v v v v
|
||||
* +---------------+-+-------------+-------+-------+-----------+
|
||||
* | header |u| padding | cap | size | text... \0|
|
||||
* +---------------+-+-------------+-------+-------+-----------+
|
||||
*
|
||||
* Legend
|
||||
* header 8 byte allocation header
|
||||
* u 1 byte DUniqueString placeholder (c++ insists)
|
||||
* padding 7 bytes allocator-imposed padding to 8-byte alignment
|
||||
* cap 4 bytes DString.capacity
|
||||
* size 4 bytes DString.size
|
||||
* text z bytes DString.size bytes of text (including null)
|
||||
* In practice followed by padding to 8 byte
|
||||
* alignment
|
||||
*/
|
||||
|
||||
/** @defgroup duniquestring-ctors constructors **/
|
||||
///@{
|
||||
|
||||
/** not copyable **/
|
||||
DUniqueString(const DUniqueString &) = delete;
|
||||
|
||||
static constexpr bool is_gc_eligible() { return false; }
|
||||
|
||||
///@}
|
||||
/** @defgroup duniquestring-methods methods **/
|
||||
///@{
|
||||
|
||||
/** Available storage for this instance.
|
||||
* For completeness' sake since uniquestring not modifiable
|
||||
**/
|
||||
size_type capacity() const noexcept { return _text()->capacity(); }
|
||||
size_type size() const noexcept { return _text()->size(); }
|
||||
const char * chars() const noexcept { return _text()->chars(); }
|
||||
|
||||
/** compare unique strings: return n with {n<0, n=0, n>0}
|
||||
* when @p lhs lexicographically {before, at, after} @p rhs
|
||||
**/
|
||||
static int compare(const DUniqueString & lhs, const DUniqueString & rhs);
|
||||
|
||||
std::size_t hash() const noexcept { return _text()->hash(); }
|
||||
operator std::string_view() const noexcept { return std::string_view(*_text()); }
|
||||
/** not assignable **/
|
||||
DUniqueString & operator=(const DUniqueString &) = delete;
|
||||
|
||||
///@}
|
||||
/** @defgroup duniquestring-printable-methods printable facet methods **/
|
||||
///@{
|
||||
|
||||
bool pretty(const ppindentinfo & ppii) const;
|
||||
|
||||
///@}
|
||||
/** @defgroup duniquestring-gcobject-methods gcobject facet methods **/
|
||||
///@{
|
||||
|
||||
/** clone unique string, using memory from allocator @p mm. **/
|
||||
DUniqueString * gco_shallow_move(obj<AGCObjectVisitor> gc) noexcept;
|
||||
|
||||
/** fixup child pointers (trivial for DUniqueString, no gc-owned children **/
|
||||
void visit_gco_children(VisitReason reason, obj<AGCObjectVisitor> gc) noexcept;
|
||||
|
||||
///@}
|
||||
|
||||
private:
|
||||
/** @defgroup duniquestring-impl-methods implementation methods **/
|
||||
///@{
|
||||
|
||||
/** default ctor **/
|
||||
DUniqueString() = default;
|
||||
|
||||
/** DString containing actual string content immediately follows DUniqueString
|
||||
* in memory; part of same alloc
|
||||
**/
|
||||
DString * _text() const noexcept;
|
||||
|
||||
//explicit DUniqueString(const DString * text) : text_{text} {}
|
||||
|
||||
/** create instance using memory from @p mm,
|
||||
* with string contents copied from @p sv
|
||||
**/
|
||||
static DUniqueString * from_view(obj<AAllocator> mm,
|
||||
std::string_view sv);
|
||||
|
||||
///@}
|
||||
|
||||
friend class StringTable;
|
||||
};
|
||||
|
||||
/* since unique: just compare addresses */
|
||||
inline bool operator==(const DUniqueString & lhs, const DUniqueString & rhs) {
|
||||
return (&lhs == &rhs);
|
||||
}
|
||||
|
||||
/* since unique: just compare addresses **/
|
||||
inline bool operator!=(const DUniqueString & lhs, const DUniqueString & rhs) {
|
||||
return (&lhs != &rhs);
|
||||
}
|
||||
|
||||
inline bool operator<=(const DUniqueString & lhs, const DUniqueString & rhs) {
|
||||
return (DUniqueString::compare(lhs, rhs) <= 0);
|
||||
}
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end UniqueString.hpp */
|
||||
|
|
@ -1,25 +0,0 @@
|
|||
/** @file SetupStringtable2.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Mar 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <xo/alloc2/Collector.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
struct SetupStringtable2 {
|
||||
public:
|
||||
using ACollector = xo::mm::ACollector;
|
||||
|
||||
public:
|
||||
/** Register object2 (facet,impl) combinations with FacetRegistry **/
|
||||
static bool register_facets();
|
||||
/** Register types with garbage collector **/
|
||||
static bool register_types(obj<ACollector> gc);
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
/* end SetupStringtable2.hpp */
|
||||
|
|
@ -1,14 +0,0 @@
|
|||
/** @file String.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DString.hpp"
|
||||
#include "string/IGCObject_DString.hpp"
|
||||
#include "string/IPrintable_DString.hpp"
|
||||
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
|
||||
/* end String.hpp */
|
||||
|
|
@ -1,80 +0,0 @@
|
|||
/** @file StringOps.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "string/IGCObject_DString.hpp"
|
||||
#include "DString.hpp"
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @brief string functions
|
||||
*
|
||||
* note: separate from DString
|
||||
**/
|
||||
struct StringOps {
|
||||
using AGCObject = xo::mm::AGCObject;
|
||||
using AAllocator = xo::mm::AAllocator;
|
||||
using size_type = DString::size_type;
|
||||
|
||||
/** wrapper for DString.empty() **/
|
||||
template <typename AFacet = AGCObject>
|
||||
static obj<AFacet,DString> empty(obj<AAllocator> mm,
|
||||
size_type cap);
|
||||
|
||||
/** wrapper for DString.from_cstr() **/
|
||||
template <typename AFacet = AGCObject>
|
||||
static obj<AFacet,DString> from_cstr(obj<AAllocator> mm,
|
||||
const char * cstr);
|
||||
|
||||
/** wrapper for DString.clone() **/
|
||||
template <typename AFacet = AGCObject,
|
||||
typename ASrcFacet = AGCObject>
|
||||
static obj<AFacet,DString> clone(obj<AAllocator> mm,
|
||||
obj<ASrcFacet,DString> src);
|
||||
|
||||
/** wrapper for DString.printf() **/
|
||||
template <typename AFacet = AGCObject, typename... Args>
|
||||
static obj<AFacet,DString> printf(obj<AAllocator> mm,
|
||||
size_type cap,
|
||||
const char * fmt,
|
||||
Args&&... args);
|
||||
};
|
||||
|
||||
template <typename AFacet>
|
||||
obj<AFacet,DString>
|
||||
StringOps::empty(obj<AAllocator> mm, size_type cap)
|
||||
{
|
||||
return obj<AFacet,DString>(DString::empty(mm, cap));
|
||||
}
|
||||
|
||||
template <typename AFacet>
|
||||
obj<AFacet,DString>
|
||||
StringOps::from_cstr(obj<AAllocator> mm, const char * cstr)
|
||||
{
|
||||
return obj<AFacet,DString>(DString::from_cstr(mm, cstr));
|
||||
}
|
||||
|
||||
template <typename AFacet, typename ASrcFacet>
|
||||
obj<AFacet,DString>
|
||||
StringOps::clone(obj<AAllocator> mm, obj<ASrcFacet,DString> src)
|
||||
{
|
||||
return obj<AFacet,DString>(DString::clone(mm, src.data()));
|
||||
}
|
||||
|
||||
template <typename AFacet, typename... Args>
|
||||
obj<AFacet,DString>
|
||||
StringOps::printf(obj<AAllocator> mm,
|
||||
size_type cap,
|
||||
const char * fmt,
|
||||
Args&&... args)
|
||||
{
|
||||
return obj<AFacet,DString>(DString::printf(mm, cap, fmt,
|
||||
std::forward<Args>(args)...));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* end StringOps.hpp */
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
/** @file StringTable.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DUniqueString.hpp"
|
||||
#include <xo/arena/DArenaHashMap.hpp>
|
||||
#include <xo/arena/DArena.hpp>
|
||||
#include <xo/arena/hashmap/verify_policy.hpp>
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
|
||||
/** @class StringTable
|
||||
* @brief table containing a set of interned strings
|
||||
*
|
||||
* A table of strings referenced in schematika expressions
|
||||
**/
|
||||
class StringTable {
|
||||
public:
|
||||
using DArena = xo::mm::DArena;
|
||||
using MemorySizeVisitor = xo::mm::MemorySizeVisitor;
|
||||
using StringMap = xo::map::DArenaHashMap<std::string_view,
|
||||
DUniqueString*>;
|
||||
using size_type = StringMap::size_type;
|
||||
|
||||
public:
|
||||
/** hint_max_capacity in bytes = capacity for strings **/
|
||||
StringTable(size_type hint_max_capacity,
|
||||
bool debug_flag = false);
|
||||
|
||||
/** false -> not eligible for GC (maps own memory + not moveable) **/
|
||||
static constexpr bool is_gc_eligible() { return false; }
|
||||
|
||||
/** lookup interned string; nullptr if not present **/
|
||||
const DUniqueString * lookup(std::string_view key) const;
|
||||
|
||||
/** return unique string with contents @p key. Idempotent! **/
|
||||
const DUniqueString * intern(std::string_view key);
|
||||
|
||||
/** generate unique symbol -- guaranteed not to collide
|
||||
* with existing symbol in this table.
|
||||
**/
|
||||
const DUniqueString * gensym(std::string_view prefix);
|
||||
|
||||
/** verify StringTable invariants.
|
||||
* Act on failure according to policy @p p
|
||||
**/
|
||||
bool verify_ok(verify_policy p = verify_policy::throw_only()) const;
|
||||
|
||||
/** visit string-table memory pools, call visitor(info) for each **/
|
||||
void visit_pools(const MemorySizeVisitor & visitor) const;
|
||||
|
||||
private:
|
||||
/** allocate string storage in this arena; use DString to represent each string.
|
||||
* Can't use DArenaVector b/c DString has variable size
|
||||
**/
|
||||
DArena strings_;
|
||||
/** map_[s] points to arena strings, i.e. members of @ref strings_ **/
|
||||
StringMap map_;
|
||||
};
|
||||
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end StringTable.hpp */
|
||||
|
|
@ -1,12 +0,0 @@
|
|||
/** @file UniqueString.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Feb 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "DUniqueString.hpp"
|
||||
#include "uniquestring/IGCObject_DUniqueString.hpp"
|
||||
#include "uniquestring/IPrintable_DUniqueString.hpp"
|
||||
|
||||
/* end UniqueString.hpp */
|
||||
|
|
@ -1,21 +0,0 @@
|
|||
/** @file init_stringtable2.hpp
|
||||
*
|
||||
* @author Roland Conybeare, Jan 2026
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <xo/subsys/Subsystem.hpp>
|
||||
|
||||
namespace xo {
|
||||
/* tag to represent the xo-expression2/ subsystem within ordered initialization */
|
||||
enum S_stringtable2_tag {};
|
||||
|
||||
template <>
|
||||
struct InitSubsys<S_stringtable2_tag> {
|
||||
static void init();
|
||||
static InitEvidence require();
|
||||
};
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end init_stringtable2.hpp */
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
/** @file IGCObject_DString.hpp
|
||||
*
|
||||
* 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_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObject_DString.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GCObject.hpp"
|
||||
#include <xo/alloc2/GCObject.hpp>
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include "DString.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IGCObject_DString; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::mm::AGCObject,
|
||||
xo::scm::DString>
|
||||
{
|
||||
using ImplType = xo::mm::IGCObject_Xfer
|
||||
<xo::scm::DString,
|
||||
xo::scm::IGCObject_DString>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IGCObject_DString
|
||||
**/
|
||||
class IGCObject_DString {
|
||||
public:
|
||||
/** @defgroup scm-gcobject-dstring-type-traits **/
|
||||
///@{
|
||||
using size_type = xo::mm::AGCObject::size_type;
|
||||
using AAllocator = xo::mm::AGCObject::AAllocator;
|
||||
using AGCObjectVisitor = xo::mm::AGCObject::AGCObjectVisitor;
|
||||
using VisitReason = xo::mm::AGCObject::VisitReason;
|
||||
using Copaque = xo::mm::AGCObject::Copaque;
|
||||
using Opaque = xo::mm::AGCObject::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-gcobject-dstring-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
|
||||
// non-const methods
|
||||
/** move instance using object visitor.
|
||||
Arguably abusing the word 'visitor' here **/
|
||||
static Opaque gco_shallow_move(DString & self, obj<AGCObjectVisitor> gc) noexcept;
|
||||
/** Invoke fn.visit_child(iface,data) for each child GCObject pointer.
|
||||
Context: provides address of data pointer so it can be updated in place
|
||||
when @p fn invokes garbage collector reentry point **/
|
||||
static void visit_gco_children(DString & self, VisitReason reason, obj<AGCObjectVisitor> fn) noexcept;
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
/** @file IPrintable_DString.hpp
|
||||
*
|
||||
* 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_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DString.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Printable.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DString.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DString; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DString>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DString,
|
||||
xo::scm::IPrintable_DString>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IPrintable_DString
|
||||
**/
|
||||
class IPrintable_DString {
|
||||
public:
|
||||
/** @defgroup scm-printable-dstring-type-traits **/
|
||||
///@{
|
||||
using ppindentinfo = xo::print::APrintable::ppindentinfo;
|
||||
using Copaque = xo::print::APrintable::Copaque;
|
||||
using Opaque = xo::print::APrintable::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-printable-dstring-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** Pretty-printing support for this object.
|
||||
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
|
||||
static bool pretty(const DString & self, const ppindentinfo & ppii);
|
||||
|
||||
// non-const methods
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
/** @file IGCObject_DUniqueString.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IGCObject_DUniqueString.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IGCObject_DUniqueString.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "GCObject.hpp"
|
||||
#include <xo/alloc2/GCObject.hpp>
|
||||
#include <xo/alloc2/Allocator.hpp>
|
||||
#include "DUniqueString.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IGCObject_DUniqueString; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::mm::AGCObject,
|
||||
xo::scm::DUniqueString>
|
||||
{
|
||||
using ImplType = xo::mm::IGCObject_Xfer
|
||||
<xo::scm::DUniqueString,
|
||||
xo::scm::IGCObject_DUniqueString>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IGCObject_DUniqueString
|
||||
**/
|
||||
class IGCObject_DUniqueString {
|
||||
public:
|
||||
/** @defgroup scm-gcobject-duniquestring-type-traits **/
|
||||
///@{
|
||||
using size_type = xo::mm::AGCObject::size_type;
|
||||
using AAllocator = xo::mm::AGCObject::AAllocator;
|
||||
using AGCObjectVisitor = xo::mm::AGCObject::AGCObjectVisitor;
|
||||
using VisitReason = xo::mm::AGCObject::VisitReason;
|
||||
using Copaque = xo::mm::AGCObject::Copaque;
|
||||
using Opaque = xo::mm::AGCObject::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-gcobject-duniquestring-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
|
||||
// non-const methods
|
||||
/** move instance using object visitor.
|
||||
Arguably abusing the word 'visitor' here **/
|
||||
static Opaque gco_shallow_move(DUniqueString & self, obj<AGCObjectVisitor> gc) noexcept;
|
||||
/** Invoke fn.visit_child(iface,data) for each child GCObject pointer.
|
||||
Context: provides address of data pointer so it can be updated in place
|
||||
when @p fn invokes garbage collector reentry point **/
|
||||
static void visit_gco_children(DUniqueString & self, VisitReason reason, obj<AGCObjectVisitor> fn) noexcept;
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
|
|
@ -1,62 +0,0 @@
|
|||
/** @file IPrintable_DUniqueString.hpp
|
||||
*
|
||||
* Generated automagically from ingredients:
|
||||
* 1. code generator:
|
||||
* [xo-facet/codegen/genfacet]
|
||||
* arguments:
|
||||
* --input [idl/IPrintable_DUniqueString.json5]
|
||||
* 2. jinja2 template for abstract facet .hpp file:
|
||||
* [iface_facet_repr.hpp.j2]
|
||||
* 3. idl for facet methods
|
||||
* [idl/IPrintable_DUniqueString.json5]
|
||||
**/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Printable.hpp"
|
||||
#include <xo/printable2/Printable.hpp>
|
||||
#include <xo/printable2/detail/IPrintable_Xfer.hpp>
|
||||
#include "DUniqueString.hpp"
|
||||
|
||||
namespace xo { namespace scm { class IPrintable_DUniqueString; } }
|
||||
|
||||
namespace xo {
|
||||
namespace facet {
|
||||
template <>
|
||||
struct FacetImplementation<xo::print::APrintable,
|
||||
xo::scm::DUniqueString>
|
||||
{
|
||||
using ImplType = xo::print::IPrintable_Xfer
|
||||
<xo::scm::DUniqueString,
|
||||
xo::scm::IPrintable_DUniqueString>;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
namespace xo {
|
||||
namespace scm {
|
||||
/** @class IPrintable_DUniqueString
|
||||
**/
|
||||
class IPrintable_DUniqueString {
|
||||
public:
|
||||
/** @defgroup scm-printable-duniquestring-type-traits **/
|
||||
///@{
|
||||
using ppindentinfo = xo::print::APrintable::ppindentinfo;
|
||||
using Copaque = xo::print::APrintable::Copaque;
|
||||
using Opaque = xo::print::APrintable::Opaque;
|
||||
///@}
|
||||
/** @defgroup scm-printable-duniquestring-methods **/
|
||||
///@{
|
||||
// const methods
|
||||
/** Pretty-printing support for this object.
|
||||
See [xo-indentlog/xo/indentlog/pretty.hpp] **/
|
||||
static bool pretty(const DUniqueString & self, const ppindentinfo & ppii);
|
||||
|
||||
// non-const methods
|
||||
///@}
|
||||
};
|
||||
|
||||
} /*namespace scm*/
|
||||
} /*namespace xo*/
|
||||
|
||||
/* end */
|
||||
Loading…
Add table
Add a link
Reference in a new issue