From 6dcf4dffa698ac1d76894b93ecc416d73f536b94 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Thu, 16 Jul 2015 21:45:22 +0200 Subject: [PATCH] Refactor CSNDFile -> CSNDFileWrapper This seems more consistent --- src/CMakeLists.txt | 2 +- src/common/resources/resourcemanager.cpp | 4 ++-- src/common/resources/resourcemanager.h | 4 ++-- .../{sndfile.cpp => sndfile_wrapper.cpp} | 24 +++++++++---------- .../{sndfile.h => sndfile_wrapper.h} | 10 +++++--- src/sound/oalsound/buffer.cpp | 3 +-- 6 files changed, 25 insertions(+), 22 deletions(-) rename src/common/resources/{sndfile.cpp => sndfile_wrapper.cpp} (79%) rename src/common/resources/{sndfile.h => sndfile_wrapper.h} (87%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index fa514232..4720cd54 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -94,7 +94,7 @@ set(BASE_SOURCES common/resources/outputstreambuffer.cpp common/resources/resourcemanager.cpp common/resources/sdl_file_wrapper.cpp - common/resources/sndfile.cpp + common/resources/sndfile_wrapper.cpp common/restext.cpp common/stringutils.cpp graphics/core/color.cpp diff --git a/src/common/resources/resourcemanager.cpp b/src/common/resources/resourcemanager.cpp index 7143a2a4..1ab06416 100644 --- a/src/common/resources/resourcemanager.cpp +++ b/src/common/resources/resourcemanager.cpp @@ -112,9 +112,9 @@ std::unique_ptr CResourceManager::GetSDLFileHandler(const std:: return std::unique_ptr(new CSDLFileWrapper(CleanPath(filename))); } -std::unique_ptr CResourceManager::GetSNDFileHandler(const std::string &filename) +std::unique_ptr CResourceManager::GetSNDFileHandler(const std::string &filename) { - return std::unique_ptr(new CSNDFile(CleanPath(filename))); + return std::unique_ptr(new CSNDFileWrapper(CleanPath(filename))); } diff --git a/src/common/resources/resourcemanager.h b/src/common/resources/resourcemanager.h index 24a93758..6cfd7ee2 100644 --- a/src/common/resources/resourcemanager.h +++ b/src/common/resources/resourcemanager.h @@ -19,7 +19,7 @@ #pragma once -#include "common/resources/sndfile.h" +#include "common/resources/sndfile_wrapper.h" #include "common/resources/sdl_file_wrapper.h" #include @@ -41,7 +41,7 @@ public: static std::string GetSaveLocation(); static std::unique_ptr GetSDLFileHandler(const std::string &filename); - static std::unique_ptr GetSNDFileHandler(const std::string &filename); + static std::unique_ptr GetSNDFileHandler(const std::string &filename); //! Check if file exists static bool Exists(const std::string &filename); diff --git a/src/common/resources/sndfile.cpp b/src/common/resources/sndfile_wrapper.cpp similarity index 79% rename from src/common/resources/sndfile.cpp rename to src/common/resources/sndfile_wrapper.cpp index e7e2f4c0..4a21e95e 100644 --- a/src/common/resources/sndfile.cpp +++ b/src/common/resources/sndfile_wrapper.cpp @@ -17,12 +17,12 @@ * along with this program. If not, see http://gnu.org/licenses */ -#include "common/resources/sndfile.h" +#include "common/resources/sndfile_wrapper.h" #include -CSNDFile::CSNDFile(const std::string& filename) +CSNDFileWrapper::CSNDFileWrapper(const std::string& filename) : m_file_info{} , m_snd_file{nullptr} , m_file{nullptr} @@ -52,7 +52,7 @@ CSNDFile::CSNDFile(const std::string& filename) } -CSNDFile::~CSNDFile() +CSNDFileWrapper::~CSNDFileWrapper() { if (m_file) { @@ -65,43 +65,43 @@ CSNDFile::~CSNDFile() } -bool CSNDFile::IsOpen() +bool CSNDFileWrapper::IsOpen() { return m_file && m_snd_file; } -SF_INFO &CSNDFile::GetFileInfo() +SF_INFO &CSNDFileWrapper::GetFileInfo() { return m_file_info; } -std::string& CSNDFile::GetLastError() +std::string& CSNDFileWrapper::GetLastError() { return m_last_error; } -sf_count_t CSNDFile::Read(short int *ptr, sf_count_t items) +sf_count_t CSNDFileWrapper::Read(short int *ptr, sf_count_t items) { return sf_read_short(m_snd_file, ptr, items); } -sf_count_t CSNDFile::SNDLength(void *data) +sf_count_t CSNDFileWrapper::SNDLength(void *data) { return PHYSFS_fileLength(static_cast(data)); } -sf_count_t CSNDFile::SNDRead(void *ptr, sf_count_t count, void *data) +sf_count_t CSNDFileWrapper::SNDRead(void *ptr, sf_count_t count, void *data) { return PHYSFS_read(static_cast(data), ptr, 1, count); } -sf_count_t CSNDFile::SNDSeek(sf_count_t offset, int whence, void *data) +sf_count_t CSNDFileWrapper::SNDSeek(sf_count_t offset, int whence, void *data) { PHYSFS_File *file = static_cast(data); switch(whence) @@ -121,13 +121,13 @@ sf_count_t CSNDFile::SNDSeek(sf_count_t offset, int whence, void *data) } -sf_count_t CSNDFile::SNDTell(void *data) +sf_count_t CSNDFileWrapper::SNDTell(void *data) { return PHYSFS_tell(static_cast(data)); } -sf_count_t CSNDFile::SNDWrite(const void *ptr, sf_count_t count, void *data) +sf_count_t CSNDFileWrapper::SNDWrite(const void *ptr, sf_count_t count, void *data) { return PHYSFS_write(static_cast(data), ptr, 1, count); } diff --git a/src/common/resources/sndfile.h b/src/common/resources/sndfile_wrapper.h similarity index 87% rename from src/common/resources/sndfile.h rename to src/common/resources/sndfile_wrapper.h index f083666b..302609d7 100644 --- a/src/common/resources/sndfile.h +++ b/src/common/resources/sndfile_wrapper.h @@ -20,15 +20,19 @@ #pragma once #include + #include #include -class CSNDFile +class CSNDFileWrapper { public: - CSNDFile(const std::string &filename); - virtual ~CSNDFile(); + CSNDFileWrapper(const std::string &filename); + virtual ~CSNDFileWrapper(); + + CSNDFileWrapper(const CSNDFileWrapper&) = delete; + CSNDFileWrapper& operator=(const CSNDFileWrapper&) = delete; SF_INFO &GetFileInfo(); bool IsOpen(); diff --git a/src/sound/oalsound/buffer.cpp b/src/sound/oalsound/buffer.cpp index 84746d35..5fa13fdd 100644 --- a/src/sound/oalsound/buffer.cpp +++ b/src/sound/oalsound/buffer.cpp @@ -23,7 +23,6 @@ #include "sound/oalsound/check.h" #include "common/resources/resourcemanager.h" -#include "common/resources/sndfile.h" #include @@ -52,7 +51,7 @@ bool Buffer::LoadFromFile(std::string filename, SoundType sound) m_sound = sound; GetLogger()->Debug("Loading audio file: %s\n", filename.c_str()); - std::unique_ptr file = CResourceManager::GetSNDFileHandler(filename); + auto file = CResourceManager::GetSNDFileHandler(filename); GetLogger()->Trace(" channels %d\n", file->GetFileInfo().channels); GetLogger()->Trace(" format %d\n", file->GetFileInfo().format);