From: ehofman Date: Mon, 19 Oct 2009 14:09:21 +0000 (+0000) Subject: use auto_ptr instead X-Git-Url: https://git.mxchange.org/?a=commitdiff_plain;h=b3e16ce8e0941365485116dff1113b3d5d3904e9;p=simgear.git use auto_ptr instead --- diff --git a/simgear/sound/sample_openal.cxx b/simgear/sound/sample_openal.cxx index 0423f2c4..a4efd08a 100644 --- a/simgear/sound/sample_openal.cxx +++ b/simgear/sound/sample_openal.cxx @@ -116,7 +116,8 @@ SGSoundSample::SGSoundSample( const char *path, const char *file ) : } // constructor -SGSoundSample::SGSoundSample( unsigned char *data, int len, int freq, int format ) : +SGSoundSample::SGSoundSample( std::auto_ptr& data, + int len, int freq, int format ) : _absolute_pos(SGVec3d::zeros()), _relative_pos(SGVec3d::zeros()), _direction(SGVec3d::zeros()), @@ -125,7 +126,7 @@ SGSoundSample::SGSoundSample( unsigned char *data, int len, int freq, int format _orivec(SGVec3f::zeros()), _base_pos(SGGeod()), _refname(random_string()), - _data(data), + _data(data.release()), _format(format), _size(len), _freq(freq), @@ -153,10 +154,6 @@ SGSoundSample::SGSoundSample( unsigned char *data, int len, int freq, int format // destructor SGSoundSample::~SGSoundSample() { - if (_data != NULL) { - delete _data; - _data = NULL; - } } void SGSoundSample::set_orientation( const SGQuatd& ori ) { diff --git a/simgear/sound/sample_openal.hxx b/simgear/sound/sample_openal.hxx index 017cdc93..ae985eba 100644 --- a/simgear/sound/sample_openal.hxx +++ b/simgear/sound/sample_openal.hxx @@ -35,6 +35,7 @@ #endif #include +#include #include #include @@ -74,7 +75,7 @@ public: * @param freq Frequency of the provided data (bytes per second) * @param format OpenAL format id of the data */ - SGSoundSample( unsigned char *data, int len, int freq, + SGSoundSample( std::auto_ptr& data, int len, int freq, int format = AL_FORMAT_MONO8 ); /** @@ -152,19 +153,21 @@ public: * sSt the data associated with this audio sample * @param data Pointer to a memory block containg this audio sample data. */ - inline void set_data( unsigned char* data ) { _data = data; } + inline void set_data( std::auto_ptr& data ) { + _data = data; + } /** * Return the data associated with this audio sample. * @return A pointer to this sound data of this audio sample. */ - inline void* get_data() const { return _data; } + inline void* get_data() const { return _data.get(); } /** * Free the data associated with this audio sample */ void free_data() { - if (_data != NULL) { delete _data; _data = NULL; } + delete _data.release(); } /** @@ -432,7 +435,7 @@ private: SGGeod _base_pos; // base position std::string _refname; // name or file path - unsigned char *_data; + std::auto_ptr _data; // configuration values int _format; diff --git a/simgear/sound/soundmgr_openal.cxx b/simgear/sound/soundmgr_openal.cxx index e4cf60ff..eb0a76e4 100644 --- a/simgear/sound/soundmgr_openal.cxx +++ b/simgear/sound/soundmgr_openal.cxx @@ -415,7 +415,10 @@ unsigned int SGSoundMgr::request_buffer(SGSoundSample *sample) void *data; load(sample_name, &data, &format, &size, &freq); - sample->set_data( (unsigned char *)data ); + std::auto_ptr ptr; + ptr.reset((unsigned char *)data); + + sample->set_data( ptr ); sample->set_frequency( freq ); sample->set_format( format ); sample->set_size( size );