From: <sag...@us...> - 2014-10-25 01:52:02
|
Revision: 4481 http://sourceforge.net/p/modplug/code/4481 Author: saga-games Date: 2014-10-25 01:51:48 +0000 (Sat, 25 Oct 2014) Log Message: ----------- [Ref] Instead of checking for MPT_FILEREADER_STD_ISTREAM at every site, use the new mpt::IO::Open to wrap stream vs memory-mapped file open calls for FileReader. Modified Paths: -------------- trunk/OpenMPT/common/mptIO.cpp trunk/OpenMPT/common/mptIO.h trunk/OpenMPT/soundlib/Load_itp.cpp trunk/OpenMPT/soundlib/Load_mt2.cpp Modified: trunk/OpenMPT/common/mptIO.cpp =================================================================== --- trunk/OpenMPT/common/mptIO.cpp 2014-10-24 09:34:51 UTC (rev 4480) +++ trunk/OpenMPT/common/mptIO.cpp 2014-10-25 01:51:48 UTC (rev 4481) @@ -22,6 +22,10 @@ #include <stdio.h> +#include "../soundlib/FileReader.h" +#ifndef MPT_FILEREADER_STD_ISTREAM +#include "../mptrack/MemoryMappedFile.h" +#endif OPENMPT_NAMESPACE_BEGIN @@ -30,7 +34,23 @@ namespace IO { +FileReader Open(const mpt::PathString &filename) +{ +#ifdef MPT_FILEREADER_STD_ISTREAM + mpt::ifstream f(filename, std::ios_base::binary); + if(f.good()) + return (&f, &filename); + else + return FileReader(); +#else + CMappedFile f; + if(f.Open(filename)) + return f.GetFile(); + else + return FileReader(); +#endif +} //STATIC_ASSERT(sizeof(std::streamoff) == 8); // Assert 64bit file support. bool IsValid(std::ostream & f) { return !f.fail(); } Modified: trunk/OpenMPT/common/mptIO.h =================================================================== --- trunk/OpenMPT/common/mptIO.h 2014-10-24 09:34:51 UTC (rev 4480) +++ trunk/OpenMPT/common/mptIO.h 2014-10-25 01:51:48 UTC (rev 4481) @@ -31,9 +31,12 @@ OPENMPT_NAMESPACE_BEGIN +class FileReader; namespace mpt { +class PathString; + namespace IO { typedef int64 Offset; @@ -47,8 +50,9 @@ return (static_cast<IO::Offset>(mpt::saturate_cast<Toff>(off)) == off); } +// Open a file (either stream or memory-mapped, depending on program configuration) and immediately return FileReader for the file +FileReader Open(const mpt::PathString &filename); - bool IsValid(std::ostream & f); bool IsValid(std::istream & f); bool IsValid(std::iostream & f); @@ -194,7 +198,7 @@ { byte = 0; if(!IO::ReadIntLE<uint8>(f, byte)) result = false; - v |= (static_cast<uint16>(byte) << (((i+1)*8) - 1)); + v |= (static_cast<uint16>(byte) << (((i+1)*8) - 1)); } return result; } @@ -214,7 +218,7 @@ { byte = 0; if(!IO::ReadIntLE<uint8>(f, byte)) result = false; - v |= (static_cast<uint32>(byte) << (((i+1)*8) - 2)); + v |= (static_cast<uint32>(byte) << (((i+1)*8) - 2)); } return result; } @@ -234,7 +238,7 @@ { byte = 0; if(!IO::ReadIntLE<uint8>(f, byte)) result = false; - v |= (static_cast<uint64>(byte) << (((i+1)*8) - 2)); + v |= (static_cast<uint64>(byte) << (((i+1)*8) - 2)); } return result; } @@ -262,7 +266,7 @@ } str.push_back(c); } - return true; + return true; } @@ -549,7 +553,7 @@ }; -#endif +#endif class FileDataContainerMemory @@ -631,4 +635,4 @@ -OPENMPT_NAMESPACE_END +OPENMPT_NAMESPACE_END \ No newline at end of file Modified: trunk/OpenMPT/soundlib/Load_itp.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_itp.cpp 2014-10-24 09:34:51 UTC (rev 4480) +++ trunk/OpenMPT/soundlib/Load_itp.cpp 2014-10-25 01:51:48 UTC (rev 4481) @@ -20,9 +20,6 @@ #include "ITTools.h" #ifdef MODPLUG_TRACKER #include "../mptrack/TrackerSettings.h" -#if !defined(MPT_FILEREADER_STD_ISTREAM) -#include "../mptrack/MemoryMappedFile.h" -#endif #ifndef MODPLUG_NO_FILESAVE #include "../common/mptFstream.h" #endif @@ -263,18 +260,7 @@ { if(m_szInstrumentPath[ins].empty()) continue; -#if defined(MPT_FILEREADER_STD_ISTREAM) - mpt::ifstream f(m_szInstrumentPath[ins], std::ios_base::binary); - if(!f.good()) - continue; - FileReader file(&f, &m_szInstrumentPath[ins]); -#else - CMappedFile f; - if(!f.Open(m_szInstrumentPath[ins])) - continue; - FileReader file = f.GetFile(); -#endif - + FileReader file(mpt::IO::Open(m_szInstrumentPath[ins])); if(file.IsValid()) ReadInstrumentFromFile(ins + 1, file, TrackerSettings::Instance().m_MayNormalizeSamplesOnLoad); } Modified: trunk/OpenMPT/soundlib/Load_mt2.cpp =================================================================== --- trunk/OpenMPT/soundlib/Load_mt2.cpp 2014-10-24 09:34:51 UTC (rev 4480) +++ trunk/OpenMPT/soundlib/Load_mt2.cpp 2014-10-25 01:51:48 UTC (rev 4481) @@ -12,12 +12,6 @@ #include "stdafx.h" #include "Loaders.h" #ifdef MODPLUG_TRACKER -// For loading external samples -#if defined(MPT_FILEREADER_STD_ISTREAM) -#include "../common/mptFstream.h" -#else -#include "../mptrack/MemoryMappedFile.h" -#endif #include "../mptrack/Moddoc.h" #endif @@ -1081,16 +1075,7 @@ path = path.RelativePathToAbsolute(mt2FileName.GetPath()); } -#if defined(MPT_FILEREADER_STD_ISTREAM) - mpt::ifstream f(path, std::ios_base::binary); - if(f.good()) - sampleFile = FileReader(&f, &path); -#else - CMappedFile f; - FileReader sampleFile; - if(f.Open(path)) - sampleFile = f.GetFile(); -#endif + FileReader sampleFile(mpt::IO::Open(path)); if(sampleFile.IsValid()) ReadSampleFromFile(i + 1, sampleFile, false); #endif This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |