KiCad PCB EDA Suite
pcm_data.cpp File Reference
#include "pcm_data.h"

Go to the source code of this file.

Functions

template<typename T >
void to_optional (const json &j, const char *key, boost::optional< T > &dest)
 
void to_json (json &j, const PACKAGE_VERSION &v)
 
void from_json (const json &j, PACKAGE_VERSION &v)
 
void to_json (json &j, const PCM_PACKAGE &p)
 
void from_json (const json &j, PCM_PACKAGE &p)
 
void to_json (json &j, const PCM_RESOURCE_REFERENCE &r)
 
void from_json (const json &j, PCM_RESOURCE_REFERENCE &r)
 
void to_json (json &j, const PCM_REPOSITORY &r)
 
void from_json (const json &j, PCM_REPOSITORY &r)
 

Function Documentation

◆ from_json() [1/4]

void from_json ( const json j,
PACKAGE_VERSION v 
)

Definition at line 65 of file pcm_data.cpp.

66 {
67  j.at( "version" ).get_to( v.version );
68  j.at( "status" ).get_to( v.status );
69  j.at( "kicad_version" ).get_to( v.kicad_version );
70 
71  to_optional( j, "version_epoch", v.version_epoch );
72  to_optional( j, "download_url", v.download_url );
73  to_optional( j, "download_sha256", v.download_sha256 );
74  to_optional( j, "download_size", v.download_size );
75  to_optional( j, "install_size", v.install_size );
76  to_optional( j, "kicad_version_max", v.kicad_version_max );
77 
78  if( j.contains( "platforms" ) )
79  j.at( "platforms" ).get_to( v.platforms );
80 }
PCM_PACKAGE_VERSION_STATUS status
Definition: pcm_data.h:81
std::vector< std::string > platforms
Definition: pcm_data.h:82
boost::optional< uint64_t > download_size
Definition: pcm_data.h:79
boost::optional< uint64_t > install_size
Definition: pcm_data.h:80
boost::optional< wxString > download_sha256
Definition: pcm_data.h:78
boost::optional< int > version_epoch
Definition: pcm_data.h:76
boost::optional< wxString > download_url
Definition: pcm_data.h:77
void to_optional(const json &j, const char *key, boost::optional< T > &dest)
Definition: pcm_data.cpp:25
wxString kicad_version
Definition: pcm_data.h:83
boost::optional< wxString > kicad_version_max
Definition: pcm_data.h:84
wxString version
Definition: pcm_data.h:75

References PACKAGE_VERSION::download_sha256, PACKAGE_VERSION::download_size, PACKAGE_VERSION::download_url, PACKAGE_VERSION::install_size, PACKAGE_VERSION::kicad_version, PACKAGE_VERSION::kicad_version_max, PACKAGE_VERSION::platforms, PACKAGE_VERSION::status, to_optional(), PACKAGE_VERSION::version, and PACKAGE_VERSION::version_epoch.

◆ from_json() [2/4]

void from_json ( const json j,
PCM_PACKAGE p 
)

Definition at line 103 of file pcm_data.cpp.

104 {
105  j.at( "name" ).get_to( p.name );
106  j.at( "description" ).get_to( p.description );
107  j.at( "description_full" ).get_to( p.description_full );
108  j.at( "identifier" ).get_to( p.identifier );
109  j.at( "type" ).get_to( p.type );
110  j.at( "author" ).get_to( p.author );
111  j.at( "license" ).get_to( p.license );
112  j.at( "resources" ).get_to( p.resources );
113  j.at( "versions" ).get_to( p.versions );
114 
115  to_optional( j, "maintainer", p.maintainer );
116 
117  if( j.contains( "tags" ) )
118  j.at( "tags" ).get_to( p.tags );
119 }
boost::optional< PCM_CONTACT > maintainer
Definition: pcm_data.h:101
PCM_PACKAGE_TYPE type
Definition: pcm_data.h:99
wxString description
Definition: pcm_data.h:96
wxString description_full
Definition: pcm_data.h:97
std::vector< std::string > tags
Definition: pcm_data.h:104
wxString name
Definition: pcm_data.h:95
STRING_MAP resources
Definition: pcm_data.h:103
std::vector< PACKAGE_VERSION > versions
Definition: pcm_data.h:105
void to_optional(const json &j, const char *key, boost::optional< T > &dest)
Definition: pcm_data.cpp:25
wxString identifier
Definition: pcm_data.h:98
PCM_CONTACT author
Definition: pcm_data.h:100
wxString license
Definition: pcm_data.h:102

References PCM_PACKAGE::author, PCM_PACKAGE::description, PCM_PACKAGE::description_full, PCM_PACKAGE::identifier, PCM_PACKAGE::license, PCM_PACKAGE::maintainer, PCM_PACKAGE::name, PCM_PACKAGE::resources, PCM_PACKAGE::tags, to_optional(), PCM_PACKAGE::type, and PCM_PACKAGE::versions.

◆ from_json() [3/4]

void from_json ( const json j,
PCM_RESOURCE_REFERENCE r 
)

Definition at line 131 of file pcm_data.cpp.

132 {
133  j.at( "url" ).get_to( r.url );
134  j.at( "update_timestamp" ).get_to( r.update_timestamp );
135 
136  to_optional(j, "sha256", r.sha256 );
137 }
E_SERIE r
Definition: eserie.cpp:41
void to_optional(const json &j, const char *key, boost::optional< T > &dest)
Definition: pcm_data.cpp:25

