mirror of
https://github.com/UpsilonNumworks/Upsilon.git
synced 2026-01-19 00:37:25 +01:00
[apps/shared/continuous_function_store] Factor numberOfActiveFunctionsOfType and activeRecordOfTypeAtIndex
This commit is contained in:
committed by
LeaNumworks
parent
56a3fcfacb
commit
d2b8e4865c
@@ -9,32 +9,6 @@ using namespace Shared;
|
||||
|
||||
namespace Graph {
|
||||
|
||||
int ContinuousFunctionStore::numberOfActiveFunctionsOfType(ContinuousFunction::PlotType plotType) const {
|
||||
int count = 0;
|
||||
for (int i = 0; i < numberOfActiveFunctions(); i++) {
|
||||
Ion::Storage::Record record = activeRecordAtIndex(i);
|
||||
ExpiringPointer<ContinuousFunction> function = modelForRecord(record);
|
||||
count += (plotType == function->plotType());
|
||||
}
|
||||
return count;
|
||||
}
|
||||
|
||||
Ion::Storage::Record ContinuousFunctionStore::activeRecordOfTypeAtIndex(ContinuousFunction::PlotType plotType, int index) const {
|
||||
int count = 0;
|
||||
Ion::Storage::Record record;
|
||||
for (int i = 0; i < numberOfActiveFunctions(); i++) {
|
||||
record = activeRecordAtIndex(i);
|
||||
ExpiringPointer<ContinuousFunction> function = modelForRecord(record);
|
||||
if (plotType == function->plotType()) {
|
||||
if (count == index) {
|
||||
break;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return record;
|
||||
}
|
||||
|
||||
Ion::Storage::Record::ErrorStatus ContinuousFunctionStore::addEmptyModel() {
|
||||
Ion::Storage::Record::ErrorStatus error;
|
||||
ContinuousFunction newModel = ContinuousFunction::NewModel(&error);
|
||||
|
||||
@@ -8,14 +8,22 @@ namespace Graph {
|
||||
|
||||
class ContinuousFunctionStore : public Shared::FunctionStore {
|
||||
public:
|
||||
int numberOfActiveFunctionsOfType(Shared::ContinuousFunction::PlotType plotType) const {
|
||||
return numberOfModelsSatisfyingTest(&isFunctionActiveOfType, &plotType);
|
||||
}
|
||||
Ion::Storage::Record activeRecordOfTypeAtIndex(Shared::ContinuousFunction::PlotType plotType, int i) const {
|
||||
return recordSatisfyingTestAtIndex(i, &isFunctionActiveOfType, &plotType);
|
||||
}
|
||||
Shared::ExpiringPointer<Shared::ContinuousFunction> modelForRecord(Ion::Storage::Record record) const { return Shared::ExpiringPointer<Shared::ContinuousFunction>(static_cast<Shared::ContinuousFunction *>(privateModelForRecord(record))); }
|
||||
int numberOfActiveFunctionsOfType(Shared::ContinuousFunction::PlotType plotType) const;
|
||||
Ion::Storage::Record activeRecordOfTypeAtIndex(Shared::ContinuousFunction::PlotType plotType, int index) const;
|
||||
private:
|
||||
Ion::Storage::Record::ErrorStatus addEmptyModel() override;
|
||||
const char * modelExtension() const override { return Ion::Storage::funcExtension; }
|
||||
Shared::ExpressionModelHandle * setMemoizedModelAtIndex(int cacheIndex, Ion::Storage::Record record) const override;
|
||||
Shared::ExpressionModelHandle * memoizedModelAtIndex(int cacheIndex) const override;
|
||||
static bool isFunctionActiveOfType(Shared::ExpressionModelHandle * model, void * context) {
|
||||
Shared::ContinuousFunction::PlotType plotType = *static_cast<Shared::ContinuousFunction::PlotType *>(context);
|
||||
return isFunctionActive(model, context) && plotType == static_cast<Shared::ContinuousFunction *>(model)->plotType();
|
||||
}
|
||||
mutable Shared::ContinuousFunction m_functions[k_maxNumberOfMemoizedModels];
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user