From 3164939c9ddb47c9e3b4fcb8ca34304b0cd1a74e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 6 Feb 2017 16:07:51 +0100 Subject: [PATCH] [apps/shared] Move function store class to shared/ to be used by sequence Change-Id: I89380d59e3450e9c5af4bf05f520ed1a5205ba29 --- apps/graph/function_store.cpp | 57 ++++------------------------- apps/graph/function_store.h | 28 ++++++--------- apps/shared/Makefile | 1 + apps/shared/function_store.cpp | 65 ++++++++++++++++++++++++++++++++++ apps/shared/function_store.h | 35 ++++++++++++++++++ 5 files changed, 118 insertions(+), 68 deletions(-) create mode 100644 apps/shared/function_store.cpp create mode 100644 apps/shared/function_store.h diff --git a/apps/graph/function_store.cpp b/apps/graph/function_store.cpp index 0592f211e..89036fe1a 100644 --- a/apps/graph/function_store.cpp +++ b/apps/graph/function_store.cpp @@ -1,8 +1,8 @@ #include "function_store.h" extern "C" { #include -} #include +} #include namespace Graph { @@ -12,7 +12,7 @@ constexpr KDColor FunctionStore::k_defaultColors[k_numberOfDefaultColors]; constexpr const char * FunctionStore::k_functionNames[k_maxNumberOfFunctions]; FunctionStore::FunctionStore() : - m_numberOfFunctions(0) + Shared::FunctionStore() { addEmptyFunction(); } @@ -29,35 +29,14 @@ Function * FunctionStore::functionAtIndex(int i) { } Function * FunctionStore::activeFunctionAtIndex(int i) { - assert(i>=0 && i=0 && i namespace Graph { -/* FunctionStore is a dumb class. - * Its only job is to store functions and to give them a color. */ -class FunctionStore { + +class FunctionStore : public Shared::FunctionStore { public: FunctionStore(); - uint32_t storeChecksum(); - Function * functionAtIndex(int i); - Function * activeFunctionAtIndex(int i); - Function * definedFunctionAtIndex(int i); - Function * addEmptyFunction(); - void removeFunction(Function * f); - int numberOfFunctions(); - // Functions can be undefined when they have a color and a name but no content - int numberOfDefinedFunctions(); - // An active function must be defined to be counted - int numberOfActiveFunctions(); + uint32_t storeChecksum() override; + Function * functionAtIndex(int i) override; + Function * activeFunctionAtIndex(int i) override; + Function * definedFunctionAtIndex(int i) override; + Function * addEmptyFunction() override; + void removeFunction(Shared::Function * f) override; static constexpr int k_maxNumberOfFunctions = 8; private: - const char * firstAvailableName(); - const KDColor firstAvailableColor(); + const char * firstAvailableName() override; + const KDColor firstAvailableColor() override; static constexpr int k_numberOfDefaultColors = 8; static constexpr KDColor k_defaultColors[k_numberOfDefaultColors] = { KDColor::RGB24(0xbe2727), KDColor::RGB24(0x3e6f3c), KDColor::RGB24(0x656975), KDColor::RGB24(0x9ec580), @@ -33,7 +28,6 @@ private: static constexpr const char * k_functionNames[k_maxNumberOfFunctions] = { "f", "g", "h", "p", "q", "r", "s", "t" }; - int m_numberOfFunctions; Function m_functions[k_maxNumberOfFunctions]; }; diff --git a/apps/shared/Makefile b/apps/shared/Makefile index eabcd4112..663670928 100644 --- a/apps/shared/Makefile +++ b/apps/shared/Makefile @@ -9,6 +9,7 @@ app_objs += $(addprefix apps/shared/,\ float_pair_store.o\ float_parameter_controller.o\ function.o\ + function_store.o\ interactive_curve_view_controller.o\ interactive_curve_view_range.o\ memoized_curve_view_range.o\ diff --git a/apps/shared/function_store.cpp b/apps/shared/function_store.cpp new file mode 100644 index 000000000..2663af258 --- /dev/null +++ b/apps/shared/function_store.cpp @@ -0,0 +1,65 @@ +#include "function_store.h" +#include + +namespace Shared { + +FunctionStore::FunctionStore() : + m_numberOfFunctions(0) +{ +} + +Function * FunctionStore::activeFunctionAtIndex(int i) { + assert(i>=0 && iisActive() && functionAtIndex(k)->layout() != nullptr) { + if (i == index) { + return functionAtIndex(k); + } + index++; + } + } + assert(false); + return nullptr; +} + +Function * FunctionStore::definedFunctionAtIndex(int i) { + assert(i>=0 && ilayout() != nullptr) { + if (i == index) { + return functionAtIndex(k); + } + index++; + } + } + assert(false); + return nullptr; +} + +int FunctionStore::numberOfFunctions() { + return m_numberOfFunctions; +} + +int FunctionStore::numberOfActiveFunctions() { + int result = 0; + for (int i = 0; i < m_numberOfFunctions; i++) { + if (functionAtIndex(i)->layout() != nullptr && functionAtIndex(i)->isActive()) { + result++; + } + } + return result; +} + +int FunctionStore::numberOfDefinedFunctions() { + int result = 0; + for (int i = 0; i < m_numberOfFunctions; i++) { + if (functionAtIndex(i)->layout() != nullptr) { + result++; + } + } + return result; +} + +} diff --git a/apps/shared/function_store.h b/apps/shared/function_store.h new file mode 100644 index 000000000..5e4f4adf2 --- /dev/null +++ b/apps/shared/function_store.h @@ -0,0 +1,35 @@ +#ifndef SHARED_FUNCTION_STORE_H +#define SHARED_FUNCTION_STORE_H + +#include "function.h" +#include + +namespace Shared { + +/* FunctionStore is a dumb class. + * Its only job is to store functions and to give them a color. */ + +class FunctionStore { +public: + FunctionStore(); + virtual uint32_t storeChecksum() = 0; + virtual Function * functionAtIndex(int i) = 0; + virtual Function * activeFunctionAtIndex(int i); + virtual Function * definedFunctionAtIndex(int i); + virtual Function * addEmptyFunction() = 0; + virtual void removeFunction(Function * f) = 0; + int numberOfFunctions(); + // Functions can be undefined when they have a color and a name but no content + int numberOfDefinedFunctions(); + // An active function must be defined to be counted + int numberOfActiveFunctions(); +protected: + int m_numberOfFunctions; +private: + virtual const char * firstAvailableName() = 0; + virtual const KDColor firstAvailableColor() = 0; +}; + +} + +#endif