2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2010 - DIGITEO - Antoine ELIAS
5 * This file must be used under the terms of the CeCILL.
6 * This source file is licensed as described in the file COPYING, which
7 * you should have received as part of this distribution. The terms
8 * are also available at
9 * http://www.cecill.info/licences/Licence_CeCILL_V2-en.txt
13 #include "arrayof.hxx"
16 #include "singlepoly.hxx"
17 #include "singlestruct.hxx"
21 #include "dynlib_ast.h"
26 /* template <typename T>
27 ArrayOf<T>* createEmptyDouble()
29 return Double::Empty();
33 int computeTuples(int* _piCountDim, int _iDims, int _iCurrentDim, int* _piIndex)
35 //if bRet == 1, previous dims has reach max value.
38 if (_iCurrentDim == 0)
41 if (_piIndex[_iCurrentDim] >= _piCountDim[_iCurrentDim])
43 _piIndex[_iCurrentDim] = 0;
49 iRet = computeTuples(_piCountDim, _iDims, _iCurrentDim - 1, _piIndex);
52 _piIndex[_iCurrentDim]++;
53 if (_piIndex[_iCurrentDim] >= _piCountDim[_iCurrentDim])
55 _piIndex[_iCurrentDim] = 0;
63 InternalType* createEmptyDouble()
65 return Double::Empty();
68 int getIntValueFromDouble(InternalType* _pIT, int _iPos)
70 return static_cast<int>(_pIT->getAs<Double>()->get(_iPos));
73 double* getDoubleArrayFromDouble(InternalType* _pIT)
75 return _pIT->getAs<Double>()->get();
78 InternalType* createDoubleVector(int _iSize)
80 int piDims[] = {1, _iSize};
81 Double* pOut = new Double(2, piDims);
82 for (int i = 0; i < _iSize; i++)
89 bool checkArgValidity(typed_list& _Arg)
91 for (int i = 0; i < (int)_Arg.size(); i++)
93 if (_Arg[i]->isDouble() == false)
98 Double* pDbl = _Arg[i]->getAs<Double>();
99 double* pdbl = pDbl->get();
100 for (int j = 0; j < pDbl->getSize(); j++)
112 template <typename T>
113 InternalType* ArrayOf<T>::insert(typed_list* _pArgs, InternalType* _pSource)
117 // An ArrayOf content in more than one Scilab variable
118 // must be cloned before to be modified.
119 ArrayOf* pClone = clone()->template getAs<ArrayOf>();
120 InternalType* pIT = pClone->insert(_pArgs, _pSource);
130 if (getScalarIndex(this, _pArgs, &index))
132 ArrayOf* pIns = _pSource->getAs<ArrayOf>();
133 int sizeIn = pIns->getSize();
134 //only scalar can be used to ".=" operation
140 T* pRealData = pIns->get();
141 T* pImgData = pIns->getImg();
143 if (isComplex() == false && pIns->isComplex() == false)
145 if (set(index, *pRealData) == true)
151 //if complex continue
154 std::vector<int> indexes;
155 if (getImplicitIndex(this, _pArgs, indexes))
157 ArrayOf* pIns = _pSource->getAs<ArrayOf>();
158 int sizeIn = pIns->getSize();
159 int count = static_cast<int>(indexes.size());
160 //only scalar can be used to ".=" operation
161 if (sizeIn != 1 && count != sizeIn)
166 T* pRealData = pIns->get();
167 T* pImgData = pIns->getImg();
170 if (isComplex() == false && pIns->isComplex() == false)
174 for (int i : indexes)
176 if (set(i, *pRealData) == false)
185 for (int i : indexes)
187 if (set(i, *pRealData) == false)
201 //if status is false, continue to entire process
205 bool bNeedToResize = false;
206 int iDims = (int)_pArgs->size();
207 int iDimsOrigine = m_iDims;
210 int* piMaxDim = new int[iDims];
211 int* piCountDim = new int[iDims];
214 int* piNewDims = NULL;
216 ArrayOf* pSource = _pSource->getAs<ArrayOf>();
218 bool bIsColon = false;
220 //evaluate each argument and replace by appropriate value and compute the count of combinations
221 int iSeqCount = checkIndexesArguments(this, _pArgs, &pArg, piMaxDim, piCountDim);
227 cleanIndexesArguments(_pArgs, &pArg);
231 //only scalar can be used to ".=" operation
232 if (iSeqCount != pSource->getSize() && pSource->isScalar() == false)
237 //remove last dimension at size 1
238 //remove last dimension if are == 1
239 for (int i = (iDims - 1); i >= 2; i--)
241 if (piMaxDim[i] == 1)
244 pArg.back()->killMe();
254 if (iDims >= m_iDims)
256 //all case are good, we can do almost everything
257 //check if resize is needed
260 bNeedToResize = true;
262 else //_iDims == m_iDims
264 for (int i = 0; i < m_iDims; i++)
266 if (m_piDims[i] < piMaxDim[i])
268 bNeedToResize = true;
274 //determine new dimension of the matrix
275 if (bNeedToResize == true)
278 piNewDims = new int[iNewDims];
279 for (int i = 0; i < m_iDims; i++)
281 piNewDims[i] = std::max(piMaxDim[i], m_piDims[i]);
284 int iSource = (pSource->getDims() - 1);
285 bool bPassed = false;
286 int *piSourceDims = pSource->getDimsArray();
288 for (int i = m_iDims; i < iNewDims; ++i)
290 piNewDims[i] = piMaxDim[i];
294 else // _iDims < m_iDims
296 if (isVector() || isScalar() || getSize() == 0) //getSize() == 0, only for [] and {}
298 if (getSize() < piMaxDim[0])
300 bNeedToResize = true;
302 piNewDims = new int[2];
304 if (getCols() == 1 || getSize() == 0)
307 piNewDims[0] = piMaxDim[0];
310 else if (getRows() == 1)
314 piNewDims[1] = piMaxDim[0];
320 //each index before last index must be in range of his dimension
321 //and last given dimension can not be > prod(last dimensions)
322 for (int i = 0; i < iDims - 1; i++)
324 //indexes are always doubles
325 double* pIdx = getDoubleArrayFromDouble(pArg[i]);
326 //InternalType* pVar = pArg[i];
327 //double* pIdx = static_cast<double*>(pVar->getAs<Double>()->get());
328 int iSize = pArg[i]->getAs<ArrayOf>()->getSize();
329 for (int j = 0; j < iSize; j++)
331 if (pIdx[j] > m_piDims[i])
336 cleanIndexesArguments(_pArgs, &pArg);
343 int iMaxLastDim = getVarMaxDim(iDims - 1, iDims);
344 double* pIdx = getDoubleArrayFromDouble(pArg[pArg.size() - 1]);
345 //InternalType* pVar = pArg[pArg.size() - 1];
346 //double* pIdx = static_cast<double*>(pVar->getAs<Double>()->get());
347 int iSize = pArg[pArg.size() - 1]->getAs<GenericType>()->getSize();
348 for (int i = 0; i < iSize; i++)
350 if (pIdx[i] > iMaxLastDim)
355 cleanIndexesArguments(_pArgs, &pArg);
362 //before resize, check input dimension
366 bool bPass = resize(piNewDims, iNewDims);
372 cleanIndexesArguments(_pArgs, &pArg);
378 piNewDims = m_piDims;
383 if (pSource->isComplex() && m_pImgData == NULL)
388 int argSize = static_cast<int>(pArg.size());
389 int* piIndex = new int[argSize];
390 int* piCoord = new int[argSize];
391 int* piViewDims = new int[iDims];
392 memset(piIndex, 0x00, sizeof(int) * argSize);
394 //convert current dimension to view dimension
395 for (int i = 0; i < iDims; i++)
397 piViewDims[i] = getVarMaxDim(i, iDims);
400 T* pRealData = pSource->get();
401 T* pImgData = pSource->getImg();
402 bool bComplex = pSource->isComplex();
404 for (int i = 0; i < iSeqCount; i++)
406 computeTuples(piCountDim, argSize, argSize - 1, piIndex);
409 for (int j = 0; j < argSize; j++)
411 piCoord[j] = getIntValueFromDouble(pArg[j], piIndex[j]) - 1;
412 //InternalType* pVar = pArg[j];
413 //piCoord[j] = static_cast<int>(pVar->getAs<Double>()->get(piIndex[j]) - 1);
414 //std::cout << piCoord[j] << " ";
417 //std::cout << "]" << std::endl;
419 int iPos = getIndexWithDims(piCoord, piViewDims, iDims);
434 cleanIndexesArguments(_pArgs, &pArg);
436 wchar_t szError[bsiz];
437 os_swprintf(szError, bsiz, _W("Invalid index.\n").c_str());
438 throw ast::ScilabError(szError);
441 if (pSource->isScalar())
443 //element-wise insertion
444 set(iPos, pRealData[0]);
445 if (pImgData != NULL && bComplex)
447 setImg(iPos, pImgData[0]);
455 for (int j = 0; j < iDimsOrigine; j++)
457 iPas = iPas * m_piDims[j];
460 for (int iPost = iPos; iPost < this->getSize(); iPost += iPas)
462 set(iPost, pRealData[i]);
463 if (pImgData != NULL && bComplex)
465 setImg(iPost, pImgData[i]);
472 set(iPos, pRealData[i]);
473 if (pImgData != NULL && bComplex)
475 setImg(iPos, pImgData[i]);
480 // reset imaginary part
481 if (m_pImgData != NULL && bComplex == false)
502 cleanIndexesArguments(_pArgs, &pArg);
507 template <typename T>
508 InternalType* ArrayOf<T>::insertNew(typed_list* _pArgs, InternalType* _pSource)
511 InternalType *pOut = NULL;
512 ArrayOf* pSource = _pSource->getAs<ArrayOf>();
514 int iDims = (int)_pArgs->size();
515 int* piMaxDim = new int[iDims];
516 int* piCountDim = new int[iDims];
517 bool bComplex = pSource->getImg() != NULL;
518 bool bUndefine = false;
519 bool bIsImpli = false;
521 //evaluate each argument and replace by appropriate value and compute the count of combinations
522 int iSeqCount = checkIndexesArguments(NULL, _pArgs, &pArg, piMaxDim, piCountDim);
529 cleanIndexesArguments(_pArgs, &pArg);
530 return createEmptyDouble();
535 iSeqCount = -iSeqCount;
541 //manage : and $ in creation by insertion
542 int *piSourceDims = pSource->getDimsArray();
543 int iSourceDims = pSource->getDims();
544 int iCompteurNull = 0;
546 for (int i = 0; i < iDims; i++)
555 if ((*_pArgs)[i]->isImplicitList())
562 //if all index are : -> a = x
563 if (iCompteurNull == pArg.size())
568 cleanIndexesArguments(_pArgs, &pArg);
573 if (pSource->isVector() && iCompteurNull == 1)
575 piMaxDim[iLastNull] = pSource->getSize();
576 pArg[iLastNull] = createDoubleVector(piMaxDim[iLastNull]);
580 //matrix and hypermatrix case
581 if (iCompteurNull < pSource->getDims())
586 cleanIndexesArguments(_pArgs, &pArg);
587 //contain bad index, like <= 0, ...
591 //replace ":" by know source dimensions
593 for (int i = 0; i < iDims; ++i)
597 if (iSource < iSourceDims)
599 piMaxDim[i] = piSourceDims[iSource];
600 pArg[i] = createDoubleVector(piMaxDim[i]);
605 //fill dimensions after pSource->getDimes() with 1
607 pArg[i] = createDoubleVector(piMaxDim[i]);
614 //remove last dimension at size 1
615 //remove last dimension if are == 1
616 for (int i = (iDims - 1); i >= 2; i--)
618 if (piMaxDim[i] == 1)
621 pArg.back()->killMe();
630 if (checkArgValidity(pArg) == false)
635 cleanIndexesArguments(_pArgs, &pArg);
636 //contain bad index, like <= 0, ...
642 if (pSource->getCols() == 1)
644 int piRealDim[2] = {piMaxDim[0], 1};
645 pOut = pSource->createEmpty(2, piRealDim, bComplex);
650 int piRealDim[2] = {1, piMaxDim[0]};
651 pOut = pSource->createEmpty(2, piRealDim, bComplex);
656 pOut = pSource->createEmpty(iDims, piMaxDim, bComplex);
659 //fill with null item
660 ArrayOf* pArrayOut = pOut->getAs<ArrayOf>();
661 T* pRealData = pArrayOut->get();
664 T* pImgData = pArrayOut->getImg();
665 for (int i = 0; i < pArrayOut->getSize(); i++)
667 pArrayOut->deleteData(pRealData[i]);
668 pRealData[i] = pSource->getNullValue();
669 pArrayOut->deleteData(pImgData[i]);
670 pImgData[i] = pSource->getNullValue();
675 for (int i = 0; i < pArrayOut->getSize(); i++)
677 pArrayOut->deleteData(pRealData[i]);
678 pRealData[i] = pSource->getNullValue();
682 if (bIsImpli && (pArrayOut->getSize() != _pSource->getAs<types::GenericType>()->getSize()))
687 cleanIndexesArguments(_pArgs, &pArg);
690 //insert values in new matrix
691 InternalType* pOut2 = pArrayOut->insert(&pArg, _pSource);
700 cleanIndexesArguments(_pArgs, &pArg);
705 template <typename T>
706 bool ArrayOf<T>::append(int _iRows, int _iCols, InternalType* _poSource)
708 ArrayOf * pGT = _poSource->getAs<ArrayOf>();
709 int iRows = pGT->getRows();
710 int iCols = pGT->getCols();
712 //insert without resize
713 if (iRows + _iRows > m_iRows || iCols + _iCols > m_iCols)
718 //Update complexity if necessary
719 if (pGT->isComplex())
723 else if (isComplex())
725 pGT->setComplex(true);
728 if (pGT->isComplex())
730 for (int i = 0; i < iRows; i++)
732 for (int j = 0; j < iCols; j++)
734 set(_iRows + i, _iCols + j, pGT->get(i, j));
735 setImg(_iRows + i, _iCols + j, pGT->getImg(i, j));
741 for (int i = 0; i < iRows; i++)
743 for (int j = 0; j < iCols; j++)
745 set(_iRows + i, _iCols + j, pGT->get(i, j));
753 template <typename T>
754 InternalType* ArrayOf<T>::remove(typed_list* _pArgs)
756 ArrayOf<T>* pOut = NULL;
757 int iDims = (int)_pArgs->size();
760 int* piMaxDim = new int[iDims];
761 int* piCountDim = new int[iDims];
763 //evaluate each argument and replace by appropriate value and compute the count of combinations
764 int iSeqCount = checkIndexesArguments(this, _pArgs, &pArg, piMaxDim, piCountDim);
770 cleanIndexesArguments(_pArgs, &pArg);
771 //no Seq, no change but no error.
775 bool* pbFull = new bool[iDims];
776 //coord must represent all values on a dimension
777 for (int i = 0; i < iDims; i++)
780 int iDimToCheck = getVarMaxDim(i, iDims);
781 int iIndexSize = pArg[i]->getAs<GenericType>()->getSize();
783 //we can have index more than once
784 if (iIndexSize >= iDimToCheck)
786 //size is good, now check datas
787 double* pIndexes = getDoubleArrayFromDouble(pArg[i]);
788 for (int j = 0; j < iDimToCheck; j++)
791 for (int k = 0; k < iIndexSize; k++)
793 if ((int)pIndexes[k] == j + 1)
804 //only one dims can be not full/entire
805 bool bNotEntire = false;
807 bool bTooMuchNotEntire = false;
808 for (int i = 0; i < iDims; i++)
810 if (pbFull[i] == false)
812 if (bNotEntire == false)
819 bTooMuchNotEntire = true;
825 if (bTooMuchNotEntire == true)
828 cleanIndexesArguments(_pArgs, &pArg);
835 int iNotEntireSize = pArg[iNotEntire]->getAs<GenericType>()->getSize();
836 double* piNotEntireIndex = getDoubleArrayFromDouble(pArg[iNotEntire]);
837 int iKeepSize = getVarMaxDim(iNotEntire, iDims);
838 bool* pbKeep = new bool[iKeepSize];
840 //fill pbKeep with true value
841 for (int i = 0; i < iKeepSize; i++)
846 for (int i = 0; i < iNotEntireSize; i++)
848 int idx = (int)piNotEntireIndex[i] - 1;
850 //don't care of value out of bounds
858 for (int i = 0; i < iKeepSize; i++)
860 if (pbKeep[i] == true)
867 int* piNewDims = new int[iDims];
868 for (int i = 0; i < iDims; i++)
872 piNewDims[i] = iNewDimSize;
876 piNewDims[i] = getVarMaxDim(i, iDims);
880 //remove last dimension if are == 1
881 int iOrigDims = iDims;
882 for (int i = (iDims - 1); i >= 2; i--)
884 if (piNewDims[i] == 1)
894 if (iNewDimSize == 0)
897 cleanIndexesArguments(_pArgs, &pArg);
899 return createEmptyDouble();
904 //two cases, depends of original matrix/vector
905 if ((*_pArgs)[0]->isColon() == false && m_iDims == 2 && m_piDims[0] == 1 && m_piDims[1] != 1)
907 //special case for row vector
908 int piRealDim[2] = {1, iNewDimSize};
909 pOut = createEmpty(2, piRealDim, m_pImgData != NULL);
910 //in this case we have to care of 2nd dimension
915 int piRealDim[2] = {iNewDimSize, 1};
916 pOut = createEmpty(2, piRealDim, m_pImgData != NULL);
921 pOut = createEmpty(iDims, piNewDims, m_pImgData != NULL);
925 //find a way to copy existing data to new variable ...
927 int* piIndexes = new int[iOrigDims];
928 int* piViewDims = new int[iOrigDims];
929 for (int i = 0; i < iOrigDims; i++)
931 piViewDims[i] = getVarMaxDim(i, iOrigDims);
934 for (int i = 0; i < getSize(); i++)
936 bool bByPass = false;
937 getIndexesWithDims(i, piIndexes, piViewDims, iOrigDims);
939 //check if piIndexes use removed indexes
940 for (int j = 0; j < iNotEntireSize; j++)
942 if ((piNotEntireIndex[j] - 1) == piIndexes[iNotEntire])
950 if (bByPass == false)
953 pOut->set(iNewPos, get(i));
954 if (m_pImgData != NULL)
956 pOut->setImg(iNewPos, getImg(i));
963 cleanIndexesArguments(_pArgs, &pArg);
970 template <typename T>
971 InternalType* ArrayOf<T>::extract(typed_list* _pArgs)
973 ArrayOf<T>* pOut = NULL;
974 int iDims = (int)_pArgs->size();
977 int* piMaxDim = new int[iDims];
978 int* piCountDim = new int[iDims];
980 //evaluate each argument and replace by appropriate value and compute the count of combinations
981 int iSeqCount = checkIndexesArguments(this, _pArgs, &pArg, piMaxDim, piCountDim);
987 cleanIndexesArguments(_pArgs, &pArg);
988 return createEmptyDouble();
996 cleanIndexesArguments(_pArgs, &pArg);
1000 if (iDims < m_iDims)
1002 for (int i = 0; i < iDims; i++)
1004 int iDimToCheck = 0;
1005 if (i == (iDims - 1))
1007 iDimToCheck = getVarMaxDim(i, iDims);
1011 iDimToCheck = m_piDims[i];
1014 if (piMaxDim[i] > iDimToCheck)
1017 delete[] piCountDim;
1019 cleanIndexesArguments(_pArgs, &pArg);
1026 if (iDims > m_iDims)
1028 for (int i = m_iDims; i < iDims; i++)
1030 if (piMaxDim[i] > 1)
1033 delete[] piCountDim;
1035 cleanIndexesArguments(_pArgs, &pArg);
1042 for (int i = 0; i < m_iDims; i++)
1044 if (piMaxDim[i] > m_piDims[i])
1047 delete[] piCountDim;
1049 cleanIndexesArguments(_pArgs, &pArg);
1050 //exrtact must be in dimension limits
1056 //remove last dimension if are == 1
1057 for (int i = (iDims - 1); i >= 2; i--)
1059 if (piCountDim[i] == 1)
1072 if (piCountDim[0] == 0)
1075 delete[] piCountDim;
1077 cleanIndexesArguments(_pArgs, &pArg);
1078 return createEmptyDouble();
1082 //two cases, depends of original matrix/vector
1083 if ((*_pArgs)[0]->isColon() == false && m_iDims == 2 && m_piDims[1] != 1 && m_piDims[0] == 1)
1085 //special case for row vector
1086 int piRealDim[2] = {1, piCountDim[0]};
1087 pOut = createEmpty(2, piRealDim, m_pImgData != NULL);
1093 //for extraction on scalar
1094 pOut = createEmpty(pArg[0]->getAs<GenericType>()->getDims(), pArg[0]->getAs<GenericType>()->getDimsArray(), m_pImgData != NULL);
1098 int piRealDim[2] = {piCountDim[0], 1};
1099 pOut = createEmpty(2, piRealDim, m_pImgData != NULL);
1107 pOut = createEmpty(iDims, piCountDim, m_pImgData != NULL);
1110 int* piIndex = new int[_pArgs->size()];
1111 int* piCoord = new int[_pArgs->size()];
1112 int* piViewDims = new int[iDims];
1113 memset(piIndex, 0x00, sizeof(int) * _pArgs->size());
1115 for (int i = 0; i < iDims; i++)
1117 piViewDims[i] = getVarMaxDim(i, iDims);
1120 for (int i = 0; i < iSeqCount; i++)
1122 //increment last dimension
1123 computeTuples(piCountDim, (int)_pArgs->size(), (int)_pArgs->size() - 1, piIndex);
1126 for (int j = 0; j < (int)_pArgs->size(); j++)
1128 piCoord[j] = getIntValueFromDouble(pArg[j], piIndex[j]) - 1;
1129 //InternalType* pVar = pArg[i];
1130 //piCoord[j] = static_cast<int>(pVar->getAs<Double>()->get(piIndex[j]) - 1);
1131 //std::cout << piCoord[j] << " ";
1133 // try to access somewhere wrong.
1138 delete[] piViewDims;
1140 delete[] piCountDim;
1143 cleanIndexesArguments(_pArgs, &pArg);
1148 //std::cout << "]" << std::endl;
1151 //put vlaue in the new matrix
1152 if ((int)_pArgs->size() < m_iDims)
1154 //compute index based on viewed matrix
1155 iPos = getIndexWithDims(piCoord, piViewDims, iDims);
1159 //compute vector index
1160 iPos = getIndex(piCoord);
1163 //convert flat dimension to 0
1164 for (int j = 0; j < iDims; j++)
1166 if (piCountDim[j] == 1)
1172 pOut->set(i, get(iPos));
1173 if (m_pImgData != NULL)
1175 pOut->setImg(i, getImg(iPos));
1183 cleanIndexesArguments(_pArgs, &pArg);
1187 delete[] piViewDims;
1189 delete[] piCountDim;
1194 template <typename T>
1195 bool ArrayOf<T>::resize(int* _piDims, int _iDims)
1197 if (_iDims == m_iDims)
1199 bool bChange = false;
1200 for (int i = 0; i < _iDims; i++)
1202 if (m_piDims[i] != _piDims[i])
1209 if (bChange == false)
1216 //alloc new data array
1217 T* pRealData = NULL;
1221 if (m_pImgData != NULL)
1223 iNewSize = get_max_size(_piDims, _iDims);
1224 if (m_iSizeMax < iNewSize)
1226 //alloc 10% bigger than asked to prevent future resize
1227 int iOldSizeMax = m_iSizeMax;
1228 m_iSizeMax = static_cast<int>(iNewSize * 1.1);
1229 pRealData = allocData(m_iSizeMax);
1230 pImgData = allocData(m_iSizeMax);
1232 //copy values into new one
1233 int* piIndexes = new int[std::max(m_iDims, _iDims)];
1234 memset(piIndexes, 0x00, sizeof(int) * std::max(m_iDims, _iDims));
1235 for (int i = 0; i < _iDims; i++)
1240 int iPreviousNewIdx = 0;
1241 for (int i = 0; i < m_iSize; i++)
1243 getIndexes(i, piIndexes);
1244 int iNewIdx = getIndexWithDims(piIndexes, _piDims, _iDims);
1245 pRealData[iNewIdx] = m_pRealData[i];
1246 pImgData[iNewIdx] = m_pImgData[i];
1247 for (int j = iPreviousNewIdx; j < iNewIdx; ++j)
1249 T pTemp = getNullValue();
1250 pRealData[j] = copyValue(pTemp);
1251 pImgData[j] = copyValue(pTemp);
1252 if (pTemp != pRealData[j])
1258 iPreviousNewIdx = iNewIdx + 1;
1261 // if it's not the first resize,
1262 // fill new data with element of last allocation
1263 if (iPreviousNewIdx < iOldSizeMax)
1265 for (int i = iPreviousNewIdx; i < iOldSizeMax; ++i)
1267 pRealData[i] = m_pRealData[i];
1268 pImgData[i] = m_pImgData[i];
1273 // first resize, iOldSizeMax don't contain the 10%
1274 iOldSizeMax = iPreviousNewIdx;
1277 for (int i = iOldSizeMax; i < m_iSizeMax; ++i)
1279 T pTemp = getNullValue();
1280 pRealData[i] = copyValue(pTemp);
1281 pImgData[i] = copyValue(pTemp);
1282 if (pTemp != pRealData[i])
1290 delete[] m_pRealData;
1291 delete[] m_pImgData;
1292 //replace old array by new one
1293 m_pRealData = pRealData;
1294 m_pImgData = pImgData;
1298 //check if only the last dims change
1299 bool bNonLastDimChange = false;
1300 for (int i = 0; i < (m_iDims - 1); i++)
1302 if (m_piDims[i] != _piDims[i])
1304 bNonLastDimChange = true;
1309 //if vector or if row dimension not change, we don't need to shift data
1310 if (m_iDims != _iDims || (!isVector() && bNonLastDimChange))
1312 //copy values into new one
1313 int* piIndexes = new int[std::max(m_iDims, _iDims)];
1314 memset(piIndexes, 0x00, sizeof(int) * std::max(m_iDims, _iDims));
1315 for (int i = m_iSize - 1; i >= 0; i--)
1317 getIndexes(i, piIndexes);
1318 int iNewIdx = getIndexWithDims(piIndexes, _piDims, _iDims);
1321 T pTemp = m_pRealData[iNewIdx];
1322 m_pRealData[iNewIdx] = m_pRealData[i];
1323 m_pRealData[i] = pTemp;
1325 pTemp = m_pImgData[iNewIdx];
1326 m_pImgData[iNewIdx] = m_pImgData[i];
1327 m_pImgData[i] = pTemp;
1336 iNewSize = get_max_size(_piDims, _iDims);
1337 if (iNewSize > m_iSizeMax)
1339 //alloc 10% bigger than asked to prevent future resize
1340 int iOldSizeMax = m_iSizeMax;
1341 m_iSizeMax = static_cast<int>(iNewSize * 1.1);
1342 pRealData = allocData(m_iSizeMax);
1344 //copy values into new one
1345 int* piIndexes = new int[std::max(m_iDims, _iDims)];
1346 memset(piIndexes, 0x00, sizeof(int) * std::max(m_iDims, _iDims));
1347 for (int i = 0; i < _iDims; i++)
1352 int iPreviousNewIdx = 0;
1353 for (int i = 0; i < m_iSize; i++)
1355 getIndexes(i, piIndexes);
1356 int iNewIdx = getIndexWithDims(piIndexes, _piDims, _iDims);
1357 pRealData[iNewIdx] = m_pRealData[i];
1358 m_pRealData[i] = NULL;
1359 for (int j = iPreviousNewIdx; j < iNewIdx; ++j)
1361 T pTemp = getNullValue();
1362 T pTemp2 = copyValue(pTemp);
1363 pRealData[j] = pTemp2;
1364 if (pTemp != pTemp2)
1370 iPreviousNewIdx = iNewIdx + 1;
1373 //clean section between m_iSize and iOldSizeMax
1374 for (int i = m_iSize; i < iOldSizeMax; ++i)
1376 deleteData(m_pRealData[i]);
1377 m_pRealData[i] = NULL;
1380 //if (iPreviousNewIdx < iOldSizeMax)
1382 // for (int i = iPreviousNewIdx; i < iOldSizeMax; ++i)
1384 // pRealData[i] = m_pRealData[i];
1385 // m_pRealData[i] = NULL;
1390 // iOldSizeMax = iPreviousNewIdx;
1393 //fill exceeded with NullValue
1394 for (int i = iPreviousNewIdx; i < m_iSizeMax; ++i)
1396 T pTemp = getNullValue();
1397 T pTemp2 = copyValue(pTemp);
1398 pRealData[i] = pTemp2;
1399 if (pTemp != pTemp2)
1407 delete[] m_pRealData;
1408 //replace old array by new one
1409 m_pRealData = pRealData;
1413 //check if only the last dims change
1414 bool bNonLastDimChange = false;
1415 for (int i = 0; i < (m_iDims - 1); i++)
1417 if (m_piDims[i] != _piDims[i])
1419 bNonLastDimChange = true;
1424 //if vector or if row dimension not change, we don't need to shift data
1425 if (m_iDims != _iDims || (!isVector() && bNonLastDimChange))
1427 //copy values into new one
1428 int* piIndexes = new int[std::max(m_iDims, _iDims)];
1429 memset(piIndexes, 0x00, sizeof(int) * std::max(m_iDims, _iDims));
1430 for (int i = m_iSize - 1; i >= 0; i--)
1432 getIndexes(i, piIndexes);
1433 int iNewIdx = getIndexWithDims(piIndexes, _piDims, _iDims);
1436 T pTemp = m_pRealData[iNewIdx];
1437 m_pRealData[iNewIdx] = m_pRealData[i];
1438 m_pRealData[i] = pTemp;
1446 if (_iDims != m_iDims)
1448 //int* piDims = new int[_iDims];
1449 for (int i = 0; i < _iDims; i++)
1451 m_piDims[i] = _piDims[i];
1453 //delete[] m_piDims;
1454 //m_piDims = piDims;
1459 for (int i = 0; i < m_iDims; i++)
1461 m_piDims[i] = _piDims[i];
1464 m_iRows = m_piDims[0];
1465 m_iCols = m_piDims[1];
1471 // used to allow definition of ArrayOf methode in this cpp file.
1472 template class EXTERN_AST ArrayOf<char>;
1473 template class EXTERN_AST ArrayOf<unsigned char>;
1474 template class EXTERN_AST ArrayOf<short>;
1475 template class EXTERN_AST ArrayOf<unsigned short>;
1476 template class EXTERN_AST ArrayOf<int>;
1477 template class EXTERN_AST ArrayOf<unsigned int>;
1478 template class EXTERN_AST ArrayOf<long long>;
1479 template class EXTERN_AST ArrayOf<unsigned long long>;
1480 template class EXTERN_AST ArrayOf<double>;
1481 template class EXTERN_AST ArrayOf<wchar_t*>;
1482 template class EXTERN_AST ArrayOf<SinglePoly*>;
1483 template class EXTERN_AST ArrayOf<SingleStruct*>;
1484 template class EXTERN_AST ArrayOf<InternalType*>; // Cell