mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[ion] Change Storage design (former kallax)
This commit is contained in:
committed by
EmilieNumworks
parent
1f351ddbd6
commit
b0ede47d55
@@ -9,29 +9,30 @@ Script::Script(Record f) :
|
||||
|
||||
bool Script::importationStatus() const {
|
||||
assert(!isNull());
|
||||
const char * body = read();
|
||||
return (body[0] == 1);
|
||||
Data d = value();
|
||||
return (((char *)d.buffer)[0] == 1);
|
||||
}
|
||||
|
||||
void Script::toggleImportationStatus() {
|
||||
assert(bodySize() >= 1);
|
||||
m_body[0] = importationStatus() ? 0 : 1;
|
||||
Data d = value();
|
||||
((char *)d.buffer)[0] = (((char *)d.buffer)[0] == 1 ? 0 : 1);
|
||||
setValue(d);
|
||||
}
|
||||
|
||||
const char * Script::readContent() const {
|
||||
const char * body = read();
|
||||
return body+k_importationStatusSize;
|
||||
assert(!isNull());
|
||||
Data d = value();
|
||||
return (const char *)d.buffer+k_importationStatusSize;
|
||||
}
|
||||
|
||||
Script::ErrorStatus Script::writeContent(const char * data, size_t size) {
|
||||
int deltaSize = (int)size+k_importationStatusSize - (int)bodySize();
|
||||
if (Ion::Kallax::sharedKallax()->moveNextRecord(start(), deltaSize)) {
|
||||
*m_size += deltaSize;
|
||||
strlcpy(m_body+k_importationStatusSize, data, size);
|
||||
return ErrorStatus::None;
|
||||
} else {
|
||||
return ErrorStatus::NoEnoughSpaceAvailable;
|
||||
}
|
||||
Ion::Storage::Record::ErrorStatus Script::writeContent(const char * data, size_t size) {
|
||||
// TODO: could we avoid this useless allocation?
|
||||
char * buffer = new char[size+k_importationStatusSize];
|
||||
strlcpy(buffer+1, data, size);
|
||||
buffer[0] = importationStatus() ? 1 : 0;
|
||||
ErrorStatus e = setValue({.buffer= buffer, .size = size+k_importationStatusSize});
|
||||
delete[] buffer;
|
||||
return e;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user