void FileReader::exciseMatrixSize(std::string &strInput, unsigned &nRowNumber, unsigned &nColumnNumber) { size_t startPos, endPos; if( ((startPos = strInput.find_first_of(MATRIX_SIZE_START_SYMBOL)) == std::string::npos) || ((endPos = strInput.find_first_of(MATRIX_SIZE_END_SYMBOL)) == std::string::npos) ) { throw fileException("Incorrect matrix description"); } std::string strMatrixSize = strInput.substr(startPos, endPos - startPos + 1); strInput.erase(startPos, endPos - startPos + 1); removeBrackets(strMatrixSize, MATRIX_SIZE_START_SYMBOL, MATRIX_SIZE_END_SYMBOL); if((strMatrixSize.find(MATRIX_ELEMENT_DELIMITER) == std::string::npos) || (std::count(strMatrixSize.begin(), strMatrixSize.end(), MATRIX_ELEMENT_DELIMITER) != 1)) { throw fileException("Incorrect matrix size"); } std::vector<std::string> vecMatrixSizes(splitStringToElements(strMatrixSize, MATRIX_ELEMENT_DELIMITER)); if(vecMatrixSizes.size() != 2) { throw fileException("Matrix size must contain 2 digits"); } try { nRowNumber = boost::lexical_cast<unsigned>(vecMatrixSizes[0]); nColumnNumber = boost::lexical_cast<unsigned>(vecMatrixSizes[1]); } catch (boost::bad_lexical_cast e) { throw fileException("Failed to cast Row anf Column numbers."); } }
FileReader::MatrixExp FileReader::getMatrixFromString(const std::string &strInput, unsigned nRowNumber, unsigned nColumnNumber) { std::string strTemp(strInput); removeBrackets(strTemp, MATRIX_ELEMENT_START_SYMBOL, MATRIX_ELEMENT_END_SYMBOL); std::cout << "String: " << strTemp << std::endl; std::vector<std::string> vecTemp = splitStringToElements(strTemp, MATRIX_ELEMENT_DELIMITER); MatrixExp matr(nRowNumber, nColumnNumber); unsigned nElem(0); try { for(unsigned i = 0; i < matr.size1(); ++i) { for(unsigned j = 0; j < matr.size2(); ++j) { // At the moment only matrix which contains digits can be read from a file // TODO: Add full support of reading from a file into Expression SimpleExpression exp(SimpleItem(std::string(""), 0, boost::lexical_cast<double>(vecTemp[nElem++]))); matr.insert_element(i, j, exp); } } } catch (boost::bad_lexical_cast e) { throw fileException("Only digital matrices are supported."); } return matr; }
FileReader::FileReader(boost::filesystem::path &FilePath) { boost::system::error_code error; if(boost::filesystem::exists(FilePath, error) && boost::filesystem::is_regular_file(FilePath, error)) { m_file.open(FilePath.string(), std::ios_base::in); } else { throw fileException(error.message().c_str()); } }
void GLC_WorldTo3dxml::setStreamWriterToFile(const QString& fileName) { delete m_pOutStream; m_pOutStream= NULL; bool success= false; if (NULL != m_p3dxmlArchive) { if (NULL != m_pCurrentZipFile) { m_pCurrentZipFile->close(); delete m_pOutStream; delete m_pCurrentZipFile; } QuaZipNewInfo quazipNewInfo(fileName); m_pCurrentZipFile= new QuaZipFile(m_p3dxmlArchive); success= m_pCurrentZipFile->open(QIODevice::WriteOnly, quazipNewInfo); if (success) { m_pOutStream= new QXmlStreamWriter(m_pCurrentZipFile); } } else { delete m_pCurrentFile; m_pCurrentFile= new QFile(m_AbsolutePath + fileName); success= m_pCurrentFile->open(QIODevice::WriteOnly); if (success) { m_pOutStream= new QXmlStreamWriter(m_pCurrentFile); } } if (NULL == m_pOutStream) { QString message(QString("GLC_WorldTo3dxml::setStreamWriterToFile Unable to create ") + fileName); GLC_Exception fileException(message); throw(fileException); } else { m_pOutStream->setAutoFormatting(true); } }
void BMPFileViewer::save(const std::string name)const { if(!customPlot->saveBmp(name.c_str())) throw fileException("File cannot be saved as: "+name); }