本文整理汇总了C++中Command类的典型用法代码示例。如果您正苦于以下问题:C++ Command类的具体用法?C++ Command怎么用?C++ Command使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Command类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: pmlist
void TreeSocket::ProcessConnectedLine(std::string& prefix, std::string& command, parameterlist& params)
{
User* who = ServerInstance->FindUUID(prefix);
std::string direction;
if (!who)
{
TreeServer* ServerSource = Utils->FindServer(prefix);
if (prefix.empty())
ServerSource = MyRoot;
if (ServerSource)
{
who = ServerSource->ServerUser;
}
else
{
/* It is important that we don't close the link here, unknown prefix can occur
* due to various race conditions such as the KILL message for a user somehow
* crossing the users QUIT further upstream from the server. Thanks jilles!
*/
if ((prefix.length() == UIDGenerator::UUID_LENGTH) && (isdigit(prefix[0])) &&
((command == "FMODE") || (command == "MODE") || (command == "KICK") || (command == "TOPIC") || (command == "KILL") || (command == "ADDLINE") || (command == "DELLINE")))
{
/* Special case, we cannot drop these commands as they've been committed already on a
* part of the network by the time we receive them, so in this scenario pretend the
* command came from a server to avoid desync.
*/
who = ServerInstance->FindUUID(prefix.substr(0, 3));
if (!who)
who = this->MyRoot->ServerUser;
}
else
{
ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Command '%s' from unknown prefix '%s'! Dropping entire command.",
command.c_str(), prefix.c_str());
return;
}
}
}
// Make sure prefix is still good
direction = who->server;
prefix = who->uuid;
/*
* Check for fake direction here, and drop any instances that are found.
* What is fake direction? Imagine the following server setup:
* 0AA <-> 0AB <-> 0AC
* Fake direction would be 0AC sending a message to 0AB claiming to be from
* 0AA, or something similar. Basically, a message taking a path that *cannot*
* be correct.
*
* When would this be seen?
* Well, hopefully never. It could be caused by race conditions, bugs, or
* "miscreant" servers, though, so let's check anyway. -- w
*
* We also check here for totally invalid prefixes (prefixes that are neither
* a valid SID or a valid UUID, so that invalid UUID or SID never makes it
* to the higher level functions. -- B
*/
TreeServer* route_back_again = Utils->BestRouteTo(direction);
if ((!route_back_again) || (route_back_again->GetSocket() != this))
{
if (route_back_again)
ServerInstance->Logs->Log(MODNAME, LOG_DEBUG, "Protocol violation: Fake direction '%s' from connection '%s'",
prefix.c_str(),linkID.c_str());
return;
}
// Translate commands coming from servers using an older protocol
if (proto_version < ProtocolVersion)
{
if (!PreProcessOldProtocolMessage(who, command, params))
return;
}
ServerCommand* scmd = Utils->Creator->CmdManager.GetHandler(command);
CommandBase* cmdbase = scmd;
Command* cmd;
if (!scmd)
{
// Not a special server-to-server command
cmd = ServerInstance->Parser->GetHandler(command);
if (!cmd)
{
irc::stringjoiner pmlist(params);
ServerInstance->Logs->Log(MODNAME, LOG_SPARSE, "Unrecognised S2S command :%s %s %s",
who->uuid.c_str(), command.c_str(), pmlist.GetJoined().c_str());
SendError("Unrecognised command '" + command + "' -- possibly loaded mismatched modules");
return;
}
cmdbase = cmd;
}
if (params.size() < cmdbase->min_params)
{
irc::stringjoiner pmlist(params);
//.........这里部分代码省略.........
示例2: FinishCommand
void CTransportCAI::UnloadLandFlood(Command& c)
{
//land, then release all units at once
CTransportUnit* transport = static_cast<CTransportUnit*>(owner);
if (inCommand) {
if (!owner->script->IsBusy()) {
FinishCommand();
}
} else {
const std::list<CTransportUnit::TransportedUnit>& transList = transport->GetTransportedUnits();
if (transList.empty()) {
FinishCommand();
return;
}
//check units are all carried
CUnit* unit = NULL;
if (c.params.size() < 4) {
unit = transList.front().unit;
} else {
const int unitID = (int)c.params[3];
std::list<CTransportUnit::TransportedUnit>::const_iterator it;
for (it = transList.begin(); it != transList.end(); ++it) {
CUnit* carried = it->unit;
if (unitID == carried->id) {
unit = carried;
break;
}
}
if (unit == NULL) {
FinishCommand();
return;
}
}
// move to position
float3 pos = c.GetPos(0);
if (isFirstIteration) {
if (goalPos.SqDistance2D(pos) > 400) {
SetGoal(startingDropPos, owner->pos);
}
}
if (startingDropPos.SqDistance2D(owner->pos) < Square(owner->unitDef->loadingRadius * 0.9f)) {
// create aircraft movetype instance
CHoverAirMoveType* am = dynamic_cast<CHoverAirMoveType*>(owner->moveType);
if (am != NULL) {
// lower to ground
startingDropPos.y = ground->GetHeightAboveWater(startingDropPos.x,startingDropPos.z);
const float3 wantedPos = startingDropPos + UpVector * unit->model->height;
SetGoal(wantedPos, owner->pos);
am->SetWantedAltitude(1);
am->maxDrift = 1;
am->dontLand = false;
// when on our way down start animations for unloading gear
if (isFirstIteration) {
owner->script->StartUnload();
}
isFirstIteration = false;
// once at ground
if (owner->pos.y - ground->GetHeightAboveWater(wantedPos.x,wantedPos.z) < 8) {
// nail it to the ground before it tries jumping up, only to land again...
am->SetState(am->AIRCRAFT_LANDED);
// call this so that other animations such as opening doors may be started
owner->script->TransportDrop(transList.front().unit, pos);
transport->DetachUnitFromAir(unit,pos);
FinishCommand();
if (transport->GetTransportedUnits().empty()) {
am->dontLand = false;
owner->script->EndTransport();
am->UpdateLanded();
}
}
} else {
// land transports
inCommand = true;
isFirstIteration = false;
StopMove();
owner->script->TransportDrop(transList.front().unit, pos);
transport->DetachUnitFromAir(unit, pos);
FinishCommand();
if (transport->GetTransportedUnits().empty()) {
owner->script->EndTransport();
}
}
}
}
}
示例3: GML_RECMUTEX_LOCK
void CSelectedUnits::GiveCommand(Command c, bool fromUser)
{
GML_RECMUTEX_LOCK(grpsel); // GiveCommand
// logOutput.Print("Command given %i",c.id);
if ((gu->spectating && !gs->godMode) || selectedUnits.empty()) {
return;
}
const int& cmd_id = c.GetID();
if (fromUser) { // add some statistics
playerHandler->Player(gu->myPlayerNum)->currentStats.numCommands++;
if (selectedGroup != -1) {
playerHandler->Player(gu->myPlayerNum)->currentStats.unitCommands += grouphandlers[gu->myTeam]->groups[selectedGroup]->units.size();
} else {
playerHandler->Player(gu->myPlayerNum)->currentStats.unitCommands += selectedUnits.size();
}
}
if (cmd_id == CMD_GROUPCLEAR) {
for (CUnitSet::iterator ui = selectedUnits.begin(); ui != selectedUnits.end(); ++ui) {
if ((*ui)->group) {
(*ui)->SetGroup(0);
possibleCommandsChanged = true;
}
}
return;
}
else if (cmd_id == CMD_GROUPSELECT) {
SelectGroup((*selectedUnits.begin())->group->id);
return;
}
else if (cmd_id == CMD_GROUPADD) {
CGroup* group = NULL;
for (CUnitSet::iterator ui = selectedUnits.begin(); ui != selectedUnits.end(); ++ui) {
if ((*ui)->group) {
group = (*ui)->group;
possibleCommandsChanged = true;
break;
}
}
if (group) {
for (CUnitSet::iterator ui = selectedUnits.begin(); ui != selectedUnits.end(); ++ui) {
if (!(*ui)->group) {
(*ui)->SetGroup(group);
}
}
SelectGroup(group->id);
}
return;
}
else if (cmd_id == CMD_TIMEWAIT) {
waitCommandsAI.AddTimeWait(c);
return;
}
else if (cmd_id == CMD_DEATHWAIT) {
waitCommandsAI.AddDeathWait(c);
return;
}
else if (cmd_id == CMD_SQUADWAIT) {
waitCommandsAI.AddSquadWait(c);
return;
}
else if (cmd_id == CMD_GATHERWAIT) {
waitCommandsAI.AddGatherWait(c);
return;
}
SendCommand(c);
#if (PLAY_SOUNDS == 1)
if (!selectedUnits.empty()) {
CUnitSet::const_iterator ui = selectedUnits.begin();
const int soundIdx = (*ui)->unitDef->sounds.ok.getRandomIdx();
if (soundIdx >= 0) {
Channels::UnitReply.PlaySample(
(*ui)->unitDef->sounds.ok.getID(soundIdx), (*ui),
(*ui)->unitDef->sounds.ok.getVolume(soundIdx));
}
}
#endif
}
示例4: switch
void CCommandAI::GiveAllowedCommand(const Command& c, bool fromSynced)
{
if (ExecuteStateCommand(c))
return;
switch (c.GetID()) {
case CMD_SELFD: {
if (owner->unitDef->canSelfD) {
if (!(c.options & SHIFT_KEY) || commandQue.empty()) {
if (owner->selfDCountdown != 0) {
owner->selfDCountdown = 0;
} else {
owner->selfDCountdown = owner->unitDef->selfDCountdown*2+1;
}
}
else if (commandQue.back().GetID() == CMD_SELFD) {
commandQue.pop_back();
} else {
commandQue.push_back(c);
}
}
return;
}
case CMD_SET_WANTED_MAX_SPEED: {
if (CanSetMaxSpeed() &&
(commandQue.empty() ||
(commandQue.back().GetID() != CMD_SET_WANTED_MAX_SPEED))) {
// bail early, do not check for overlaps or queue cancelling
commandQue.push_back(c);
if (commandQue.size()==1 && !owner->beingBuilt) {
SlowUpdate();
}
}
return;
}
case CMD_WAIT: {
GiveWaitCommand(c);
return;
}
case CMD_INSERT: {
ExecuteInsert(c, fromSynced);
return;
}
case CMD_REMOVE: {
ExecuteRemove(c);
return;
}
}
// flush the queue for immediate commands
// NOTE: CMD_STOP can be a queued order (!)
if (!(c.options & SHIFT_KEY)) {
waitCommandsAI.ClearUnitQueue(owner, commandQue);
ClearTargetLock((commandQue.empty())? Command(CMD_STOP): commandQue.front());
ClearCommandDependencies();
SetOrderTarget(NULL);
// if c is an attack command, the actual order-target
// gets set via ExecuteAttack (called from SlowUpdate
// at the end of this function)
commandQue.clear();
assert(commandQue.empty());
inCommand = false;
}
AddCommandDependency(c);
if (c.GetID() == CMD_PATROL) {
CCommandQueue::iterator ci = commandQue.begin();
for (; ci != commandQue.end() && ci->GetID() != CMD_PATROL; ++ci) {
// just increment
}
if (ci == commandQue.end()) {
if (commandQue.empty()) {
Command c2(CMD_PATROL, c.options, owner->pos);
commandQue.push_back(c2);
} else {
do {
--ci;
if (ci->params.size() >= 3) {
Command c2(CMD_PATROL, c.options);
c2.params = ci->params;
commandQue.push_back(c2);
break;
} else if (ci == commandQue.begin()) {
Command c2(CMD_PATROL, c.options, owner->pos);
commandQue.push_back(c2);
break;
}
}
while (ci != commandQue.begin());
}
}
}
// cancel duplicated commands
bool first;
if (CancelCommands(c, commandQue, first) > 0) {
if (first) {
//.........这里部分代码省略.........
示例5: HeartBeatCommand
void CoasterChannel::checkHeartbeat() {
// TODO: this can be sent after shutdown
Command* cmd = new HeartBeatCommand();
cmd->send(this, &heartbeatCB);
}
示例6: SelectCircleUnits
void CSelectedUnitsHandlerAI::SelectAttack(const Command& cmd, int player)
{
std::vector<int> targets;
if (cmd.params.size() == 4) {
SelectCircleUnits(cmd.GetPos(0), cmd.params[3], player, targets);
} else {
SelectRectangleUnits(cmd.GetPos(0), cmd.GetPos(3), player, targets);
}
if (targets.empty())
return;
const bool queueing = !!(cmd.options & SHIFT_KEY);
const std::vector<int>& selected = selectedUnitsHandler.netSelected[player];
const unsigned int targetsCount = targets.size();
const unsigned int selectedCount = selected.size();
if (selectedCount == 0)
return;
Command attackCmd(CMD_ATTACK, cmd.options, 0.0f);
// delete the attack commands and bail for CONTROL_KEY
if (cmd.options & CONTROL_KEY) {
attackCmd.options |= SHIFT_KEY;
for (unsigned int s = 0; s < selectedCount; s++) {
const CUnit* unit = unitHandler->units[ selected[s] ];
if (unit == NULL)
continue;
CCommandAI* commandAI = unitHandler->units[selected[s]]->commandAI;
for (unsigned int t = 0; t < targetsCount; t++) {
attackCmd.params[0] = targets[t];
if (commandAI->WillCancelQueued(attackCmd)) {
commandAI->GiveCommand(attackCmd, false);
}
}
}
return;
}
// get the group center
float3 midPos;
unsigned int realCount = 0;
for (unsigned int s = 0; s < selectedCount; s++) {
CUnit* unit = unitHandler->units[selected[s]];
if (unit == NULL)
continue;
if (queueing) {
midPos += LastQueuePosition(unit);
} else {
midPos += unit->midPos;
}
realCount++;
}
if (realCount == 0)
return;
midPos /= realCount;
// sort the targets
std::vector<DistInfo> distVec;
for (unsigned int t = 0; t < targetsCount; t++) {
const CUnit* unit = unitHandler->units[ targets[t] ];
const float3 unitPos = queueing ? LastQueuePosition(unit) : float3(unit->midPos);
DistInfo di;
di.unitID = targets[t];
di.dist = (unitPos - midPos).SqLength2D();
distVec.push_back(di);
}
sort(distVec.begin(), distVec.end());
// give the commands
for (unsigned int s = 0; s < selectedCount; s++) {
if (!queueing) {
// clear it for the first command
attackCmd.options &= ~SHIFT_KEY;
}
CUnit* unit = unitHandler->units[selected[s]];
if (unit == NULL)
continue;
CCommandAI* commandAI = unit->commandAI;
for (unsigned t = 0; t < targetsCount; t++) {
//.........这里部分代码省略.........
示例7: if
void CSelectedUnitsHandlerAI::GiveCommandNet(Command &c, int player)
{
const std::vector<int>& netSelected = selectedUnitsHandler.netSelected[player];
std::vector<int>::const_iterator ui;
const int nbrOfSelectedUnits = netSelected.size();
const int cmd_id = c.GetID();
if (nbrOfSelectedUnits < 1) {
// no units to command
}
else if ((cmd_id == CMD_ATTACK) && (
(c.GetParamsCount() == 6) ||
((c.GetParamsCount() == 4) && (c.GetParam(3) > 0.001f))
))
{
SelectAttack(c, player);
}
else if (nbrOfSelectedUnits == 1) {
// a single unit selected
CUnit* unit = unitHandler->units[*netSelected.begin()];
if (unit) {
unit->commandAI->GiveCommand(c, true);
if (MayRequireSetMaxSpeedCommand(c)) {
AddUnitSetMaxSpeedCommand(unit, c.options);
}
if (cmd_id == CMD_WAIT) {
if (player == gu->myPlayerNum) {
waitCommandsAI.AcknowledgeCommand(c);
}
}
}
}
// User Move Front Command:
//
// CTRL: Group Front/Speed command
//
// User Move Command:
//
// ALT: Group Front command
// ALT+CTRL: Group Front/Speed command
// CTRL: Group Locked/Speed command (maintain relative positions)
//
// User Patrol and Fight Commands:
//
// CTRL: Group Locked/Speed command (maintain relative positions)
// ALT+CTRL: Group Locked command (maintain relative positions)
//
else if (((cmd_id == CMD_MOVE) || (cmd_id == CMD_FIGHT)) && (c.GetParamsCount() == 6)) {
CalculateGroupData(player, !!(c.options & SHIFT_KEY));
MakeFrontMove(&c, player);
const bool groupSpeed = !!(c.options & CONTROL_KEY);
for(ui = netSelected.begin(); ui != netSelected.end(); ++ui) {
CUnit* unit = unitHandler->units[*ui];
if (unit) {
if (groupSpeed) {
AddGroupSetMaxSpeedCommand(unit, c.options);
} else {
AddUnitSetMaxSpeedCommand(unit, c.options);
}
}
}
}
else if ((cmd_id == CMD_MOVE) && (c.options & ALT_KEY)) {
CalculateGroupData(player, !!(c.options & SHIFT_KEY));
// use the vector from the middle of group to new pos as forward dir
const float3 pos(c.GetParam(0), c.GetParam(1), c.GetParam(2));
float3 frontdir = pos - centerCoor;
frontdir.y = 0.0f;
frontdir.ANormalize();
const float3 sideDir = frontdir.cross(UpVector);
// calculate so that the units form in an aproximate square
float length = 100.0f + (math::sqrt((float)nbrOfSelectedUnits) * 32.0f);
// push back some extra params so it confer with a front move
c.PushPos(pos + (sideDir * length));
MakeFrontMove(&c, player);
const bool groupSpeed = !!(c.options & CONTROL_KEY);
for(ui = netSelected.begin(); ui != netSelected.end(); ++ui) {
CUnit* unit = unitHandler->units[*ui];
if (unit) {
if (groupSpeed) {
AddGroupSetMaxSpeedCommand(unit, c.options);
} else {
AddUnitSetMaxSpeedCommand(unit, c.options);
}
}
}
}
else if ((c.options & CONTROL_KEY) &&
((cmd_id == CMD_MOVE) || (cmd_id == CMD_PATROL) || (cmd_id == CMD_FIGHT))) {
CalculateGroupData(player, !!(c.options & SHIFT_KEY));
//.........这里部分代码省略.........
示例8: echo
CommandResult Actions::echo(const Command &cmd)
{
return {true, cmd.argument()};
}
示例9: KeyDown
// Only override the ones you need; the default action is to return false.
bool MapOutfitterPanel::KeyDown(SDL_Keycode key, Uint16 mod, const Command &command)
{
if(command.Has(Command::MAP) || key == 'd' || key == SDLK_ESCAPE || (key == 'w' && (mod & (KMOD_CTRL | KMOD_GUI))))
GetUI()->Pop(this);
else if(key == 's')
{
GetUI()->Pop(this);
GetUI()->Push(new MapShipyardPanel(*this));
}
else if(key == 'i')
{
GetUI()->Pop(this);
GetUI()->Push(new MissionPanel(*this));
}
else if(key == 'p')
{
GetUI()->Pop(this);
GetUI()->Push(new MapDetailPanel(*this));
}
else if((key == SDLK_DOWN || key == SDLK_UP) && !zones.empty())
{
// First, find the currently selected item, if any
auto it = zones.begin();
if(!selected)
{
if(key == SDLK_DOWN)
it = --zones.end();
}
else
{
for( ; it != zones.end() - 1; ++it)
if(it->Value() == selected)
break;
}
if(key == SDLK_DOWN)
{
++it;
if(it == zones.end())
it = zones.begin();
}
else
{
if(it == zones.begin())
it = zones.end();
--it;
}
double top = (it->Center() - it->Size()).Y();
double bottom = (it->Center() + it->Size()).Y();
if(bottom > Screen::Bottom())
scroll += Screen::Bottom() - bottom;
if(top < Screen::Top())
scroll += Screen::Top() - top;
selected = it->Value();
}
else if(key == SDLK_PAGEUP || key == SDLK_PAGEDOWN)
{
scroll += (Screen::Height() - 100) * ((key == SDLK_PAGEUP) - (key == SDLK_PAGEDOWN));
scroll = min(0, max(-maxScroll, scroll));
}
else
return false;
return true;
}
示例10: while
void* ThreadPool::Process(void* arg)
{
ThreadProcess threadprocess;
Command command;
while (true)
{
pthread_mutex_lock(&command_mutex_);
// 如果线程需要退出,则此时退出
if (1 == thread_id_map_[pthread_self()])
{
pthread_mutex_unlock(&command_mutex_);
printf("thread %u will exit\n", pthread_self());
pthread_exit(NULL);
}
// 当线程不需要退出且没有需要处理的任务时,需要缩容的则缩容,不需要的则等待信号
if (0 == command_.size() && !bshutdown_)
{
if(icurr_thread_num_ > THREAD_NUM)
{
DeleteThread();
if (1 == thread_id_map_[pthread_self()])
{
pthread_mutex_unlock(&command_mutex_);
printf("thread %u will exit\n", pthread_self());
pthread_exit(NULL);
}
}
pthread_cond_wait(&command_cond_,&command_mutex_);
}
// 线程池需要关闭,关闭已有的锁,线程退出
if(bshutdown_)
{
pthread_mutex_unlock (&command_mutex_);
printf ("thread %u will exit\n", pthread_self ());
pthread_exit (NULL);
}
// 如果线程池的最大线程数不等于初始线程数,则表明需要扩容
if(icurr_thread_num_ < command_.size()))
{
AddThread();
}
// 从容器中取出待办任务
std::vector<Command>::iterator iter = command_.begin();
command.set_arg(iter->get_arg());
command.set_cmd(iter->get_cmd());
command_.erase(iter);
pthread_mutex_unlock(&command_mutex_);
// 开始业务处理
switch(command.get_cmd())
{
case 0:
threadprocess.Process0(command.get_arg());
break;
case 1:
threadprocess.Process1(command.get_arg());
break;
case 2:
threadprocess.Process2(command.get_arg());
break;
default:
break;
}
}
return NULL; // 完全为了消除警告(eclipse编写的代码,警告很烦人)
}
示例11: ks
/** Checks for an already occupied shortcut. */
void DlgCustomKeyboardImp::on_editShortcut_textChanged(const QString& sc)
{
assignedTreeWidget->clear();
QTreeWidgetItem* item = commandTreeWidget->currentItem();
if (!item)
return;
QVariant data = item->data(1, Qt::UserRole);
QByteArray name = data.toByteArray(); // command name
CommandManager & cCmdMgr = Application::Instance->commandManager();
Command* cmd = cCmdMgr.getCommandByName(name.constData());
if (cmd && !cmd->getAction()) {
buttonAssign->setEnabled(false); // command not in use
return;
}
buttonAssign->setEnabled(true);
QKeySequence ks(sc);
if (!ks.isEmpty()) {
int countAmbiguous = 0;
QString ambiguousCommand;
QString ambiguousMenu;
CommandManager & cCmdMgr = Application::Instance->commandManager();
std::vector<Command*> cmds = cCmdMgr.getAllCommands();
for (std::vector<Command*>::iterator it = cmds.begin(); it != cmds.end(); ++it) {
QList<QAction*> acts;
if ((*it)->getAction()) {
// A command may have several QAction's. So, check all of them if one of them matches (See bug #0002160)
QList<QAction*> acts = (*it)->getAction()->findChildren<QAction*>();
for (QList<QAction*>::iterator jt = acts.begin(); jt != acts.end(); ++jt) {
if ((*jt)->shortcut() == ks) {
++countAmbiguous;
ambiguousCommand = QString::fromLatin1((*it)->getName()); // store the last one
ambiguousMenu = qApp->translate((*it)->className(), (*it)->getMenuText());
QTreeWidgetItem* item = new QTreeWidgetItem(assignedTreeWidget);
item->setText(1, qApp->translate((*it)->className(), (*it)->getMenuText()));
item->setToolTip(1, qApp->translate((*it)->className(), (*it)->getToolTipText()));
item->setData(1, Qt::UserRole, QByteArray((*it)->getName()));
item->setSizeHint(0, QSize(32, 32));
if ((*it)->getPixmap())
item->setIcon(0, BitmapFactory().iconFromTheme((*it)->getPixmap()));
break;
}
}
}
}
if (countAmbiguous > 0)
assignedTreeWidget->resizeColumnToContents(0);
if (countAmbiguous > 1) {
QMessageBox::warning(this, tr("Multiple defined shortcut"),
tr("The shortcut '%1' is defined more than once. This could result into unexpected behaviour.").arg(sc) );
editShortcut->setFocus();
buttonAssign->setEnabled(false);
} else if (countAmbiguous == 1 && ambiguousCommand != QLatin1String(name)) {
QMessageBox::warning(this, tr("Already defined shortcut"),
tr("The shortcut '%1' is already assigned to '%2'.\n\nPlease define another shortcut.").arg(sc).arg(ambiguousMenu) );
editShortcut->setFocus();
buttonAssign->setEnabled(false);
} else {
if (cmd && cmd->getAction() && cmd->getAction()->shortcut() == ks)
buttonAssign->setEnabled(false);
}
} else {
if (cmd && cmd->getAction() && cmd->getAction()->shortcut().isEmpty())
buttonAssign->setEnabled(false); // both key sequences are empty
}
}
示例12: if
int ClusterCommand::execute(){
try {
if (abort == true) { if (calledHelp) { return 0; } return 2; }
//phylip file given and cutoff not given - use cluster.classic because it uses less memory and is faster
if ((format == "phylip") && (cutoff > 10.0)) {
m->mothurOutEndLine(); m->mothurOut("You are using a phylip file and no cutoff. I will run cluster.classic to save memory and time."); m->mothurOutEndLine();
//run unique.seqs for deconvolute results
string inputString = "phylip=" + distfile;
if (namefile != "") { inputString += ", name=" + namefile; }
else if (countfile != "") { inputString += ", count=" + countfile; }
inputString += ", precision=" + toString(precision);
inputString += ", method=" + method;
if (hard) { inputString += ", hard=T"; }
else { inputString += ", hard=F"; }
if (sim) { inputString += ", sim=T"; }
else { inputString += ", sim=F"; }
m->mothurOutEndLine();
m->mothurOut("/------------------------------------------------------------/"); m->mothurOutEndLine();
m->mothurOut("Running command: cluster.classic(" + inputString + ")"); m->mothurOutEndLine();
Command* clusterClassicCommand = new ClusterDoturCommand(inputString);
clusterClassicCommand->execute();
delete clusterClassicCommand;
m->mothurOut("/------------------------------------------------------------/"); m->mothurOutEndLine();
return 0;
}
ReadMatrix* read;
if (format == "column") { read = new ReadColumnMatrix(columnfile, sim); } //sim indicates whether its a similarity matrix
else if (format == "phylip") { read = new ReadPhylipMatrix(phylipfile, sim); }
read->setCutoff(cutoff);
NameAssignment* nameMap = NULL;
CountTable* ct = NULL;
map<string, int> counts;
if(namefile != ""){
nameMap = new NameAssignment(namefile);
nameMap->readMap();
read->read(nameMap);
}else if (countfile != "") {
ct = new CountTable();
ct->readTable(countfile, false, false);
read->read(ct);
counts = ct->getNameMap();
}else { read->read(nameMap); }
list = read->getListVector();
matrix = read->getDMatrix();
if(countfile != "") {
rabund = new RAbundVector();
createRabund(ct, list, rabund); //creates an rabund that includes the counts for the unique list
delete ct;
}else { rabund = new RAbundVector(list->getRAbundVector()); }
delete read;
if (m->control_pressed) { //clean up
delete list; delete matrix; delete rabund; if(countfile == ""){rabundFile.close(); sabundFile.close(); m->mothurRemove((fileroot+ tag + ".rabund")); m->mothurRemove((fileroot+ tag + ".sabund")); }
listFile.close(); m->mothurRemove((fileroot+ tag + ".list")); outputTypes.clear(); return 0;
}
//create cluster
if (method == "furthest") { cluster = new CompleteLinkage(rabund, list, matrix, cutoff, method, adjust); }
else if(method == "nearest"){ cluster = new SingleLinkage(rabund, list, matrix, cutoff, method, adjust); }
else if(method == "average"){ cluster = new AverageLinkage(rabund, list, matrix, cutoff, method, adjust); }
else if(method == "weighted"){ cluster = new WeightedLinkage(rabund, list, matrix, cutoff, method, adjust); }
tag = cluster->getTag();
if (outputDir == "") { outputDir += m->hasPath(distfile); }
fileroot = outputDir + m->getRootName(m->getSimpleName(distfile));
map<string, string> variables;
variables["[filename]"] = fileroot;
variables["[clustertag]"] = tag;
string sabundFileName = getOutputFileName("sabund", variables);
string rabundFileName = getOutputFileName("rabund", variables);
if (countfile != "") { variables["[tag2]"] = "unique_list"; }
string listFileName = getOutputFileName("list", variables);
if (countfile == "") {
m->openOutputFile(sabundFileName, sabundFile);
m->openOutputFile(rabundFileName, rabundFile);
outputNames.push_back(sabundFileName); outputTypes["sabund"].push_back(sabundFileName);
outputNames.push_back(rabundFileName); outputTypes["rabund"].push_back(rabundFileName);
}
m->openOutputFile(listFileName, listFile);
outputNames.push_back(listFileName); outputTypes["list"].push_back(listFileName);
list->printHeaders(listFile);
time_t estart = time(NULL);
float previousDist = 0.00000;
//.........这里部分代码省略.........
示例13: NNCommand2
void
NNCommand2(Connection *conn)
{
char *ptr;
char *cmd;
char *buf;
Command *scan;
int len;
conn->co_Func = NNCommand2;
conn->co_State = "waitcmd";
/*
* we have to be careful in regards to recursive operation, nor do
* we want one descriptor to hog the process. We can't set RFds
* because the next command may already be entirely loaded into an
* MBuf so setting RFds may not unblock us. Instead, we set WFds
* which basically forces a wakeup at some point in the future.
*/
if (conn->co_FCounter) {
FD_SET(conn->co_Desc->d_Fd, &WFds);
/*
* if the other side closed the connection, select() is
* not going to wake up for write(!) so set RFds too.
*/
if (conn->co_TMBuf.mh_WError)
FD_SET(conn->co_Desc->d_Fd, &RFds);
return;
}
++conn->co_FCounter;
/*
* if there is still output pending, do not process the next
* command.
*/
if (conn->co_TMBuf.mh_Bytes > 0 && !conn->co_TMBuf.mh_WError)
return;
/*
* get command
*/
if ((len = MBReadLine(&conn->co_RMBuf, &buf)) == 0) {
StatusUpdate(conn, "(idle)");
return;
}
conn->co_ByteCountType = DRBC_NONE;
/*
* check EOF
*/
if (len < 0 || conn->co_TMBuf.mh_WError) {
NNTerminate(conn);
return;
}
/*
* strip CR LF
*/
ptr = buf;
if (len > 1 && ptr[len-2] == '\r')
ptr[len-2] = 0;
if (DebugOpt)
printf("command: %s\n", ptr);
if (strncasecmp(ptr, "authinfo pass ", 14)) {
LogCmd(conn, '<', ptr);
} else {
LogCmd(conn, '<', "authinfo pass **unlogged**");
}
if (conn->co_Auth.dr_Flags & DF_USEPROXIED) {
struct sockaddr_in sin;
char *pt = NULL;
if (strncasecmp(ptr, "proxied ", 8) || ! ((pt = strrchr(ptr, ':')))) {
MBLogPrintf(conn,
&conn->co_TMBuf,
"400 %s: Proxy authentication failure.\r\n",
conn->co_Auth.dr_VServerDef->vs_HostName
);
NNTerminate(conn);
}
*pt++ = '\0';
ptr += 8;
bzero((void *)&sin, sizeof(&sin));
sin.sin_family = AF_INET;
sin.sin_port = htons(atoi(pt));
sin.sin_addr.s_addr = inet_addr(ptr);
bcopy(&sin, &conn->co_Auth.dr_Addr, sizeof(conn->co_Auth.dr_Addr));
conn->co_Auth.dr_Flags &= ~DF_USEPROXIED;
//.........这里部分代码省略.........
示例14: tokens
void CommandParser::ProcessCommand(LocalUser *user, std::string &cmd)
{
std::vector<std::string> command_p;
irc::tokenstream tokens(cmd);
std::string command, token;
tokens.GetToken(command);
/* A client sent a nick prefix on their command (ick)
* rhapsody and some braindead bouncers do this --
* the rfc says they shouldnt but also says the ircd should
* discard it if they do.
*/
if (command[0] == ':')
tokens.GetToken(command);
while (tokens.GetToken(token))
command_p.push_back(token);
std::transform(command.begin(), command.end(), command.begin(), ::toupper);
/* find the command, check it exists */
Command* handler = GetHandler(command);
/* Modify the user's penalty regardless of whether or not the command exists */
if (!user->HasPrivPermission("users/flood/no-throttle"))
{
// If it *doesn't* exist, give it a slightly heftier penalty than normal to deter flooding us crap
user->CommandFloodPenalty += handler ? handler->Penalty * 1000 : 2000;
}
if (!handler)
{
ModResult MOD_RESULT;
FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, command_p, user, false, cmd));
if (MOD_RESULT == MOD_RES_DENY)
return;
/*
* This double lookup is in case a module (abbreviation) wishes to change a command.
* Sure, the double lookup is a bit painful, but bear in mind this only happens for unknowns anyway.
*
* Thanks dz for making me actually understand why this is necessary!
* -- w00t
*/
handler = GetHandler(command);
if (!handler)
{
if (user->registered == REG_ALL)
user->WriteNumeric(ERR_UNKNOWNCOMMAND, "%s :Unknown command",command.c_str());
ServerInstance->stats->statsUnknown++;
return;
}
}
// If we were given more parameters than max_params then append the excess parameter(s)
// to command_p[maxparams-1], i.e. to the last param that is still allowed
if (handler->max_params && command_p.size() > handler->max_params)
{
/*
* command_p input (assuming max_params 1):
* this
* is
* a
* test
*/
// Iterator to the last parameter that will be kept
const std::vector<std::string>::iterator lastkeep = command_p.begin() + (handler->max_params - 1);
// Iterator to the first excess parameter
const std::vector<std::string>::iterator firstexcess = lastkeep + 1;
// Append all excess parameter(s) to the last parameter, seperated by spaces
for (std::vector<std::string>::const_iterator i = firstexcess; i != command_p.end(); ++i)
{
lastkeep->push_back(' ');
lastkeep->append(*i);
}
// Erase the excess parameter(s)
command_p.erase(firstexcess, command_p.end());
}
/*
* We call OnPreCommand here seperately if the command exists, so the magic above can
* truncate to max_params if necessary. -- w00t
*/
ModResult MOD_RESULT;
FIRST_MOD_RESULT(OnPreCommand, MOD_RESULT, (command, command_p, user, false, cmd));
if (MOD_RESULT == MOD_RES_DENY)
return;
/* activity resets the ping pending timer */
user->nping = ServerInstance->Time() + user->MyClass->GetPingTime();
if (handler->flags_needed)
{
if (!user->IsModeSet(handler->flags_needed))
{
user->WriteNumeric(ERR_NOPRIVILEGES, ":Permission Denied - You do not have the required operator privileges");
return;
//.........这里部分代码省略.........
示例15: globalContext
void OutputPaneManager::init()
{
ActionContainer *mwindow = ActionManager::actionContainer(Constants::M_WINDOW);
const Context globalContext(Constants::C_GLOBAL);
// Window->Output Panes
ActionContainer *mpanes = ActionManager::createMenu(Constants::M_WINDOW_PANES);
mwindow->addMenu(mpanes, Constants::G_WINDOW_PANES);
mpanes->menu()->setTitle(tr("Output &Panes"));
mpanes->appendGroup("Coreplugin.OutputPane.ActionsGroup");
mpanes->appendGroup("Coreplugin.OutputPane.PanesGroup");
Command *cmd;
cmd = ActionManager::registerAction(m_clearAction, "Coreplugin.OutputPane.clear", globalContext);
m_clearButton->setDefaultAction(cmd->action());
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
cmd = ActionManager::registerAction(m_prevAction, "Coreplugin.OutputPane.previtem", globalContext);
cmd->setDefaultKeySequence(QKeySequence(tr("Shift+F6")));
m_prevToolButton->setDefaultAction(cmd->action());
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
cmd = ActionManager::registerAction(m_nextAction, "Coreplugin.OutputPane.nextitem", globalContext);
m_nextToolButton->setDefaultAction(cmd->action());
cmd->setDefaultKeySequence(QKeySequence(tr("F6")));
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
cmd = ActionManager::registerAction(m_minMaxAction, "Coreplugin.OutputPane.minmax", globalContext);
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? tr("Ctrl+9") : tr("Alt+9")));
cmd->setAttribute(Command::CA_UpdateText);
cmd->setAttribute(Command::CA_UpdateIcon);
mpanes->addAction(cmd, "Coreplugin.OutputPane.ActionsGroup");
connect(m_minMaxAction, SIGNAL(triggered()), this, SLOT(slotMinMax()));
m_minMaxButton->setDefaultAction(cmd->action());
mpanes->addSeparator(globalContext, "Coreplugin.OutputPane.ActionsGroup");
QFontMetrics titleFm = m_titleLabel->fontMetrics();
int minTitleWidth = 0;
m_panes = ExtensionSystem::PluginManager::getObjects<IOutputPane>();
qSort(m_panes.begin(), m_panes.end(), &comparePanes);
const int n = m_panes.size();
int shortcutNumber = 1;
const Id baseId = Id("QtCreator.Pane.");
for (int i = 0; i != n; ++i) {
IOutputPane *outPane = m_panes.at(i);
const int idx = m_outputWidgetPane->addWidget(outPane->outputWidget(this));
QTC_CHECK(idx == i);
connect(outPane, SIGNAL(showPage(int)), this, SLOT(showPage(int)));
connect(outPane, SIGNAL(hidePage()), this, SLOT(slotHide()));
connect(outPane, SIGNAL(togglePage(int)), this, SLOT(togglePage(int)));
connect(outPane, SIGNAL(navigateStateUpdate()), this, SLOT(updateNavigateState()));
connect(outPane, SIGNAL(flashButton()), this, SLOT(flashButton()));
connect(outPane, SIGNAL(setBadgeNumber(int)), this, SLOT(setBadgeNumber(int)));
QWidget *toolButtonsContainer = new QWidget(m_opToolBarWidgets);
QHBoxLayout *toolButtonsLayout = new QHBoxLayout;
toolButtonsLayout->setMargin(0);
toolButtonsLayout->setSpacing(0);
foreach (QWidget *toolButton, outPane->toolBarWidgets())
toolButtonsLayout->addWidget(toolButton);
toolButtonsLayout->addStretch(5);
toolButtonsContainer->setLayout(toolButtonsLayout);
m_opToolBarWidgets->addWidget(toolButtonsContainer);
minTitleWidth = qMax(minTitleWidth, titleFm.width(outPane->displayName()));
QString suffix = outPane->displayName().simplified();
suffix.remove(QLatin1Char(' '));
const Id id = baseId.withSuffix(suffix);
QAction *action = new QAction(outPane->displayName(), this);
Command *cmd = ActionManager::registerAction(action, id, globalContext);
mpanes->addAction(cmd, "Coreplugin.OutputPane.PanesGroup");
m_actions.append(cmd->action());
m_ids.append(id);
cmd->setDefaultKeySequence(QKeySequence(paneShortCut(shortcutNumber)));
OutputPaneToggleButton *button = new OutputPaneToggleButton(shortcutNumber, outPane->displayName(),
cmd->action());
++shortcutNumber;
m_buttonsWidget->layout()->addWidget(button);
m_buttons.append(button);
connect(button, SIGNAL(clicked()), this, SLOT(buttonTriggered()));
bool visible = outPane->priorityInStatusBar() != -1;
button->setVisible(visible);
connect(cmd->action(), SIGNAL(triggered()), this, SLOT(shortcutTriggered()));
}
m_titleLabel->setMinimumWidth(minTitleWidth + m_titleLabel->contentsMargins().left()
+ m_titleLabel->contentsMargins().right());
m_buttonsWidget->layout()->addWidget(m_manageButton);
connect(m_manageButton, SIGNAL(clicked()), this, SLOT(popupMenu()));
//.........这里部分代码省略.........