// Set the number of past visuals to show. void OrkObjectDisplay::updateHistoryLength() { int new_length = history_length_property_->getInt(); // Create a new array of visual pointers, all NULL. std::vector<boost::shared_ptr<OrkObjectVisual> > new_visuals(new_length); // Copy the contents from the old array to the new. // (Number to copy is the minimum of the 2 vector lengths). size_t copy_len = (new_visuals.size() > visuals_.size()) ? visuals_.size() : new_visuals.size(); for (size_t i = 0; i < copy_len; i++) { int new_index = (messages_received_ - i) % new_visuals.size(); int old_index = (messages_received_ - i) % visuals_.size(); new_visuals[new_index] = visuals_[old_index]; } // We don't need to create any new visuals here, they are created as // needed when messages are received. // Put the new vector into the member variable version and let the // old one go out of scope. visuals_.swap(new_visuals); }
// Set the number of past visuals to show. void AmbientSoundDisplay::setHistoryLength( int length )/*{{{*/ { // Don't let people enter invalid values. if( length < 1 ) { length = 1; } // If the length is not changing, we don't need to do anything. if( history_length_ == length ) { return; } // Set the actual variable. history_length_ = length; propertyChanged( history_length_property_ ); // Create a new array of visual pointers, all NULL. std::vector<AmbientSoundVisual*> new_visuals( history_length_, (AmbientSoundVisual*)0 ); // Copy the contents from the old array to the new. // (Number to copy is the minimum of the 2 vector lengths). size_t copy_len = (new_visuals.size() > visuals_.size()) ? visuals_.size() : new_visuals.size(); for( size_t i = 0; i < copy_len; i++ ) { int new_index = (messages_received_ - i) % new_visuals.size(); int old_index = (messages_received_ - i) % visuals_.size(); new_visuals[ new_index ] = visuals_[ old_index ]; visuals_[ old_index ] = NULL; } // Delete any remaining old visuals for( size_t i = 0; i < visuals_.size(); i++ ) { delete visuals_[ i ]; } // We don't need to create any new visuals here, they are created as // needed when messages are received. // Put the new vector into the member variable version and let the // old one go out of scope. visuals_.swap( new_visuals ); }/*}}}*/