use auto_ptr instead

This commit is contained in:
ehofman 2009-10-19 14:09:21 +00:00 committed by Tim Moore
parent 31dd77c694
commit b3e16ce8e0
3 changed files with 15 additions and 12 deletions

View File

@ -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<unsigned char>& 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 ) {

View File

@ -35,6 +35,7 @@
#endif
#include <string>
#include <memory>
#include <simgear/compiler.h>
#include <simgear/debug/logstream.hxx>
@ -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<unsigned char>& 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<unsigned char>& 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<unsigned char> _data;
// configuration values
int _format;

View File

@ -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<unsigned char> ptr;
ptr.reset((unsigned char *)data);
sample->set_data( ptr );
sample->set_frequency( freq );
sample->set_format( format );
sample->set_size( size );