KiCad PCB EDA Suite
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, boost::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.get();
44
45 if( v.download_url )
46 j["download_url"] = v.download_url.get();
47
48 if( v.download_sha256 )
49 j["download_sha256"] = v.download_sha256.get();
50
51 if( v.download_size )
52 j["download_size"] = v.download_size.get();
53
54 if( v.install_size )
55 j["install_size"] = v.install_size.get();
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.get();
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.get();
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.get();
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.get();
158
159 if( r.manifests )
160 j["manifests"] = r.manifests.get();
161
162 if( r.maintainer )
163 j["maintainer"] = r.maintainer.get();
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}
E_SERIE r
Definition: eserie.cpp:41
nlohmann::json json
Definition: gerbview.cpp:43
void to_optional(const json &j, const char *key, boost::optional< T > &dest)
Definition: pcm_data.cpp:25
void to_json(json &j, const PACKAGE_VERSION &v)
Definition: pcm_data.cpp:36
void from_json(const json &j, PACKAGE_VERSION &v)
Definition: pcm_data.cpp:68
< Package version metadata Package metadata
Definition: pcm_data.h:74
boost::optional< uint64_t > download_size
Definition: pcm_data.h:79
boost::optional< int > version_epoch
Definition: pcm_data.h:76
wxString version
Definition: pcm_data.h:75
PCM_PACKAGE_VERSION_STATUS status
Definition: pcm_data.h:81
boost::optional< wxString > download_sha256
Definition: pcm_data.h:78
boost::optional< wxString > kicad_version_max
Definition: pcm_data.h:84
boost::optional< uint64_t > install_size
Definition: pcm_data.h:80
boost::optional< wxString > download_url
Definition: pcm_data.h:77
std::vector< std::string > platforms
Definition: pcm_data.h:82
wxString kicad_version
Definition: pcm_data.h:83
std::vector< std::string > keep_on_update
Definition: pcm_data.h:85
Repository reference to a resource.
Definition: pcm_data.h:95
wxString description
Definition: pcm_data.h:97
wxString description_full
Definition: pcm_data.h:98
wxString identifier
Definition: pcm_data.h:99
wxString license
Definition: pcm_data.h:103
std::vector< std::string > tags
Definition: pcm_data.h:105
STRING_MAP resources
Definition: pcm_data.h:104
boost::optional< PCM_CONTACT > maintainer
Definition: pcm_data.h:102
wxString name
Definition: pcm_data.h:96
std::vector< PACKAGE_VERSION > versions
Definition: pcm_data.h:107
PCM_PACKAGE_TYPE type
Definition: pcm_data.h:100
std::vector< std::string > keep_on_update
Definition: pcm_data.h:106
PCM_CONTACT author
Definition: pcm_data.h:101
Package installation entry.
Definition: pcm_data.h:122
Repository metadata.
Definition: pcm_data.h:113