Revert "Move JSON_SETTINGS and PARAMS to kicommon"
This reverts commit 81855aaaa6
This commit is contained in:
parent
2311eed08a
commit
72d83cd5de
|
@ -97,13 +97,6 @@ set( KICOMMON_SRCS
|
|||
kicad_curl/kicad_curl.cpp
|
||||
kicad_curl/kicad_curl_easy.cpp
|
||||
|
||||
settings/aui_settings.cpp
|
||||
settings/bom_settings.cpp
|
||||
settings/grid_settings.cpp
|
||||
settings/json_settings.cpp
|
||||
settings/nested_settings.cpp
|
||||
settings/parameters.cpp
|
||||
|
||||
widgets/progress_reporter_base.cpp
|
||||
widgets/std_bitmap_button.cpp
|
||||
|
||||
|
@ -142,8 +135,6 @@ add_library( kicommon SHARED
|
|||
${KICOMMON_SRCS}
|
||||
)
|
||||
|
||||
set_target_properties(kicommon PROPERTIES CXX_VISIBILITY_PRESET hidden)
|
||||
|
||||
target_link_libraries( kicommon
|
||||
core
|
||||
kimath
|
||||
|
@ -573,9 +564,15 @@ set( COMMON_SRCS
|
|||
tool/zoom_tool.cpp
|
||||
|
||||
settings/app_settings.cpp
|
||||
settings/aui_settings.cpp
|
||||
settings/bom_settings.cpp
|
||||
settings/color_settings.cpp
|
||||
settings/cvpcb_settings.cpp
|
||||
settings/common_settings.cpp
|
||||
settings/grid_settings.cpp
|
||||
settings/json_settings.cpp
|
||||
settings/nested_settings.cpp
|
||||
settings/parameters.cpp
|
||||
settings/settings_manager.cpp
|
||||
settings/kicad_settings.cpp
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
|
||||
*/
|
||||
|
||||
#include <json_common.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <database/database_lib_settings.h>
|
||||
#include <settings/parameters.h>
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
|
||||
#include "easyeda_parser_structs.h"
|
||||
|
||||
#include <json_common.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <core/json_serializers.h>
|
||||
|
||||
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
#include <ki_exception.h>
|
||||
#include <string_utils.h>
|
||||
#include <json_common.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <core/json_serializers.h>
|
||||
|
||||
#include <wx/log.h>
|
||||
|
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
#include <memory>
|
||||
|
||||
#include <json_common.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <core/json_serializers.h>
|
||||
#include <string_utils.h>
|
||||
|
||||
|
|
|
@ -36,13 +36,13 @@
|
|||
|
||||
#include <notifications_manager.h>
|
||||
#include <widgets/kistatusbar.h>
|
||||
#include <json_common.h>
|
||||
|
||||
#include "core/wx_stl_compat.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <fstream>
|
||||
#include <map>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <core/json_serializers.h>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
|
||||
#include <project/net_settings.h>
|
||||
#include <settings/parameters.h>
|
||||
#include <settings/json_settings_internals.h>
|
||||
#include <settings/settings_manager.h>
|
||||
#include <string_utils.h>
|
||||
#include <base_units.h>
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <search_stack.h>
|
||||
#include <settings/settings_manager.h>
|
||||
#include <settings/common_settings.h>
|
||||
#include <settings/json_settings.h>
|
||||
#include <settings/json_settings_internals.h>
|
||||
#include <settings/parameters.h>
|
||||
#include <systemdirsappend.h>
|
||||
#include <trace_helpers.h>
|
||||
|
|
|
@ -43,6 +43,8 @@
|
|||
#include <wx/stdstream.h>
|
||||
#include <wx/wfstream.h>
|
||||
|
||||
const wxChar* const traceSettings = wxT( "KICAD_SETTINGS" );
|
||||
|
||||
|
||||
nlohmann::json::json_pointer JSON_SETTINGS_INTERNALS::PointerFromString( std::string aPath )
|
||||
{
|
||||
|
@ -589,37 +591,23 @@ std::optional<ValueType> JSON_SETTINGS::Get( const std::string& aPath ) const
|
|||
|
||||
|
||||
// Instantiate all required templates here to allow reducing scope of json.hpp
|
||||
template KICOMMON_API std::optional<bool> JSON_SETTINGS::Get<bool>( const std::string& aPath ) const;
|
||||
template KICOMMON_API std::optional<double>
|
||||
JSON_SETTINGS::Get<double>( const std::string& aPath ) const;
|
||||
template KICOMMON_API std::optional<float>
|
||||
JSON_SETTINGS::Get<float>( const std::string& aPath ) const;
|
||||
template KICOMMON_API std::optional<int> JSON_SETTINGS::Get<int>( const std::string& aPath ) const;
|
||||
template KICOMMON_API std::optional<unsigned int>
|
||||
JSON_SETTINGS::Get<unsigned int>( const std::string& aPath ) const;
|
||||
template KICOMMON_API std::optional<unsigned long long>
|
||||
JSON_SETTINGS::Get<unsigned long long>( const std::string& aPath ) const;
|
||||
template KICOMMON_API std::optional<std::string>
|
||||
JSON_SETTINGS::Get<std::string>( const std::string& aPath ) const;
|
||||
template KICOMMON_API std::optional<nlohmann::json>
|
||||
JSON_SETTINGS::Get<nlohmann::json>( const std::string& aPath ) const;
|
||||
template KICOMMON_API std::optional<KIGFX::COLOR4D>
|
||||
JSON_SETTINGS::Get<KIGFX::COLOR4D>( const std::string& aPath ) const;
|
||||
template KICOMMON_API std::optional<BOM_FIELD>
|
||||
JSON_SETTINGS::Get<BOM_FIELD>( const std::string& aPath ) const;
|
||||
template KICOMMON_API std::optional<BOM_PRESET>
|
||||
JSON_SETTINGS::Get<BOM_PRESET>( const std::string& aPath ) const;
|
||||
template KICOMMON_API std::optional<BOM_FMT_PRESET>
|
||||
JSON_SETTINGS::Get<BOM_FMT_PRESET>( const std::string& aPath ) const;
|
||||
template KICOMMON_API std::optional<GRID> JSON_SETTINGS::Get<GRID>( const std::string& aPath ) const;
|
||||
template KICOMMON_API std::optional<wxPoint>
|
||||
JSON_SETTINGS::Get<wxPoint>( const std::string& aPath ) const;
|
||||
template KICOMMON_API std::optional<wxSize>
|
||||
JSON_SETTINGS::Get<wxSize>( const std::string& aPath ) const;
|
||||
template KICOMMON_API std::optional<wxRect>
|
||||
JSON_SETTINGS::Get<wxRect>( const std::string& aPath ) const;
|
||||
template KICOMMON_API std::optional<wxAuiPaneInfo>
|
||||
JSON_SETTINGS::Get<wxAuiPaneInfo>( const std::string& aPath ) const;
|
||||
template std::optional<bool> JSON_SETTINGS::Get<bool>( const std::string& aPath ) const;
|
||||
template std::optional<double> JSON_SETTINGS::Get<double>( const std::string& aPath ) const;
|
||||
template std::optional<float> JSON_SETTINGS::Get<float>( const std::string& aPath ) const;
|
||||
template std::optional<int> JSON_SETTINGS::Get<int>( const std::string& aPath ) const;
|
||||
template std::optional<unsigned int> JSON_SETTINGS::Get<unsigned int>( const std::string& aPath ) const;
|
||||
template std::optional<unsigned long long> JSON_SETTINGS::Get<unsigned long long>( const std::string& aPath ) const;
|
||||
template std::optional<std::string> JSON_SETTINGS::Get<std::string>( const std::string& aPath ) const;
|
||||
template std::optional<nlohmann::json> JSON_SETTINGS::Get<nlohmann::json>( const std::string& aPath ) const;
|
||||
template std::optional<KIGFX::COLOR4D> JSON_SETTINGS::Get<KIGFX::COLOR4D>( const std::string& aPath ) const;
|
||||
template std::optional<BOM_FIELD> JSON_SETTINGS::Get<BOM_FIELD>( const std::string& aPath ) const;
|
||||
template std::optional<BOM_PRESET> JSON_SETTINGS::Get<BOM_PRESET>( const std::string& aPath ) const;
|
||||
template std::optional<BOM_FMT_PRESET> JSON_SETTINGS::Get<BOM_FMT_PRESET>( const std::string& aPath ) const;
|
||||
template std::optional<GRID> JSON_SETTINGS::Get<GRID>( const std::string& aPath ) const;
|
||||
template std::optional<wxPoint> JSON_SETTINGS::Get<wxPoint>( const std::string& aPath ) const;
|
||||
template std::optional<wxSize> JSON_SETTINGS::Get<wxSize>( const std::string& aPath ) const;
|
||||
template std::optional<wxRect> JSON_SETTINGS::Get<wxRect>( const std::string& aPath ) const;
|
||||
template std::optional<wxAuiPaneInfo> JSON_SETTINGS::Get<wxAuiPaneInfo>( const std::string& aPath ) const;
|
||||
|
||||
template<typename ValueType>
|
||||
void JSON_SETTINGS::Set( const std::string& aPath, ValueType aVal )
|
||||
|
@ -629,34 +617,24 @@ void JSON_SETTINGS::Set( const std::string& aPath, ValueType aVal )
|
|||
|
||||
|
||||
// Instantiate all required templates here to allow reducing scope of json.hpp
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<bool>( const std::string& aPath, bool aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<double>( const std::string& aPath, double aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<float>( const std::string& aPath, float aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<int>( const std::string& aPath, int aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<unsigned int>( const std::string& aPath,
|
||||
unsigned int aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<unsigned long long>( const std::string& aPath,
|
||||
unsigned long long aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<const char*>( const std::string& aPath,
|
||||
const char* aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<std::string>( const std::string& aPath,
|
||||
std::string aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<nlohmann::json>( const std::string& aPath,
|
||||
nlohmann::json aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<KIGFX::COLOR4D>( const std::string& aPath,
|
||||
KIGFX::COLOR4D aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<BOM_FIELD>( const std::string& aPath,
|
||||
BOM_FIELD aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<BOM_PRESET>( const std::string& aPath,
|
||||
BOM_PRESET aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<BOM_FMT_PRESET>( const std::string& aPath,
|
||||
BOM_FMT_PRESET aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<GRID>( const std::string& aPath, GRID aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<wxPoint>( const std::string& aPath, wxPoint aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<wxSize>( const std::string& aPath, wxSize aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<wxRect>( const std::string& aPath, wxRect aValue );
|
||||
template KICOMMON_API void JSON_SETTINGS::Set<wxAuiPaneInfo>( const std::string& aPath,
|
||||
wxAuiPaneInfo aValue );
|
||||
template void JSON_SETTINGS::Set<bool>( const std::string& aPath, bool aValue );
|
||||
template void JSON_SETTINGS::Set<double>( const std::string& aPath, double aValue );
|
||||
template void JSON_SETTINGS::Set<float>( const std::string& aPath, float aValue );
|
||||
template void JSON_SETTINGS::Set<int>( const std::string& aPath, int aValue );
|
||||
template void JSON_SETTINGS::Set<unsigned int>( const std::string& aPath, unsigned int aValue );
|
||||
template void JSON_SETTINGS::Set<unsigned long long>( const std::string& aPath, unsigned long long aValue );
|
||||
template void JSON_SETTINGS::Set<const char*>( const std::string& aPath, const char* aValue );
|
||||
template void JSON_SETTINGS::Set<std::string>( const std::string& aPath, std::string aValue );
|
||||
template void JSON_SETTINGS::Set<nlohmann::json>( const std::string& aPath, nlohmann::json aValue );
|
||||
template void JSON_SETTINGS::Set<KIGFX::COLOR4D>( const std::string& aPath, KIGFX::COLOR4D aValue );
|
||||
template void JSON_SETTINGS::Set<BOM_FIELD>( const std::string& aPath, BOM_FIELD aValue );
|
||||
template void JSON_SETTINGS::Set<BOM_PRESET>( const std::string& aPath, BOM_PRESET aValue );
|
||||
template void JSON_SETTINGS::Set<BOM_FMT_PRESET>( const std::string& aPath, BOM_FMT_PRESET aValue );
|
||||
template void JSON_SETTINGS::Set<GRID>( const std::string& aPath, GRID aValue );
|
||||
template void JSON_SETTINGS::Set<wxPoint>( const std::string& aPath, wxPoint aValue );
|
||||
template void JSON_SETTINGS::Set<wxSize>( const std::string& aPath, wxSize aValue );
|
||||
template void JSON_SETTINGS::Set<wxRect>( const std::string& aPath, wxRect aValue );
|
||||
template void JSON_SETTINGS::Set<wxAuiPaneInfo>( const std::string& aPath, wxAuiPaneInfo aValue );
|
||||
|
||||
|
||||
void JSON_SETTINGS::registerMigration( int aOldSchemaVersion, int aNewSchemaVersion,
|
||||
|
@ -797,13 +775,13 @@ bool JSON_SETTINGS::fromLegacy( wxConfigBase* aConfig, const std::string& aKey,
|
|||
|
||||
// Explicitly declare these because we only support a few types anyway, and it means we can keep
|
||||
// wxConfig detail out of the header file
|
||||
template KICOMMON_API bool JSON_SETTINGS::fromLegacy<int>( wxConfigBase*, const std::string&,
|
||||
template bool JSON_SETTINGS::fromLegacy<int>( wxConfigBase*, const std::string&,
|
||||
const std::string& );
|
||||
|
||||
template KICOMMON_API bool JSON_SETTINGS::fromLegacy<double>( wxConfigBase*, const std::string&,
|
||||
template bool JSON_SETTINGS::fromLegacy<double>( wxConfigBase*, const std::string&,
|
||||
const std::string& );
|
||||
|
||||
template KICOMMON_API bool JSON_SETTINGS::fromLegacy<bool>( wxConfigBase*, const std::string&,
|
||||
template bool JSON_SETTINGS::fromLegacy<bool>( wxConfigBase*, const std::string&,
|
||||
const std::string& );
|
||||
|
||||
|
||||
|
@ -936,10 +914,9 @@ ResultType JSON_SETTINGS::fetchOrDefault( const nlohmann::json& aJson, const std
|
|||
}
|
||||
|
||||
|
||||
template KICOMMON_API std::string JSON_SETTINGS::fetchOrDefault( const nlohmann::json& aJson,
|
||||
template std::string JSON_SETTINGS::fetchOrDefault( const nlohmann::json& aJson,
|
||||
const std::string& aKey, std::string aDefault );
|
||||
|
||||
|
||||
template KICOMMON_API bool JSON_SETTINGS::fetchOrDefault( const nlohmann::json& aJson,
|
||||
const std::string& aKey,
|
||||
template bool JSON_SETTINGS::fetchOrDefault( const nlohmann::json& aJson, const std::string& aKey,
|
||||
bool aDefault );
|
||||
|
|
|
@ -22,9 +22,190 @@
|
|||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <gal/color4d.h>
|
||||
#include <project/project_file.h>
|
||||
#include <settings/parameters.h>
|
||||
#include <settings/bom_settings.h>
|
||||
#include <settings/grid_settings.h>
|
||||
|
||||
template <typename ValueType>
|
||||
void PARAM_LAMBDA<ValueType>::Load( JSON_SETTINGS* aSettings, bool aResetIfMissing ) const
|
||||
{
|
||||
if( m_readOnly )
|
||||
return;
|
||||
|
||||
if( std::is_same<ValueType, nlohmann::json>::value )
|
||||
{
|
||||
if( std::optional<nlohmann::json> optval = aSettings->GetJson( m_path ) )
|
||||
m_setter( *optval );
|
||||
else
|
||||
m_setter( m_default );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( std::optional<ValueType> optval = aSettings->Get<ValueType>( m_path ) )
|
||||
m_setter( *optval );
|
||||
else
|
||||
m_setter( m_default );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
template <typename ValueType>
|
||||
bool PARAM_LAMBDA<ValueType>::MatchesFile( JSON_SETTINGS* aSettings ) const
|
||||
{
|
||||
if( std::is_same<ValueType, nlohmann::json>::value )
|
||||
{
|
||||
if( std::optional<nlohmann::json> optval = aSettings->GetJson( m_path ) )
|
||||
return *optval == m_getter();
|
||||
}
|
||||
else
|
||||
{
|
||||
if( std::optional<ValueType> optval = aSettings->Get<ValueType>( m_path ) )
|
||||
return *optval == m_getter();
|
||||
}
|
||||
|
||||
// Not in file
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Instantiate all required templates here to allow reducing scope of json.hpp
|
||||
template class PARAM_LAMBDA<bool>;
|
||||
template class PARAM_LAMBDA<int>;
|
||||
template class PARAM_LAMBDA<nlohmann::json>;
|
||||
template class PARAM_LAMBDA<std::string>;
|
||||
|
||||
template <typename ValueType>
|
||||
void PARAM_LIST<ValueType>::Load( JSON_SETTINGS* aSettings, bool aResetIfMissing ) const
|
||||
{
|
||||
if( m_readOnly )
|
||||
return;
|
||||
|
||||
if( std::optional<nlohmann::json> js = aSettings->GetJson( m_path ) )
|
||||
{
|
||||
std::vector<ValueType> val;
|
||||
|
||||
if( js->is_array() )
|
||||
{
|
||||
for( const auto& el : js->items() )
|
||||
val.push_back( el.value().get<ValueType>() );
|
||||
}
|
||||
|
||||
*m_ptr = val;
|
||||
}
|
||||
else if( aResetIfMissing )
|
||||
*m_ptr = m_default;
|
||||
}
|
||||
|
||||
|
||||
template <typename ValueType>
|
||||
void PARAM_LIST<ValueType>::Store( JSON_SETTINGS* aSettings ) const
|
||||
{
|
||||
nlohmann::json js = nlohmann::json::array();
|
||||
|
||||
for( const auto& el : *m_ptr )
|
||||
js.push_back( el );
|
||||
|
||||
aSettings->Set<nlohmann::json>( m_path, js );
|
||||
}
|
||||
|
||||
|
||||
template <typename ValueType>
|
||||
bool PARAM_LIST<ValueType>::MatchesFile( JSON_SETTINGS* aSettings ) const
|
||||
{
|
||||
if( std::optional<nlohmann::json> js = aSettings->GetJson( m_path ) )
|
||||
{
|
||||
if( js->is_array() )
|
||||
{
|
||||
std::vector<ValueType> val;
|
||||
|
||||
for( const auto& el : js->items() )
|
||||
{
|
||||
try
|
||||
{
|
||||
val.emplace_back( el.value().get<ValueType>() );
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
// Probably typecast didn't work; skip this element
|
||||
}
|
||||
}
|
||||
|
||||
return val == *m_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template class PARAM_LIST<int>;
|
||||
template class PARAM_LIST<double>;
|
||||
template class PARAM_LIST<wxString>;
|
||||
template class PARAM_LIST<KIGFX::COLOR4D>;
|
||||
template class PARAM_LIST<FILE_INFO_PAIR>;
|
||||
template class PARAM_LIST<BOM_PRESET>;
|
||||
template class PARAM_LIST<BOM_FMT_PRESET>;
|
||||
template class PARAM_LIST<GRID>;
|
||||
|
||||
|
||||
template <typename ValueType>
|
||||
void PARAM_SET<ValueType>::Load( JSON_SETTINGS* aSettings, bool aResetIfMissing ) const
|
||||
{
|
||||
if( m_readOnly )
|
||||
return;
|
||||
|
||||
if( std::optional<nlohmann::json> js = aSettings->GetJson( m_path ) )
|
||||
{
|
||||
std::set<ValueType> val;
|
||||
|
||||
if( js->is_array() )
|
||||
{
|
||||
for( const auto& el : js->items() )
|
||||
val.insert( el.value().get<ValueType>() );
|
||||
}
|
||||
|
||||
*m_ptr = val;
|
||||
}
|
||||
else if( aResetIfMissing )
|
||||
*m_ptr = m_default;
|
||||
}
|
||||
|
||||
|
||||
template <typename ValueType>
|
||||
void PARAM_SET<ValueType>::Store( JSON_SETTINGS* aSettings ) const
|
||||
{
|
||||
nlohmann::json js = nlohmann::json::array();
|
||||
|
||||
for( const auto& el : *m_ptr )
|
||||
js.push_back( el );
|
||||
|
||||
aSettings->Set<nlohmann::json>( m_path, js );
|
||||
}
|
||||
|
||||
|
||||
template <typename ValueType>
|
||||
bool PARAM_SET<ValueType>::MatchesFile( JSON_SETTINGS* aSettings ) const
|
||||
{
|
||||
if( std::optional<nlohmann::json> js = aSettings->GetJson( m_path ) )
|
||||
{
|
||||
if( js->is_array() )
|
||||
{
|
||||
std::set<ValueType> val;
|
||||
|
||||
for( const auto& el : js->items() )
|
||||
val.insert( el.value().get<ValueType>() );
|
||||
|
||||
return val == *m_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template class PARAM_SET<wxString>;
|
||||
|
||||
|
||||
void PARAM_PATH_LIST::Store( JSON_SETTINGS* aSettings ) const
|
||||
|
@ -57,6 +238,66 @@ bool PARAM_PATH_LIST::MatchesFile( JSON_SETTINGS* aSettings ) const
|
|||
}
|
||||
|
||||
|
||||
template <typename Value>
|
||||
void PARAM_MAP<Value>::Load( JSON_SETTINGS* aSettings, bool aResetIfMissing ) const
|
||||
{
|
||||
if( m_readOnly )
|
||||
return;
|
||||
|
||||
if( std::optional<nlohmann::json> js = aSettings->GetJson( m_path ) )
|
||||
{
|
||||
if( js->is_object() )
|
||||
{
|
||||
m_ptr->clear();
|
||||
|
||||
for( const auto& el : js->items() )
|
||||
( *m_ptr )[el.key()] = el.value().get<Value>();
|
||||
}
|
||||
}
|
||||
else if( aResetIfMissing )
|
||||
*m_ptr = m_default;
|
||||
}
|
||||
|
||||
|
||||
template <typename Value>
|
||||
void PARAM_MAP<Value>::Store( JSON_SETTINGS* aSettings ) const
|
||||
{
|
||||
nlohmann::json js( {} );
|
||||
|
||||
for( const auto& el : *m_ptr )
|
||||
js[el.first] = el.second;
|
||||
|
||||
aSettings->Set<nlohmann::json>( m_path, js );
|
||||
}
|
||||
|
||||
|
||||
template <typename Value>
|
||||
bool PARAM_MAP<Value>::MatchesFile( JSON_SETTINGS* aSettings ) const
|
||||
{
|
||||
if( std::optional<nlohmann::json> js = aSettings->GetJson( m_path ) )
|
||||
{
|
||||
if( js->is_object() )
|
||||
{
|
||||
if( m_ptr->size() != js->size() )
|
||||
return false;
|
||||
|
||||
std::map<std::string, Value> val;
|
||||
|
||||
for( const auto& el : js->items() )
|
||||
val[el.key()] = el.value().get<Value>();
|
||||
|
||||
return val == *m_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
template class PARAM_MAP<int>;
|
||||
template class PARAM_MAP<double>;
|
||||
template class PARAM_MAP<bool>;
|
||||
|
||||
|
||||
void PARAM_WXSTRING_MAP::Load( JSON_SETTINGS* aSettings, bool aResetIfMissing ) const
|
||||
{
|
||||
|
@ -117,25 +358,3 @@ bool PARAM_WXSTRING_MAP::MatchesFile( JSON_SETTINGS* aSettings ) const
|
|||
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
// Instantiate all required templates here and export
|
||||
template class KICOMMON_API PARAM_LAMBDA<bool>;
|
||||
template class KICOMMON_API PARAM_LAMBDA<int>;
|
||||
template class KICOMMON_API PARAM_LAMBDA<nlohmann::json>;
|
||||
template class KICOMMON_API PARAM_LAMBDA<std::string>;
|
||||
|
||||
template class KICOMMON_API PARAM_LIST<int>;
|
||||
template class KICOMMON_API PARAM_LIST<double>;
|
||||
template class KICOMMON_API PARAM_LIST<wxString>;
|
||||
template class KICOMMON_API PARAM_LIST<KIGFX::COLOR4D>;
|
||||
//template KICOMMON_API class PARAM_LIST<FILE_INFO_PAIR>;
|
||||
template class KICOMMON_API PARAM_LIST<struct BOM_PRESET>;
|
||||
template class KICOMMON_API PARAM_LIST<struct BOM_FMT_PRESET>;
|
||||
template class KICOMMON_API PARAM_LIST<GRID>;
|
||||
|
||||
template class KICOMMON_API PARAM_SET<wxString>;
|
||||
|
||||
template class KICOMMON_API PARAM_MAP<int>;
|
||||
template class KICOMMON_API PARAM_MAP<double>;
|
||||
template class KICOMMON_API PARAM_MAP<bool>;
|
|
@ -44,16 +44,6 @@
|
|||
#define APILOCAL
|
||||
#endif
|
||||
|
||||
// We use APIVISIBLE to mark extern template declarations where we cannot use APIEXPORT
|
||||
// Because MSVC disallows mixing dllexport and extern templates, we can't just use APIEXPORT
|
||||
// However MSVC is fine with the dllexport in the cpp file and extern in the header
|
||||
// But we need the visibility declared on both instantiation and extern for GCC/Clang to make
|
||||
// the symbol visible
|
||||
#if defined( __GNUC__ ) || defined( __clang__ )
|
||||
#define APIVISIBLE __attribute__ ((visibility("default")))
|
||||
#else
|
||||
#define APIVISIBLE
|
||||
#endif
|
||||
|
||||
#if defined(COMPILING_DLL)
|
||||
#define KIFACE_API APIEXPORT
|
||||
|
|
|
@ -1,35 +0,0 @@
|
|||
/*
|
||||
* This program source code file is part of KiCad, a free EDA CAD application.
|
||||
*
|
||||
* Copyright (C) 2024 KiCad Developers, see AUTHORS.txt for contributors.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it
|
||||
* under the terms of the GNU General Public License as published by the
|
||||
* Free Software Foundation, either version 3 of the License, or (at your
|
||||
* option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
* General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along
|
||||
* with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#ifndef JSON_COMMON_H
|
||||
#define JSON_COMMON_H
|
||||
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#include <kicommon.h>
|
||||
|
||||
/**
|
||||
* This is simply a "stub" meant to inform MSVC when compiling shared libraries that it can find
|
||||
* template instances in kicommon of nlohmann::json's various templates
|
||||
*/
|
||||
class KICOMMON_API JSON_COMMON_EXPORT_STUB final : public nlohmann::json
|
||||
{
|
||||
};
|
||||
|
||||
#endif
|
|
@ -64,7 +64,7 @@ public:
|
|||
|
||||
/**
|
||||
* Get a NETCLASS object from a given Netclass name string
|
||||
*
|
||||
*
|
||||
* @param aNetClassName the Netclass name to resolve
|
||||
* @return shared pointer to the requested NETCLASS object, or the default NETCLASS
|
||||
*/
|
||||
|
|
|
@ -30,21 +30,21 @@ class wxPoint;
|
|||
class wxRect;
|
||||
class wxSize;
|
||||
|
||||
KICOMMON_API void to_json( nlohmann::json& aJson, const wxPoint& aPoint );
|
||||
KICOMMON_API void from_json( const nlohmann::json& aJson, wxPoint& aPoint );
|
||||
KICOMMON_API bool operator<( const wxPoint& aLhs, const wxPoint& aRhs );
|
||||
extern void to_json( nlohmann::json& aJson, const wxPoint& aPoint );
|
||||
extern void from_json( const nlohmann::json& aJson, wxPoint& aPoint );
|
||||
extern bool operator<( const wxPoint& aLhs, const wxPoint& aRhs );
|
||||
|
||||
KICOMMON_API void to_json( nlohmann::json& aJson, const wxSize& aPoint );
|
||||
KICOMMON_API void from_json( const nlohmann::json& aJson, wxSize& aPoint );
|
||||
KICOMMON_API bool operator<( const wxSize& aLhs, const wxSize& aRhs );
|
||||
extern void to_json( nlohmann::json& aJson, const wxSize& aPoint );
|
||||
extern void from_json( const nlohmann::json& aJson, wxSize& aPoint );
|
||||
extern bool operator<( const wxSize& aLhs, const wxSize& aRhs );
|
||||
|
||||
KICOMMON_API void to_json( nlohmann::json& aJson, const wxRect& aRect );
|
||||
KICOMMON_API void from_json( const nlohmann::json& aJson, wxRect& aRect );
|
||||
KICOMMON_API bool operator<( const wxRect& aLhs, const wxRect& aRhs );
|
||||
extern void to_json( nlohmann::json& aJson, const wxRect& aRect );
|
||||
extern void from_json( const nlohmann::json& aJson, wxRect& aRect );
|
||||
extern bool operator<( const wxRect& aLhs, const wxRect& aRhs );
|
||||
|
||||
KICOMMON_API void to_json( nlohmann::json& aJson, const wxAuiPaneInfo& aPaneInfo );
|
||||
KICOMMON_API void from_json( const nlohmann::json& aJson, wxAuiPaneInfo& aPaneInfo );
|
||||
KICOMMON_API bool operator<( const wxAuiPaneInfo& aLhs, const wxAuiPaneInfo& aRhs );
|
||||
KICOMMON_API bool operator==( const wxAuiPaneInfo& aLhs, const wxAuiPaneInfo& aRhs );
|
||||
extern void to_json( nlohmann::json& aJson, const wxAuiPaneInfo& aPaneInfo );
|
||||
extern void from_json( const nlohmann::json& aJson, wxAuiPaneInfo& aPaneInfo );
|
||||
extern bool operator<( const wxAuiPaneInfo& aLhs, const wxAuiPaneInfo& aRhs );
|
||||
extern bool operator==( const wxAuiPaneInfo& aLhs, const wxAuiPaneInfo& aRhs );
|
||||
|
||||
#endif // _AUI_SETTINGS_H_
|
||||
|
|
|
@ -27,7 +27,7 @@
|
|||
#include <i18n_utility.h>
|
||||
|
||||
// A single field within a BOM, e.g. Reference, Value, Footprint
|
||||
struct KICOMMON_API BOM_FIELD
|
||||
struct BOM_FIELD
|
||||
{
|
||||
wxString name;
|
||||
wxString label;
|
||||
|
@ -37,16 +37,16 @@ struct KICOMMON_API BOM_FIELD
|
|||
bool operator==( const BOM_FIELD& rhs ) const;
|
||||
};
|
||||
|
||||
KICOMMON_API bool operator!=( const BOM_FIELD& lhs, const BOM_FIELD& rhs );
|
||||
KICOMMON_API bool operator<( const BOM_FIELD& lhs, const BOM_FIELD& rhs );
|
||||
bool operator!=( const BOM_FIELD& lhs, const BOM_FIELD& rhs );
|
||||
bool operator<( const BOM_FIELD& lhs, const BOM_FIELD& rhs );
|
||||
|
||||
KICOMMON_API void to_json( nlohmann::json& j, const BOM_FIELD& f );
|
||||
KICOMMON_API void from_json( const nlohmann::json& j, BOM_FIELD& f );
|
||||
void to_json( nlohmann::json& j, const BOM_FIELD& f );
|
||||
void from_json( const nlohmann::json& j, BOM_FIELD& f );
|
||||
|
||||
|
||||
// A complete preset defining a BOM "View" with a list of all the fields to show,
|
||||
// group by, order, filtering settings, etc.
|
||||
struct KICOMMON_API BOM_PRESET
|
||||
struct BOM_PRESET
|
||||
{
|
||||
wxString name;
|
||||
bool readOnly = false;
|
||||
|
@ -66,15 +66,15 @@ struct KICOMMON_API BOM_PRESET
|
|||
static std::vector<BOM_PRESET> BuiltInPresets();
|
||||
};
|
||||
|
||||
KICOMMON_API bool operator!=( const BOM_PRESET& lhs, const BOM_PRESET& rhs );
|
||||
KICOMMON_API bool operator<( const BOM_PRESET& lhs, const BOM_PRESET& rhs );
|
||||
bool operator!=( const BOM_PRESET& lhs, const BOM_PRESET& rhs );
|
||||
bool operator<( const BOM_PRESET& lhs, const BOM_PRESET& rhs );
|
||||
|
||||
KICOMMON_API void to_json( nlohmann::json& j, const BOM_PRESET& f );
|
||||
KICOMMON_API void from_json( const nlohmann::json& j, BOM_PRESET& f );
|
||||
void to_json( nlohmann::json& j, const BOM_PRESET& f );
|
||||
void from_json( const nlohmann::json& j, BOM_PRESET& f );
|
||||
|
||||
|
||||
// A formatting preset, like CSV (Comma Separated Values)
|
||||
struct KICOMMON_API BOM_FMT_PRESET
|
||||
struct BOM_FMT_PRESET
|
||||
{
|
||||
wxString name;
|
||||
bool readOnly = false;
|
||||
|
@ -94,11 +94,11 @@ struct KICOMMON_API BOM_FMT_PRESET
|
|||
static std::vector<BOM_FMT_PRESET> BuiltInPresets();
|
||||
};
|
||||
|
||||
KICOMMON_API bool operator!=( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs );
|
||||
KICOMMON_API bool operator<( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs );
|
||||
bool operator!=( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs );
|
||||
bool operator<( const BOM_FMT_PRESET& lhs, const BOM_FMT_PRESET& rhs );
|
||||
|
||||
KICOMMON_API void to_json( nlohmann::json& j, const BOM_FMT_PRESET& f );
|
||||
KICOMMON_API void from_json( const nlohmann::json& j, BOM_FMT_PRESET& f );
|
||||
void to_json( nlohmann::json& j, const BOM_FMT_PRESET& f );
|
||||
void from_json( const nlohmann::json& j, BOM_FMT_PRESET& f );
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -30,7 +30,7 @@ class UNITS_PROVIDER;
|
|||
/**
|
||||
* Common grid settings, available to every frame
|
||||
*/
|
||||
struct KICOMMON_API GRID
|
||||
struct GRID
|
||||
{
|
||||
bool operator==( const GRID& aOther ) const;
|
||||
|
||||
|
@ -53,11 +53,11 @@ struct KICOMMON_API GRID
|
|||
wxString y;
|
||||
};
|
||||
|
||||
KICOMMON_API bool operator!=( const GRID& lhs, const GRID& rhs );
|
||||
KICOMMON_API bool operator<( const GRID& lhs, const GRID& rhs );
|
||||
bool operator!=( const GRID& lhs, const GRID& rhs );
|
||||
bool operator<( const GRID& lhs, const GRID& rhs );
|
||||
|
||||
KICOMMON_API void to_json( nlohmann::json& j, const GRID& g );
|
||||
KICOMMON_API void from_json( const nlohmann::json& j, GRID& g );
|
||||
void to_json( nlohmann::json& j, const GRID& g );
|
||||
void from_json( const nlohmann::json& j, GRID& g );
|
||||
|
||||
|
||||
struct GRID_SETTINGS
|
||||
|
|
|
@ -28,27 +28,21 @@
|
|||
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <settings/json_settings_internals.h>
|
||||
|
||||
#include <kicommon.h>
|
||||
#include <nlohmann/json_fwd.hpp>
|
||||
|
||||
class wxConfigBase;
|
||||
class NESTED_SETTINGS;
|
||||
class PARAM_BASE;
|
||||
class SETTINGS_MANAGER;
|
||||
|
||||
class wxAuiPaneInfo;
|
||||
struct BOM_FIELD;
|
||||
struct BOM_PRESET;
|
||||
struct BOM_FMT_PRESET;
|
||||
struct GRID;
|
||||
|
||||
namespace KIGFX
|
||||
{
|
||||
class COLOR4D;
|
||||
};
|
||||
|
||||
#define traceSettings wxT( "KICAD_SETTINGS" )
|
||||
/**
|
||||
* Flag to enable debug output of settings operations and management.
|
||||
*
|
||||
* Use "KICAD_SETTINGS" to enable.
|
||||
*
|
||||
* @ingroup trace_env_vars
|
||||
*/
|
||||
extern const wxChar* const traceSettings;
|
||||
|
||||
enum class SETTINGS_LOC {
|
||||
USER, ///< The main config directory (e.g. ~/.config/kicad/)
|
||||
|
@ -62,7 +56,7 @@ enum class SETTINGS_LOC {
|
|||
/// pimpl to allow hiding json.hpp
|
||||
class JSON_SETTINGS_INTERNALS;
|
||||
|
||||
class KICOMMON_API JSON_SETTINGS
|
||||
class JSON_SETTINGS
|
||||
{
|
||||
public:
|
||||
friend class NESTED_SETTINGS;
|
||||
|
@ -346,32 +340,14 @@ protected:
|
|||
|
||||
// Specializations to allow conversion between wxString and std::string via JSON_SETTINGS API
|
||||
|
||||
template<> KICOMMON_API std::optional<wxString> JSON_SETTINGS::Get( const std::string& aPath ) const;
|
||||
template<> std::optional<wxString> JSON_SETTINGS::Get( const std::string& aPath ) const;
|
||||
|
||||
template<> KICOMMON_API void JSON_SETTINGS::Set<wxString>( const std::string& aPath, wxString aVal );
|
||||
template<> void JSON_SETTINGS::Set<wxString>( const std::string& aPath, wxString aVal );
|
||||
|
||||
// Specializations to allow directly reading/writing wxStrings from JSON
|
||||
|
||||
KICOMMON_API void to_json( nlohmann::json& aJson, const wxString& aString );
|
||||
void to_json( nlohmann::json& aJson, const wxString& aString );
|
||||
|
||||
KICOMMON_API void from_json( const nlohmann::json& aJson, wxString& aString );
|
||||
|
||||
extern template std::optional<bool> JSON_SETTINGS::Get<bool>( const std::string& aPath ) const;
|
||||
extern template std::optional<double> JSON_SETTINGS::Get<double>( const std::string& aPath ) const;
|
||||
extern template std::optional<float> JSON_SETTINGS::Get<float>( const std::string& aPath ) const;
|
||||
extern template std::optional<int> JSON_SETTINGS::Get<int>( const std::string& aPath ) const;
|
||||
extern template std::optional<unsigned int> JSON_SETTINGS::Get<unsigned int>( const std::string& aPath ) const;
|
||||
extern template std::optional<unsigned long long> JSON_SETTINGS::Get<unsigned long long>( const std::string& aPath ) const;
|
||||
extern template std::optional<std::string> JSON_SETTINGS::Get<std::string>( const std::string& aPath ) const;
|
||||
extern template std::optional<nlohmann::json> JSON_SETTINGS::Get<nlohmann::json>( const std::string& aPath ) const;
|
||||
extern template std::optional<KIGFX::COLOR4D> JSON_SETTINGS::Get<KIGFX::COLOR4D>( const std::string& aPath ) const;
|
||||
extern template std::optional<BOM_FIELD> JSON_SETTINGS::Get<BOM_FIELD>( const std::string& aPath ) const;
|
||||
extern template std::optional<BOM_PRESET> JSON_SETTINGS::Get<BOM_PRESET>( const std::string& aPath ) const;
|
||||
extern template std::optional<BOM_FMT_PRESET> JSON_SETTINGS::Get<BOM_FMT_PRESET>( const std::string& aPath ) const;
|
||||
extern template std::optional<GRID> JSON_SETTINGS::Get<GRID>( const std::string& aPath ) const;
|
||||
extern template std::optional<wxPoint> JSON_SETTINGS::Get<wxPoint>( const std::string& aPath ) const;
|
||||
extern template std::optional<wxSize> JSON_SETTINGS::Get<wxSize>( const std::string& aPath ) const;
|
||||
extern template std::optional<wxRect> JSON_SETTINGS::Get<wxRect>( const std::string& aPath ) const;
|
||||
extern template std::optional<wxAuiPaneInfo> JSON_SETTINGS::Get<wxAuiPaneInfo>( const std::string& aPath ) const;
|
||||
void from_json( const nlohmann::json& aJson, wxString& aString );
|
||||
|
||||
#endif
|
||||
|
|
|
@ -21,9 +21,10 @@
|
|||
#ifndef KICAD_JSON_SETTINGS_INTERNALS_H
|
||||
#define KICAD_JSON_SETTINGS_INTERNALS_H
|
||||
|
||||
#include <json_common.h>
|
||||
// This is a pretty heavy file. Try to use json_fwd.hpp most places.
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
class KICOMMON_API JSON_SETTINGS_INTERNALS : public nlohmann::json
|
||||
class JSON_SETTINGS_INTERNALS : public nlohmann::json
|
||||
{
|
||||
friend class JSON_SETTINGS;
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
* NESTED_SETTINGS is a JSON_SETTINGS that lives inside a JSON_SETTINGS.
|
||||
* Instead of being backed by a JSON file on disk, it loads and stores to its parent.
|
||||
*/
|
||||
class KICOMMON_API NESTED_SETTINGS : public JSON_SETTINGS
|
||||
class NESTED_SETTINGS : public JSON_SETTINGS
|
||||
{
|
||||
public:
|
||||
NESTED_SETTINGS( const std::string& aName, int aSchemaVersion, JSON_SETTINGS* aParent,
|
||||
|
|
|
@ -27,13 +27,10 @@
|
|||
#include <math/util.h>
|
||||
|
||||
#include <optional>
|
||||
#include <gal/color4d.h>
|
||||
#include <settings/json_settings.h>
|
||||
#include <settings/bom_settings.h>
|
||||
#include <settings/grid_settings.h>
|
||||
#include <kicommon.h>
|
||||
|
||||
class KICOMMON_API PARAM_BASE
|
||||
|
||||
class PARAM_BASE
|
||||
{
|
||||
public:
|
||||
PARAM_BASE( std::string aJsonPath, bool aReadOnly ) :
|
||||
|
@ -170,7 +167,7 @@ protected:
|
|||
/**
|
||||
* Stores a path as a string with directory separators normalized to unix-style
|
||||
*/
|
||||
class KICOMMON_API PARAM_PATH : public PARAM<wxString>
|
||||
class PARAM_PATH : public PARAM<wxString>
|
||||
{
|
||||
public:
|
||||
PARAM_PATH( const std::string& aJsonPath, wxString* aPtr, const wxString& aDefault,
|
||||
|
@ -302,26 +299,7 @@ public:
|
|||
m_setter( std::move( aSetter ) )
|
||||
{ }
|
||||
|
||||
void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
|
||||
{
|
||||
if( m_readOnly )
|
||||
return;
|
||||
|
||||
if( std::is_same<ValueType, nlohmann::json>::value )
|
||||
{
|
||||
if( std::optional<nlohmann::json> optval = aSettings->GetJson( m_path ) )
|
||||
m_setter( *optval );
|
||||
else
|
||||
m_setter( m_default );
|
||||
}
|
||||
else
|
||||
{
|
||||
if( std::optional<ValueType> optval = aSettings->Get<ValueType>( m_path ) )
|
||||
m_setter( *optval );
|
||||
else
|
||||
m_setter( m_default );
|
||||
}
|
||||
}
|
||||
void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override;
|
||||
|
||||
void Store( JSON_SETTINGS* aSettings ) const override
|
||||
{
|
||||
|
@ -344,22 +322,7 @@ public:
|
|||
m_setter( m_default );
|
||||
}
|
||||
|
||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override
|
||||
{
|
||||
if( std::is_same<ValueType, nlohmann::json>::value )
|
||||
{
|
||||
if( std::optional<nlohmann::json> optval = aSettings->GetJson( m_path ) )
|
||||
return *optval == m_getter();
|
||||
}
|
||||
else
|
||||
{
|
||||
if( std::optional<ValueType> optval = aSettings->Get<ValueType>( m_path ) )
|
||||
return *optval == m_getter();
|
||||
}
|
||||
|
||||
// Not in file
|
||||
return false;
|
||||
}
|
||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
|
||||
|
||||
private:
|
||||
ValueType m_default;
|
||||
|
@ -368,11 +331,6 @@ private:
|
|||
};
|
||||
|
||||
|
||||
extern template class APIVISIBLE PARAM_LAMBDA<bool>;
|
||||
extern template class APIVISIBLE PARAM_LAMBDA<int>;
|
||||
extern template class APIVISIBLE PARAM_LAMBDA<nlohmann::json>;
|
||||
extern template class APIVISIBLE PARAM_LAMBDA<std::string>;
|
||||
|
||||
/**
|
||||
* Represents a parameter that has a scaling factor between the value in the file and the
|
||||
* value used internally (i.e. the value pointer). This basically only makes sense to use
|
||||
|
@ -481,85 +439,22 @@ public:
|
|||
m_default( std::move( aDefault ) )
|
||||
{ }
|
||||
|
||||
void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
|
||||
{
|
||||
if( m_readOnly )
|
||||
return;
|
||||
void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override;
|
||||
|
||||
if( std::optional<nlohmann::json> js = aSettings->GetJson( m_path ) )
|
||||
{
|
||||
std::vector<Type> val;
|
||||
|
||||
if( js->is_array() )
|
||||
{
|
||||
for( const auto& el : js->items() )
|
||||
val.push_back( el.value().get<Type>() );
|
||||
}
|
||||
|
||||
*m_ptr = val;
|
||||
}
|
||||
else if( aResetIfMissing )
|
||||
*m_ptr = m_default;
|
||||
}
|
||||
|
||||
void Store( JSON_SETTINGS* aSettings ) const override
|
||||
{
|
||||
nlohmann::json js = nlohmann::json::array();
|
||||
|
||||
for( const auto& el : *m_ptr )
|
||||
js.push_back( el );
|
||||
|
||||
aSettings->Set<nlohmann::json>( m_path, js );
|
||||
}
|
||||
void Store( JSON_SETTINGS* aSettings) const override;
|
||||
|
||||
void SetDefault() override
|
||||
{
|
||||
*m_ptr = m_default;
|
||||
}
|
||||
|
||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override
|
||||
{
|
||||
if( std::optional<nlohmann::json> js = aSettings->GetJson( m_path ) )
|
||||
{
|
||||
if( js->is_array() )
|
||||
{
|
||||
std::vector<Type> val;
|
||||
|
||||
for( const auto& el : js->items() )
|
||||
{
|
||||
try
|
||||
{
|
||||
val.emplace_back( el.value().get<Type>() );
|
||||
}
|
||||
catch( ... )
|
||||
{
|
||||
// Probably typecast didn't work; skip this element
|
||||
}
|
||||
}
|
||||
|
||||
return val == *m_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
|
||||
|
||||
protected:
|
||||
std::vector<Type>* m_ptr;
|
||||
std::vector<Type> m_default;
|
||||
};
|
||||
|
||||
|
||||
extern template class APIVISIBLE PARAM_LIST<int>;
|
||||
extern template class APIVISIBLE PARAM_LIST<double>;
|
||||
extern template class APIVISIBLE PARAM_LIST<KIGFX::COLOR4D>;
|
||||
//template KICOMMON_EXTERN_DECL class PARAM_LIST<FILE_INFO_PAIR>;
|
||||
extern template class APIVISIBLE PARAM_LIST<struct BOM_PRESET>;
|
||||
extern template class APIVISIBLE PARAM_LIST<struct BOM_FMT_PRESET>;
|
||||
extern template class APIVISIBLE PARAM_LIST<GRID>;
|
||||
extern template class APIVISIBLE PARAM_LIST<wxString>;
|
||||
|
||||
|
||||
template<typename Type>
|
||||
class PARAM_SET : public PARAM_BASE
|
||||
{
|
||||
|
@ -578,73 +473,27 @@ public:
|
|||
m_default( aDefault )
|
||||
{ }
|
||||
|
||||
void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
|
||||
{
|
||||
if( m_readOnly )
|
||||
return;
|
||||
|
||||
if( std::optional<nlohmann::json> js = aSettings->GetJson( m_path ) )
|
||||
{
|
||||
std::set<Type> val;
|
||||
|
||||
if( js->is_array() )
|
||||
{
|
||||
for( const auto& el : js->items() )
|
||||
val.insert( el.value().get<Type>() );
|
||||
}
|
||||
|
||||
*m_ptr = val;
|
||||
}
|
||||
else if( aResetIfMissing )
|
||||
*m_ptr = m_default;
|
||||
}
|
||||
|
||||
void Store( JSON_SETTINGS* aSettings) const override
|
||||
{
|
||||
nlohmann::json js = nlohmann::json::array();
|
||||
|
||||
for( const auto& el : *m_ptr )
|
||||
js.push_back( el );
|
||||
|
||||
aSettings->Set<nlohmann::json>( m_path, js );
|
||||
}
|
||||
void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override;
|
||||
|
||||
void Store( JSON_SETTINGS* aSettings) const override;
|
||||
|
||||
void SetDefault() override
|
||||
{
|
||||
*m_ptr = m_default;
|
||||
}
|
||||
|
||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override
|
||||
{
|
||||
if( std::optional<nlohmann::json> js = aSettings->GetJson( m_path ) )
|
||||
{
|
||||
if( js->is_array() )
|
||||
{
|
||||
std::set<Type> val;
|
||||
|
||||
for( const auto& el : js->items() )
|
||||
val.insert( el.value().get<Type>() );
|
||||
|
||||
return val == *m_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
|
||||
|
||||
protected:
|
||||
std::set<Type>* m_ptr;
|
||||
std::set<Type> m_default;
|
||||
};
|
||||
|
||||
extern template class APIVISIBLE PARAM_SET<wxString>;
|
||||
|
||||
/**
|
||||
* Represents a list of strings holding directory paths.
|
||||
* Normalizes paths to unix directory separator style in the file.
|
||||
*/
|
||||
class KICOMMON_API PARAM_PATH_LIST : public PARAM_LIST<wxString>
|
||||
class PARAM_PATH_LIST : public PARAM_LIST<wxString>
|
||||
{
|
||||
public:
|
||||
PARAM_PATH_LIST( const std::string& aJsonPath, std::vector<wxString>* aPtr,
|
||||
|
@ -714,60 +563,16 @@ public:
|
|||
m_default( aDefault )
|
||||
{ }
|
||||
|
||||
void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override
|
||||
{
|
||||
if( m_readOnly )
|
||||
return;
|
||||
void Load( JSON_SETTINGS* aSettings, bool aResetIfMissing = true ) const override;
|
||||
|
||||
if( std::optional<nlohmann::json> js = aSettings->GetJson( m_path ) )
|
||||
{
|
||||
if( js->is_object() )
|
||||
{
|
||||
m_ptr->clear();
|
||||
|
||||
for( const auto& el : js->items() )
|
||||
( *m_ptr )[el.key()] = el.value().get<Value>();
|
||||
}
|
||||
}
|
||||
else if( aResetIfMissing )
|
||||
*m_ptr = m_default;
|
||||
}
|
||||
|
||||
void Store( JSON_SETTINGS* aSettings) const override
|
||||
{
|
||||
nlohmann::json js( {} );
|
||||
|
||||
for( const auto& el : *m_ptr )
|
||||
js[el.first] = el.second;
|
||||
|
||||
aSettings->Set<nlohmann::json>( m_path, js );
|
||||
}
|
||||
void Store( JSON_SETTINGS* aSettings) const override;
|
||||
|
||||
virtual void SetDefault() override
|
||||
{
|
||||
*m_ptr = m_default;
|
||||
}
|
||||
|
||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override
|
||||
{
|
||||
if( std::optional<nlohmann::json> js = aSettings->GetJson( m_path ) )
|
||||
{
|
||||
if( js->is_object() )
|
||||
{
|
||||
if( m_ptr->size() != js->size() )
|
||||
return false;
|
||||
|
||||
std::map<std::string, Value> val;
|
||||
|
||||
for( const auto& el : js->items() )
|
||||
val[el.key()] = el.value().get<Value>();
|
||||
|
||||
return val == *m_ptr;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
bool MatchesFile( JSON_SETTINGS* aSettings ) const override;
|
||||
|
||||
private:
|
||||
std::map<std::string, Value>* m_ptr;
|
||||
|
@ -775,15 +580,10 @@ private:
|
|||
};
|
||||
|
||||
|
||||
extern template class APIVISIBLE PARAM_MAP<int>;
|
||||
extern template class APIVISIBLE PARAM_MAP<double>;
|
||||
extern template class APIVISIBLE PARAM_MAP<bool>;
|
||||
|
||||
|
||||
/**
|
||||
* A helper for <wxString, wxString> maps
|
||||
*/
|
||||
class KICOMMON_API PARAM_WXSTRING_MAP : public PARAM_BASE
|
||||
class PARAM_WXSTRING_MAP : public PARAM_BASE
|
||||
{
|
||||
public:
|
||||
PARAM_WXSTRING_MAP( const std::string& aJsonPath, std::map<wxString, wxString>* aPtr,
|
||||
|
|
|
@ -27,7 +27,6 @@
|
|||
#include <functional>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <json_common.h>
|
||||
#include <nlohmann/json-schema.hpp>
|
||||
#include <thread>
|
||||
#include <tuple>
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "core/wx_stl_compat.h"
|
||||
|
||||
#include <map>
|
||||
#include <json_common.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <core/json_serializers.h>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
#include <wx/zipstrm.h>
|
||||
#include <wx/log.h>
|
||||
|
||||
#include <json_common.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
#include <core/json_serializers.h>
|
||||
#include <core/map_helpers.h>
|
||||
#include <string_utf8_map.h>
|
||||
|
|
|
@ -6,8 +6,6 @@ add_library( nlohmann_json_schema_validator STATIC
|
|||
string-format-check.cpp
|
||||
)
|
||||
|
||||
add_dependencies( nlohmann_json_schema_validator kicommon )
|
||||
|
||||
target_include_directories( nlohmann_json_schema_validator
|
||||
PUBLIC
|
||||
$<INSTALL_INTERFACE:include>
|
||||
|
@ -16,5 +14,4 @@ target_include_directories( nlohmann_json_schema_validator
|
|||
|
||||
target_link_libraries( nlohmann_json_schema_validator
|
||||
PUBLIC nlohmann_json
|
||||
PRIVATE kicommon
|
||||
)
|
||||
|
|
|
@ -21,7 +21,6 @@
|
|||
# define JSON_SCHEMA_VALIDATOR_API
|
||||
#endif
|
||||
|
||||
#include <json_common.h>
|
||||
#include <nlohmann/json.hpp>
|
||||
|
||||
#ifdef NLOHMANN_JSON_VERSION_MAJOR
|
||||
|
|
Loading…
Reference in New Issue