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
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
20#ifndef JSON_COMMON_H
21#define JSON_COMMON_H
22
23/***********************************************************************************************************************
24 * If we are compiling against libc++ >= 19, 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#include <version>
37
38#if defined( _LIBCPP_VERSION )
39#if _LIBCPP_VERSION >= 190102
40
41#include <wx/unichar.h>
42
43template <>
44struct std::char_traits<wxUniChar>
45{
46 using char_type = wxUniChar;
47 using int_type = int;
48 using off_type = std::streamoff;
49 using pos_type = std::streampos;
50 using state_type = mbstate_t;
51
52 static inline void assign( char_type& __c1, const char_type& __c2 ) noexcept { __c1 = __c2; }
53
54 static inline bool eq( char_type __c1, char_type __c2 ) noexcept { return __c1 == __c2; }
55
56 static inline bool lt( char_type __c1, char_type __c2 ) noexcept { return __c1 < __c2; }
57
58 static constexpr int compare( const char_type* __s1, const char_type* __s2, size_t __n )
59 {
60 for( ; __n; --__n, ++__s1, ++__s2 )
61 {
62 if( lt( *__s1, *__s2 ) )
63 return -1;
64
65 if( lt( *__s2, *__s1 ) )
66 return 1;
67 }
68
69 return 0;
70 }
71
72 static size_t length( const char_type* __s )
73 {
74 size_t __len = 0;
75
76 for( ; !eq( *__s, char_type( 0 ) ); ++__s )
77 ++__len;
78
79 return __len;
80 }
81
82 static constexpr const char_type* find( const char_type* __s, size_t __n, const char_type& __a )
83 {
84 for( ; __n; --__n )
85 {
86 if( eq( *__s, __a ) )
87 return __s;
88 ++__s;
89 }
90
91 return nullptr;
92 }
93
94 static constexpr char_type* move( char_type* __s1, const char_type* __s2, size_t __n )
95 {
96 if( __n == 0 )
97 return __s1;
98
99 char_type* __r = __s1;
100
101 if( __s1 < __s2 )
102 {
103 for( ; __n; --__n, ++__s1, ++__s2 )
104 assign( *__s1, *__s2 );
105 }
106 else if( __s2 < __s1 )
107 {
108 __s1 += __n;
109 __s2 += __n;
110
111 for( ; __n; --__n )
112 assign( *--__s1, *--__s2 );
113 }
114
115 return __r;
116 }
117
118 static constexpr char_type* copy( char_type* __s1, const char_type* __s2, size_t __n )
119 {
120 char_type* __r = __s1;
121
122 for( ; __n; --__n, ++__s1, ++__s2 )
123 assign( *__s1, *__s2 );
124
125 return __r;
126 }
127
128 static char_type* assign( char_type* __s, size_t __n, char_type __a )
129 {
130 char_type* __r = __s;
131
132 for( ; __n; --__n, ++__s )
133 assign( *__s, __a );
134
135 return __r;
136 }
137
138 static inline constexpr int_type not_eof( int_type __c ) noexcept
139 {
140 return eq_int_type( __c, eof() ) ? ~eof() : __c;
141 }
142
143 static inline char_type to_char_type( int_type __c ) noexcept { return char_type( __c ); }
144
145 static inline int_type to_int_type( char_type __c ) noexcept { return static_cast<int_type>( __c ); }
146
147 static inline constexpr bool eq_int_type( int_type __c1, int_type __c2 ) noexcept { return __c1 == __c2; }
148
149 static inline constexpr int_type eof() noexcept { return static_cast<int_type>( EOF ); }
150};
151
152#endif
153#endif
154
155#include <nlohmann/json.hpp>
156#include <kicommon.h>
157
162class KICOMMON_API JSON_COMMON_EXPORT_STUB final : public nlohmann::json
163{
164};
165
166#endif
This is simply a "stub" meant to inform MSVC when compiling shared libraries that it can find templat...
#define KICOMMON_API
Definition kicommon.h:27