4#ifndef _ZDCJSONConfig_h
5#define _ZDCJSONConfig_h
7#include <nlohmann/json.hpp>
18 using JSON = nlohmann::json;
32 template<
typename T>
bool
33 checkType(T value, JSON::value_t paramType,
int paramSize = -1)
35 if (value.is_null())
return false;
37 if (value.type() == paramType) {
38 if (paramSize == -1)
return true;
39 else if (value.size() ==
size_t(paramSize))
return true;
43 if (value.is_primitive()) {
44 if (paramType == JSON::value_t::number_float) {
45 if (value.type() == JSON::value_t::number_integer ||
46 value.type() == JSON::value_t::number_unsigned)
return true;
48 else if (paramType == JSON::value_t::number_integer &&
49 value.type() == JSON::value_t::number_unsigned)
return true;
50 else if (paramType == JSON::value_t::number_integer &&
51 value.type() == JSON::value_t::number_float) {
53 if (std::abs(std::floor(fvalue)-fvalue) < 1e-6)
return true;
60 template<
typename T>
void
67 if (chanConfig.find(key) == chanConfig.end()) {
68 chanConfig[key] = value;
73 template<
typename T>
void
80 template<
typename T>
void
94 template<
typename T> std::pair<bool, std::string>
95 ParsePerChannelParams(
const std::string& paramKey,
const T& paramValue, JSON::value_t paramType,
size_t paramSize);
100 ZDCJSONConfig(
const std::vector<std::string>& sideNames,
size_t numChannelsPerSide) :
121 if (iter.value().is_null())
return false;
123 returnValue = iter.value().get_to(returnValue);
135 if (!(side <
m_nSides && channel <
m_numChannelsPerSide))
throw std::runtime_error(
"ZDCJSONConfig::getChannelConfig(): bad arm or side index");
std::pair< bool, std::string > ParseConfig(const JSON &config, const JSONParamList &JSONConfigParams)
std::map< std::string, JSONParamDescr > JSONParamList
bool getGlobalParam(std::string key, T &returnValue)
ZDCJSONConfig(const std::vector< std::string > &sideNames, size_t numChannelsPerSide)
std::vector< JSON > m_channelConfig
void setAllParameter(const std::string &key, T value)
bool checkType(T value, JSON::value_t paramType, int paramSize=-1)
const JSON & getChannelConfig(size_t side, size_t channel) const
void setChannelParameter(unsigned int side, unsigned int chanIndex, const std::string &key, T value)
size_t m_numChannelsPerSide
std::tuple< JSON::value_t, unsigned int, bool, bool > JSONParamDescr
std::vector< std::string > m_sideLabels
void setPerSideParameter(unsigned int side, std::string key, T value)
std::pair< bool, std::string > ParsePerChannelParams(const std::string ¶mKey, const T ¶mValue, JSON::value_t paramType, size_t paramSize)
std::string find(const std::string &s)
return a remapped string