From: <man...@us...> - 2014-10-29 11:59:52
|
Revision: 4516 http://sourceforge.net/p/modplug/code/4516 Author: manxorist Date: 2014-10-29 11:59:43 +0000 (Wed, 29 Oct 2014) Log Message: ----------- [Ref] Convert the AddToLog interface to mpt::ustring. Keep supporting std::string (for now). Modified Paths: -------------- trunk/OpenMPT/common/Logging.h trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp trunk/OpenMPT/mptrack/Moddoc.cpp trunk/OpenMPT/mptrack/Moddoc.h trunk/OpenMPT/soundlib/Sndfile.cpp trunk/OpenMPT/soundlib/Sndfile.h Modified: trunk/OpenMPT/common/Logging.h =================================================================== --- trunk/OpenMPT/common/Logging.h 2014-10-28 16:39:30 UTC (rev 4515) +++ trunk/OpenMPT/common/Logging.h 2014-10-29 11:59:43 UTC (rev 4516) @@ -39,8 +39,7 @@ class ILog { public: - virtual void AddToLog(const std::string &text) const { AddToLog(LogInformation, text); } - virtual void AddToLog(LogLevel level, const std::string &text) const = 0; + virtual void AddToLog(LogLevel level, const mpt::ustring &text) const = 0; }; Modified: trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp =================================================================== --- trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2014-10-28 16:39:30 UTC (rev 4515) +++ trunk/OpenMPT/libopenmpt/libopenmpt_impl.cpp 2014-10-29 11:59:43 UTC (rev 4516) @@ -191,8 +191,8 @@ return; } private: - void AddToLog( LogLevel level, const std::string & text ) const { - destination->log( mpt::ToCharset( mpt::CharsetUTF8, LogLevelToString( level ) ) + std::string(": ") + text ); + void AddToLog( LogLevel level, const mpt::ustring & text ) const { + destination->log( mpt::ToCharset( mpt::CharsetUTF8, LogLevelToString( level ) + MPT_USTRING(": ") + text ) ); } }; // class log_forwarder @@ -202,21 +202,21 @@ public: std::vector<std::pair<LogLevel,std::string> > GetMessages() const; private: - void AddToLog( LogLevel level, const std::string & text ) const; + void AddToLog( LogLevel level, const mpt::ustring & text ) const; }; // class loader_log std::vector<std::pair<LogLevel,std::string> > loader_log::GetMessages() const { return m_Messages; } -void loader_log::AddToLog( LogLevel level, const std::string & text ) const { - m_Messages.push_back( std::make_pair( level, text ) ); +void loader_log::AddToLog( LogLevel level, const mpt::ustring & text ) const { + m_Messages.push_back( std::make_pair( level, mpt::ToCharset( mpt::CharsetUTF8, text ) ) ); } void module_impl::PushToCSoundFileLog( const std::string & text ) const { - m_sndFile->AddToLog( LogError, text ); + m_sndFile->AddToLog( LogError, mpt::ToUnicode( mpt::CharsetUTF8, text ) ); } void module_impl::PushToCSoundFileLog( int loglevel, const std::string & text ) const { - m_sndFile->AddToLog( static_cast<LogLevel>( loglevel ), text ); + m_sndFile->AddToLog( static_cast<LogLevel>( loglevel ), mpt::ToUnicode( mpt::CharsetUTF8, text ) ); } static ResamplingMode filterlength_to_resamplingmode(std::int32_t length) { Modified: trunk/OpenMPT/mptrack/Moddoc.cpp =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.cpp 2014-10-28 16:39:30 UTC (rev 4515) +++ trunk/OpenMPT/mptrack/Moddoc.cpp 2014-10-29 11:59:43 UTC (rev 4516) @@ -853,8 +853,8 @@ } -void CModDoc::AddToLog(LogLevel level, const std::string &text) const -//------------------------------------------------------------------- +void CModDoc::AddToLog(LogLevel level, const mpt::ustring &text) const +//-------------------------------------------------------------------- { if(m_LogMode == LogModeGather) { @@ -863,24 +863,24 @@ { switch(level) { - case LogError: Reporting::Error(text.c_str()); break; - case LogWarning: Reporting::Warning(text.c_str()); break; - case LogInformation: Reporting::Information(text.c_str()); break; - case LogNotification: Reporting::Notification(text.c_str()); break; - default: Reporting::Information(text.c_str()); break; + case LogError: Reporting::Error(mpt::ToWide(text)); break; + case LogWarning: Reporting::Warning(mpt::ToWide(text)); break; + case LogInformation: Reporting::Information(mpt::ToWide(text)); break; + case LogNotification: Reporting::Notification(mpt::ToWide(text)); break; + default: Reporting::Information(mpt::ToWide(text)); break; } } } -std::string CModDoc::GetLogString() const +mpt::ustring CModDoc::GetLogString() const //--------------------------------------- { - std::string ret; + mpt::ustring ret; for(std::vector<LogEntry>::const_iterator i=m_Log.begin(); i!=m_Log.end(); ++i) { ret += (*i).message; - ret += "\r\n"; + ret += MPT_USTRING("\r\n"); } return ret; } @@ -918,15 +918,15 @@ if(!parent) parent = CMainFrame::GetMainFrame(); if(GetLog().size() > 0) { - std::wstring text = preamble + mpt::ToWide(mpt::CharsetLocale, GetLogString()); + std::wstring text = preamble + GetLogString(); std::wstring actualTitle = (title.length() == 0) ? MAINFRAME_TITLEW : title; switch(GetMaxLogLevel()) { - case LogError: Reporting::Error(text.c_str(), actualTitle.c_str(), parent); break; - case LogWarning: Reporting::Warning(text.c_str(), actualTitle.c_str(), parent); break; - case LogInformation: Reporting::Information(text.c_str(), actualTitle.c_str(), parent); break; - case LogNotification: Reporting::Notification(text.c_str(), actualTitle.c_str(), parent); break; - default: Reporting::Information(text.c_str(), actualTitle.c_str(), parent); break; + case LogError: Reporting::Error(text, actualTitle.c_str(), parent); break; + case LogWarning: Reporting::Warning(text, actualTitle.c_str(), parent); break; + case LogInformation: Reporting::Information(text, actualTitle.c_str(), parent); break; + case LogNotification: Reporting::Notification(text, actualTitle.c_str(), parent); break; + default: Reporting::Information(text, actualTitle.c_str(), parent); break; } return IDOK; } Modified: trunk/OpenMPT/mptrack/Moddoc.h =================================================================== --- trunk/OpenMPT/mptrack/Moddoc.h 2014-10-28 16:39:30 UTC (rev 4515) +++ trunk/OpenMPT/mptrack/Moddoc.h 2014-10-29 11:59:43 UTC (rev 4516) @@ -131,9 +131,9 @@ struct LogEntry { LogLevel level; - std::string message; + mpt::ustring message; LogEntry() : level(LogInformation) {} - LogEntry(LogLevel l, const std::string &m) : level(l), message(m) {} + LogEntry(LogLevel l, const mpt::ustring &m) : level(l), message(m) {} }; @@ -211,11 +211,11 @@ SAMPLEINDEX GetNumSamples() const { return m_SndFile.m_nSamples; } // Logging for general progress and error events. - void AddToLog(LogLevel level, const std::string &text) const; - void AddToLog(const std::string &text) const { AddToLog(LogInformation, text); } + void AddToLog(LogLevel level, const mpt::ustring &text) const; + /*MPT_DEPRECATED*/ void AddToLog(const std::string &text) const { AddToLog(LogInformation, mpt::ToUnicode(mpt::CharsetLocale, text)); } const std::vector<LogEntry> & GetLog() const { return m_Log; } - std::string GetLogString() const; + mpt::ustring GetLogString() const; LogLevel GetMaxLogLevel() const; protected: LogMode GetLogMode() const { return m_LogMode; } Modified: trunk/OpenMPT/soundlib/Sndfile.cpp =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.cpp 2014-10-28 16:39:30 UTC (rev 4515) +++ trunk/OpenMPT/soundlib/Sndfile.cpp 2014-10-29 11:59:43 UTC (rev 4516) @@ -651,8 +651,8 @@ } -void CSoundFile::AddToLog(LogLevel level, const std::string &text) const -//---------------------------------------------------------------------- +void CSoundFile::AddToLog(LogLevel level, const mpt::ustring &text) const +//----------------------------------------------------------------------- { if(m_pCustomLog) { @@ -662,11 +662,7 @@ #ifdef MODPLUG_TRACKER if(GetpModDoc()) GetpModDoc()->AddToLog(level, text); #else - #ifdef MPT_WITH_CHARSET_LOCALE - Log(level, mpt::ToUnicode(mpt::CharsetLocale, text)); - #else - Log(level, mpt::ToUnicode(mpt::CharsetUTF8, text)); - #endif + Log(level, text); #endif } } @@ -1667,7 +1663,7 @@ { if(s_pTuningsSharedLocal->Serialize() != CTuningCollection::SERIALIZATION_SUCCESS) { - AddToLog(LogError, "Static tuning serialisation failed"); + AddToLog(LogError, MPT_USTRING("Static tuning serialisation failed")); return false; } return true; Modified: trunk/OpenMPT/soundlib/Sndfile.h =================================================================== --- trunk/OpenMPT/soundlib/Sndfile.h 2014-10-28 16:39:30 UTC (rev 4515) +++ trunk/OpenMPT/soundlib/Sndfile.h 2014-10-29 11:59:43 UTC (rev 4516) @@ -526,8 +526,12 @@ public: // logging and user interaction void SetCustomLog(ILog *pLog) { m_pCustomLog = pLog; } - void AddToLog(LogLevel level, const std::string &text) const; - void AddToLog(const std::string &text) const { AddToLog(LogInformation, text); } + void AddToLog(LogLevel level, const mpt::ustring &text) const; +#if defined(MPT_WITH_CHARSET_LOCALE) + /*MPT_DEPRECATED*/ void AddToLog(const std::string &text) const { AddToLog(LogInformation, mpt::ToUnicode(mpt::CharsetLocale, text)); } +#else + /*MPT_DEPRECATED*/ void AddToLog(const std::string &text) const { AddToLog(LogInformation, mpt::ToUnicode(mpt::CharsetUTF8, text)); } +#endif public: This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |