KiCad PCB EDA Suite
Loading...
Searching...
No Matches
pcm_data.cpp
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) 2021 Andrew Lutsenko, anlutsenko at gmail dot com
5 * Copyright (C) 1992-2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#include "pcm_data.h"
22
23
24template <typename T>
25void to_optional( const json& j, const char* key, std::optional<T>& dest )
26{
27 if( j.contains( key ) )
28 {
29 T tmp;
30 j.at( key ).get_to( tmp );
31 dest.emplace( tmp );
32 }
33}
34
35
36void to_json( json& j, const PACKAGE_VERSION& v )
37{
38 j = json{ { "version", v.version },
39 { "status", v.status },
40 { "kicad_version", v.kicad_version } };
41
42 if( v.version_epoch )
43 j["version_epoch"] = *v.version_epoch;
44
45 if( v.download_url )
46 j["download_url"] = *v.download_url;
47
48 if( v.download_sha256 )
49 j["download_sha256"] = *v.download_sha256;
50
51 if( v.download_size )
52 j["download_size"] = *v.download_size;
53
54 if( v.install_size )
55 j["install_size"] = *v.install_size;
56
57 if( v.platforms.size() > 0 )
58 nlohmann::to_json( j["platforms"], v.platforms );
59
60 if( v.kicad_version_max )
61 j["kicad_version_max"] = *v.kicad_version_max;
62
63 if( v.keep_on_update.size() > 0 )
64 nlohmann::to_json( j["keep_on_update"], v.keep_on_update );
65}
66
67
68void from_json( const json& j, PACKAGE_VERSION& v )
69{
70 j.at( "version" ).get_to( v.version );
71 j.at( "status" ).get_to( v.status );
72 j.at( "kicad_version" ).get_to( v.kicad_version );
73
74 to_optional( j, "version_epoch", v.version_epoch );
75 to_optional( j, "download_url", v.download_url );
76 to_optional( j, "download_sha256", v.download_sha256 );
77 to_optional( j, "download_size", v.download_size );
78 to_optional( j, "install_size", v.install_size );
79 to_optional( j, "kicad_version_max", v.kicad_version_max );
80
81 if( j.contains( "platforms" ) )
82 j.at( "platforms" ).get_to( v.platforms );
83
84 if( j.contains( "keep_on_update" ) )
85 j.at( "keep_on_update" ).get_to( v.keep_on_update );
86}
87
88
89void to_json( json& j, const PCM_PACKAGE& p )
90{
91 j = json{ { "name", p.name },
92 { "description", p.description },
93 { "description_full", p.description_full },
94 { "identifier", p.identifier },
95 { "type", p.type },
96 { "author", p.author },
97 { "license", p.license },
98 { "resources", p.resources },
99 { "versions", p.versions } };
100
101 if( p.maintainer )
102 j["maintainer"] = *p.maintainer;
103
104 if( p.tags.size() > 0 )
105 j["tags"] = p.tags;
106
107 if( p.keep_on_update.size() > 0 )
108 j["keep_on_update"] = p.keep_on_update;
109}
110
111
112void from_json( const json& j, PCM_PACKAGE& p )
113{
114 j.at( "name" ).get_to( p.name );
115 j.at( "description" ).get_to( p.description );
116 j.at( "description_full" ).get_to( p.description_full );
117 j.at( "identifier" ).get_to( p.identifier );
118 j.at( "type" ).get_to( p.type );
119 j.at( "author" ).get_to( p.author );
120 j.at( "license" ).get_to( p.license );
121 j.at( "resources" ).get_to( p.resources );
122 j.at( "versions" ).get_to( p.versions );
123
124 to_optional( j, "maintainer", p.maintainer );
125 to_optional( j, "category", p.category );
126
127 if( p.type == PT_PLUGIN && p.category && p.category.value() == PC_FAB )
128 p.type = PT_FAB;
129
130 if( j.contains( "tags" ) )
131 j.at( "tags" ).get_to( p.tags );
132
133 if( j.contains( "keep_on_update" ) )
134 j.at( "keep_on_update" ).get_to( p.keep_on_update );
135}
136
137
139{
140 j = json{ { "url", r.url }, { "update_timestamp", r.update_timestamp } };
141
142 if( r.sha256 )
143 j["sha256"] = *r.sha256;
144}
145
146
148{
149 j.at( "url" ).get_to( r.url );
150 j.at( "update_timestamp" ).get_to( r.update_timestamp );
151
152 to_optional( j, "sha256", r.sha256 );
153}
154
155
156void to_json( json& j, const PCM_REPOSITORY& r )
157{
158 j = json{ { "name", r.name }, { "packages", r.packages } };
159
160 if( r.resources )
161 j["resources"] = *r.resources;
162
163 if( r.manifests )
164 j["manifests"] = *r.manifests;
165
166 if( r.maintainer )
167 j["maintainer"] = *r.maintainer;
168}
169
170
171void from_json( const json& j, PCM_REPOSITORY& r )
172{
173 j.at( "name" ).get_to( r.name );
174 j.at( "packages" ).get_to( r.packages );
175
176 to_optional( j, "resources", r.resources );
177 to_optional( j, "manifests", r.manifests );
178 to_optional( j, "maintainer", r.maintainer );
179}
180
181
183{
184 j = json{ { "package", e.package },
185 { "current_version", e.current_version },
186 { "repository_id", e.repository_id },
187 { "repository_name", e.repository_name },
188 { "install_timestamp", e.install_timestamp },
189 { "pinned", e.pinned } };
190}
191
192
194{
195 j.at( "package" ).get_to( e.package );
196 j.at( "current_version" ).get_to( e.current_version );
197 j.at( "repository_id" ).get_to( e.repository_id );
198 j.at( "repository_name" ).get_to( e.repository_name );
199 j.at( "install_timestamp" ).get_to( e.install_timestamp );
200
201 e.pinned = false;
202 if( j.contains( "pinned" ) )
203 j.at( "pinned" ).get_to( e.pinned );
204}
nlohmann::json json
Definition: gerbview.cpp:47
void to_json(json &j, const PACKAGE_VERSION &v)
Definition: pcm_data.cpp:36
void to_optional(const json &j, const char *key, std::optional< T > &dest)
Definition: pcm_data.cpp:25
void from_json(const json &j, PACKAGE_VERSION &v)
Definition: pcm_data.cpp:68
@ PC_FAB
Definition: pcm_data.h:55
@ PT_PLUGIN
Definition: pcm_data.h:44
@ PT_FAB
Definition: pcm_data.h:45
< Package version metadata Package metadata
Definition: pcm_data.h:84
std::optional< uint64_t > download_size
Definition: pcm_data.h:89
std::optional< uint64_t > install_size
Definition: pcm_data.h:90
wxString version
Definition: pcm_data.h:85
PCM_PACKAGE_VERSION_STATUS status
Definition: pcm_data.h:91
std::optional< wxString > kicad_version_max
Definition: pcm_data.h:94
std::optional< wxString > download_url
Definition: pcm_data.h:87
std::optional< wxString > download_sha256
Definition: pcm_data.h:88
std::optional< int > version_epoch
Definition: pcm_data.h:86
std::vector< std::string > platforms
Definition: pcm_data.h:92
wxString kicad_version
Definition: pcm_data.h:93
std::vector< std::string > keep_on_update
Definition: pcm_data.h:95
Definition: pcm_data.h:149
wxString repository_name
Definition: pcm_data.h:153
PCM_PACKAGE package
Definition: pcm_data.h:150
uint64_t install_timestamp
Definition: pcm_data.h:154
wxString repository_id
Definition: pcm_data.h:152
wxString current_version
Definition: pcm_data.h:151
bool pinned
Definition: pcm_data.h:155
Repository reference to a resource.
Definition: pcm_data.h:105
wxString description
Definition: pcm_data.h:107
wxString description_full
Definition: pcm_data.h:108
wxString identifier
Definition: pcm_data.h:109
wxString license
Definition: pcm_data.h:114
std::vector< std::string > tags
Definition: pcm_data.h:116
STRING_MAP resources
Definition: pcm_data.h:115
std::optional< PCM_CONTACT > maintainer
Definition: pcm_data.h:113
wxString name
Definition: pcm_data.h:106
std::vector< PACKAGE_VERSION > versions
Definition: pcm_data.h:118
std::optional< PCM_PLUGIN_CATEGORY > category
Definition: pcm_data.h:111
PCM_PACKAGE_TYPE type
Definition: pcm_data.h:110
std::vector< std::string > keep_on_update
Definition: pcm_data.h:117
PCM_CONTACT author
Definition: pcm_data.h:112
Package installation entry.
Definition: pcm_data.h:133
PCM_RESOURCE_REFERENCE packages
Definition: pcm_data.h:135
std::optional< PCM_CONTACT > maintainer
Definition: pcm_data.h:138
wxString name
Definition: pcm_data.h:134
std::optional< PCM_RESOURCE_REFERENCE > manifests
Definition: pcm_data.h:137
std::optional< PCM_RESOURCE_REFERENCE > resources
Definition: pcm_data.h:136
Repository metadata.
Definition: pcm_data.h:124
std::optional< wxString > sha256
Definition: pcm_data.h:126
uint64_t update_timestamp
Definition: pcm_data.h:127