Skip to content

Commit

Permalink
Deleted operator= and copy ctor
Browse files Browse the repository at this point in the history
  • Loading branch information
sbooth committed Feb 29, 2012
1 parent 457d493 commit 7613392
Show file tree
Hide file tree
Showing 14 changed files with 34 additions and 99 deletions.
32 changes: 0 additions & 32 deletions Decoders/AudioDecoder.cpp
Expand Up @@ -705,12 +705,6 @@ AudioDecoder::AudioDecoder(InputSource *inputSource)
memset(&mSourceFormat, 0, sizeof(mSourceFormat));
}

AudioDecoder::AudioDecoder(const AudioDecoder& rhs)
: mInputSource(nullptr), mChannelLayout(nullptr), mIsOpen(false)
{
*this = rhs;
}

AudioDecoder::~AudioDecoder()
{
if(mInputSource)
Expand All @@ -720,32 +714,6 @@ AudioDecoder::~AudioDecoder()
free(mChannelLayout),mChannelLayout = nullptr;
}

#pragma mark Operator Overloads

AudioDecoder& AudioDecoder::operator=(const AudioDecoder& rhs)
{
if(this == &rhs)
return *this;

if(mInputSource)
delete mInputSource, mInputSource = nullptr;

if(mChannelLayout)
free(mChannelLayout), mChannelLayout = nullptr;

if(rhs.mInputSource)
mInputSource = rhs.mInputSource;

mFormat = rhs.mFormat;
mSourceFormat = rhs.mSourceFormat;
mChannelLayout = CopyChannelLayout(rhs.mChannelLayout);
mIsOpen = rhs.mIsOpen;

memcpy(&mCallbacks, &rhs.mCallbacks, sizeof(rhs.mCallbacks));

return *this;
}

#pragma mark Base Functionality

CFStringRef AudioDecoder::CreateSourceFormatDescription() const
Expand Down
8 changes: 5 additions & 3 deletions Decoders/AudioDecoder.h
Expand Up @@ -113,7 +113,11 @@ class AudioDecoder
// ========================================
// Destruction
virtual ~AudioDecoder();


// This class is non-copyable
AudioDecoder(const AudioDecoder& rhs) = delete;
AudioDecoder& operator=(const AudioDecoder& rhs) = delete;

// ========================================
// The URL this decoder will process
inline CFURLRef GetURL() const { return mInputSource->GetURL(); }
Expand Down Expand Up @@ -182,8 +186,6 @@ class AudioDecoder
// For subclass use only
AudioDecoder();
AudioDecoder(InputSource *inputSource);
AudioDecoder(const AudioDecoder& rhs);
AudioDecoder& operator=(const AudioDecoder& rhs);

private:

Expand Down
8 changes: 0 additions & 8 deletions Guard.cpp
Expand Up @@ -52,14 +52,6 @@ Guard::~Guard()
LOGGER_ERR("org.sbooth.AudioEngine.Guard", "pthread_cond_destroy failed: " << strerror(success));
}

Guard::Guard(const Guard& /*guard*/)
{}

Guard& Guard::operator=(const Guard& /*guard*/)
{
return *this;
}

void Guard::Wait()
{
pthread_t currentThread = pthread_self();
Expand Down
6 changes: 3 additions & 3 deletions Guard.h
Expand Up @@ -41,6 +41,9 @@ class Guard : public Mutex
Guard();
virtual ~Guard();

Guard(const Guard& rhs) = delete;
Guard& operator=(const Guard& rhs) = delete;

// Wait() and WaitUntil() will throw std::runtime_error if the mutex isn't locked
// WaitUntil() returns true if the request timed out, false otherwise

Expand All @@ -51,9 +54,6 @@ class Guard : public Mutex
void Broadcast();

protected:
Guard(const Guard& guard);
Guard& operator=(const Guard& guard);

pthread_cond_t mCondition;

public:
Expand Down
24 changes: 0 additions & 24 deletions Input/InputSource.cpp
Expand Up @@ -87,32 +87,8 @@ InputSource::InputSource(CFURLRef url)
mURL = static_cast<CFURLRef>(CFRetain(url));
}

InputSource::InputSource(const InputSource& rhs)
: mURL(nullptr), mIsOpen(false)
{
*this = rhs;
}

InputSource::~InputSource()
{
if(mURL)
CFRelease(mURL), mURL = nullptr;
}

#pragma mark Operator Overloads

InputSource& InputSource::operator=(const InputSource& rhs)
{
if(this == &rhs)
return *this;

if(mURL)
CFRelease(mURL), mURL = nullptr;

if(rhs.mURL)
mURL = static_cast<CFURLRef>(CFRetain(rhs.mURL));

mIsOpen = rhs.mIsOpen;

return *this;
}
8 changes: 5 additions & 3 deletions Input/InputSource.h
Expand Up @@ -65,7 +65,11 @@ class InputSource
// ========================================
// Destruction
virtual ~InputSource();


// This class is non-copyable
InputSource(const InputSource& rhs) = delete;
InputSource& operator=(const InputSource& rhs) = delete;

