2 * Scilab ( http://www.scilab.org/ ) - This file is part of Scilab
3 * Copyright (C) 2008-2008 - 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
15 #include "boolexp.hxx"
16 #include "tostring_common.hxx"
17 #include "configvariable.hxx"
18 #include "type_traits.hxx"
22 #include "core_math.h"
29 if (isDeletable() == true)
36 Inspector::removeItem(this);
40 Bool::Bool(int _iRows, int _iCols)
42 int piDims[2] = {_iRows, _iCols};
44 create(piDims, 2, &piBool, NULL);
46 Inspector::addItem(this);
50 Bool::Bool(int _iReal)
52 int piDims[2] = {1, 1};
54 create(piDims, 2, &piBool, NULL);
55 piBool[0] = _iReal == 0 ? 0 : 1;
57 Inspector::addItem(this);
61 Bool::Bool(int _iRows, int _iCols, int **_piData)
63 int piDims[2] = {_iRows, _iCols};
64 create(piDims, 2, _piData, NULL);
66 Inspector::addItem(this);
70 Bool::Bool(int _iDims, int* _piDims)
73 create(_piDims, _iDims, &piData, NULL);
75 Inspector::addItem(this);
79 Bool::Bool(int _iRows, int _iCols, int * _piData)
81 m_pRealData = _piData;
85 m_iSize = m_iRows * m_iCols;
87 m_piDims[0] = m_iRows;
88 m_piDims[1] = m_iCols;
91 Inspector::addItem(this);
95 InternalType* Bool::clone()
97 Bool *pbClone = new Bool(getDims(), getDimsArray());
104 std::cout << "types::Bool";
107 bool Bool::setFalse()
109 for (int i = 0 ; i < getSize() ; i++)
118 for (int i = 0 ; i < getSize() ; i++)
125 bool Bool::subMatrixToString(std::wostringstream& ostr, int* _piDims, int /*_iDims*/)
127 int iCurrentLine = 0;
128 int iLineLen = ConfigVariable::getConsoleWidth();
129 int iMaxLines = ConfigVariable::getConsoleLines();
136 int iPos = getIndex(_piDims);
137 ostr << (get(iPos) == 1 ? L" T" : L" F");
140 else if (getCols() == 1)
143 for (int i = m_iRows1PrintState ; i < getRows() ; i++)
146 if ((iMaxLines == 0 && iCurrentLine >= MAX_LINES) || (iMaxLines != 0 && iCurrentLine >= iMaxLines))
148 m_iRows1PrintState = i;
154 int iPos = getIndex(_piDims);
155 ostr << (get(iPos) ? L" T" : L" F");
159 else if (getRows() == 1)
162 std::wostringstream ostemp;
163 int iLastVal = m_iCols1PrintState;
166 for (int i = m_iCols1PrintState ; i < getCols() ; i++)
170 int iPos = getIndex(_piDims);
172 if (iLen + 2 >= iLineLen)
174 iCurrentLine += 4; //"column x to Y" + empty line + value + empty line
175 if ((iMaxLines == 0 && iCurrentLine >= MAX_LINES) || (iMaxLines != 0 && iCurrentLine >= iMaxLines))
177 m_iCols1PrintState = iLastVal;
181 ostr << std::endl << L" column " << iLastVal + 1 << L" to " << i << std::endl << std::endl;
182 ostr << L" " << ostemp.str() << std::endl;
188 ostemp << (get(iPos) ? L" T" : L" F");
194 ostr << std::endl << L" column " << iLastVal + 1 << L" to " << getCols() << std::endl << std::endl;
196 ostr << L" " << ostemp.str() << std::endl;
200 std::wostringstream ostemp;
202 int iLastCol = m_iCols1PrintState;
204 //compute the row size for padding for each printed bloc.
205 for (int iCols1 = m_iCols1PrintState ; iCols1 < getCols() ; iCols1++)
207 if (iLen + 2 > iLineLen)
209 //find the limit, print this part
210 for (int iRows2 = m_iRows2PrintState ; iRows2 < getRows() ; iRows2++)
213 if ((iMaxLines == 0 && iCurrentLine >= MAX_LINES) ||
214 ( (iMaxLines != 0 && iCurrentLine + 3 >= iMaxLines && iRows2 == m_iRows2PrintState) ||
215 (iMaxLines != 0 && iCurrentLine + 1 >= iMaxLines && iRows2 != m_iRows2PrintState)))
217 if (m_iRows2PrintState == 0 && iRows2 != 0)
220 ostr << std::endl << L" column " << iLastCol + 1 << L" to " << iCols1 << std::endl << std::endl;
222 ostr << L" " << ostemp.str();
223 m_iRows2PrintState = iRows2;
224 m_iCols1PrintState = iLastCol;
228 for (int iCols2 = iLastCol ; iCols2 < iCols1 ; iCols2++)
232 int iPos = getIndex(_piDims);
233 ostemp << (get(iPos) == 0 ? L" F" : L" T");
235 ostemp << std::endl << L" ";
239 if (m_iRows2PrintState == 0)
242 ostr << std::endl << L" column " << iLastCol + 1 << L" to " << iCols1 << std::endl << std::endl;
245 ostr << L" " << ostemp.str();
248 m_iRows2PrintState = 0;
249 m_iCols1PrintState = 0;
254 for (int iRows2 = m_iRows2PrintState ; iRows2 < getRows() ; iRows2++)
257 if ((iMaxLines == 0 && iCurrentLine >= MAX_LINES) || (iMaxLines != 0 && iCurrentLine >= iMaxLines))
259 if (m_iRows2PrintState == 0 && iLastCol != 0)
262 ostr << std::endl << L" column " << iLastCol + 1 << L" to " << getCols() << std::endl << std::endl;
265 ostr << ostemp.str();
266 m_iRows2PrintState = iRows2;
267 m_iCols1PrintState = iLastCol;
271 for (int iCols2 = iLastCol ; iCols2 < getCols() ; iCols2++)
275 int iPos = getIndex(_piDims);
277 ostemp << (get(iPos) == 0 ? L" F" : L" T");
279 ostemp << std::endl << L" ";
281 if (m_iRows2PrintState == 0 && iLastCol != 0)
283 ostr << std::endl << L" column " << iLastCol + 1 << L" to " << getCols() << std::endl << std::endl;
285 ostr << L" " << ostemp.str();
291 bool Bool::operator==(const InternalType& it)
293 if (const_cast<InternalType &>(it).isBool() == false)
298 Bool* pb = const_cast<InternalType &>(it).getAs<types::Bool>();
300 if (pb->getDims() != getDims())
305 for (int i = 0 ; i < getDims() ; i++)
307 if (pb->getDimsArray()[i] != getDimsArray()[i])
313 if (memcmp(get(), pb->get(), getSize() * sizeof(int)) != 0)
320 bool Bool::operator!=(const InternalType& it)
322 return !(*this == it);
325 int Bool::getNullValue()
330 Bool* Bool::createEmpty(int _iDims, int* _piDims, bool /*_bComplex*/)
332 return new Bool(_iDims, _piDims);
335 int Bool::copyValue(int _iData)
337 return _iData == 0 ? 0 : 1;
340 void Bool::deleteAll()
342 delete[] m_pRealData;
347 void Bool::deleteImg()
351 int* Bool::allocData(int _iSize)
353 return new int[_iSize];
356 ast::Exp* Bool::getExp(const Location& loc)
358 return new ast::BoolExp(loc, this);
361 bool Bool::transpose(InternalType *& out)
363 return type_traits::transpose(*this, out);