From 82ea774621e0c9608deb2c3404a7a56cb8b09a2b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Thu, 22 Sep 2016 14:46:01 +0200 Subject: [PATCH] [apps/graph] implement add and remove functions in function store Change-Id: Iabbe9a83f575a81081999d65e6faedbc05476626 --- apps/graph/function_store.cpp | 23 ++++++++++++++++------- apps/graph/function_store.h | 8 ++++++++ apps/graph/graph_app.cpp | 16 ++++++++++++---- 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/apps/graph/function_store.cpp b/apps/graph/function_store.cpp index 5f33d0122..67f05b7b0 100644 --- a/apps/graph/function_store.cpp +++ b/apps/graph/function_store.cpp @@ -3,10 +3,8 @@ extern "C" { #include } -constexpr int numberOfDefaultColors = 3; -constexpr KDColor defaultColors[numberOfDefaultColors] = { - KDColorRed, KDColorGreen, KDColorBlue -}; +constexpr int Graph::FunctionStore::numberOfDefaultColors; +constexpr KDColor Graph::FunctionStore::defaultColors[numberOfDefaultColors]; Graph::FunctionStore::FunctionStore() : m_numberOfFunctions(0) @@ -18,10 +16,21 @@ Graph::Function * Graph::FunctionStore::functionAtIndex(int i) { return &m_functions[i]; } -void Graph::FunctionStore::pushFunction(const char * functionText) { +void Graph::FunctionStore::addFunction(Function * f) { assert(m_numberOfFunctions < k_maxNumberOfFunctions); - m_functions[m_numberOfFunctions] = Function(functionText, defaultColors[m_numberOfFunctions%numberOfDefaultColors]); - m_numberOfFunctions++; + m_functions[m_numberOfFunctions++] = (*f); +} + +void Graph::FunctionStore::removeFunction(Function * f) { + int i = 0; + while (&m_functions[i] != f && i < m_numberOfFunctions) { + i++; + } + assert(i>=0 && i