[ion] Namespace Record and Kallax

This commit is contained in:
Émilie Feral
2018-02-28 15:53:33 +01:00
committed by EmilieNumworks
parent aa984bca74
commit f9656fd94f
13 changed files with 50 additions and 23 deletions

View File

@@ -11,7 +11,7 @@ EditorController::EditorController(MenuController * menuController) :
ViewController(nullptr),
m_textArea(this),
m_areaBuffer(nullptr),
m_script(Record()),
m_script(Ion::Record()),
m_menuController(menuController)
{
m_textArea.setDelegate(this);
@@ -26,7 +26,7 @@ void EditorController::setScript(Script script) {
m_script = script;
const char * scriptBody = m_script.readContent();
size_t scriptBodySize = strlen(scriptBody)+1;
size_t availableScriptSize = scriptBodySize + Kallax::sharedKallax()->availableSize();
size_t availableScriptSize = scriptBodySize + Ion::Kallax::sharedKallax()->availableSize();
assert(m_areaBuffer == nullptr);
m_areaBuffer = new char[availableScriptSize];
strlcpy(m_areaBuffer, scriptBody, scriptBodySize);
@@ -36,8 +36,8 @@ void EditorController::setScript(Script script) {
// TODO: this should be done in textAreaDidFinishEditing maybe??
bool EditorController::handleEvent(Ion::Events::Event event) {
if (event == Ion::Events::OK || event == Ion::Events::Back) {
Record::ErrorStatus err = m_script.writeContent(m_areaBuffer, strlen(m_areaBuffer)+1);
if (err == Record::ErrorStatus::NoEnoughSpaceAvailable) {
Script::ErrorStatus err = m_script.writeContent(m_areaBuffer, strlen(m_areaBuffer)+1);
if (err == Script::ErrorStatus::NoEnoughSpaceAvailable) {
assert(false); // This should not happen as we set the text area according to the available space in the Kallax
} else {
stackController()->pop();

View File

@@ -302,8 +302,8 @@ bool MenuController::textFieldDidFinishEditing(TextField * textField, const char
} else {
newName = text;
}
Record::ErrorStatus error = m_scriptStore->scriptAtIndex(m_selectableTableView.selectedRow()).rename(newName);
if (error == Record::ErrorStatus::None) {
Script::ErrorStatus error = m_scriptStore->scriptAtIndex(m_selectableTableView.selectedRow()).rename(newName);
if (error == Script::ErrorStatus::None) {
updateAddScriptRowDisplay();
textField->setText(newName);
int currentRow = m_selectableTableView.selectedRow();
@@ -318,7 +318,7 @@ bool MenuController::textFieldDidFinishEditing(TextField * textField, const char
static_cast<AppsContainer *>(const_cast<Container *>(app()->container()))->setShiftAlphaStatus(Ion::Events::ShiftAlphaStatus::Default);
return true;
} else {
assert(error == Record::ErrorStatus::NameTaken);
assert(error == Script::ErrorStatus::NameTaken);
// The name cannot be to long as the text field size was set accordingly
// TODO:
@@ -337,8 +337,8 @@ bool MenuController::textFieldDidAbortEditing(TextField * textField, const char
// The previous text was an empty name. Use a numbered default script name.
char numberedDefaultName[k_defaultScriptNameMaxSize];
numberedDefaultScriptName(numberedDefaultName);
Record::ErrorStatus error = m_scriptStore->scriptAtIndex(m_selectableTableView.selectedRow()).rename(numberedDefaultName);
assert(error == Record::ErrorStatus::None);
Script::ErrorStatus error = m_scriptStore->scriptAtIndex(m_selectableTableView.selectedRow()).rename(numberedDefaultName);
assert(error == Script::ErrorStatus::None);
updateAddScriptRowDisplay();
m_selectableTableView.reloadData();
}

View File

@@ -23,9 +23,9 @@ const char * Script::readContent() const {
return body+k_importationStatusSize;
}
Record::ErrorStatus Script::writeContent(const char * data, size_t size) {
Script::ErrorStatus Script::writeContent(const char * data, size_t size) {
int deltaSize = (int)size+k_importationStatusSize - (int)bodySize();
if (Kallax::sharedKallax()->moveNextRecord(start(), deltaSize)) {
if (Ion::Kallax::sharedKallax()->moveNextRecord(start(), deltaSize)) {
*m_size += deltaSize;
strlcpy(m_body+k_importationStatusSize, data, size);
return ErrorStatus::None;

View File

@@ -8,10 +8,10 @@ namespace Code {
/* Record : | Total Size | Type | Name | Body |
* Script: | AutoImportationStatus | Content |*/
class Script : public Record {
class Script : public Ion::Record {
friend class ScriptStore;
public:
Script(Record f);
Script(Ion::Record f);
bool importationStatus() const;
void toggleImportationStatus();

View File

@@ -12,7 +12,7 @@ ScriptParameterController::ScriptParameterController(Responder * parentResponder
m_deleteScript(I18n::Message::DeleteScript),
m_selectableTableView(this, this, 0, 1, Metric::CommonTopMargin, Metric::CommonRightMargin,
Metric::CommonBottomMargin, Metric::CommonLeftMargin, this),
m_script(Record()),
m_script(Ion::Record()),
m_menuController(menuController)
{
}
@@ -22,7 +22,7 @@ void ScriptParameterController::setScript(Script script){
}
void ScriptParameterController::dismissScriptParameterController() {
m_script = Script(Record());
m_script = Script(Ion::Record());
stackViewController()->pop();
}

View File

@@ -20,17 +20,17 @@ ScriptStore::ScriptStore()
}
Script ScriptStore::scriptAtIndex(int index) {
Record f = Kallax::sharedKallax()->recordOfTypeAtIndex(Record::Type::Script, index);
Ion::Record f = Ion::Kallax::sharedKallax()->recordOfTypeAtIndex(Ion::Record::Type::Script, index);
return Script(f);
}
Script ScriptStore::scriptNamed(const char * name) {
Record f = Kallax::sharedKallax()->getRecord(Record::Type::Script, name);
Ion::Record f = Ion::Kallax::sharedKallax()->getRecord(Ion::Record::Type::Script, name);
return Script(f);
}
int ScriptStore::numberOfScripts() {
return Kallax::sharedKallax()->numberOfRecordOfType(Record::Type::Script);
return Ion::Kallax::sharedKallax()->numberOfRecordOfType(Ion::Record::Type::Script);
}
bool ScriptStore::addNewScript() {
@@ -44,7 +44,7 @@ void ScriptStore::deleteAllScripts() {
}
bool ScriptStore::isFull() {
return (numberOfScripts() >= k_maxNumberOfScripts || Kallax::sharedKallax()->availableSize() < k_fullFreeSpaceSizeLimit);
return (numberOfScripts() >= k_maxNumberOfScripts || Ion::Kallax::sharedKallax()->availableSize() < k_fullFreeSpaceSizeLimit);
}
void ScriptStore::scanScriptsForFunctionsAndVariables(void * context, ScanCallback storeFunction, ScanCallback storeVariable) {
@@ -143,8 +143,8 @@ bool ScriptStore::addScriptFromTemplate(const ScriptTemplate * scriptTemplate) {
body[0] = 1;
strlcpy(body+1, scriptTemplate->content(), scriptSize);
bool result = false;
if (Kallax::sharedKallax()->sizeOfRecordWithBody(body) <= Kallax::sharedKallax()->availableSize()) {
Kallax::sharedKallax()->addRecord(scriptTemplate->name(), Record::Type::Script, body);
if (Ion::Kallax::sharedKallax()->sizeOfRecordWithBody(body) <= Ion::Kallax::sharedKallax()->availableSize()) {
Ion::Kallax::sharedKallax()->addRecord(scriptTemplate->name(), Ion::Record::Type::Script, body);
result = true;
}
delete[] body;

View File

@@ -35,7 +35,7 @@ public:
private:
// If the kallax free space has a size smaller than
// k_fullFreeSpaceSizeLimit, we consider the script store as full.
static constexpr int k_fullFreeSpaceSizeLimit = Record::k_sizeSize+Record::k_nameSize+Record::k_typeSize+10;
static constexpr int k_fullFreeSpaceSizeLimit = Ion::Record::k_sizeSize+Ion::Record::k_nameSize+Ion::Record::k_typeSize+10;
static constexpr size_t k_fileInput2ParseNodeStructKind = 1;
static constexpr size_t k_functionDefinitionParseNodeStructKind = 3;
static constexpr size_t k_expressionStatementParseNodeStructKind = 5;