StringData FieldRef::dottedSubstring(size_t startPart, size_t endPart) const { if (_size == 0 || startPart >= endPart || endPart > numParts()) return StringData(); if (!_replacements.empty() || _size != _cachedSize) reserialize(); dassert(_replacements.empty() && _size == _cachedSize); StringData result(_dotted); // Fast-path if we want the whole thing if (startPart == 0 && endPart == numParts()) return result; size_t startChar = 0; for (size_t i = 0; i < startPart; ++i) { startChar += getPart(i).size() + 1; // correct for '.' } size_t endChar = startChar; for (size_t i = startPart; i < endPart; ++i) { endChar += getPart(i).size() + 1; } // correct for last '.' if (endPart != numParts()) --endChar; return result.substr(startChar, endChar - startChar); }
/************************************************************************************************** * Hash * ***********************************************************************************************/ void Worm::calcHash(){ hash = 0; for(uint i=0; i<length; ++i){ hash ^= ((getPart(i).getPosX() | (getPart(i).getPosY() << 16)) << i); } // std::cout << hash << std::endl; }
bool Worm::operator<(const Worm& other) const{ if(hash < other.hash) return true; if(hash > other.hash) return false; for(uint i=0; i<length; ++i){ if(getPart(i) < other.getPart(i)) return true; if(other.getPart(i) < getPart(i) ) return false; } return false; }
void btGImpactMeshShapePart::processAllTrianglesRay(btTriangleCallback* callback,const btVector3& rayFrom, const btVector3& rayTo) const { lockChildShapes(); btAlignedObjectArray<int> collided; btVector3 rayDir(rayTo - rayFrom); rayDir.normalize(); m_box_set.rayQuery(rayDir, rayFrom, collided); if(collided.size()==0) { unlockChildShapes(); return; } int part = (int)getPart(); btPrimitiveTriangle triangle; int i = collided.size(); while(i--) { getPrimitiveTriangle(collided[i],triangle); callback->processTriangle(triangle.m_vertices,part,collided[i]); } unlockChildShapes(); }
void btGImpactMeshShapePart::processAllTriangles(btTriangleCallback* callback,const btVector3& aabbMin,const btVector3& aabbMax) const { lockChildShapes(); btAABB box; box.m_min = aabbMin; box.m_max = aabbMax; btAlignedObjectArray<int> collided; m_box_set.boxQuery(box,collided); if(collided.size()==0) { unlockChildShapes(); return; } int part = (int)getPart(); btPrimitiveTriangle triangle; int i = collided.size(); while(i--) { this->getPrimitiveTriangle(collided[i],triangle); callback->processTriangle(triangle.m_vertices,part,collided[i]); } unlockChildShapes(); }
bool FieldRef::equalsDottedField( const StringData& other ) const { StringData rest = other; for ( size_t i = 0; i < _size; i++ ) { StringData part = getPart( i ); if ( !rest.startsWith( part ) ) return false; if ( i == _size - 1 ) return rest.size() == part.size(); // make sure next thing is a dot if ( rest.size() == part.size() ) return false; if ( rest[part.size()] != '.' ) return false; rest = rest.substr( part.size() + 1 ); } return false; }
/** * Set \a from node as \a partname node. */ SbBool TSeparatorKit::setPart(const SbName& partname, SoNode* from ) { if( partname == "tracker" ) { SoTransform* parentTransform = static_cast< SoTransform* > ( getPart("transform", true ) ); if( !parentTransform ) return false; if( !from ) { parentTransform->translation.disconnect(); parentTransform->rotation.disconnect(); parentTransform->scaleFactor.disconnect(); parentTransform->scaleOrientation.disconnect(); parentTransform->center.disconnect(); } else { TTracker* trackerNode = static_cast< TTracker* >( from ); trackerNode->ConnectParentTranform(parentTransform); /*parentTransform->translation.connectFrom( &trackerNode->outputTranslation ); parentTransform->rotation.connectFrom( &trackerNode->outputRotation ); parentTransform->scaleFactor.connectFrom( &trackerNode->outputScaleFactor ); parentTransform->scaleOrientation.connectFrom( &trackerNode->outputScaleOrientation ); parentTransform->center.connectFrom( &trackerNode->outputCenter );*/ } } return SoSeparatorKit::setPart( partname, from ); }
void DownloadSession::addPart(const PartFile& partFile) { if (partFile.m_values == ReturnValues::good)// && partFile.m_partHash == calculatePartHash(partFile)) { if (!flushPart(partFile)) { setEnd(StatusValue::notSave); return; } } else if (partFile.m_values == ReturnValues::noPart) { unsetPart(); } else if (partFile.m_values == ReturnValues::noDistribution) { setEnd(StatusValue::notDistribution); return; } if (getPart()) { write(); } }
void RKEditorDataFrame::commonInit () { RK_TRACE (EDITOR); setPart (new RKDummyPart (this, this)); getPart ()->insertChildClient (this); initializeActivationSignals (); open_chain = RKGlobals::rInterface ()->startChain (0); }
/** * Returns the "offset:" value of a PluralFormat argument, or 0 if none is specified. * @param pluralStart the index of the first PluralFormat argument style part. (0..countParts()-1) * @return the "offset:" value. * @draft ICU 4.8 */ double MessagePattern::getPluralOffset(int32_t pluralStart) const { const Part &part=getPart(pluralStart); if(Part::hasNumericValue(part.type)) { return getNumericValue(part); } else { return 0; } }
int FieldRef::compare(const FieldRef& other) const { const size_t toCompare = std::min(_size, other._size); for (size_t i = 0; i < toCompare; i++) { if (getPart(i) == other.getPart(i)) { continue; } return getPart(i) < other.getPart(i) ? -1 : 1; } const size_t rest = _size - toCompare; const size_t otherRest = other._size - toCompare; if ((rest == 0) && (otherRest == 0)) { return 0; } else if (rest < otherRest) { return -1; } else { return 1; } }
void FormGame::updateSkill_3Cooldown(int percent) { if(percent <= 0) _ui->_l_foreground_skill_3->setPixmap(_tank->getSkill(3)->isReadyToExecute() ? QPixmap() : _skill_locked); else _ui->_l_foreground_skill_3->setPixmap(_skills_cooldown.at(getPart(_skills_cooldown.size(),percent))); if(_tank->getSkill(3)->isActive() && !_tank->getSkill(3)->inCooldown()) _ui->_l_foreground_skill_3->setPixmap(_tank->getSkill(3)->getManaCost() <= _tank->currentMana() ? QPixmap() : _skill_locked); }
/* * Checks if shooting is allowed and starts animation if so */ bool Player::shoot(){ if(m_LaserStatus > 0) return false; getPart("gun")->playAnimation("gunRotation",3); m_LaserStatus = m_LaserCooldown; return true; }
void QgsMapToolViewshed::adjustRadius( double newRadius ) { QGis::UnitType measureUnit = QGis::Meters; QGis::UnitType targetUnit = canvas()->mapSettings().destinationCrs().mapUnits(); QgsDistanceArea().convertMeasurement( newRadius, measureUnit, targetUnit, false ); double radius, startAngle, stopAngle; QgsPoint center; getPart( 0, center, radius, startAngle, stopAngle ); setPart( 0, center, newRadius, startAngle, stopAngle ); update(); }
void FieldRef::reserialize() const { std::string nextDotted; // Reserve some space in the string. We know we will have, at minimum, a character for // each component we are writing, and a dot for each component, less one. We don't want // to reserve more, since we don't want to forfeit the SSO if it is applicable. nextDotted.reserve((_size > 0) ? (_size * 2) - 1 : 0); // Concatenate the fields to a new string for (size_t i = 0; i != _size; ++i) { if (i > 0) nextDotted.append(1, '.'); const StringData part = getPart(i); nextDotted.append(part.rawData(), part.size()); } // Make the new string our contents _dotted.swap(nextDotted); // Before we reserialize, it's possible that _cachedSize != _size because parts were added or // removed. This reserialization process reconciles the components in our cached string // (_dotted) with the modified path. _cachedSize = _size; // Fixup the parts to refer to the new string std::string::const_iterator where = _dotted.begin(); const std::string::const_iterator end = _dotted.end(); for (size_t i = 0; i != _size; ++i) { boost::optional<StringView>& part = (i < kReserveAhead) ? _fixed[i] : _variable[getIndex(i)]; const size_t size = part ? part->len : _replacements[i].size(); // There is one case where we expect to see the "where" iterator to be at "end" here: we // are at the last part of the FieldRef and that part is the empty string. In that case, we // need to make sure we do not dereference the "where" iterator. invariant(where != end || (size == 0 && i == _size - 1)); if (!size) { part = StringView{}; } else { std::size_t offset = where - _dotted.begin(); part = StringView{offset, size}; } where += size; // skip over '.' unless we are at the end. if (where != end) { dassert(*where == '.'); ++where; } } // Drop any replacements _replacements.clear(); }
QAction* RKConsole::addProxyAction (const QString& actionName, const QString& label) { RK_TRACE (APP); RK_ASSERT (getPart ()); RK_ASSERT (view); // katepart has more than one actionCollection QList<KActionCollection*> acs = view->findChildren<KActionCollection*>(); acs.append (view->actionCollection ()); QAction* found = 0; foreach (KActionCollection* ac, acs) { found = ac->action (actionName); if (found) break; }
std::string FieldRef::dottedField() const { std::string res; if (_size == 0) { return res; } res.append(_fixed[0].rawData(), _fixed[0].size()); for (size_t i=1; i<_size; i++) { res.append(1, '.'); StringData part = getPart(i); res.append(part.rawData(), part.size()); } return res; }
/** * Download a track from SoundCloud. * * \return This method returns true if the download is successfull, false if it * fails. */ bool SoundCloud::download() { if (!initializeDownload()) return false; // parse file host and path char host[HOST_BUFFER_SIZE] = {0}; if (api_->getStringByName_P(SOUNDCLOUD_HOST_KEY, host, HOST_BUFFER_SIZE) <= 0) { return false; } char path[PATH_BUFFER_SIZE] = {0}; if (api_->getStringByName_P(SOUNDCLOUD_URL_KEY, path, PATH_BUFFER_SIZE) <= 0) { return false; } url_t url = {host, path}; // connect to file host if (!connect(host)) return false; // retrieve file size uint32_t fileSize = getLengthFromHeader(buffer_, bufferSize_, url); if (fileSize <= 1) return false; uint16_t nParts = (fileSize - 1)/bufferSize_ + 1; download_t download = {fileSize, nParts}; // create the local file if (!open(filepath_, O_CREAT | O_WRITE)) return false; // download the file piece by piece for (uint32_t i = 0; i < nParts; i++) { int nErrors = 0; while (nErrors++ < 3) { int nBytes = getPart(i, url, download); if (nBytes > 0) { // write data to SD card write(buffer_, nBytes); sync(); break; } else if (!renewDownloadUrl(url)) { sd_->remove(filepath_); close(); return false; } } } // close the file close(); return true; }
SoPath* TSceneKit::GetSoPath(SoNode * theNode ) { TSeparatorKit* sunNode = static_cast< TSeparatorKit* > (getPart( "childList[0]", false ) ); if( !sunNode ) return NULL; TSeparatorKit* rootNode = static_cast< TSeparatorKit* > ( sunNode->getPart( "childList[0]", false ) ); if( !rootNode ) return NULL; SoSearchAction* coinSearch = new SoSearchAction(); coinSearch->setNode( theNode ); coinSearch->setInterest( SoSearchAction::FIRST ); coinSearch->apply( rootNode ); SoPath* nodePath = coinSearch->getPath( ); return nodePath; }
std::string FieldRef::dottedField( size_t offset ) const { std::string res; if (_size == 0 || offset >= numParts() ) { return res; } for (size_t i=offset; i<_size; i++) { if ( i > offset ) res.append(1, '.'); StringData part = getPart(i); res.append(part.rawData(), part.size()); } return res; }
bool FieldRef::isPrefixOf( const FieldRef& other ) const { // Can't be a prefix if equal to or larger if ( other._size <= _size ) return false; for ( size_t i = 0; i < _size; i++ ) { // Get parts StringData part = getPart( i ); StringData otherPart = other.getPart( i ); // If the parts are diff, can't be a prefix if ( part != otherPart ) return false; } return true; }
UnicodeString MessagePattern::autoQuoteApostropheDeep() const { if(!needsAutoQuoting) { return msg; } UnicodeString modified(msg); // Iterate backward so that the insertion indexes do not change. int32_t count=countParts(); for(int32_t i=count; i>0;) { const Part &part=getPart(--i); if(part.getType()==UMSGPAT_PART_TYPE_INSERT_CHAR) { modified.insert(part.index, (UChar)part.value); } } return modified; }
size_t FieldRef::commonPrefixSize(const FieldRef& other) const { if (_size == 0 || other._size == 0) { return 0; } size_t maxPrefixSize = std::min(_size - 1, other._size - 1); size_t prefixSize = 0; while (prefixSize <= maxPrefixSize) { if (getPart(prefixSize) != other.getPart(prefixSize)) { break; } prefixSize++; } return prefixSize; }
// Get next part of xml/html document void SmartTranslate::getNextPart(bool test){ int tmpFrom; from = buffer.indexOf('<', to); tmpFrom = from; while (true){ to = buffer.indexOf('>', from); if (to + 3 <= buffer.length()){ if (buffer.at(to+1) == '<' || // ...><a href... buffer.at(to+2) == '<'){ // ...> <a href... | ...>=<a href... from = to + 2; } else break; } else break; } from = tmpFrom; result += buffer.mid(from, to-from+1); from = to + 1; to = buffer.indexOf('<', from); if (to == -1){ if(!test) { emit finish(); } else { emit getPacketCount(packetCount); } return; } QString tmpStr = buffer.mid(from, to-from); if(tmpStr.contains(QRegExp("^([\\W\\d\\_]|&[a-zA-Z]+;)+$"))){ result += tmpStr; getNextPart(test); } else { if(!test) emit getPart(tmpStr); else { packetCount ++; getNextPart(test); } } }
QString LHMail::getShowText(bool EMBEDDED, bool advancedLook) { QString ret; if (!EMBEDDED) { ret+= "<HTML>\n"; } if (advancedLook) { ret+= "<h3>" + LHHtmlTools::full( subject() ) + "</h3>\n"; ret+= "From: " + LHMailAddr::convToHtmlMulti(from()) + "<br>\n"; ret+= "To: " + LHMailAddr::convToHtmlMulti(to()) + "<br>\n<p>\n"; } if (isSinglePart()) { if (/* advancedLook && */header().testData("Content-Type", "text/html")) { //QMimeSourceFactory::defaultFactory()->setText( "HTML_PART", messageBody() ); //ret += "\n<br><A href=\"HTML_PART\">" + tr("HTML message") + "</A><br>\n"; ret += "\n<br><A href=\"html://"+getAddress()+"\">" + tr("HTML message") + "</A><br>\n"; } ret += LHHtmlTools::full(messageBody()); } else { //ret+="<meta http-equiv=\"content-type\" content=\"text/html; charset=" + encoding() +"\" /> \n"; uint pc = getPartCount(); for (uint i=0; i<pc; i++) { LHMailBase* mp = getPart(i); ret+= mp->getShowText (false, advancedLook); } } if (!EMBEDDED) { ret+= "</HTML>\n"; } return ret; }
// Getting the current line----------------------------------- void Save::getLine(char* line){ u16 i; char c = fgetc(file); for( i = 0; !feof(file) && c != '\n'; ++i){ if (c == '['){ getPart(); ignoreEndOfLine(); line = NULL; i = 0; break; } if (c == '#'){ ignoreEndOfLine(); line = NULL; i = 0; break; } line[i] = c; c = fgetc(file); } line[i] = '\0'; }
void OPC_RELATION_LIST(sLONG_PTR *pResult, PackagePtr pParams) { C_TEXT Param1; C_TEXT Param2; ARRAY_TEXT Param3; ARRAY_TEXT Param4; ARRAY_TEXT Param5; ARRAY_TEXT Param6; Param1.fromParamAtIndex(pParams, 1); Param2.fromParamAtIndex(pParams, 2); CUTF8String path; Param1.copyPath(&path); opcContainer *c = opcContainerOpen(_X(path.c_str()), OPC_OPEN_READ_ONLY, NULL, NULL); if (c) { Param3.setSize(1); Param4.setSize(1); Param5.setSize(1); Param6.setSize(1); opcPart part = getPart(c, Param2); traverseRelation(c, part, Param3, Param4, Param5, Param6); opcContainerClose(c, OPC_CLOSE_NOW); } Param3.toParamAtIndex(pParams, 3); Param4.toParamAtIndex(pParams, 4); Param5.toParamAtIndex(pParams, 5); Param6.toParamAtIndex(pParams, 6); }
void FieldRef::reserialize() const { std::string nextDotted; // Reserve some space in the string. We know we will have, at minimum, a character for // each component we are writing, and a dot for each component, less one. We don't want // to reserve more, since we don't want to forfeit the SSO if it is applicable. nextDotted.reserve((_size * 2) - 1); // Concatenate the fields to a new string for (size_t i = 0; i != _size; ++i) { if (i > 0) nextDotted.append(1, '.'); const StringData part = getPart(i); nextDotted.append(part.rawData(), part.size()); } // Make the new string our contents _dotted.swap(nextDotted); // Fixup the parts to refer to the new string std::string::const_iterator where = _dotted.begin(); const std::string::const_iterator end = _dotted.end(); for (size_t i = 0; i != _size; ++i) { StringData& part = (i < kReserveAhead) ? _fixed[i] : _variable[getIndex(i)]; const size_t size = part.size(); part = StringData(&*where, size); where += size; // skip over '.' unless we are at the end. if (where != end) { dassert(*where == '.'); ++where; } } // Drop any replacements _replacements.clear(); }
// Start of smart translating void SmartTranslate::startTranslating(){ to = 0; packetCount = 0; result = ""; isFinish = false; buffer = Crossplatform::clipboard(); if(buffer == ""){ emit finish(); return; } else if(!buffer.contains("<")){ emit getPart(buffer); isFinish = true; return; } // Twice parsing, count knowing part's count and normal for(int i=0; i<2; i++) { // If full HTML, for go trougth header scripts and styles if(buffer.contains("<!DOCTYPE HTML", Qt::CaseInsensitive) && buffer.indexOf("<body", 0, Qt::CaseInsensitive)) { to = buffer.indexOf("<body", 0, Qt::CaseInsensitive); result += buffer.mid(0, to); } getNextPart(i==0); // Testing parse for knowing part's count / normal parsing if(i == 0) { to = 0; result = ""; isFinish = false; } } }
RKConsole::RKConsole (QWidget *parent, bool tool_window, const char *name) : RKMDIWindow (parent, RKMDIWindow::ConsoleWindow, tool_window, name) { RK_TRACE (APP); QVBoxLayout *layout = new QVBoxLayout (this); layout->setContentsMargins (0, 0, 0, 0); // create a Kate-part as command-editor KTextEditor::Editor* editor = KTextEditor::editor("katepart"); RK_ASSERT (editor); doc = editor->createDocument (this); view = doc->createView (this); layout->addWidget (view); KTextEditor::ConfigInterface *confint = qobject_cast<KTextEditor::ConfigInterface*> (view); RK_ASSERT (view); confint->setConfigValue ("dynamic-word-wrap", false); setFocusProxy (view); setFocusPolicy (Qt::StrongFocus); /* We need to disable kactions that were plugged to the KateViewInternal in kateview.cpp. These actions include Key_Up, Key_Down, etc. */ kate_edit_actions = view->findChild<KActionCollection*> ("edit_actions"); if (!kate_edit_actions) { kate_edit_actions=view->actionCollection(); } if (kate_edit_actions) { // make sure these actions never get triggered by a shortcut QList<QKeySequence> noshort; noshort.append (QKeySequence ()); // no primary noshort.append (QKeySequence ()); // no secondary noshort.append (QKeySequence ()); // for good measure QList<QAction*> keas = kate_edit_actions->actions (); for (int i = 0; i < keas.size (); ++i) { keas[i]->setShortcuts (noshort); } } else { RK_DO (qDebug ("Could not retrieve the katepart's edit action collection"), APP, DL_ERROR); } if (view->focusProxy ()) view->focusProxy()->installEventFilter(this); view->installEventFilter(this); doc->setModified (false); hinter = new RKFunctionArgHinter (this, view); setCaption (i18n ("R Console")); console_part = new RKConsolePart (this); setPart (console_part); setMetaInfo (shortCaption (), "rkward://page/rkward_console", RKSettings::PageConsole); initializeActivationSignals (); initializeActions (getPart ()->actionCollection ()); nprefix = "> "; iprefix = "+ "; prefix = nprefix; // KDE4: a way to do this? // doc->setUndoSteps (0); clear (); RKCommandHighlighter::setHighlighting (doc, RKCommandHighlighter::RInteractiveSession); commands_history = RKSettingsModuleConsole::loadCommandHistory (); commands_history_position = commands_history.constEnd (); current_command = 0; current_command_displayed_up_to = 0; tab_key_pressed_before = false; previous_chunk_was_piped = false; // KDE4 TODO: workaround for KDE 4 pre-release versions. Hope this gets fixed before 4.0 // see http://lists.kde.org/?l=kwrite-devel&m=119721420603507&w=2 setMinimumHeight (50); }