KiCad PCB EDA Suite
Loading...
Searching...
No Matches
json_common.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#ifndef JSON_COMMON_H
21#define JSON_COMMON_H
22
23/***********************************************************************************************************************
24 * If we are compiling on Apple with Clang >= 17, the version of LLVM no longer includes a generic template for
25 * char_traits for char types which are not specified in the C++ standard. We define our own here for types required by
26 * the JSON library.
27 *
28 * From: https://github.com/llvm/llvm-project/commit/c3668779c13596e223c26fbd49670d18cd638c40
29 *
30 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
31 * See https://llvm.org/LICENSE.txt for license information.
32 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
33 *
34 **********************************************************************************************************************/
35
36#ifdef __APPLE__
37#if __clang_major__ >= 17
38
39#include <wx/unichar.h>
40
41template <>
42struct std::char_traits<wxUniChar>
43{
44 using char_type = wxUniChar;
45 using int_type = int;
46 using off_type = std::streamoff;
47 using pos_type = std::streampos;
48 using state_type = mbstate_t;
49
50 static inline void assign( char_type& __c1, const char_type& __c2 ) noexcept { __c1 = __c2; }
51
52 static inline bool eq( char_type __c1, char_type __c2 ) noexcept { return __c1 == __c2; }
53
54 static inline bool lt( char_type __c1, char_type __c2 ) noexcept { return __c1 < __c2; }
55
56 static constexpr int compare( const char_type* __s1, const char_type* __s2, size_t __n )
57 {
58 for( ; __n; --__n, ++__s1, ++__s2 )
59 {
60 if( lt( *__s1, *__s2 ) )
61 return -1;
62
63 if( lt( *__s2, *__s1 ) )
64 return 1;
65 }
66
67 return 0;
68 }
69
70 static size_t length( const char_type* __s )
71 {
72 size_t __len = 0;
73
74 for( ; !eq( *__s, char_type( 0 ) ); ++__s )
75 ++__len;
76
77 return __len;
78 }
79
80 static constexpr const char_type* find( const char_type* __s, size_t __n, const char_type& __a )
81 {
82 for( ; __n; --__n )
83 {
84 if( eq( *__s, __a ) )
85 return __s;
86 ++__s;
87 }
88
89 return nullptr;
90 }
91
92 static constexpr char_type* move( char_type* __s1, const char_type* __s2, size_t __n )
93 {
94 if( __n == 0 )
95 return __s1;
96
97 char_type* __r = __s1;
98
99 if( __s1 < __s2 )
100 {
101 for( ; __n; --__n, ++__s1, ++__s2 )
102 assign( *__s1, *__s2 );
103 }
104 else if( __s2 < __s1 )
105 {
106 __s1 += __n;
107 __s2 += __n;
108
109 for( ; __n; --__n )
110 assign( *--__s1, *--__s2 );
111 }
112
113 return __r;
114 }
115
116 static constexpr char_type* copy( char_type* __s1, const char_type* __s2, size_t __n )
117 {
118 char_type* __r = __s1;
119
120 for( ; __n; --__n, ++__s1, ++__s2 )
121 assign( *__s1, *__s2 );
122
123 return __r;
124 }
125
126 static char_type* assign( char_type* __s, size_t __n, char_type __a )
127 {
128 char_type* __r = __s;
129
130 for( ; __n; --__n, ++__s )
131 assign( *__s, __a );
132
133 return __r;
134 }
135
136 static inline constexpr int_type not_eof( int_type __c ) noexcept
137 {
138 return eq_int_type( __c, eof() ) ? ~eof() : __c;
139 }
140
141 static inline char_type to_char_type( int_type __c ) noexcept { return char_type( __c ); }
142
143 static inline int_type to_int_type( char_type __c ) noexcept { return static_cast<int_type>( __c ); }
144
145 static inline constexpr bool eq_int_type( int_type __c1, int_type __c2 ) noexcept { return __c1 == __c2; }
146
147 static inline constexpr int_type eof() noexcept { return static_cast<int_type>( EOF ); }
148};
149
150#endif
151#endif
152
153#include <nlohmann/json.hpp>
154#include <kicommon.h>
155
160class KICOMMON_API JSON_COMMON_EXPORT_STUB final : public nlohmann::json
161{
162};
163
164#endif
This is simply a "stub" meant to inform MSVC when compiling shared libraries that it can find templat...
Definition: json_common.h:161
#define KICOMMON_API
Definition: kicommon.h:28