[apps/sequence] Add model to the new application folder sequence/

Change-Id: I9880e85770d0895849f7f47c474a2a42b00eb3e1
This commit is contained in:
Émilie Feral
2017-02-06 17:18:34 +01:00
parent 3164939c9d
commit 44ce4fb069
7 changed files with 154 additions and 0 deletions

View File

@@ -3,6 +3,7 @@ include apps/graph/Makefile
include apps/home/Makefile
include apps/probability/Makefile
include apps/regression/Makefile
include apps/sequence/Makefile
include apps/settings/Makefile
include apps/shared/Makefile
include apps/statistics/Makefile

6
apps/sequence/Makefile Normal file
View File

@@ -0,0 +1,6 @@
app_objs += $(addprefix apps/sequence/,\
sequence.o\
sequence_store.o\
)
app_images += apps/sequence/sequence_icon.png

View File

@@ -0,0 +1,9 @@
#include "sequence.h"
namespace Sequence {
char Sequence::symbol() const {
return 'n';
}
}

17
apps/sequence/sequence.h Normal file
View File

@@ -0,0 +1,17 @@
#ifndef SEQUENCE_SEQUENCE_H
#define SEQUENCE_SEQUENCE_H
#include "../shared/function.h"
namespace Sequence {
class Sequence : public Shared::Function {
public:
using Shared::Function::Function;
private:
char symbol() const override;
};
}
#endif

Binary file not shown.

After

Width:  |  Height:  |  Size: 827 B

View File

@@ -0,0 +1,87 @@
#include "sequence_store.h"
extern "C" {
#include <assert.h>
#include <stddef.h>
}
#include <ion.h>
namespace Sequence {
constexpr KDColor SequenceStore::k_defaultColors[k_maxNumberOfSequences];
constexpr const char * SequenceStore::k_sequenceNames[k_maxNumberOfSequences];
uint32_t SequenceStore::storeChecksum() {
size_t dataLengthInBytes = m_numberOfFunctions*sizeof(Sequence);
assert((dataLengthInBytes & 0x3) == 0); // Assert that dataLengthInBytes is a multiple of 4
return Ion::crc32((uint32_t *)m_sequences, dataLengthInBytes>>2);
}
Sequence * SequenceStore::functionAtIndex(int i) {
assert(i>=0 && i<m_numberOfFunctions);
return &m_sequences[i];
}
Sequence * SequenceStore::activeFunctionAtIndex(int i) {
return (Sequence *)Shared::FunctionStore::activeFunctionAtIndex(i);
}
Sequence * SequenceStore::definedFunctionAtIndex(int i) {
return (Sequence *)Shared::FunctionStore::definedFunctionAtIndex(i);
}
Sequence * SequenceStore::addEmptyFunction() {
assert(m_numberOfFunctions < k_maxNumberOfSequences);
const char * name = firstAvailableName();
KDColor color = firstAvailableColor();
Sequence addedSequence = Sequence(name, color);
m_sequences[m_numberOfFunctions] = addedSequence;
Sequence * result = &m_sequences[m_numberOfFunctions];
m_numberOfFunctions++;
return result;
}
void SequenceStore::removeFunction(Shared::Function * f) {
int i = 0;
while (&m_sequences[i] != f && i < m_numberOfFunctions) {
i++;
}
assert(i>=0 && i<m_numberOfFunctions);
m_numberOfFunctions--;
for (int j = i; j<m_numberOfFunctions; j++) {
m_sequences[j] = m_sequences[j+1];
}
}
const char * SequenceStore::firstAvailableName() {
for (int k = 0; k < k_maxNumberOfSequences; k++) {
int j = 0;
while (j < m_numberOfFunctions) {
if (m_sequences[j].name() == k_sequenceNames[k]) {
break;
}
j++;
}
if (j == m_numberOfFunctions) {
return k_sequenceNames[k];
}
}
return k_sequenceNames[0];
}
const KDColor SequenceStore::firstAvailableColor() {
for (int k = 0; k < k_maxNumberOfSequences; k++) {
int j = 0;
while (j < m_numberOfFunctions) {
if (m_sequences[j].color() == k_defaultColors[k]) {
break;
}
j++;
}
if (j == m_numberOfFunctions) {
return k_defaultColors[k];
}
}
return k_defaultColors[0];
}
}

View File

@@ -0,0 +1,34 @@
#ifndef SEQUENCE_SEQUENCE_STORE_H
#define SEQUENCE_SEQUENCE_STORE_H
#include "sequence.h"
#include "../shared/function_store.h"
#include <stdint.h>
namespace Sequence {
class SequenceStore : public Shared::FunctionStore {
public:
using Shared::FunctionStore::FunctionStore;
uint32_t storeChecksum() override;
Sequence * functionAtIndex(int i) override;
Sequence * activeFunctionAtIndex(int i) override;
Sequence * definedFunctionAtIndex(int i) override;
Sequence * addEmptyFunction() override;
void removeFunction(Shared::Function * f) override;
static constexpr int k_maxNumberOfSequences = 3;
private:
const char * firstAvailableName() override;
const KDColor firstAvailableColor() override;
static constexpr KDColor k_defaultColors[k_maxNumberOfSequences] = {
KDColor::RGB24(0xbe2727), KDColor::RGB24(0x3e6f3c), KDColor::RGB24(0x656975)
};
static constexpr const char * k_sequenceNames[k_maxNumberOfSequences] = {
"u", "v", "w"
};
Sequence m_sequences[k_maxNumberOfSequences];
};
}
#endif