From ef1821c025fcd383ef61ddac6328de888bd41a34 Mon Sep 17 00:00:00 2001 From: Erik Hofman Date: Fri, 16 Feb 2018 16:09:26 +0100 Subject: [PATCH] Switch to C++11 --- simgear/sound/sample_group.cxx | 38 +++++--------- simgear/sound/sample_group.hxx | 2 - simgear/sound/soundmgr_aeonwave.cxx | 62 +++++++++-------------- simgear/sound/soundmgr_openal.cxx | 62 ++++++++++------------- simgear/sound/soundmgr_openal_private.hxx | 5 -- 5 files changed, 64 insertions(+), 105 deletions(-) diff --git a/simgear/sound/sample_group.cxx b/simgear/sound/sample_group.cxx index bbd38590..12bbd3ba 100644 --- a/simgear/sound/sample_group.cxx +++ b/simgear/sound/sample_group.cxx @@ -137,10 +137,8 @@ void SGSampleGroup::update( double dt ) { _changed = false; } - sample_map_iterator sample_current = _samples.begin(); - sample_map_iterator sample_end = _samples.end(); - for ( ; sample_current != sample_end; ++sample_current ) { - SGSoundSample *sample = sample_current->second; + for (auto current =_samples.begin(); current !=_samples.end(); ++current) { + SGSoundSample *sample = current->second; if ( !sample->is_valid_source() && sample->is_playing() && !sample->test_out_of_range()) { start_playing_sample(sample); @@ -156,7 +154,7 @@ void SGSampleGroup::update( double dt ) { bool SGSampleGroup::add( SGSharedPtr sound, const std::string& refname ) { - sample_map_iterator sample_it = _samples.find( refname ); + auto sample_it = _samples.find( refname ); if ( sample_it != _samples.end() ) { // sample name already exists return false; @@ -170,7 +168,7 @@ bool SGSampleGroup::add( SGSharedPtr sound, // remove a sound effect, return true if successful bool SGSampleGroup::remove( const std::string &refname ) { - sample_map_iterator sample_it = _samples.find( refname ); + auto sample_it = _samples.find( refname ); if ( sample_it == _samples.end() ) { // sample was not found return false; @@ -187,7 +185,7 @@ bool SGSampleGroup::remove( const std::string &refname ) { // return true of the specified sound exists in the sound manager system bool SGSampleGroup::exists( const std::string &refname ) { - sample_map_iterator sample_it = _samples.find( refname ); + auto sample_it = _samples.find( refname ); if ( sample_it == _samples.end() ) { // sample was not found return false; @@ -200,7 +198,7 @@ bool SGSampleGroup::exists( const std::string &refname ) { // return a pointer to the SGSoundSample if the specified sound exists // in the sound manager system, otherwise return NULL SGSoundSample *SGSampleGroup::find( const std::string &refname ) { - sample_map_iterator sample_it = _samples.find( refname ); + auto sample_it = _samples.find( refname ); if ( sample_it == _samples.end() ) { // sample was not found return NULL; @@ -214,10 +212,8 @@ void SGSampleGroup::stop () { _pause = true; - sample_map_iterator sample_current = _samples.begin(); - sample_map_iterator sample_end = _samples.end(); - for ( ; sample_current != sample_end; ++sample_current ) { - SGSoundSample *sample = sample_current->second; + for (auto current =_samples.begin(); current !=_samples.end(); ++current) { + SGSoundSample *sample = current->second; _smgr->sample_destroy( sample ); } } @@ -228,11 +224,9 @@ SGSampleGroup::suspend () { if (_active && _pause == false) { _pause = true; - sample_map_iterator sample_current = _samples.begin(); - sample_map_iterator sample_end = _samples.end(); - for ( ; sample_current != sample_end; ++sample_current ) { + for (auto current =_samples.begin(); current !=_samples.end(); ++current) { #ifdef ENABLE_SOUND - SGSoundSample *sample = sample_current->second; + SGSoundSample *sample = current->second; _smgr->sample_suspend( sample ); #endif } @@ -246,10 +240,8 @@ SGSampleGroup::resume () { if (_active && _pause == true) { #ifdef ENABLE_SOUND - sample_map_iterator sample_current = _samples.begin(); - sample_map_iterator sample_end = _samples.end(); - for ( ; sample_current != sample_end; ++sample_current ) { - SGSoundSample *sample = sample_current->second; + for (auto current =_samples.begin(); current !=_samples.end(); ++current) { + SGSoundSample *sample = current->second; _smgr->sample_resume( sample ); } testForMgrError("resume"); @@ -319,10 +311,8 @@ void SGSampleGroup::update_pos_and_orientation() { velocity = toVec3f( hlOr.backTransform(_velocity*SG_FEET_TO_METER) ); } - sample_map_iterator sample_current = _samples.begin(); - sample_map_iterator sample_end = _samples.end(); - for ( ; sample_current != sample_end; ++sample_current ) { - SGSoundSample *sample = sample_current->second; + for (auto current =_samples.begin(); current !=_samples.end(); ++current ) { + SGSoundSample *sample = current->second; sample->set_master_volume( _volume ); sample->set_orientation( _orientation ); sample->set_rotation( ec2body ); diff --git a/simgear/sound/sample_group.hxx b/simgear/sound/sample_group.hxx index 8db767ff..a40dee47 100644 --- a/simgear/sound/sample_group.hxx +++ b/simgear/sound/sample_group.hxx @@ -40,8 +40,6 @@ typedef std::map < std::string, SGSharedPtr > sample_map; -typedef sample_map::iterator sample_map_iterator; -typedef sample_map::const_iterator const_sample_map_iterator; class SGSoundMgr; diff --git a/simgear/sound/soundmgr_aeonwave.cxx b/simgear/sound/soundmgr_aeonwave.cxx index 0ba9d33b..832bb795 100644 --- a/simgear/sound/soundmgr_aeonwave.cxx +++ b/simgear/sound/soundmgr_aeonwave.cxx @@ -36,7 +36,6 @@ #include #include -#include #include #include "soundmgr.hxx" @@ -50,17 +49,10 @@ // We keep track of the emitters ourselves. typedef std::map < unsigned int, aax::Emitter > source_map; -typedef source_map::iterator source_map_iterator; -typedef source_map::const_iterator const_source_map_iterator; // The AeonWave class keeps track of the buffers, so use a reference instead. typedef std::map < unsigned int, aax::Buffer& > buffer_map; -typedef buffer_map::iterator buffer_map_iterator; -typedef buffer_map::const_iterator const_buffer_map_iterator; - typedef std::map < std::string, SGSharedPtr > sample_group_map; -typedef sample_group_map::iterator sample_group_map_iterator; -typedef sample_group_map::const_iterator const_sample_group_map_iterator; #ifndef NDEBUG # define TRY(a) if ((a) == 0) printf("%i: %s\n", __LINE__, d->_aax.strerror()) @@ -83,8 +75,7 @@ public: ~SoundManagerPrivate() { - std::vector::iterator it; - for (it = _devices.begin(); it != _devices.end(); ++it) { + for (auto it = _devices.begin(); it != _devices.end(); ++it) { free((void*)*it); } _devices.clear(); @@ -117,7 +108,7 @@ public: buffer_map _buffers; aax::Buffer nullBuffer; aax::Buffer& get_buffer(unsigned int id) { - buffer_map_iterator buffer_it = _buffers.find(id); + auto buffer_it = _buffers.find(id); if ( buffer_it != _buffers.end() ) return buffer_it->second; SG_LOG(SG_SOUND, SG_ALERT, "unknown buffer id requested."); return nullBuffer; @@ -127,7 +118,7 @@ public: source_map _sources; aax::Emitter nullEmitter; aax::Emitter& get_emitter(unsigned int id) { - source_map_iterator source_it = _sources.find(id); + auto source_it = _sources.find(id); if ( source_it != _sources.end() ) return source_it->second; SG_LOG(SG_SOUND, SG_ALERT, "unknown source id requested."); return nullEmitter; @@ -243,10 +234,9 @@ void SGSoundMgr::activate() if ( is_working() ) { _active = true; - sample_group_map_iterator sample_grp_current = d->_sample_groups.begin(); - sample_group_map_iterator sample_grp_end = d->_sample_groups.end(); - for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) { - SGSampleGroup *sgrp = sample_grp_current->second; + for ( auto current = d->_sample_groups.begin(); + current != d->_sample_groups.end(); ++current ) { + SGSampleGroup *sgrp = current->second; sgrp->activate(); } } @@ -258,10 +248,9 @@ void SGSoundMgr::stop() { #ifdef ENABLE_SOUND // first stop all sample groups - sample_group_map_iterator sample_grp_current = d->_sample_groups.begin(); - sample_group_map_iterator sample_grp_end = d->_sample_groups.end(); - for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) { - SGSampleGroup *sgrp = sample_grp_current->second; + for ( auto current = d->_sample_groups.begin(); + current != d->_sample_groups.end(); ++ current ) { + SGSampleGroup *sgrp = current->second; sgrp->stop(); } @@ -285,10 +274,9 @@ void SGSoundMgr::suspend() { #ifdef ENABLE_SOUND if (is_working()) { - sample_group_map_iterator sample_grp_current = d->_sample_groups.begin(); - sample_group_map_iterator sample_grp_end = d->_sample_groups.end(); - for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) { - SGSampleGroup *sgrp = sample_grp_current->second; + for (auto current = d->_sample_groups.begin(); + current != d->_sample_groups.end(); ++current ) { + SGSampleGroup *sgrp = current->second; sgrp->stop(); } _active = false; @@ -300,10 +288,9 @@ void SGSoundMgr::resume() { #ifdef ENABLE_SOUND if (is_working()) { - sample_group_map_iterator sample_grp_current = d->_sample_groups.begin(); - sample_group_map_iterator sample_grp_end = d->_sample_groups.end(); - for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) { - SGSampleGroup *sgrp = sample_grp_current->second; + for ( auto current = d->_sample_groups.begin(); + current != d->_sample_groups.end(); ++current ) { + SGSampleGroup *sgrp = current->second; sgrp->resume(); } _active = true; @@ -320,10 +307,9 @@ void SGSoundMgr::update( double dt ) d->update_pos_and_orientation(); } - sample_group_map_iterator sample_grp_current = d->_sample_groups.begin(); - sample_group_map_iterator sample_grp_end = d->_sample_groups.end(); - for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) { - SGSampleGroup *sgrp = sample_grp_current->second; + for ( auto current = d->_sample_groups.begin(); + current != d->_sample_groups.end(); ++current ) { + SGSampleGroup *sgrp = current->second; sgrp->update(dt); } @@ -360,7 +346,7 @@ void SGSoundMgr::update( double dt ) // add a sample group, return true if successful bool SGSoundMgr::add( SGSampleGroup *sgrp, const std::string& refname ) { - sample_group_map_iterator sample_grp_it = d->_sample_groups.find( refname ); + auto sample_grp_it = d->_sample_groups.find( refname ); if ( sample_grp_it != d->_sample_groups.end() ) { // sample group already exists return false; @@ -376,7 +362,7 @@ bool SGSoundMgr::add( SGSampleGroup *sgrp, const std::string& refname ) // remove a sound effect, return true if successful bool SGSoundMgr::remove( const std::string &refname ) { - sample_group_map_iterator sample_grp_it = d->_sample_groups.find( refname ); + auto sample_grp_it = d->_sample_groups.find( refname ); if ( sample_grp_it == d->_sample_groups.end() ) { // sample group was not found. return false; @@ -390,7 +376,7 @@ bool SGSoundMgr::remove( const std::string &refname ) // return true of the specified sound exists in the sound manager system bool SGSoundMgr::exists( const std::string &refname ) { - sample_group_map_iterator sample_grp_it = d->_sample_groups.find( refname ); + auto sample_grp_it = d->_sample_groups.find( refname ); return ( sample_grp_it != d->_sample_groups.end() ); } @@ -398,7 +384,7 @@ bool SGSoundMgr::exists( const std::string &refname ) { // return a pointer to the SGSampleGroup if the specified sound exists // in the sound manager system, otherwise return NULL SGSampleGroup *SGSoundMgr::find( const std::string &refname, bool create ) { - sample_group_map_iterator sample_grp_it = d->_sample_groups.find( refname ); + auto sample_grp_it = d->_sample_groups.find( refname ); if ( sample_grp_it == d->_sample_groups.end() ) { // sample group was not found. if (create) { @@ -432,7 +418,7 @@ unsigned int SGSoundMgr::request_source() // Free up a source id void SGSoundMgr::release_source( unsigned int source ) { - source_map_iterator source_it = d->_sources.find(source); + auto source_it = d->_sources.find(source); if ( source_it != d->_sources.end() ) { aax::Emitter& emitter = source_it->second; @@ -527,7 +513,7 @@ void SGSoundMgr::release_buffer(SGSoundSample *sample) if ( !sample->is_queue() ) { unsigned int buffer = sample->get_buffer(); - buffer_map_iterator buffer_it = d->_buffers.find(buffer); + auto buffer_it = d->_buffers.find(buffer); if ( buffer_it != d->_buffers.end() ) { sample->no_valid_buffer(); diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index f437cee2..64a706df 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -36,8 +36,6 @@ #include #include -#include - #include "soundmgr.hxx" #include "readwav.hxx" #include "soundmgr_openal_private.hxx" @@ -283,10 +281,9 @@ void SGSoundMgr::activate() if ( is_working() ) { _active = true; - sample_group_map_iterator sample_grp_current = d->_sample_groups.begin(); - sample_group_map_iterator sample_grp_end = d->_sample_groups.end(); - for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) { - SGSampleGroup *sgrp = sample_grp_current->second; + for ( auto current = d->_sample_groups.begin(); + current != d->_sample_groups.end(); ++current ) { + SGSampleGroup *sgrp = current->second; sgrp->activate(); } } @@ -298,25 +295,23 @@ void SGSoundMgr::stop() { #ifdef ENABLE_SOUND // first stop all sample groups - sample_group_map_iterator sample_grp_current = d->_sample_groups.begin(); - sample_group_map_iterator sample_grp_end = d->_sample_groups.end(); - for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) { - SGSampleGroup *sgrp = sample_grp_current->second; + for ( auto current = d->_sample_groups.begin(); + current != d->_sample_groups.end(); ++current ) { + SGSampleGroup *sgrp = current->second; sgrp->stop(); } // clear all OpenAL sources - BOOST_FOREACH(ALuint source, d->_free_sources) { + for(ALuint source : d->_free_sources) { alDeleteSources( 1 , &source ); testForError("SGSoundMgr::stop: delete sources"); } d->_free_sources.clear(); // clear any OpenAL buffers before shutting down - buffer_map_iterator buffers_current = d->_buffers.begin(); - buffer_map_iterator buffers_end = d->_buffers.end(); - for ( ; buffers_current != buffers_end; ++buffers_current ) { - refUint ref = buffers_current->second; + for ( auto current = d->_buffers.begin(); + current != d->_buffers.begin(); ++current ) { + refUint ref = current->second; ALuint buffer = ref.id; alDeleteBuffers(1, &buffer); testForError("SGSoundMgr::stop: delete buffers"); @@ -342,10 +337,9 @@ void SGSoundMgr::suspend() { #ifdef ENABLE_SOUND if (is_working()) { - sample_group_map_iterator sample_grp_current = d->_sample_groups.begin(); - sample_group_map_iterator sample_grp_end = d->_sample_groups.end(); - for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) { - SGSampleGroup *sgrp = sample_grp_current->second; + for ( auto current = d->_sample_groups.begin(); + current != d->_sample_groups.end(); ++current ) { + SGSampleGroup *sgrp = current->second; sgrp->stop(); } _active = false; @@ -357,10 +351,9 @@ void SGSoundMgr::resume() { #ifdef ENABLE_SOUND if (is_working()) { - sample_group_map_iterator sample_grp_current = d->_sample_groups.begin(); - sample_group_map_iterator sample_grp_end = d->_sample_groups.end(); - for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) { - SGSampleGroup *sgrp = sample_grp_current->second; + for ( auto current = d->_sample_groups.begin(); + current != d->_sample_groups.end(); ++current ) { + SGSampleGroup *sgrp = current->second; sgrp->resume(); } _active = true; @@ -379,10 +372,9 @@ void SGSoundMgr::update( double dt ) d->update_pos_and_orientation(); } - sample_group_map_iterator sample_grp_current = d->_sample_groups.begin(); - sample_group_map_iterator sample_grp_end = d->_sample_groups.end(); - for ( ; sample_grp_current != sample_grp_end; ++sample_grp_current ) { - SGSampleGroup *sgrp = sample_grp_current->second; + for ( auto current = d->_sample_groups.begin(); + current != d->_sample_groups.end(); ++current ) { + SGSampleGroup *sgrp = current->second; sgrp->update(dt); } @@ -420,7 +412,7 @@ if (isNaN(toVec3f(_velocity).data())) printf("NaN in listener velocity\n"); // add a sample group, return true if successful bool SGSoundMgr::add( SGSampleGroup *sgrp, const std::string& refname ) { - sample_group_map_iterator sample_grp_it = d->_sample_groups.find( refname ); + auto sample_grp_it = d->_sample_groups.find( refname ); if ( sample_grp_it != d->_sample_groups.end() ) { // sample group already exists return false; @@ -436,7 +428,7 @@ bool SGSoundMgr::add( SGSampleGroup *sgrp, const std::string& refname ) // remove a sound effect, return true if successful bool SGSoundMgr::remove( const std::string &refname ) { - sample_group_map_iterator sample_grp_it = d->_sample_groups.find( refname ); + auto sample_grp_it = d->_sample_groups.find( refname ); if ( sample_grp_it == d->_sample_groups.end() ) { // sample group was not found. return false; @@ -450,7 +442,7 @@ bool SGSoundMgr::remove( const std::string &refname ) // return true of the specified sound exists in the sound manager system bool SGSoundMgr::exists( const std::string &refname ) { - sample_group_map_iterator sample_grp_it = d->_sample_groups.find( refname ); + auto sample_grp_it = d->_sample_groups.find( refname ); return ( sample_grp_it != d->_sample_groups.end() ); } @@ -458,7 +450,7 @@ bool SGSoundMgr::exists( const std::string &refname ) { // return a pointer to the SGSampleGroup if the specified sound exists // in the sound manager system, otherwise return NULL SGSampleGroup *SGSoundMgr::find( const std::string &refname, bool create ) { - sample_group_map_iterator sample_grp_it = d->_sample_groups.find( refname ); + auto sample_grp_it = d->_sample_groups.find( refname ); if ( sample_grp_it == d->_sample_groups.end() ) { // sample group was not found. if (create) { @@ -508,9 +500,7 @@ unsigned int SGSoundMgr::request_source() // Free up a source id for further use void SGSoundMgr::release_source( unsigned int source ) { - vector::iterator it; - - it = std::find(d->_sources_in_use.begin(), d->_sources_in_use.end(), source); + auto it = std::find(d->_sources_in_use.begin(), d->_sources_in_use.end(), source); if ( it != d->_sources_in_use.end() ) { #ifdef ENABLE_SOUND ALint result; @@ -538,7 +528,7 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample) void *sample_data = NULL; // see if the sample name is already cached - buffer_map_iterator buffer_it = d->_buffers.find( sample_name ); + auto buffer_it = d->_buffers.find( sample_name ); if ( buffer_it != d->_buffers.end() ) { buffer_it->second.refctr++; buffer = buffer_it->second.id; @@ -632,7 +622,7 @@ void SGSoundMgr::release_buffer(SGSoundSample *sample) if ( !sample->is_queue() ) { std::string sample_name = sample->get_sample_name(); - buffer_map_iterator buffer_it = d->_buffers.find( sample_name ); + auto buffer_it = d->_buffers.find( sample_name ); if ( buffer_it == d->_buffers.end() ) { // buffer was not found return; diff --git a/simgear/sound/soundmgr_openal_private.hxx b/simgear/sound/soundmgr_openal_private.hxx index 70ba23af..e6407378 100644 --- a/simgear/sound/soundmgr_openal_private.hxx +++ b/simgear/sound/soundmgr_openal_private.hxx @@ -64,12 +64,7 @@ struct refUint { }; typedef std::map < std::string, refUint > buffer_map; -typedef buffer_map::iterator buffer_map_iterator; -typedef buffer_map::const_iterator const_buffer_map_iterator; - typedef std::map < std::string, SGSharedPtr > sample_group_map; -typedef sample_group_map::iterator sample_group_map_iterator; -typedef sample_group_map::const_iterator const_sample_group_map_iterator; inline bool isNaN(float *v) { return (SGMisc::isNaN(v[0]) || SGMisc::isNaN(v[1]) || SGMisc::isNaN(v[2]));