unsigned int ping_right() { unsigned int value=p_right(); #ifdef USE_SONIC_AVERAGE for(char i=0;i!=PING_AVERAGE;i++) value=(value+p_right())/2; #endif return value; }
//! <b>Requires</b>: p is a node of a tree. //! //! <b>Effects</b>: Returns true if p is the header of the tree. //! //! <b>Complexity</b>: Constant. //! //! <b>Throws</b>: Nothing. static bool is_header(const const_node_ptr & p) { node_ptr p_left (NodeTraits::get_left(p)); node_ptr p_right(NodeTraits::get_right(p)); if(!NodeTraits::get_parent(p) || //Header condition when empty tree (p_left && p_right && //Header always has leftmost and rightmost (p_left == p_right || //Header condition when only node (NodeTraits::get_parent(p_left) != p || NodeTraits::get_parent(p_right) != p )) //When tree size > 1 headers can't be leftmost's //and rightmost's parent )){ return true; } return false; }
void MediaView::paintEvent(QPaintEvent *e) { QPainter p(this); QRect r(e->rect()); QPainter::CompositionMode m = p.compositionMode(); p.setCompositionMode(QPainter::CompositionMode_Source); // main bg p.setOpacity(st::medviewLightOpacity); QRect r_bg(st::medviewNavBarWidth, 0, width() - 2 * st::medviewNavBarWidth, height()); if (r_bg.intersects(r)) p.fillRect(r_bg.intersected(r), st::black->b); // left nav bar bg if (_leftNav.intersects(r)) { if (_leftNavVisible) { float64 o = overLevel(OverLeftNav); p.setOpacity(o * st::medviewDarkOpacity + (1 - o) * st::medviewLightOpacity); p.fillRect(_leftNav.intersected(r), st::black->b); } else { p.setOpacity(st::medviewLightOpacity); p.fillRect(_leftNav.intersected(r), st::black->b); } } // right nav bar if (_rightNav.intersects(r)) { if (_rightNavVisible) { float64 o = overLevel(OverRightNav); p.setOpacity(o * st::medviewDarkOpacity + (1 - o) * st::medviewLightOpacity); p.fillRect(_rightNav.intersected(r), st::black->b); } else { p.setOpacity(st::medviewLightOpacity); p.fillRect(_rightNav.intersected(r), st::black->b); } } p.setCompositionMode(m); // header p.setOpacity(1); p.setPen(st::medviewHeaderColor->p); p.setFont(st::medviewHeaderFont->f); QRect r_header(_save.x() + _save.width(), _save.y(), _close.x() - _save.x() - _save.width(), _save.height()); if (r_header.intersects(r)) p.drawText(r_header, _header, style::al_center); // name p.setPen(nameDateColor(overLevel(OverName))); if (_over == OverName) _from->nameText.replaceFont(st::msgNameFont->underline()); if (_nameNav.intersects(r)) _from->nameText.drawElided(p, _nameNav.left(), _nameNav.top(), _nameNav.width()); if (_over == OverName) _from->nameText.replaceFont(st::msgNameFont); // date p.setPen(nameDateColor(overLevel(OverDate))); p.setFont((_over == OverDate ? st::medviewDateFont->underline() : st::medviewDateFont)->f); if (_dateNav.intersects(r)) p.drawText(_dateNav.left(), _dateNav.top() + st::medviewDateFont->ascent, _dateText); // left nav bar if (_leftNavVisible) { QPoint p_left((st::medviewNavBarWidth - st::medviewLeft.pxWidth()) / 2, (height() - st::medviewLeft.pxHeight()) / 2); if (QRect(p_left.x(), p_left.y(), st::medviewLeft.pxWidth(), st::medviewLeft.pxHeight()).intersects(r)) { float64 o = overLevel(OverLeftNav); p.setOpacity(o * st::medviewDarkNav + (1 - o) * st::medviewLightNav); p.drawPixmap(p_left, App::sprite(), st::medviewLeft); } } // right nav bar if (_rightNavVisible) { QPoint p_right(width() - (st::medviewNavBarWidth + st::medviewRight.pxWidth()) / 2, (height() - st::medviewRight.pxHeight()) / 2); if (QRect(p_right.x(), p_right.y(), st::medviewRight.pxWidth(), st::medviewRight.pxHeight()).intersects(r)) { float64 o = overLevel(OverRightNav); p.setOpacity(o * st::medviewDarkNav + (1 - o) * st::medviewLightNav); p.drawPixmap(p_right, App::sprite(), st::medviewRight); } } // photo p.setOpacity(1); if (!_full && _photo->full->loaded()) { _current = _photo->full->pixNoCache(_w, 0, true); _full = true; } else if (_current.isNull() && _photo->thumb->loaded()) { _current = _photo->thumb->pixBlurredNoCache(_w); } if (QRect(_x, _y, _current.width() / cIntRetinaFactor(), _current.height() / cIntRetinaFactor()).intersects(r)) { p.drawPixmap(_x, _y, _current); } }
TokenBase* calculator::calculate(const TokenQueue_t& rpn, TokenMap scope, const opMap_t& opMap) { evaluationData data(rpn, scope, opMap); // Evaluate the expression in RPN form. std::stack<TokenBase*> evaluation; while (!data.rpn.empty()) { TokenBase* base = data.rpn.front()->clone(); data.rpn.pop(); // Operator: if (base->type == OP) { data.op = static_cast<Token<std::string>*>(base)->val; delete base; /* * * * * Resolve operands Values and References: * * * * */ if (evaluation.size() < 2) { cleanStack(evaluation); throw std::domain_error("Invalid equation."); } TokenBase* b_right = evaluation.top(); evaluation.pop(); TokenBase* b_left = evaluation.top(); evaluation.pop(); if (b_right->type == VAR) { std::string var_name = static_cast<Token<std::string>*>(b_right)->val; delete b_right; delete resolve_reference(b_left); cleanStack(evaluation); throw std::domain_error("Unable to find the variable '" + var_name + "'."); } else { b_right = resolve_reference(b_right, &data.scope); } packToken r_left; packToken m_left; if (b_left->type & REF) { RefToken* left = static_cast<RefToken*>(b_left); r_left = left->key; m_left = left->source; b_left = resolve_reference(left, &data.scope); } else if (b_left->type == VAR) { r_left = static_cast<Token<std::string>*>(b_left)->val; } /* * * * * Resolve Asign Operation * * * * */ if (!data.op.compare("=")) { delete b_left; // If the left operand has a variable name: if (r_left->type == STR) { if (m_left->type == MAP) { TokenMap& map = m_left.asMap(); std::string& key = r_left.asString(); map[key] = packToken(b_right->clone()); } else { TokenMap* map = data.scope.findMap(r_left.asString()); if (!map || *map == TokenMap::default_global()) { // Assign on the local scope. // The user should not be able to implicitly overwrite // variables he did not declare, since it's error prone. data.scope[r_left.asString()] = packToken(b_right->clone()); } else { (*map)[r_left.asString()] = packToken(b_right->clone()); } } evaluation.push(b_right); // If the left operand has an index number: } else if (r_left->type & NUM) { if (m_left->type == LIST) { TokenList& list = m_left.asList(); size_t index = r_left.asInt(); list[index] = packToken(b_right->clone()); } else { delete b_right; cleanStack(evaluation); throw std::domain_error("Left operand of assignment is not a list!"); } evaluation.push(b_right); } else { packToken p_right(b_right->clone()); delete b_right; cleanStack(evaluation); throw undefined_operation(data.op, r_left, p_right); } } else if (b_left->type == FUNC && data.op == "()") { Function* f_left = static_cast<Function*>(b_left); if (!data.op.compare("()")) { // Collect the parameter tuple: Tuple right; if (b_right->type == TUPLE) { right = *static_cast<Tuple*>(b_right); } else { right = Tuple(b_right); } delete b_right; packToken _this; if (m_left->type != NONE) { _this = m_left; } else { _this = data.scope; } // Execute the function: packToken ret; try { ret = Function::call(_this, f_left, &right, data.scope); } catch (...) { cleanStack(evaluation); delete f_left; throw; } delete f_left; evaluation.push(ret->clone()); } else { packToken p_right(b_right->clone()); packToken p_left(b_left->clone()); delete b_right; cleanStack(evaluation); throw undefined_operation(data.op, p_left, p_right); } } else { data.opID = Operation::build_mask(b_left->type, b_right->type); packToken p_left(b_left); packToken p_right(b_right); TokenBase* result = 0; try { // Resolve the operation: result = exec_operation(p_left, p_right, &data, data.op); if (!result) { result = exec_operation(p_left, p_right, &data, ANY_OP); } } catch (...) { cleanStack(evaluation); throw; } if (result) { evaluation.push(result); } else { cleanStack(evaluation); throw undefined_operation(data.op, p_left, p_right); } } } else if (base->type == VAR) { // Variable packToken* value = NULL; std::string key = static_cast<Token<std::string>*>(base)->val; value = data.scope.find(key); if (value) { TokenBase* copy = (*value)->clone(); evaluation.push(new RefToken(key, copy)); delete base; } else { evaluation.push(base); } } else { evaluation.push(base); } } return evaluation.top(); }