From 6a1ceba8c0914691ebc873fd666e7cde1cffdb64 Mon Sep 17 00:00:00 2001 From: Piotr Dziwinski Date: Sun, 7 Sep 2014 19:26:06 +0200 Subject: Some cleaning up --- src/common/resources/inputstream.h | 4 +-- src/common/resources/inputstreambuffer.cpp | 8 ++--- src/common/resources/inputstreambuffer.h | 4 +-- src/common/resources/outputstream.h | 2 +- src/common/resources/outputstreambuffer.cpp | 4 +-- src/common/resources/outputstreambuffer.h | 2 -- src/common/resources/resourcemanager.cpp | 51 +++++++++++++++------------ src/common/resources/resourcestreambuffer.cpp | 0 src/common/resources/resourcestreambuffer.h | 0 src/common/resources/sndfile.cpp | 2 -- src/common/resources/sndfile.h | 1 - 11 files changed, 39 insertions(+), 39 deletions(-) delete mode 100644 src/common/resources/resourcestreambuffer.cpp delete mode 100644 src/common/resources/resourcestreambuffer.h (limited to 'src/common') diff --git a/src/common/resources/inputstream.h b/src/common/resources/inputstream.h index 9d1c578..9573f2c 100644 --- a/src/common/resources/inputstream.h +++ b/src/common/resources/inputstream.h @@ -25,9 +25,9 @@ class CInputStream : public std::istream public: CInputStream(); virtual ~CInputStream(); - + void open(const std::string &filename); void close(); - bool is_open(); + bool is_open(); size_t size(); }; diff --git a/src/common/resources/inputstreambuffer.cpp b/src/common/resources/inputstreambuffer.cpp index b8710e9..cfa06fb 100644 --- a/src/common/resources/inputstreambuffer.cpp +++ b/src/common/resources/inputstreambuffer.cpp @@ -68,14 +68,14 @@ std::streambuf::int_type CInputStreamBuffer::underflow() { if (gptr() < egptr()) return traits_type::to_int_type(*gptr()); - + if (PHYSFS_eof(m_file)) return traits_type::eof(); - + PHYSFS_sint64 read_count = PHYSFS_read(m_file, m_buffer, sizeof(char), m_buffer_size); if (read_count <= 0) return traits_type::eof(); - + setg(m_buffer, m_buffer, m_buffer + read_count); return traits_type::to_int_type(*gptr()); @@ -98,7 +98,7 @@ std::streampos CInputStreamBuffer::seekoff(std::streamoff off, std::ios_base::se off argument is relative to way */ std::streamoff new_position; - + switch (way) { case std::ios_base::beg: diff --git a/src/common/resources/inputstreambuffer.h b/src/common/resources/inputstreambuffer.h index 93cb43c..384ebfb 100644 --- a/src/common/resources/inputstreambuffer.h +++ b/src/common/resources/inputstreambuffer.h @@ -25,7 +25,7 @@ class CInputStreamBuffer : public std::streambuf public: CInputStreamBuffer(size_t buffer_size = 512); virtual ~CInputStreamBuffer(); - + void open(const std::string &filename); void close(); bool is_open(); @@ -41,7 +41,7 @@ private: // copying not allowed CInputStreamBuffer(const CInputStreamBuffer &); CInputStreamBuffer &operator= (const CInputStreamBuffer &); - + PHYSFS_File *m_file; char *m_buffer; size_t m_buffer_size; diff --git a/src/common/resources/outputstream.h b/src/common/resources/outputstream.h index 4f4cd72..bedbbbd 100644 --- a/src/common/resources/outputstream.h +++ b/src/common/resources/outputstream.h @@ -25,7 +25,7 @@ class COutputStream : public std::ostream public: COutputStream(); virtual ~COutputStream(); - + void open(const std::string &filename); void close(); bool is_open(); diff --git a/src/common/resources/outputstreambuffer.cpp b/src/common/resources/outputstreambuffer.cpp index 22ed7cb..38979db 100644 --- a/src/common/resources/outputstreambuffer.cpp +++ b/src/common/resources/outputstreambuffer.cpp @@ -59,7 +59,7 @@ std::streambuf::int_type COutputStreamBuffer::overflow(std::streambuf::int_type { /* This function should be called when pptr() == epptr(). We use it also in sync() so we also have to write data if buffer is not full. */ - + if (pbase() == pptr()) // no data to write, sync() called with empty buffer return 0; @@ -68,7 +68,7 @@ std::streambuf::int_type COutputStreamBuffer::overflow(std::streambuf::int_type if (bytes_written <= 0) return traits_type::eof(); - pbump(-bytes_written); + pbump(-bytes_written); // write final char if (ch != traits_type::eof()) { bytes_written = PHYSFS_write(m_file, &ch, 1, 1); diff --git a/src/common/resources/outputstreambuffer.h b/src/common/resources/outputstreambuffer.h index 1d98791..1318530 100644 --- a/src/common/resources/outputstreambuffer.h +++ b/src/common/resources/outputstreambuffer.h @@ -25,7 +25,6 @@ class COutputStreamBuffer : public std::streambuf public: COutputStreamBuffer(size_t buffer_size = 512); virtual ~COutputStreamBuffer(); - void open(const std::string &filename); void close(); bool is_open(); @@ -38,7 +37,6 @@ private: // copying not allowed COutputStreamBuffer(const COutputStreamBuffer &); COutputStreamBuffer &operator= (const COutputStreamBuffer &); - PHYSFS_File *m_file; char *m_buffer; size_t m_buffer_size; diff --git a/src/common/resources/resourcemanager.cpp b/src/common/resources/resourcemanager.cpp index 0741c70..6459df0 100644 --- a/src/common/resources/resourcemanager.cpp +++ b/src/common/resources/resourcemanager.cpp @@ -22,6 +22,11 @@ #include +namespace +{ + const Uint32 PHYSFS_RWOPS_TYPE = 0xc010b04f; +} + CResourceManager::CResourceManager(const char *argv0) { @@ -53,7 +58,7 @@ bool CResourceManager::AddLocation(const std::string &location, bool prepend) CLogger::GetInstancePointer()->Error("Error while mounting \"%s\"\n", location.c_str()); } } - + return false; } @@ -67,7 +72,7 @@ bool CResourceManager::RemoveLocation(const std::string &location) CLogger::GetInstancePointer()->Error("Error while unmounting \"%s\"\n", location.c_str()); } } - + return false; } @@ -81,7 +86,7 @@ bool CResourceManager::SetSaveLocation(const std::string &location) CLogger::GetInstancePointer()->Error("Error while setting save location to \"%s\"\n", location.c_str()); } } - + return false; } @@ -94,13 +99,13 @@ SDL_RWops* CResourceManager::GetSDLFileHandler(const std::string &filename) CLogger::GetInstancePointer()->Error("Unable to allocate SDL_RWops for \"%s\"\n", filename.c_str()); return nullptr; } - + if (!PHYSFS_isInit()) { SDL_FreeRW(handler); return nullptr; } - + PHYSFS_File *file = PHYSFS_openRead(filename.c_str()); if (!file) { @@ -112,15 +117,15 @@ SDL_RWops* CResourceManager::GetSDLFileHandler(const std::string &filename) handler->read = SDLRead; handler->write = SDLWrite; handler->close = SDLClose; - handler->type = 0xc010b04f; + handler->type = PHYSFS_RWOPS_TYPE; handler->hidden.unknown.data1 = file; - + return handler; } CSNDFile* CResourceManager::GetSNDFileHandler(const std::string &filename) -{ +{ return new CSNDFile(filename); } @@ -133,15 +138,15 @@ bool CResourceManager::Exists(const std::string &filename) std::vector CResourceManager::ListFiles(const std::string &directory) { std::vector result; - + char **files = PHYSFS_enumerateFiles(directory.c_str()); - + for (char **i = files; *i != nullptr; i++) { result.push_back(*i); } - + PHYSFS_freeList(files); - + return result; } @@ -152,10 +157,10 @@ int CResourceManager::SDLClose(SDL_RWops *context) { PHYSFS_close(static_cast(context->hidden.unknown.data1)); SDL_FreeRW(context); - + return 0; } - + return 1; } @@ -166,10 +171,10 @@ int CResourceManager::SDLRead(SDL_RWops *context, void *ptr, int size, int maxnu { PHYSFS_File *file = static_cast(context->hidden.unknown.data1); SDL_memset(ptr, 0, size * maxnum); - + return PHYSFS_read(file, ptr, size, maxnum); } - + return 0; } @@ -186,37 +191,37 @@ int CResourceManager::SDLSeek(SDL_RWops *context, int offset, int whence) { PHYSFS_File *file = static_cast(context->hidden.unknown.data1); int position, result; - + switch (whence) { default: case RW_SEEK_SET: result = PHYSFS_seek(file, offset); return result > 0 ? offset : -1; - + case RW_SEEK_CUR: position = offset + PHYSFS_tell(file); result = PHYSFS_seek(file, position); return result > 0 ? position : -1; - + case RW_SEEK_END: position = PHYSFS_fileLength(file) - offset; result = PHYSFS_seek(file, position); - return result > 0 ? position : -1; + return result > 0 ? position : -1; } } - + return -1; } bool CResourceManager::CheckSDLContext(SDL_RWops *context) { - if (context->type != 0xc010b04f) + if (context->type != PHYSFS_RWOPS_TYPE) { SDL_SetError("Wrong kind of RWops"); return false; } - + return true; } diff --git a/src/common/resources/resourcestreambuffer.cpp b/src/common/resources/resourcestreambuffer.cpp deleted file mode 100644 index e69de29..0000000 diff --git a/src/common/resources/resourcestreambuffer.h b/src/common/resources/resourcestreambuffer.h deleted file mode 100644 index e69de29..0000000 diff --git a/src/common/resources/sndfile.cpp b/src/common/resources/sndfile.cpp index 3f5a60d..b71f06a 100644 --- a/src/common/resources/sndfile.cpp +++ b/src/common/resources/sndfile.cpp @@ -31,7 +31,6 @@ CSNDFile::CSNDFile(const std::string& filename) { m_last_error = "Resource system not started!"; } - if (m_file) { m_snd_file = sf_open_virtual(&snd_callbacks, SFM_READ, &m_file_info, m_file); @@ -99,7 +98,6 @@ sf_count_t CSNDFile::SNDRead(void *ptr, sf_count_t count, void *data) sf_count_t CSNDFile::SNDSeek(sf_count_t offset, int whence, void *data) { PHYSFS_File *file = static_cast(data); - switch(whence) { case SEEK_CUR: diff --git a/src/common/resources/sndfile.h b/src/common/resources/sndfile.h index 5ea6ccc..5fc00f4 100644 --- a/src/common/resources/sndfile.h +++ b/src/common/resources/sndfile.h @@ -38,7 +38,6 @@ private: static sf_count_t SNDRead(void *ptr, sf_count_t count, void *data); static sf_count_t SNDWrite(const void *ptr, sf_count_t count, void *data); static sf_count_t SNDTell(void *data); - SF_INFO m_file_info; SNDFILE *m_snd_file; PHYSFS_File *m_file; -- cgit v1.2.3-1-g7c22