mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[ion] Move Storage extensions declaration in Storage class
This commit is contained in:
@@ -64,11 +64,11 @@ bool StorageListController::textFieldDidFinishEditing(TextField * textField, con
|
||||
}
|
||||
|
||||
// Delete any variable with the same name
|
||||
GlobalContext::DestroyRecordsBaseNamedWithoutExtension(baseName, GlobalContext::funcExtension /*TODO store elsewhere?*/);
|
||||
GlobalContext::DestroyRecordsBaseNamedWithoutExtension(baseName, Ion::Storage::funcExtension);
|
||||
|
||||
// Set the name
|
||||
StorageFunction::NameNotCompliantError nameError = StorageFunction::NameNotCompliantError::None;
|
||||
Ion::Storage::Record::ErrorStatus error = StorageFunction::BaseNameCompliant(baseName, &nameError) ? modelStore()->recordAtIndex(m_selectableTableView.selectedRow()).setBaseNameWithExtension(baseName, GlobalContext::funcExtension /*TODO store elsewhere?*/) : Ion::Storage::Record::ErrorStatus::NonCompliantName;
|
||||
Ion::Storage::Record::ErrorStatus error = StorageFunction::BaseNameCompliant(baseName, &nameError) ? modelStore()->recordAtIndex(m_selectableTableView.selectedRow()).setBaseNameWithExtension(baseName, Ion::Storage::funcExtension) : Ion::Storage::Record::ErrorStatus::NonCompliantName;
|
||||
|
||||
// Handle any error
|
||||
if (error == Ion::Storage::Record::ErrorStatus::None) {
|
||||
|
||||
@@ -15,7 +15,7 @@ public:
|
||||
char unknownSymbol() const override { return Poincare::Symbol::SpecialSymbols::UnknownX; }
|
||||
private:
|
||||
Ion::Storage::Record::ErrorStatus addEmptyModel() override;
|
||||
const char * modelExtension() const override { return Shared::GlobalContext::funcExtension; }
|
||||
const char * modelExtension() const override { return Ion::Storage::funcExtension; }
|
||||
void setMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record record) const override;
|
||||
Shared::SingleExpressionModelHandle * memoizedModelAtIndex(int cacheIndex) const override;
|
||||
mutable Shared::StorageCartesianFunction m_functions[k_maxNumberOfMemoizedModels];
|
||||
|
||||
@@ -14,7 +14,7 @@ const char * SequenceStore::firstAvailableName(int * nameIndex) {
|
||||
int currentNameIndex = 0;
|
||||
while (currentNameIndex < MaxNumberOfSequences) {
|
||||
const char * name = k_sequenceNames[currentNameIndex];
|
||||
if (Ion::Storage::sharedStorage()->recordBaseNamedWithExtension(name, Shared::GlobalContext::seqExtension).isNull()) {
|
||||
if (Ion::Storage::sharedStorage()->recordBaseNamedWithExtension(name, Ion::Storage::seqExtension).isNull()) {
|
||||
if (nameIndex) {
|
||||
*nameIndex = currentNameIndex;
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ public:
|
||||
};
|
||||
|
||||
private:
|
||||
const char * modelExtension() const override { return Shared::GlobalContext::seqExtension; }
|
||||
const char * modelExtension() const override { return Ion::Storage::seqExtension; }
|
||||
/* We don't really use model memoization as the number of Sequence is limited
|
||||
* and we keep enough Sequences to store them all. */
|
||||
void setMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record record) const override;
|
||||
|
||||
@@ -10,9 +10,6 @@ using namespace Poincare;
|
||||
|
||||
namespace Shared {
|
||||
|
||||
constexpr char GlobalContext::expExtension[];
|
||||
constexpr char GlobalContext::funcExtension[];
|
||||
constexpr char GlobalContext::seqExtension[];
|
||||
constexpr const char * GlobalContext::k_extensions[];
|
||||
|
||||
bool GlobalContext::SymbolAbstractNameIsFree(const char * baseName) {
|
||||
@@ -23,10 +20,10 @@ Poincare::Expression GlobalContext::ExpressionFromRecord(Ion::Storage::Record re
|
||||
if (record.isNull() || record.value().size == 0) {
|
||||
return Expression();
|
||||
}
|
||||
if (Ion::Storage::FullNameHasExtension(record.fullName(), expExtension, strlen(expExtension))) {
|
||||
if (Ion::Storage::FullNameHasExtension(record.fullName(), Ion::Storage::expExtension, strlen(Ion::Storage::expExtension))) {
|
||||
return ExpressionFromSymbolRecord(record);
|
||||
}
|
||||
assert(Ion::Storage::FullNameHasExtension(record.fullName(), funcExtension, strlen(funcExtension)));
|
||||
assert(Ion::Storage::FullNameHasExtension(record.fullName(), Ion::Storage::funcExtension, strlen(Ion::Storage::funcExtension)));
|
||||
return ExpressionFromFunctionRecord(record);
|
||||
}
|
||||
|
||||
@@ -34,7 +31,7 @@ Poincare::Expression GlobalContext::ExpressionFromSymbolRecord(Ion::Storage::Rec
|
||||
if (record.isNull() || record.value().size == 0) {
|
||||
return Expression();
|
||||
}
|
||||
assert(Ion::Storage::FullNameHasExtension(record.fullName(), expExtension, strlen(expExtension)));
|
||||
assert(Ion::Storage::FullNameHasExtension(record.fullName(), Ion::Storage::expExtension, strlen(Ion::Storage::expExtension)));
|
||||
// An expression record value is the expression itself
|
||||
Ion::Storage::Record::Data d = record.value();
|
||||
return Expression::ExpressionFromAddress(d.buffer, d.size);
|
||||
@@ -43,7 +40,7 @@ Poincare::Expression GlobalContext::ExpressionFromFunctionRecord(Ion::Storage::R
|
||||
if (record.isNull() || record.value().size == 0) {
|
||||
return Expression();
|
||||
}
|
||||
if (!Ion::Storage::FullNameHasExtension(record.fullName(), funcExtension, strlen(funcExtension))) {
|
||||
if (!Ion::Storage::FullNameHasExtension(record.fullName(), Ion::Storage::funcExtension, strlen(Ion::Storage::funcExtension))) {
|
||||
return Expression();
|
||||
}
|
||||
/* An function record value has metadata before the expression. To get the
|
||||
@@ -94,7 +91,7 @@ const Expression GlobalContext::ExpressionForSymbolAndRecord(const SymbolAbstrac
|
||||
|
||||
const Expression GlobalContext::ExpressionForActualSymbol(const SymbolAbstract & symbol, Ion::Storage::Record r) {
|
||||
assert(symbol.type() == ExpressionNode::Type::Symbol);
|
||||
if (r.isNull() || !Ion::Storage::FullNameHasExtension(r.fullName(), expExtension, strlen(expExtension))) {
|
||||
if (r.isNull() || !Ion::Storage::FullNameHasExtension(r.fullName(), Ion::Storage::expExtension, strlen(Ion::Storage::expExtension))) {
|
||||
return Expression();
|
||||
}
|
||||
// Look up the file system for symbol
|
||||
@@ -102,7 +99,7 @@ const Expression GlobalContext::ExpressionForActualSymbol(const SymbolAbstract &
|
||||
}
|
||||
|
||||
Ion::Storage::Record::ErrorStatus GlobalContext::SetExpressionForActualSymbol(const Expression & expression, const SymbolAbstract & symbol, Ion::Storage::Record previousRecord) {
|
||||
if (!previousRecord.isNull() && Ion::Storage::FullNameHasExtension(previousRecord.fullName(), funcExtension, strlen(funcExtension))) {
|
||||
if (!previousRecord.isNull() && Ion::Storage::FullNameHasExtension(previousRecord.fullName(), Ion::Storage::funcExtension, strlen(Ion::Storage::funcExtension))) {
|
||||
/* A function can overwrite a variable, but a variable cannot be created if
|
||||
* it has the same name as an existing function. */
|
||||
// TODO Pop up "Name taken for a function"
|
||||
@@ -110,13 +107,13 @@ Ion::Storage::Record::ErrorStatus GlobalContext::SetExpressionForActualSymbol(co
|
||||
}
|
||||
// Delete any record with same name (as it is going to be overriden)
|
||||
previousRecord.destroy();
|
||||
return Ion::Storage::sharedStorage()->createRecordWithExtension(symbol.name(), expExtension, expression.addressInPool(), expression.size());
|
||||
return Ion::Storage::sharedStorage()->createRecordWithExtension(symbol.name(), Ion::Storage::expExtension, expression.addressInPool(), expression.size());
|
||||
}
|
||||
|
||||
Ion::Storage::Record::ErrorStatus GlobalContext::SetExpressionForFunctionRecord(Expression expressionToStore, Ion::Storage::Record previousRecord, const char * baseName) {
|
||||
Ion::Storage::Record recordToSet = previousRecord;
|
||||
Ion::Storage::Record::ErrorStatus error = Ion::Storage::Record::ErrorStatus::None;
|
||||
if (!Ion::Storage::FullNameHasExtension(previousRecord.fullName(), funcExtension, strlen(funcExtension))) {
|
||||
if (!Ion::Storage::FullNameHasExtension(previousRecord.fullName(), Ion::Storage::funcExtension, strlen(Ion::Storage::funcExtension))) {
|
||||
// The previous record was not a function. Destroy it and create the new record.
|
||||
previousRecord.destroy();
|
||||
StorageCartesianFunction newModel = StorageCartesianFunction::NewModel(&error, baseName);
|
||||
@@ -134,8 +131,7 @@ Ion::Storage::Record::ErrorStatus GlobalContext::SetExpressionForFunction(const
|
||||
}
|
||||
|
||||
Ion::Storage::Record GlobalContext::SymbolAbstractRecordWithBaseName(const char * name) {
|
||||
const char * extensions[2] = {expExtension, funcExtension/*, seqExtension*/};
|
||||
return Ion::Storage::sharedStorage()->recordBaseNamedWithExtensions(name, extensions, 2);
|
||||
return Ion::Storage::sharedStorage()->recordBaseNamedWithExtensions(name, k_extensions, k_numberOfExtensions);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -14,10 +14,7 @@ namespace Shared {
|
||||
class GlobalContext final : public Poincare::Context {
|
||||
public:
|
||||
static constexpr int k_numberOfExtensions = 2;
|
||||
static constexpr char expExtension[] = "exp"; // TODO: store this elsewhere?
|
||||
static constexpr char funcExtension[] = "func"; // TODO: store this elsewhere?
|
||||
static constexpr const char * k_extensions[] = {expExtension, funcExtension};
|
||||
static constexpr char seqExtension[] = "seq";
|
||||
static constexpr const char * k_extensions[] = {Ion::Storage::expExtension, Ion::Storage::funcExtension};
|
||||
|
||||
// Storage information
|
||||
static bool SymbolAbstractNameIsFree(const char * baseName);
|
||||
|
||||
@@ -53,7 +53,7 @@ StorageCartesianFunction StorageCartesianFunction::NewModel(Ion::Storage::Record
|
||||
DefaultName(nameBuffer, SymbolAbstract::k_maxNameSize);
|
||||
baseName = nameBuffer;
|
||||
}
|
||||
*error = Ion::Storage::sharedStorage()->createRecordWithExtension(baseName, GlobalContext::funcExtension, &data, sizeof(data));
|
||||
*error = Ion::Storage::sharedStorage()->createRecordWithExtension(baseName, Ion::Storage::funcExtension, &data, sizeof(data));
|
||||
|
||||
// Return if error
|
||||
if (*error != Ion::Storage::Record::ErrorStatus::None) {
|
||||
@@ -61,7 +61,7 @@ StorageCartesianFunction StorageCartesianFunction::NewModel(Ion::Storage::Record
|
||||
}
|
||||
|
||||
// Return the StorageCartesianFunction withthe new record
|
||||
return StorageCartesianFunction(Ion::Storage::sharedStorage()->recordBaseNamedWithExtension(baseName, GlobalContext::funcExtension));
|
||||
return StorageCartesianFunction(Ion::Storage::sharedStorage()->recordBaseNamedWithExtension(baseName, Ion::Storage::funcExtension));
|
||||
}
|
||||
|
||||
int StorageCartesianFunction::derivativeNameWithArgument(char * buffer, size_t bufferSize, char arg) {
|
||||
|
||||
@@ -12,8 +12,6 @@ using namespace Shared;
|
||||
|
||||
namespace Solver {
|
||||
|
||||
constexpr char Equation::extension[];
|
||||
|
||||
Equation::Equation(Ion::Storage::Record record) :
|
||||
SingleExpressionModelHandle(record)
|
||||
{
|
||||
|
||||
@@ -14,7 +14,6 @@ public:
|
||||
Poincare::Expression standardForm(Poincare::Context * context) const { return m_handle.standardForm(this, context); }
|
||||
bool containsIComplex(Poincare::Context * context) const;
|
||||
|
||||
static constexpr char extension[] = "eq"; // TODO: store this elsewhere?
|
||||
private:
|
||||
class Handle : public Shared::ExpressionModelHandle {
|
||||
public:
|
||||
|
||||
@@ -35,13 +35,13 @@ Ion::Storage::Record::ErrorStatus EquationStore::addEmptyModel() {
|
||||
int currentNumber = 0;
|
||||
while (currentNumber < k_maxNumberOfEquations) {
|
||||
name[1] = '0'+currentNumber;
|
||||
if (Ion::Storage::sharedStorage()->recordBaseNamedWithExtension(name, Equation::extension).isNull()) {
|
||||
if (Ion::Storage::sharedStorage()->recordBaseNamedWithExtension(name, Ion::Storage::eqExtension).isNull()) {
|
||||
break;
|
||||
}
|
||||
currentNumber++;
|
||||
}
|
||||
assert(currentNumber < k_maxNumberOfEquations);
|
||||
return Ion::Storage::sharedStorage()->createRecordWithExtension(name, Equation::extension, nullptr, 0);
|
||||
return Ion::Storage::sharedStorage()->createRecordWithExtension(name, Ion::Storage::eqExtension, nullptr, 0);
|
||||
}
|
||||
|
||||
void EquationStore::setMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record record) const {
|
||||
|
||||
@@ -78,7 +78,7 @@ private:
|
||||
static constexpr int k_maxNumberOfEquations = Poincare::Expression::k_maxNumberOfVariables; // Enable the same number of equations as the number of unknown variables
|
||||
|
||||
// StorageExpressionModelStore
|
||||
const char * modelExtension() const override { return Equation::extension; }
|
||||
const char * modelExtension() const override { return Ion::Storage::eqExtension; }
|
||||
/* We don't really use model memoization as the number of Equation is limited
|
||||
* and we keep enough Equations to store them all. */
|
||||
void setMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record record) const override;
|
||||
|
||||
@@ -77,9 +77,9 @@ int VariableBoxController::numberOfRows() {
|
||||
case Page::RootMenu:
|
||||
return k_numberOfMenuRows;
|
||||
case Page::Expression:
|
||||
return Storage::sharedStorage()->numberOfRecordsWithExtension(GlobalContext::expExtension);
|
||||
return Storage::sharedStorage()->numberOfRecordsWithExtension(Ion::Storage::expExtension);
|
||||
case Page::Function:
|
||||
return Storage::sharedStorage()->numberOfRecordsWithExtension(GlobalContext::funcExtension);
|
||||
return Storage::sharedStorage()->numberOfRecordsWithExtension(Ion::Storage::funcExtension);
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
@@ -243,7 +243,7 @@ Layout VariableBoxController::expressionLayoutForRecord(Storage::Record record,
|
||||
|
||||
const char * VariableBoxController::extension() const {
|
||||
assert(m_currentPage != Page::RootMenu);
|
||||
return m_currentPage == Page::Function ? GlobalContext::funcExtension : GlobalContext::expExtension;
|
||||
return m_currentPage == Page::Function ? Ion::Storage::funcExtension : Ion::Storage::expExtension;
|
||||
}
|
||||
|
||||
Storage::Record VariableBoxController::recordAtIndex(int rowIndex) {
|
||||
|
||||
@@ -20,6 +20,11 @@ public:
|
||||
static Storage * sharedStorage();
|
||||
constexpr static char k_dotChar = '.';
|
||||
|
||||
static constexpr char eqExtension[] = "eq";
|
||||
static constexpr char expExtension[] = "exp";
|
||||
static constexpr char funcExtension[] = "func";
|
||||
static constexpr char seqExtension[] = "seq";
|
||||
|
||||
class Record {
|
||||
/* A Record is identified by the CRC32 on its fullName because:
|
||||
* - A record is identified by its fullName, which is unique
|
||||
@@ -103,7 +108,7 @@ public:
|
||||
Record recordWithExtensionAtIndex(const char * extension, int index);
|
||||
Record recordNamed(const char * fullName);
|
||||
Record recordBaseNamedWithExtension(const char * baseName, const char * extension);
|
||||
Record recordBaseNamedWithExtensions(const char * baseName, const char * extension[], size_t numberOfExtensions);
|
||||
Record recordBaseNamedWithExtensions(const char * baseName, const char * const extension[], size_t numberOfExtensions);
|
||||
|
||||
// Record destruction
|
||||
void destroyAllRecords();
|
||||
|
||||
@@ -22,6 +22,11 @@ namespace Ion {
|
||||
|
||||
uint32_t staticStorageArea[sizeof(Storage)/sizeof(uint32_t)] = {0};
|
||||
|
||||
constexpr char Storage::expExtension[];
|
||||
constexpr char Storage::funcExtension[];
|
||||
constexpr char Storage::seqExtension[];
|
||||
constexpr char Storage::eqExtension[];
|
||||
|
||||
Storage * Storage::sharedStorage() {
|
||||
static Storage * storage = nullptr;
|
||||
if (storage == nullptr) {
|
||||
@@ -220,7 +225,7 @@ Storage::Record Storage::recordBaseNamedWithExtension(const char * baseName, con
|
||||
return recordBaseNamedWithExtensions(baseName, extensions, 1);
|
||||
}
|
||||
|
||||
Storage::Record Storage::recordBaseNamedWithExtensions(const char * baseName, const char * extensions[], size_t numberOfExtensions) {
|
||||
Storage::Record Storage::recordBaseNamedWithExtensions(const char * baseName, const char * const extensions[], size_t numberOfExtensions) {
|
||||
size_t nameLength = strlen(baseName);
|
||||
for (char * p : *this) {
|
||||
const char * currentName = fullNameOfRecordStarting(p);
|
||||
|
||||
Reference in New Issue
Block a user