Migrate some members of the Player class to smart pointers
1. Moves the mutex and mixer channel members to unique pointers 2. Moves the trackFile to a weak pointer 3. Move member initialization to the class definition This class still retains a raw *cd member, however fixing this ripples up to the array of [26] CD images, and across more code that generically deals with mount points; so this work remains to do.
This commit is contained in:
parent
2d76132a8b
commit
91cd907c4e
4 changed files with 70 additions and 76 deletions
|
@ -106,6 +106,18 @@ MixerChannel * MIXER_FindChannel(const char * name);
|
|||
/* Find the device you want to delete with findchannel "delchan gets deleted" */
|
||||
void MIXER_DelChannel(MixerChannel* delchan);
|
||||
|
||||
// A smart pointer deleter for MixerChannel objects
|
||||
// Use-case:
|
||||
// std::unique_ptr<MixerChannel, MixerChannelDeleter> myChannel;
|
||||
// myChannel.reset(MIXER_AddChannel(...));
|
||||
//
|
||||
struct MixerChannelDeleter {
|
||||
void operator()(MixerChannel *channel) {
|
||||
if (channel)
|
||||
MIXER_DelChannel(channel);
|
||||
}
|
||||
};
|
||||
|
||||
/* Object to maintain a mixerchannel; As all objects it registers itself with create
|
||||
* and removes itself when destroyed. */
|
||||
class MixerObject{
|
||||
|
|
|
@ -27,11 +27,27 @@
|
|||
#include <string.h>
|
||||
#include <string>
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#define strcasecmp(a, b) _stricmp(a, b)
|
||||
#define strncasecmp(a, b, n) _strnicmp(a, b, n)
|
||||
#endif
|
||||
|
||||
// A smart-pointer deleter for SDL-Mutex objects.
|
||||
// Use-case example:
|
||||
// std::unique_ptr<SDL_mutex, SdlMutexDeleter> myMutex;
|
||||
// myMutex.reset(SDL_CreateMutex());
|
||||
//
|
||||
struct SdlMutexDeleter {
|
||||
void operator()(SDL_mutex* mutex) {
|
||||
if (mutex)
|
||||
SDL_DestroyMutex(mutex);
|
||||
}
|
||||
};
|
||||
|
||||
// Returns the filename with the prior path stripped.
|
||||
// Works with both \ and / directory delimeters.
|
||||
std::string get_basename(const std::string& filename);
|
||||
|
||||
// Include a message in assert, similar to static_assert:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue