static bool AddParameters(const BMessage& message, driver_settings *to) { const char *name; BMessage current; driver_parameter *parameter; for(int32 index = 0; message.FindMessage(MDSU_PARAMETERS, index, ¤t) == B_OK; index++) { name = current.FindString(MDSU_NAME); parameter = new_driver_parameter(name); if(!AddValues(current, parameter)) return false; AddParameters(current, parameter); add_driver_parameter(parameter, to); } return true; }
size_t SparseBinaryInput<ElemType>::ReadMinibatch(void* data_buffer, std::map<std::wstring, shared_ptr<BinaryMatrix<ElemType>>>& matrices) { // fprintf(stderr, "start read minibatch.\n"); /* size_t readSize = m_offsets[cur_batch + 1] - m_offsets[cur_batch]; void* data_buffer = GetTempDataPointer(readSize); fprintf(stderr, "start reading data.\n"); m_inFile.clear(); m_inFile.seekg(m_dataStart + m_offsets[cur_batch], ios::beg); m_inFile.read((char*)data_buffer, readSize); fprintf(stderr, "done reading data.\n"); */ int32_t nnz; int32_t curMBSize; int64_t buffer_offset = 0; curMBSize = *(int32_t*) ((char*) data_buffer + buffer_offset); buffer_offset += sizeof(int32_t); for (int32_t c = 0; c < m_features.size(); c++) { // fprintf(stderr, "read features %d.\n", c); nnz = *(int32_t*) ((char*) data_buffer + buffer_offset); buffer_offset += sizeof(int32_t); ElemType* vals = (ElemType*) ((char*) data_buffer + buffer_offset); buffer_offset += sizeof(ElemType) * nnz; int32_t* rowIndices = (int32_t*) ((char*) data_buffer + buffer_offset); buffer_offset += sizeof(int32_t) * nnz; int32_t* colIndices = (int32_t*) ((char*) data_buffer + buffer_offset); buffer_offset += sizeof(int32_t) * (curMBSize + 1); auto findMat = matrices.find(m_features[c]); if (findMat != matrices.end()) { auto mat = findMat->second; mat->ResizeArrays(nnz); mat->AddValues(vals, nnz); mat->AddRowIndices(rowIndices, nnz); mat->AddColIndices(colIndices, curMBSize + 1); mat->UpdateNNz(nnz); #ifdef DEBUG mat->Print("features"); #endif } } for (int32_t c = 0; c < m_labels.size(); c++) { // fprintf(stderr, "read labels %d.\n", c); int32_t numCols = m_mappedNumCols[m_labels[c]]; ElemType* vals = (ElemType*) ((char*) data_buffer + buffer_offset); buffer_offset += sizeof(ElemType) * curMBSize * numCols; auto findMat = matrices.find(m_labels[c]); if (findMat != matrices.end()) { auto mat = findMat->second; mat->AddValues(vals, curMBSize); #ifdef DEBUG mat->Print("labels"); #endif } } return (size_t) curMBSize; }
void ConfigurationManager::Load(const std::string& path) { namespace fs = boost::filesystem; fs::path filePath; if (path.empty()) filePath = path_; else filePath = fs::path(path); if (fs::is_directory(filePath)) { // Search all xml files from path. std::list<std::string> files = GetFiles(filePath); for (std::list<std::string>::iterator iter = files.begin(); iter != files.end(); ++iter) { std::string group = ""; // Get group name (it is encoded to filename) fs::path file(*iter); std::string fileName = file.filename(); std::string::size_type bPos = fileName.find(file_name_encoding_); if( bPos != std::string::npos) { // File is valid. bPos += file_name_encoding_.size(); std::string::size_type ePos = fileName.find(".xml"); // Get group name. group = fileName.substr(bPos, ePos - bPos); } else { // File was invalid. continue; } if (!QString::fromStdString(fileName).endsWith(".xml")) continue; //! Poco xml configuration reader Poco::AutoPtr<Poco::Util::XMLConfiguration> pConfiguration; try { pConfiguration = new Poco::Util::XMLConfiguration(); std::fstream stream(iter->c_str(), std::ios::in); pConfiguration->load(stream); } catch ( std::exception& /*ex*/) { // XML file was not valid (not so beatiful way to check validity) continue; } if (pConfiguration.get() != 0) { // Read values from xml file and set them into memory. AddValues(pConfiguration, group); } } } else { // Path is a file. std::string group = ""; std::string fileName = filePath.filename(); std::string::size_type bPos = fileName.find(file_name_encoding_); if( bPos != std::string::npos) { // File is valid. std::string::size_type ePos = fileName.find(".xml"); // Get group name. group = fileName.substr(bPos, ePos - bPos); } else { // File was invalid. return; } Poco::AutoPtr<Poco::Util::XMLConfiguration> pConfiguration; try { pConfiguration = new Poco::Util::XMLConfiguration(); std::fstream stream(filePath.file_string().c_str(), std::ios::in); pConfiguration->load(stream); } catch ( std::exception& /*ex*/) { // XML file was not valid (not so beatiful way to check it validity) // Create exception. std::string what = std::string("Failed to load configuration file: ") + path; throw Exception(what.c_str()); } if ( pConfiguration.get() != 0 ) AddValues(pConfiguration,group); } }
wyBool ExportAsSimpleSQL::WriteInsertStatement(ExportSQLData *data) { wyInt32 messagecount = 0, rowcount = 0, rowptr = 0; wyString value, messbuff, table; wyBool ismysql41 = IsMySQL41(m_tunnel, m_mysql), retval = wyTrue; MYSQL_ROWS *rowswalker = NULL; //HWND hwndgrid; MDIWindow *wnd; wnd = GetActiveWin(); /*if(wnd && wnd->GetActiveTabEditor() && wnd->GetActiveTabEditor()->m_pctabmgmt && wnd->GetActiveTabEditor()->m_pctabmgmt->m_pcdataviewquery && wnd->GetActiveTabEditor()->m_pctabmgmt->m_pcdataviewquery->m_hwndgrid) { hwndgrid = wnd->GetActiveTabEditor()->m_pctabmgmt->m_pcdataviewquery->m_hwndgrid; }*/ m_tunnel->mysql_data_seek(m_myres,(my_ulonglong)0); /* if(data->m_tabrec->m_data) tmp = data->m_tabrec->m_data->m_data; */ while(1) { if(*data->m_stopped == wyTrue) { SetWindowText(GetDlgItem(data->m_hwnd, IDC_MESSAGE), _(L"Aborted by user")); return wyFalse; } //If exporting from result tab with edit mode 'data->m_tabrec->m_data' will not be NULL , this contains rows to export. //If export from 'Tabletab' or result tab in 'read only mode' use the normal MYSQL_RES pointer, to retrive the data if(!data->m_tabrec->m_rowarray->GetLength()) { if(m_isdatafromquery == wyTrue) { //If use mysql_useresult() then we should use this m_myrow = m_tunnel->mysql_fetch_row(m_myres); } else { SeekCurrentRowFromMySQLResult(m_myres, &rowswalker, m_tunnel, &m_myrow, &m_rowlength); } if(!m_myrow) { //SendMessage(hwndgrid, WM_SETREDRAW, TRUE, 0); break; } } //In result tab with 'edit' mode or the result is edited else { //bug fixed.http://code.google.com/p/sqlyog/issues/detail?id=494 //no need to export unsaved row.. if it is a saved row then m_newrow =wyFalse if(rowptr == data->m_tabrec->m_rowarray->GetLength()) break; //no need to export unsaved row.. if it is a saved row then m_newrow =wyFalse if(data->m_tabrec->m_rowarray->GetRowExAt(rowptr)->IsNewRow()) { rowptr++; break; } if(data->m_tabrec->m_modifiedrow >=0 && data->m_tabrec->m_modifiedrow == rowcount && data->m_tabrec->m_oldrow->IsNewRow() == wyFalse) { m_myrow = data->m_tabrec->m_oldrow->m_row; } else { m_myrow = data->m_tabrec->m_rowarray->GetRowExAt(rowptr)->m_row; } rowptr++; } if(ismysql41 == wyTrue) value.Sprintf("insert into `%s` ", data->m_tablename.GetString()); else { //table.SetAs(data->m_tabrec->m_table.GetString()); value.Sprintf("insert into `%s` ", data->m_tablename.GetAsAnsi()); } AddColumnNames(data, value); value.Add("values("); retval = AddValues(data, value); /*if(!data->m_tabrec->m_data) { SendMessage(hwndgrid, WM_SETREDRAW, TRUE, 0); }*/ //Freeing the buffer that keeps the row-lengths if(m_rowlength) { free(m_rowlength); m_rowlength = NULL; } if(retval == wyFalse) { return wyFalse; } value.Strip(1); /// Strip 1 for the last ',' value.Add(");\r\n"); messbuff.Sprintf(_(" %d Rows Exported"), ++messagecount); SendMessage(data->m_hwndmessage, WM_SETTEXT, 0, (LPARAM)messbuff.GetAsWideChar()); if(WriteToFile(value) == wyFalse) return wyFalse; rowcount++; } value.Add(";\r\n"); if(m_rowlength) { free(m_rowlength); m_rowlength = NULL; } return wyTrue; }