KiCad PCB EDA Suite
pcm_data.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 (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#ifndef PCM_DATA_H_
22#define PCM_DATA_H_
23
24#include "core/wx_stl_compat.h"
25
26#include <map>
27#include <nlohmann/json.hpp>
28#include <optional>
29#include <string>
30#include <tuple>
31#include <vector>
32#include <wx/string.h>
33
34
35using STRING_MAP = std::map<std::string, wxString>;
36using nlohmann::json;
37
38
41{
46};
47
48
51{
57};
58
59
62{
63 wxString name;
65};
66
67
68// MSVC, wxWidgets and nlohmann_json don't play nice together and
69// create linker errors about redefinition of some vector members
70// if an attempt to use vector<wxString> in json is made.
71
74{
75 wxString version;
76 std::optional<int> version_epoch;
77 std::optional<wxString> download_url;
78 std::optional<wxString> download_sha256;
79 std::optional<uint64_t> download_size;
80 std::optional<uint64_t> install_size;
82 std::vector<std::string> platforms;
83 wxString kicad_version;
84 std::optional<wxString> kicad_version_max;
85 std::vector<std::string> keep_on_update;
86
87 // Not serialized fields
88 std::tuple<int, int, int, int> parsed_version; // Full version tuple for sorting
89 bool compatible = true;
90};
91
92
95{
96 wxString name;
97 wxString description;
99 wxString identifier;
102 std::optional<PCM_CONTACT> maintainer;
103 wxString license;
105 std::vector<std::string> tags;
106 std::vector<std::string> keep_on_update;
107 std::vector<PACKAGE_VERSION> versions;
108};
109
110
113{
114 wxString url;
115 std::optional<wxString> sha256;
117};
118
119
122{
123 wxString name;
125 std::optional<PCM_RESOURCE_REFERENCE> resources;
126 std::optional<PCM_RESOURCE_REFERENCE> manifests;
127 std::optional<PCM_CONTACT> maintainer;
128
129 // Not serialized fields
130 std::vector<PCM_PACKAGE> package_list;
131 // pkg id to index of package from package_list for quick lookup
132 std::unordered_map<wxString, size_t> package_map;
133};
134
135
138{
144 bool pinned;
145
146 // Not serialized fields
148};
149
150
151// Teaching json en/decoder to understand wxStrings
152namespace nlohmann
153{
154template <>
155struct adl_serializer<wxString>
156{
157 static void to_json( json& j, const wxString& s ) { j = s.ToUTF8(); }
158
159 static void from_json( const json& j, wxString& s )
160 {
161 s = wxString::FromUTF8( j.get<std::string>().c_str() );
162 }
163};
164} // namespace nlohmann
165
166
168 { PT_INVALID, "invalid" },
169 { PT_PLUGIN, "plugin" },
170 { PT_LIBRARY, "library" },
171 { PT_COLORTHEME, "colortheme" },
172 } )
173
174
176 {
177 { PVS_INVALID, "invalid" },
178 { PVS_STABLE, "stable" },
179 { PVS_TESTING, "testing" },
180 { PVS_DEVELOPMENT, "development" },
181 { PVS_DEPRECATED, "deprecated" },
182 } )
183
184
185// Following are templates and definitions for en/decoding above structs
186// to/from json
187
188NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( PCM_CONTACT, name, contact )
189
190
191void to_json( json& j, const PACKAGE_VERSION& v );
192void from_json( const json& j, PACKAGE_VERSION& v );
193
194
195void to_json( json& j, const PCM_PACKAGE& p );
196void from_json( const json& j, PCM_PACKAGE& p );
197
198
199void to_json( json& j, const PCM_RESOURCE_REFERENCE& r );
200void from_json( const json& j, PCM_RESOURCE_REFERENCE& r );
201
202
203void to_json( json& j, const PCM_REPOSITORY& r );
204void from_json( const json& j, PCM_REPOSITORY& r );
205
206
207void to_json( json& j, const PCM_INSTALLATION_ENTRY& e );
208void from_json( const json& j, PCM_INSTALLATION_ENTRY& e );
209
210
211#endif // PCM_DATA_H_
const char * name
Definition: DXF_plotter.cpp:56
std::map< wxString, wxString > STRING_MAP
Definition: env_vars.cpp:27
E_SERIE r
Definition: eserie.cpp:41
nlohmann::json json
Definition: gerbview.cpp:44
PCM_PACKAGE_TYPE
< Supported package types
Definition: pcm_data.h:41
@ PT_COLORTHEME
Definition: pcm_data.h:45
@ PT_INVALID
Definition: pcm_data.h:42
@ PT_PLUGIN
Definition: pcm_data.h:43
@ PT_LIBRARY
Definition: pcm_data.h:44
PCM_PACKAGE_VERSION_STATUS
Definition: pcm_data.h:51
@ PVS_INVALID
Definition: pcm_data.h:52
@ PVS_DEVELOPMENT
Definition: pcm_data.h:55
@ PVS_STABLE
Definition: pcm_data.h:53
@ PVS_TESTING
Definition: pcm_data.h:54
@ PVS_DEPRECATED
Definition: pcm_data.h:56
void to_json(json &j, const PCM_PACKAGE &p)
Definition: pcm_data.cpp:89
NLOHMANN_JSON_SERIALIZE_ENUM(PCM_PACKAGE_TYPE, { { PT_INVALID, "invalid" }, { PT_PLUGIN, "plugin" }, { PT_LIBRARY, "library" }, { PT_COLORTHEME, "colortheme" }, }) NLOHMANN_JSON_SERIALIZE_ENUM(PCM_PACKAGE_VERSION_STATUS
void from_json(const json &j, PACKAGE_VERSION &v)
Definition: pcm_data.cpp:68
< Package version metadata Package metadata
Definition: pcm_data.h:74
std::optional< uint64_t > download_size
Definition: pcm_data.h:79
bool compatible
Definition: pcm_data.h:89
std::optional< uint64_t > install_size
Definition: pcm_data.h:80
wxString version
Definition: pcm_data.h:75
PCM_PACKAGE_VERSION_STATUS status
Definition: pcm_data.h:81
std::optional< wxString > kicad_version_max
Definition: pcm_data.h:84
std::optional< wxString > download_url
Definition: pcm_data.h:77
std::optional< wxString > download_sha256
Definition: pcm_data.h:78
std::optional< int > version_epoch
Definition: pcm_data.h:76
std::vector< std::string > platforms
Definition: pcm_data.h:82
wxString kicad_version
Definition: pcm_data.h:83
std::tuple< int, int, int, int > parsed_version
Definition: pcm_data.h:88
std::vector< std::string > keep_on_update
Definition: pcm_data.h:85
wxString name
Definition: pcm_data.h:63
STRING_MAP contact
Definition: pcm_data.h:64
Definition: pcm_data.h:138
wxString repository_name
Definition: pcm_data.h:142
PCM_PACKAGE package
Definition: pcm_data.h:139
uint64_t install_timestamp
Definition: pcm_data.h:143
wxString repository_id
Definition: pcm_data.h:141
wxString current_version
Definition: pcm_data.h:140
bool update_available
Definition: pcm_data.h:147
bool pinned
Definition: pcm_data.h:144
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
std::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
PCM_RESOURCE_REFERENCE packages
Definition: pcm_data.h:124
std::optional< PCM_CONTACT > maintainer
Definition: pcm_data.h:127
std::vector< PCM_PACKAGE > package_list
Definition: pcm_data.h:130
wxString name
Definition: pcm_data.h:123
std::optional< PCM_RESOURCE_REFERENCE > manifests
Definition: pcm_data.h:126
std::optional< PCM_RESOURCE_REFERENCE > resources
Definition: pcm_data.h:125
std::unordered_map< wxString, size_t > package_map
Definition: pcm_data.h:132
Repository metadata.
Definition: pcm_data.h:113
std::optional< wxString > sha256
Definition: pcm_data.h:115
uint64_t update_timestamp
Definition: pcm_data.h:116
static void from_json(const json &j, wxString &s)
Definition: pcm_data.h:159
static void to_json(json &j, const wxString &s)
Definition: pcm_data.h:157