本文整理汇总了C++中revert函数的典型用法代码示例。如果您正苦于以下问题:C++ revert函数的具体用法?C++ revert怎么用?C++ revert使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了revert函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RevertBinaryTree
void RevertBinaryTree(std::unique_ptr<TreeNode<T>>& root) {
if (root != nullptr) {
root->left.swap(root->right);
revert(root->left);
revert(root->right);
}
}
示例2: play
/*
Basically the same code as minimax. It initiates the move making process.
*/
void AI::make_move(int current_player, Board* game_board) {
//Defines max and min possible scores.
int alpha = -2000;
int beta = 2000;
//The depth is initially 0. This will be incremented after every recursive call to minimax.
int depth = 0;
//Defines the best possible score so far and a default position.
int best_score;
int position = 4;
//If player is X.
if (current_player == 1) {
//We try to get a better score than alpha, so we default to alpha in the beginning.
best_score = alpha;
//We basically perform all 7 (at most) possible moves.
for (int i = 1; i < 8; ++i) {
//Only if i is a valid move.
if (valid_move(i)) {
//It plays the move i in the vector and simply recursively calls minimax to maximize (or minimize) its score and revert all moves.
play(current_player, i);
int score = minimax(best_score, beta, -current_player, game_board, depth);
if (score > best_score) {
//Score and position are stored.
best_score = score;
position = i;
}
//Move is reverted.
revert(current_player, i);
//Here we perform alpha beta pruning, which enables us to discard large sections of the Search Tree.
if (beta <= best_score) {
break;
}
}
}
}
//Same process as with 1.
else if (current_player == -1) {
best_score = beta;
for (int i = 1; i < 8; ++i) {
if (valid_move(i)) {
play(current_player, i);
int score = minimax(alpha, best_score, -current_player, game_board, depth);
if (score < best_score) {
best_score = score;
position = i;
}
revert(current_player, i);
if (best_score <= alpha) {
break;
}
}
}
}
//After determining the best position (from the best score), it makes that move.
play(current_player, position);
}
示例3: set_border_color
static void
set_border_color(char *arg)
{
int color;
color = get_color_number(arg);
if (color == -1) {
revert();
errx(1, "invalid color '%s'", arg);
}
if (ioctl(0, KDSBORDER, color) != 0) {
revert();
err(1, "ioctl(KD_SBORDER)");
}
}
示例4: KDialog
void IdleTimeDetector::informOverrun()
{
if (!_overAllIdleDetect)
return; // In the preferences the user has indicated that he do not
// want idle detection.
_timer->stop();
start = QDateTime::currentDateTime();
idlestart = start.addSecs(-60 * _maxIdle);
QString backThen = KGlobal::locale()->formatTime(idlestart.time());
// Create dialog
KDialog *dialog=new KDialog( 0 );
QWidget* wid=new QWidget(dialog);
dialog->setMainWidget( wid );
QVBoxLayout *lay1 = new QVBoxLayout(wid);
QHBoxLayout *lay2 = new QHBoxLayout();
lay1->addLayout(lay2);
QString idlemsg=QString( "Desktop has been idle since %1. What do you want to do ?" ).arg(backThen);
QLabel *label = new QLabel( idlemsg, wid );
lay2->addWidget( label );
connect( dialog , SIGNAL(cancelClicked()) , this , SLOT(revert()) );
connect( wid , SIGNAL(changed(bool)) , wid , SLOT(enabledButtonApply(bool)) );
QString explanation=i18n("Continue timing. Timing has started at %1", backThen);
QString explanationrevert=i18n("Stop timing and revert back to the time at %1.", backThen);
dialog->setButtonText(KDialog::Ok, i18n("Continue timing."));
dialog->setButtonText(KDialog::Cancel, i18n("Revert timing"));
dialog->setButtonWhatsThis(KDialog::Ok, explanation);
dialog->setButtonWhatsThis(KDialog::Cancel, explanationrevert);
// The user might be looking at another virtual desktop as where ktimetracker is running
KWindowSystem::self()->setOnDesktop( dialog->winId(), KWindowSystem::self()->currentDesktop() );
KWindowSystem::self()->demandAttention( dialog->winId() );
kDebug(5970) << "Setting WinId " << dialog->winId() << " to deskTop " << KWindowSystem::self()->currentDesktop();
dialog->show();
}
示例5: mw
View::View(Kate::MainWindow *mainWindow)
: Kate::PluginView(mainWindow)
, mw(mainWindow)
{
toolView = mainWindow->createToolView("KatecodeinfoPlugin", Kate::MainWindow::Bottom, SmallIcon("msg_info"), i18n("Codeinfo"));
QWidget* w = new QWidget(toolView);
setupUi(w);
config();
w->show();
btnConfig->setIcon(KIcon("configure"));
m_nregex = NamedRegExp();
updateCmbActions();
updateGlobal();
connect(btnFile, SIGNAL(clicked()), this, SLOT(loadFile()));
connect(btnClipboard, SIGNAL(clicked()), this, SLOT(loadClipboard()));
connect(btnRun, SIGNAL(clicked()), this, SLOT(run()));
connect(btnConfig, SIGNAL(clicked()), this, SLOT(config()));
connect(btnSave, SIGNAL(clicked()), this, SLOT(save()));
connect(btnRevert, SIGNAL(clicked()), this, SLOT(revert()));
connect(lstCodeinfo, SIGNAL(itemClicked(QTreeWidgetItem*, int)), this, SLOT(infoSelected(QTreeWidgetItem*, int)));
connect(cmbActions, SIGNAL(currentIndexChanged(const QString &)), this, SLOT(actionSelected(const QString &)));
connect(txtRegex, SIGNAL(textChanged(QString)), this, SLOT(regexChanged(QString)));
connect(txtCommand, SIGNAL(textChanged(QString)), this, SLOT(commandChanged(QString)));
actionSelected(cmbActions->currentText());
}
示例6: main
int main(int argc, char* argv) {
long long sum = 0;
int digits[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
long long num = is_qualified(digits);
if (num > 0) {
//printf("qualified number = %lld\n", num);
sum = sum + num;
}
int n = 9;
int i = n;
while (i > 0) {
int prev = i - 1;
if (digits[prev] < digits[i]) {
for (int j = n; j >= i; j--) {
if (digits[j] > digits[prev]) {
swap(&digits[j], &digits[prev]);
if (i < n) revert(digits, i, n);
i = n;
break;
}
}
num = is_qualified(digits);
if (num > 0) {
//printf("qualified number = %lld\n", num);
sum = sum + num;
}
} else {
i--;
}
}
printf("sum = %lld\n", sum);
}
示例7: revert
weighted_point eigen_feature_mapper::revert(
const eigen_wsvec_t& src) const {
weighted_point ret;
ret.weight = src.weight;
ret.data = revert(src.data);
return ret;
}
示例8: revert
void MickeyApplyDialog::on_RevertButton_pressed()
{
timer.stop();
//std::cout<<"Reverting..."<<std::endl;
emit revert();
hide();
}
示例9: JUBATUS_EXCEPTION
// return at most n nodes, if theres nodes less than n, return size is also less than n.
// find(hash) :: lock_service -> key -> [node] where hash(node0) <= hash(key) < hash(node1)
bool cht::find(const std::string& key, std::vector<std::pair<std::string,int> >& out, size_t n){
out.clear();
std::vector<std::string> hlist;
if(! get_hashlist_(key, hlist)){
throw JUBATUS_EXCEPTION(not_found(key));
}
std::string hash = make_hash(key);
std::string path = ACTOR_BASE_PATH + "/" + name_ + "/cht";
std::vector<std::string>::iterator node0 = std::lower_bound(hlist.begin(), hlist.end(), hash);
size_t idx = int(node0 - hlist.begin()) % hlist.size();
std::string loc;
for(size_t i=0; i<n; ++i){
std::string ip;
int port;
if(lock_service_->read(path + "/" + hlist[idx], loc)){
revert(loc, ip, port);
out.push_back(make_pair(ip,port));
}else{
// TODO: output log
throw JUBATUS_EXCEPTION(not_found(path));
}
idx++;
idx %= hlist.size();
}
return !hlist.size();
}
示例10: connect
void IgnoreListModel::clientConnected() {
connect(Client::ignoreListManager(), SIGNAL(updated()), SLOT(revert()));
if(Client::ignoreListManager()->isInitialized())
initDone();
else
connect(Client::ignoreListManager(), SIGNAL(initDone()), SLOT(initDone()));
}
示例11: revert
void IgnoreListModel::commit() {
if(!_configChanged)
return;
Client::ignoreListManager()->requestUpdate(_clonedIgnoreListManager.toVariantMap());
revert();
}
示例12: QObject
VideoProcessor::VideoProcessor(QObject *parent)
: QObject(parent)
, delay(-1)
, rate(0)
, fnumber(0)
, length(0)
, stop(true)
, modify(false)
, curPos(0)
, curIndex(0)
, curLevel(0)
, digits(0)
, extension(".avi")
, levels(4)
, alpha(10)
, lambda_c(80)
, fl(0.05)
, fh(0.4)
, chromAttenuation(0.1)
, delta(0)
, exaggeration_factor(2.0)
, lambda(0)
{
connect(this, SIGNAL(revert()), this, SLOT(revertVideo()));
}
示例13: tr
void GraffitiTab::renameFiles ()
{
if (!FilesModel_->GetModified ().isEmpty ())
{
auto res = QMessageBox::question (this,
"LMP Graffiti",
tr ("You have unsaved files with changed tags. Do you want to save or discard those changes?"),
QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
if (res == QMessageBox::Save)
save ();
else if (res == QMessageBox::Discard)
revert ();
else
return;
}
QList<MediaInfo> infos;
for (const auto& index : Ui_.FilesList_->selectionModel ()->selectedRows ())
infos << index.data (FilesModel::Roles::MediaInfoRole).value<MediaInfo> ();
if (infos.isEmpty ())
return;
auto dia = new RenameDialog (LMPProxy_, this);
dia->SetInfos (infos);
dia->setAttribute (Qt::WA_DeleteOnClose);
dia->show ();
}
示例14: SLOT
void GraffitiTab::SetupToolbar ()
{
Save_ = Toolbar_->addAction (tr ("Save"),
this, SLOT (save ()));
Save_->setProperty ("ActionIcon", "document-save");
Save_->setShortcut (QString ("Ctrl+S"));
Revert_ = Toolbar_->addAction (tr ("Revert"),
this, SLOT (revert ()));
Revert_->setProperty ("ActionIcon", "document-revert");
Toolbar_->addSeparator ();
RenameFiles_ = Toolbar_->addAction (tr ("Rename files"),
this, SLOT (renameFiles ()));
RenameFiles_->setProperty ("ActionIcon", "edit-rename");
Toolbar_->addSeparator ();
GetTags_ = Toolbar_->addAction (tr ("Fetch tags"),
this, SLOT (fetchTags ()));
GetTags_->setProperty ("ActionIcon", "download");
SplitCue_ = Toolbar_->addAction (tr ("Split CUE..."),
this, SLOT (splitCue ()));
SplitCue_->setProperty ("ActionIcon", "split");
SplitCue_->setEnabled (false);
}
示例15: make_hash
// find(hash) :: lock_service -> key -> [node] where hash(node0) <= hash(key) < hash(node1)
bool cht::find(const std::string& key, std::vector<std::pair<std::string,int> >& out){
out.clear();
std::string path = ACTOR_BASE_PATH + "/" + name_ + "/cht";
std::string hash = make_hash(key);
std::vector<std::pair<std::string, int> > ret;
std::vector<std::string> hlist;
lock_service_->list(path, hlist);
if(hlist.empty()) return false;
std::sort(hlist.begin(), hlist.end());
std::vector<std::string>::iterator node0 = std::lower_bound(hlist.begin(), hlist.end(), hash);
size_t idx = int(node0 - hlist.begin()) % hlist.size();
std::string loc;
for(int i=0; i<2; ++i){
std::string ip;
int port;
if(lock_service_->read(path + "/" + hlist[idx], loc)){
revert(loc, ip, port);
out.push_back(make_pair(ip,port));
}else{
// TODO: output log
}
idx++;
idx %= hlist.size();
}
return !hlist.size();
}