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 <[email protected]>
5 * Copyright (C) 2007-2014 Jean-Pierre Charras, jp.charras at wanadoo.fr
6 * Copyright (C) 1992-2020 KiCad Developers, see AUTHORS.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 silencing 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
96#define TO_UTF8( wxstring ) ( (const char*) (wxstring).utf8_str() )
97
104#define TO_STR2(x) #x
105#define TO_STR(x) TO_STR2(x)
106
110static inline wxString FROM_UTF8( const char* cstring )
111{
112 wxString line = wxString::FromUTF8( cstring );
113
114 if( line.IsEmpty() ) // happens when cstring is not a valid UTF8 sequence
115 line = wxConvCurrent->cMB2WC( cstring ); // try to use locale conversion
116
117 return line;
118}
119
120#define UNIMPLEMENTED_FOR( type ) \
121 wxFAIL_MSG( wxString::Format( wxT( "%s: unimplemented for %s" ), __FUNCTION__, type ) )
122
123#endif // MACROS_H
static wxString FROM_UTF8(const char *cstring)
Convert a UTF8 encoded C string to a wxString for all wxWidgets build modes.
Definition: macros.h:110