KiCad PCB EDA Suite
Loading...
Searching...
No Matches
json_schema_validator.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 The KiCad Developers, see AUTHORS.txt for contributors.
5 *
6 * This program is free software: you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation, either version 3 of the License, or (at your
9 * option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <fstream>
21#include <wx/filename.h>
22#include <wx/log.h>
23
25#include <locale_io.h>
26
27
28JSON_SCHEMA_VALIDATOR::JSON_SCHEMA_VALIDATOR( const wxFileName& aSchemaFile )
29{
30 std::ifstream schema_stream( aSchemaFile.GetFullPath().fn_str() );
31 nlohmann::json schema;
32
33 try
34 {
35 // For some obscure reason on MINGW, using UCRT option,
36 // m_schema_validator.set_root_schema() hangs without switching to locale "C"
37#if defined(__MINGW32__) && defined(_UCRT)
39#endif
40
41 schema_stream >> schema;
42 m_validator.set_root_schema( schema );
43 }
44 catch( std::exception& e )
45 {
46 if( !aSchemaFile.FileExists() )
47 {
48 wxLogError( wxString::Format( _( "schema file '%s' not found" ),
49 aSchemaFile.GetFullPath() ) );
50 }
51 else
52 {
53 wxLogError( wxString::Format( _( "Error loading schema: %s" ), e.what() ) );
54 }
55 }
56}
57
58
59nlohmann::json JSON_SCHEMA_VALIDATOR::Validate( const nlohmann::json& aJson,
60 nlohmann::json_schema::error_handler& aErrorHandler,
61 const nlohmann::json_uri& aInitialUri ) const
62{
63 return m_validator.validate( aJson, aErrorHandler, aInitialUri );
64}
JSON_SCHEMA_VALIDATOR(const wxFileName &aSchemaFile)
nlohmann::json_schema::json_validator m_validator
nlohmann::json Validate(const nlohmann::json &aJson, nlohmann::json_schema::error_handler &aErrorHandler, const nlohmann::json_uri &aInitialUri=nlohmann::json_uri("#")) const
Instantiate the current locale within a scope in which you are expecting exceptions to be thrown.
Definition: locale_io.h:49
#define _(s)
std::vector< FAB_LAYER_COLOR > dummy