Files
Upsilon/apps/graph/function_store.cpp
Émilie Feral ab74fe6933 [apps/graphs] Modify how functions are handled by the function store
Change-Id: I0d7a989526440a3b6d6a925b30d0d8742017e3f9
2016-09-26 14:51:10 +02:00

46 lines
1.2 KiB
C++

#include "function_store.h"
extern "C" {
#include <assert.h>
}
constexpr int Graph::FunctionStore::numberOfDefaultColors;
constexpr KDColor Graph::FunctionStore::defaultColors[numberOfDefaultColors];
Graph::FunctionStore::FunctionStore() :
m_numberOfFunctions(0)
{
}
Graph::Function * Graph::FunctionStore::functionAtIndex(int i) {
assert(i>=0 && i<m_numberOfFunctions);
return &m_functions[i];
}
Graph::Function * Graph::FunctionStore::addEmptyFunction() {
assert(m_numberOfFunctions < k_maxNumberOfFunctions);
Graph::Function addedFunction = Function();
addedFunction.setColor(defaultColors[numberOfFunctions()%numberOfDefaultColors]);
addedFunction.setName("f(x)");
addedFunction.setActive(true);
m_functions[m_numberOfFunctions] = addedFunction;
Function * result = &m_functions[m_numberOfFunctions];
m_numberOfFunctions++;
return result;
}
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() {
return m_numberOfFunctions;
}