diff --git a/apps/graph/storage_cartesian_function_store.cpp b/apps/graph/storage_cartesian_function_store.cpp index c9aeee27e..3f5b734e0 100644 --- a/apps/graph/storage_cartesian_function_store.cpp +++ b/apps/graph/storage_cartesian_function_store.cpp @@ -5,22 +5,14 @@ extern "C" { } #include +using namespace Shared; + namespace Graph { -//constexpr const char * StorageCartesianFunctionStore::k_functionNames[k_maxNumberOfFunctions]; - -Shared::StorageCartesianFunction StorageCartesianFunctionStore::NullModel() { - return Shared::StorageCartesianFunction(""); -} - StorageCartesianFunctionStore::StorageCartesianFunctionStore() : - Shared::StorageFunctionStore() + Shared::StorageFunctionStore() { - //addEmptyModel(); -} - -char StorageCartesianFunctionStore::symbol() const { - return 'x'; + addEmptyModel(); } void StorageCartesianFunctionStore::removeAll() { @@ -28,5 +20,26 @@ void StorageCartesianFunctionStore::removeAll() { addEmptyModel(); } +void StorageCartesianFunctionStore::addEmptyModel() { + Ion::Storage::Record::ErrorStatus error; + StorageCartesianFunction newModel = StorageCartesianFunction::NewModel(&error); + assert(error == Ion::Storage::Record::ErrorStatus::None); +} + +void StorageCartesianFunctionStore::privateSetMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record record) const { + assert(cacheIndex >= 0 && cacheIndex < k_maxNumberOfMemoizedModels); + m_functions[cacheIndex] = StorageCartesianFunction(record); +} + +void StorageCartesianFunctionStore::moveMemoizedModel(int previousIndex, int nextIndex) const { + assert(nextIndex >= 0 && nextIndex < k_maxNumberOfMemoizedModels); + assert(previousIndex >= 0 && previousIndex < k_maxNumberOfMemoizedModels); + m_functions[nextIndex] = m_functions[previousIndex]; +} + +StorageExpressionModel * StorageCartesianFunctionStore::memoizedModelAtIndex(int cacheIndex) const { + assert(cacheIndex >= 0 && cacheIndex < k_maxNumberOfMemoizedModels); + return &m_functions[cacheIndex]; +} } diff --git a/apps/graph/storage_cartesian_function_store.h b/apps/graph/storage_cartesian_function_store.h index 9ee82bb3d..02ca4ae9f 100644 --- a/apps/graph/storage_cartesian_function_store.h +++ b/apps/graph/storage_cartesian_function_store.h @@ -8,26 +8,21 @@ namespace Graph { -class StorageCartesianFunctionStore : public Shared::StorageFunctionStore { +class StorageCartesianFunctionStore : public Shared::StorageFunctionStore { public: - static Shared::StorageCartesianFunction NullModel(); - StorageCartesianFunctionStore(); -/* StorageCartesianFunction activeCartesianFunctionAtIndex(int i) override { return (CartesianFunction *)Shared::FunctionStore::activeFunctionAtIndex(i); } - StorageCartesianFunction definedFunctionAtIndex(int i) override { return (CartesianFunction *)Shared::FunctionStore::definedFunctionAtIndex(i); } -*/ - char symbol() const override; + Shared::StorageCartesianFunction * modelAtIndex(int i) const override { return static_cast(Shared::StorageFunctionStore::modelAtIndex(i)); } + Shared::StorageCartesianFunction * activeFunctionAtIndex(int i) const override { return static_cast(Shared::StorageFunctionStore::activeFunctionAtIndex(i)); } + Shared::StorageCartesianFunction * definedModelAtIndex(int i) const override { return static_cast(Shared::StorageFunctionStore::definedModelAtIndex(i)); } + char symbol() const override { return 'x'; } void removeAll() override; - static constexpr int k_maxNumberOfFunctions = 4; //TODO private: -/* static constexpr const char * k_functionNames[k_maxNumberOfFunctions] = { - "f", "g", "h", "p" //TODO - }; - - const char * firstAvailableName() override { - return firstAvailableAttribute(k_functionNames, FunctionStore::name); - }*/ - const char * firstAvailableName() override { return "f"; } + void addEmptyModel(); + const char * modelExtension() const override { return Shared::GlobalContext::funcExtension; } + void privateSetMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record record) const override; + void moveMemoizedModel(int previousIndex, int nextIndex) const override; + Shared::StorageExpressionModel * memoizedModelAtIndex(int cacheIndex) const override; + mutable Shared::StorageCartesianFunction m_functions[k_maxNumberOfMemoizedModels]; }; } diff --git a/apps/shared/storage_expression_model_store.h b/apps/shared/storage_expression_model_store.h index 26917681e..db157c663 100644 --- a/apps/shared/storage_expression_model_store.h +++ b/apps/shared/storage_expression_model_store.h @@ -26,10 +26,11 @@ public: // Other void tidy(); +protected: + constexpr static int k_maxNumberOfMemoizedModels = 5; private: virtual const char * modelExtension() const = 0; // Memoization of k_maxNumberOfMemoizedModels consecutive models - constexpr static int k_maxNumberOfMemoizedModels = 5; mutable int m_firstMemoizedModelIndex; mutable uint32_t m_memoizedModelChecksum[k_maxNumberOfMemoizedModels]; void setMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record) const; diff --git a/apps/shared/storage_function_store.h b/apps/shared/storage_function_store.h index ea246d610..7a733a7f1 100644 --- a/apps/shared/storage_function_store.h +++ b/apps/shared/storage_function_store.h @@ -17,7 +17,7 @@ public: int numberOfActiveFunctions() const; virtual StorageFunction * modelAtIndex(int i) const override { return static_cast(StorageExpressionModelStore::modelAtIndex(i)); } virtual StorageFunction * definedModelAtIndex(int i) const override { return static_cast(StorageExpressionModelStore::definedModelAtIndex(i)); } - virtual StorageFunction * activeFunctionAtIndex(int i); + virtual StorageFunction * activeFunctionAtIndex(int i) const; virtual char symbol() const = 0; };