}
// 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()),
_orivec(SGVec3f::zeros()),
_base_pos(SGGeod()),
_refname(random_string()),
- _data(data),
+ _data(data.release()),
_format(format),
_size(len),
_freq(freq),
// destructor
SGSoundSample::~SGSoundSample() {
- if (_data != NULL) {
- delete _data;
- _data = NULL;
- }
}
void SGSoundSample::set_orientation( const SGQuatd& ori ) {
#endif
#include <string>
+#include <memory>
#include <simgear/compiler.h>
#include <simgear/debug/logstream.hxx>
* @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 );
/**
* 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();
}
/**
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;
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 );