* Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
* Copyright (C) 2008-2008 - DIGITEO - Antoine ELIAS
*
-* This file must be used under the terms of the CeCILL.
-* This source file is licensed as described in the file COPYING, which
-* you should have received as part of this distribution. The terms
-* are also available at
-* http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
+ * Copyright (C) 2012 - 2016 - Scilab Enterprises
+ *
+ * This file is hereby licensed under the terms of the GNU GPL v2.0,
+ * pursuant to article 5.3.4 of the CeCILL v.2.1.
+ * This file was originally licensed under the terms of the CeCILL v2.1,
+ * and continues to be available under such terms.
+ * For more information, see the COPYING file which you should have received
+ * along with this program.
*
*/
#include <sstream>
+#include <algorithm>
#include "core_math.h"
#include "tostring_common.hxx"
#include "singlepoly.hxx"
#include "polynom.hxx"
#include "configvariable.hxx"
-using namespace std;
-
namespace types
{
Polynom::Polynom()
{
#ifndef NDEBUG
- //Inspector::addItem(this);
+ Inspector::addItem(this);
#endif
}
-Polynom::Polynom(wstring _szVarName, int _iRows, int _iCols)
+Polynom::Polynom(const std::wstring& _szVarName, int _iRows, int _iCols)
{
int piDims[2] = {_iRows, _iCols};
createPoly(_szVarName, 2, piDims, NULL);
}
-Polynom::Polynom(wstring _szVarName, int _iRows, int _iCols, const int *_piRank)
+Polynom::Polynom(const std::wstring& _szVarName, int _iRows, int _iCols, const int *_piRank)
{
int piDims[2] = {_iRows, _iCols};
createPoly(_szVarName, 2, piDims, _piRank);
}
-Polynom::Polynom(std::wstring _szVarName, int _iDims, int* _piDims)
+Polynom::Polynom(const std::wstring& _szVarName, int _iDims, const int* _piDims)
{
createPoly(_szVarName, _iDims, _piDims, NULL);
}
-Polynom::Polynom(std::wstring _szVarName, int _iDims, int* _piDims, const int *_piRank)
+Polynom::Polynom(const std::wstring& _szVarName, int _iDims, const int* _piDims, const int *_piRank)
{
createPoly(_szVarName, _iDims, _piDims, _piRank);
}
deleteAll();
}
#ifndef NDEBUG
- //Inspector::removeItem(this);
+ Inspector::removeItem(this);
#endif
}
-void Polynom::createPoly(std::wstring _szVarName, int _iDims, int* _piDims, const int *_piRank)
+bool Polynom::getMemory(long long* _piSize, long long* _piSizePlusType)
+{
+ *_piSize = 0;
+ for (int i = 0; i<getSize(); i++)
+ {
+ *_piSize += (get(i)->getRank()+1)*sizeof(double);
+ }
+
+ *_piSize = *_piSize * (isComplex() ? 2 : 1);
+ *_piSizePlusType = *_piSize + getSize()*sizeof(SinglePoly *) + sizeof(*this);
+ return true;
+}
+
+
+void Polynom::createPoly(const std::wstring& _szVarName, int _iDims, const int* _piDims, const int *_piRank)
{
m_szVarName = _szVarName;
SinglePoly** pPoly = NULL;
}
}
#ifndef NDEBUG
- //Inspector::addItem(this);
+ Inspector::addItem(this);
#endif
}
-bool Polynom::set(int _iPos, SinglePoly* _pS)
+Polynom* Polynom::set(int _iPos, SinglePoly* _pS)
{
- bool bComplex = isComplex();
if (m_pRealData == NULL || _iPos >= m_iSize)
{
- return false;
+ return NULL;
+ }
+
+ typedef Polynom* (Polynom::*set_t)(int, SinglePoly*);
+ Polynom* pIT = checkRef(this, (set_t)&Polynom::set, _iPos, _pS);
+ if (pIT != this)
+ {
+ return pIT;
}
if (m_pRealData[_iPos])
m_pRealData[_iPos] = copyValue(_pS);
+ bool bComplex = isComplex();
if (_pS->isComplex() && bComplex == false)
{
setComplex(true);
m_pRealData[_iPos]->setComplex(true);
}
- return true;
+ return this;
}
-bool Polynom::set(int _iRows, int _iCols, SinglePoly* _pS)
+Polynom* Polynom::set(int _iRows, int _iCols, SinglePoly* _pS)
{
return set(_iCols * getRows() + _iRows, _pS);
}
-bool Polynom::set(SinglePoly** _pS)
+Polynom* Polynom::set(SinglePoly** _pS)
{
+ typedef Polynom* (Polynom::*set_t)(SinglePoly**);
+ Polynom* pIT = checkRef(this, (set_t)&Polynom::set, _pS);
+ if (pIT != this)
+ {
+ return pIT;
+ }
+
for (int i = 0 ; i < m_iSize ; i++)
{
set(i, _pS[i]);
}
- return true;
+
+ return this;
}
-bool Polynom::setCoef(int _iRows, int _iCols, Double *_pdblCoef)
+Polynom* Polynom::setCoef(int _iRows, int _iCols, Double *_pdblCoef)
{
int piDims[] = {_iRows, _iCols};
int iPos = getIndex(piDims);
return setCoef(iPos, _pdblCoef);
}
-bool Polynom::setCoef(int _iIdx, Double *_pdblCoef)
+Polynom* Polynom::setCoef(int _iIdx, Double *_pdblCoef)
{
- if (_iIdx < getSize())
+ if (_iIdx > m_iSize)
{
- /*Get old SinglePoly*/
- m_pRealData[_iIdx]->setRank(_pdblCoef->getSize() - 1);
- m_pRealData[_iIdx]->setCoef(_pdblCoef);
+ return NULL;
}
- else
+
+ typedef Polynom* (Polynom::*setCoef_t)(int, Double*);
+ Polynom* pIT = checkRef(this, (setCoef_t)&Polynom::setCoef, _iIdx, _pdblCoef);
+ if (pIT != this)
{
- return false;
+ return pIT;
}
- return true;
+ /*Get old SinglePoly*/
+ m_pRealData[_iIdx]->setRank(_pdblCoef->getSize() - 1);
+ m_pRealData[_iIdx]->setCoef(_pdblCoef);
+
+ return this;
}
void Polynom::setZeros()
}
}
+bool Polynom::getSizes(int *_piSizes)
+{
+ if (_piSizes == NULL || m_pRealData == NULL)
+ {
+ return false;
+ }
+
+ for (int i = 0 ; i < getSize() ; i++)
+ {
+ _piSizes[i] = m_pRealData[i]->getSize();
+ }
+
+ return true;
+}
+
bool Polynom::getRank(int *_piRank)
{
if (_piRank == NULL || m_pRealData == NULL)
std::cout << "types::SinglePoly";
}
-wstring Polynom::getVariableName()
+std::wstring& Polynom::getVariableName()
{
return m_szVarName;
}
-void Polynom::setVariableName(wstring _szVarName)
+void Polynom::setVariableName(const std::wstring& _szVarName)
{
m_szVarName = _szVarName;
}
return false;
}
-void Polynom::setComplex(bool _bComplex)
+Polynom* Polynom::setComplex(bool _bComplex)
{
- if (_bComplex != isComplex())
+ if (_bComplex == isComplex())
{
- for (int i = 0 ; i < getSize() ; i++)
- {
- get(i)->setComplex(_bComplex);
- }
+ return this;
+ }
+
+ typedef Polynom* (Polynom::*setcplx_t)(bool);
+ Polynom* pIT = checkRef(this, (setcplx_t)&Polynom::setComplex, _bComplex);
+ if (pIT != this)
+ {
+ return pIT;
}
+
+ for (int i = 0 ; i < getSize() ; i++)
+ {
+ get(i)->setComplex(_bComplex);
+ }
+
+ return this;
}
-InternalType* Polynom::clone()
+Polynom* Polynom::clone()
{
Polynom* pMP = new Polynom(getVariableName(), getDims(), getDimsArray());
for (int i = 0 ; i < getSize() ; i++)
return pCoef;
}
-void Polynom::setCoef(Double *_pCoef)
+Polynom* Polynom::setCoef(Double *_pCoef)
{
+ typedef Polynom* (Polynom::*setCoef_t)(Double*);
+ Polynom* pIT = checkRef(this, (setCoef_t)&Polynom::setCoef, _pCoef);
+ if (pIT != this)
+ {
+ return pIT;
+ }
+
setComplex(_pCoef->isComplex());
double *pR = _pCoef->getReal();
}
}
}
+
+ return this;
}
bool Polynom::subMatrixToString(std::wostringstream& ostr, int* _piDims, int _iDims)
{
- wostringstream osExp;
- wostringstream osCoef;
+ std::wostringstream osExp;
+ std::wostringstream osPoly;
- list<wstring>::const_iterator it_Exp;
- list<wstring>::const_iterator it_Coef;
- list<wstring> listExpR, listCoefR, listExpI, listCoefI;
+ std::list<std::wstring>::const_iterator it_Exp;
+ std::list<std::wstring>::const_iterator it_Coef;
+ std::list<std::wstring> listExpR, listWstPoly, listExpI, listCoefI;
- if (isScalar())
- {
- if (isComplex())
- {
- ostr << L"Real part" << endl << endl << endl;
- get(0)->toStringReal(getVariableName(), &listExpR, &listCoefR);
- for (it_Coef = listCoefR.begin(), it_Exp = listExpR.begin() ; it_Coef != listCoefR.end() ; it_Coef++, it_Exp++)
- {
- ostr << *it_Exp << endl << *it_Coef << endl;
- }
-
- ostr << L"Imaginary part" << endl << endl << endl ;
- get(0)->toStringImg(getVariableName(), &listExpI, &listCoefI);
- for (it_Coef = listCoefI.begin(), it_Exp = listExpI.begin() ; it_Coef != listCoefI.end() ; it_Coef++, it_Exp++)
- {
- ostr << *it_Exp << endl << *it_Coef << endl;
- }
- }
- else
- {
- get(0)->toStringReal(getVariableName(), &listExpR, &listCoefR);
-
- for (it_Coef = listCoefR.begin(), it_Exp = listExpR.begin() ; it_Coef != listCoefR.end() ; it_Coef++, it_Exp++)
- {
- ostr << *it_Exp << endl << *it_Coef << endl;
- }
- }
- }
- else if (getRows() == 1)
+ //Matrix
+ if (isComplex())
{
- if (isComplex())
- {
- ostr << L"Real part" << endl << endl;
- ostr << getRowString(_piDims, _iDims, false);
- ostr << L"Imaginary part" << endl << endl;
- ostr << getRowString(_piDims, _iDims, true);
- }
- else
- {
- ostr << getRowString(_piDims, _iDims, false);
- }
- }
- else if (getCols() == 1)
- {
- if (isComplex())
- {
- ostr << L"Real part" << endl << endl;
- ostr << getColString(_piDims, _iDims, false);
- ostr << L"Imaginary part" << endl << endl;
- ostr << getColString(_piDims, _iDims, true);
- }
- else
- {
- ostr << getColString(_piDims, _iDims, false);
- }
+ ostr << L"Real part" << std::endl << std::endl;
+ ostr << getMatrixString(_piDims, _iDims, false);
+ ostr << L"Imaginary part" << std::endl << std::endl;
+ ostr << getMatrixString(_piDims, _iDims, true);
}
else
{
- //Matrix
- if (isComplex())
- {
- ostr << L"Real part" << endl << endl;
- ostr << getMatrixString(_piDims, _iDims, false);
- ostr << L"Imaginary part" << endl << endl;
- ostr << getMatrixString(_piDims, _iDims, true);
- }
- else
- {
- ostr << getMatrixString(_piDims, _iDims, false);
- }
+ ostr << getMatrixString(_piDims, _iDims, false);
}
return true;
}
-wstring Polynom::getMatrixString(int* _piDims, int /*_iDims*/, bool _bComplex)
+std::wstring Polynom::getMatrixString(int* _piDims, int /*_iDims*/, bool _bComplex)
{
int iLineLen = ConfigVariable::getConsoleWidth();
- wostringstream ostr;
- wostringstream osExp;
- wostringstream osCoef;
+ std::wostringstream ostr;
+ std::wostringstream osPoly;
- list<wstring>::const_iterator it_Exp;
- list<wstring>::const_iterator it_Coef;
- list<wstring> listExpR, listCoefR, listExpI, listCoefI;
+ std::list<std::wstring>::const_iterator it_Coef;
+ std::list<std::wstring> listWstPoly;
int iLen = 0;
int iLastCol = 0;
bool bWordWarp = false;
- wstring szExp, szCoef;
-
- int *piMaxLen = new int[getCols()];
- memset(piMaxLen, 0x00, sizeof(int) * getCols());
+ int *piMaxLen = new int[abs(getCols())];
+ memset(piMaxLen, 0x00, sizeof(int) * abs(getCols()));
//find the largest row for each col
- for (int iCols1 = 0 ; iCols1 < getCols() ; iCols1++)
+ for (int iCols1 = 0 ; iCols1 < abs(getCols()) ; iCols1++)
{
- for (int iRows1 = 0 ; iRows1 < getRows() ; iRows1++)
+ for (int iRows1 = 0 ; iRows1 < abs(getRows()) ; iRows1++)
{
- // FIXME : iLen shadow previous declaration
- int iLen = 0;
+ int iLength = 0;
_piDims[0] = iRows1;
_piDims[1] = iCols1;
int iPos = getIndex(_piDims);
if (_bComplex)
{
- get(iPos)->toStringImg(getVariableName(), &listExpR, &listCoefR);
+ get(iPos)->toStringImg(getVariableName(), &listWstPoly);
}
else
{
- get(iPos)->toStringReal(getVariableName(), &listExpR, &listCoefR);
+ get(iPos)->toStringReal(getVariableName(), &listWstPoly);
}
- if (listExpR.size() > 1)
- {
- for (it_Exp = listExpR.begin() ; it_Exp != listExpR.end() ; it_Exp++)
- {
- iLen += static_cast<int>((*it_Exp).size());
- }
- }
- else
+ for (auto it : listWstPoly)
{
- if (listExpR.front().size() != 0)
- {
- iLen = static_cast<int>(listExpR.front().size());
- }
- else
- {
- iLen = static_cast<int>(listCoefR.front().size());
- }
+ iLength += static_cast<int>(it.size());
}
- piMaxLen[iCols1] = std::min(std::max(piMaxLen[iCols1], iLen), iLineLen);
- listExpR.clear();
- listCoefR.clear();
+ piMaxLen[iCols1] = std::min(std::max(piMaxLen[iCols1], iLength), iLineLen);
+ listWstPoly.clear();
}
//We know the length of the column
-
if (static_cast<int>(iLen + piMaxLen[iCols1]) >= iLineLen && iLen != 0)
{
//if the max length exceeded
- wostringstream ostemp;
+ std::wostringstream ostemp;
bWordWarp = true;
- for (int iRows2 = 0 ; iRows2 < getRows() ; iRows2++)
+ for (int iRows2 = 0 ; iRows2 < abs(getRows()) ; iRows2++)
{
bool bMultiLine = false;
for (int iCols2 = iLastCol ; iCols2 < iCols1; iCols2++)
int iPos = getIndex(_piDims);
if (_bComplex)
{
- get(iPos)->toStringImg(getVariableName(), &listExpR, &listCoefR);
+ get(iPos)->toStringImg(getVariableName(), &listWstPoly);
}
else
{
- get(iPos)->toStringReal(getVariableName(), &listExpR, &listCoefR);
+ get(iPos)->toStringReal(getVariableName(), &listWstPoly);
}
- if (listCoefR.size() > 1)
+ if (listWstPoly.size() > 1)
{
- for (it_Coef = listCoefR.begin(), it_Exp = listExpR.begin() ; it_Coef != listCoefR.end() ; it_Coef++, it_Exp++)
+ for (auto it : listWstPoly)
{
- osExp << *it_Exp;
- addSpaces(&osExp, piMaxLen[iCols2] - static_cast<int>((*it_Exp).size()));
- osExp << endl;
-
- osExp << *it_Coef;
- addSpaces(&osExp, piMaxLen[iCols2] - static_cast<int>((*it_Coef).size()));
- osExp << endl;
+ osPoly << it << std::endl;
bMultiLine = true;
}
}
else
{
- osExp << listExpR.front();
- addSpaces(&osExp, piMaxLen[iCols2] - static_cast<int>(listExpR.front().size()));
- osCoef << listCoefR.front();
- addSpaces(&osCoef, piMaxLen[iCols2] - static_cast<int>(listCoefR.front().size()));
+ osPoly << listWstPoly.front();
+ addSpaces(&osPoly, piMaxLen[iCols2] - static_cast<int>(listWstPoly.front().size()));
bMultiLine = false;
}
- listExpR.clear();
- listCoefR.clear();
+ listWstPoly.clear();
}
if (bMultiLine == false)
{
- osExp << endl;
- osCoef << endl;
+ osPoly << std::endl;
}
- ostemp << osExp.str();
- ostemp << osCoef.str() << endl;
- osExp.str(L"");
- osCoef.str(L"");
+ ostemp << osPoly.str() << std::endl;
+ osPoly.str(L"");
}
- iLen = piMaxLen[iCols1];
+ iLen = piMaxLen[iCols1];
//write "column x to y"
- if (iLastCol + 1 == iCols1)
- {
- ostr << endl << L" Column " << iCols1 << endl << endl;
- }
- else
- {
- ostr << endl << L" Column " << iLastCol + 1 << L" to " << iCols1 << endl << endl;
- }
-
- ostr << ostemp.str() << endl;
+ addColumnString(ostr, iLastCol + 1, iCols1);
+ ostr << ostemp.str() << std::endl;
iLastCol = iCols1;
}
if (bWordWarp)
{
- if (iLastCol + 1 == getCols())
- {
- ostr << endl << L" Column " << getCols() << endl << endl;
- }
- else
- {
- ostr << endl << L" Column " << iLastCol + 1 << L" to " << getCols() << endl << endl;
- }
+ addColumnString(ostr, iLastCol + 1, getCols());
}
//print the end
- for (int iRows2 = 0 ; iRows2 < getRows() ; iRows2++)
+ for (int iRows2 = 0 ; iRows2 < abs(getRows()) ; iRows2++)
{
- for (int iCols2 = iLastCol ; iCols2 < getCols() ; iCols2++)
+ for (int iCols2 = iLastCol ; iCols2 < abs(getCols()) ; iCols2++)
{
_piDims[0] = iRows2;
_piDims[1] = iCols2;
int iPos = getIndex(_piDims);
if (_bComplex)
{
- get(iPos)->toStringImg( getVariableName(), &listExpR, &listCoefR);
+ get(iPos)->toStringImg(getVariableName(), &listWstPoly);
}
else
{
- get(iPos)->toStringReal(getVariableName(), &listExpR, &listCoefR);
+ get(iPos)->toStringReal(getVariableName(), &listWstPoly);
}
- if (listCoefR.size() > 1)
- {
- for (it_Coef = listCoefR.begin(), it_Exp = listExpR.begin() ; it_Coef != listCoefR.end() ; it_Coef++, it_Exp++)
- {
- //normally useless ...
- osExp << *it_Exp;
- addSpaces(&osExp, piMaxLen[iCols2] - static_cast<int>((*it_Exp).size()));
- osExp << endl;
-
- osExp << *it_Coef;
- addSpaces(&osExp, piMaxLen[iCols2] - static_cast<int>((*it_Coef).size()));
- osExp << endl;
- }
- }
- else
+ if (listWstPoly.size() > 1)
{
- if (listExpR.front().size() != 0)
+ for (auto it : listWstPoly)
{
- osExp << listExpR.front();
+ osPoly << it << std::endl;
}
-
- addSpaces(&osExp, piMaxLen[iCols2] - static_cast<int>(listExpR.front().size()));
- osCoef << listCoefR.front();
- addSpaces(&osCoef, piMaxLen[iCols2] - static_cast<int>(listCoefR.front().size()));
- }
- listExpR.clear();
- listCoefR.clear();
- }
-
- if (osExp.str().size() != 0)
- {
- osExp << endl;
- }
- osCoef << endl;
- ostr << osExp.str();
- ostr << osCoef.str() << endl;
- osExp.str(L"");
- osCoef.str(L"");
- }
- return ostr.str();
-}
-
-wstring Polynom::getRowString(int* _piDims, int /*_iDims*/, bool _bComplex)
-{
- int iLineLen = ConfigVariable::getConsoleWidth();
-
- int iLen = 0;
- int iLastFlush = 0;
-
- wostringstream ostr;
- wostringstream osExp;
- wostringstream osCoef;
-
- list<wstring>::const_iterator it_Exp;
- list<wstring>::const_iterator it_Coef;
- list<wstring> listExpR, listCoefR, listExpI, listCoefI;
-
- for (int i = 0 ; i < getCols() ; i++)
- {
- wstring szExp, szCoef;
-
- _piDims[1] = 0;
- _piDims[0] = i;
- int iPos = getIndex(_piDims);
- if (_bComplex)
- {
- get(iPos)->toStringImg(getVariableName(), &listExpR, &listCoefR);
- }
- else
- {
- get(iPos)->toStringReal(getVariableName(), &listExpR, &listCoefR);
- }
-
- if (iLen != 0 && static_cast<int>(listExpR.front().size()) + iLen >= iLineLen - 1)
- {
- //flush strean
- if (i == iLastFlush + 1)
- {
- ostr << endl << L" Column " << i << endl << endl;
}
else
{
- ostr << endl << L" Column " << iLastFlush + 1 /* 2 is better than 1, no ? */ << L" to " << i << endl << endl;
+ osPoly << listWstPoly.front();
+ addSpaces(&osPoly, piMaxLen[iCols2] - static_cast<int>(listWstPoly.front().size()));
}
-
- iLastFlush = i;
- iLen = 0;
- ostr << osExp.str() << endl;
- ostr << osCoef.str() << endl;
- osExp.str(L" ");
- osCoef.str(L" ");
+ listWstPoly.clear();
}
- if (listCoefR.size() > 1)
+ osPoly << std::endl;
+ if (isIdentity())
{
- for (it_Coef = listCoefR.begin(), it_Exp = listExpR.begin() ; it_Coef != listCoefR.end() ; it_Coef++, it_Exp++)
- {
- osExp << *it_Exp << endl << *it_Coef << endl;
- }
+ ostr << L"eye *" << std::endl << std::endl;
}
- else
- {
- osExp << listExpR.front();
- osCoef << listCoefR.front();
- }
-
- if (osExp.str().size() != 0)
- {
- iLen = static_cast<int>(osExp.str().size());
- }
- else
- {
- iLen = static_cast<int>(osCoef.str().size());
- }
-
- listCoefR.clear();
- listExpR.clear();
+ ostr << osPoly.str() << std::endl;
+ osPoly.str(L"");
}
- if (iLastFlush != 0)
- {
- //last line of a multiline output
- if (iLastFlush + 1 == getSize())
- {
- ostr << endl << L" Column " << getSize() << endl << endl;
- }
- else
- {
- ostr << endl << L" Column " << iLastFlush + 1 << L" to " << getSize() << endl << endl;
- }
- }
- ostr << osExp.str() << endl;
- ostr << osCoef.str() << endl;
+ delete[] piMaxLen;
return ostr.str();
}
-wstring Polynom::getColString(int* _piDims, int /*_iDims*/, bool _bComplex)
-{
- wostringstream ostr;
- wostringstream osExp;
- wostringstream osCoef;
-
- list<wstring>::const_iterator it_Exp;
- list<wstring>::const_iterator it_Coef;
- list<wstring> listExpR, listCoefR, listExpI, listCoefI;
-
- for (int i = 0 ; i < getRows() ; i++)
- {
- wstring szExp, szCoef;
-
- _piDims[0] = i;
- _piDims[1] = 0;
- int iPos = getIndex(_piDims);
- if (_bComplex)
- {
- get(iPos)->toStringImg(getVariableName(), &listExpR, &listCoefR);
- }
- else
- {
- get(iPos)->toStringReal(getVariableName(), &listExpR, &listCoefR);
- }
-
- for (it_Coef = listCoefR.begin(), it_Exp = listExpR.begin() ; it_Coef != listCoefR.end() ; it_Coef++, it_Exp++)
- {
- ostr << *it_Exp << endl << *it_Coef << endl;
- }
- ostr << endl;
- listCoefR.clear();
- listExpR.clear();
- }
- return ostr.str();
-}
Double* Polynom::extractCoef(int _iRank)
{
return pdbl;
}
+
bool Polynom::insertCoef(int _iRank, Double* _pCoef)
{
double *pReal = _pCoef->getReal();
return false;
}
- if (pM->isComplex() != isComplex())
- {
- return false;
- }
-
for (int i = 0 ; i < getSize() ; i++)
{
SinglePoly* p1 = get(i);
void Polynom::deleteAll()
{
- for (int i = 0 ; i < getSize() ; i++)
+ for (int i = 0 ; i < m_iSizeMax ; i++)
{
- delete m_pRealData[i];
+ m_pRealData[i]->killMe();
}
delete[] m_pRealData;
m_pRealData = NULL;
memset(pData, 0x00, _iSize * sizeof(SinglePoly*));
return pData;
}
+
+void Polynom::deleteData(SinglePoly* data)
+{
+ if (data)
+ {
+ data->killMe();
+ }
+}
+
+//overload to check variable name and call arrayof<>::insert after
+Polynom* Polynom::insert(typed_list* _pArgs, InternalType* _pSource)
+{
+ Polynom* p = _pSource->getAs<Polynom>();
+ if (p->getVariableName() != getVariableName())
+ {
+ char szError[512];
+ os_sprintf(szError, _("Input arguments should have the same formal variable name.\n"));
+ wchar_t* pwstError = to_wide_string(szError);
+ std::wstring wstError(pwstError);
+ FREE(pwstError);
+ throw ast::InternalError(wstError);
+ }
+
+ return ArrayOf<SinglePoly*>::insert(_pArgs, _pSource)->getAs<Polynom>();
+}
+
+Polynom* Polynom::Dollar()
+{
+ int iRank = 1;
+ Polynom* pDollar = new Polynom(L"$", 1, 1, &iRank);
+ double* pdblCoef = pDollar->get(0)->get();
+ pdblCoef[0] = 0;
+ pdblCoef[1] = 1;
+
+ return pDollar;
+}
+
+bool Polynom::isDollar()
+{
+ if (m_szVarName != L"$" || getSize() != 1)
+ {
+ return false;
+ }
+
+ double* pCoef = get(0)->get();
+
+ if (pCoef[0] != 0 && pCoef[1] != 1)
+ {
+ return false;
+ }
+
+ return true;
+}
+
}