// ========================================
// The URL this source will process
inline CFURLRef GetURL() const { return mURL; }
Expand Down Expand Up @@ -99,7 +103,5 @@ class InputSource
// For subclass use only
InputSource();
InputSource(CFURLRef url);
InputSource(const InputSource& rhs);
InputSource& operator=(const InputSource& rhs);

};
8 changes: 0 additions & 8 deletions Mutex.cpp
Expand Up @@ -53,14 +53,6 @@ Mutex::~Mutex()
LOGGER_ERR("org.sbooth.AudioEngine.Mutex", "pthread_mutex_destroy failed: " << strerror(success));
}

Mutex::Mutex(const Mutex& /*mutex*/)
{}

Mutex& Mutex::operator=(const Mutex& /*mutex*/)
{
return *this;
}

bool Mutex::Lock()
{
pthread_t currentThread = pthread_self();
Expand Down
6 changes: 3 additions & 3 deletions Mutex.h
Expand Up @@ -41,6 +41,9 @@ class Mutex
Mutex();
virtual ~Mutex();

Mutex(const Mutex& rhs) = delete;
Mutex& operator=(const Mutex& rhs) = delete;

// Lock() and Unlock() return true if the operation was successful, false otherwise
// TryLock() returns true if the lock is held by the current thread, false otherwise
// All three may throw std::runtime_exception if something bad happens
Expand All @@ -54,9 +57,6 @@ class Mutex
inline bool Owned() const { return pthread_equal(mOwner, pthread_self()); }

protected:
Mutex(const Mutex& mutex);
Mutex& operator=(const Mutex& mutex);

pthread_mutex_t mMutex;
pthread_t mOwner;

Expand Down
4 changes: 4 additions & 0 deletions Player/AudioPlayer.h
Expand Up @@ -85,6 +85,10 @@ class AudioPlayer
AudioPlayer();
~AudioPlayer();

// This class is non-copyable
AudioPlayer(const AudioPlayer& rhs) = delete;
AudioPlayer& operator=(const AudioPlayer& rhs) = delete;

// ========================================
// Playback Control
bool Play();
Expand Down
4 changes: 4 additions & 0 deletions Player/BasicAudioPlayer.h
Expand Up @@ -88,6 +88,10 @@ class BasicAudioPlayer
BasicAudioPlayer();
~BasicAudioPlayer();

// This class is non-copyable
BasicAudioPlayer(const BasicAudioPlayer& rhs) = delete;
BasicAudioPlayer& operator=(const BasicAudioPlayer& rhs) = delete;

// ========================================
// Playback Control
bool Play();
Expand Down
7 changes: 4 additions & 3 deletions Player/DecoderStateData.cpp
Expand Up @@ -38,9 +38,10 @@ DecoderStateData::DecoderStateData()
{}

DecoderStateData::DecoderStateData(AudioDecoder *decoder)
: mDecoder(decoder), mBufferList(nullptr), mBufferCapacityFrames(0), mTimeStamp(0), mFramesRendered(0), mFrameToSeek(-1), mFlags(0)
: DecoderStateData()
{
assert(nullptr != decoder);
mDecoder = decoder;

// NB: The decoder may return an estimate of the total frames
mTotalFrames = mDecoder->GetTotalFrames();
Expand All @@ -49,7 +50,7 @@ DecoderStateData::DecoderStateData(AudioDecoder *decoder)
DecoderStateData::~DecoderStateData()
{
// Delete the decoder
if(nullptr != mDecoder)
if(mDecoder)
delete mDecoder, mDecoder = nullptr;

DeallocateBufferList();
Expand All @@ -65,7 +66,7 @@ void DecoderStateData::AllocateBufferList(UInt32 capacityFrames)

void DecoderStateData::DeallocateBufferList()
{
if(nullptr != mBufferList) {
if(mBufferList) {
mBufferCapacityFrames = 0;
mBufferList = DeallocateABL(mBufferList);
}
Expand Down
3 changes: 3 additions & 0 deletions Player/DecoderStateData.h
Expand Up @@ -57,6 +57,9 @@ class DecoderStateData
DecoderStateData(AudioDecoder *decoder);
~DecoderStateData();

DecoderStateData(const DecoderStateData& rhs) = delete;
DecoderStateData& operator=(const DecoderStateData& rhs) = delete;

void AllocateBufferList(UInt32 capacityFrames);
void DeallocateBufferList();

Expand Down
8 changes: 0 additions & 8 deletions Semaphore.cpp
Expand Up @@ -52,14 +52,6 @@ Semaphore::~Semaphore()
LOGGER_ERR("org.sbooth.AudioEngine.Semaphore", "semaphore_destroy failed: " << mach_error_string(result));
}

Semaphore::Semaphore(const Semaphore& /*semaphore*/)
{}

Semaphore& Semaphore::operator=(const Semaphore& /*semaphore*/)
{
return *this;
}

bool Semaphore::Signal()
{
kern_return_t result = semaphore_signal(mSemaphore);
Expand Down
7 changes: 3 additions & 4 deletions Semaphore.h
Expand Up @@ -41,16 +41,15 @@ class Semaphore
Semaphore();
~Semaphore();

Semaphore(const Semaphore& rhs) = delete;
Semaphore& operator=(const Semaphore& rhs) = delete;

bool Signal();
bool SignalAll();

bool Wait();
bool TimedWait(mach_timespec_t duration);

protected:
Semaphore(const Semaphore& semaphore);
Semaphore& operator=(const Semaphore& semaphore);

private:
semaphore_t mSemaphore;
};

0 comments on commit 7613392

Please sign in to comment.