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 <boost/optional.hpp>
27 #include <map>
28 #include <nlohmann/json.hpp>
29 #include <string>
30 #include <tuple>
31 #include <vector>
32 #include <wx/string.h>
33 
34 
35 using STRING_MAP = std::map<std::string, wxString>;
36 using 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  boost::optional<int> version_epoch;
77  boost::optional<wxString> download_url;
78  boost::optional<wxString> download_sha256;
79  boost::optional<uint64_t> download_size;
80  boost::optional<uint64_t> install_size;
82  std::vector<std::string> platforms;
83  wxString kicad_version;
84  boost::optional<wxString> kicad_version_max;
85 
86  // Not serialized fields
87  std::tuple<int, int, int, int> parsed_version; // Full version tuple for sorting
88  bool compatible;
89 };
90 
91 
94 {
95  wxString name;
96  wxString description;
97  wxString description_full;
98  wxString identifier;
101  boost::optional<PCM_CONTACT> maintainer;
102  wxString license;
104  std::vector<std::string> tags;
105  std::vector<PACKAGE_VERSION> versions;
106 };
107 
108 
111 {
112  wxString url;
113  boost::optional<wxString> sha256;
115 };
116 
117 
120 {
121  wxString name;
123  boost::optional<PCM_RESOURCE_REFERENCE> resources;
124  boost::optional<PCM_RESOURCE_REFERENCE> manifests;
125  boost::optional<PCM_CONTACT> maintainer;
126 
127  // Not serialized fields
128  std::vector<PCM_PACKAGE> package_list;
129 };
130 
131 
134 {
136  wxString current_version;
137  wxString repository_id;
138  wxString repository_name;
140 };
141 
142 
143 // Teaching json en/decoder to understand wxStrings
144 namespace nlohmann
145 {
146 template <>
147 struct adl_serializer<wxString>
148 {
149  static void to_json( json& j, const wxString& s ) { j = s.ToUTF8(); }
150 
151  static void from_json( const json& j, wxString& s )
152  {
153  s = wxString::FromUTF8( j.get<std::string>().c_str() );
154  }
155 };
156 } // namespace nlohmann
157 
158 
160  { PT_INVALID, "invalid" },
161  { PT_PLUGIN, "plugin" },
162  { PT_LIBRARY, "library" },
163  { PT_COLORTHEME, "colortheme" },
164  } )
165 
166 
168  {
169  { PVS_INVALID, "invalid" },
170  { PVS_STABLE, "stable" },
171  { PVS_TESTING, "testing" },
172  { PVS_DEVELOPMENT, "development" },
173  { PVS_DEPRECATED, "deprecated" },
174  } )
175 
176 
177 // Following are templates and definitions for en/decoding above structs
178 // to/from json
179 
181 
182 
183 void to_json( json& j, const PACKAGE_VERSION& v );
184 void from_json( const json& j, PACKAGE_VERSION& v );
185 
186 
187 void to_json( json& j, const PCM_PACKAGE& p );
188 void from_json( const json& j, PCM_PACKAGE& p );
189 
190 
191 void to_json( json& j, const PCM_RESOURCE_REFERENCE& r );
192 void from_json( const json& j, PCM_RESOURCE_REFERENCE& r );
193 
194 
195 void to_json( json& j, const PCM_REPOSITORY& r );
196 void from_json( const json& j, PCM_REPOSITORY& r );
197 
198 
199 NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE( PCM_INSTALLATION_ENTRY, package, current_version, repository_id,
200  repository_name, install_timestamp );
201 
202 
203 #endif // PCM_DATA_H_
< Package version metadata Package metadata
Definition: pcm_data.h:73
PCM_PACKAGE_VERSION_STATUS status
Definition: pcm_data.h:81
boost::optional< PCM_CONTACT > maintainer
Definition: pcm_data.h:101
PCM_PACKAGE_TYPE type
Definition: pcm_data.h:99
PCM_PACKAGE_TYPE
< Supported package types
Definition: pcm_data.h:40
std::vector< std::string > platforms
Definition: pcm_data.h:82
PCM_RESOURCE_REFERENCE packages
Definition: pcm_data.h:122
uint64_t update_timestamp
Definition: pcm_data.h:114
boost::optional< uint64_t > download_size
Definition: pcm_data.h:79
boost::optional< PCM_RESOURCE_REFERENCE > resources
Definition: pcm_data.h:123
boost::optional< uint64_t > install_size
Definition: pcm_data.h:80
wxString description
Definition: pcm_data.h:96
wxString name
Definition: pcm_data.h:63
nlohmann::json json
Definition: gerbview.cpp:41
PCM_PACKAGE_VERSION_STATUS
Definition: pcm_data.h:50
boost::optional< wxString > download_sha256
Definition: pcm_data.h:78
boost::optional< int > version_epoch
Definition: pcm_data.h:76
bool compatible
Definition: pcm_data.h:88
wxString name
Definition: pcm_data.h:121
wxString description_full
Definition: pcm_data.h:97
static void to_json(json &j, const wxString &s)
Definition: pcm_data.h:149
boost::optional< wxString > download_url
Definition: pcm_data.h:77
Repository reference to a resource.
Definition: pcm_data.h:93
std::vector< std::string > tags
Definition: pcm_data.h:104
std::map< wxString, wxString > STRING_MAP
Definition: env_vars.cpp:27
NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(PCM_INSTALLATION_ENTRY, package, current_version, repository_id, repository_name, install_timestamp)
wxString name
Definition: pcm_data.h:95
E_SERIE r
Definition: eserie.cpp:41
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
STRING_MAP resources
Definition: pcm_data.h:103
std::vector< PACKAGE_VERSION > versions
Definition: pcm_data.h:105
uint64_t install_timestamp
Definition: pcm_data.h:139
void from_json(const json &j, PACKAGE_VERSION &v)
Definition: pcm_data.cpp:65
wxString current_version
Definition: pcm_data.h:136
const char * name
Definition: DXF_plotter.cpp:56
std::tuple< int, int, int, int > parsed_version
Definition: pcm_data.h:87
wxString identifier
Definition: pcm_data.h:98
wxString kicad_version
Definition: pcm_data.h:83
boost::optional< wxString > kicad_version_max
Definition: pcm_data.h:84
boost::optional< PCM_RESOURCE_REFERENCE > manifests
Definition: pcm_data.h:124
PCM_CONTACT author
Definition: pcm_data.h:100
wxString license
Definition: pcm_data.h:102
boost::optional< wxString > sha256
Definition: pcm_data.h:113
std::vector< PCM_PACKAGE > package_list
Definition: pcm_data.h:128
wxString repository_id
Definition: pcm_data.h:137
void to_json(json &j, const PCM_PACKAGE &p)
Definition: pcm_data.cpp:83
PCM_PACKAGE package
Definition: pcm_data.h:135
wxString repository_name
Definition: pcm_data.h:138
Definition: pcm_data.h:133
Package installation entry.
Definition: pcm_data.h:119
STRING_MAP contact
Definition: pcm_data.h:64
static void from_json(const json &j, wxString &s)
Definition: pcm_data.h:151
boost::optional< PCM_CONTACT > maintainer
Definition: pcm_data.h:125
Repository metadata.
Definition: pcm_data.h:110
wxString version
Definition: pcm_data.h:75