2011-09-01 12:54:34 +00:00
|
|
|
/**
|
|
|
|
* @file macros.h
|
|
|
|
* @brief This file contains miscellaneous helper definitions and functions.
|
|
|
|
*/
|
2007-05-06 16:03:28 +00:00
|
|
|
|
|
|
|
#ifndef MACROS_H
|
|
|
|
#define MACROS_H
|
2007-06-05 12:10:51 +00:00
|
|
|
|
2010-10-20 20:24:26 +00:00
|
|
|
#include <wx/wx.h>
|
|
|
|
|
2011-02-02 15:31:48 +00:00
|
|
|
/**
|
|
|
|
* Macro TO_UTF8
|
|
|
|
* converts a wxString to a UTF8 encoded C string for all wxWidgets build modes.
|
|
|
|
* wxstring is a wxString, not a wxT() or _(). The scope of the return value
|
|
|
|
* is very limited and volatile, but can be used with printf() style functions well.
|
2013-04-28 15:43:26 +00:00
|
|
|
* NOTE: Trying to convert it to a function is tricky because of the
|
|
|
|
* type of the parameter!
|
2011-02-02 15:31:48 +00:00
|
|
|
*/
|
|
|
|
#define TO_UTF8( wxstring ) ( (const char*) (wxstring).utf8_str() )
|
|
|
|
|
|
|
|
/**
|
2013-03-31 13:27:46 +00:00
|
|
|
* function FROM_UTF8
|
2011-02-02 15:31:48 +00:00
|
|
|
* converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
|
|
|
|
*/
|
2011-03-24 00:15:33 +00:00
|
|
|
static inline wxString FROM_UTF8( const char* cstring )
|
2011-03-02 11:03:06 +00:00
|
|
|
{
|
|
|
|
wxString line = wxString::FromUTF8( cstring );
|
2011-09-01 12:54:34 +00:00
|
|
|
|
2011-03-02 11:03:06 +00:00
|
|
|
if( line.IsEmpty() ) // happens when cstring is not a valid UTF8 sequence
|
|
|
|
line = wxConvCurrent->cMB2WC( cstring ); // try to use locale conversion
|
2011-09-01 12:54:34 +00:00
|
|
|
|
2011-03-02 11:03:06 +00:00
|
|
|
return line;
|
|
|
|
}
|
2011-03-24 00:15:33 +00:00
|
|
|
|
2009-04-17 06:23:07 +00:00
|
|
|
/**
|
|
|
|
* Function GetChars
|
2010-08-03 02:13:33 +00:00
|
|
|
* returns a wxChar* to the actual character data within a wxString, and is
|
|
|
|
* helpful for passing strings to wxString::Printf(wxT("%s"), GetChars(wxString) )
|
|
|
|
* <p>
|
2010-12-14 15:56:30 +00:00
|
|
|
* wxChar is defined to be
|
|
|
|
* <ul>
|
2010-08-03 02:13:33 +00:00
|
|
|
* <li> standard C style char when wxUSE_UNICODE==0 </li>
|
|
|
|
* <li> wchar_t when wxUSE_UNICODE==1 (the default). </li>
|
2010-12-14 15:56:30 +00:00
|
|
|
* </ul>
|
2010-08-03 02:13:33 +00:00
|
|
|
* i.e. it depends on how the wxWidgets library was compiled. There was a period
|
|
|
|
* during the development of wxWidgets 2.9 when GetData() was missing, so this
|
|
|
|
* function was used to provide insulation from that design change. It may
|
|
|
|
* no longer be needed, and is harmless. GetData() seems to be an acceptable
|
|
|
|
* alternative in all cases now.
|
2009-04-17 06:23:07 +00:00
|
|
|
*/
|
2010-08-03 02:13:33 +00:00
|
|
|
static inline const wxChar* GetChars( const wxString& s )
|
2009-04-17 06:23:07 +00:00
|
|
|
{
|
2009-12-29 10:35:11 +00:00
|
|
|
#if wxCHECK_VERSION( 2, 9, 0 )
|
|
|
|
return (const wxChar*) s.c_str();
|
2009-04-17 06:23:07 +00:00
|
|
|
#else
|
|
|
|
return s.GetData();
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2013-05-01 17:32:36 +00:00
|
|
|
// This really needs a function? well, it is used *a lot* of times
|
|
|
|
template<class T> inline void NEGATE( T &x ) { x = -x; }
|
2009-12-29 10:35:11 +00:00
|
|
|
|
2011-08-29 19:50:05 +00:00
|
|
|
/// # of elements in an array
|
2010-01-29 23:55:49 +00:00
|
|
|
#define DIM( x ) unsigned( sizeof(x) / sizeof( (x)[0] ) ) // not size_t
|
2008-11-09 02:57:42 +00:00
|
|
|
|
2013-05-02 18:06:58 +00:00
|
|
|
/// Exchange two values
|
|
|
|
// std::swap works only with arguments of the same type (which is saner);
|
|
|
|
// here the compiler will figure out what to do (I hope to get rid of
|
|
|
|
// this soon or late)
|
2013-04-28 15:43:26 +00:00
|
|
|
template<class T, class T2> inline void EXCHG( T& a, T2& b )
|
|
|
|
{
|
|
|
|
T temp = a;
|
|
|
|
a = b;
|
|
|
|
b = temp;
|
|
|
|
}
|
2008-10-30 10:55:46 +00:00
|
|
|
|
2007-05-06 16:03:28 +00:00
|
|
|
#endif /* ifdef MACRO_H */
|