diff --git a/apps/shared/expression_model_store.cpp b/apps/shared/expression_model_store.cpp index 431a2c2a8..00289df4e 100644 --- a/apps/shared/expression_model_store.cpp +++ b/apps/shared/expression_model_store.cpp @@ -40,7 +40,7 @@ void ExpressionModelStore::tidy() { resetMemoizedModelsExceptRecord(); } -int ExpressionModelStore::numberOfModelsSatisfyingTest(ModelTest test) const { +int ExpressionModelStore::numberOfModelsSatisfyingTest(ModelTest test, void * context) const { int count = 0; int index = 0; Ion::Storage::Record record; @@ -49,15 +49,15 @@ int ExpressionModelStore::numberOfModelsSatisfyingTest(ModelTest test) const { if (record.isNull()) { break; } - if (test(privateModelForRecord(record))) { + if (test(privateModelForRecord(record), context)) { count++; } } while (true); return count; } -Ion::Storage::Record ExpressionModelStore::recordSatisfyingTestAtIndex(int i, ModelTest test) const { - assert(0 <= i && i < numberOfModelsSatisfyingTest(test)); +Ion::Storage::Record ExpressionModelStore::recordSatisfyingTestAtIndex(int i, ModelTest test, void * context) const { + assert(0 <= i && i < numberOfModelsSatisfyingTest(test, context)); int count = 0; int index = 0; Ion::Storage::Record record; @@ -67,7 +67,7 @@ Ion::Storage::Record ExpressionModelStore::recordSatisfyingTestAtIndex(int i, Mo assert(false); break; } - if (test(privateModelForRecord(record))) { + if (test(privateModelForRecord(record), context)) { if (i == count) { break; } diff --git a/apps/shared/expression_model_store.h b/apps/shared/expression_model_store.h index 8307136bc..c583b6996 100644 --- a/apps/shared/expression_model_store.h +++ b/apps/shared/expression_model_store.h @@ -19,9 +19,13 @@ public: // By default, the number of models is not bounded virtual int maxNumberOfModels() const { return -1; } int numberOfModels() const; - int numberOfDefinedModels() const { return numberOfModelsSatisfyingTest(&isModelDefined); } Ion::Storage::Record recordAtIndex(int i) const; - Ion::Storage::Record definedRecordAtIndex(int i) const { return recordSatisfyingTestAtIndex(i, &isModelDefined); } + int numberOfDefinedModels() const { + return numberOfModelsSatisfyingTest(&isModelDefined, nullptr); + } + Ion::Storage::Record definedRecordAtIndex(int i) const { + return recordSatisfyingTestAtIndex(i, &isModelDefined, nullptr); + } ExpiringPointer modelForRecord(Ion::Storage::Record record) const { return ExpiringPointer(privateModelForRecord(record)); } // Add and Remove @@ -35,10 +39,10 @@ public: protected: constexpr static int k_maxNumberOfMemoizedModels = 10; int maxNumberOfMemoizedModels() const { return maxNumberOfModels() < 0 ? k_maxNumberOfMemoizedModels : maxNumberOfModels(); } - typedef bool (*ModelTest)(ExpressionModelHandle * model); - int numberOfModelsSatisfyingTest(ModelTest test) const; - Ion::Storage::Record recordSatisfyingTestAtIndex(int i, ModelTest test) const; - static bool isModelDefined(ExpressionModelHandle * model) { + typedef bool (*ModelTest)(ExpressionModelHandle * model, void * context); + int numberOfModelsSatisfyingTest(ModelTest test, void * context) const; + Ion::Storage::Record recordSatisfyingTestAtIndex(int i, ModelTest test, void * context) const; + static bool isModelDefined(ExpressionModelHandle * model, void * context) { return model->isDefined(); } ExpressionModelHandle * privateModelForRecord(Ion::Storage::Record record) const; diff --git a/apps/shared/function_store.h b/apps/shared/function_store.h index f4f45266c..2790f6703 100644 --- a/apps/shared/function_store.h +++ b/apps/shared/function_store.h @@ -13,13 +13,17 @@ class FunctionStore : public ExpressionModelStore { public: FunctionStore() : ExpressionModelStore() {} uint32_t storeChecksum(); - int numberOfActiveFunctions() const { return numberOfModelsSatisfyingTest(&isFunctionActive); } - Ion::Storage::Record activeRecordAtIndex(int i) const { return recordSatisfyingTestAtIndex(i, &isFunctionActive); } + int numberOfActiveFunctions() const { + return numberOfModelsSatisfyingTest(&isFunctionActive, nullptr); + } + Ion::Storage::Record activeRecordAtIndex(int i) const { + return recordSatisfyingTestAtIndex(i, &isFunctionActive, nullptr); + } ExpiringPointer modelForRecord(Ion::Storage::Record record) const { return ExpiringPointer(static_cast(privateModelForRecord(record))); } protected: - static bool isFunctionActive(ExpressionModelHandle * model) { + static bool isFunctionActive(ExpressionModelHandle * model, void * context) { // An active function must be defined - return isModelDefined(model) && static_cast(model)->isActive(); + return isModelDefined(model, context) && static_cast(model)->isActive(); } };