Numworks Epsilon  1.4.1
Graphing Calculator Operating System
matrix_data.cpp
Go to the documentation of this file.
1 extern "C" {
2 #include <assert.h>
3 #include <stdlib.h>
4 }
5 #include <poincare/matrix_data.h>
6 #include <poincare/complex.h>
7 
8 namespace Poincare {
9 
10 MatrixData::MatrixData(ListData * listData, bool clone) :
11  m_numberOfRows(1),
12  m_numberOfColumns(0)
13 {
14  assert(listData != nullptr);
15  m_numberOfColumns = listData->numberOfOperands();
16  m_operands = new const Expression *[m_numberOfColumns];
17  for (int i = 0; i < m_numberOfColumns; i++) {
18  if (clone) {
19  m_operands[i] = listData->operand(i)->clone();
20  } else {
21  m_operands[i] = listData->operand(i);
22  }
23  }
24 }
25 
27  if (m_operands != nullptr) {
28  for (int i=0; i<m_numberOfRows*m_numberOfColumns; i++) {
29  delete m_operands[i];
30  }
31  delete[] m_operands;
32  }
33 }
34 
35 void MatrixData::pushListData(ListData * listData, bool clone) {
36  const Expression ** newOperands = new const Expression * [(m_numberOfRows+1)*m_numberOfColumns];
37  assert(listData->numberOfOperands() == m_numberOfColumns);
38  for (int i = 0; i < m_numberOfRows*m_numberOfColumns; i++) {
39  newOperands[i] = m_operands[i];
40  }
41  for (int i = 0; i < m_numberOfColumns; i++) {
42  if (clone) {
43  newOperands[m_numberOfRows*m_numberOfColumns+i] = listData->operand(i)->clone();
44  } else {
45  newOperands[m_numberOfRows*m_numberOfColumns+i] = listData->operand(i);
46  }
47  }
48  delete[] m_operands;
49  m_operands = newOperands;
50  m_numberOfRows++;
51 }
52 
54  return m_numberOfRows;
55 }
56 
58  return m_numberOfColumns;
59 }
60 
61 void MatrixData::pilferOperands(const Expression *** newStorage) {
62  *newStorage = m_operands;
63  m_operands = nullptr;
64 }
65 
66 }
#define assert(e)
Definition: assert.h:9
virtual Expression * clone() const =0
int numberOfOperands() const
Definition: list_data.cpp:37
void pushListData(ListData *listData, bool clone)
Definition: matrix_data.cpp:35
void pilferOperands(const Expression ***newStorageAddress)
Definition: matrix_data.cpp:61
const Expression * operand(int i) const
Definition: list_data.cpp:45
MatrixData(ListData *listData, bool clone)
Definition: matrix_data.cpp:10