Numworks Epsilon  1.4.1
Graphing Calculator Operating System
cartesian_function_store.cpp
Go to the documentation of this file.
2 extern "C" {
3 #include <assert.h>
4 #include <stddef.h>
5 }
6 #include <ion.h>
7 
8 namespace Graph {
9 
11 constexpr KDColor CartesianFunctionStore::k_defaultColors[k_maxNumberOfFunctions];
12 constexpr const char * CartesianFunctionStore::k_functionNames[k_maxNumberOfFunctions];
13 
15  Shared::FunctionStore()
16 {
18 }
19 
21  size_t dataLengthInBytes = k_maxNumberOfFunctions*sizeof(uint32_t);
22  assert((dataLengthInBytes & 0x3) == 0); // Assert that dataLengthInBytes is a multiple of 4
24  for (int i = 0; i < k_maxNumberOfFunctions; i++) {
25  checksums[i] = m_functions[i].checksum();
26  }
27  return Ion::crc32((uint32_t *)checksums, dataLengthInBytes/sizeof(uint32_t));
28 }
29 
31  assert(i>=0 && i<m_numberOfFunctions);
32  return &m_functions[i];
33 }
34 
37 }
38 
41 }
42 
45  const char * name = firstAvailableName();
46  KDColor color = firstAvailableColor();
47  CartesianFunction addedFunction(name, color);
48  m_functions[m_numberOfFunctions] = addedFunction;
49  CartesianFunction * result = &m_functions[m_numberOfFunctions];
51  return result;
52 }
53 
55  int i = 0;
56  while (&m_functions[i] != f && i < m_numberOfFunctions) {
57  i++;
58  }
59  assert(i>=0 && i<m_numberOfFunctions);
61  for (int j = i; j<m_numberOfFunctions; j++) {
62  m_functions[j] = m_functions[j+1];
63  }
64  CartesianFunction emptyFunction("", KDColorBlack);
65  m_functions[m_numberOfFunctions] = emptyFunction;
66 }
67 
70 }
71 
73  return 'x';
74 }
75 
76 const char * CartesianFunctionStore::firstAvailableName() {
77  for (int k = 0; k < k_maxNumberOfFunctions; k++) {
78  int j = 0;
79  while (j < m_numberOfFunctions) {
80  if (m_functions[j].name() == k_functionNames[k]) {
81  break;
82  }
83  j++;
84  }
85  if (j == m_numberOfFunctions) {
86  return k_functionNames[k];
87  }
88  }
89  return k_functionNames[0];
90 }
91 
92 const KDColor CartesianFunctionStore::firstAvailableColor() {
93  for (int k = 0; k < k_maxNumberOfFunctions; k++) {
94  int j = 0;
95  while (j < m_numberOfFunctions) {
96  if (m_functions[j].color() == k_defaultColors[k]) {
97  break;
98  }
99  j++;
100  }
101  if (j == m_numberOfFunctions) {
102  return k_defaultColors[k];
103  }
104  }
105  return k_defaultColors[0];
106 }
107 
109  for (int i = 0; i < m_numberOfFunctions; i++) {
110  CartesianFunction emptyFunction("", KDColorBlack);
111  m_functions[i] = emptyFunction;
112  }
115 }
116 
117 }
#define assert(e)
Definition: assert.h:9
CartesianFunction * functionAtIndex(int i) override
Definition: app.cpp:9
virtual uint32_t checksum()
Definition: function.cpp:29
virtual Function * definedFunctionAtIndex(int i)
unsigned int uint32_t
Definition: stdint.h:6
CartesianFunction * addEmptyFunction() override
constexpr KDColor KDColorBlack
Definition: color.h:41
void removeFunction(Shared::Function *f) override
Definition: color.h:6
virtual Function * activeFunctionAtIndex(int i)
uint32_t crc32(const uint32_t *data, size_t length)
Definition: device.cpp:37
CartesianFunction * activeFunctionAtIndex(int i) override
static constexpr int k_maxNumberOfFunctions
CartesianFunction * definedFunctionAtIndex(int i) override