virtual destructor on BaseDecoder

magic-numbers
dimitri 8 years ago
parent c1a0f1c44a
commit c1881be5c7

@ -55,35 +55,25 @@ struct BaseDecoder
virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) = 0; virtual void LoadFromPath(nqr::AudioData * data, const std::string & path) = 0;
virtual void LoadFromBuffer(nqr::AudioData * data, const std::vector<uint8_t> & memory) = 0; virtual void LoadFromBuffer(nqr::AudioData * data, const std::vector<uint8_t> & memory) = 0;
virtual std::vector<std::string> GetSupportedFileExtensions() = 0; virtual std::vector<std::string> GetSupportedFileExtensions() = 0;
virtual ~BaseDecoder() {}
}; };
typedef std::pair<std::string, std::shared_ptr<nqr::BaseDecoder>> DecoderPair; typedef std::pair<std::string, std::shared_ptr<nqr::BaseDecoder>> DecoderPair;
class NyquistIO class NyquistIO
{ {
std::string ParsePathForExtension(const std::string & path) const;
std::shared_ptr<nqr::BaseDecoder> GetDecoderForExtension(const std::string ext);
void BuildDecoderTable();
void AddDecoderToTable(std::shared_ptr<nqr::BaseDecoder> decoder);
std::map<std::string, std::shared_ptr<BaseDecoder>> decoderTable;
NO_MOVE(NyquistIO);
public: public:
NyquistIO(); NyquistIO();
~NyquistIO(); ~NyquistIO();
void Load(AudioData * data, const std::string & path); void Load(AudioData * data, const std::string & path);
void Load(AudioData *data, std::string extension, const std::vector<uint8_t> & buffer); void Load(AudioData *data, std::string extension, const std::vector<uint8_t> & buffer);
bool IsFileSupported(const std::string path) const; bool IsFileSupported(const std::string path) const;
private:
std::string ParsePathForExtension(const std::string & path) const;
std::shared_ptr<nqr::BaseDecoder> GetDecoderForExtension(const std::string ext);
void BuildDecoderTable();
void AddDecoderToTable(std::shared_ptr<nqr::BaseDecoder> decoder);
std::map<std::string, std::shared_ptr<BaseDecoder>> decoderTable;
NO_MOVE(NyquistIO);
}; };
} // end namespace nqr } // end namespace nqr

@ -93,36 +93,24 @@ void NyquistIO::Load(AudioData * data, std::string extension, const std::vector<
{ {
throw std::runtime_error("No available decoders."); throw std::runtime_error("No available decoders.");
} }
} }
bool NyquistIO::IsFileSupported(const std::string path) const bool NyquistIO::IsFileSupported(const std::string path) const
{ {
auto fileExtension = ParsePathForExtension(path); auto fileExtension = ParsePathForExtension(path);
if (decoderTable.find(fileExtension) == decoderTable.end()) if (decoderTable.find(fileExtension) == decoderTable.end()) return false;
{ else return true;
return false;
}
else
{
return true;
}
} }
std::string NyquistIO::ParsePathForExtension(const std::string & path) const std::string NyquistIO::ParsePathForExtension(const std::string & path) const
{ {
if (path.find_last_of(".") != std::string::npos) if (path.find_last_of(".") != std::string::npos) return path.substr(path.find_last_of(".") + 1);
return path.substr(path.find_last_of(".") + 1);
return std::string(""); return std::string("");
} }
std::shared_ptr<BaseDecoder> NyquistIO::GetDecoderForExtension(const std::string ext) std::shared_ptr<BaseDecoder> NyquistIO::GetDecoderForExtension(const std::string ext)
{ {
if (decoderTable.size()) if (decoderTable.size()) return decoderTable[ext];
{
return decoderTable[ext];
}
else throw std::runtime_error("No available decoders."); else throw std::runtime_error("No available decoders.");
return nullptr; return nullptr;
} }

Loading…
Cancel
Save