/** Return a named parameter of a given type. Avoids allocating std::string * temporaries * @param comp :: Component to which parameter is related * @param name :: Parameter name * @param type :: An optional type string * @returns The named parameter of the given type if it exists or a NULL shared * pointer if not */ boost::shared_ptr<Parameter> ParameterMap::get(const IComponent *comp, const char *name, const char *type) const { Parameter_sptr result; if (!comp) return result; PARALLEL_CRITICAL(m_mapAccess) { auto itr = positionOf(comp, name, type); if (itr != m_map.end()) result = itr->second; } return result; }
void BoardWidget::mouseReleaseEvent( QMouseEvent* pEvent ) { if (!gettingMove && !editMode) return; mbDown = false; if (editMode) { int i; // printf("Releasing..."); for(i=0; i<Board::AllFields;i++) if (field[i] == Board::color1bright || field[i] == Board::color2bright) { //printf(" Found %d\n",i); field[i] = editColor; } for(i=0; i<Board::AllFields;i++) board.setField( i, field[i]); int vState = board.validState(); // set color1/2Count color1Count = board.getColor1Count(); color2Count = board.getColor2Count(); if (renderMode) updatePieces(); update(); emit edited(vState); return; } if (!startValid) return; int pos = positionOf( pEvent->x(), pEvent->y() ); if (isValidEnd(pos)) { startValid = false; setCursor(Qt::CrossCursor); gettingMove = false; updatePosition(true); emit moveChoosen(actMove); qDebug() << "Move" << actMove.name() << "chosen"; return; } updatePosition(true); startValid = false; setCursor(Qt::CrossCursor); QString tmp; emit updateSpy(tmp); }
/** Method for adding/replacing a parameter providing shared pointer to it. * @param comp :: A pointer to the component that this parameter is attached to * @param par :: a shared pointer to existing parameter. The ParameterMap stores * share pointer and increment ref count to it * @param pDescription :: a pointer (may be NULL) to a string, containing * parameter's * description. If provided, the contents of the string is copied to the * parameters * memory */ void ParameterMap::add(const IComponent *comp, const boost::shared_ptr<Parameter> &par, const std::string *const pDescription) { // can not add null pointer if (!par) return; if (pDescription) par->setDescription(*pDescription); PARALLEL_CRITICAL(m_mapAccess) { auto existing_par = positionOf(comp, par->name().c_str(), ""); // As this is only an add method it should really throw if it already // exists. // However, this is old behavior and many things rely on this actually be // an // add/replace-style function if (existing_par != m_map.end()) { existing_par->second = par; } else { m_map.insert(std::make_pair(comp->getComponentID(), par)); } } }
void BoardWidget::mouseMoveEvent( QMouseEvent* pEvent ) { if ((!gettingMove && !editMode) || !mbDown) return; int pos = positionOf( pEvent->x(), pEvent->y() ); if (pos == oldPos) return; oldPos = pos; if (editMode) { int f = fieldOf(pos); if (field[f] != Board::out && field[f] != editColor) { if (editColor == Board::color1) field[f] = Board::color1bright; else if (editColor == Board::color2) field[f] = Board::color2bright; else if (field[f] == Board::color1) field[f] = Board::color1bright; else if (field[f] == Board::color2) field[f] = Board::color2bright; if (renderMode) updatePieces(); update(); } return; } if (!startValid) { /* We haven't a valid move yet. Check if we are over a valid start */ startValid = isValidStart(pos, (pEvent->button() == Qt::MidButton)); qDebug() << "Start pos " << pos << " is valid: " << startValid; // actMove.print(); if (!startValid) return; startPos = oldPos = pos; showStart(actMove,1); startShown = true; QString tmp; actValue = - board.calcEvaluation(); tmp = tr("Board value: %1").arg(actValue); emit updateSpy(tmp); return; } /* restore board */ updatePosition(); startShown = false; if (isValidEnd(pos)) { // actMove.print(); board.playMove(actMove); int v = board.calcEvaluation(); board.takeBack(); QString tmp; tmp.sprintf("%+d", v-actValue); QString str = QString("%1 : %2").arg(actMove.name()).arg(tmp); emit updateSpy(str); showMove(actMove,3); setCursor(*arrow[shownDirection]); } else { QString tmp; setCursor(Qt::CrossCursor); if (pos == startPos) { showStart(actMove,1); startShown = true; tmp = tr("Board value: %1").arg(actValue); } else { if (renderMode) updatePieces(); update(); } emit updateSpy(tmp); } }
void BoardWidget::mousePressEvent( QMouseEvent* pEvent ) { int pos = positionOf( pEvent->x(), pEvent->y() ); int f = fieldOf(pos); if (pEvent->button() == Qt::RightButton) { emit rightButtonPressed(f, pEvent->globalPos()); return; } if (!gettingMove && !editMode) { return; } mbDown = true; if (editMode) { editColor = (pEvent->button() == Qt::MidButton) ? Board::color2 : Board::color1; int newColor = (pEvent->button() == Qt::MidButton) ? Board::color2bright : Board::color1bright; if (field[f] == Board::free) { field[f] = newColor; } else if (field[f] == Board::color1) { if (editColor == Board::color1) { editColor = Board::free; newColor = Board::color1bright; } field[f] = newColor; } else if (field[f] == Board::color2) { if (editColor == Board::color2) { editColor = Board::free; newColor = Board::color2bright; } field[f] = newColor; } else { editColor = Board::out; } oldPos = pos; if (renderMode) updatePieces(); update(); return; } startValid = isValidStart(pos, (pEvent->button() == Qt::MidButton)); //qDebug() << "Start pos " << pos << " is valid: " << startValid; // actMove.print(); if (!startValid) return; startPos = oldPos = pos; showStart(actMove,1); startShown = true; QString tmp; actValue = - board.calcEvaluation(); tmp = tr("Board value: %1").arg(actValue); emit updateSpy(tmp); }