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
126 if( j.contains( "tags" ) )
127 j.at( "tags" ).get_to( p.tags );
128
129 if( j.contains( "keep_on_update" ) )
130 j.at( "keep_on_update" ).get_to( p.keep_on_update );
131}
132
133
135{
136 j = json{ { "url", r.url }, { "update_timestamp", r.update_timestamp } };
137
138 if( r.sha256 )
139 j["sha256"] = *r.sha256;
140}
141
142
144{
145 j.at( "url" ).get_to( r.url );
146 j.at( "update_timestamp" ).get_to( r.update_timestamp );
147
148 to_optional( j, "sha256", r.sha256 );
149}
150
151
152void to_json( json& j, const PCM_REPOSITORY& r )
153{
154 j = json{ { "name", r.name }, { "packages", r.packages } };
155
156 if( r.resources )
157 j["resources"] = *r.resources;
158
159 if( r.manifests )
160 j["manifests"] = *r.manifests;
161
162 if( r.maintainer )
163 j["maintainer"] = *r.maintainer;
164}
165
166
167void from_json( const json& j, PCM_REPOSITORY& r )
168{
169 j.at( "name" ).get_to( r.name );
170 j.at( "packages" ).get_to( r.packages );
171
172 to_optional( j, "resources", r.resources );
173 to_optional( j, "manifests", r.manifests );
174 to_optional( j, "maintainer", r.maintainer );
175}
176
177
179{
180 j = json{ { "package", e.package },
181 { "current_version", e.current_version },
182 { "repository_id", e.repository_id },
183 { "repository_name", e.repository_name },
184 { "install_timestamp", e.install_timestamp },
185 { "pinned", e.pinned } };
186}
187
188
190{
191 j.at( "package" ).get_to( e.package );
192 j.at( "current_version" ).get_to( e.current_version );
193 j.at( "repository_id" ).get_to( e.repository_id );
194 j.at( "repository_name" ).get_to( e.repository_name );
195 j.at( "install_timestamp" ).get_to( e.install_timestamp );
196
197 e.pinned = false;
198 if( j.contains( "pinned" ) )
199 j.at( "pinned" ).get_to( e.pinned );
200}
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
< Package version metadata Package metadata
Definition: pcm_data.h:75
std::optional< uint64_t > download_size
Definition: pcm_data.h:80
std::optional< uint64_t > install_size
Definition: pcm_data.h:81
wxString version
Definition: pcm_data.h:76
PCM_PACKAGE_VERSION_STATUS status
Definition: pcm_data.h:82
std::optional< wxString > kicad_version_max
Definition: pcm_data.h:85
std::optional< wxString > download_url
Definition: pcm_data.h:78
std::optional< wxString > download_sha256
Definition: pcm_data.h:79
std::optional< int > version_epoch
Definition: pcm_data.h:77
std::vector< std::string > platforms
Definition: pcm_data.h:83
wxString kicad_version
Definition: pcm_data.h:84
std::vector< std::string > keep_on_update
Definition: pcm_data.h:86
Definition: pcm_data.h:139
wxString repository_name
Definition: pcm_data.h:143
PCM_PACKAGE package
Definition: pcm_data.h:140
uint64_t install_timestamp
Definition: pcm_data.h:144
wxString repository_id
Definition: pcm_data.h:142
wxString current_version
Definition: pcm_data.h:141
bool pinned
Definition: pcm_data.h:145
Repository reference to a resource.
Definition: pcm_data.h:96
wxString description
Definition: pcm_data.h:98
wxString description_full
Definition: pcm_data.h:99
wxString identifier
Definition: pcm_data.h:100
wxString license
Definition: pcm_data.h:104
std::vector< std::string > tags
Definition: pcm_data.h:106
STRING_MAP resources
Definition: pcm_data.h:105
std::optional< PCM_CONTACT > maintainer
Definition: pcm_data.h:103
wxString name
Definition: pcm_data.h:97
std::vector< PACKAGE_VERSION > versions
Definition: pcm_data.h:108
PCM_PACKAGE_TYPE type
Definition: pcm_data.h:101
std::vector< std::string > keep_on_update
Definition: pcm_data.h:107
PCM_CONTACT author
Definition: pcm_data.h:102
Package installation entry.
Definition: pcm_data.h:123
PCM_RESOURCE_REFERENCE packages
Definition: pcm_data.h:125
std::optional< PCM_CONTACT > maintainer
Definition: pcm_data.h:128
wxString name
Definition: pcm_data.h:124
std::optional< PCM_RESOURCE_REFERENCE > manifests
Definition: pcm_data.h:127
std::optional< PCM_RESOURCE_REFERENCE > resources
Definition: pcm_data.h:126
Repository metadata.
Definition: pcm_data.h:114
std::optional< wxString > sha256
Definition: pcm_data.h:116
uint64_t update_timestamp
Definition: pcm_data.h:117