WIP: Completed but un-tested port of Link.

Link is now mostly ported from Python but as of yet un-tested.
Refactored Interface.
Orgnanized example apps.
This commit is contained in:
Chad Attermann committed 2025-08-21 17:29:26 -06:00
1 parent a89a4bed86
commit 11155b5829
77 files changed
+4722 -1993

No files matched your search

+19 -19
View File
@@ -6,29 +6,29 @@ using namespace RNS;
// - If capacity is specified (>0) then create empty shared data with initial reserved capacity
// - If capacity is not specified (<=0) then create empty shared data with no initial capacity
void Bytes::newData(size_t capacity /*= 0*/) {
MEMF("Bytes is creating own data with capacity %u", capacity);
MEM("newData: Creating new data...");
//MEMF("Bytes is creating own data with capacity %u", capacity);
//MEM("newData: Creating new data...");
Data* data = new Data();
if (data == nullptr) {
ERROR("Bytes failed to allocate empty data buffer");
throw std::runtime_error("Failed to allocate empty data buffer");
}
MEM("newData: Created new data");
//MEM("newData: Created new data");
if (capacity > 0) {
MEM("newData: Reserving data capacity...");
//MEMF("newData: Reserving data capacity of %u...", capacity);
data->reserve(capacity);
MEM("newData: Reserved data capacity");
//MEM("newData: Reserved data capacity");
}
MEM("newData: Assigning data to shared data pointer...");
//MEM("newData: Assigning data to shared data pointer...");
_data = SharedData(data);
MEM("newData: Assigned data to shared data pointer");
//MEM("newData: Assigned data to shared data pointer");
_exclusive = true;
}
// Ensures that instance has exclusive shared data
// - If instance has no shared data then create new shared data
// - If instance does not have exclusive on shared data that is not empty then make a copy of shared data (if requests) and reserve capacity (if requested)
// - If instance does not have exclusive on shared data that is empty then then create new shared data
// - If instance does not have exclusive on shared data that is empty then create new shared data
// - If instance already has exclusive on shared data then do nothing except reserve capacity (if requested)
void Bytes::exclusiveData(bool copy /*= true*/, size_t capacity /*= 0*/) {
if (!_data) {
@@ -38,32 +38,32 @@ void Bytes::exclusiveData(bool copy /*= true*/, size_t capacity /*= 0*/) {
if (copy && !_data->empty()) {
//TRACE("Bytes is creating a writable copy of its shared data");
//Data* data = new Data(*_data.get());
MEM("exclusiveData: Creating new data...");
//MEM("exclusiveData: Creating new data...");
Data* data = new Data();
if (data == nullptr) {
ERROR("Bytes failed to duplicate data buffer");
throw std::runtime_error("Failed to duplicate data buffer");
}
MEM("exclusiveData: Created new data");
//MEM("exclusiveData: Created new data");
if (capacity > 0) {
MEM("exclusiveData: Reserving data capacity...");
//MEMF("exclusiveData: Reserving data capacity of %u...", capacity);
// if requested capacity < existing size then reserve capacity for existing size instead
data->reserve((capacity > _data->size()) ? capacity : _data->size());
MEM("exclusiveData: Reserved data capacity");
//MEM("exclusiveData: Reserved data capacity");
}
else {
data->reserve(_data->size());
}
MEM("exclusiveData: Copying existing data...");
//MEM("exclusiveData: Copying existing data...");
data->insert(data->begin(), _data->begin(), _data->end());
MEM("exclusiveData: Copied existing data");
MEM("exclusiveData: Assigning data to shared data pointer...");
//MEM("exclusiveData: Copied existing data");
//MEM("exclusiveData: Assigning data to shared data pointer...");
_data = SharedData(data);
MEM("exclusiveData: Assigned data to shared data pointer");
//MEM("exclusiveData: Assigned data to shared data pointer");
_exclusive = true;
}
else {
//MEM("Bytes is creating its own data because shared is empty");
//MEM("Bytes is creating its own data because shared is empty");
//data = new Data();
//if (data == nullptr) {
// ERROR("Bytes failed to allocate empty data buffer");
@@ -71,9 +71,9 @@ MEM("exclusiveData: Assigned data to shared data pointer");
//}
//_data = SharedData(data);
//_exclusive = true;
MEM("exclusiveData: Creating new empty data...");
//MEM("exclusiveData: Creating new empty data...");
newData(capacity);
MEM("exclusiveData: Created new empty data");
//MEM("exclusiveData: Created new empty data");
}
}
else if (capacity > 0 && capacity > size()) {