Blame view

epsilon-master/poincare/src/layout/static_layout_hierarchy.cpp 1.93 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
  #include <poincare/static_layout_hierarchy.h>
  #include <poincare/expression_layout_array.h>
  extern "C" {
  #include <assert.h>
  }
  
  namespace Poincare {
  
  template<int T>
  StaticLayoutHierarchy<T>::StaticLayoutHierarchy() :
    ExpressionLayout(),
    m_children{}
  {
  }
  
  template<int T>
  StaticLayoutHierarchy<T>::StaticLayoutHierarchy(const ExpressionLayout * const * children, bool cloneChildren) :
    ExpressionLayout()
  {
    build(children, T, cloneChildren);
  }
  
  template<>
  StaticLayoutHierarchy<1>::StaticLayoutHierarchy(const ExpressionLayout * e, bool cloneChildren) :
    StaticLayoutHierarchy((ExpressionLayout **)&e, cloneChildren)
  {
  }
  
  template<>
  StaticLayoutHierarchy<2>::StaticLayoutHierarchy(const ExpressionLayout * e1, const ExpressionLayout * e2, bool cloneChildren) :
    StaticLayoutHierarchy(ExpressionLayoutArray(e1, e2).array(), cloneChildren)
  {
  }
  
  template<>
  StaticLayoutHierarchy<3>::StaticLayoutHierarchy(const ExpressionLayout * e1, const ExpressionLayout * e2, const ExpressionLayout * e3, bool cloneChildren) :
    StaticLayoutHierarchy(ExpressionLayoutArray(e1, e2, e3).array(), cloneChildren)
  {
  }
  
  template<int T>
  StaticLayoutHierarchy<T>::~StaticLayoutHierarchy() {
    for (int i = 0; i < T; i++) {
      if (m_children[i] != nullptr) {
        delete m_children[i];
      }
    }
  }
  
  template<int T>
  void StaticLayoutHierarchy<T>::build(const ExpressionLayout * const * operands, int numberOfOperands, bool cloneOperands) {
    assert(operands != nullptr);
    assert(numberOfOperands <= T);
    for (int i = 0; i < numberOfOperands; i++) {
      assert(operands[i] != nullptr);
      if (cloneOperands) {
        m_children[i] = operands[i]->clone();
      } else {
        m_children[i] = operands[i];
      }
      const_cast<ExpressionLayout *>(m_children[i])->setParent(this);
    }
  }
  
  template class Poincare::StaticLayoutHierarchy<0>;
  template class Poincare::StaticLayoutHierarchy<1>;
  template class Poincare::StaticLayoutHierarchy<2>;
  template class Poincare::StaticLayoutHierarchy<3>;
  
  }