void MinirobotsQueueClass::put(struct Item item) { if (isAppend(item)) { append(item); } else { queue[iPut] = item; if (isFull()) { iGet = iNext(iGet); } else if (isEmpty()) { iGet = iPut; } iPut = iNext(iPut); } }
/** \brief Replace all occurrences of a substring with another string. \param strFind The string that shall be replaced. \param strReplaceWith The string that should be inserted instead of strFind */ void ParserError::ReplaceSubString( string_type &strSource, const string_type &strFind, const string_type &strReplaceWith) { string_type strResult; string_type::size_type iPos(0), iNext(0); for(;;) { iNext = strSource.find(strFind, iPos); strResult.append(strSource, iPos, iNext-iPos); if( iNext==string_type::npos ) break; strResult.append(strReplaceWith); iPos = iNext + strFind.length(); } strSource.swap(strResult); }
struct Item MinirobotsQueueClass::get() { Item item = queue[iGet]; iGet = (iNext(iGet) == iPut) ? -1 : iNext(iGet); return item; }
//----------------------------------------------------------------------------- //! //----------------------------------------------------------------------------- // Tune to the next favorite channel, given that the current channel may or may not be // a favorite void tSiriusController::TuneFavorite( eDirection direction ) { if (m_pFavoriteChannels == 0) { if ( RefreshFavoriteChannels(tAudioSettings::Instance()->Favorites()) == false ) { //ShowNotice(tr("**NOTE** Still powering up, please try again.")); return; } } Assert(m_pFavoriteChannels); // Find a favorite channel which is greater than the currently playing channel if (m_pFavoriteChannels->isEmpty()) { //ShowNotice(tr("**NOTE** No favorites defined")); return; } // If just 1 and currently playing do nothing if (m_pFavoriteChannels->size() == 1 && m_ChannelId == m_pFavoriteChannels->first()) { //ShowNotice(tr("**NOTE** No more favorites")); return; } // The current channel may not be in the list of favs int iCurrentChannel = m_pFavoriteChannels->indexOf(m_ChannelId); if (iCurrentChannel >= 0) { // Current channel is in the list of favs // Tune to the one after it (forward), or before it (!forward), which may not exist tCircularIndex iNext(m_pFavoriteChannels->size(), iCurrentChannel); direction == eDirection_Up ? ++iNext : --iNext; if (m_ChannelId != m_pFavoriteChannels->at(iNext.AsInt())) // iNext may wrap { TuneChannelAbsolute(m_pFavoriteChannels->at(iNext.AsInt())); } return; } // Current channel is not in the of favs // Tune to the first channel greater than the current channel (forward), or // tune to the first channel less than the current channel (!forward) iCurrentChannel = -1; if (direction == eDirection_Up) { int listSize = m_pFavoriteChannels->size(); for (int i = 0; i < listSize; i++) { if (m_ChannelId < m_pFavoriteChannels->at(i)) { iCurrentChannel = i; break; } } } else { for (int i = m_pFavoriteChannels->size() - 1; i >= 0; i--) { if (m_ChannelId > m_pFavoriteChannels->at(i)) { iCurrentChannel = i; break; } } } if (iCurrentChannel == -1) { iCurrentChannel = direction == eDirection_Up ? 0 : m_pFavoriteChannels->size() - 1; } TuneChannelAbsolute(m_pFavoriteChannels->at(iCurrentChannel)); }