Loading...
Searching...
No Matches
ParametersJSON.cpp File Reference
#include "eon/ParametersJSON.h"
#include "eon/HelperFunctions.h"
#include "eon/Parameters.h"
#include "eon/ParametersINI.h"
#include "magic_enum/magic_enum.hpp"
#include <cctype>
#include <format>
#include <nlohmann/json.hpp>
#include <stdexcept>

Go to the source code of this file.

Namespaces

namespace  eonc
 RAII resource manager for the ARTn C library with global synchronization.
namespace  eonc::config

Macros

#define JSON_OPT(j, key, target)

Typedefs

using json = nlohmann::json

Functions

template<typename E>
static json enum_to_json (E val)
template<typename E>
static E enum_from_json (const json &j, E fallback)
json eonc::config::to_json (const Parameters &params)
 Serialize all Parameters to JSON.
void eonc::config::from_json (const nlohmann::json &j, Parameters &params)
 Deserialize JSON into Parameters, then resolve computed fields.
int eonc::config::load_json (const std::string &json_str, Parameters &params)
 Load Parameters from a JSON string. Returns 0 on success.

Macro Definition Documentation

◆ JSON_OPT

#define JSON_OPT ( j,
key,
target )
Value:
if ((j).contains(key)) \
(target) = (j).at(key).get<decltype(target)>()

Definition at line 40 of file ParametersJSON.cpp.

40#define JSON_OPT(j, key, target) \
41 if ((j).contains(key)) \
42 (target) = (j).at(key).get<decltype(target)>()

Typedef Documentation

◆ json

using json = nlohmann::json

Definition at line 23 of file ParametersJSON.cpp.

Function Documentation

◆ enum_from_json()

template<typename E>
E enum_from_json ( const json & j,
E fallback )
static

Definition at line 30 of file ParametersJSON.cpp.

30 {
31 if (j.is_string()) {
32 auto result = magic_enum::enum_cast<E>(j.get<std::string>(),
33 magic_enum::case_insensitive);
34 return result.value_or(fallback);
35 }
36 return fallback;
37}

◆ enum_to_json()

template<typename E>
json enum_to_json ( E val)
static

Definition at line 26 of file ParametersJSON.cpp.

26 {
27 return std::string(magic_enum::enum_name(val));
28}