From 4220131160f8713e78ff58fe0a7bff1fb16984ce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Mon, 19 Dec 2016 15:36:40 +0100 Subject: [PATCH] [apps/statistics] Create a model data Change-Id: Iad946d1a1bc27aaea985f73d87163e8368206d40 --- apps/statistics/Makefile | 1 + apps/statistics/data.cpp | 38 ++++++++++++++++++++++++++++++++++++++ apps/statistics/data.h | 26 ++++++++++++++++++++++++++ 3 files changed, 65 insertions(+) create mode 100644 apps/statistics/data.cpp create mode 100644 apps/statistics/data.h diff --git a/apps/statistics/Makefile b/apps/statistics/Makefile index 7518d7d97..35ed9e716 100644 --- a/apps/statistics/Makefile +++ b/apps/statistics/Makefile @@ -2,6 +2,7 @@ app_objs += $(addprefix apps/statistics/,\ app.o\ box_controller.o\ calculation_controller.o\ + data.o\ data_controller.o\ histogram_controller.o\ ) diff --git a/apps/statistics/data.cpp b/apps/statistics/data.cpp new file mode 100644 index 000000000..38820b5c6 --- /dev/null +++ b/apps/statistics/data.cpp @@ -0,0 +1,38 @@ +#include "data.h" + +namespace Statistics { + +Data::Data() : + m_numberOfPairs(0) +{ +} + +int Data::numberOfPairs() const { + return m_numberOfPairs; +} + +float Data::valueAtIndex(int index) { + return m_values[index]; +} + +int Data::sizeAtIndex(int index) { + return m_sizes[index]; +} + +void Data::setValueAtIndex(float value, int index) { + m_values[index] = value; + if (index >= m_numberOfPairs) { + m_sizes[index] = 0; + m_numberOfPairs++; + } +} + +void Data::setSizeAtIndex(int size, int index) { + m_sizes[index] = size; + if (index >= m_numberOfPairs) { + m_values[index] = 0.0f; + m_numberOfPairs++; + } +} + +} diff --git a/apps/statistics/data.h b/apps/statistics/data.h new file mode 100644 index 000000000..668729ab7 --- /dev/null +++ b/apps/statistics/data.h @@ -0,0 +1,26 @@ +#ifndef STATISTICS_DATA_H +#define STATISTICS_DATA_H + +namespace Statistics { + +class Data { +public: + Data(); + // Delete the implicit copy constructor: the object is heavy + Data(const Data&) = delete; + int numberOfPairs() const; + float valueAtIndex(int index); + int sizeAtIndex(int index); + void setValueAtIndex(float value, int index); + void setSizeAtIndex(int size, int index); + // TODO: decide the max number of elements after optimization + constexpr static int k_maxNumberOfPairs = 500; +private: + int m_sizes[k_maxNumberOfPairs]; + float m_values[k_maxNumberOfPairs]; + int m_numberOfPairs; +}; + +} + +#endif