KiCad PCB EDA Suite
macros.h
Go to the documentation of this file.
1 /*
2  * This program source code file is part of KiCad, a free EDA CAD application.
3  *
4  * Copyright (C) 2020 Ian McInerney <ian.s.mcinerney@ieee.org>
5  * Copyright (C) 2007-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
6  * Copyright (C) 1992-2020 KiCad Developers, see CHANGELOG.TXT for contributors.
7  *
8  * This program is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU General Public License
10  * as published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program; if not, you may find one here:
20  * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
21  * or you may search the http://www.gnu.org website for the version 2 license,
22  * or you may write to the Free Software Foundation, Inc.,
23  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24  */
25 
31 #ifndef MACROS_H
32 #define MACROS_H
33 
34 #include <wx/string.h>
35 
36 #if defined( __has_attribute )
37  #define KI_HAS_ATTRIBUTE( x ) __has_attribute( x )
38 #else
39  #define KI_HAS_ATTRIBUTE( x ) 0
40 #endif
41 
42 // Based on the declaration inside the LLVM source code
43 #if defined( __cplusplus ) && defined( __has_cpp_attribute )
44  #define KI_HAS_CPP_ATTRIBUTE( x ) __has_cpp_attribute( x )
45 #else
46  #define KI_HAS_CPP_ATTRIBUTE( x ) 0
47 #endif
48 
65 #if __cplusplus >= 201703L
66  // C++ 17 includes this macro on all compilers
67  #define KI_FALLTHROUGH [[fallthrough]]
68 
69 #elif KI_HAS_CPP_ATTRIBUTE( clang::fallthrough )
70  // Clang provides this attribute to silence the "-Wimplicit-fallthrough" warning
71  #define KI_FALLTHROUGH [[clang::fallthrough]]
72 
73 #elif KI_HAS_CPP_ATTRIBUTE( gnu::fallthrough )
74  // GNU-specific C++ attribute to sliencing the warning
75  #define KI_FALLTHROUGH [[gnu::fallthrough]]
76 
77 #elif defined( __GNUC__ ) && __GNUC__ >= 7
78  // GCC 7+ includes the "-Wimplicit-fallthrough" warning, and this attribute to silence it
79  #define KI_FALLTHROUGH __attribute__ ((fallthrough))
80 
81 #else
82  // In every other case, don't do anything
83  #define KI_FALLTHROUGH ( ( void ) 0 )
84 
85 #endif
86 
95 #define TO_UTF8( wxstring ) ( (const char*) (wxstring).utf8_str() )
96 
102 #define TO_STR2(x) #x
103 #define TO_STR(x) TO_STR2(x)
104 
109 static inline wxString FROM_UTF8( const char* cstring )
110 {
111  wxString line = wxString::FromUTF8( cstring );
112 
113  if( line.IsEmpty() ) // happens when cstring is not a valid UTF8 sequence
114  line = wxConvCurrent->cMB2WC( cstring ); // try to use locale conversion
115 
116  return line;
117 }
118 
119 #endif // MACROS_H
static wxString FROM_UTF8(const char *cstring)
function FROM_UTF8 converts a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:109