References r, and to_optional().

◆ from_json() [4/4]

void from_json ( const json j,
PCM_REPOSITORY r 
)

Definition at line 155 of file pcm_data.cpp.

156 {
157  j.at( "name" ).get_to( r.name );
158  j.at( "packages" ).get_to( r.packages );
159 
160  to_optional(j, "resources", r.resources );
161  to_optional(j, "manifests", r.manifests );
162  to_optional(j, "maintainer", r.maintainer );
163 }
E_SERIE r
Definition: eserie.cpp:41
void to_optional(const json &j, const char *key, boost::optional< T > &dest)
Definition: pcm_data.cpp:25

References r, and to_optional().

◆ to_json() [1/4]

void to_json ( json j,
const PACKAGE_VERSION v 
)

Definition at line 36 of file pcm_data.cpp.

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 }
PCM_PACKAGE_VERSION_STATUS status
Definition: pcm_data.h:81
std::vector< std::string > platforms
Definition: pcm_data.h:82
boost::optional< uint64_t > download_size
Definition: pcm_data.h:79
boost::optional< uint64_t > install_size
Definition: pcm_data.h:80
void to_json(json &j, const PACKAGE_VERSION &v)
Definition: pcm_data.cpp:36
nlohmann::json json
Definition: gerbview.cpp:41
boost::optional< wxString > download_sha256
Definition: pcm_data.h:78
boost::optional< int > version_epoch
Definition: pcm_data.h:76
boost::optional< wxString > download_url
Definition: pcm_data.h:77
wxString kicad_version
Definition: pcm_data.h:83
boost::optional< wxString > kicad_version_max
Definition: pcm_data.h:84
wxString version
Definition: pcm_data.h:75

References PACKAGE_VERSION::download_sha256, PACKAGE_VERSION::download_size, PACKAGE_VERSION::download_url, PACKAGE_VERSION::install_size, PACKAGE_VERSION::kicad_version, PACKAGE_VERSION::kicad_version_max, PACKAGE_VERSION::platforms, PACKAGE_VERSION::status, PACKAGE_VERSION::version, and PACKAGE_VERSION::version_epoch.

◆ to_json() [2/4]

void to_json ( json j,
const PCM_PACKAGE p 
)

Definition at line 83 of file pcm_data.cpp.

84 {
85  j = json{ { "name", p.name },
86  { "description", p.description },
87  { "description_full", p.description_full },
88  { "identifier", p.identifier },
89  { "type", p.type },
90  { "author", p.author },
91  { "license", p.license },
92  { "resources", p.resources },
93  { "versions", p.versions } };
94 
95  if( p.maintainer )
96  j["maintainer"] = p.maintainer.get();
97 
98  if( p.tags.size() > 0 )
99  j["tags"] = p.tags;
100 }
boost::optional< PCM_CONTACT > maintainer
Definition: pcm_data.h:101
PCM_PACKAGE_TYPE type
Definition: pcm_data.h:99
wxString description
Definition: pcm_data.h:96
nlohmann::json json
Definition: gerbview.cpp:41
wxString description_full
Definition: pcm_data.h:97
std::vector< std::string > tags
Definition: pcm_data.h:104
wxString name
Definition: pcm_data.h:95
STRING_MAP resources
Definition: pcm_data.h:103
std::vector< PACKAGE_VERSION > versions
Definition: pcm_data.h:105
wxString identifier
Definition: pcm_data.h:98
PCM_CONTACT author
Definition: pcm_data.h:100
wxString license
Definition: pcm_data.h:102

References PCM_PACKAGE::author, PCM_PACKAGE::description, PCM_PACKAGE::description_full, PCM_PACKAGE::identifier, PCM_PACKAGE::license, PCM_PACKAGE::maintainer, PCM_PACKAGE::name, PCM_PACKAGE::resources, PCM_PACKAGE::tags, PCM_PACKAGE::type, and PCM_PACKAGE::versions.

◆ to_json() [3/4]

void to_json ( json j,
const PCM_RESOURCE_REFERENCE r 
)

Definition at line 122 of file pcm_data.cpp.

123 {
124  j = json{ { "url", r.url }, { "update_timestamp", r.update_timestamp } };
125 
126  if( r.sha256 )
127  j["sha256"] = r.sha256.get();
128 }
nlohmann::json json
Definition: gerbview.cpp:41
E_SERIE r
Definition: eserie.cpp:41

References r.

◆ to_json() [4/4]

void to_json ( json j,
const PCM_REPOSITORY r 
)

Definition at line 140 of file pcm_data.cpp.

141 {
142  j = json{ { "name", r.name }, { "packages", r.packages } };
143 
144  if( r.resources )
145  j["resources"] = r.resources.get();
146 
147  if( r.manifests )
148  j["manifests"] = r.manifests.get();
149 
150  if( r.maintainer )
151  j["maintainer"] = r.maintainer.get();
152 }
nlohmann::json json
Definition: gerbview.cpp:41
E_SERIE r
Definition: eserie.cpp:41

References r.

◆ to_optional()

template<typename T >
void to_optional ( const json j,
const char *  key,
boost::optional< T > &  dest 
)

Definition at line 25 of file pcm_data.cpp.

26 {
27  if( j.contains( key ) )
28  {
29  T tmp;
30  j.at( key ).get_to( tmp );
31  dest.emplace( tmp );
32  }
33 }

Referenced by from_json().