Stricter constness

Marked AE decoder classes as final to encourage devirtualization
This commit is contained in:
Silent 2017-10-20 00:58:06 +02:00
parent 90590af639
commit 71ebe0d9eb
3 changed files with 33 additions and 31 deletions

View file

@ -22,7 +22,7 @@ enum eDecoderType
};
// 1.0/Steam structure
class NOVMT CAEDataStreamOld : public IStream
class NOVMT CAEDataStreamOld final : public IStream
{
private:
HANDLE hHandle;
@ -57,9 +57,9 @@ public:
}
}
inline DWORD GetID()
inline DWORD GetID() const
{ return dwID; }
inline HANDLE GetFile()
inline HANDLE GetFile() const
{ return hHandle; }
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void ** ppvObject);
@ -87,7 +87,7 @@ public:
// Custom methods
DWORD Seek(LONG nToSeek, DWORD nPoint);
DWORD FillBuffer(void* pBuf, DWORD nLen);
DWORD GetCurrentPosition()
DWORD GetCurrentPosition() const
{
LARGE_INTEGER filePointer;
filePointer.QuadPart = 0;
@ -97,7 +97,7 @@ public:
};
// 1.01 structure
class NOVMT CAEDataStreamNew : public IStream
class NOVMT CAEDataStreamNew final : public IStream
{
private:
void* pUselessMalloc;
@ -134,9 +134,9 @@ public:
}
}
inline DWORD GetID()
inline DWORD GetID() const
{ return dwID; }
inline HANDLE GetFile()
inline HANDLE GetFile() const
{ return hHandle; }
virtual HRESULT STDMETHODCALLTYPE QueryInterface(REFIID iid, void ** ppvObject);
@ -164,7 +164,7 @@ public:
// Custom methods
DWORD Seek(LONG nToSeek, DWORD nPoint);
DWORD FillBuffer(void* pBuf, DWORD nLen);
DWORD GetCurrentPosition()
DWORD GetCurrentPosition() const
{
LARGE_INTEGER filePointer;
filePointer.QuadPart = 0;
@ -201,20 +201,20 @@ public:
return reinterpret_cast<CAEDataStreamNew*>(this)->FillBuffer(pBuf, nLen);
return reinterpret_cast<CAEDataStreamOld*>(this)->FillBuffer(pBuf, nLen); }
unsigned int GetCurrentPosition()
unsigned int GetCurrentPosition() const
{ if ( m_bUseNewStruct )
return reinterpret_cast<CAEDataStreamNew*>(this)->GetCurrentPosition();
return reinterpret_cast<CAEDataStreamOld*>(this)->GetCurrentPosition(); }
return reinterpret_cast<const CAEDataStreamNew*>(this)->GetCurrentPosition();
return reinterpret_cast<const CAEDataStreamOld*>(this)->GetCurrentPosition(); }
inline DWORD GetID()
inline DWORD GetID() const
{ if ( m_bUseNewStruct )
return reinterpret_cast<CAEDataStreamNew*>(this)->GetID();
return reinterpret_cast<CAEDataStreamOld*>(this)->GetID(); }
return reinterpret_cast<const CAEDataStreamNew*>(this)->GetID();
return reinterpret_cast<const CAEDataStreamOld*>(this)->GetID(); }
inline HANDLE GetFile()
inline HANDLE GetFile() const
{ if ( m_bUseNewStruct )
return reinterpret_cast<CAEDataStreamNew*>(this)->GetFile();
return reinterpret_cast<CAEDataStreamOld*>(this)->GetFile(); }
return reinterpret_cast<const CAEDataStreamNew*>(this)->GetFile();
return reinterpret_cast<const CAEDataStreamOld*>(this)->GetFile(); }
};
@ -233,18 +233,20 @@ public:
inline CAEDataStream* GetStream()
{ return pStream; }
inline const CAEDataStream* GetStream() const
{ return pStream; }
virtual bool Initialise()=0;
virtual uint32_t FillBuffer(void* pBuf,uint32_t nLen)=0;
virtual uint32_t GetStreamLengthMs()=0;
virtual uint32_t GetStreamPlayTimeMs()=0;
virtual uint32_t GetStreamLengthMs() const =0;
virtual uint32_t GetStreamPlayTimeMs() const =0;
virtual void SetCursor(uint32_t nTime)=0;
virtual uint32_t GetSampleRate()=0;
virtual uint32_t GetSampleRate() const =0;
virtual ~CAEStreamingDecoder();
virtual uint32_t GetStreamID()=0;
virtual uint32_t GetStreamID() const =0;
};
static_assert(sizeof(CAEDataStreamOld) == 0x28, "Wrong size: CAEDataStreamOld");

View file

@ -2,7 +2,7 @@
#include "AudioHardwareSA.h"
class CAEFLACDecoder : public CAEStreamingDecoder
class CAEFLACDecoder final : public CAEStreamingDecoder
{
private:
FLAC__StreamDecoder* m_FLACdecoder = nullptr;
@ -31,14 +31,14 @@ public:
virtual ~CAEFLACDecoder() override;
virtual bool Initialise() override;
virtual uint32_t FillBuffer(void* pBuf, uint32_t nLen) override;
virtual uint32_t GetStreamLengthMs() override
virtual uint32_t GetStreamLengthMs() const override
{ return uint32_t((m_streamMeta->data.stream_info.total_samples * 1000) / m_streamMeta->data.stream_info.sample_rate); }
virtual uint32_t GetStreamPlayTimeMs() override
virtual uint32_t GetStreamPlayTimeMs() const override
{ return uint32_t((m_currentSample * 1000) / m_streamMeta->data.stream_info.sample_rate); }
virtual void SetCursor(uint32_t nTime) override
{ FLAC__stream_decoder_seek_absolute(m_FLACdecoder, (uint64_t(nTime) * m_streamMeta->data.stream_info.sample_rate) / 1000); }
virtual uint32_t GetSampleRate() override
virtual uint32_t GetSampleRate() const override
{ return m_streamMeta->data.stream_info.sample_rate; }
virtual uint32_t GetStreamID() override
virtual uint32_t GetStreamID() const override
{ return GetStream()->GetID(); }
};

View file

@ -2,7 +2,7 @@
#include "AudioHardwareSA.h"
class CAEWaveDecoder : public CAEStreamingDecoder
class CAEWaveDecoder final : public CAEStreamingDecoder
{
private:
uint32_t m_dataSize;
@ -33,9 +33,9 @@ public:
virtual bool Initialise() override;
virtual uint32_t FillBuffer(void* pBuf, uint32_t nLen) override;
virtual uint32_t GetStreamLengthMs() override
virtual uint32_t GetStreamLengthMs() const override
{ return (static_cast<uint64_t>(m_dataSize) * 1000) / m_formatChunk.blockAlign; }
virtual uint32_t GetStreamPlayTimeMs() override
virtual uint32_t GetStreamPlayTimeMs() const override
{ return (static_cast<uint64_t>(GetStream()->GetCurrentPosition() - m_offsetToData) * 1000) / m_formatChunk.blockAlign; }
virtual void SetCursor(uint32_t nTime) override
@ -44,10 +44,10 @@ public:
GetStream()->Seek( m_offsetToData + (static_cast<uint32_t>(sampleNum) * m_formatChunk.blockAlign), FILE_BEGIN );
}
virtual uint32_t GetSampleRate() override
virtual uint32_t GetSampleRate() const override
{ return m_formatChunk.sampleRate; }
virtual uint32_t GetStreamID() override
virtual uint32_t GetStreamID() const override
{ return GetStream()->GetID(); }
private: