KiCad PCB EDA Suite
Loading...
Searching...
No Matches
json_settings_internals.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 (C) 2021 Jon Evans <[email protected]>
5 * Copyright (C) 2021 KiCad Developers, see AUTHORS.txt for contributors.
6 *
7 * This program is free software: you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation, either version 3 of the License, or (at your
10 * option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program. If not, see <http://www.gnu.org/licenses/>.
19 */
20
21#ifndef KICAD_JSON_SETTINGS_INTERNALS_H
22#define KICAD_JSON_SETTINGS_INTERNALS_H
23
24#include <json_common.h>
25
26class KICOMMON_API JSON_SETTINGS_INTERNALS : public nlohmann::json
27{
28 friend class JSON_SETTINGS;
29
30public:
32 nlohmann::json()
33 {}
34
40 static nlohmann::json::json_pointer PointerFromString( std::string aPath );
41
42 template<typename ValueType>
43 void SetFromString( const std::string& aPath, ValueType aVal )
44 {
45 // Calls the overload below, which will convert from dotted string to JSON pointer
46 ( *this )[aPath] = std::move( aVal );
47 }
48
49 template<typename ValueType>
50 ValueType Get( const std::string& aPath ) const
51 {
52 return at( PointerFromString( aPath ) ).get<ValueType>();
53 }
54
55 nlohmann::json& At( const std::string& aPath )
56 {
57 return at( PointerFromString( aPath ) );
58 }
59
60 nlohmann::json& operator[]( const nlohmann::json::json_pointer& aPointer )
61 {
62 return nlohmann::json::operator[]( aPointer );
63 }
64
65 nlohmann::json& operator[]( const std::string& aPath )
66 {
67 return nlohmann::json::operator[]( PointerFromString( aPath ) );
68 }
69
70 void CloneFrom( const JSON_SETTINGS_INTERNALS& aOther )
71 {
72 nlohmann::json::json_pointer root( "" );
73 this->nlohmann::json::operator[]( root ) = aOther.nlohmann::json::operator[]( root );
74 }
75
76private:
77
78 nlohmann::json m_original;
79};
80
81#endif // KICAD_JSON_SETTINGS_INTERNALS_H
nlohmann::json & At(const std::string &aPath)
nlohmann::json & operator[](const std::string &aPath)
nlohmann::json & operator[](const nlohmann::json::json_pointer &aPointer)
void SetFromString(const std::string &aPath, ValueType aVal)
void CloneFrom(const JSON_SETTINGS_INTERNALS &aOther)
ValueType Get(const std::string &aPath) const
nlohmann::json json
Definition: gerbview.cpp:47
#define KICOMMON_API
Definition: kicommon.h:28