diff --git a/include/libnyquist/AudioDecoder.h b/include/libnyquist/AudioDecoder.h index c49ef03..0f5947f 100644 --- a/include/libnyquist/AudioDecoder.h +++ b/include/libnyquist/AudioDecoder.h @@ -55,35 +55,25 @@ struct BaseDecoder virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) = 0; virtual void LoadFromBuffer(nqr::AudioData * data, const std::vector & memory) = 0; virtual std::vector GetSupportedFileExtensions() = 0; + virtual ~BaseDecoder() {} }; typedef std::pair> DecoderPair; class NyquistIO { + std::string ParsePathForExtension(const std::string & path) const; + std::shared_ptr GetDecoderForExtension(const std::string ext); + void BuildDecoderTable(); + void AddDecoderToTable(std::shared_ptr decoder); + std::map> decoderTable; + NO_MOVE(NyquistIO); public: - NyquistIO(); ~NyquistIO(); - void Load(AudioData * data, const std::string & path); void Load(AudioData *data, std::string extension, const std::vector & buffer); - bool IsFileSupported(const std::string path) const; - -private: - - std::string ParsePathForExtension(const std::string & path) const; - - std::shared_ptr GetDecoderForExtension(const std::string ext); - - void BuildDecoderTable(); - - void AddDecoderToTable(std::shared_ptr decoder); - - std::map> decoderTable; - - NO_MOVE(NyquistIO); }; } // end namespace nqr diff --git a/src/AudioDecoder.cpp b/src/AudioDecoder.cpp index b2f4723..e9f6e11 100644 --- a/src/AudioDecoder.cpp +++ b/src/AudioDecoder.cpp @@ -93,36 +93,24 @@ void NyquistIO::Load(AudioData * data, std::string extension, const std::vector< { throw std::runtime_error("No available decoders."); } - } bool NyquistIO::IsFileSupported(const std::string path) const { auto fileExtension = ParsePathForExtension(path); - if (decoderTable.find(fileExtension) == decoderTable.end()) - { - return false; - } - else - { - return true; - } + if (decoderTable.find(fileExtension) == decoderTable.end()) return false; + else return true; } std::string NyquistIO::ParsePathForExtension(const std::string & path) const { - if (path.find_last_of(".") != std::string::npos) - return path.substr(path.find_last_of(".") + 1); - + if (path.find_last_of(".") != std::string::npos) return path.substr(path.find_last_of(".") + 1); return std::string(""); } std::shared_ptr NyquistIO::GetDecoderForExtension(const std::string ext) { - if (decoderTable.size()) - { - return decoderTable[ext]; - } + if (decoderTable.size()) return decoderTable[ext]; else throw std::runtime_error("No available decoders."); return nullptr; }