KiCad PCB EDA Suite
Loading...
Searching...
No Matches
easyedapro_v3_parser.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, you may find one here:
18 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
19 * or you may search the http://www.gnu.org website for the version 2 license,
20 * or you may write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 */
23
24#ifndef EASYEDAPRO_V3_PARSER_H_
25#define EASYEDAPRO_V3_PARSER_H_
26
27#include <map>
28#include <vector>
29
30#include <wx/string.h>
31
32#include <nlohmann/json.hpp>
33
34
35namespace EASYEDAPRO
36{
37
41struct V3_ROW
42{
43 wxString type;
44 wxString id;
45 int ticket = 0;
46 nlohmann::json outer;
47 nlohmann::json inner;
48};
49
50
55{
56 wxString docType;
57 wxString uuid;
58 nlohmann::json head;
59 std::vector<V3_ROW> rows;
60 std::map<wxString, size_t> rowById;
61};
62
63
64// v3 JSON accessor utilities — type-safe extraction from nlohmann::json objects.
65
66wxString V3JsonToString( const nlohmann::json& aValue,
67 const wxString& aDefault = wxEmptyString );
68
69wxString V3GetString( const nlohmann::json& aObj, const char* aKey,
70 const wxString& aDefault = wxEmptyString );
71
72wxString V3GetString( const nlohmann::json& aObj, const wxString& aKey,
73 const wxString& aDefault = wxEmptyString );
74
75double V3GetDouble( const nlohmann::json& aObj, const char* aKey, double aDefault = 0.0 );
76
77int V3GetInt( const nlohmann::json& aObj, const char* aKey, int aDefault = 0 );
78
79bool V3GetBool( const nlohmann::json& aObj, const char* aKey, bool aDefault = false );
80
81bool V3IsNullOrMissing( const nlohmann::json& aObj, const char* aKey );
82
83nlohmann::json V3ParseIdArray( const wxString& aId );
84
85
92{
93public:
94 explicit V3_DOC_PARSER( const wxString& aFileName );
95
103 static bool IsV3Archive( const wxString& aFileName );
104
113 static bool IsV3Library( const wxString& aFileName, const wxString& aRequiredDocType = wxEmptyString );
114
120 void Load();
121
127 void LoadLibrary();
128
129 const nlohmann::json& GetProject2() const { return m_project2; }
130
131 const nlohmann::json& GetLibraryIndex() const { return m_libraryIndex; }
132
133 const std::map<wxString, V3_DOC_RAW>& GetRawDocs( const wxString& aDocType ) const;
134
135 const V3_DOC_RAW* FindRawDoc( const wxString& aDocType, const wxString& aUuid ) const;
136
137 int GetSkippedCount() const { return m_skippedCount; }
138
139private:
140 wxString m_fileName;
141 nlohmann::json m_project2;
142 nlohmann::json m_libraryIndex;
143 std::map<wxString, std::map<wxString, V3_DOC_RAW>> m_rawDocs;
145};
146
147} // namespace EASYEDAPRO
148
149
150#endif // EASYEDAPRO_V3_PARSER_H_
void Load()
Load all v3 docs from the archive.
const V3_DOC_RAW * FindRawDoc(const wxString &aDocType, const wxString &aUuid) const
const nlohmann::json & GetProject2() const
const std::map< wxString, V3_DOC_RAW > & GetRawDocs(const wxString &aDocType) const
static bool IsV3Library(const wxString &aFileName, const wxString &aRequiredDocType=wxEmptyString)
Return true if aFileName looks like an EasyEDA Pro v3 library archive.
std::map< wxString, std::map< wxString, V3_DOC_RAW > > m_rawDocs
const nlohmann::json & GetLibraryIndex() const
V3_DOC_PARSER(const wxString &aFileName)
static bool IsV3Archive(const wxString &aFileName)
Return true if aFileName looks like an EasyEDA Pro v3 archive.
void LoadLibrary()
Load all v3 docs from a library archive.
bool V3GetBool(const nlohmann::json &aObj, const char *aKey, bool aDefault)
nlohmann::json V3ParseIdArray(const wxString &aId)
bool V3IsNullOrMissing(const nlohmann::json &aObj, const char *aKey)
double V3GetDouble(const nlohmann::json &aObj, const char *aKey, double aDefault)
wxString V3JsonToString(const nlohmann::json &aValue, const wxString &aDefault)
int V3GetInt(const nlohmann::json &aObj, const char *aKey, int aDefault)
wxString V3GetString(const nlohmann::json &aObj, const char *aKey, const wxString &aDefault)
Raw parsed document from an EasyEDA Pro v3 .epru stream.
std::map< wxString, size_t > rowById
std::vector< V3_ROW > rows
One parsed row from an EasyEDA Pro v3 .epru document stream.