[apps/graph] implement add and remove functions in function store

Change-Id: Iabbe9a83f575a81081999d65e6faedbc05476626
This commit is contained in:
Émilie Feral
2016-09-22 14:46:01 +02:00
parent 98f1a2e998
commit 82ea774621
3 changed files with 36 additions and 11 deletions

View File

@@ -3,10 +3,8 @@ extern "C" {
#include <assert.h>
}
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<m_numberOfFunctions);
m_numberOfFunctions--;
for (int j = i; j<m_numberOfFunctions; j++) {
m_functions[j] = m_functions[j+1];
}
}
int Graph::FunctionStore::numberOfFunctions() {