QSqlRecord DBHandler::queryOne(PreparedQuery* query) { #ifdef CXX_11 std::unique_ptr<PreparedQuery> qu(query); #else /* CXX_11? */ std::auto_ptr<PreparedQuery> qu(query); #endif /* CXX_11? */ QMutexLocker locker(&dbMutex); if (!db.isOpen ()) throw std::runtime_error ("Database is not open."); if (!qu->execute ()) { std::ostringstream msg; msg << "Database query failed: " << qu->query.lastError ().text ().toStdString (); throw std::runtime_error (msg.str ()); } if (!qu->query.next ()) throw std::runtime_error ("Expected at least one result" " in DBHandler::queryOne."); QSqlRecord res = qu->query.record (); if (qu->query.next ()) throw std::runtime_error ("Expected at most one result" " in DBHandler::queryOne."); return res; }
int qu(int l,int r,int a,int b,int i) { if(l==a&&r==b) return seg[i]; int mid=(l+r)>>1; if(mid>=b) return qu(l,mid,a,b,2*i); else if(a>mid) return qu(mid+1,r,a,b,2*i+1); else return max(qu(l,mid,a,mid,2*i),qu(mid+1,r,mid+1,b,2*i+1)); }
bool DBHandler::runQuery(PreparedQuery* query) { #ifdef CXX_11 std::unique_ptr<PreparedQuery> qu(query); #else /* CXX_11? */ std::auto_ptr<PreparedQuery> qu(query); #endif /* CXX_11? */ QMutexLocker locker(&dbMutex); if (!db.isOpen ()) return false; return qu->execute (); }
VOID CWXObj_Object::SetOrientation(const fVector3& vRotate) { TDAssert(m_pWXObject); Ogre::Quaternion qu(Ogre::Radian(vRotate.y), Ogre::Vector3::UNIT_Y); m_pWXObject->setProperty(FOBJ_ORIENTATION, qu); }
VOID CObjEntityModel::SetOrientation(const fVector3& vRotate) { KLAssert(m_pFairyObj); Ogre::Quaternion qu(Ogre::Radian(vRotate.y), Ogre::Vector3::UNIT_Y); m_pFairyObj->setProperty(FOBJ_ORIENTATION, qu); }
bool GameLibraryModel::select() { const QString query = selectStatement(); if (query.isEmpty()) return false; beginResetModel(); // d->clearCache(); QSqlQuery qu(database()); qu.prepare(query); for (auto &val : params) { qu.addBindValue(val); } qu.exec(); setQuery(qu); if (!qu.isActive() || lastError().isValid()) { setTable(tableName()); // resets the record & index endResetModel(); return false; } endResetModel(); return true; }
void main(){ int iLine,iColumn;//行和列 //棋盘初始化,空格为*,放置皇后的地方为@ printf("print the default matrix:\n"); for(iLine=0;iLine<8;iLine++){ a[iLine] = 0;//列标记初始化,表示无列冲突 for(iColumn=0;iColumn<8;iColumn++){ Queen[iLine][iColumn] = '*'; printf("%2c",Queen[iLine][iColumn]); } printf("\n"); } //主、从对角线标记初始化,表示没有冲突 for(iLine=0;iLine<15;iLine++) b[iLine] = c[iLine] = 0; //主对角线和从对角线输出 printf("\nmain diagonal:\n"); for(iLine=0;iLine<15;iLine++){ printf("%2d",b[iLine]); } printf("\nsecondary diagonal:\n"); for(iLine=0;iLine<15;iLine++){ printf("%2d",b[iLine]); } printf("\n\n"); qu(0); }
void CreateTableDialog::on_buttonBox_accepted() { if (isAlter) { db.exec(createTempString); if (db.lastError().isValid()) { QMessageBox::critical(this, tr("Error"), tr("Table Error:\n%1").arg(db.lastError().text())); return; } db.exec(insertTempString); if (db.lastError().isValid()) { QMessageBox::critical(this, tr("Error"), tr("Table Error:\n%1").arg(db.lastError().text())); return; } db.exec(QString("DROP TABLE `%1`;").arg(ui->txtTableName->text())); if (db.lastError().isValid()) { QMessageBox::critical(this, tr("Error"), tr("Table Error:\n%1").arg(db.lastError().text())); return; } } QSqlQuery qu(getSQL(), db); if (!qu.lastError().isValid()) { if (isAlter) { QString newColumnList = ""; for (int i = 0; i < columnList.count(); ++i) { QString colValue = columnList.at(i); if (gridColumns.contains(colValue)) { newColumnList += colValue + ", "; } } newColumnList = newColumnList.remove(newColumnList.count() - 2, 2); QString newInsert = "INSERT INTO `" + ui->txtTableName->text(); newInsert += "` ("; newInsert += newColumnList; newInsert += ") SELECT "; newInsert += newColumnList; newInsert += " FROM TEMP_TABLE;"; db.exec(newInsert); if (db.lastError().isValid()) { QMessageBox::critical(this, tr("Error"), tr("Table Error:\n%1").arg(db.lastError().text())); return; } db.exec("DROP TABLE TEMP_TABLE;"); if (db.lastError().isValid()) { QMessageBox::critical(this, tr("Error"), tr("Table Error:\n%1").arg(db.lastError().text())); return; } } this->accept(); } else { QMessageBox::critical(this, tr("Error"), tr("Table Error:\n%1").arg(qu.lastError().text())); return; } }
int qu(int a,int b,int c,int d,int i) { if(a<=seg[i].l&&seg[i].r<=b&&c<=seg[i].a&&seg[i].b<=d) return seg[i].sum; if(b<seg[i].l||seg[i].r<a||c>seg[i].b||seg[i].a>d) return 0; int t=0; for(int j=0;j<4;j++) if(seg[i].ch[j]) t+=qu(a,b,c,d,seg[i].ch[j]); return t; }
bool parseBitcoinURI(const QUrl &uri, SendCoinsRecipient *out) { // NovaCoin: check prefix if(uri.scheme() != QString("Candle")) return false; SendCoinsRecipient rv; rv.address = uri.path(); rv.amount = 0; #if QT_VERSION >= 0x050000 QUrlQuery qu(uri); QList<QPair<QString, QString> > items = qu.queryItems(); #else QList<QPair<QString, QString> > items = uri.queryItems(); #endif for (QList<QPair<QString, QString> >::iterator i = items.begin(); i != items.end(); i++) { bool fShouldReturnFalse = false; if (i->first.startsWith("req-")) { i->first.remove(0, 4); fShouldReturnFalse = true; } if (i->first == "label") { rv.label = i->second; fShouldReturnFalse = false; } else if (i->first == "amount") { if(!i->second.isEmpty()) { if(!BitcoinUnits::parse(BitcoinUnits::BTC, i->second, &rv.amount)) { return false; } } fShouldReturnFalse = false; } if (fShouldReturnFalse) return false; } if(out) { *out = rv; } return true; }
int main() { while(scanf("%d",&n)!=EOF) { build(1,n,1); for(int i=1;i<=n;i++) scanf("%d%d%d",s+i,x+i,y+i); dp[n]=s[n]; for(int i=n-1;i>=1;i--) { ud(1,n,i+1,1,dp[i+1]); if(i+y[i]-1<=n) dp[i]=s[i]+qu(1,n,i+x[i],i+y[i]-1,1); else if(i+x[i]<=n) dp[i]=s[i]+qu(1,n,i+x[i],n,1); else dp[i]=s[i]; } printf("%d\n",dp[1]); } return 0; }
void IMG_linkrelout(Image_t *img, uaddr_t addr, const char *name, const char *segname) { assert(img != NULL); sqlq_t qi(img->db, "INSERT OR IGNORE INTO tab_label(name, type, module, segment) VALUES(@N, 0, NULL, " "(SELECT segid FROM tab_segment WHERE name=@B))"); qi.bind_str(1, name); qi.bind_str(2, segname); qi.run(); sqlq_t qu(img->db, "UPDATE tab_reloc SET label=(SELECT labid FROM tab_label WHERE name=@A) " "WHERE address=@C"); qu.bind_str(1, name); qu.bind_int(2, addr); qu.run(); }
/*! Populates the model with data from the table that was set via setTable(), using the specified filter and sort condition, and returns true if successful; otherwise returns false. \sa setTable(), setFilter(), selectStatement() */ bool QSqlTableModel::select() { Q_D(QSqlTableModel); QString query = selectStatement(); if (query.isEmpty()) return false; revertAll(); QSqlQuery qu(query, d->db); setQuery(qu); if (!qu.isActive()) { // something went wrong - revert to non-select state d->initRecordAndPrimaryIndex(); return false; } return true; }
int main() { int iLine,iColumn; //棋盘初始化,空格为*,放置皇后的地方为@ for(iLine=0;iLine<8;iLine++) { a[iLine]=0; //列标记初始化,表示无列冲突 for(iColumn=0;iColumn<8;iColumn++) Queen[iLine][iColumn]='*'; } //主、从对角线标记初始化,表示没有冲突 for(iLine=0;iLine<15;iLine++) b[iLine]=c[iLine]=0; qu(0); return 0; }
int main() { while(gets(str)!=NULL) { cnt=0; ff=1; get(1,MAXN,1,MAXN); while(1) { if(str[0]=='E') break; if(str[0]=='I') { ff=1; gets(str); continue; } else if(str[0]=='Q') { ff=0; gets(str); continue; } else { int a,b,c,d; if(ff) { sscanf(str,"%d%d%d",&a,&b,&c); ud(a,b,1,c); } else { sscanf(str,"%d%d%d%d",&a,&b,&c,&d); printf("%d\n",qu(a,b,c,d,1)); } } gets(str); } } return 0; }
bool WPUtils::deleteBlog(QString bid, QString burl) { //get current blog(s) from db QSqlQuery q(_db); q.exec("SELECT * FROM userinfo"); q.next(); QString bi = q.value(0).toString().replace(bid, ""); QString xr = q.value(4).toString().replace(burl, ""); QSqlQuery qu(_db); qu.prepare("UPDATE userinfo SET blogid=:bi and url=:u"); qu.bindValue(":bi", bi); qu.bindValue(":u", xr); bool r = qu.exec(); q.clear(); qu.clear(); return r; }
void CreateTableDialog::startAlterTable(QString tableName) { QSqlQuery qu(QString("PRAGMA TABLE_INFO (`%1`)").arg(tableName), db); columnList.clear(); ui->txtTableName->setText(tableName); ui->txtTableName->setReadOnly(true); isAlter = true; while (qu.next()) { columnList.insert(columnList.count(), qu.record().value("name").toString()); DatabaseTableField f; QSqlRecord rec = qu.record(); f.cid = rec.value("cid").toInt(); f.name = rec.value("name").toString(); f.type = rec.value("type").toString(); f.pk = rec.value("pk").toBool(); f.notnull = rec.value("notnull").toBool(); f.defval = rec.value("dflt value").toString(); if (f.pk) f.type += " PRIMARY KEY"; f_originalColumnList.insert(f_originalColumnList.count(), f); addField(f); } QString tempCreate = "CREATE TEMPORARY TABLE TEMP_TABLE("; QString tempInsert = "INSERT INTO TEMP_TABLE SELECT "; originalColumnList = ""; for (int i = 0; i < columnList.count(); ++i) { tempCreate += columnList.at(i); tempCreate += ", "; tempInsert += columnList.at(i); tempInsert += ", "; originalColumnList += columnList.at(i); originalColumnList += ", "; } tempCreate = tempCreate.remove(tempCreate.size() - 2, 2); tempInsert = tempInsert.remove(tempInsert.size() - 2, 2); originalColumnList = originalColumnList.remove(originalColumnList.size() - 2, 2); tempCreate += ");"; tempInsert += " FROM `" + tableName + "`;"; createTempString = tempCreate; insertTempString = tempInsert; }
void Test::readNodeConformityFromText(QString &str_node) { TestNode node(TYPE_NODE_CONFORMITY); QStringList str_list = str_node.split("\n"); QString real_answ = ""; QRegExp qu("^L\\d"), an("^R\\d"); QByteArray q_id, a_id; int answ_index = 0; for(int i = 0; i < str_list.count(); i++) { if(str_list.at(i).isEmpty()) continue; QStringList tmp = str_list.at(i).split(":"); if(tmp.count() < 2) continue; if(tmp.at(0) == "Q") node.setTaskTest(tmp.at(1).trimmed()); if(qu.exactMatch(tmp.at(0))) { node.addQuestion(tmp.at(1).trimmed()); q_id.append(QChar(tmp.at(0).trimmed() [1])); } if(an.exactMatch(tmp.at(0))) { node.addAnswer(tmp.at(1).trimmed()); a_id.append(QChar(tmp.at(0).trimmed() [1])); } } for(int i = 0; i < a_id.count(); i++) { answ_index = q_id.indexOf(a_id[i]); real_answ += QString().setNum(answ_index + 1); } node.setReals(real_answ); nodeList.append(node); }
/*! Populates the model with data from the table that was set via setTable(), using the specified filter and sort condition, and returns \c true if successful; otherwise returns \c false. \note Calling select() will revert any unsubmitted changes and remove any inserted columns. \sa setTable(), setFilter(), selectStatement() */ bool QSqlTableModel::select() { Q_D(QSqlTableModel); const QString query = selectStatement(); if (query.isEmpty()) return false; beginResetModel(); d->clearCache(); QSqlQuery qu(query, d->db); setQuery(qu); if (!qu.isActive() || lastError().isValid()) { // something went wrong - revert to non-select state d->initRecordAndPrimaryIndex(); endResetModel(); return false; } endResetModel(); return true; }
//参数i代表行 void qu(int i){ int iLine;//行 int iColumn;//列 int iCol;//列 for(iColumn=0;iColumn<8;iColumn++){ //如果无冲突 if(a[iColumn]==0&&b[i-iColumn+7]==0&&c[i+iColumn]==0){ Queen[i][iColumn] = '@';//放皇后 a[iColumn] = 1;//标记,下一次该列上不能放皇后 b[i-iColumn+7] = 1;//标记,下一次该主对角线不能放皇后 c[i+iColumn] = 1;//标记,下一次该从对角线不能放皇后 //如果行还没有遍历完,进入下一行 if(i<7){ qu(i+1); }else{//否则输出 //输出棋盘状态 //int iLine,iColumn; printf("the status is:%d\n",++iQueenNum); for(iLine=0;iLine<8;iLine++){ for(iCol=0;iCol<8;iCol++) printf("%c ",Queen[iLine][iCol]); printf("\n"); } printf("\n\n"); if(iQueenNum % 10 == 0){ //getch(); return; } } //如果前次的皇后放置导致后面的放置无论如何都不能满足要求,则回溯,重置 Queen[i][iColumn] = '*'; a[iColumn] = 0; b[i-iColumn+7] = 0; c[i+iColumn] = 0; } } }
void qu(int iRow) { int iColumn; for(iColumn=0;iColumn<8;iColumn++) { if(a[iColumn]==0&&b[iRow-iColumn+7]==0&&c[iRow+iColumn]==0) //如果无冲突 { Queen[iRow][iColumn]='@'; //放皇后 a[iColumn]=1; //标记,下一次该列上不能放皇后 b[iRow-iColumn+7]=1; //标记,下一次该主对角线上不能放皇后 c[iRow+iColumn]=1; //标记,下一次该从对角线上不能放皇后 if(iRow<7) qu(iRow+1); //如果行还没有遍历完,进入下一行 else //否则输出 { //输出棋盘状态 int iLine,iColumn; printf("第%d种状态为:\n",++iQueenNum); for(iLine=0;iLine<8;iLine++) { for(iColumn=0;iColumn<8;iColumn++) printf("%c ",Queen[iLine][iColumn]); printf("\n"); } printf("\n\n"); } //如果前次的皇后放置导致后面的放置无论如何都不能满足要求,则回溯,重置 Queen[iRow][iColumn]='*'; a[iColumn]=0; b[iRow-iColumn+7]=0; c[iRow+iColumn]=0; } } }
tahoe_ioconf() { register struct device *dp, *mp, *np; register int vba_n, slave; FILE *fp; fp = fopen(path("ioconf.c"), "w"); if (fp == 0) { perror(path("ioconf.c")); exit(1); } fprintf(fp, "#include \"sys/param.h\"\n"); fprintf(fp, "#include \"tahoe/include/pte.h\"\n"); fprintf(fp, "#include \"sys/buf.h\"\n"); fprintf(fp, "#include \"sys/map.h\"\n"); fprintf(fp, "\n"); fprintf(fp, "#include \"tahoe/vba/vbavar.h\"\n"); fprintf(fp, "\n"); fprintf(fp, "#define C (caddr_t)\n\n"); /* * Now generate interrupt vectors for the versabus */ for (dp = dtab; dp != 0; dp = dp->d_next) { mp = dp->d_conn; if (mp == 0 || mp == TO_NEXUS || !eq(mp->d_name, "vba")) continue; if (dp->d_vec != 0) { struct idlst *ip; fprintf(fp, "extern struct vba_driver %sdriver;\n", dp->d_name); fprintf(fp, "extern "); ip = dp->d_vec; for (;;) { fprintf(fp, "X%s%d()", ip->id, dp->d_unit); ip = ip->id_next; if (ip == 0) break; fprintf(fp, ", "); } fprintf(fp, ";\n"); fprintf(fp, "int\t (*%sint%d[])() = { ", dp->d_name, dp->d_unit); ip = dp->d_vec; for (;;) { fprintf(fp, "X%s%d", ip->id, dp->d_unit); ip = ip->id_next; if (ip == 0) break; fprintf(fp, ", "); } fprintf(fp, ", 0 } ;\n"); } else if (dp->d_type == DRIVER) /* devices w/o interrupts */ fprintf(fp, "extern struct vba_driver %sdriver;\n", dp->d_name); } fprintf(fp, "\nstruct vba_ctlr vbminit[] = {\n"); fprintf(fp, "/*\t driver,\tctlr,\tvbanum,\talive,\tintr,\taddr */\n"); for (dp = dtab; dp != 0; dp = dp->d_next) { mp = dp->d_conn; if (dp->d_type != CONTROLLER || mp == TO_NEXUS || mp == 0 || !eq(mp->d_name, "vba")) continue; if (dp->d_vec == 0) { printf("must specify vector for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_addr == 0) { printf("must specify csr address for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) { printf("drives need their own entries; dont "); printf("specify drive or slave for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_flags) { printf("controllers (e.g. %s%d) ", dp->d_name, dp->d_unit); printf("don't have flags, only devices do\n"); continue; } fprintf(fp, "\t{ &%sdriver,\t%d,\t%s,\t0,\t%sint%d, C 0x%x },\n", dp->d_name, dp->d_unit, qu(mp->d_unit), dp->d_name, dp->d_unit, dp->d_addr); } fprintf(fp, "\t0\n};\n"); /* versabus devices */ fprintf(fp, "\nstruct vba_device vbdinit[] = {\n"); fprintf(fp, "\t/* driver, unit, ctlr, vbanum, slave, intr, addr, dk, flags*/\n"); for (dp = dtab; dp != 0; dp = dp->d_next) { mp = dp->d_conn; if (dp->d_unit == QUES || dp->d_type != DEVICE || mp == 0 || mp == TO_NEXUS || mp->d_type == MASTER || eq(mp->d_name, "mba")) continue; np = mp->d_conn; if (np != 0 && np != TO_NEXUS && eq(np->d_name, "mba")) continue; np = 0; if (eq(mp->d_name, "vba")) { if (dp->d_vec == 0) printf( "Warning, no interrupt vector specified for device %s%d\n", dp->d_name, dp->d_unit); if (dp->d_addr == 0) { printf("must specify csr for device %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) { printf("drives/slaves can be specified "); printf("only for controllers, "); printf("not for device %s%d\n", dp->d_name, dp->d_unit); continue; } vba_n = mp->d_unit; slave = QUES; } else { if ((np = mp->d_conn) == 0) { printf("%s%d isn't connected to anything ", mp->d_name, mp->d_unit); printf(", so %s%d is unattached\n", dp->d_name, dp->d_unit); continue; } vba_n = np->d_unit; if (dp->d_drive == UNKNOWN) { printf("must specify ``drive number'' "); printf("for %s%d\n", dp->d_name, dp->d_unit); continue; } /* NOTE THAT ON THE UNIBUS ``drive'' IS STORED IN */ /* ``SLAVE'' AND WE DON'T WANT A SLAVE SPECIFIED */ if (dp->d_slave != UNKNOWN) { printf("slave numbers should be given only "); printf("for massbus tapes, not for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_vec != 0) { printf("interrupt vectors should not be "); printf("given for drive %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_addr != 0) { printf("csr addresses should be given only "); printf("on controllers, not on %s%d\n", dp->d_name, dp->d_unit); continue; } slave = dp->d_drive; } fprintf(fp, "\t{ &%sdriver, %2d, %s,", eq(mp->d_name, "vba") ? dp->d_name : mp->d_name, dp->d_unit, eq(mp->d_name, "vba") ? " -1" : qu(mp->d_unit)); fprintf(fp, " %s, %2d, %s, C 0x%-6x, %d, 0x%x },\n", qu(vba_n), slave, intv(dp), dp->d_addr, dp->d_dk, dp->d_flags); } fprintf(fp, "\t0\n};\n"); pseudo_ioconf(fp); (void) fclose(fp); }
vax_ioconf() { register struct device *dp, *mp, *np; register int uba_n, slave; FILE *fp; fp = fopen(path("ioconf.c"), "w"); if (fp == 0) { perror(path("ioconf.c")); exit(1); } fprintf(fp, "#include \"vax/include/pte.h\"\n"); fprintf(fp, "#include \"sys/param.h\"\n"); fprintf(fp, "#include \"sys/buf.h\"\n"); fprintf(fp, "#include \"sys/map.h\"\n"); fprintf(fp, "\n"); fprintf(fp, "#include \"vax/mba/mbavar.h\"\n"); fprintf(fp, "#include \"vax/uba/ubavar.h\"\n\n"); fprintf(fp, "\n"); fprintf(fp, "#define C (caddr_t)\n\n"); /* * First print the mba initialization structures */ if (seen_mba) { for (dp = dtab; dp != 0; dp = dp->d_next) { mp = dp->d_conn; if (mp == 0 || mp == TO_NEXUS || !eq(mp->d_name, "mba")) continue; fprintf(fp, "extern struct mba_driver %sdriver;\n", dp->d_name); } fprintf(fp, "\nstruct mba_device mbdinit[] = {\n"); fprintf(fp, "\t/* Device, Unit, Mba, Drive, Dk */\n"); for (dp = dtab; dp != 0; dp = dp->d_next) { mp = dp->d_conn; if (dp->d_unit == QUES || mp == 0 || mp == TO_NEXUS || !eq(mp->d_name, "mba")) continue; if (dp->d_addr) { printf("can't specify csr address on mba for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_vec != 0) { printf("can't specify vector for %s%d on mba\n", dp->d_name, dp->d_unit); continue; } if (dp->d_drive == UNKNOWN) { printf("drive not specified for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_slave != UNKNOWN) { printf("can't specify slave number for %s%d\n", dp->d_name, dp->d_unit); continue; } fprintf(fp, "\t{ &%sdriver, %d, %s,", dp->d_name, dp->d_unit, qu(mp->d_unit)); fprintf(fp, " %s, %d },\n", qu(dp->d_drive), dp->d_dk); } fprintf(fp, "\t0\n};\n\n"); /* * Print the mbsinit structure * Driver Controller Unit Slave */ fprintf(fp, "struct mba_slave mbsinit [] = {\n"); fprintf(fp, "\t/* Driver, Ctlr, Unit, Slave */\n"); for (dp = dtab; dp != 0; dp = dp->d_next) { /* * All slaves are connected to something which * is connected to the massbus. */ if ((mp = dp->d_conn) == 0 || mp == TO_NEXUS) continue; np = mp->d_conn; if (np == 0 || np == TO_NEXUS || !eq(np->d_name, "mba")) continue; fprintf(fp, "\t{ &%sdriver, %s", mp->d_name, qu(mp->d_unit)); fprintf(fp, ", %2d, %s },\n", dp->d_unit, qu(dp->d_slave)); } fprintf(fp, "\t0\n};\n\n"); } /* * Now generate interrupt vectors for the unibus */ for (dp = dtab; dp != 0; dp = dp->d_next) { if (dp->d_vec != 0) { struct idlst *ip; mp = dp->d_conn; if (mp == 0 || mp == TO_NEXUS || (!eq(mp->d_name, "uba") && !eq(mp->d_name, "bi"))) continue; fprintf(fp, "extern struct uba_driver %sdriver;\n", dp->d_name); fprintf(fp, "extern "); ip = dp->d_vec; for (;;) { fprintf(fp, "X%s%d()", ip->id, dp->d_unit); ip = ip->id_next; if (ip == 0) break; fprintf(fp, ", "); } fprintf(fp, ";\n"); fprintf(fp, "int\t (*%sint%d[])() = { ", dp->d_name, dp->d_unit); ip = dp->d_vec; for (;;) { fprintf(fp, "X%s%d", ip->id, dp->d_unit); ip = ip->id_next; if (ip == 0) break; fprintf(fp, ", "); } fprintf(fp, ", 0 } ;\n"); } } fprintf(fp, "\nstruct uba_ctlr ubminit[] = {\n"); fprintf(fp, "/*\t driver,\tctlr,\tubanum,\talive,\tintr,\taddr */\n"); for (dp = dtab; dp != 0; dp = dp->d_next) { mp = dp->d_conn; if (dp->d_type != CONTROLLER || mp == TO_NEXUS || mp == 0 || !eq(mp->d_name, "uba")) continue; if (dp->d_vec == 0) { printf("must specify vector for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_addr == 0) { printf("must specify csr address for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) { printf("drives need their own entries; dont "); printf("specify drive or slave for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_flags) { printf("controllers (e.g. %s%d) ", dp->d_name, dp->d_unit); printf("don't have flags, only devices do\n"); continue; } fprintf(fp, "\t{ &%sdriver,\t%d,\t%s,\t0,\t%sint%d, C 0%o },\n", dp->d_name, dp->d_unit, qu(mp->d_unit), dp->d_name, dp->d_unit, dp->d_addr); } fprintf(fp, "\t0\n};\n"); /* unibus devices */ fprintf(fp, "\nstruct uba_device ubdinit[] = {\n"); fprintf(fp, "\t/* driver, unit, ctlr, ubanum, slave, intr, addr, dk, flags*/\n"); for (dp = dtab; dp != 0; dp = dp->d_next) { mp = dp->d_conn; if (dp->d_unit == QUES || dp->d_type != DEVICE || mp == 0 || mp == TO_NEXUS || mp->d_type == MASTER || eq(mp->d_name, "mba")) continue; np = mp->d_conn; if (np != 0 && np != TO_NEXUS && eq(np->d_name, "mba")) continue; np = 0; if (eq(mp->d_name, "uba")) { if (dp->d_vec == 0) { printf("must specify vector for device %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_addr == 0) { printf("must specify csr for device %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_drive != UNKNOWN || dp->d_slave != UNKNOWN) { printf("drives/slaves can be specified "); printf("only for controllers, "); printf("not for device %s%d\n", dp->d_name, dp->d_unit); continue; } uba_n = mp->d_unit; slave = QUES; } else { if ((np = mp->d_conn) == 0) { printf("%s%d isn't connected to anything ", mp->d_name, mp->d_unit); printf(", so %s%d is unattached\n", dp->d_name, dp->d_unit); continue; } uba_n = np->d_unit; if (dp->d_drive == UNKNOWN) { printf("must specify ``drive number'' "); printf("for %s%d\n", dp->d_name, dp->d_unit); continue; } /* NOTE THAT ON THE UNIBUS ``drive'' IS STORED IN */ /* ``SLAVE'' AND WE DON'T WANT A SLAVE SPECIFIED */ if (dp->d_slave != UNKNOWN) { printf("slave numbers should be given only "); printf("for massbus tapes, not for %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_vec != 0) { printf("interrupt vectors should not be "); printf("given for drive %s%d\n", dp->d_name, dp->d_unit); continue; } if (dp->d_addr != 0) { printf("csr addresses should be given only "); printf("on controllers, not on %s%d\n", dp->d_name, dp->d_unit); continue; } slave = dp->d_drive; } fprintf(fp, "\t{ &%sdriver, %2d, %s,", eq(mp->d_name, "uba") ? dp->d_name : mp->d_name, dp->d_unit, eq(mp->d_name, "uba") ? " -1" : qu(mp->d_unit)); fprintf(fp, " %s, %2d, %s, C 0%-6o, %d, 0x%x },\n", qu(uba_n), slave, intv(dp), dp->d_addr, dp->d_dk, dp->d_flags); } fprintf(fp, "\t0\n};\n"); pseudo_ioconf(fp); (void) fclose(fp); }
static void CalculateMDFData(T* angles, T* axes, T* weights, T* odf, T* mdf, size_t numEntries) { SpaceGroupOps orientationOps; const int odfsize = orientationOps.getODFSize(); const int mdfsize = orientationOps.getMDFSize(); uint64_t m_Seed = QDateTime::currentMSecsSinceEpoch(); SIMPL_RANDOMNG_NEW_SEEDED(m_Seed); int mbin; float w = 0; int choose1, choose2; QuatF q1; QuatF q2; float totaldensity; float n1, n2, n3; float random1, random2, density; for (int i = 0; i < mdfsize; i++) { mdf[i] = 0.0; } int remainingcount = 10000; int aSize = static_cast<int>(numEntries); for (int i = 0; i < aSize; i++) { FOrientArrayType ax( axes[3 * i], axes[3 * i + 1], axes[3 * i + 2], angles[i]); FOrientArrayType rod(4); OrientationTransforms<FOrientArrayType, float>::ax2ro(ax, rod); rod = orientationOps.getMDFFZRod(rod); mbin = orientationOps.getMisoBin(rod); mdf[mbin] = -int((weights[i] / float(mdfsize)) * 10000.0); remainingcount = remainingcount + mdf[mbin]; } for (int i = 0; i < remainingcount; i++) { m_Seed++; SIMPL_RANDOMNG_NEW_SEEDED(m_Seed); random1 = rg.genrand_res53(); random2 = rg.genrand_res53(); choose1 = 0; choose2 = 0; totaldensity = 0; for (int j = 0; j < odfsize; j++) { density = odf[j]; float d = totaldensity; totaldensity = totaldensity + density; if(random1 >= d && random1 < totaldensity) { choose1 = static_cast<int>(j); } if(random2 >= d && random2 < totaldensity) { choose2 = static_cast<int>(j); } } FOrientArrayType eu = orientationOps.determineEulerAngles(m_Seed, choose1); FOrientArrayType qu(4); OrientationTransforms<FOrientArrayType, float>::eu2qu(eu, qu); q1 = qu.toQuaternion(); m_Seed++; eu = orientationOps.determineEulerAngles(m_Seed, choose2); OrientationTransforms<FOrientArrayType, float>::eu2qu(eu, qu); q2 = qu.toQuaternion(); w = orientationOps.getMisoQuat(q1, q2, n1, n2, n3); FOrientArrayType ax(n1, n2, n3, w); FOrientArrayType ro(4); OrientationTransforms<FOrientArrayType, float>::ax2ro(ax, ro); ro = orientationOps.getMDFFZRod(ro); mbin = orientationOps.getMisoBin(ro); if(mdf[mbin] >= 0) { mdf[mbin]++; } if(mdf[mbin] < 0) { i = i - 1; } } for (int i = 0; i < mdfsize; i++) { if(mdf[i] < 0) { mdf[i] = -mdf[i]; } mdf[i] = mdf[i] / 10000.0; } }
VOID CFairyObject::SetOrientation(const fVector3& vRotate) { Ogre::Quaternion qu(Ogre::Radian(vRotate.y), Ogre::Vector3::UNIT_Y); m_pFairyObj->setProperty(FOBJ_ORIENTATION, qu); }