KiCad PCB EDA Suite
JSON_SETTINGS_INTERNALS Class Reference

#include <json_settings_internals.h>

Inheritance diagram for JSON_SETTINGS_INTERNALS:

Public Member Functions

 JSON_SETTINGS_INTERNALS ()
 
template<typename ValueType >
void SetFromString (const std::string &aPath, ValueType aVal)
 
template<typename ValueType >
ValueType Get (const std::string &aPath) const
 
nlohmann::jsonAt (const std::string &aPath)
 
nlohmann::jsonoperator[] (const nlohmann::json::json_pointer &aPointer)
 
nlohmann::jsonoperator[] (const std::string &aPath)
 
void CloneFrom (const JSON_SETTINGS_INTERNALS &aOther)
 

Static Public Member Functions

static nlohmann::json::json_pointer PointerFromString (std::string aPath)
 Builds a JSON pointer based on a given string. More...
 

Friends

class JSON_SETTINGS
 

Detailed Description

Definition at line 27 of file json_settings_internals.h.

Constructor & Destructor Documentation

◆ JSON_SETTINGS_INTERNALS()

JSON_SETTINGS_INTERNALS::JSON_SETTINGS_INTERNALS ( )
inline

Definition at line 32 of file json_settings_internals.h.

32 :
34 {}
nlohmann::json json
Definition: gerbview.cpp:44

Member Function Documentation

◆ At()

nlohmann::json & JSON_SETTINGS_INTERNALS::At ( const std::string &  aPath)
inline

Definition at line 56 of file json_settings_internals.h.

57 {
58 return at( PointerFromString( aPath ) );
59 }
static nlohmann::json::json_pointer PointerFromString(std::string aPath)
Builds a JSON pointer based on a given string.

References PointerFromString().

◆ CloneFrom()

void JSON_SETTINGS_INTERNALS::CloneFrom ( const JSON_SETTINGS_INTERNALS aOther)
inline

Definition at line 71 of file json_settings_internals.h.

72 {
73 nlohmann::json::json_pointer root( "" );
74 this->nlohmann::json::operator[]( root ) = aOther.nlohmann::json::operator[]( root );
75 }

◆ Get()

template<typename ValueType >
ValueType JSON_SETTINGS_INTERNALS::Get ( const std::string &  aPath) const
inline

Definition at line 51 of file json_settings_internals.h.

52 {
53 return at( PointerFromString( aPath ) ).get<ValueType>();
54 }

References PointerFromString().

◆ operator[]() [1/2]

nlohmann::json & JSON_SETTINGS_INTERNALS::operator[] ( const nlohmann::json::json_pointer &  aPointer)
inline

Definition at line 61 of file json_settings_internals.h.

62 {
63 return nlohmann::json::operator[]( aPointer );
64 }

◆ operator[]() [2/2]

nlohmann::json & JSON_SETTINGS_INTERNALS::operator[] ( const std::string &  aPath)
inline

Definition at line 66 of file json_settings_internals.h.

67 {
68 return nlohmann::json::operator[]( PointerFromString( aPath ) );
69 }

References PointerFromString().

◆ PointerFromString()

nlohmann::json::json_pointer JSON_SETTINGS_INTERNALS::PointerFromString ( std::string  aPath)
static

Builds a JSON pointer based on a given string.

Parameters
aPathis the path in the form "key1.key2.key3"
Returns
a JSON pointer that can be used to index into a JSON object

Definition at line 44 of file json_settings.cpp.

45{
46 std::replace( aPath.begin(), aPath.end(), '.', '/' );
47 aPath.insert( 0, "/" );
48
49 nlohmann::json::json_pointer p;
50
51 try
52 {
53 p = nlohmann::json::json_pointer( aPath );
54 }
55 catch( ... )
56 {
57 wxASSERT_MSG( false, wxT( "Invalid pointer path in PointerFromString!" ) );
58 }
59
60 return p;
61}

Referenced by At(), JSON_SETTINGS::Contains(), JSON_SETTINGS::Count(), Get(), BOARD_DESIGN_SETTINGS::LoadFromFile(), PCB_CALCULATOR_SETTINGS::MigrateFromLegacy(), operator[](), and JSON_SETTINGS::SetIfPresent().

◆ SetFromString()

template<typename ValueType >
void JSON_SETTINGS_INTERNALS::SetFromString ( const std::string &  aPath,
ValueType  aVal 
)
inline

Definition at line 44 of file json_settings_internals.h.

45 {
46 // Calls the overload below, which will convert from dotted string to JSON pointer
47 ( *this )[aPath] = aVal;
48 }

Friends And Related Function Documentation

◆ JSON_SETTINGS

friend class JSON_SETTINGS
friend

Definition at line 29 of file json_settings_internals.h.


The documentation for this class was generated from the following files: