Blame view

epsilon-master/apps/graph/cartesian_function_store.cpp 1.51 KB
6663b6c9   adorian   projet complet av...
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
  #include "cartesian_function_store.h"
  extern "C" {
  #include <assert.h>
  #include <stddef.h>
  }
  #include <ion.h>
  
  namespace Graph {
  
  constexpr int CartesianFunctionStore::k_maxNumberOfFunctions;
  constexpr const char * CartesianFunctionStore::k_functionNames[k_maxNumberOfFunctions];
  
  CartesianFunctionStore::CartesianFunctionStore() :
    Shared::FunctionStore()
  {
    addEmptyModel();
  }
  
  uint32_t CartesianFunctionStore::storeChecksum() {
    size_t dataLengthInBytes = k_maxNumberOfFunctions*sizeof(uint32_t);
    assert((dataLengthInBytes & 0x3) == 0); // Assert that dataLengthInBytes is a multiple of 4
    uint32_t checksums[k_maxNumberOfFunctions];
    for (int i = 0; i < k_maxNumberOfFunctions; i++) {
      checksums[i] = m_functions[i].checksum();
    }
    return Ion::crc32((uint32_t *)checksums, dataLengthInBytes/sizeof(uint32_t));
  }
  
  
  char CartesianFunctionStore::symbol() const {
    return 'x';
  }
  
  void CartesianFunctionStore::removeAll() {
    FunctionStore::removeAll();
    addEmptyModel();
  }
  
  CartesianFunction * CartesianFunctionStore::emptyModel() {
    static CartesianFunction addedFunction("", KDColorBlack);
    addedFunction = CartesianFunction(firstAvailableName(), firstAvailableColor());
    return &addedFunction;
  }
  
  CartesianFunction * CartesianFunctionStore::nullModel() {
    static CartesianFunction emptyFunction("", KDColorBlack);
    return &emptyFunction;
  }
  
  void CartesianFunctionStore::setModelAtIndex(Shared::ExpressionModel * e, int i) {
    assert(i>=0 && i<m_numberOfModels);
    m_functions[i] = *(static_cast<CartesianFunction *>(e));
  }
  
  }