From 8ec6673aee7fda0fad6d3ade4b65a326230edd19 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Wed, 10 Oct 2018 16:45:14 +0200 Subject: [PATCH] [shared] Fix storage_function_store without template --- apps/shared/storage_expression_model_store.h | 4 +- apps/shared/storage_function_store.cpp | 56 +++++++------------- apps/shared/storage_function_store.h | 30 ++++------- 3 files changed, 30 insertions(+), 60 deletions(-) diff --git a/apps/shared/storage_expression_model_store.h b/apps/shared/storage_expression_model_store.h index 9eeeaf6cd..26917681e 100644 --- a/apps/shared/storage_expression_model_store.h +++ b/apps/shared/storage_expression_model_store.h @@ -17,8 +17,8 @@ public: // Getters int numberOfModels() const; int numberOfDefinedModels() const; - StorageExpressionModel * modelAtIndex(int i) const; - StorageExpressionModel * definedModelAtIndex(int i) const; + virtual StorageExpressionModel * modelAtIndex(int i) const; + virtual StorageExpressionModel * definedModelAtIndex(int i) const; // Add and Remove virtual void removeAll(); diff --git a/apps/shared/storage_function_store.cpp b/apps/shared/storage_function_store.cpp index 94e3d234d..ace60daaa 100644 --- a/apps/shared/storage_function_store.cpp +++ b/apps/shared/storage_function_store.cpp @@ -4,59 +4,41 @@ namespace Shared { -template -int StorageFunctionStore::numberOfActiveFunctions() { +uint32_t StorageFunctionStore::storeChecksum() { + return Ion::Storage::sharedStorage()->checksum(); +} + +int StorageFunctionStore::numberOfActiveFunctions() const { int result = 0; - int modelsCount = StorageExpressionModelStore::numberOfModels(); - for (int i = 0; i < modelsCount; i++) { - T function = StorageExpressionModelStore::modelAtIndex(i); - if (function.isDefined() && function.isActive()) { + int i = 0; + StorageFunction * function = modelAtIndex(i++); + while (!function->isNull()) { + if (function->isDefined() && function->isActive()) { result++; } + function = modelAtIndex(i++); } return result; } -template -T StorageFunctionStore::activeFunctionAtIndex(int i) { - assert(i >= 0 && i < numberOfActiveFunctions()); + +StorageFunction * StorageFunctionStore::activeFunctionAtIndex(int i) { + assert(i >= 0 && i < numberOfDefinedModels()); int index = 0; - int modelsCount = StorageExpressionModelStore::numberOfModels(); - for (int k = 0; k < modelsCount; k++) { - T function = StorageExpressionModelStore::modelAtIndex(k); - if (function.isActive() && function.isDefined()) { + int currentModelIndex = 0; + StorageFunction * function = modelAtIndex(currentModelIndex++); + while (!function->isNull()) { + assert(currentModelIndex < numberOfModels()); + if (function->isActive() && function->isDefined()) { if (i == index) { return function; } index++; } + function = modelAtIndex(currentModelIndex++); } assert(false); return nullptr; } -template -template -U StorageFunctionStore::firstAvailableAttribute(U attributes[], AttributeGetter attribute) { - int modelsCount = StorageExpressionModelStore::numberOfModels(); - for (int k = 0; k < 4/*TODO*/; k++) { - int j = 0; - while (j < modelsCount) { - if (attribute(StorageExpressionModelStore::modelAtIndex(j)) == attributes[k]) { - break; - } - j++; - } - if (j == modelsCount) { - return attributes[k]; - } - } - return attributes[0]; } - -} - -//TODO specify templates -template class Shared::StorageFunctionStore; -/*template char const* const Shared::StorageFunctionStore::firstAvailableAttribute(char const* const*, char const* const (*)(Shared::StorageFunction)); -template KDColor const Shared::StorageFunctionStore::firstAvailableAttribute(KDColor const*, KDColor const (*)(Shared::StorageFunction));*/ diff --git a/apps/shared/storage_function_store.h b/apps/shared/storage_function_store.h index 8af81ce46..ea246d610 100644 --- a/apps/shared/storage_function_store.h +++ b/apps/shared/storage_function_store.h @@ -7,31 +7,19 @@ namespace Shared { -/* FunctionStore storse functions and gives them a color. The template should be - * a class derived from Shared::Function */ +/* FunctionStore storse functions and gives them a color. */ -template -class StorageFunctionStore : public StorageExpressionModelStore { +class StorageFunctionStore : public StorageExpressionModelStore { public: - StorageFunctionStore() : StorageExpressionModelStore() {} - uint32_t storeChecksum() { - return Ion::Storage::sharedStorage()->checksum(); - } - int numberOfActiveFunctions(); // An active function must be defined to be counted - virtual T activeFunctionAtIndex(int i); - T definedFunctionAtIndex(int i) { return static_cast(StorageExpressionModelStore::definedModelAtIndex(i)); } //TODO keep it? + StorageFunctionStore() : StorageExpressionModelStore() {} + uint32_t storeChecksum(); + // An active function must be defined to be counted + 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 char symbol() const = 0; -protected: - static const char * const name(T f) { return f.name(); } - static KDColor const color(T f) { return f.color(); } - template using AttributeGetter = U (*)(T f); - template U firstAvailableAttribute(U attributes[], AttributeGetter attribute); - const KDColor firstAvailableColor() { - return firstAvailableAttribute(Palette::DataColor, StorageFunctionStore::color); - } -private: - virtual const char * firstAvailableName() = 0; }; }