2009-09-08 12:08:10 +00:00
|
|
|
/* PCSX2 - PS2 Emulator for PCs
|
2010-05-03 14:08:02 +00:00
|
|
|
* Copyright (C) 2002-2010 PCSX2 Dev Team
|
2010-04-25 00:31:27 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is free software: you can redistribute it and/or modify it under the terms
|
|
|
|
* of the GNU Lesser General Public License as published by the Free Software Found-
|
|
|
|
* ation, either version 3 of the License, or (at your option) any later version.
|
2009-07-03 00:49:40 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* PCSX2 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
|
|
|
|
* without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
|
|
|
|
* PURPOSE. See the GNU General Public License for more details.
|
2009-07-03 00:49:40 +00:00
|
|
|
*
|
2009-09-08 12:08:10 +00:00
|
|
|
* You should have received a copy of the GNU General Public License along with PCSX2.
|
|
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
2009-07-03 00:49:40 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
#include "Dependencies.h"
|
2010-08-03 22:18:19 +00:00
|
|
|
#include "SafeArray.h"
|
2010-10-18 15:46:05 +00:00
|
|
|
#include "ScopedAlloc.h"
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
|
2009-07-03 00:49:40 +00:00
|
|
|
#include <wx/tokenzr.h>
|
|
|
|
|
2010-06-10 11:27:30 +00:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// pxToUTF8
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// Converts a string to UTF8 and provides an interface for getting its length.
|
|
|
|
class pxToUTF8
|
|
|
|
{
|
|
|
|
DeclareNoncopyableObject( pxToUTF8 );
|
|
|
|
|
|
|
|
protected:
|
|
|
|
wxCharBuffer m_result;
|
|
|
|
int m_length;
|
|
|
|
|
|
|
|
public:
|
|
|
|
explicit pxToUTF8(const wxString& src)
|
|
|
|
: m_result( src.ToUTF8() )
|
|
|
|
{
|
|
|
|
m_length = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
size_t Length()
|
|
|
|
{
|
|
|
|
if( -1 == m_length )
|
|
|
|
m_length = strlen( m_result );
|
|
|
|
return m_length;
|
|
|
|
}
|
|
|
|
|
|
|
|
void Convert( const wxString& src )
|
|
|
|
{
|
|
|
|
m_result = src.ToUTF8();
|
|
|
|
m_length = -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
const char* data() const { return m_result; }
|
|
|
|
|
|
|
|
operator const char*() const
|
|
|
|
{
|
|
|
|
return m_result.data();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
Lots of new code maintenance stuffs:
* Completely new assertion macros: pxAssert, pxAssertMsg, and pxFail, pxAssertDev (both which default to using a message). These replace *all* wxASSERT, DevAssert, and jASSUME varieties of macros. New macros borrow the best of all assertion worlds: MSVCRT, wxASSERT, and AtlAssume. :)
* Rewrote the Console namespace as a structure called IConsoleWriter, and created several varieties of ConsoleWriters for handling different states of log and console availability (should help reduce overhead of console logging nicely).
* More improvements to the PersistentThread model, using safely interlocked "Do*" style callbacks for starting and cleaning up threads.
* Fixed console logs so that they're readable in Win32 notepad again (the log writer adds CRs to naked LFs).
* Added AppInit.cpp -- contains constructor, destructor, OnInit, and command line parsing mess.
git-svn-id: http://pcsx2.googlecode.com/svn/trunk@1950 96395faa-99c1-11dd-bbfe-3dabce05a288
2009-10-04 08:27:27 +00:00
|
|
|
extern void px_fputs( FILE* fp, const char* src );
|
|
|
|
|
2009-07-03 00:49:40 +00:00
|
|
|
// wxWidgets lacks one of its own...
|
|
|
|
extern const wxRect wxDefaultRect;
|
|
|
|
|
2009-11-16 00:40:09 +00:00
|
|
|
extern void SplitString( wxArrayString& dest, const wxString& src, const wxString& delims, wxStringTokenizerMode mode = wxTOKEN_RET_EMPTY_ALL );
|
2010-06-30 03:21:59 +00:00
|
|
|
extern wxString JoinString( const wxArrayString& src, const wxString& separator );
|
|
|
|
extern wxString JoinString( const wxChar** src, const wxString& separator );
|
2009-09-16 17:23:02 +00:00
|
|
|
|
2009-07-03 00:49:40 +00:00
|
|
|
extern wxString ToString( const wxPoint& src, const wxString& separator=L"," );
|
|
|
|
extern wxString ToString( const wxSize& src, const wxString& separator=L"," );
|
|
|
|
extern wxString ToString( const wxRect& src, const wxString& separator=L"," );
|
|
|
|
|
|
|
|
extern bool TryParse( wxPoint& dest, const wxStringTokenizer& parts );
|
|
|
|
extern bool TryParse( wxSize& dest, const wxStringTokenizer& parts );
|
|
|
|
|
|
|
|
extern bool TryParse( wxPoint& dest, const wxString& src, const wxPoint& defval=wxDefaultPosition, const wxString& separators=L",");
|
|
|
|
extern bool TryParse( wxSize& dest, const wxString& src, const wxSize& defval=wxDefaultSize, const wxString& separators=L",");
|
|
|
|
extern bool TryParse( wxRect& dest, const wxString& src, const wxRect& defval=wxDefaultRect, const wxString& separators=L",");
|
|
|
|
|
2009-11-08 17:18:34 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// ParsedAssignmentString
|
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// This class is a simple helper for parsing INI-style assignments, in the typical form of:
|
|
|
|
// variable = value
|
|
|
|
// filename = SomeString.txt
|
|
|
|
// integer = 15
|
|
|
|
//
|
|
|
|
// This parser supports both '//' and ';' at the head of a line as indicators of a commented
|
|
|
|
// line, and such a line will return empty strings for l- and r-value.
|
|
|
|
//
|
|
|
|
// No type handling is performed -- the user must manually parse strings into integers, etc.
|
|
|
|
// For advanced "fully functional" ini file parsing, consider using wxFileConfig instead.
|
|
|
|
//
|
|
|
|
struct ParsedAssignmentString
|
|
|
|
{
|
|
|
|
wxString lvalue;
|
|
|
|
wxString rvalue;
|
|
|
|
bool IsComment;
|
|
|
|
|
|
|
|
ParsedAssignmentString( const wxString& src );
|
|
|
|
};
|
|
|
|
|
2010-10-04 17:12:28 +00:00
|
|
|
// ======================================================================================
|
|
|
|
// FastFormatAscii / FastFormatUnicode (overview!)
|
|
|
|
// ======================================================================================
|
|
|
|
// Fast formatting of ASCII or Unicode text. These classes uses a series of thread-local
|
|
|
|
// format buffers that are allocated only once and grown to accommodate string formatting
|
|
|
|
// needs. Because the buffers are thread-local, no thread synch objects are required in
|
|
|
|
// order to format strings, allowing for multi-threaded string formatting operations to be
|
|
|
|
// performed with maximum efficiency. This class also reduces the overhead typically required
|
|
|
|
// to allocate string buffers off the heap.
|
|
|
|
//
|
|
|
|
// Drawbacks:
|
|
|
|
// * Some overhead is added to the creation and destruction of threads, however since thread
|
|
|
|
// construction is a typically slow process, and often avoided to begin with, this should
|
|
|
|
// be a sound trade-off.
|
|
|
|
//
|
|
|
|
// Notes:
|
|
|
|
// * conversion to wxString requires a heap allocation.
|
|
|
|
// * FastFormatUnicode can accept either UTF8 or UTF16/32 (wchar_t) input, but FastFormatAscii
|
|
|
|
// accepts Ascii/UTF8 only.
|
|
|
|
//
|
|
|
|
|
2010-08-03 22:18:19 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2010-10-04 17:12:28 +00:00
|
|
|
// FastFormatAscii
|
2010-08-03 22:18:19 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
2010-10-04 17:12:28 +00:00
|
|
|
|
2010-08-03 22:18:19 +00:00
|
|
|
class FastFormatAscii
|
|
|
|
{
|
|
|
|
protected:
|
2010-10-18 01:40:49 +00:00
|
|
|
ScopedAlignedAlloc<char,16>* m_dest;
|
2010-08-03 22:18:19 +00:00
|
|
|
bool m_deleteDest;
|
2010-10-18 01:40:49 +00:00
|
|
|
uint m_Length;
|
2010-08-03 22:18:19 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
FastFormatAscii();
|
|
|
|
~FastFormatAscii() throw();
|
|
|
|
FastFormatAscii& Write( const char* fmt, ... );
|
|
|
|
FastFormatAscii& WriteV( const char* fmt, va_list argptr );
|
|
|
|
|
2010-10-04 17:12:28 +00:00
|
|
|
void Clear();
|
2010-09-04 14:11:50 +00:00
|
|
|
bool IsEmpty() const;
|
2010-10-18 01:40:49 +00:00
|
|
|
uint Length() const { return m_Length; }
|
2010-09-04 14:11:50 +00:00
|
|
|
|
2010-08-31 05:14:00 +00:00
|
|
|
const char* c_str() const { return m_dest->GetPtr(); }
|
|
|
|
operator const char*() const { return m_dest->GetPtr(); }
|
2010-08-03 22:18:19 +00:00
|
|
|
|
|
|
|
const wxString GetString() const;
|
2010-08-31 05:14:00 +00:00
|
|
|
//operator wxString() const;
|
2010-10-18 01:40:49 +00:00
|
|
|
|
|
|
|
FastFormatAscii& operator+=(const wxString& s)
|
|
|
|
{
|
|
|
|
Write( "%ls", s.c_str() );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
FastFormatAscii& operator+=(const wxChar* psz )
|
|
|
|
{
|
|
|
|
Write( "%ls", psz );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
FastFormatAscii& operator+=(const char* psz )
|
|
|
|
{
|
|
|
|
Write( "%s", psz );
|
|
|
|
return *this;
|
|
|
|
}
|
2010-08-03 22:18:19 +00:00
|
|
|
};
|
|
|
|
|
2010-10-04 17:12:28 +00:00
|
|
|
// --------------------------------------------------------------------------------------
|
|
|
|
// FastFormatUnicode
|
|
|
|
// --------------------------------------------------------------------------------------
|
2010-08-03 22:18:19 +00:00
|
|
|
class FastFormatUnicode
|
|
|
|
{
|
|
|
|
protected:
|
2010-10-18 01:40:49 +00:00
|
|
|
ScopedAlignedAlloc<char,16>* m_dest;
|
2010-08-03 22:18:19 +00:00
|
|
|
bool m_deleteDest;
|
2010-10-18 01:40:49 +00:00
|
|
|
uint m_Length;
|
2010-08-03 22:18:19 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
FastFormatUnicode();
|
|
|
|
~FastFormatUnicode() throw();
|
|
|
|
|
|
|
|
FastFormatUnicode& Write( const char* fmt, ... );
|
|
|
|
FastFormatUnicode& Write( const wxChar* fmt, ... );
|
|
|
|
FastFormatUnicode& WriteV( const char* fmt, va_list argptr );
|
|
|
|
FastFormatUnicode& WriteV( const wxChar* fmt, va_list argptr );
|
2010-06-09 17:37:11 +00:00
|
|
|
|
2010-10-04 17:12:28 +00:00
|
|
|
void Clear();
|
2010-09-04 14:11:50 +00:00
|
|
|
bool IsEmpty() const;
|
2010-10-18 01:40:49 +00:00
|
|
|
uint Length() const { return m_Length; }
|
|
|
|
|
|
|
|
FastFormatUnicode& ToUpper();
|
|
|
|
FastFormatUnicode& ToLower();
|
2010-09-04 14:11:50 +00:00
|
|
|
|
2010-08-31 05:14:00 +00:00
|
|
|
const wxChar* c_str() const { return (const wxChar*)m_dest->GetPtr(); }
|
|
|
|
operator const wxChar*() const { return (const wxChar*)m_dest->GetPtr(); }
|
|
|
|
operator wxString() const { return (const wxChar*)m_dest->GetPtr(); }
|
2010-10-18 01:40:49 +00:00
|
|
|
|
|
|
|
FastFormatUnicode& operator+=(const wxString& s)
|
|
|
|
{
|
|
|
|
Write( L"%s", s.c_str() );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
FastFormatUnicode& operator+=(const wxChar* psz )
|
|
|
|
{
|
|
|
|
Write( L"%s", psz );
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
FastFormatUnicode& operator+=(const char* psz );
|
2010-08-03 22:18:19 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
extern bool pxParseAssignmentString( const wxString& src, wxString& ldest, wxString& rdest );
|
2010-05-20 12:23:13 +00:00
|
|
|
|
2010-10-18 01:40:49 +00:00
|
|
|
#define pxsFmt FastFormatUnicode().Write
|
|
|
|
#define pxsFmtV FastFormatUnicode().WriteV
|
|
|
|
|
2010-11-17 05:49:11 +00:00
|
|
|
#define pxsPtr(ptr) pxsFmt("0x%08X", (ptr)).c_str()
|
|
|
|
|
2010-10-18 01:40:49 +00:00
|
|
|
extern wxString& operator+=(wxString& str1, const FastFormatUnicode& str2);
|
|
|
|
extern wxString operator+(const wxString& str1, const FastFormatUnicode& str2);
|
|
|
|
extern wxString operator+(const wxChar* str1, const FastFormatUnicode& str2);
|
|
|
|
|
2009-07-03 00:49:40 +00:00
|
|
|
|
|
|
|
//////////////////////////////////////////////////////////////////////////////////////////
|
|
|
|
// Custom internal sprintf functions, which are ASCII only (even in UNICODE builds)
|
|
|
|
//
|
|
|
|
// These functions are useful since they are ASCII always, even under Unicode. Typically
|
|
|
|
// even in a unicode app.
|
|
|
|
|
|
|
|
extern void ssprintf(std::string& dest, const char* fmt, ...);
|
|
|
|
extern void ssappendf(std::string& dest, const char* format, ...);
|
|
|
|
extern void vssprintf(std::string& dest, const char* format, va_list args);
|
|
|
|
extern void vssappendf(std::string& dest, const char* format, va_list args);
|
|
|
|
|
|
|
|
extern std::string fmt_string( const char* fmt, ... );
|
|
|
|
extern std::string vfmt_string( const char* fmt, va_list args );
|