extern "C" { #include #include } #include #include namespace Poincare { MatrixData::MatrixData(ListData * listData, bool clone) : m_numberOfRows(1), m_numberOfColumns(0) { assert(listData != nullptr); m_numberOfColumns = listData->numberOfOperands(); m_operands = new Expression *[m_numberOfColumns]; for (int i = 0; i < m_numberOfColumns; i++) { if (clone) { m_operands[i] = (Expression *)listData->operand(i)->clone(); } else { m_operands[i] = (Expression *)listData->operand(i); } } } MatrixData::MatrixData(Expression ** newOperands, int numberOfOperands, int numberOfRows, int numberOfColumns, bool cloneOperands) : m_numberOfRows(numberOfRows), m_numberOfColumns(numberOfColumns) { assert(newOperands != nullptr); m_operands = new Expression *[m_numberOfRows*m_numberOfColumns]; for (int i = 0; i < m_numberOfRows*m_numberOfColumns; i++) { if (cloneOperands) { m_operands[i] = i < numberOfOperands ? newOperands[i]->clone() : defaultExpression(); } else { m_operands[i] = i < numberOfOperands ? newOperands[i] : defaultExpression(); } } } Complex * MatrixData::defaultExpression() { static Complex * defaultExpression = new Complex(Complex::Float(0.0)); return defaultExpression; } MatrixData::~MatrixData() { for (int i=0; inumberOfOperands(); if (clone) { newOperands[m_numberOfRows*m_numberOfColumns+i] = i < max ? (Expression *)listData->operand(i)->clone() : defaultExpression(); } else { newOperands[m_numberOfRows*m_numberOfColumns+i] = i < max ? (Expression *)listData->operand(i) : defaultExpression(); } } delete[] m_operands; m_operands = newOperands; m_numberOfRows++; } int MatrixData::numberOfRows() { return m_numberOfRows; } int MatrixData::numberOfColumns() { return m_numberOfColumns; } Expression ** MatrixData::operands() const { return m_operands; } }