From 35ee4679654be45d91c5474aa907584fbbdd2521 Mon Sep 17 00:00:00 2001 From: Ruben Dashyan Date: Thu, 22 Aug 2019 16:38:29 +0200 Subject: [PATCH] [apps/graph/cartesian_function_store] Define activeRecordOfTypeAtIndex --- apps/graph/cartesian_function_store.cpp | 26 +++++++++++++++++++++++++ apps/graph/cartesian_function_store.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/apps/graph/cartesian_function_store.cpp b/apps/graph/cartesian_function_store.cpp index 98af7af7c..06d20aab6 100644 --- a/apps/graph/cartesian_function_store.cpp +++ b/apps/graph/cartesian_function_store.cpp @@ -9,6 +9,32 @@ using namespace Shared; namespace Graph { +int CartesianFunctionStore::numberOfActiveFunctionsOfType(CartesianFunction::PlotType plotType) const { + int count = 0; + for (int i = 0; i < numberOfActiveFunctions(); i++) { + Ion::Storage::Record record = activeRecordAtIndex(i); + ExpiringPointer function = modelForRecord(record); + count += (plotType == function->plotType()); + } + return count; +} + +Ion::Storage::Record CartesianFunctionStore::activeRecordOfTypeAtIndex(CartesianFunction::PlotType plotType, int index) const { + int count = 0; + Ion::Storage::Record record; + for (int i = 0; i < numberOfActiveFunctions(); i++) { + record = activeRecordAtIndex(i); + ExpiringPointer function = modelForRecord(record); + if (plotType == function->plotType()) { + if (count == index) { + break; + } + count++; + } + } + return record; +} + Ion::Storage::Record::ErrorStatus CartesianFunctionStore::addEmptyModel() { Ion::Storage::Record::ErrorStatus error; CartesianFunction newModel = CartesianFunction::NewModel(&error); diff --git a/apps/graph/cartesian_function_store.h b/apps/graph/cartesian_function_store.h index 62c7e136f..94f4d9e61 100644 --- a/apps/graph/cartesian_function_store.h +++ b/apps/graph/cartesian_function_store.h @@ -11,6 +11,8 @@ namespace Graph { class CartesianFunctionStore : public Shared::FunctionStore { public: Shared::ExpiringPointer modelForRecord(Ion::Storage::Record record) const { return Shared::ExpiringPointer(static_cast(privateModelForRecord(record))); } + int numberOfActiveFunctionsOfType(Shared::CartesianFunction::PlotType plotType) const; + Ion::Storage::Record activeRecordOfTypeAtIndex(Shared::CartesianFunction::PlotType plotType, int index) const; private: Ion::Storage::Record::ErrorStatus addEmptyModel() override; const char * modelExtension() const override { return Ion::Storage::funcExtension; }