From 7d23adb596bac7dbb8ecfb442ade7149291d429b Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 10 Jun 2021 14:05:57 +0200 Subject: [PATCH 001/477] remove effective coupling code The effective coupling module has been superseded by FlexibleDecay. --- CHANGES.rst | 17 +- meta/EffectiveCouplings.m | 801 ------------ meta/FlexibleSUSY.m | 106 +- meta/Observables.m | 211 +-- meta/WriteOut.m | 59 - meta/module.mk | 1 - model_specific/SM/module.mk | 2 - .../SM/standard_model_effective_couplings.cpp | 513 -------- .../SM/standard_model_effective_couplings.hpp | 113 -- src/effective_couplings.cpp | 1145 ----------------- src/effective_couplings.hpp | 47 - src/module.mk | 2 - templates/effective_couplings.cpp.in | 150 --- templates/effective_couplings.hpp.in | 86 -- templates/module.mk | 2 - templates/module.mk.in | 2 - templates/observables.cpp.in | 5 - test/module.mk | 11 - test/test_CMSSM_effective_couplings.cpp | 1143 ---------------- test/test_SM_effective_couplings.cpp | 259 ---- test/test_effective_couplings.cpp | 85 -- 21 files changed, 29 insertions(+), 4731 deletions(-) delete mode 100644 meta/EffectiveCouplings.m delete mode 100644 model_specific/SM/standard_model_effective_couplings.cpp delete mode 100644 model_specific/SM/standard_model_effective_couplings.hpp delete mode 100644 src/effective_couplings.cpp delete mode 100644 src/effective_couplings.hpp delete mode 100644 templates/effective_couplings.cpp.in delete mode 100644 templates/effective_couplings.hpp.in delete mode 100644 test/test_CMSSM_effective_couplings.cpp delete mode 100644 test/test_SM_effective_couplings.cpp delete mode 100644 test/test_effective_couplings.cpp diff --git a/CHANGES.rst b/CHANGES.rst index f652b2f082..1115a226b3 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,11 +1,24 @@ +FlexibleSUSY 2.6.1 [?, ?? 202?] +================================== + +Changes +------- + +* Removed code computing Higgs effective couplings. This code has been + superseded by FlexibleDecay. + +Fixed bugs +---------- + FlexibleSUSY 2.6.0 [June, 10 2021] ================================== New features ------------ -* FlexibleDecay [`arXiv:2106.05038 `_] - calculation of scalar decays with an emphasis on - Higgs decays and featuring decoupling behaviour for large BSM masses. +* FlexibleDecay [`arXiv:2106.05038 `_] + - calculation of scalar decays with an emphasis on Higgs decays and + featuring decoupling behaviour for large BSM masses. Changes ------- diff --git a/meta/EffectiveCouplings.m b/meta/EffectiveCouplings.m deleted file mode 100644 index 4bb390198f..0000000000 --- a/meta/EffectiveCouplings.m +++ /dev/null @@ -1,801 +0,0 @@ -(* :Copyright: - - ==================================================================== - This file is part of FlexibleSUSY. - - FlexibleSUSY 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. - - FlexibleSUSY 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 FlexibleSUSY. If not, see - . - ==================================================================== - -*) - -BeginPackage["EffectiveCouplings`", {"SARAH`", "CConversion`", "Parameters`", "SelfEnergies`", "TreeMasses`", "TextFormatting`", "Utils`", "Vertices`", "Constraint`"}]; - -InitializeEffectiveCouplings::usage=""; -InitializeMixingFromModelInput::usage=""; -GetMixingMatrixFromModel::usage=""; -GetNeededVerticesList::usage=""; -CalculatePartialWidths::usage=""; -CalculateQCDAmplitudeScalingFactors::usage=""; -CalculateQCDScalingFactor::usage=""; -CreateEffectiveCouplingsGetters::usage=""; -CreateEffectiveCouplingsDefinitions::usage=""; -CreateEffectiveCouplingsInit::usage=""; -CreateEffectiveCouplingsCalculation::usage=""; -CreateEffectiveCouplings::usage=""; - -(* @todo error handle when e.g. the strong coupling is not defined *) - -Begin["`Private`"]; - -InitializeMixingFromModelInput[massMatrix_TreeMasses`FSMassMatrix] := - Module[{i, macro, symbol, result = ""}, - symbol = TreeMasses`GetMixingMatrixSymbol[massMatrix]; - If[SARAH`SupersymmetricModel, - macro = "MODELPARAMETER";, - macro = "PHYSICAL"; - ]; - If[symbol === Null, - Return[""]; - ]; - If[Length[symbol] > 1, - (result = result <> ", " <> CConversion`ToValidCSymbolString[#] <> "(" <> macro <> "(" - <> CConversion`ToValidCSymbolString[#] <> "))")& /@ symbol;, - result = ", " <> CConversion`ToValidCSymbolString[symbol] - <> "(" <> macro <> "(" <> CConversion`ToValidCSymbolString[symbol] <> "))"; - ]; - result - ]; - -GetMixingMatrixFromModel[massMatrix_TreeMasses`FSMassMatrix] := - Module[{i, macro, symbol, result = ""}, - symbol = TreeMasses`GetMixingMatrixSymbol[massMatrix]; - If[symbol === Null, - Return[""]; - ]; - If[SARAH`SupersymmetricModel, - macro = "MODELPARAMETER";, - macro = "PHYSICAL"; - ]; - If[Length[symbol] > 1, - (result = result <> CConversion`ToValidCSymbolString[#] <> " = " <> macro <> "(" - <> CConversion`ToValidCSymbolString[#] <> ");\n")& /@ symbol;, - result = CConversion`ToValidCSymbolString[symbol] <> " = " <> macro <> "(" - <> CConversion`ToValidCSymbolString[symbol] <> ");\n"; - ]; - result - ]; - -CalculateQCDAmplitudeScalingFactors[] := - Module[{coeff, scalarQCD, fermionQCD, pseudoscalarQCD, body = "", - scalarScalarLoopFactor = "", scalarFermionLoopFactor = "", - pseudoscalarFermionLoopFactor = ""}, - scalarQCD = 1 + 2 SARAH`strongCoupling^2 / (3 Pi^2); - body = "result = " <> CConversion`RValueToCFormString[scalarQCD] <> ";"; - scalarScalarLoopFactor = Parameters`CreateLocalConstRefs[{SARAH`strongCoupling}] - <> "if (m_loop > m_decay) {\n" - <> TextFormatting`IndentText[body] <> "\n}"; - scalarFermionLoopFactor = Parameters`CreateLocalConstRefs[{SARAH`strongCoupling}] - <> "result = 1.0 + " - <> CConversion`RValueToCFormString[SARAH`strongCoupling^2 / (4 Pi^2)] - <> " * scalar_diphoton_fermion_loop(m_decay, m_loop);\n"; - pseudoscalarFermionLoopFactor = Parameters`CreateLocalConstRefs[{SARAH`strongCoupling}] - <> "result = 1.0 + " - <> CConversion`RValueToCFormString[SARAH`strongCoupling^2 / (4 Pi^2)] - <> " * pseudoscalar_diphoton_fermion_loop(m_decay, m_loop);\n"; - scalarScalarLoopFactor = TextFormatting`IndentText[scalarScalarLoopFactor]; - scalarFermionLoopFactor = TextFormatting`IndentText[scalarFermionLoopFactor]; - pseudoscalarFermionLoopFactor = TextFormatting`IndentText[pseudoscalarFermionLoopFactor]; - {scalarScalarLoopFactor, scalarFermionLoopFactor, pseudoscalarFermionLoopFactor} - ]; - -CalculateQCDScalingFactor[] := - Module[{nloQCD, nnloQCD, nnnloQCD, scalarFactor = "", pseudoscalarFactor = ""}, - (* NLO, NNLO and NNNLO contributions to scalar coupling *) - nloQCD = (95 / 4 - 7 / 6 Symbol["Nf"]) SARAH`strongCoupling^2 / (4 Pi^2); - nnloQCD = 149533 / 288 - 363 Zeta[2] / 8 - 495 Zeta[3] / 8 + 19 Symbol["l"] / 8; - nnloQCD = nnloQCD + Symbol["Nf"] (-4157 / 72 + 11 Zeta[2] / 2 + 5 Zeta[3] / 4 + 2 Symbol["l"] / 3); - nnloQCD = nnloQCD + Symbol["Nf"]^2 (127 / 108 - Zeta[2] / 6); - nnloQCD = nnloQCD SARAH`strongCoupling^4 / (16 Pi^4); - nnnloQCD = 467.683620788 + 122.440972222 Symbol["l"] + 10.9409722222 Symbol["l"]^2; - nnnloQCD = nnnloQCD SARAH`strongCoupling^6 / (64 Pi^6); - scalarFactor = scalarFactor <> "const double nlo_qcd = " <> CConversion`RValueToCFormString[nloQCD] <> ";\n"; - scalarFactor = scalarFactor <> "const double nnlo_qcd = " <> CConversion`RValueToCFormString[nnloQCD] <> ";\n"; - scalarFactor = scalarFactor <> "const double nnnlo_qcd = " <> CConversion`RValueToCFormString[nnnloQCD] <> ";\n"; - scalarFactor = Parameters`CreateLocalConstRefs[{nloQCD, nnloQCD, nnnloQCD}] <> "\n" <> scalarFactor; - (* NLO, NNLO and NNNLO contributions to pseudoscalar coupling *) - nloQCD = (97 / 4 - 7 / 6 Symbol["Nf"]) SARAH`strongCoupling^2 / (4 Pi^2); - nnloQCD = (237311 / 864 - 529 Zeta[2] / 24 - 445 Zeta[3] / 8 + 5 Symbol["l"]); - nnloQCD = nnloQCD SARAH`strongCoupling^4 / (16 Pi^4); - nnnloQCD = 0; - pseudoscalarFactor = pseudoscalarFactor <> "const double nlo_qcd = " - <> CConversion`RValueToCFormString[nloQCD] <> ";\n"; - pseudoscalarFactor = pseudoscalarFactor <> "const double nnlo_qcd = " - <> CConversion`RValueToCFormString[nnloQCD] <> ";\n"; - pseudoscalarFactor = pseudoscalarFactor <> "const double nnnlo_qcd = " - <> CConversion`RValueToCFormString[nnnloQCD] <> ";\n"; - pseudoscalarFactor = Parameters`CreateLocalConstRefs[{nloQCD, nnloQCD, nnnloQCD}] <> "\n" <> pseudoscalarFactor; - {scalarFactor, pseudoscalarFactor} - ]; - -GetAllowedCouplingsForModel[] := - Module[{dim, - valid = {FlexibleSUSYObservable`CpHiggsPhotonPhoton, - FlexibleSUSYObservable`CpHiggsGluonGluon, - FlexibleSUSYObservable`CpPseudoScalarPhotonPhoton, - FlexibleSUSYObservable`CpPseudoScalarGluonGluon} - }, - If[FreeQ[TreeMasses`GetParticles[], SARAH`HiggsBoson], - valid = DeleteCases[valid, a_ /; (a === FlexibleSUSYObservable`CpHiggsPhotonPhoton || - a === FlexibleSUSYObservable`CpHiggsGluonGluon)]; - ]; - If[FreeQ[TreeMasses`GetParticles[], SARAH`PseudoScalar], - valid = DeleteCases[valid, a_ /; (a === FlexibleSUSYObservable`CpPseudoScalarPhotonPhoton || - a === FlexibleSUSYObservable`CpPseudoScalarGluonGluon)]; - ]; - valid - ]; - -GetExternalStates[couplingSymbol_] := - Module[{particle, vectorBoson}, - Which[couplingSymbol === FlexibleSUSYObservable`CpHiggsPhotonPhoton, - particle = SARAH`HiggsBoson; - vectorBoson = SARAH`VectorP;, - couplingSymbol === FlexibleSUSYObservable`CpHiggsGluonGluon, - particle = SARAH`HiggsBoson; - vectorBoson = SARAH`VectorG;, - couplingSymbol === FlexibleSUSYObservable`CpPseudoScalarPhotonPhoton, - particle = SARAH`PseudoScalar; - vectorBoson = SARAH`VectorP;, - couplingSymbol === FlexibleSUSYObservable`CpPseudoScalarGluonGluon, - particle = SARAH`PseudoScalar; - vectorBoson = SARAH`VectorG;, - True, particle = Null; vectorBoson = Null - ]; - {particle, vectorBoson} - ]; - -CalculatePartialWidths[couplings_List] := - Module[{couplingSymbol, dim, particle, vectorBoson, particlesStr, - massStr, functionName, couplingName, - body, prototypes = {}, functions = {}}, - For[i = 1, i <= Length[couplings], i++, - couplingSymbol = couplings[[i,1]]; - {particle, vectorBoson} = GetExternalStates[couplingSymbol]; - particlesStr = CConversion`ToValidCSymbolString[particle] - <> CConversion`ToValidCSymbolString[vectorBoson] - <> CConversion`ToValidCSymbolString[vectorBoson]; - dim = TreeMasses`GetDimension[particle]; - functionName = "get_" <> particlesStr <> "_partial_width("; - If[dim == 1, - functionName = functionName <> ") const";, - functionName = functionName <> "int gO1) const"; - ]; - couplingName = "eff_Cp" <> particlesStr; - massStr = CConversion`ToValidCSymbolString[FlexibleSUSY`M[particle]]; - body = "const double mass = PHYSICAL(" <> massStr <> ")"; - If[dim != 1, - body = body <> "(gO1)"; - ]; - body = body <> ";\n"; - If[vectorBoson === SARAH`VectorP, - body = body <> "return " <> CConversion`RValueToCFormString[1 / (64 Pi)] - <> " * Power(mass, 3.0) * AbsSqr(" <> couplingName - <> If[dim != 1, "(gO1)", ""] <> ");";, - body = body <> "return " <> CConversion`RValueToCFormString[1 / (8 Pi)] - <> " * Power(mass, 3.0) * AbsSqr(" <> couplingName - <> If[dim != 1, "(gO1)", ""] <> ");"; - ]; - functions = Append[functions, - "double " <> FlexibleSUSY`FSModelName <> "_effective_couplings::" - <> functionName <> "\n{\n" <> TextFormatting`IndentText[body] - <> "\n}\n"]; - prototypes = Append[prototypes, - "double " <> functionName <> ";"]; - ]; - Utils`StringJoinWithSeparator[#, "\n"]& /@ {prototypes, functions} - ]; - -NonZeroVertexQ[vertex_] := MemberQ[vertex[[2 ;;]][[All, 1]], Except[0]]; - -(* @todo extend to multiple non-Abelian groups *) -IsColorOrLorentzIndex[index_] := Vertices`SarahColorIndexQ[index] || - Vertices`SarahLorentzIndexQ[index]; -StripColorAndLorentzIndices[p_Symbol] := p; -StripColorAndLorentzIndices[SARAH`bar[p_]] := SARAH`bar[StripColorAndLorentzIndices[p]]; -StripColorAndLorentzIndices[Susyno`LieGroups`conj[p_]] := Susyno`LieGroups`conj[StripColorAndLorentzIndices[p]]; -StripColorAndLorentzIndices[p_] := - Module[{remainingIndices}, - remainingIndices = Select[p[[1]], (!IsColorOrLorentzIndex[#])&]; - If[Length[remainingIndices] === 0, - Head[p], - Head[p][remainingIndices] - ] - ]; -SetAttributes[StripColorAndLorentzIndices, {Listable}]; - -(* @todo this is very slow because each possible vertex must be calculated, - this can be improved by either pre-calculating all vertices or saving - previous results (e.g. define along the lines of f[p] := f[p] = ...) *) -GetTwoBodyDecays[particle_] := - Module[{i, j, allParticles, combinations, vertex, fields, couplings, - candidate, found = {}, decays = {}}, - allParticles = Select[TreeMasses`GetParticles[], !TreeMasses`IsGhost[#]&]; - combinations = Table[Sort[{SARAH`AntiField[particle], - SARAH`AntiField[allParticles[[i]]], - allParticles[[j]]}], - {i, 1, Length[allParticles]}, {j, 1, Length[allParticles]}]; - combinations = DeleteDuplicates[Flatten[combinations, 1]]; - For[i = 1, i <= Length[combinations], i++, - vertex = SARAH`Vertex[combinations[[i]], UseDependences -> True]; - If[NonZeroVertexQ[vertex], - fields = First[vertex]; - coupling = Rest[vertex]; - If[Length[coupling] > 1, - coupling = Vertices`SortCp[SARAH`Cp @@ (StripColorAndLorentzIndices @ fields)][SARAH`PL];, - coupling = Vertices`SortCp[SARAH`Cp @@ (StripColorAndLorentzIndices @ fields)]; - ]; - candidate = Append[DeleteCases[fields /. head_[{__}] :> head, p_ /; p === SARAH`AntiField[particle], {0, Infinity}, 1], coupling]; - If[FreeQ[found, C[candidate[[1]], candidate[[2]]]] && - FreeQ[found, C[SARAH`AntiField[candidate[[1]]], SARAH`AntiField[candidate[[2]]]]] || - SARAH`AntiField[particle] =!= particle, - If[((!TreeMasses`IsMassless[candidate[[1]]] || !TreeMasses`IsVector[candidate[[1]]]) && - (!TreeMasses`IsMassless[candidate[[2]]] || !TreeMasses`IsVector[candidate[[2]]])) || - !FreeQ[SARAH`AllowDecaysMasslessVectors, SARAH`RE[particle]], - decays = Append[decays, candidate]; - found = Append[found, C[candidate[[1]], candidate[[2]]]]; - ]; - ]; - ]; - ]; - decays - ]; - -GetParticlesCouplingToVectorBoson[vector_] := - Module[{i, charge, allParticles, particles = {}}, - allParticles = Select[TreeMasses`GetParticles[], !TreeMasses`IsGhost[#]&]; - For[i = 1, i <= Length[allParticles], i++, - If[vector === SARAH`VectorG, - (* @note could use defined functions in e.g. TreeMasses, plus check - for undefined group factors, but will do it this way for now - to ensure consistency with SARAH *) - charge = SARAH`Vertex[{SARAH`AntiField[allParticles[[i]]], - allParticles[[i]], SARAH`VectorG}, - UseDependences -> True][[2,1]]; - If[charge =!= 0, - particles = Append[particles, allParticles[[i]]]; - ];, - charge = TreeMasses`GetElectricCharge[allParticles[[i]]]; - If[NumericQ[charge], - charge = {charge}, - charge = Cases[SARAH`Vertex[{SARAH`AntiField[allParticles[[i]]], - allParticles[[i]], SARAH`VectorP}, - UseDependences -> True][[2,1]], _?NumberQ]; - ]; - If[charge =!= {} && SARAH`AntiField[allParticles[[i]]] =!= allParticles[[i]] && - charge =!= {0}, - particles = Append[particles, allParticles[[i]]]; - ]; - ]; - ]; - particles - ]; - -IsMasslessOrGoldstone[SARAH`bar[p_]] := IsMasslessOrGoldstone[p]; -IsMasslessOrGoldstone[Susyno`LieGroups`conj[p_]] := IsMasslessOrGoldstone[p]; -IsMasslessOrGoldstone[particle_] := - Module[{result}, - result = TreeMasses`IsMassless[particle] || - (TreeMasses`IsGoldstone[particle] && TreeMasses`GetDimension[particle] == 1); - result - ]; - -InitializeEffectiveCouplings[] := - Module[{i, couplings, particle, vectorBoson, - allParticles = {}, allVectorBosons = {}, - twoBodyDecays, vectorBosonInteractions, - neededTwoBodyDecays, neededVectorBosonInteractions, - neededCoups, result = {}}, - couplings = GetAllowedCouplingsForModel[]; - {allParticles, allVectorBosons} = DeleteDuplicates /@ {(#[[1]])& /@ (GetExternalStates[#]& /@ couplings), - (#[[2]])& /@ (GetExternalStates[#]& /@ couplings)}; - twoBodyDecays = {#, GetTwoBodyDecays[#]}& /@ allParticles; - vectorBosonInteractions = {#, GetParticlesCouplingToVectorBoson[#]}& /@ allVectorBosons; - For[i = 1, i <= Length[couplings], i++, - {particle, vectorBoson} = GetExternalStates[couplings[[i]]]; - neededTwoBodyDecays = First[Select[twoBodyDecays, (#[[1]] === particle)&]]; - neededVectorBosonInteractions = First[Select[vectorBosonInteractions, (#[[1]] === vectorBoson)&]]; - neededCoups = Select[neededTwoBodyDecays[[2]], - (MemberQ[neededVectorBosonInteractions[[2]], #[[1]]] || - MemberQ[neededVectorBosonInteractions[[2]], #[[2]]])&]; - (* only keep vertices of the form pD -> p SARAH`AntiField[p] *) - neededCoups = Cases[neededCoups, {p1_, p2_, _} /; p1 === SARAH`AntiField[p2]]; - (* filter out massless states and Goldstones *) - neededCoups = Select[neededCoups, (!IsMasslessOrGoldstone[#[[1]]] && !IsMasslessOrGoldstone[#[[2]]])&]; - result = Append[result, {couplings[[i]], #[[3]]& /@ neededCoups}]; - ]; - result - ]; - -GetNeededVerticesList[couplings_List] := - {Null[Null, Join[(#[[2]])& /@ couplings]]}; - -CreateEffectiveCouplingName[pIn_, pOut_] := - "eff_Cp" <> CConversion`ToValidCSymbolString[pIn] <> CConversion`ToValidCSymbolString[pOut] <> CConversion`ToValidCSymbolString[pOut]; - -CreateEffectiveCouplingsGetters[couplings_List] := - Module[{i, couplingSymbols, type, particle, - vectorBoson, dim, couplingName, getters = ""}, - couplingSymbols = #[[1]]& /@ couplings; - type = CConversion`CreateCType[CConversion`ScalarType[CConversion`complexScalarCType]]; - For[i = 1, i <= Length[couplingSymbols], i++, - {particle, vectorBoson} = GetExternalStates[couplingSymbols[[i]]]; - dim = TreeMasses`GetDimension[particle]; - couplingName = CreateEffectiveCouplingName[particle, vectorBoson]; - getters = getters <> type <> " get_" <> couplingName; - If[dim == 1, - getters = getters <> "() const { return " <> couplingName <> "; }\n";, - getters = getters <> "(int gO1) const { return " <> couplingName <> "(gO1); }\n"; - ]; - ]; - getters - ]; - -CreateEffectiveCouplingsDefinitions[couplings_List] := - Module[{i, couplingSymbols, dim, type, particle, vectorBoson, - couplingName, defs = ""}, - couplingSymbols = #[[1]]& /@ couplings; - For[i = 1, i <= Length[couplingSymbols], i++, - {particle, vectorBoson} = GetExternalStates[couplingSymbols[[i]]]; - couplingName = CreateEffectiveCouplingName[particle, vectorBoson]; - dim = TreeMasses`GetDimension[particle]; - If[dim == 1, - type = CConversion`CreateCType[CConversion`ScalarType[CConversion`complexScalarCType]];, - type = CConversion`CreateCType[CConversion`ArrayType[CConversion`complexScalarCType, dim]]; - ]; - defs = defs <> type <> " " <> couplingName <> ";\n"; - ]; - defs - ]; - -CreateEffectiveCouplingsInit[couplings_List] := - Module[{i, couplingSymbols, particle, - vectorBoson, couplingName, dim, type, init = ""}, - couplingSymbols = #[[1]]& /@ couplings; - For[i = 1, i <= Length[couplingSymbols], i++, - {particle, vectorBoson} = GetExternalStates[couplingSymbols[[i]]]; - couplingName = CreateEffectiveCouplingName[particle, vectorBoson]; - dim = TreeMasses`GetDimension[particle]; - If[dim == 1, - type = CConversion`ScalarType[CConversion`complexScalarCType];, - type = CConversion`ArrayType[CConversion`complexScalarCType, dim]; - ]; - init = init <> ", " <> CConversion`CreateDefaultConstructor[couplingName, type]; - ]; - init - ]; - -RunToDecayingParticleScale[scale_] := - Module[{body, result = ""}, - If[SARAH`SupersymmetricModel, - body = "model.run_to(" <> scale <> ");\n"; - result = "if (rg_improve && scale > " <> scale <> ") {\n" - <> TextFormatting`IndentText[body] <> "}\n"; - ]; - result - ]; - -RunStrongCouplingToScale[scale_] := - Module[{result = ""}, - If[ValueQ[SARAH`hyperchargeCoupling] && ValueQ[SARAH`leftCoupling] && - ValueQ[SARAH`strongCoupling], - result = result <> "run_SM_strong_coupling_to(sm, " <> scale <> ");\n"; - ]; - result - ]; - -CallEffectiveCouplingCalculation[couplingSymbol_] := - Module[{particle, vectorBoson, savedMass, dim, start, idx = "", - body, couplingName, call = ""}, - {particle, vectorBoson} = GetExternalStates[couplingSymbol]; - savedMass = CConversion`RValueToCFormString[FlexibleSUSY`M[particle]]; - dim = TreeMasses`GetDimension[particle]; - start = TreeMasses`GetDimensionStartSkippingGoldstones[particle]; - If[dim != 1 && start <= dim, - idx = "gO1"; - savedMass = savedMass <> "(" <> idx <> ")"; - ]; - If[vectorBoson === SARAH`VectorP, - body = RunStrongCouplingToScale["0.5 * " <> savedMass];, - body = RunStrongCouplingToScale[savedMass]; - ]; - call = call <> body; - couplingName = CreateEffectiveCouplingName[particle, vectorBoson]; - call = call <> "calculate_" <> couplingName; - If[idx != "", - call = call <> "(" <> idx <> ");";, - call = call <> "();"; - ]; - call - ]; - -CreateEffectiveCouplingsCalculation[couplings_List] := - Module[{i, couplingSymbols, particle, couplingsForParticles = {}, - pos, couplingList, mass, - savedMass, dim, start, body, result = ""}, - couplingSymbols = #[[1]]& /@ couplings; - For[i = 1, i <= Length[couplingSymbols], i++, - particle = GetExternalStates[couplingSymbols[[i]]][[1]]; - If[FreeQ[couplingsForParticles, particle], - couplingsForParticles = Append[couplingsForParticles, {particle, {couplingSymbols[[i]]}}];, - pos = Position[couplingsForParticles, {particle, _List}][[1,1]]; - couplingList = couplingsForParticles[[pos]] /. {p_, coups_} :> {p, Append[coups, couplingSymbols[[i]]]}; - couplingsForParticles = ReplacePart[couplingsForParticles, pos -> couplingList]; - ]; - ]; - For[i = 1, i <= Length[couplingsForParticles], i++, - particle = couplingsForParticles[[i,1]]; - mass = CConversion`ToValidCSymbolString[FlexibleSUSY`M[particle]]; - savedMass = "const auto " <> mass <> " = PHYSICAL(" <> mass <> ");\n"; - dim = TreeMasses`GetDimension[particle]; - start = TreeMasses`GetDimensionStartSkippingGoldstones[particle]; - If[dim == 1 && !TreeMasses`IsGoldstone[particle], - body = RunToDecayingParticleScale[mass]; - If[SARAH`SupersymmetricModel, - body = body <> "model.calculate_DRbar_masses();\n" - <> "copy_mixing_matrices_from_model();\n"; - ]; - result = result <> savedMass <> body <> Utils`StringJoinWithSeparator[CallEffectiveCouplingCalculation[#]& /@ couplingsForParticles[[i,2]], "\n"] <> "\n\n"; - , - If[start <= dim, - body = RunToDecayingParticleScale[mass <> "(gO1)"]; - If[SARAH`SupersymmetricModel, - body = body <> "model.calculate_DRbar_masses();\n" - <> "copy_mixing_matrices_from_model();\n"; - ]; - result = result <> savedMass - <> "for (int gO1 = " <> ToString[start-1] <> "; gO1 < " <> ToString[dim] <> "; ++gO1) {\n"; - body = body <> Utils`StringJoinWithSeparator[CallEffectiveCouplingCalculation[#]& /@ couplingsForParticles[[i,2]], "\n"] <> "\n"; - result = result <> TextFormatting`IndentText[body] <> "}\n\n"; - ]; - ]; - ]; - - result = "const double scale = model.get_scale();\nconst Eigen::ArrayXd saved_parameters(model.get());\n\n" - <> "const double saved_mt = PHYSICAL(" - <> CConversion`RValueToCFormString[TreeMasses`GetThirdGenerationMass[TreeMasses`GetSMTopQuarkMultiplet[]]] - <> ");\nPHYSICAL(" - <> CConversion`RValueToCFormString[TreeMasses`GetThirdGenerationMass[TreeMasses`GetSMTopQuarkMultiplet[]]] - <> ") = qedqcd.displayPoleMt();\n\n" - <> result; - result = result <> "PHYSICAL(" - <> CConversion`RValueToCFormString[TreeMasses`GetThirdGenerationMass[TreeMasses`GetSMTopQuarkMultiplet[]]] - <> ") = saved_mt;\n"; - result = result <> "model.set_scale(scale);\nmodel.set(saved_parameters);\n"; - - result - ]; - -CreateEffectiveCouplingPrototype[coupling_] := - Module[{couplingSymbol = coupling[[1]], particle, vectorBoson, - dim, name, result = ""}, - {particle, vectorBoson} = GetExternalStates[couplingSymbol]; - If[particle =!= Null && vectorBoson =!= Null, - dim = TreeMasses`GetDimension[particle]; - name = CreateEffectiveCouplingName[particle, vectorBoson]; - result = "void calculate_" <> name <> If[dim == 1, "();\n", "(int gO1);\n"]; - ]; - result - ]; - -GetEffectiveVEV[] := - Module[{vev, parameters = {}, result = ""}, - If[SARAH`SupersymmetricModel, - vev = Simplify[2 Sqrt[-SARAH`Vertex[{SARAH`VectorW, Susyno`LieGroups`conj[SARAH`VectorW]}][[2,1]] - / SARAH`leftCoupling^2] /. SARAH`sum[a_,b_,c_,d_] :> Sum[d,{a,b,c}]]; - vev = Parameters`DecreaseIndexLiterals[vev]; - parameters = Parameters`FindAllParameters[vev]; - result = "const auto vev = " <> CConversion`RValueToCFormString[vev] <> ";\n";, - result = "const auto vev = 1.0 / Sqrt(qedqcd.displayFermiConstant() * Sqrt(2.0));\n"; - ]; - {result, parameters} - ]; - -GetMultiplicity[vectorBoson_, internal_] := SARAH`ChargeFactor[vectorBoson, internal, internal]; - -GetParticleGenerationIndex[particle_, coupling_] := - Module[{dim, indexList, result = {}}, - dim = TreeMasses`GetDimension[particle]; - If[dim != 1, - indexList = Flatten[Cases[Vertices`GetParticleList[coupling], - p_[a_List] /; p === particle :> a, {0, Infinity}]]; - result = Select[indexList, StringMatchQ[ToString[#], "gt" ~~ __] &]; - If[Length[result] > 1, - result = {result[[1]]}; - ]; - ]; - result - ]; - -(* @todo these are basically identical to those in SelfEnergies, - it would be better to reuse the definitions there if possible *) -GetParticleIndicesInCoupling[SARAH`Cp[a__]] := Flatten[Cases[{a}, List[__], Infinity]]; - -GetParticleIndicesInCoupling[SARAH`Cp[a__][_]] := GetParticleIndicesInCoupling[SARAH`Cp[a]]; - -CreateCouplingSymbol[coupling_] := - Module[{symbol, indices}, - indices = GetParticleIndicesInCoupling[coupling]; - symbol = ToValidCSymbol[coupling /. a_[List[__]] :> a]; - symbol[Sequence @@ indices] - ]; - -CreateLocalConstRefsIgnoringMixings[expr_, mixings_List] := - Module[{symbols, poleMasses}, - symbols = Parameters`FindAllParameters[expr]; - poleMasses = { - Cases[expr, FlexibleSUSY`Pole[FlexibleSUSY`M[a_]] /; MemberQ[Parameters`GetOutputParameters[],FlexibleSUSY`M[a]] :> FlexibleSUSY`M[a], {0,Infinity}], - Cases[expr, FlexibleSUSY`Pole[FlexibleSUSY`M[a_[__]]] /; MemberQ[Parameters`GetOutputParameters[],FlexibleSUSY`M[a]] :> FlexibleSUSY`M[a], {0,Infinity}] - }; - symbols = DeleteDuplicates[Flatten[symbols]]; - symbols = Complement[symbols, mixings]; - Parameters`CreateLocalConstRefs[symbols] - ]; - -CreateNeededCouplingFunction[coupling_, expr_, mixings_List] := - Module[{symbol, prototype = "", definition = "", - indices = {}, localExpr, body = "", functionName = "", i, - type, typeStr}, - indices = GetParticleIndicesInCoupling[coupling]; - symbol = CreateCouplingSymbol[coupling]; - functionName = CConversion`ToValidCSymbolString[CConversion`GetHead[symbol]]; - functionName = functionName <> "("; - For[i = 1, i <= Length[indices], i++, - If[i > 1, functionName = functionName <> ", ";]; - functionName = functionName <> "int "; - If[!IntegerQ[indices[[i]]] && !FreeQ[expr, indices[[i]]], - functionName = functionName <> CConversion`ToValidCSymbolString[indices[[i]]]; - ]; - ]; - functionName = functionName <> ")"; - If[Parameters`IsRealExpression[expr], - type = CConversion`ScalarType[CConversion`realScalarCType];, - type = CConversion`ScalarType[CConversion`complexScalarCType];]; - typeStr = CConversion`CreateCType[type]; - prototype = typeStr <> " " <> functionName <> " const;\n"; - definition = typeStr <> " " <> FlexibleSUSY`FSModelName - <> "_effective_couplings::" <> functionName <> " const\n{\n"; - localExpr = expr /. (Rule[#[],#]& /@ Parameters`GetDependenceSPhenoSymbols[]); - localExpr = localExpr /. Parameters`GetDependenceSPhenoRules[]; - body = CreateLocalConstRefsIgnoringMixings[localExpr, mixings] <> "\n" <> - "const " <> typeStr <> " result = " <> - Parameters`ExpressionToString[localExpr] <> ";\n\n" <> - "return result;\n"; - body = TextFormatting`IndentText[TextFormatting`WrapLines[body]]; - definition = definition <> body <> "}\n"; - {prototype, definition} - ]; - -CreateNeededVertexExpressions[vertexRules_List, mixings_List] := - Module[{k, prototypes = "", defs = "", coupling, expr, - p, d}, - For[k = 1, k <= Length[vertexRules], k++, - coupling = Vertices`ToCp[vertexRules[[k,1]]]; - expr = vertexRules[[k,2]]; - {p, d} = CreateNeededCouplingFunction[coupling, expr, mixings]; - prototypes = prototypes <> p; - defs = defs <> d <> "\n"; - ]; - {prototypes, defs} - ]; - -HasColorCharge[particle_] := - Module[{dynkin}, - dynkin = SA`Dynkin[particle,Position[SARAH`Gauge, SARAH`strongCoupling][[1,1]]]; - If[!NumericQ[dynkin], dynkin = 0]; - dynkin == 1/2 - ]; - -CreateCouplingContribution[particle_, vectorBoson_, coupling_] := - Module[{i, internal, particleIndex, indices, dim, start, factor, qcdfactor, - mass, massStr, couplingSymbol, couplingName, - scaleFunction, body = "", result = "", parameters = {}}, - internal = DeleteCases[Vertices`GetParticleList[coupling] /. field_[{__}] :> field, - p_ /; p === particle, 1]; - internal = First[internal /. {SARAH`bar[p_] :> p, Susyno`LieGroups`conj[p_] :> p}]; - dim = TreeMasses`GetDimension[internal]; - mass = FlexibleSUSY`M[internal]; - massStr = CConversion`ToValidCSymbolString[mass]; - If[dim != 1, - massStr = massStr <> "(gI1)"; - ]; - parameters = Append[parameters, mass]; - Which[TreeMasses`IsScalar[internal], - factor = 1/2; - If[particle === SARAH`HiggsBoson, - scaleFunction = "AS0"; - If[vectorBoson === SARAH`VectorP && HasColorCharge[internal], - qcdfactor = "scalar_scalar_qcd_factor(decay_mass, " <> massStr <> ")";, - qcdfactor = ""; - ];, - Return[{"",{}}]; - ];, - TreeMasses`IsVector[internal], - factor = -1/2; - If[particle === SARAH`HiggsBoson, - scaleFunction = "AS1"; - qcdfactor = "";, - Return[{"",{}}]; - ];, - TreeMasses`IsFermion[internal], - factor = 1; - If[particle === SARAH`HiggsBoson, - scaleFunction = "AS12"; - If[vectorBoson === SARAH`VectorP && HasColorCharge[internal], - qcdfactor = "scalar_fermion_qcd_factor(decay_mass, " <> massStr <> ")";, - qcdfactor = ""; - ];, - scaleFunction = "AP12"; - If[vectorBoson === SARAH`VectorP && HasColorCharge[internal], - qcdfactor = "pseudoscalar_fermion_qcd_factor(decay_mass, " <> massStr <> ")";, - qcdfactor = ""; - ]; - ]; - ]; - If[vectorBoson === SARAH`VectorP, - factor = factor * TreeMasses`GetElectricCharge[internal]^2 GetMultiplicity[vectorBoson, internal]; - ]; - indices = GetParticleIndicesInCoupling[coupling]; - particleIndex = GetParticleGenerationIndex[particle, coupling]; - indices = Replace[indices, p_ /; !MemberQ[particleIndex, p] -> SARAH`gI1, 1]; - indices = Replace[indices, p_ /; MemberQ[particleIndex, p] -> SARAH`gO1, 1]; - couplingSymbol = CConversion`ToValidCSymbol[coupling /. a_[List[__]] :> a]; - couplingSymbol = couplingSymbol[Sequence @@ indices]; - couplingName = CConversion`ToValidCSymbolString[CConversion`GetHead[couplingSymbol]]; - couplingName = couplingName <> "("; - For[i = 1, i <= Length[indices], i++, - If[i > 1, couplingName = couplingName <> ", ";]; - If[!IntegerQ[indices[[i]]], - couplingName = couplingName <> CConversion`ToValidCSymbolString[indices[[i]]]; - ]; - ]; - couplingName = couplingName <> ")"; - body = "result += " <> If[factor != 1, CConversion`RValueToCFormString[factor] <> " * ", ""] - <> If[qcdfactor != "", qcdfactor <> " * ", ""] <> couplingName - <> " * vev * " <> scaleFunction <> "(decay_scale / Sqr(" <> massStr <> ")) / " - <> If[IsFermion[internal], massStr, "Sqr(" <> massStr <> ")"] <> ";"; - If[dim == 1, - result = body <> "\n";, - start = TreeMasses`GetDimensionStartSkippingGoldstones[internal]; - result = "for (int gI1 = " <> ToString[start - 1] <> "; gI1 < " <> ToString[dim] <> "; ++gI1) {\n"; - result = result <> TextFormatting`IndentText[body] <> "\n}\n"; - ]; - {result, parameters} - ]; - -CreateEffectiveCouplingFunction[coupling_] := - Module[{i, couplingSymbol = coupling[[1]], neededCouplings = coupling[[2]], - particle, vectorBoson, dim, type, name, savedMass, mass, mixingSymbol, - mixingName, parameters = {}, poleMasses, currentLine, body = "", result = ""}, - {particle, vectorBoson} = GetExternalStates[couplingSymbol]; - If[particle =!= Null && vectorBoson =!= Null, - name = CreateEffectiveCouplingName[particle, vectorBoson]; - dim = TreeMasses`GetDimension[particle]; - result = result <> "void " <> FlexibleSUSY`FSModelName - <> "_effective_couplings::calculate_" <> name <> "("; - If[dim == 1, - result = result <> ")\n{\n";, - result = result <> "int gO1)\n{\n"; - ]; - - mass = CConversion`ToValidCSymbolString[FlexibleSUSY`M[particle]]; - savedMass = "const auto decay_mass = PHYSICAL(" <> mass <> ")"; - If[dim == 1, - savedMass = savedMass <> ";\n";, - savedMass = savedMass <> "(gO1);\n"; - ]; - body = body <> savedMass; - body = body <> "const auto decay_scale = 0.25 * Sqr(decay_mass);\n"; - (* use physical mixing matrices for decaying particle *) - mixingSymbol = TreeMasses`FindMixingMatrixSymbolFor[particle]; - If[mixingSymbol =!= Null, - mixingName = CConversion`ToValidCSymbolString[mixingSymbol]; - body = body <> "const auto saved_" <> mixingName <> " = " <> mixingName <> ";\n"; - body = body <> mixingName <> " = PHYSICAL(" <> mixingName <> ");\n\n";, - body = body <> "\n"; - ]; - {currentLine, parameters} = {#[[1]], Join[parameters, #[[2]]]}& @ (GetEffectiveVEV[]); - body = body <> currentLine <> "\n"; - body = body <> CConversion`CreateDefaultDefinition["result", CConversion`ScalarType[CConversion`complexScalarCType]] <> ";\n"; - - For[i = 1, i <= Length[neededCouplings], i++, - {currentLine, parameters} = {#[[1]], Join[parameters, #[[2]]]}& @ (CreateCouplingContribution[particle, vectorBoson, neededCouplings[[i]]]); - body = body <> currentLine; - ]; - - Which[particle === SARAH`HiggsBoson && vectorBoson === SARAH`VectorG, - body = body <> "result *= 0.75;\n\n"; - body = body <> "if (include_qcd_corrections) {\n" - <> TextFormatting`IndentText["result *= scalar_scaling_factor(decay_mass);"] <> "\n}\n";, - particle === SARAH`PseudoScalar && vectorBoson === SARAH`VectorP, - body = body <> "result *= 2.0;\n";, - particle === SARAH`PseudoScalar && vectorBoson === SARAH`VectorG, - body = body <> "result *= 1.5;\n\n"; - body = body <> "if (include_qcd_corrections) {\n" - <> TextFormatting`IndentText["result *= pseudoscalar_scaling_factor(decay_mass);"] <> "\n}\n"; - ]; - - If[vectorBoson === SARAH`VectorG, - parameters = Append[parameters, SARAH`strongCoupling]; - body = "const double alpha_s = " <> CConversion`RValueToCFormString[SARAH`strongCoupling^2 / (4 Pi)] - <> ";\n" <> body; - ]; - - (* use pole masses in loop functions *) - If[SARAH`SupersymmetricModel, - body = Parameters`CreateLocalConstRefs[DeleteDuplicates[parameters]] <> body <> "\n";, - poleMasses = DeleteDuplicates[Select[parameters, Parameters`IsOutputParameter]]; - body = Parameters`CreateLocalConstRefsForPhysicalParameters[poleMasses] <> body <> "\n"; - body = Parameters`CreateLocalConstRefs[DeleteDuplicates[Complement[parameters, poleMasses]]] <> body <> "\n"; - ]; - - If[vectorBoson === SARAH`VectorP, - body = body <> "result *= " - <> CConversion`RValueToCFormString[1 / (2^(3/4) Pi)] - <> " * physical_input.get(Physical_input::alpha_em_0) * Sqrt(qedqcd.displayFermiConstant());\n\n";, - body = body <> "result *= " - <> CConversion`RValueToCFormString[2^(1/4) / (3 Pi)] - <> " * alpha_s * Sqrt(qedqcd.displayFermiConstant());\n\n"; - ]; - - (* restore saved mixing *) - If[mixingSymbol =!= Null, - body = body <> mixingName <> " = saved_" <> mixingName <> ";\n"; - ]; - body = body <> name <> If[dim != 1, "(gO1) = ", " = "] <> "result;\n"; - - result = result <> TextFormatting`IndentText[TextFormatting`WrapLines[body]] <> "\n}\n"; - ]; - result - ]; - -CreateEffectiveCouplingsPrototypes[couplings_List] := - Module[{result = ""}, - (result = result <> CreateEffectiveCouplingPrototype[#])& /@ couplings; - result - ]; - -CreateEffectiveCouplingsFunctions[couplings_List] := - Module[{result = ""}, - (result = result <> CreateEffectiveCouplingFunction[#] <> "\n")& /@ couplings; - result - ]; - -CreateEffectiveCouplings[couplings_List, massMatrices_List, vertexRules_List] := - Module[{mixings, relevantVertexRules, verticesPrototypes, - verticesFunctions,prototypes = "", functions = ""}, - mixings = Cases[Flatten[TreeMasses`GetMixingMatrixSymbol[#]& /@ massMatrices], Except[Null]]; - relevantVertexRules = Cases[vertexRules, r:(Rule[a_,b_] /; !FreeQ[couplings,a]) :> r]; - {verticesPrototypes, verticesFunctions} = - CreateNeededVertexExpressions[relevantVertexRules, mixings]; - prototypes = prototypes <> verticesPrototypes - <> CreateEffectiveCouplingsPrototypes[couplings]; - functions = functions <> verticesFunctions - <> CreateEffectiveCouplingsFunctions[couplings]; - {prototypes, functions} - ]; - -End[]; - -EndPackage[]; diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index aa23f302f6..f9217e41fe 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -56,7 +56,6 @@ "BrLToLGamma`", "FToFConversionInNucleus`", "BtoSGamma`", - "EffectiveCouplings`", "FlexibleEFTHiggsMatching`", "FSMathLink`", "FlexibleTower`", @@ -213,16 +212,6 @@ FlexibleSUSY model file (FlexibleSUSY.m). { {1, FlexibleSUSYObservable`aMuon} } - }, - { - EFFHIGGSCOUPLINGS, - NoScale, - { - {1, FlexibleSUSYObservable`CpHiggsPhotonPhoton}, - {2, FlexibleSUSYObservable`CpHiggsGluonGluon}, - {3, FlexibleSUSYObservable`CpPseudoScalarPhotonPhoton}, - {4, FlexibleSUSYObservable`CpPseudoScalarGluonGluon} - } } }; FSAuxiliaryParameterInfo = {}; @@ -651,6 +640,12 @@ FlexibleSUSY model file (FlexibleSUSY.m). If[Head[FlexibleSUSY`ExtraSLHAOutputBlocks] =!= List, FlexibleSUSY`ExtraSLHAOutputBlocks = {}; ]; + If[MemberQ[FlexibleSUSY`ExtraSLHAOutputBlocks, {FlexibleSUSY`EFFHIGGSCOUPLINGS, __}], + Print["Warning: Effective coupling module has been disabled since v2.6.0."]; + Print[" Please use FlexibleDecay instead."]; + FlexibleSUSY`ExtraSLHAOutputBlocks = + DeleteCases[FlexibleSUSY`ExtraSLHAOutputBlocks, {FlexibleSUSY`EFFHIGGSCOUPLINGS, __}]; + ]; If[Head[FlexibleSUSY`EWSBOutputParameters] =!= List, Print["Error: EWSBOutputParameters has to be set to a list", " of model parameters chosen to be output of the EWSB eqs."]; @@ -2164,58 +2159,6 @@ corresponding tadpole is real or imaginary (only in models with CP } ]; ]; -WriteEffectiveCouplings[couplings_List, settings_List, massMatrices_List, vertexRules_List, files_List] := - Module[{i, partialWidthGetterPrototypes, partialWidthGetters, - loopCouplingsGetters, loopCouplingsDefs, mixingMatricesDefs = "", - loopCouplingsInit, mixingMatricesInit = "", copyMixingMatrices = "", - setSMStrongCoupling = "", - calculateScalarScalarLoopQCDFactor, calculateScalarFermionLoopQCDFactor, - calculatePseudocalarFermionLoopQCDFactor, - calculateScalarQCDScalingFactor, calculatePseudoscalarQCDScalingFactor, - calculateLoopCouplings, loopCouplingsPrototypes, - loopCouplingsFunctions}, - {partialWidthGetterPrototypes, partialWidthGetters} = EffectiveCouplings`CalculatePartialWidths[couplings]; - If[ValueQ[SARAH`strongCoupling], - setSMStrongCoupling = "model.set_" <> CConversion`ToValidCSymbolString[SARAH`strongCoupling] <> "(sm.get_g3());\n"; - ]; - loopCouplingsGetters = EffectiveCouplings`CreateEffectiveCouplingsGetters[couplings]; - For[i = 1, i <= Length[massMatrices], i++, - mixingMatricesDefs = mixingMatricesDefs <> TreeMasses`CreateMixingMatrixDefinition[massMatrices[[i]]]; - mixingMatricesInit = mixingMatricesInit <> EffectiveCouplings`InitializeMixingFromModelInput[massMatrices[[i]]]; - copyMixingMatrices = copyMixingMatrices <> EffectiveCouplings`GetMixingMatrixFromModel[massMatrices[[i]]]; - ]; - loopCouplingsDefs = EffectiveCouplings`CreateEffectiveCouplingsDefinitions[couplings]; - loopCouplingsInit = EffectiveCouplings`CreateEffectiveCouplingsInit[couplings]; - {calculateScalarScalarLoopQCDFactor, calculateScalarFermionLoopQCDFactor, - calculatePseudoscalarFermionLoopQCDFactor} = - EffectiveCouplings`CalculateQCDAmplitudeScalingFactors[]; - {calculateScalarQCDScalingFactor, calculatePseudoscalarQCDScalingFactor} = - EffectiveCouplings`CalculateQCDScalingFactor[]; - calculateLoopCouplings = EffectiveCouplings`CreateEffectiveCouplingsCalculation[couplings]; - {loopCouplingsPrototypes, loopCouplingsFunctions} = - EffectiveCouplings`CreateEffectiveCouplings[couplings, massMatrices, vertexRules]; - WriteOut`ReplaceInFiles[files, - { "@partialWidthGetterPrototypes@" -> IndentText[partialWidthGetterPrototypes], - "@partialWidthGetters@" -> partialWidthGetters, - "@loopCouplingsGetters@" -> IndentText[loopCouplingsGetters], - "@loopCouplingsPrototypes@" -> IndentText[loopCouplingsPrototypes], - "@mixingMatricesDefs@" -> IndentText[mixingMatricesDefs], - "@loopCouplingsDefs@" -> IndentText[loopCouplingsDefs], - "@mixingMatricesInit@" -> IndentText[WrapLines[mixingMatricesInit]], - "@loopCouplingsInit@" -> IndentText[WrapLines[loopCouplingsInit]], - "@copyMixingMatrices@" -> IndentText[copyMixingMatrices], - "@setSMStrongCoupling@" -> IndentText[setSMStrongCoupling], - "@calculateScalarScalarLoopQCDFactor@" -> IndentText[WrapLines[calculateScalarScalarLoopQCDFactor]], - "@calculateScalarFermionLoopQCDFactor@" -> IndentText[WrapLines[calculateScalarFermionLoopQCDFactor]], - "@calculatePseudoscalarFermionLoopQCDFactor@" -> IndentText[WrapLines[calculatePseudoscalarFermionLoopQCDFactor]], - "@calculateScalarQCDScalingFactor@" -> IndentText[WrapLines[calculateScalarQCDScalingFactor]], - "@calculatePseudoscalarQCDScalingFactor@" -> IndentText[WrapLines[calculatePseudoscalarQCDScalingFactor]], - "@calculateLoopCouplings@" -> IndentText[calculateLoopCouplings], - "@loopCouplingsFunctions@" -> loopCouplingsFunctions, - Sequence @@ GeneralReplacementRules[] - } ]; - ]; - (* Write the observables files *) WriteObservables[extraSLHAOutputBlocks_, files_List] := Module[{requestedObservables, numberOfObservables, observablesDef, @@ -3104,15 +3047,10 @@ corresponding tadpole is real or imaginary (only in models with CP FileNameJoin[{outputDir, ToString[eigenstates], "Vertices", "FSVertexRules.m"}]; -GetEffectiveCouplingsFileName[outputDir_String, eigenstates_] := - FileNameJoin[{outputDir, ToString[eigenstates], "Vertices", - "FSEffectiveCouplings.m"}]; - NeedToCalculateVertices[eigenstates_] := NeedToUpdateTarget[ "vertex", - { GetVertexRuleFileName[$sarahCurrentOutputMainDir, eigenstates], - GetEffectiveCouplingsFileName[$sarahCurrentOutputMainDir, eigenstates] }]; + { GetVertexRuleFileName[$sarahCurrentOutputMainDir, eigenstates] }]; NeedToUpdateTarget[name_String, targets_List] := Module[{ targetsExist = FilesExist[targets], @@ -4064,9 +4002,9 @@ corresponding tadpole is real or imaginary (only in models with CP treeLevelEwsbSolutionOutputFiles = {}, treeLevelEwsbEqsOutputFile, solverEwsbSolvers = {}, fixedParameters, lesHouchesInputParameters, - extraSLHAOutputBlocks, effectiveCouplings = {}, extraVertices = {}, + extraSLHAOutputBlocks, deltaVBwave, deltaVBvertex, deltaVBbox, - vertexRules, vertexRuleFileName, effectiveCouplingsFileName, + vertexRules, vertexRuleFileName, Lat$massMatrices, spectrumGeneratorFiles = {}, spectrumGeneratorInputFile, semiAnalyticBCs, semiAnalyticSolns, semiAnalyticHighScaleFiles, semiAnalyticSUSYScaleFiles, semiAnalyticLowScaleFiles, @@ -4424,22 +4362,14 @@ corresponding tadpole is real or imaginary (only in models with CP vertexRuleFileName = GetVertexRuleFileName[$sarahCurrentOutputMainDir, FSEigenstates]; - effectiveCouplingsFileName = - GetEffectiveCouplingsFileName[$sarahCurrentOutputMainDir, FSEigenstates]; If[NeedToCalculateVertices[FSEigenstates], - (* effectiveCouplings = {{coupling, {needed couplings}}, ...} *) - Put[effectiveCouplings = - SortCps @ EffectiveCouplings`InitializeEffectiveCouplings[], - effectiveCouplingsFileName]; - extraVertices = EffectiveCouplings`GetNeededVerticesList[effectiveCouplings]; Put[vertexRules = Vertices`VertexRules[Join[nPointFunctions, - extraVertices, deltaVBwave, - deltaVBvertex, deltaVBbox], Lat$massMatrices], - vertexRuleFileName], + deltaVBwave, deltaVBvertex, deltaVBbox], + Lat$massMatrices], + vertexRuleFileName], vertexRules = Get[vertexRuleFileName]; - effectiveCouplings = Get[effectiveCouplingsFileName]; - ]; + ]; (* apply user-defined rules *) vertexRules = vertexRules /. FlexibleSUSY`FSVertexRules; @@ -4890,16 +4820,6 @@ corresponding tadpole is real or imaginary (only in models with CP ]; (* If[FSCalculateDecays] *) Utils`PrintHeadline["Creating other observables"]; - Print["Creating class for effective couplings ..."]; - (* @note separating this out for now for simplicity *) - (* @todo maybe implement a flag (like for addons) to turn on/off? *) - WriteEffectiveCouplings[effectiveCouplings, FlexibleSUSY`LowScaleInput, massMatrices, vertexRules, - {{FileNameJoin[{$flexiblesusyTemplateDir, "effective_couplings.hpp.in"}], - FileNameJoin[{FSOutputDir, FlexibleSUSY`FSModelName <> "_effective_couplings.hpp"}]}, - {FileNameJoin[{$flexiblesusyTemplateDir, "effective_couplings.cpp.in"}], - FileNameJoin[{FSOutputDir, FlexibleSUSY`FSModelName <> "_effective_couplings.cpp"}]} - }]; - Print["Creating class for observables ..."]; WriteObservables[extraSLHAOutputBlocks, {{FileNameJoin[{$flexiblesusyTemplateDir, "observables.hpp.in"}], diff --git a/meta/Observables.m b/meta/Observables.m index cc8a0b2777..10ed8351bf 100644 --- a/meta/Observables.m +++ b/meta/Observables.m @@ -25,8 +25,6 @@ (* observables *) Begin["FlexibleSUSYObservable`"]; FSObservables = { aMuon, aMuonUncertainty, aMuonGM2Calc, aMuonGM2CalcUncertainty, - CpHiggsPhotonPhoton, CpHiggsGluonGluon, - CpPseudoScalarPhotonPhoton, CpPseudoScalarGluonGluon, EDM, BrLToLGamma, bsgamma }; If[FlexibleSUSY`FSFeynArtsAvailable && FlexibleSUSY`FSFormCalcAvailable, @@ -56,30 +54,7 @@ GetRequestedObservables[blocks_] := Module[{observables, dim, test}, observables = DeleteDuplicates[Cases[blocks, a_?IsObservable :> a, {0, Infinity}]]; - If[MemberQ[observables, FlexibleSUSYObservable`CpHiggsPhotonPhoton] || - MemberQ[observables, FlexibleSUSYObservable`CpHiggsGluonGluon], - dim = TreeMasses`GetDimensionWithoutGoldstones[SARAH`HiggsBoson] - If[FreeQ[TreeMasses`GetParticles[], SARAH`HiggsBoson] || - TreeMasses`GetDimensionWithoutGoldstones[SARAH`HiggsBoson] == 0, - Print["Warning: no physical Higgs boson found."]; - Print[" Effective couplings for Higgs boson will not"]; - Print[" be calculated."]; - observables = DeleteCases[observables, a_ /; (a === FlexibleSUSYObservable`CpHiggsPhotonPhoton || - a === FlexibleSUSYObservable`CpHiggsGluonGluon)]; - ]; - ]; - If[MemberQ[observables, FlexibleSUSYObservable`CpPseudoScalarPhotonPhoton] || - MemberQ[observables, FlexibleSUSYObservable`CpPseudoScalarGluonGluon], - If[FreeQ[TreeMasses`GetParticles[], SARAH`PseudoScalar] || - TreeMasses`GetDimensionWithoutGoldstones[SARAH`PseudoScalar] == 0, - Print["Warning: no physical pseudoscalar boson found."]; - Print[" Effective couplings for pseudoscalar boson will not"]; - Print[" be calculated."]; - observables = DeleteCases[observables, a_ /; (a === FlexibleSUSYObservable`CpPseudoScalarPhotonPhoton || - a === FlexibleSUSYObservable`CpPseudoScalarGluonGluon)]; - ]; - ]; -test = Complement[ + test = Complement[ Cases[observables, _FlexibleSUSYObservable`BrLToLGamma], Cases[observables, FlexibleSUSYObservable`BrLToLGamma[fin_?IsLepton -> {fout_?IsLepton, vout_ /; vout === GetPhoton[]}]] ]; @@ -96,10 +71,6 @@ GetObservableName[obs_ /; obs === FlexibleSUSYObservable`aMuonUncertainty] := "a_muon_uncertainty"; GetObservableName[obs_ /; obs === FlexibleSUSYObservable`aMuonGM2Calc] := "a_muon_gm2calc"; GetObservableName[obs_ /; obs === FlexibleSUSYObservable`aMuonGM2CalcUncertainty] := "a_muon_gm2calc_uncertainty"; -GetObservableName[obs_ /; obs === FlexibleSUSYObservable`CpHiggsPhotonPhoton] := "eff_cp_higgs_photon_photon"; -GetObservableName[obs_ /; obs === FlexibleSUSYObservable`CpHiggsGluonGluon] := "eff_cp_higgs_gluon_gluon"; -GetObservableName[obs_ /; obs === FlexibleSUSYObservable`CpPseudoScalarPhotonPhoton] := "eff_cp_pseudoscalar_photon_photon"; -GetObservableName[obs_ /; obs === FlexibleSUSYObservable`CpPseudoScalarGluonGluon] := "eff_cp_pseudoscalar_gluon_gluon"; GetObservableName[FlexibleSUSYObservable`EDM[p_[idx_]]] := GetObservableName[FlexibleSUSYObservable`EDM[p]] <> "_" <> ToString[idx]; GetObservableName[FlexibleSUSYObservable`EDM[p_]] := "edm_" <> CConversion`ToValidCSymbolString[p]; GetObservableName[FlexibleSUSYObservable`BrLToLGamma[pIn_[_] -> {pOut_[_], spectator_}]] := CConversion`ToValidCSymbolString[pIn] <> "_to_" <> CConversion`ToValidCSymbolString[pOut] <> "_" <> CConversion`ToValidCSymbolString[spectator]; @@ -111,10 +82,6 @@ GetObservableDescription[obs_ /; obs === FlexibleSUSYObservable`aMuonUncertainty] := "uncertainty of a_muon = (g-2)/2 of the muon (calculated with FlexibleSUSY)"; GetObservableDescription[obs_ /; obs === FlexibleSUSYObservable`aMuonGM2Calc] := "a_muon = (g-2)/2 of the muon (calculated with GM2Calc)"; GetObservableDescription[obs_ /; obs === FlexibleSUSYObservable`aMuonGM2CalcUncertainty] := "uncertainty of (g-2)/2 of the muon (calculated with GM2Calc)"; -GetObservableDescription[obs_ /; obs === FlexibleSUSYObservable`CpHiggsPhotonPhoton] := "effective H-Photon-Photon coupling"; -GetObservableDescription[obs_ /; obs === FlexibleSUSYObservable`CpHiggsGluonGluon] := "effective H-Gluon-Gluon coupling"; -GetObservableDescription[obs_ /; obs === FlexibleSUSYObservable`CpPseudoScalarPhotonPhoton] := "effective A-Photon-Photon coupling"; -GetObservableDescription[obs_ /; obs === FlexibleSUSYObservable`CpPseudoScalarGluonGluon] := "effective A-Gluon-Gluon coupling"; GetObservableDescription[FlexibleSUSYObservable`EDM[p_[idx_]]] := "electric dipole moment of " <> CConversion`ToValidCSymbolString[p] <> "(" <> ToString[idx] <> ") [1/GeV]"; GetObservableDescription[FlexibleSUSYObservable`EDM[p_]] := "electric dipole moment of " <> CConversion`ToValidCSymbolString[p] <> " [1/GeV]"; GetObservableDescription[FlexibleSUSYObservable`BrLToLGamma[pIn_ -> {pOut_, _}]] := @@ -144,46 +111,6 @@ GetObservableType[FlexibleSUSYObservable`FToFConversionInNucleus[pIn_[idxIn_] -> pOut_[idxOut_], _]] := CConversion`ScalarType[CConversion`realScalarCType]; GetObservableType[obs_ /; obs === FlexibleSUSYObservable`bsgamma] := CConversion`ScalarType[CConversion`realScalarCType]; -GetObservableType[obs_ /; obs === FlexibleSUSYObservable`CpHiggsPhotonPhoton] := - Module[{dim, type}, - dim = TreeMasses`GetDimensionWithoutGoldstones[SARAH`HiggsBoson]; - If[dim == 1, - type = CConversion`ScalarType[CConversion`complexScalarCType], - type = CConversion`ArrayType[CConversion`complexScalarCType, dim] - ]; - type - ]; - -GetObservableType[obs_ /; obs === FlexibleSUSYObservable`CpHiggsGluonGluon] := - Module[{dim, type}, - dim = TreeMasses`GetDimensionWithoutGoldstones[SARAH`HiggsBoson]; - If[dim == 1, - type = CConversion`ScalarType[CConversion`complexScalarCType], - type = CConversion`ArrayType[CConversion`complexScalarCType, dim] - ]; - type - ]; - -GetObservableType[obs_ /; obs === FlexibleSUSYObservable`CpPseudoScalarPhotonPhoton] := - Module[{dim, type}, - dim = TreeMasses`GetDimensionWithoutGoldstones[SARAH`PseudoScalar]; - If[dim == 1, - type = CConversion`ScalarType[CConversion`complexScalarCType], - type = CConversion`ArrayType[CConversion`complexScalarCType, dim] - ]; - type - ]; - -GetObservableType[obs_ /; obs === FlexibleSUSYObservable`CpPseudoScalarGluonGluon] := - Module[{dim, type}, - dim = TreeMasses`GetDimensionWithoutGoldstones[SARAH`PseudoScalar]; - If[dim == 1, - type = CConversion`ScalarType[CConversion`complexScalarCType], - type = CConversion`ArrayType[CConversion`complexScalarCType, dim] - ]; - type - ]; - CountNumberOfObservables[observables_List] := Module[{i, number = 0}, For[i = 1, i <= Length[observables], i++, @@ -288,130 +215,6 @@ structName <> ".AMUGM2CALCUNCERTAINTY = gm2calc_calculate_amu_uncertainty(gm2calc_data);\n" <> "#endif"; -CalculateObservable[obs_ /; obs === FlexibleSUSYObservable`CpHiggsPhotonPhoton, structName_String] := - Module[{i, type, dim, start, result = ""}, - type = GetObservableType[obs]; - dim = TreeMasses`GetDimensionWithoutGoldstones[SARAH`HiggsBoson]; - If[dim != 1, - start = TreeMasses`GetDimensionStartSkippingGoldstones[SARAH`HiggsBoson] - 1; - For[i = 1, i <= dim, i++, - result = result <> structName <> ".EFFCPHIGGSPHOTONPHOTON(" - <> ToString[i-1] <> ") = effective_couplings.get_eff_Cp" - <> CConversion`ToValidCSymbolString[SARAH`HiggsBoson] - <> CConversion`ToValidCSymbolString[SARAH`VectorP] - <> CConversion`ToValidCSymbolString[SARAH`VectorP] <> "(" - <> ToString[start+i-1] <> If[i != dim, ");\n", ");"]; - ];, - dim = TreeMasses`GetDimension[SARAH`HiggsBoson]; - If[dim == 1, - result = structName <> ".EFFCPHIGGSPHOTONPHOTON = effective_couplings.get_eff_Cp" - <> CConversion`ToValidCSymbolString[SARAH`HiggsBoson] - <> CConversion`ToValidCSymbolString[SARAH`VectorP] - <> CConversion`ToValidCSymbolString[SARAH`VectorP] <> "();", - start = TreeMasses`GetDimensionStartSkippingGoldstones[SARAH`HiggsBoson] - 1; - result = structName <> ".EFFCPHIGGSPHOTONPHOTON = effective_couplings.get_eff_Cp" - <> CConversion`ToValidCSymbolString[SARAH`HiggsBoson] - <> CConversion`ToValidCSymbolString[SARAH`VectorP] - <> CConversion`ToValidCSymbolString[SARAH`VectorP] <> "(" - <> ToString[start] <> ");" - ]; - ]; - result - ]; - -CalculateObservable[obs_ /; obs === FlexibleSUSYObservable`CpHiggsGluonGluon, structName_String] := - Module[{i, type, dim, start, result = ""}, - type = GetObservableType[obs]; - dim = TreeMasses`GetDimensionWithoutGoldstones[SARAH`HiggsBoson]; - If[dim != 1, - start = TreeMasses`GetDimensionStartSkippingGoldstones[SARAH`HiggsBoson] - 1; - For[i = 1, i <= dim, i++, - result = result <> structName <> ".EFFCPHIGGSGLUONGLUON(" - <> ToString[i-1] <> ") = effective_couplings.get_eff_Cp" - <> CConversion`ToValidCSymbolString[SARAH`HiggsBoson] - <> CConversion`ToValidCSymbolString[SARAH`VectorG] - <> CConversion`ToValidCSymbolString[SARAH`VectorG] <> "(" - <> ToString[start+i-1] <> If[i != dim, ");\n", ");"]; - ];, - dim = TreeMasses`GetDimension[SARAH`HiggsBoson]; - If[dim == 1, - result = structName <> ".EFFCPHIGGSGLUONGLUON = effective_couplings.get_eff_Cp" - <> CConversion`ToValidCSymbolString[SARAH`HiggsBoson] - <> CConversion`ToValidCSymbolString[SARAH`VectorG] - <> CConversion`ToValidCSymbolString[SARAH`VectorG] <> "();", - start = TreeMasses`GetDimensionStartSkippingGoldstones[SARAH`HiggsBoson] - 1; - result = structName <> ".EFFCPHIGGSGLUONGLUON = effective_couplings.get_eff_Cp" - <> CConversion`ToValidCSymbolString[SARAH`HiggsBoson] - <> CConversion`ToValidCSymbolString[SARAH`VectorG] - <> CConversion`ToValidCSymbolString[SARAH`VectorG] <> "(" - <> ToString[start] <> ");" - ]; - ]; - result - ]; - -CalculateObservable[obs_ /; obs === FlexibleSUSYObservable`CpPseudoScalarPhotonPhoton, structName_String] := - Module[{i, type, dim, start, result = ""}, - type = GetObservableType[obs]; - dim = TreeMasses`GetDimensionWithoutGoldstones[SARAH`PseudoScalar]; - If[dim != 1, - start = TreeMasses`GetDimensionStartSkippingGoldstones[SARAH`PseudoScalar] - 1; - For[i = 1, i <= dim, i++, - result = result <> structName <> ".EFFCPPSEUDOSCALARPHOTONPHOTON(" - <> ToString[i-1] <> ") = effective_couplings.get_eff_Cp" - <> CConversion`ToValidCSymbolString[SARAH`PseudoScalar] - <> CConversion`ToValidCSymbolString[SARAH`VectorP] - <> CConversion`ToValidCSymbolString[SARAH`VectorP] <> "(" - <> ToString[start+i-1] <> If[i != dim, ");\n", ");"]; - ];, - dim = TreeMasses`GetDimension[SARAH`PseudoScalar]; - If[dim == 1, - result = structName <> ".EFFCPPSEUDOSCALARPHOTONPHOTON = effective_couplings.get_eff_Cp" - <> CConversion`ToValidCSymbolString[SARAH`PseudoScalar] - <> CConversion`ToValidCSymbolString[SARAH`VectorP] - <> CConversion`ToValidCSymbolString[SARAH`VectorP] <> "();", - start = TreeMasses`GetDimensionStartSkippingGoldstones[SARAH`PseudoScalar] - 1; - result = structName <> ".EFFCPPSEUDOSCALARPHOTONPHOTON = effective_couplings.get_eff_Cp" - <> CConversion`ToValidCSymbolString[SARAH`PseudoScalar] - <> CConversion`ToValidCSymbolString[SARAH`VectorP] - <> CConversion`ToValidCSymbolString[SARAH`VectorP] <> "(" - <> ToString[start] <> ");" - ]; - ]; - result - ]; - -CalculateObservable[obs_ /; obs === FlexibleSUSYObservable`CpPseudoScalarGluonGluon, structName_String] := - Module[{i, type, dim, start, result = ""}, - type = GetObservableType[obs]; - dim = TreeMasses`GetDimensionWithoutGoldstones[SARAH`PseudoScalar]; - If[dim != 1, - start = TreeMasses`GetDimensionStartSkippingGoldstones[SARAH`PseudoScalar] - 1; - For[i = 1, i <= dim, i++, - result = result <> structName <> ".EFFCPPSEUDOSCALARGLUONGLUON(" - <> ToString[i-1] <> ") = effective_couplings.get_eff_Cp" - <> CConversion`ToValidCSymbolString[SARAH`PseudoScalar] - <> CConversion`ToValidCSymbolString[SARAH`VectorG] - <> CConversion`ToValidCSymbolString[SARAH`VectorG] <> "(" - <> ToString[start+i-1] <> If[i != dim, ");\n", ");"]; - ];, - dim = TreeMasses`GetDimension[SARAH`PseudoScalar]; - If[dim == 1, - result = structName <> ".EFFCPPSEUDOSCALARGLUONGLUON = effective_couplings.get_eff_Cp" - <> CConversion`ToValidCSymbolString[SARAH`PseudoScalar] - <> CConversion`ToValidCSymbolString[SARAH`VectorG] - <> CConversion`ToValidCSymbolString[SARAH`VectorG] <> "();", - start = TreeMasses`GetDimensionStartSkippingGoldstones[SARAH`PseudoScalar] - 1; - result = structName <> ".EFFCPPSEUDOSCALARGLUONGLUON = effective_couplings.get_eff_Cp" - <> CConversion`ToValidCSymbolString[SARAH`PseudoScalar] - <> CConversion`ToValidCSymbolString[SARAH`VectorG] - <> CConversion`ToValidCSymbolString[SARAH`VectorG] <> "(" - <> ToString[start] <> ");" - ]; - ]; - result - ]; - CalculateObservable[FlexibleSUSYObservable`EDM[p_], structName_String] := Module[{pStr = CConversion`ToValidCSymbolString[p]}, structName <> ".EDM0(" <> pStr <> ") = " <> @@ -544,12 +347,6 @@ "#endif\n\n" ]; -FillEffectiveCouplingsInterfaceData[struct_String] := - Module[{result}, - result = FlexibleSUSY`FSModelName <> "_effective_couplings " <> struct <> "(model, qedqcd, physical_input);\n"; - result = result <> "effective_couplings.calculate_effective_couplings();\n" - ]; - FillInterfaceData[{}] := ""; FillInterfaceData[obs_List] := @@ -558,12 +355,6 @@ MemberQ[obs,FlexibleSUSYObservable`aMuonGM2CalcUncertainty], filled = filled <> FillGM2CalcInterfaceData["gm2calc_data"]; ]; - If[MemberQ[obs,FlexibleSUSYObservable`CpHiggsPhotonPhoton] || - MemberQ[obs,FlexibleSUSYObservable`CpHiggsGluonGluon] || - MemberQ[obs, FlexibleSUSYObservable`CpPseudoScalarPhotonPhoton] || - MemberQ[obs, FlexibleSUSYObservable`CpPseudoScalarGluonGluon], - filled = filled <> FillEffectiveCouplingsInterfaceData["effective_couplings"]; - ]; filled ]; diff --git a/meta/WriteOut.m b/meta/WriteOut.m index 5bef2aa9f2..36832df0a1 100644 --- a/meta/WriteOut.m +++ b/meta/WriteOut.m @@ -448,57 +448,6 @@ ClearAttributes[WriteSLHABlockEntry, HoldFirst]; -WriteEffectiveCouplingsSLHABlockEntry[blockName_, particle_, vectorBoson_] := - Module[{i, dim, dimWithoutGoldstones, start, particlePDG, vectorPDG, - struct, comment, value, result = ""}, - vectorPDG = Parameters`GetPDGCodesForParticle[vectorBoson][[1]]; - particlePDG = Parameters`GetPDGCodesForParticle[particle]; - dim = TreeMasses`GetDimension[particle]; - dimWithoutGoldstones = TreeMasses`GetDimensionWithoutGoldstones[particle]; - If[Length[particlePDG] != dim, - Print["Warning: length of PDG number list != dimension of particle ", particle]; - Print[" PDG number list = ", particlePDG]; - Print[" dimension of particle ", particle, " = ", dim]; - ]; - If[Length[particlePDG] < dim, - Return[""]; - ]; - start = TreeMasses`GetDimensionStartSkippingGoldstones[particle]; - Which[particle === SARAH`HiggsBoson && vectorBoson === SARAH`VectorP, - struct = "OBSERVABLES.eff_cp_higgs_photon_photon"; - comment = "Abs(effective H-Photon-Photon coupling)";, - particle === SARAH`HiggsBoson && vectorBoson === SARAH`VectorG, - struct = "OBSERVABLES.eff_cp_higgs_gluon_gluon"; - comment = "Abs(effective H-Gluon-Gluon coupling)";, - particle === SARAH`PseudoScalar && vectorBoson === SARAH`VectorP, - struct = "OBSERVABLES.eff_cp_pseudoscalar_photon_photon"; - comment = "Abs(effective A-Photon-Photon coupling)";, - particle === SARAH`PseudoScalar && vectorBoson === SARAH`VectorG, - struct = "OBSERVABLES.eff_cp_pseudoscalar_gluon_gluon"; - comment = "Abs(effective A-Gluon-Gluon coupling)";, - True, - Print["Error: unsupported effective coupling ", - particle, "-", vectorBoson, "-", vectorBoson, - "requested!"]; - Quit[1] - ]; - If[dimWithoutGoldstones == 1 || start == dim, - value = "Abs(" <> struct <> ")"; - result = result - <> WriteSLHABlockEntry[blockName, - {value, particlePDG[[start]], vectorPDG, vectorPDG}, - comment];, - For[i = start, i <= Length[particlePDG], i++, - value = "Abs(" <> struct <> "(" <> ToString[i-start] <> "))"; - result = result - <> WriteSLHABlockEntry[blockName, - {value, particlePDG[[i]], vectorPDG, vectorPDG}, - comment]; - ]; - ]; - result - ]; - WriteSLHABlockEntry[blockName_, {par_?Observables`IsObservable, idx___}, comment_String:""] := Module[{result = ""}, Switch[par, @@ -510,14 +459,6 @@ result = WriteSLHABlockEntry[blockName, {"OBSERVABLES.a_muon_gm2calc", idx}, "Delta(g-2)_muon/2 GM2Calc"], FlexibleSUSYObservable`aMuonGM2CalcUncertainty, result = WriteSLHABlockEntry[blockName, {"OBSERVABLES.a_muon_gm2calc_uncertainty", idx}, "Delta(g-2)_muon/2 GM2Calc uncertainty"], - FlexibleSUSYObservable`CpHiggsPhotonPhoton, - result = WriteEffectiveCouplingsSLHABlockEntry[blockName, SARAH`HiggsBoson, SARAH`VectorP], - FlexibleSUSYObservable`CpHiggsGluonGluon, - result = WriteEffectiveCouplingsSLHABlockEntry[blockName, SARAH`HiggsBoson, SARAH`VectorG], - FlexibleSUSYObservable`CpPseudoScalarPhotonPhoton, - result = WriteEffectiveCouplingsSLHABlockEntry[blockName, SARAH`PseudoScalar, SARAH`VectorP], - FlexibleSUSYObservable`CpPseudoScalarGluonGluon, - result = WriteEffectiveCouplingsSLHABlockEntry[blockName, SARAH`PseudoScalar, SARAH`VectorG], FlexibleSUSYObservable`EDM[_], result = WriteSLHABlockEntry[blockName, {"OBSERVABLES." <> Observables`GetObservableName[par], idx}, diff --git a/meta/module.mk b/meta/module.mk index 0778c3bc57..ca6abfca05 100644 --- a/meta/module.mk +++ b/meta/module.mk @@ -78,7 +78,6 @@ META_SRC := \ $(DIR)/FToFConversionInNucleus.m \ $(DIR)/BrLToLGamma.m \ $(DIR)/BtoSGamma.m \ - $(DIR)/EffectiveCouplings.m \ $(DIR)/EWSB.m \ $(DIR)/FlexibleEFTHiggsMatching.m \ $(DIR)/FlexibleSUSY.m \ diff --git a/model_specific/SM/module.mk b/model_specific/SM/module.mk index 6279567196..bc9ce74b5d 100644 --- a/model_specific/SM/module.mk +++ b/model_specific/SM/module.mk @@ -11,7 +11,6 @@ LIB_model_specific_SM_SRC := \ $(DIR)/sm_threeloophiggs.cpp \ $(DIR)/sm_twoloophiggs.cpp \ $(DIR)/standard_model.cpp \ - $(DIR)/standard_model_effective_couplings.cpp \ $(DIR)/standard_model_physical.cpp \ $(DIR)/standard_model_two_scale_convergence_tester.cpp \ $(DIR)/standard_model_two_scale_low_scale_constraint.cpp \ @@ -25,7 +24,6 @@ LIB_model_specific_SM_HDR := \ $(DIR)/sm_twoloophiggs.hpp \ $(DIR)/standard_model.hpp \ $(DIR)/standard_model_convergence_tester.hpp \ - $(DIR)/standard_model_effective_couplings.hpp \ $(DIR)/standard_model_low_scale_constraint.hpp \ $(DIR)/standard_model_physical.hpp \ $(DIR)/standard_model_two_scale_convergence_tester.hpp \ diff --git a/model_specific/SM/standard_model_effective_couplings.cpp b/model_specific/SM/standard_model_effective_couplings.cpp deleted file mode 100644 index 17c47a7311..0000000000 --- a/model_specific/SM/standard_model_effective_couplings.cpp +++ /dev/null @@ -1,513 +0,0 @@ -// ==================================================================== -// This file is part of FlexibleSUSY. -// -// FlexibleSUSY 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. -// -// FlexibleSUSY 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 FlexibleSUSY. If not, see -// . -// ==================================================================== - -#include "standard_model_effective_couplings.hpp" - -#include "effective_couplings.hpp" -#include "standard_model.hpp" -#include "wrappers.hpp" - -namespace flexiblesusy { -namespace standard_model { - -using namespace effective_couplings; - -#define INPUTPARAMETER(parameter) model.get_input().parameter -#define MODELPARAMETER(parameter) model.get_##parameter() -#define DERIVEDPARAMETER(parameter) model.##parameter() -#define PHASE(parameter) model.get_##parameter() -#define PHYSICAL(parameter) model.get_physical().parameter - -Standard_model_effective_couplings::Standard_model_effective_couplings( - const Standard_model& model_, - const softsusy::QedQcd& qedqcd_, - const Physical_input& input_) - : model(model_), qedqcd(qedqcd_), physical_input(input_) - , rg_improve(true), include_qcd_corrections(true) - , Vd(PHYSICAL(Vd)), Ud(PHYSICAL(Ud)), Vu(PHYSICAL(Vu)), Uu(PHYSICAL(Uu)), Ve - (PHYSICAL(Ve)), Ue(PHYSICAL(Ue)), ZZ(PHYSICAL(ZZ)) - - , eff_CphhVPVP(0), eff_CphhVGVG(0), eff_CpAhVPVP(0), eff_CpAhVGVG(0) - -{ -} - -void Standard_model_effective_couplings::calculate_effective_couplings() -{ - const standard_model::Standard_model sm(initialise_SM()); - const double scale = model.get_scale(); - const Eigen::ArrayXd saved_parameters(model.get()); - - const double saved_mt = PHYSICAL(MFu(2)); - PHYSICAL(MFu(2)) = qedqcd.displayPoleMt(); - - const auto Mhh = PHYSICAL(Mhh); - run_SM_strong_coupling_to(sm, 0.5 * Mhh); - calculate_eff_CphhVPVP(); - run_SM_strong_coupling_to(sm, Mhh); - calculate_eff_CphhVGVG(); - - PHYSICAL(MFu(2)) = saved_mt; - model.set_scale(scale); - model.set(saved_parameters); - -} - -void Standard_model_effective_couplings::set_model(const Standard_model& model_) -{ - model = model_; - copy_mixing_matrices_from_model(); -} - -void Standard_model_effective_couplings::copy_mixing_matrices_from_model() -{ - Vd = PHYSICAL(Vd); - Ud = PHYSICAL(Ud); - Vu = PHYSICAL(Vu); - Uu = PHYSICAL(Uu); - Ve = PHYSICAL(Ve); - Ue = PHYSICAL(Ue); - ZZ = PHYSICAL(ZZ); - -} - -standard_model::Standard_model Standard_model_effective_couplings::initialise_SM() const -{ - standard_model::Standard_model sm; - - sm.set_loops(2); - sm.set_thresholds(2); - sm.set_physical_input(physical_input); - - sm.initialise_from_input(qedqcd); - - return sm; -} - -void Standard_model_effective_couplings::run_SM_strong_coupling_to(standard_model::Standard_model sm, double m) -{ - sm.run_to(m); - model.set_g3(sm.get_g3()); -} - -std::complex Standard_model_effective_couplings::scalar_scalar_qcd_factor(double m_decay, double m_loop) const -{ - std::complex result(1.0, 0.0); - - if (include_qcd_corrections) { - const auto g3 = MODELPARAMETER(g3); - if (m_loop > m_decay) { - result = 1 + 0.06754745576155852*Sqr(g3); - } - - } - - return result; -} - -std::complex Standard_model_effective_couplings::scalar_fermion_qcd_factor(double m_decay, double m_loop) const -{ - std::complex result(1.0, 0.0); - - if (include_qcd_corrections) { - const auto g3 = MODELPARAMETER(g3); - result = 1.0 + 0.025330295910584444*Sqr(g3) * - scalar_diphoton_fermion_loop(m_decay, m_loop); - - } - - return result; -} - -std::complex Standard_model_effective_couplings::pseudoscalar_fermion_qcd_factor(double m_decay, double m_loop) const -{ - std::complex result(1.0, 0.0); - - if (include_qcd_corrections) { - const auto g3 = MODELPARAMETER(g3); - result = 1.0 + 0.025330295910584444*Sqr(g3) * - pseudoscalar_diphoton_fermion_loop(m_decay, m_loop); - - } - - return result; -} - -double Standard_model_effective_couplings::number_of_active_flavours(double m) const -{ - if (m < qedqcd.displayMbMb()) { - return 4.0; - } else if (m < qedqcd.displayPoleMt()) { - return 5.0; - } else { - return 6.0; - } -} - -double Standard_model_effective_couplings::scalar_scaling_factor(double m) const -{ - const double Nf = number_of_active_flavours(m); - const double mtpole = qedqcd.displayPoleMt(); - const double l = Log(Sqr(m) / Sqr(mtpole)); - - const auto g3 = MODELPARAMETER(g3); - - const double nlo_qcd = 0.025330295910584444*(23.75 - 1.1666666666666667*Nf)* - Sqr(g3); - const double nnlo_qcd = 0.000641623890917771*Power(g3,4)*(370.1956513893174 - + 2.375*l + (-47.18640261449638 + 0.6666666666666666*l)*Nf + - 0.9017702481178881*Sqr(Nf)); - const double nnnlo_qcd = 0.000016252523020247696*Power(g3,6)*(467.683620788 - + 122.440972222*l + 10.9409722222*Sqr(l)); - - return Sqrt(1.0 + nlo_qcd + nnlo_qcd + nnnlo_qcd); -} - -double Standard_model_effective_couplings::pseudoscalar_scaling_factor(double m) const -{ - const double Nf = number_of_active_flavours(m); - const double mtpole = qedqcd.displayPoleMt(); - const double l = Log(Sqr(m) / Sqr(mtpole)); - - const auto g3 = MODELPARAMETER(g3); - - const double nlo_qcd = 0.025330295910584444*(24.25 - 1.1666666666666667*Nf)* - Sqr(g3); - const double nnlo_qcd = 0.000641623890917771*Power(g3,4)*(171.54400563089382 - + 5*l); - const double nnnlo_qcd = 0; - - return Sqrt(1.0 + nlo_qcd + nnlo_qcd + nnnlo_qcd); -} - -double Standard_model_effective_couplings::get_hhVPVP_partial_width() const -{ - const double mass = PHYSICAL(Mhh); - return 0.0049735919716217296 * Power(mass, 3.0) * AbsSqr(eff_CphhVPVP); -} - -double Standard_model_effective_couplings::get_hhVGVG_partial_width() const -{ - const double mass = PHYSICAL(Mhh); - return 0.039788735772973836 * Power(mass, 3.0) * AbsSqr(eff_CphhVGVG); -} - -double Standard_model_effective_couplings::get_AhVPVP_partial_width() const -{ - const double mass = PHYSICAL(MAh); - return 0.0049735919716217296 * Power(mass, 3.0) * AbsSqr(eff_CpAhVPVP); -} - -double Standard_model_effective_couplings::get_AhVGVG_partial_width() const -{ - const double mass = PHYSICAL(MAh); - return 0.039788735772973836 * Power(mass, 3.0) * AbsSqr(eff_CpAhVGVG); -} - -std::complex Standard_model_effective_couplings::CpFdhhbarFdPL(int gt1, int gt3) const -{ - const auto Yd = MODELPARAMETER(Yd); - - std::complex result; - - std::complex tmp_467; - std::complex tmp_468; - for (int j2 = 0; j2 < 3; ++j2) { - std::complex tmp_469; - std::complex tmp_470; - for (int j1 = 0; j1 < 3; ++j1) { - tmp_470 += Conj(Ud(gt3,j1))*Yd(j1,j2); - } - tmp_469 += tmp_470; - tmp_468 += (Conj(Vd(gt1,j2))) * tmp_469; - } - tmp_467 += tmp_468; - result += (-0.7071067811865475) * tmp_467; - - return result; -} - -std::complex Standard_model_effective_couplings::CpFuhhbarFuPL(int gt1, int gt3) const -{ - const auto Yu = MODELPARAMETER(Yu); - - std::complex result; - - std::complex tmp_471; - std::complex tmp_472; - for (int j2 = 0; j2 < 3; ++j2) { - std::complex tmp_473; - std::complex tmp_474; - for (int j1 = 0; j1 < 3; ++j1) { - tmp_474 += Conj(Uu(gt3,j1))*Yu(j1,j2); - } - tmp_473 += tmp_474; - tmp_472 += (Conj(Vu(gt1,j2))) * tmp_473; - } - tmp_471 += tmp_472; - result += (0.7071067811865475) * tmp_471; - - return result; -} - -std::complex Standard_model_effective_couplings::CpFehhbarFePL(int gt1, int gt3) const -{ - const auto Ye = MODELPARAMETER(Ye); - - std::complex result; - - std::complex tmp_475; - std::complex tmp_476; - for (int j2 = 0; j2 < 3; ++j2) { - std::complex tmp_477; - std::complex tmp_478; - for (int j1 = 0; j1 < 3; ++j1) { - tmp_478 += Conj(Ue(gt3,j1))*Ye(j1,j2); - } - tmp_477 += tmp_478; - tmp_476 += (Conj(Ve(gt1,j2))) * tmp_477; - } - tmp_475 += tmp_476; - result += (-0.7071067811865475) * tmp_475; - - return result; -} - -double Standard_model_effective_couplings::CphhVWpconjVWp() const -{ - const auto g2 = MODELPARAMETER(g2); - const auto v = MODELPARAMETER(v); - - double result = 0.0; - - result = 0.5*v*Sqr(g2); - - return result; -} - -std::complex Standard_model_effective_couplings::CpAhFdbarFdPL(int gt2, int gt3) const -{ - const auto Yd = MODELPARAMETER(Yd); - - std::complex result; - - std::complex tmp_479; - std::complex tmp_480; - for (int j2 = 0; j2 < 3; ++j2) { - std::complex tmp_481; - std::complex tmp_482; - for (int j1 = 0; j1 < 3; ++j1) { - tmp_482 += Conj(Ud(gt3,j1))*Yd(j1,j2); - } - tmp_481 += tmp_482; - tmp_480 += (Conj(Vd(gt2,j2))) * tmp_481; - } - tmp_479 += tmp_480; - result += (std::complex(0.,0.7071067811865475)) * tmp_479; - - return result; -} - -std::complex Standard_model_effective_couplings::CpAhFubarFuPL(int gt2, int gt3) const -{ - const auto Yu = MODELPARAMETER(Yu); - - std::complex result; - - std::complex tmp_483; - std::complex tmp_484; - for (int j2 = 0; j2 < 3; ++j2) { - std::complex tmp_485; - std::complex tmp_486; - for (int j1 = 0; j1 < 3; ++j1) { - tmp_486 += Conj(Uu(gt3,j1))*Yu(j1,j2); - } - tmp_485 += tmp_486; - tmp_484 += (Conj(Vu(gt2,j2))) * tmp_485; - } - tmp_483 += tmp_484; - result += (std::complex(0.,0.7071067811865475)) * tmp_483; - - return result; -} - -std::complex Standard_model_effective_couplings::CpAhFebarFePL(int gt2, int gt3) const -{ - const auto Ye = MODELPARAMETER(Ye); - - std::complex result; - - std::complex tmp_487; - std::complex tmp_488; - for (int j2 = 0; j2 < 3; ++j2) { - std::complex tmp_489; - std::complex tmp_490; - for (int j1 = 0; j1 < 3; ++j1) { - tmp_490 += Conj(Ue(gt3,j1))*Ye(j1,j2); - } - tmp_489 += tmp_490; - tmp_488 += (Conj(Ve(gt2,j2))) * tmp_489; - } - tmp_487 += tmp_488; - result += (std::complex(0.,0.7071067811865475)) * tmp_487; - - return result; -} - -void Standard_model_effective_couplings::calculate_eff_CphhVPVP() -{ - const auto MFd = PHYSICAL(MFd); - const auto MFu = PHYSICAL(MFu); - const auto MFe = PHYSICAL(MFe); - const auto MVWp = PHYSICAL(MVWp); - const auto decay_mass = PHYSICAL(Mhh); - const auto decay_scale = 0.25 * Sqr(decay_mass); - - const auto vev = 1.0 / Sqrt(qedqcd.displayFermiConstant() * Sqrt(2.0)); - - std::complex result = 0; - for (int gI1 = 0; gI1 < 3; ++gI1) { - result += 0.3333333333333333 * scalar_fermion_qcd_factor(decay_mass, - MFd(gI1)) * CpFdhhbarFdPL(gI1, gI1) * vev * AS12(decay_scale / Sqr(MFd( - gI1))) / MFd(gI1); - } - for (int gI1 = 0; gI1 < 3; ++gI1) { - result += 1.3333333333333333 * scalar_fermion_qcd_factor(decay_mass, - MFu(gI1)) * CpFuhhbarFuPL(gI1, gI1) * vev * AS12(decay_scale / Sqr(MFu( - gI1))) / MFu(gI1); - } - for (int gI1 = 0; gI1 < 3; ++gI1) { - result += CpFehhbarFePL(gI1, gI1) * vev * AS12(decay_scale / Sqr(MFe( - gI1))) / MFe(gI1); - } - result += -0.5 * CphhVWpconjVWp() * vev * AS1(decay_scale / Sqr(MVWp)) / Sqr - (MVWp); - - - result *= 0.18926819071273507 * physical_input.get( - Physical_input::alpha_em_0) * Sqrt(qedqcd.displayFermiConstant()); - - eff_CphhVPVP = result; - -} - -void Standard_model_effective_couplings::calculate_eff_CphhVGVG() -{ - const auto g3 = MODELPARAMETER(g3); - const auto MFd = PHYSICAL(MFd); - const auto MFu = PHYSICAL(MFu); - const double alpha_s = 0.07957747154594767*Sqr(g3); - const auto decay_mass = PHYSICAL(Mhh); - const auto decay_scale = 0.25 * Sqr(decay_mass); - - const auto vev = 1.0 / Sqrt(qedqcd.displayFermiConstant() * Sqrt(2.0)); - - std::complex result = 0; - for (int gI1 = 0; gI1 < 3; ++gI1) { - result += CpFdhhbarFdPL(gI1, gI1) * vev * AS12(decay_scale / Sqr(MFd( - gI1))) / MFd(gI1); - } - for (int gI1 = 0; gI1 < 3; ++gI1) { - result += CpFuhhbarFuPL(gI1, gI1) * vev * AS12(decay_scale / Sqr(MFu( - gI1))) / MFu(gI1); - } - result *= std::complex(0.75,0.); - - if (include_qcd_corrections) { - result *= scalar_scaling_factor(decay_mass); - } - - - result *= 0.12617879380849006 * alpha_s * Sqrt(qedqcd.displayFermiConstant() - ); - - eff_CphhVGVG = result; - -} - -void Standard_model_effective_couplings::calculate_eff_CpAhVPVP() -{ - const auto MFd = PHYSICAL(MFd); - const auto MFu = PHYSICAL(MFu); - const auto MFe = PHYSICAL(MFe); - const auto decay_mass = PHYSICAL(MAh); - const auto decay_scale = 0.25 * Sqr(decay_mass); - - const auto vev = 1.0 / Sqrt(qedqcd.displayFermiConstant() * Sqrt(2.0)); - - std::complex result = 0; - for (int gI1 = 0; gI1 < 3; ++gI1) { - result += 0.3333333333333333 * pseudoscalar_fermion_qcd_factor( - decay_mass, MFd(gI1)) * CpAhFdbarFdPL(gI1, gI1) * vev * AP12(decay_scale - / Sqr(MFd(gI1))) / MFd(gI1); - } - for (int gI1 = 0; gI1 < 3; ++gI1) { - result += 1.3333333333333333 * pseudoscalar_fermion_qcd_factor( - decay_mass, MFu(gI1)) * CpAhFubarFuPL(gI1, gI1) * vev * AP12(decay_scale - / Sqr(MFu(gI1))) / MFu(gI1); - } - for (int gI1 = 0; gI1 < 3; ++gI1) { - result += CpAhFebarFePL(gI1, gI1) * vev * AP12(decay_scale / Sqr(MFe( - gI1))) / MFe(gI1); - } - result *= std::complex(2.0,0.); - - - result *= 0.18926819071273507 * physical_input.get( - Physical_input::alpha_em_0) * Sqrt(qedqcd.displayFermiConstant()); - - eff_CpAhVPVP = result; - -} - -void Standard_model_effective_couplings::calculate_eff_CpAhVGVG() -{ - const auto g3 = MODELPARAMETER(g3); - const auto MFd = PHYSICAL(MFd); - const auto MFu = PHYSICAL(MFu); - const double alpha_s = 0.07957747154594767*Sqr(g3); - const auto decay_mass = PHYSICAL(MAh); - const auto decay_scale = 0.25 * Sqr(decay_mass); - - const auto vev = 1.0 / Sqrt(qedqcd.displayFermiConstant() * Sqrt(2.0)); - - std::complex result = 0; - for (int gI1 = 0; gI1 < 3; ++gI1) { - result += CpAhFdbarFdPL(gI1, gI1) * vev * AP12(decay_scale / Sqr(MFd( - gI1))) / MFd(gI1); - } - for (int gI1 = 0; gI1 < 3; ++gI1) { - result += CpAhFubarFuPL(gI1, gI1) * vev * AP12(decay_scale / Sqr(MFu( - gI1))) / MFu(gI1); - } - result *= std::complex(1.5,0.); - - if (include_qcd_corrections) { - result *= pseudoscalar_scaling_factor(decay_mass); - } - - - result *= 0.12617879380849006 * alpha_s * Sqrt(qedqcd.displayFermiConstant() - ); - - eff_CpAhVGVG = result; - -} - -} // namespace standard_model -} // namespace flexiblesusy diff --git a/model_specific/SM/standard_model_effective_couplings.hpp b/model_specific/SM/standard_model_effective_couplings.hpp deleted file mode 100644 index f8f75bf8cd..0000000000 --- a/model_specific/SM/standard_model_effective_couplings.hpp +++ /dev/null @@ -1,113 +0,0 @@ -// ==================================================================== -// This file is part of FlexibleSUSY. -// -// FlexibleSUSY 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. -// -// FlexibleSUSY 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 FlexibleSUSY. If not, see -// . -// ==================================================================== - - -#ifndef STANDARD_MODEL_EFFECTIVE_COUPLINGS_H -#define STANDARD_MODEL_EFFECTIVE_COUPLINGS_H - -#include "standard_model.hpp" -#include "lowe.h" -#include "physical_input.hpp" - -#include -#include - -namespace flexiblesusy { - -namespace standard_model { - -class Standard_model_effective_couplings { -public: - Standard_model_effective_couplings(const Standard_model&, - const softsusy::QedQcd&, - const Physical_input&); - - void do_run_couplings(bool flag) { rg_improve = flag; } - bool do_run_couplings() const { return rg_improve; } - void do_include_qcd_corrections(bool flag) { include_qcd_corrections = flag; } - bool do_include_qcd_corrections() const { return include_qcd_corrections; } - void set_physical_inputs(const Physical_input& inputs_) { physical_input = inputs_; } - void set_low_energy_data(const softsusy::QedQcd& qedqcd_) { qedqcd = qedqcd_; } - void set_model(const Standard_model& model_); - - double get_hhVPVP_partial_width() const; - double get_hhVGVG_partial_width() const; - double get_AhVPVP_partial_width() const; - double get_AhVGVG_partial_width() const; - std::complex get_eff_CphhVPVP() const { return eff_CphhVPVP; } - std::complex get_eff_CphhVGVG() const { return eff_CphhVGVG; } - std::complex get_eff_CpAhVPVP() const { return eff_CpAhVPVP; } - std::complex get_eff_CpAhVGVG() const { return eff_CpAhVGVG; } - - void calculate_effective_couplings(); - - std::complex CpFdhhbarFdPL(int gt1, int gt3) const; - std::complex CpFuhhbarFuPL(int gt1, int gt3) const; - std::complex CpFehhbarFePL(int gt1, int gt3) const; - double CphhVWpconjVWp() const; - std::complex CpAhFdbarFdPL(int gt2, int gt3) const; - std::complex CpAhFubarFuPL(int gt2, int gt3) const; - std::complex CpAhFebarFePL(int gt2, int gt3) const; - void calculate_eff_CphhVPVP(); - void calculate_eff_CphhVGVG(); - void calculate_eff_CpAhVPVP(); - void calculate_eff_CpAhVGVG(); - -private: - Standard_model model; - softsusy::QedQcd qedqcd; - Physical_input physical_input; - bool rg_improve; - bool include_qcd_corrections; - - void copy_mixing_matrices_from_model(); - - standard_model::Standard_model initialise_SM() const; - void run_SM_strong_coupling_to(standard_model::Standard_model, double m); - - // higher order corrections to the amplitudes for - // effective coupling to photons - std::complex scalar_scalar_qcd_factor(double, double) const; - std::complex scalar_fermion_qcd_factor(double, double) const; - std::complex pseudoscalar_fermion_qcd_factor(double, double) const; - - // higher order corrections to the leading order - // effective couplings to gluons - double number_of_active_flavours(double) const; - double scalar_scaling_factor(double) const; - double pseudoscalar_scaling_factor(double) const; - - Eigen::Matrix,3,3> Vd; - Eigen::Matrix,3,3> Ud; - Eigen::Matrix,3,3> Vu; - Eigen::Matrix,3,3> Uu; - Eigen::Matrix,3,3> Ve; - Eigen::Matrix,3,3> Ue; - Eigen::Matrix ZZ; - - std::complex eff_CphhVPVP; - std::complex eff_CphhVGVG; - std::complex eff_CpAhVPVP; - std::complex eff_CpAhVGVG; - -}; - -} // namespace standard_model -} // namespace flexiblesusy - -#endif diff --git a/src/effective_couplings.cpp b/src/effective_couplings.cpp deleted file mode 100644 index a93238b25e..0000000000 --- a/src/effective_couplings.cpp +++ /dev/null @@ -1,1145 +0,0 @@ -// ==================================================================== -// This file is part of FlexibleSUSY. -// -// FlexibleSUSY 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. -// -// FlexibleSUSY 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 FlexibleSUSY. If not, see -// . -// ==================================================================== - -#include "effective_couplings.hpp" - -#include -#include -#include - -namespace flexiblesusy { - -namespace effective_couplings { - -namespace { - -constexpr double Pi = 3.141592653589793; - -double sqr(double x) noexcept { return x*x; } - -std::complex sqr(const std::complex& z) noexcept -{ - return z * z; -} - -const std::map >& get_scalar_fermion_loop_data() -{ - static const std::map > data = { - {0.000000, std::complex(-1.000000, 0.000000)}, - {2.500000e-02, std::complex(-9.274410e-01, 0.000000)}, - {5.000000e-02, std::complex(-8.699240e-01, 0.000000)}, - {7.500000e-02, std::complex(-8.171770e-01, 0.000000)}, - {1.000000e-01, std::complex(-7.673120e-01, 0.000000)}, - {1.250000e-01, std::complex(-7.192000e-01, 0.000000)}, - {1.500000e-01, std::complex(-6.724460e-01, 0.000000)}, - {2.000000e-01, std::complex(-5.813970e-01, 0.000000)}, - {2.250000e-01, std::complex(-5.366180e-01, 0.000000)}, - {2.500000e-01, std::complex(-4.920900e-01, 0.000000)}, - {2.750000e-01, std::complex(-4.476720e-01, 0.000000)}, - {3.000000e-01, std::complex(-4.032190e-01, 0.000000)}, - {3.250000e-01, std::complex(-3.586210e-01, 0.000000)}, - {3.750000e-01, std::complex(-2.685470e-01, 0.000000)}, - {4.000000e-01, std::complex(-2.228670e-01, 0.000000)}, - {4.250000e-01, std::complex(-1.766110e-01, 0.000000)}, - {4.500000e-01, std::complex(-1.296750e-01, 0.000000)}, - {4.750000e-01, std::complex(-8.194230e-02, 0.000000)}, - {5.000000e-01, std::complex(-3.329450e-02, 0.000000)}, - {5.250000e-01, std::complex(1.639910e-02, 0.000000)}, - {5.500000e-01, std::complex(6.728150e-02, 0.000000)}, - {5.750000e-01, std::complex(1.195110e-01, 0.000000)}, - {6.000000e-01, std::complex(1.732640e-01, 0.000000)}, - {6.250000e-01, std::complex(2.287460e-01, 0.000000)}, - {6.500000e-01, std::complex(2.861880e-01, 0.000000)}, - {6.750000e-01, std::complex(3.458640e-01, 0.000000)}, - {7.000000e-01, std::complex(4.080960e-01, 0.000000)}, - {7.500000e-01, std::complex(5.418690e-01, 0.000000)}, - {7.750000e-01, std::complex(6.144780e-01, 0.000000)}, - {8.000000e-01, std::complex(6.918550e-01, 0.000000)}, - {8.250000e-01, std::complex(7.749940e-01, 0.000000)}, - {8.500000e-01, std::complex(8.652370e-01, 0.000000)}, - {8.750000e-01, std::complex(9.644870e-01, 0.000000)}, - {9.000000e-01, std::complex(1.075600, 0.000000)}, - {9.250000e-01, std::complex(1.203210, 0.000000)}, - {9.500000e-01, std::complex(1.355880, 0.000000)}, - {9.750000e-01, std::complex(1.553630, 0.000000)}, - {9.775000e-01, std::complex(1.577670, 0.000000)}, - {9.800000e-01, std::complex(1.602870, 0.000000)}, - {9.825000e-01, std::complex(1.629430, 0.000000)}, - {9.850000e-01, std::complex(1.657590, 0.000000)}, - {9.875000e-01, std::complex(1.687670, 0.000000)}, - {9.900000e-01, std::complex(1.720150, 0.000000)}, - {9.925000e-01, std::complex(1.755740, 0.000000)}, - {9.950000e-01, std::complex(1.795700, 0.000000)}, - {9.975000e-01, std::complex(1.842770, 0.000000)}, - {9.997500e-01, std::complex(1.899920, 0.000000)}, - {9.999750e-01, std::complex(1.908560, 0.000000)}, - {9.999975e-01, std::complex(1.908160, 0.000000)}, - {1.000002, std::complex(1.910400, 1.397050e-02)}, - {1.000025, std::complex(1.915280, 1.661240e-04)}, - {1.000250, std::complex(1.920980, 4.940420e-03)}, - {1.002500, std::complex(1.974600, 4.992560e-02)}, - {1.005000, std::complex(2.015800, 9.685620e-02)}, - {1.007500, std::complex(2.049050, 1.413840e-01)}, - {1.010000, std::complex(2.075740, 1.877710e-01)}, - {1.012500, std::complex(2.098510, 2.294580e-01)}, - {1.015000, std::complex(2.117730, 2.678450e-01)}, - {1.017500, std::complex(2.134460, 3.082090e-01)}, - {1.020000, std::complex(2.148530, 3.453210e-01)}, - {1.022500, std::complex(2.160570, 3.955390e-01)}, - {1.025000, std::complex(2.167440, 3.674170e-01)}, - {1.050000, std::complex(2.217290, 7.401210e-01)}, - {1.075000, std::complex(2.202960, 9.972400e-01)}, - {1.100000, std::complex(2.160810, 1.209370)}, - {1.125000, std::complex(2.104920, 1.386380)}, - {1.150000, std::complex(2.041990, 1.536790)}, - {1.175000, std::complex(1.977190, 1.667430)}, - {1.200000, std::complex(1.910320, 1.781250)}, - {1.225000, std::complex(1.844700, 1.879300)}, - {1.250000, std::complex(1.780290, 1.968390)}, - {1.275000, std::complex(1.717540, 2.045420)}, - {1.300000, std::complex(1.655320, 2.112210)}, - {1.325000, std::complex(1.598500, 2.177810)}, - {1.350000, std::complex(1.541930, 2.235760)}, - {1.375000, std::complex(1.487760, 2.287090)}, - {1.400000, std::complex(1.435160, 2.334260)}, - {1.425000, std::complex(1.383500, 2.373900)}, - {1.450000, std::complex(1.335620, 2.416060)}, - {1.475000, std::complex(1.289760, 2.453690)}, - {1.500000, std::complex(1.243910, 2.487070)}, - {1.525000, std::complex(1.201800, 2.518090)}, - {1.550000, std::complex(1.143560, 2.542650)}, - {1.575000, std::complex(1.119830, 2.573500)}, - {1.600000, std::complex(1.079290, 2.595490)}, - {1.625000, std::complex(1.041180, 2.616630)}, - {1.650000, std::complex(1.007980, 2.644280)}, - {1.675000, std::complex(9.728280e-01, 2.665720)}, - {1.700000, std::complex(9.395430e-01, 2.683790)}, - {1.725000, std::complex(9.076790e-01, 2.703480)}, - {1.750000, std::complex(8.751620e-01, 2.718770)}, - {1.775000, std::complex(8.451780e-01, 2.734570)}, - {1.800000, std::complex(8.157810e-01, 2.749670)}, - {1.825000, std::complex(7.869390e-01, 2.764300)}, - {1.850000, std::complex(7.589250e-01, 2.777410)}, - {1.875000, std::complex(7.321510e-01, 2.790010)}, - {1.900000, std::complex(7.087210e-01, 2.802260)}, - {1.925000, std::complex(6.804190e-01, 2.813950)}, - {1.950000, std::complex(6.561150e-01, 2.824470)}, - {1.975000, std::complex(6.278130e-01, 2.830280)}, - {2.000000, std::complex(6.079530e-01, 2.844660)}, - {2.025000, std::complex(5.851860e-01, 2.856120)}, - {2.050000, std::complex(5.640790e-01, 2.863510)}, - {2.075000, std::complex(5.433580e-01, 2.871930)}, - {2.100000, std::complex(5.199450e-01, 2.878980)}, - {2.125000, std::complex(5.012280e-01, 2.888570)}, - {2.150000, std::complex(4.822080e-01, 2.895210)}, - {2.175000, std::complex(4.629140e-01, 2.902580)}, - {2.200000, std::complex(4.438430e-01, 2.909290)}, - {2.225000, std::complex(4.234060e-01, 2.913920)}, - {2.250000, std::complex(4.055230e-01, 2.925310)}, - {2.275000, std::complex(3.903050e-01, 2.928750)}, - {2.300000, std::complex(3.728230e-01, 2.933830)}, - {2.325000, std::complex(3.569420e-01, 2.940510)}, - {2.350000, std::complex(3.410110e-01, 2.945240)}, - {2.375000, std::complex(3.252790e-01, 2.949580)}, - {2.400000, std::complex(3.091420e-01, 2.955910)}, - {2.425000, std::complex(2.919870e-01, 2.959440)}, - {2.450000, std::complex(2.786050e-01, 2.964930)}, - {2.475000, std::complex(2.642730e-01, 2.970060)}, - {2.500000, std::complex(2.459080e-01, 2.978780)}, - {2.625000, std::complex(1.852400e-01, 2.991680)}, - {2.750000, std::complex(1.253350e-01, 3.008150)}, - {2.875000, std::complex(7.046560e-02, 3.021720)}, - {3.000000, std::complex(2.001250e-02, 3.035770)}, - {3.125000, std::complex(-2.403420e-02, 3.044270)}, - {3.250000, std::complex(-6.512050e-02, 3.053970)}, - {3.375000, std::complex(-1.093980e-01, 3.060300)}, - {3.500000, std::complex(-1.394160e-01, 3.068600)}, - {3.625000, std::complex(-1.726980e-01, 3.075360)}, - {3.750000, std::complex(-2.031350e-01, 3.081210)}, - {3.875000, std::complex(-2.363260e-01, 3.087060)}, - {4.000000, std::complex(-2.583920e-01, 3.092340)}, - {4.125000, std::complex(-2.832940e-01, 3.095760)}, - {4.250000, std::complex(-3.085850e-01, 3.100940)}, - {4.375000, std::complex(-3.286430e-01, 3.103730)}, - {4.500000, std::complex(-3.493200e-01, 3.108120)}, - {4.625000, std::complex(-3.688020e-01, 3.110960)}, - {4.750000, std::complex(-3.872730e-01, 3.114360)}, - {4.875000, std::complex(-4.077860e-01, 3.121410)}, - {5.000000, std::complex(-4.211210e-01, 3.119970)}, - {5.250000, std::complex(-4.517070e-01, 3.125250)}, - {5.500000, std::complex(-4.804080e-01, 3.130170)}, - {5.750000, std::complex(-5.042630e-01, 3.134640)}, - {6.000000, std::complex(-5.269960e-01, 3.138710)}, - {6.250000, std::complex(-5.486190e-01, 3.142740)}, - {6.500000, std::complex(-5.670900e-01, 3.147910)}, - {6.750000, std::complex(-5.842780e-01, 3.150820)}, - {7.000000, std::complex(-6.017080e-01, 3.157090)}, - {7.250000, std::complex(-6.183280e-01, 3.158450)}, - {7.500000, std::complex(-6.294920e-01, 3.160890)}, - {7.750000, std::complex(-6.423680e-01, 3.163460)}, - {8.000000, std::complex(-6.561920e-01, 3.167320)}, - {8.250000, std::complex(-6.580500e-01, 3.111450)}, - {8.500000, std::complex(-6.760020e-01, 3.173130)}, - {8.750000, std::complex(-6.859640e-01, 3.176160)}, - {9.000000, std::complex(-6.948940e-01, 3.179130)}, - {9.250000, std::complex(-7.031180e-01, 3.182040)}, - {9.500000, std::complex(-7.116720e-01, 3.184860)}, - {9.750000, std::complex(-7.193760e-01, 3.187730)}, - {1.000000e+01, std::complex(-7.263360e-01, 3.190610)}, - {1.025000e+01, std::complex(-7.331110e-01, 3.193210)}, - {1.050000e+01, std::complex(-7.384460e-01, 3.201870)}, - {1.075000e+01, std::complex(-7.456170e-01, 3.198790)}, - {1.100000e+01, std::complex(-7.508340e-01, 3.201790)}, - {1.125000e+01, std::complex(-7.565260e-01, 3.203980)}, - {1.150000e+01, std::complex(-7.611350e-01, 3.206560)}, - {1.175000e+01, std::complex(-7.662840e-01, 3.209140)}, - {1.200000e+01, std::complex(-7.707960e-01, 3.212030)}, - {1.225000e+01, std::complex(-7.752710e-01, 3.214360)}, - {1.250000e+01, std::complex(-7.790270e-01, 3.217150)}, - {1.275000e+01, std::complex(-7.845720e-01, 3.220080)}, - {1.300000e+01, std::complex(-7.818920e-01, 3.222210)}, - {1.325000e+01, std::complex(-7.906490e-01, 3.224360)}, - {1.350000e+01, std::complex(-7.936570e-01, 3.227110)}, - {1.375000e+01, std::complex(-7.971300e-01, 3.229460)}, - {1.400000e+01, std::complex(-7.946630e-01, 3.244450)}, - {1.425000e+01, std::complex(-8.026810e-01, 3.238130)}, - {1.450000e+01, std::complex(-8.058680e-01, 3.238630)}, - {1.475000e+01, std::complex(-8.085860e-01, 3.239030)}, - {1.500000e+01, std::complex(-8.102950e-01, 3.241340)}, - {1.525000e+01, std::complex(-8.133750e-01, 3.243740)}, - {1.550000e+01, std::complex(-8.150670e-01, 3.248200)}, - {1.575000e+01, std::complex(-8.176110e-01, 3.249920)}, - {1.600000e+01, std::complex(-8.202630e-01, 3.254450)}, - {1.625000e+01, std::complex(-8.463510e-01, 3.191430)}, - {1.650000e+01, std::complex(-8.235680e-01, 3.256100)}, - {1.675000e+01, std::complex(-8.250930e-01, 3.257230)}, - {1.700000e+01, std::complex(-8.273730e-01, 3.259390)}, - {1.725000e+01, std::complex(-8.286090e-01, 3.273550)}, - {1.750000e+01, std::complex(-8.305330e-01, 3.263970)}, - {1.775000e+01, std::complex(-8.328030e-01, 3.265800)}, - {1.800000e+01, std::complex(-8.338430e-01, 3.268230)}, - {1.825000e+01, std::complex(-8.347070e-01, 3.271350)}, - {1.850000e+01, std::complex(-8.358370e-01, 3.274640)}, - {1.875000e+01, std::complex(-8.374380e-01, 3.274590)}, - {1.900000e+01, std::complex(-8.384120e-01, 3.277190)}, - {1.925000e+01, std::complex(-8.402010e-01, 3.278980)}, - {1.950000e+01, std::complex(-8.408070e-01, 3.280950)}, - {1.975000e+01, std::complex(-8.418340e-01, 3.283500)}, - {2.000000e+01, std::complex(-8.424940e-01, 3.286340)}, - {2.025000e+01, std::complex(-8.442360e-01, 3.287140)}, - {2.050000e+01, std::complex(-8.449020e-01, 3.289190)}, - {2.075000e+01, std::complex(-8.464230e-01, 3.291930)}, - {2.100000e+01, std::complex(-8.462180e-01, 3.293560)}, - {2.125000e+01, std::complex(-8.480760e-01, 3.296380)}, - {2.150000e+01, std::complex(-8.472430e-01, 3.298700)}, - {2.175000e+01, std::complex(-8.489340e-01, 3.299710)}, - {2.200000e+01, std::complex(-8.497100e-01, 3.301270)}, - {2.225000e+01, std::complex(-8.506200e-01, 3.303100)}, - {2.250000e+01, std::complex(-8.487620e-01, 3.314010)}, - {2.275000e+01, std::complex(-8.500720e-01, 3.306940)}, - {2.300000e+01, std::complex(-8.519600e-01, 3.309770)}, - {2.325000e+01, std::complex(-8.522630e-01, 3.310530)}, - {2.350000e+01, std::complex(-8.510320e-01, 3.315750)}, - {2.375000e+01, std::complex(-8.539750e-01, 3.314820)}, - {2.400000e+01, std::complex(-8.527500e-01, 3.315770)}, - {2.425000e+01, std::complex(-8.547330e-01, 3.318300)}, - {2.450000e+01, std::complex(-8.545140e-01, 3.319950)}, - {2.475000e+01, std::complex(-8.555860e-01, 3.322180)}, - {2.500000e+01, std::complex(-8.530350e-01, 3.323310)}, - {2.625000e+01, std::complex(-8.575340e-01, 3.333010)}, - {2.750000e+01, std::complex(-8.585380e-01, 3.341910)}, - {2.875000e+01, std::complex(-8.576420e-01, 3.356210)}, - {3.000000e+01, std::complex(-8.597370e-01, 3.356690)}, - {3.125000e+01, std::complex(-8.576430e-01, 3.374410)}, - {3.250000e+01, std::complex(-8.592460e-01, 3.377930)}, - {3.375000e+01, std::complex(-8.597280e-01, 3.383100)}, - {3.500000e+01, std::complex(-8.593010e-01, 3.390200)}, - {3.625000e+01, std::complex(-8.584100e-01, 3.398350)}, - {3.750000e+01, std::complex(-8.507510e-01, 3.413200)}, - {3.875000e+01, std::complex(-8.567330e-01, 3.412240)}, - {4.000000e+01, std::complex(-8.522690e-01, 3.427060)}, - {4.125000e+01, std::complex(-8.544010e-01, 3.427280)}, - {4.250000e+01, std::complex(-8.477110e-01, 3.450660)}, - {4.375000e+01, std::complex(-8.525840e-01, 3.438880)}, - {4.500000e+01, std::complex(-8.502110e-01, 3.447640)}, - {4.625000e+01, std::complex(-8.494860e-01, 3.453470)}, - {4.750000e+01, std::complex(-8.488420e-01, 3.457370)}, - {4.875000e+01, std::complex(-8.462250e-01, 3.463940)}, - {5.000000e+01, std::complex(-8.456140e-01, 3.469520)}, - {5.250000e+01, std::complex(-8.430690e-01, 3.481720)}, - {5.500000e+01, std::complex(-8.408260e-01, 3.492080)}, - {5.750000e+01, std::complex(-8.371300e-01, 3.504700)}, - {6.000000e+01, std::complex(-8.325950e-01, 3.517420)}, - {6.250000e+01, std::complex(-8.314450e-01, 3.524800)}, - {6.500000e+01, std::complex(-8.274530e-01, 3.537040)}, - {6.750000e+01, std::complex(-8.261580e-01, 3.543130)}, - {7.000000e+01, std::complex(-8.183210e-01, 3.548650)}, - {7.250000e+01, std::complex(-8.197600e-01, 3.558200)}, - {7.500000e+01, std::complex(-8.177000e-01, 3.569170)}, - {7.750000e+01, std::complex(-8.089130e-01, 3.589240)}, - {8.000000e+01, std::complex(-8.104730e-01, 3.586730)}, - {8.250000e+01, std::complex(-8.087020e-01, 3.595360)}, - {8.500000e+01, std::complex(-7.978130e-01, 3.608560)}, - {8.750000e+01, std::complex(-8.044710e-01, 3.610160)}, - {9.000000e+01, std::complex(-8.006390e-01, 3.617100)}, - {9.250000e+01, std::complex(-7.970650e-01, 3.627710)}, - {9.500000e+01, std::complex(-7.956520e-01, 3.631140)}, - {9.750000e+01, std::complex(-7.847550e-01, 3.642800)}, - {1.000000e+02, std::complex(-7.842690e-01, 3.653610)}, - {1.025000e+02, std::complex(-7.582520e-01, 3.667740)}, - {1.050000e+02, std::complex(-7.831340e-01, 3.661320)}, - {1.075000e+02, std::complex(-7.669900e-01, 3.660770)}, - {1.100000e+02, std::complex(-7.781230e-01, 3.674210)}, - {1.125000e+02, std::complex(-7.610390e-01, 3.686090)}, - {1.150000e+02, std::complex(-7.753390e-01, 3.684740)}, - {1.175000e+02, std::complex(-8.045650e-01, 3.641630)}, - {1.200000e+02, std::complex(-7.666080e-01, 3.702040)}, - {1.225000e+02, std::complex(-8.494620e-01, 3.466970)}, - {1.250000e+02, std::complex(-7.661640e-01, 3.710060)}, - {1.375000e+02, std::complex(-7.547590e-01, 3.735350)}, - {1.500000e+02, std::complex(-7.468060e-01, 3.761270)}, - {1.625000e+02, std::complex(-7.134580e-01, 3.796710)}, - {1.750000e+02, std::complex(-7.325910e-01, 3.810560)}, - {1.875000e+02, std::complex(-7.204100e-01, 3.827430)}, - {2.000000e+02, std::complex(-6.431750e-01, 3.921010)}, - {2.125000e+02, std::complex(-6.989200e-01, 3.867360)}, - {2.250000e+02, std::complex(-6.881680e-01, 3.889280)}, - {2.375000e+02, std::complex(-6.741300e-01, 3.913110)}, - {2.500000e+02, std::complex(-6.784930e-01, 3.918510)}, - {2.625000e+02, std::complex(-7.149390e-01, 3.886200)}, - {2.750000e+02, std::complex(-6.761000e-01, 3.940910)}, - {2.875000e+02, std::complex(-6.682460e-01, 3.959060)}, - {3.000000e+02, std::complex(-6.624520e-01, 3.967190)}, - {3.125000e+02, std::complex(-6.574130e-01, 3.985200)}, - {3.250000e+02, std::complex(-6.452390e-01, 4.010600)}, - {3.375000e+02, std::complex(-6.349790e-01, 4.009280)}, - {3.500000e+02, std::complex(-6.265670e-01, 4.006580)}, - {3.625000e+02, std::complex(-6.381220e-01, 4.031630)}, - {3.750000e+02, std::complex(-6.195300e-01, 4.046400)}, - {3.875000e+02, std::complex(-6.423240e-01, 4.058040)}, - {4.000000e+02, std::complex(-5.624150e-01, 4.050670)}, - {4.125000e+02, std::complex(-6.127920e-01, 4.072060)}, - {4.250000e+02, std::complex(-6.192850e-01, 4.082630)}, - {4.375000e+02, std::complex(-6.139200e-01, 4.096560)}, - {4.500000e+02, std::complex(-5.866120e-01, 4.089830)}, - {4.625000e+02, std::complex(-5.710360e-01, 4.087280)}, - {4.750000e+02, std::complex(-4.207690e-01, 4.288790)}, - {4.875000e+02, std::complex(-6.170350e-01, 4.133430)}, - {5.000000e+02, std::complex(-6.029440e-01, 4.137850)}, - {5.250000e+02, std::complex(-5.822620e-01, 4.161870)}, - {5.500000e+02, std::complex(-5.991270e-01, 4.170990)}, - {5.750000e+02, std::complex(-5.189840e-01, 4.206430)}, - {6.000000e+02, std::complex(-5.957670e-01, 4.193760)}, - {6.250000e+02, std::complex(-5.628110e-01, 4.227600)}, - {6.500000e+02, std::complex(-5.219400e-01, 4.171480)}, - {6.750000e+02, std::complex(-5.646360e-01, 4.240940)}, - {7.000000e+02, std::complex(-5.745030e-01, 4.236090)}, - {7.250000e+02, std::complex(-5.744090e-01, 4.258600)}, - {7.500000e+02, std::complex(-5.671400e-01, 4.258510)}, - {7.750000e+02, std::complex(-5.652500e-01, 4.264550)}, - {8.000000e+02, std::complex(-5.420170e-01, 4.295980)}, - {8.250000e+02, std::complex(-5.422580e-01, 4.314380)}, - {8.500000e+02, std::complex(-6.051220e-01, 4.246880)}, - {8.750000e+02, std::complex(-5.504890e-01, 4.326040)}, - {9.000000e+02, std::complex(-5.520800e-01, 4.325450)}, - {9.250000e+02, std::complex(-4.959200e-01, 4.258360)}, - {9.500000e+02, std::complex(-5.521010e-01, 4.358470)}, - {9.750000e+02, std::complex(-5.294560e-01, 4.380260)}, - {1.000000e+03, std::complex(-5.083960e-01, 4.371040)}, - {1.025000e+03, std::complex(-5.456840e-01, 4.384650)}, - {1.050000e+03, std::complex(-5.435860e-01, 4.393050)}, - {1.075000e+03, std::complex(-5.416760e-01, 4.401180)}, - {1.100000e+03, std::complex(-5.546870e-01, 4.371810)}, - {1.125000e+03, std::complex(-5.668080e-01, 4.371030)}, - {1.150000e+03, std::complex(-5.364750e-01, 4.424370)}, - {1.175000e+03, std::complex(-4.698540e-01, 4.476270)}, - {1.200000e+03, std::complex(-4.618550e-01, 4.354330)}, - {1.225000e+03, std::complex(-4.703910e-01, 4.449320)}, - {1.250000e+03, std::complex(-5.300020e-01, 4.453420)}, - {1.375000e+03, std::complex(-4.930750e-01, 4.494780)}, - {1.500000e+03, std::complex(-5.172970e-01, 4.516980)}, - {1.625000e+03, std::complex(-5.510960e-01, 4.559270)}, - {1.750000e+03, std::complex(-5.078310e-01, 4.571030)}, - {1.875000e+03, std::complex(-4.901370e-01, 4.622460)}, - {2.000000e+03, std::complex(-4.839760e-01, 4.656640)}, - {2.125000e+03, std::complex(-6.801030e-01, 4.470020)}, - {2.250000e+03, std::complex(-4.950810e-01, 4.659700)}, - {2.375000e+03, std::complex(-4.927970e-01, 4.678860)}, - {2.500000e+03, std::complex(-4.907780e-01, 4.697060)}, - {2.625000e+03, std::complex(-4.890080e-01, 4.714400)}, - {2.750000e+03, std::complex(-4.874400e-01, 4.730940)}, - {2.875000e+03, std::complex(-4.860670e-01, 4.746770)}, - {3.000000e+03, std::complex(-4.848620e-01, 4.761940)}, - {3.125000e+03, std::complex(-4.838120e-01, 4.776500)}, - {3.250000e+03, std::complex(-4.828940e-01, 4.790510)}, - {3.375000e+03, std::complex(-4.821040e-01, 4.803990)}, - {3.500000e+03, std::complex(-4.814220e-01, 4.817000)}, - {3.625000e+03, std::complex(-4.808480e-01, 4.829560)}, - {3.750000e+03, std::complex(-4.803670e-01, 4.841700)}, - {3.875000e+03, std::complex(-4.799690e-01, 4.853450)}, - {4.000000e+03, std::complex(-4.796470e-01, 4.864840)}, - {4.125000e+03, std::complex(-4.793990e-01, 4.875880)}, - {4.250000e+03, std::complex(-4.792170e-01, 4.886590)}, - {4.375000e+03, std::complex(-4.790840e-01, 4.896990)}, - {4.500000e+03, std::complex(-4.789680e-01, 4.907040)}, - {4.625000e+03, std::complex(-4.790210e-01, 4.916980)}, - {4.750000e+03, std::complex(-4.790510e-01, 4.926570)}, - {4.875000e+03, std::complex(-4.791300e-01, 4.935920)}, - {5.000000e+03, std::complex(-4.792570e-01, 4.945040)}, - {5.250000e+03, std::complex(-4.796050e-01, 4.962610)}, - {5.500000e+03, std::complex(-4.800930e-01, 4.979390)}, - {5.750000e+03, std::complex(-4.807000e-01, 4.995430)}, - {6.000000e+03, std::complex(-4.814030e-01, 5.010780)}, - {6.250000e+03, std::complex(-4.821960e-01, 5.025530)}, - {6.500000e+03, std::complex(-4.830640e-01, 5.039710)}, - {6.750000e+03, std::complex(-4.840040e-01, 5.053350)}, - {7.000000e+03, std::complex(-4.850120e-01, 5.066510)}, - {7.250000e+03, std::complex(-4.860650e-01, 5.079220)}, - {7.500000e+03, std::complex(-4.871620e-01, 5.091490)}, - {7.750000e+03, std::complex(-4.883080e-01, 5.103370)}, - {8.000000e+03, std::complex(-4.894960e-01, 5.114870)}, - {8.250000e+03, std::complex(-4.907040e-01, 5.126030)}, - {8.500000e+03, std::complex(-4.919510e-01, 5.136860)}, - {8.750000e+03, std::complex(-4.932090e-01, 5.147370)}, - {9.000000e+03, std::complex(-4.945050e-01, 5.157590)}, - {9.250000e+03, std::complex(-4.957630e-01, 5.167590)}, - {9.500000e+03, std::complex(-4.971370e-01, 5.177230)}, - {9.750000e+03, std::complex(-4.984880e-01, 5.186670)}, - {1.000000e+04, std::complex(-4.998480e-01, 5.195860)}, - {1.025000e+04, std::complex(-5.012260e-01, 5.204840)}, - {1.050000e+04, std::complex(-5.026090e-01, 5.213590)}, - {1.075000e+04, std::complex(-5.039980e-01, 5.222160)}, - {1.100000e+04, std::complex(-5.053960e-01, 5.230520)}, - {1.125000e+04, std::complex(-5.068090e-01, 5.238680)}, - {1.150000e+04, std::complex(-5.082170e-01, 5.246680)}, - {1.175000e+04, std::complex(-5.096310e-01, 5.254510)}, - {1.200000e+04, std::complex(-5.110560e-01, 5.262180)}, - {1.225000e+04, std::complex(-5.124760e-01, 5.269690)}, - {1.250000e+04, std::complex(-5.139030e-01, 5.277040)}, - {1.375000e+04, std::complex(-5.210650e-01, 5.311770)}, - {1.500000e+04, std::complex(-5.281870e-01, 5.343490)}, - {1.625000e+04, std::complex(-5.352570e-01, 5.372690)}, - {1.750000e+04, std::complex(-5.407550e-01, 5.400700)}, - {1.875000e+04, std::complex(-5.491820e-01, 5.424950)}, - {2.000000e+04, std::complex(-5.559810e-01, 5.448540)}, - {2.125000e+04, std::complex(-5.608930e-01, 5.471800)}, - {2.250000e+04, std::complex(-5.651330e-01, 5.489130)}, - {2.375000e+04, std::complex(-5.731510e-01, 5.507680)}, - {2.500000e+04, std::complex(-5.416510e-01, 5.554760)}, - {2.625000e+04, std::complex(-5.851030e-01, 5.551470)}, - {2.750000e+04, std::complex(-5.911890e-01, 5.568540)}, - {2.875000e+04, std::complex(-5.972020e-01, 5.584870)}, - {3.000000e+04, std::complex(-6.030830e-01, 5.600500)}, - {3.125000e+04, std::complex(-6.088740e-01, 5.615470)}, - {3.250000e+04, std::complex(-6.145350e-01, 5.629900)}, - {3.375000e+04, std::complex(-6.201340e-01, 5.643760)}, - {3.500000e+04, std::complex(-6.256230e-01, 5.657140)}, - {3.625000e+04, std::complex(-6.310320e-01, 5.670020)}, - {3.750000e+04, std::complex(-6.363710e-01, 5.682500)}, - {3.875000e+04, std::complex(-6.416170e-01, 5.694550)}, - {4.000000e+04, std::complex(-6.467650e-01, 5.706240)}, - {4.125000e+04, std::complex(-6.518280e-01, 5.717570)}, - {4.250000e+04, std::complex(-6.567960e-01, 5.728560)}, - {4.375000e+04, std::complex(-6.617620e-01, 5.739240)}, - {4.500000e+04, std::complex(-6.667960e-01, 5.749480)}, - {4.625000e+04, std::complex(-6.716260e-01, 5.759560)}, - {4.750000e+04, std::complex(-6.762020e-01, 5.769430)}, - {4.875000e+04, std::complex(-6.809970e-01, 5.778920)}, - {5.000000e+04, std::complex(-6.854800e-01, 5.788330)}, - {5.250000e+04, std::complex(-6.945120e-01, 5.806250)}, - {5.500000e+04, std::complex(-7.029630e-01, 5.823580)}, - {5.750000e+04, std::complex(-7.114860e-01, 5.839920)}, - {6.000000e+04, std::complex(-7.201270e-01, 5.855470)}, - {6.250000e+04, std::complex(-7.284420e-01, 5.870400)}, - {6.500000e+04, std::complex(-7.363280e-01, 5.884850)}, - {6.750000e+04, std::complex(-7.437560e-01, 5.898960)}, - {7.000000e+04, std::complex(-7.516830e-01, 5.912240)}, - {7.250000e+04, std::complex(-7.588050e-01, 5.925290)}, - {7.500000e+04, std::complex(-7.662530e-01, 5.937730)}, - {7.750000e+04, std::complex(-7.732090e-01, 5.949940)}, - {8.000000e+04, std::complex(-7.803130e-01, 5.961600)}, - {8.250000e+04, std::complex(-7.876450e-01, 5.972720)}, - {8.500000e+04, std::complex(-7.940580e-01, 5.983890)}, - {8.750000e+04, std::complex(-8.010120e-01, 5.994420)}, - {9.000000e+04, std::complex(-8.070480e-01, 6.005040)}, - {9.250000e+04, std::complex(-8.136710e-01, 6.015010)}, - {9.500000e+04, std::complex(-8.199980e-01, 6.024830)}, - {9.750000e+04, std::complex(-8.258620e-01, 6.034570)}, - {1.000000e+05, std::complex(-8.317770e-01, 6.044000)}, - {1.025000e+05, std::complex(-8.382350e-01, 6.052860)}, - {1.050000e+05, std::complex(-8.444230e-01, 6.061530)}, - {1.075000e+05, std::complex(-8.497830e-01, 6.070490)}, - {1.100000e+05, std::complex(-8.555830e-01, 6.078880)}, - {1.125000e+05, std::complex(-8.611510e-01, 6.087280)}, - {1.150000e+05, std::complex(-8.665250e-01, 6.095480)}, - {1.175000e+05, std::complex(-8.724370e-01, 6.103110)}, - {1.200000e+05, std::complex(-8.772580e-01, 6.111240)}, - {1.225000e+05, std::complex(-8.832730e-01, 6.118490)}, - {1.250000e+05, std::complex(-8.883480e-01, 6.125990)}, - {1.375000e+05, std::complex(-9.132800e-01, 6.161310)}, - {1.500000e+05, std::complex(-9.370350e-01, 6.193350)}, - {1.625000e+05, std::complex(-9.593780e-01, 6.222940)}, - {1.750000e+05, std::complex(-9.803260e-01, 6.250430)}, - {1.875000e+05, std::complex(-1.000830, 6.275730)}, - {2.000000e+05, std::complex(-1.019750, 6.299570)}, - {2.125000e+05, std::complex(-1.038250, 6.321990)}, - {2.250000e+05, std::complex(-1.055860, 6.342960)}, - {2.375000e+05, std::complex(-1.072980, 6.362930)}, - {2.500000e+05, std::complex(-1.070330, 6.345460)} - }; - - return data; -} - -const std::map >& get_pseudoscalar_fermion_loop_data() -{ - static const std::map > data = { - {0.000000, std::complex(0.000000, 0.000000)}, - {2.500000e-02, std::complex(1.076560e-01, 0.000000)}, - {5.000000e-02, std::complex(1.949420e-01, 0.000000)}, - {7.500000e-02, std::complex(2.758870e-01, 0.000000)}, - {1.000000e-01, std::complex(3.534260e-01, 0.000000)}, - {1.250000e-01, std::complex(4.289350e-01, 0.000000)}, - {1.500000e-01, std::complex(5.032720e-01, 0.000000)}, - {2.000000e-01, std::complex(6.505730e-01, 0.000000)}, - {2.250000e-01, std::complex(7.243250e-01, 0.000000)}, - {2.500000e-01, std::complex(7.985640e-01, 0.000000)}, - {2.750000e-01, std::complex(8.735650e-01, 0.000000)}, - {3.000000e-01, std::complex(9.495800e-01, 0.000000)}, - {3.250000e-01, std::complex(1.026860, 0.000000)}, - {3.750000e-01, std::complex(1.186230, 0.000000)}, - {4.000000e-01, std::complex(1.268850, 0.000000)}, - {4.250000e-01, std::complex(1.353800, 0.000000)}, - {4.500000e-01, std::complex(1.441410, 0.000000)}, - {4.750000e-01, std::complex(1.532020, 0.000000)}, - {5.000000e-01, std::complex(1.626020, 0.000000)}, - {5.250000e-01, std::complex(1.723870, 0.000000)}, - {5.500000e-01, std::complex(1.826080, 0.000000)}, - {5.750000e-01, std::complex(1.933240, 0.000000)}, - {6.000000e-01, std::complex(2.046040, 0.000000)}, - {6.250000e-01, std::complex(2.165330, 0.000000)}, - {6.500000e-01, std::complex(2.292110, 0.000000)}, - {6.750000e-01, std::complex(2.427600, 0.000000)}, - {7.000000e-01, std::complex(2.573330, 0.000000)}, - {7.500000e-01, std::complex(2.903840, 0.000000)}, - {7.750000e-01, std::complex(3.094420, 0.000000)}, - {8.000000e-01, std::complex(3.307510, 0.000000)}, - {8.250000e-01, std::complex(3.549500, 0.000000)}, - {8.500000e-01, std::complex(3.829820, 0.000000)}, - {8.750000e-01, std::complex(4.163300, 0.000000)}, - {9.000000e-01, std::complex(4.575060, 0.000000)}, - {9.250000e-01, std::complex(5.112990, 0.000000)}, - {9.500000e-01, std::complex(5.886840, 0.000000)}, - {9.750000e-01, std::complex(7.257360, 0.000000)}, - {9.775000e-01, std::complex(7.471170, 0.000000)}, - {9.800000e-01, std::complex(7.711960, 0.000000)}, - {9.825000e-01, std::complex(7.987180, 0.000000)}, - {9.850000e-01, std::complex(8.307840, 0.000000)}, - {9.875000e-01, std::complex(8.691140, 0.000000)}, - {9.900000e-01, std::complex(9.166180, 0.000000)}, - {9.925000e-01, std::complex(9.788040, 0.000000)}, - {9.950000e-01, std::complex(1.068200e+01, 0.000000)}, - {9.975000e-01, std::complex(1.225460e+01, 0.000000)}, - {9.997500e-01, std::complex(1.780480e+01, 0.000000)}, - {9.999750e-01, std::complex(2.367810e+01, 0.000000)}, - {9.999975e-01, std::complex(2.970570e+01, 0.000000)}, - {1.000002, std::complex(2.965620e+01, 8.318080)}, - {1.000025, std::complex(2.355710e+01, 8.187350)}, - {1.000250, std::complex(1.752540e+01, 7.932950)}, - {1.002500, std::complex(1.173000e+01, 7.356690)}, - {1.005000, std::complex(1.007550e+01, 7.105360)}, - {1.007500, std::complex(9.139160, 6.937030)}, - {1.010000, std::complex(8.490480, 6.813100)}, - {1.012500, std::complex(7.997270, 6.709250)}, - {1.015000, std::complex(7.600540, 6.619270)}, - {1.017500, std::complex(7.270930, 6.544830)}, - {1.020000, std::complex(6.988450, 6.476850)}, - {1.022500, std::complex(6.745280, 6.432950)}, - {1.025000, std::complex(6.508740, 6.302860)}, - {1.050000, std::complex(5.159350, 6.004980)}, - {1.075000, std::complex(4.412310, 5.793880)}, - {1.100000, std::complex(3.905890, 5.647170)}, - {1.125000, std::complex(3.526080, 5.534670)}, - {1.150000, std::complex(3.223860, 5.444410)}, - {1.175000, std::complex(2.975840, 5.370250)}, - {1.200000, std::complex(2.764050, 5.307690)}, - {1.225000, std::complex(2.580530, 5.250960)}, - {1.250000, std::complex(2.420000, 5.203470)}, - {1.275000, std::complex(2.275920, 5.158490)}, - {1.300000, std::complex(2.143720, 5.116090)}, - {1.325000, std::complex(2.029640, 5.081870)}, - {1.350000, std::complex(1.922910, 5.049630)}, - {1.375000, std::complex(1.824490, 5.018220)}, - {1.400000, std::complex(1.733200, 4.989580)}, - {1.425000, std::complex(1.645760, 4.959580)}, - {1.450000, std::complex(1.568710, 4.936700)}, - {1.475000, std::complex(1.496310, 4.913710)}, - {1.500000, std::complex(1.425980, 4.891260)}, - {1.525000, std::complex(1.361940, 4.869200)}, - {1.550000, std::complex(1.281500, 4.851600)}, - {1.575000, std::complex(1.241970, 4.829040)}, - {1.600000, std::complex(1.183670, 4.808110)}, - {1.625000, std::complex(1.129590, 4.788340)}, - {1.650000, std::complex(1.085190, 4.775910)}, - {1.675000, std::complex(1.037810, 4.760570)}, - {1.700000, std::complex(9.923900e-01, 4.743420)}, - {1.725000, std::complex(9.504580e-01, 4.729520)}, - {1.750000, std::complex(9.072510e-01, 4.713500)}, - {1.775000, std::complex(8.679390e-01, 4.698840)}, - {1.800000, std::complex(8.299460e-01, 4.685000)}, - {1.825000, std::complex(7.932470e-01, 4.672120)}, - {1.850000, std::complex(7.576060e-01, 4.658910)}, - {1.875000, std::complex(7.237830e-01, 4.646140)}, - {1.900000, std::complex(6.938680e-01, 4.633010)}, - {1.925000, std::complex(6.595310e-01, 4.622550)}, - {1.950000, std::complex(6.293180e-01, 4.610510)}, - {1.975000, std::complex(5.938350e-01, 4.596510)}, - {2.000000, std::complex(5.708960e-01, 4.588870)}, - {2.025000, std::complex(5.439020e-01, 4.580170)}, - {2.050000, std::complex(5.176490e-01, 4.567900)}, - {2.075000, std::complex(4.926010e-01, 4.557390)}, - {2.100000, std::complex(4.647580e-01, 4.547410)}, - {2.125000, std::complex(4.428880e-01, 4.538930)}, - {2.150000, std::complex(4.199240e-01, 4.528410)}, - {2.175000, std::complex(3.972860e-01, 4.519440)}, - {2.200000, std::complex(3.749200e-01, 4.510430)}, - {2.225000, std::complex(3.507120e-01, 4.500540)}, - {2.250000, std::complex(3.318060e-01, 4.496940)}, - {2.275000, std::complex(3.127840e-01, 4.485150)}, - {2.300000, std::complex(2.923910e-01, 4.476380)}, - {2.325000, std::complex(2.743710e-01, 4.469110)}, - {2.350000, std::complex(2.557950e-01, 4.460490)}, - {2.375000, std::complex(2.374670e-01, 4.451910)}, - {2.400000, std::complex(2.196490e-01, 4.445880)}, - {2.425000, std::complex(2.000050e-01, 4.437940)}, - {2.450000, std::complex(1.849040e-01, 4.430990)}, - {2.475000, std::complex(1.689050e-01, 4.424440)}, - {2.500000, std::complex(1.504040e-01, 4.423210)}, - {2.625000, std::complex(7.934640e-02, 4.381720)}, - {2.750000, std::complex(1.297750e-02, 4.351380)}, - {2.875000, std::complex(-4.733390e-02, 4.323120)}, - {3.000000, std::complex(-1.014980e-01, 4.299410)}, - {3.125000, std::complex(-1.498850e-01, 4.273050)}, - {3.250000, std::complex(-1.938790e-01, 4.250980)}, - {3.375000, std::complex(-2.409990e-01, 4.230170)}, - {3.500000, std::complex(-2.730740e-01, 4.209970)}, - {3.625000, std::complex(-3.080540e-01, 4.192000)}, - {3.750000, std::complex(-3.400120e-01, 4.174700)}, - {3.875000, std::complex(-3.740870e-01, 4.160310)}, - {4.000000, std::complex(-3.973230e-01, 4.144090)}, - {4.125000, std::complex(-4.234040e-01, 4.128620)}, - {4.250000, std::complex(-4.490400e-01, 4.116440)}, - {4.375000, std::complex(-4.700820e-01, 4.101950)}, - {4.500000, std::complex(-4.910300e-01, 4.090400)}, - {4.625000, std::complex(-5.110380e-01, 4.078200)}, - {4.750000, std::complex(-5.297450e-01, 4.067310)}, - {4.875000, std::complex(-5.492750e-01, 4.061330)}, - {5.000000, std::complex(-5.640350e-01, 4.046380)}, - {5.250000, std::complex(-5.947660e-01, 4.027540)}, - {5.500000, std::complex(-6.233500e-01, 4.010660)}, - {5.750000, std::complex(-6.471030e-01, 3.994550)}, - {6.000000, std::complex(-6.695870e-01, 3.979860)}, - {6.250000, std::complex(-6.907760e-01, 3.966670)}, - {6.500000, std::complex(-7.085310e-01, 3.955430)}, - {6.750000, std::complex(-7.254040e-01, 3.943170)}, - {7.000000, std::complex(-7.416220e-01, 3.935370)}, - {7.250000, std::complex(-7.580050e-01, 3.923890)}, - {7.500000, std::complex(-7.689110e-01, 3.913260)}, - {7.750000, std::complex(-7.812950e-01, 3.904020)}, - {8.000000, std::complex(-7.942160e-01, 3.897010)}, - {8.250000, std::complex(-8.078170e-01, 3.832290)}, - {8.500000, std::complex(-8.128800e-01, 3.881760)}, - {8.750000, std::complex(-8.221520e-01, 3.875220)}, - {9.000000, std::complex(-8.304150e-01, 3.868990)}, - {9.250000, std::complex(-8.379850e-01, 3.863090)}, - {9.500000, std::complex(-8.458430e-01, 3.857650)}, - {9.750000, std::complex(-8.528570e-01, 3.852550)}, - {1.000000e+01, std::complex(-8.591450e-01, 3.847710)}, - {1.025000e+01, std::complex(-8.652810e-01, 3.842980)}, - {1.050000e+01, std::complex(-8.689540e-01, 3.844010)}, - {1.075000e+01, std::complex(-8.764360e-01, 3.834700)}, - {1.100000e+01, std::complex(-8.809730e-01, 3.831060)}, - {1.125000e+01, std::complex(-8.860830e-01, 3.827020)}, - {1.150000e+01, std::complex(-8.900930e-01, 3.823440)}, - {1.175000e+01, std::complex(-8.945950e-01, 3.820190)}, - {1.200000e+01, std::complex(-8.984350e-01, 3.817370)}, - {1.225000e+01, std::complex(-9.023230e-01, 3.814250)}, - {1.250000e+01, std::complex(-9.054520e-01, 3.811640)}, - {1.275000e+01, std::complex(-9.102230e-01, 3.809670)}, - {1.300000e+01, std::complex(-9.074140e-01, 3.805780)}, - {1.325000e+01, std::complex(-9.153060e-01, 3.803960)}, - {1.350000e+01, std::complex(-9.177110e-01, 3.801930)}, - {1.375000e+01, std::complex(-9.206080e-01, 3.799770)}, - {1.400000e+01, std::complex(-9.159340e-01, 3.808650)}, - {1.425000e+01, std::complex(-9.244560e-01, 3.799380)}, - {1.450000e+01, std::complex(-9.273640e-01, 3.795870)}, - {1.475000e+01, std::complex(-9.298400e-01, 3.792330)}, - {1.500000e+01, std::complex(-9.310700e-01, 3.790540)}, - {1.525000e+01, std::complex(-9.335660e-01, 3.789160)}, - {1.550000e+01, std::complex(-9.344470e-01, 3.789620)}, - {1.575000e+01, std::complex(-9.365420e-01, 3.787750)}, - {1.600000e+01, std::complex(-9.383150e-01, 3.788630)}, - {1.625000e+01, std::complex(-9.720960e-01, 3.729790)}, - {1.650000e+01, std::complex(-9.410860e-01, 3.783450)}, - {1.675000e+01, std::complex(-9.423010e-01, 3.781260)}, - {1.700000e+01, std::complex(-9.440710e-01, 3.780230)}, - {1.725000e+01, std::complex(-9.431240e-01, 3.790380)}, - {1.750000e+01, std::complex(-9.462580e-01, 3.778470)}, - {1.775000e+01, std::complex(-9.480620e-01, 3.777380)}, - {1.800000e+01, std::complex(-9.486300e-01, 3.776730)}, - {1.825000e+01, std::complex(-9.489330e-01, 3.776790)}, - {1.850000e+01, std::complex(-9.494620e-01, 3.777120)}, - {1.875000e+01, std::complex(-9.509030e-01, 3.774440)}, - {1.900000e+01, std::complex(-9.513830e-01, 3.774230)}, - {1.925000e+01, std::complex(-9.527410e-01, 3.773420)}, - {1.950000e+01, std::complex(-9.529640e-01, 3.772690)}, - {1.975000e+01, std::complex(-9.535020e-01, 3.772610)}, - {2.000000e+01, std::complex(-9.536580e-01, 3.772820)}, - {2.025000e+01, std::complex(-9.551040e-01, 3.771310)}, - {2.050000e+01, std::complex(-9.553750e-01, 3.770870)}, - {2.075000e+01, std::complex(-9.563520e-01, 3.771250)}, - {2.100000e+01, std::complex(-9.558620e-01, 3.770410)}, - {2.125000e+01, std::complex(-9.571490e-01, 3.770990)}, - {2.150000e+01, std::complex(-9.559790e-01, 3.770810)}, - {2.175000e+01, std::complex(-9.573500e-01, 3.769760)}, - {2.200000e+01, std::complex(-9.577910e-01, 3.769160)}, - {2.225000e+01, std::complex(-9.583200e-01, 3.768870)}, - {2.250000e+01, std::complex(-9.550790e-01, 3.776780)}, - {2.275000e+01, std::complex(-9.571400e-01, 3.768270)}, - {2.300000e+01, std::complex(-9.584600e-01, 3.769160)}, - {2.325000e+01, std::complex(-9.585610e-01, 3.767940)}, - {2.350000e+01, std::complex(-9.566560e-01, 3.770740)}, - {2.375000e+01, std::complex(-9.594490e-01, 3.768340)}, - {2.400000e+01, std::complex(-9.580930e-01, 3.767200)}, - {2.425000e+01, std::complex(-9.595470e-01, 3.767990)}, - {2.450000e+01, std::complex(-9.590460e-01, 3.767710)}, - {2.475000e+01, std::complex(-9.596870e-01, 3.768160)}, - {2.500000e+01, std::complex(-9.570650e-01, 3.767160)}, - {2.625000e+01, std::complex(-9.596560e-01, 3.768510)}, - {2.750000e+01, std::complex(-9.590870e-01, 3.769320)}, - {2.875000e+01, std::complex(-9.561250e-01, 3.775530)}, - {3.000000e+01, std::complex(-9.576080e-01, 3.769620)}, - {3.125000e+01, std::complex(-9.531960e-01, 3.779840)}, - {3.250000e+01, std::complex(-9.538940e-01, 3.777550)}, - {3.375000e+01, std::complex(-9.533630e-01, 3.777040)}, - {3.500000e+01, std::complex(-9.517810e-01, 3.778560)}, - {3.625000e+01, std::complex(-9.496690e-01, 3.781310)}, - {3.750000e+01, std::complex(-9.405070e-01, 3.789920)}, - {3.875000e+01, std::complex(-9.458530e-01, 3.785340)}, - {4.000000e+01, std::complex(-9.397520e-01, 3.794720)}, - {4.125000e+01, std::complex(-9.413720e-01, 3.791260)}, - {4.250000e+01, std::complex(-9.323680e-01, 3.808890)}, - {4.375000e+01, std::complex(-9.377840e-01, 3.794770)}, - {4.500000e+01, std::complex(-9.343410e-01, 3.799410)}, - {4.625000e+01, std::complex(-9.327520e-01, 3.801600)}, - {4.750000e+01, std::complex(-9.314380e-01, 3.802120)}, - {4.875000e+01, std::complex(-9.280190e-01, 3.805100)}, - {5.000000e+01, std::complex(-9.265960e-01, 3.807470)}, - {5.250000e+01, std::complex(-9.224410e-01, 3.813370)}, - {5.500000e+01, std::complex(-9.187830e-01, 3.817970)}, - {5.750000e+01, std::complex(-9.135930e-01, 3.824920)}, - {6.000000e+01, std::complex(-9.076430e-01, 3.832210)}, - {6.250000e+01, std::complex(-9.053880e-01, 3.835040)}, - {6.500000e+01, std::complex(-9.000650e-01, 3.842470)}, - {6.750000e+01, std::complex(-8.978360e-01, 3.844550)}, - {7.000000e+01, std::complex(-8.895000e-01, 3.845750)}, - {7.250000e+01, std::complex(-8.896100e-01, 3.851710)}, - {7.500000e+01, std::complex(-8.863290e-01, 3.858890)}, - {7.750000e+01, std::complex(-8.759940e-01, 3.874300)}, - {8.000000e+01, std::complex(-8.772550e-01, 3.869350)}, - {8.250000e+01, std::complex(-8.745030e-01, 3.874770)}, - {8.500000e+01, std::complex(-8.627990e-01, 3.883950)}, - {8.750000e+01, std::complex(-8.685970e-01, 3.883620)}, - {9.000000e+01, std::complex(-8.640790e-01, 3.887640)}, - {9.250000e+01, std::complex(-8.595460e-01, 3.895260)}, - {9.500000e+01, std::complex(-8.576090e-01, 3.896330)}, - {9.750000e+01, std::complex(-8.461040e-01, 3.904570)}, - {1.000000e+02, std::complex(-8.445310e-01, 3.912870)}, - {1.025000e+02, std::complex(-8.185670e-01, 3.922540)}, - {1.050000e+02, std::complex(-8.422780e-01, 3.916480)}, - {1.075000e+02, std::complex(-8.267250e-01, 3.913120)}, - {1.100000e+02, std::complex(-8.360270e-01, 3.924990)}, - {1.125000e+02, std::complex(-8.187290e-01, 3.933470)}, - {1.150000e+02, std::complex(-8.320920e-01, 3.931650)}, - {1.175000e+02, std::complex(-8.624630e-01, 3.891310)}, - {1.200000e+02, std::complex(-8.220970e-01, 3.944540)}, - {1.225000e+02, std::complex(-9.162170e-01, 3.725880)}, - {1.250000e+02, std::complex(-8.206240e-01, 3.949370)}, - {1.375000e+02, std::complex(-8.069580e-01, 3.966440)}, - {1.500000e+02, std::complex(-7.966930e-01, 3.985160)}, - {1.625000e+02, std::complex(-7.618720e-01, 4.012050)}, - {1.750000e+02, std::complex(-7.783480e-01, 4.022170)}, - {1.875000e+02, std::complex(-7.649770e-01, 4.033710)}, - {2.000000e+02, std::complex(-6.854410e-01, 4.114950)}, - {2.125000e+02, std::complex(-7.408410e-01, 4.063980)}, - {2.250000e+02, std::complex(-7.287670e-01, 4.081410)}, - {2.375000e+02, std::complex(-7.135250e-01, 4.100760)}, - {2.500000e+02, std::complex(-7.168470e-01, 4.103730)}, - {2.625000e+02, std::complex(-7.527330e-01, 4.072580)}, - {2.750000e+02, std::complex(-7.124000e-01, 4.120630)}, - {2.875000e+02, std::complex(-7.035340e-01, 4.135590)}, - {3.000000e+02, std::complex(-6.971670e-01, 4.141230)}, - {3.125000e+02, std::complex(-6.910640e-01, 4.156440)}, - {3.250000e+02, std::complex(-6.778280e-01, 4.178490)}, - {3.375000e+02, std::complex(-6.677270e-01, 4.175210)}, - {3.500000e+02, std::complex(-6.594620e-01, 4.170790)}, - {3.625000e+02, std::complex(-6.689900e-01, 4.193900)}, - {3.750000e+02, std::complex(-6.502250e-01, 4.205840)}, - {3.875000e+02, std::complex(-6.711730e-01, 4.216770)}, - {4.000000e+02, std::complex(-5.948230e-01, 4.204950)}, - {4.125000e+02, std::complex(-6.417410e-01, 4.226540)}, - {4.250000e+02, std::complex(-6.472120e-01, 4.235860)}, - {4.375000e+02, std::complex(-6.412130e-01, 4.247910)}, - {4.500000e+02, std::complex(-6.151300e-01, 4.239300)}, - {4.625000e+02, std::complex(-6.000860e-01, 4.235240)}, - {4.750000e+02, std::complex(-4.474580e-01, 4.420810)}, - {4.875000e+02, std::complex(-6.416880e-01, 4.279580)}, - {5.000000e+02, std::complex(-6.278020e-01, 4.282370)}, - {5.250000e+02, std::complex(-6.065990e-01, 4.302910)}, - {5.500000e+02, std::complex(-6.220060e-01, 4.310840)}, - {5.750000e+02, std::complex(-5.434380e-01, 4.340190)}, - {6.000000e+02, std::complex(-6.171970e-01, 4.329800)}, - {6.250000e+02, std::complex(-5.839680e-01, 4.359710)}, - {6.500000e+02, std::complex(-5.466400e-01, 4.303160)}, - {6.750000e+02, std::complex(-5.846380e-01, 4.370330)}, - {7.000000e+02, std::complex(-5.940230e-01, 4.364990)}, - {7.250000e+02, std::complex(-5.928400e-01, 4.385600)}, - {7.500000e+02, std::complex(-5.856290e-01, 4.384290)}, - {7.750000e+02, std::complex(-5.833640e-01, 4.389110)}, - {8.000000e+02, std::complex(-5.596990e-01, 4.417590)}, - {8.250000e+02, std::complex(-5.590650e-01, 4.434450)}, - {8.500000e+02, std::complex(-6.216490e-01, 4.371060)}, - {8.750000e+02, std::complex(-5.661810e-01, 4.444410)}, - {9.000000e+02, std::complex(-5.675510e-01, 4.443180)}, - {9.250000e+02, std::complex(-5.157180e-01, 4.376070)}, - {9.500000e+02, std::complex(-5.660980e-01, 4.473550)}, - {9.750000e+02, std::complex(-5.434320e-01, 4.493080)}, - {1.000000e+03, std::complex(-5.233450e-01, 4.482900)}, - {1.025000e+03, std::complex(-5.585990e-01, 4.496640)}, - {1.050000e+03, std::complex(-5.561640e-01, 4.504080)}, - {1.075000e+03, std::complex(-5.539260e-01, 4.511270)}, - {1.100000e+03, std::complex(-5.672790e-01, 4.482900)}, - {1.125000e+03, std::complex(-5.788380e-01, 4.482020)}, - {1.150000e+03, std::complex(-5.477980e-01, 4.531840)}, - {1.175000e+03, std::complex(-4.818960e-01, 4.579170)}, - {1.200000e+03, std::complex(-4.779800e-01, 4.461080)}, - {1.225000e+03, std::complex(-4.830520e-01, 4.552330)}, - {1.250000e+03, std::complex(-5.402060e-01, 4.557730)}, - {1.375000e+03, std::complex(-5.028850e-01, 4.594370)}, - {1.500000e+03, std::complex(-5.251460e-01, 4.614700)}, - {1.625000e+03, std::complex(-5.561430e-01, 4.654850)}, - {1.750000e+03, std::complex(-5.137850e-01, 4.663500)}, - {1.875000e+03, std::complex(-4.949940e-01, 4.711330)}, - {2.000000e+03, std::complex(-4.878720e-01, 4.742990)}, - {2.125000e+03, std::complex(-6.820930e-01, 4.567030)}, - {2.250000e+03, std::complex(-4.981180e-01, 4.744200)}, - {2.375000e+03, std::complex(-4.952330e-01, 4.761730)}, - {2.500000e+03, std::complex(-4.926530e-01, 4.778410)}, - {2.625000e+03, std::complex(-4.903560e-01, 4.794340)}, - {2.750000e+03, std::complex(-4.882910e-01, 4.809550)}, - {2.875000e+03, std::complex(-4.864500e-01, 4.824130)}, - {3.000000e+03, std::complex(-4.848020e-01, 4.838120)}, - {3.125000e+03, std::complex(-4.833320e-01, 4.851570)}, - {3.250000e+03, std::complex(-4.820140e-01, 4.864520)}, - {3.375000e+03, std::complex(-4.808430e-01, 4.877010)}, - {3.500000e+03, std::complex(-4.797980e-01, 4.889060)}, - {3.625000e+03, std::complex(-4.788770e-01, 4.900710)}, - {3.750000e+03, std::complex(-4.780630e-01, 4.911980)}, - {3.875000e+03, std::complex(-4.773460e-01, 4.922910)}, - {4.000000e+03, std::complex(-4.767180e-01, 4.933500)}, - {4.125000e+03, std::complex(-4.761750e-01, 4.943780)}, - {4.250000e+03, std::complex(-4.757100e-01, 4.953760)}, - {4.375000e+03, std::complex(-4.753040e-01, 4.963460)}, - {4.500000e+03, std::complex(-4.749280e-01, 4.972830)}, - {4.625000e+03, std::complex(-4.747220e-01, 4.982120)}, - {4.750000e+03, std::complex(-4.745060e-01, 4.991080)}, - {4.875000e+03, std::complex(-4.743460e-01, 4.999830)}, - {5.000000e+03, std::complex(-4.742420e-01, 5.008360)}, - {5.250000e+03, std::complex(-4.741500e-01, 5.024820)}, - {5.500000e+03, std::complex(-4.742210e-01, 5.040540)}, - {5.750000e+03, std::complex(-4.744350e-01, 5.055600)}, - {6.000000e+03, std::complex(-4.747660e-01, 5.070030)}, - {6.250000e+03, std::complex(-4.752050e-01, 5.083900)}, - {6.500000e+03, std::complex(-4.757360e-01, 5.097240)}, - {6.750000e+03, std::complex(-4.763560e-01, 5.110090)}, - {7.000000e+03, std::complex(-4.770560e-01, 5.122500)}, - {7.250000e+03, std::complex(-4.778150e-01, 5.134490)}, - {7.500000e+03, std::complex(-4.786300e-01, 5.146070)}, - {7.750000e+03, std::complex(-4.795060e-01, 5.157300)}, - {8.000000e+03, std::complex(-4.804330e-01, 5.168170)}, - {8.250000e+03, std::complex(-4.813910e-01, 5.178730)}, - {8.500000e+03, std::complex(-4.823970e-01, 5.188980)}, - {8.750000e+03, std::complex(-4.834230e-01, 5.198940)}, - {9.000000e+03, std::complex(-4.844930e-01, 5.208620)}, - {9.250000e+03, std::complex(-4.855350e-01, 5.218100)}, - {9.500000e+03, std::complex(-4.866970e-01, 5.227250)}, - {9.750000e+03, std::complex(-4.878450e-01, 5.236200)}, - {1.000000e+04, std::complex(-4.890060e-01, 5.244930)}, - {1.025000e+04, std::complex(-4.901930e-01, 5.253470)}, - {1.050000e+04, std::complex(-4.913890e-01, 5.261780)}, - {1.075000e+04, std::complex(-4.925970e-01, 5.269930)}, - {1.100000e+04, std::complex(-4.938190e-01, 5.277880)}, - {1.125000e+04, std::complex(-4.950610e-01, 5.285640)}, - {1.150000e+04, std::complex(-4.963020e-01, 5.293260)}, - {1.175000e+04, std::complex(-4.975540e-01, 5.300720)}, - {1.200000e+04, std::complex(-4.988200e-01, 5.308020)}, - {1.225000e+04, std::complex(-5.000850e-01, 5.315170)}, - {1.250000e+04, std::complex(-5.013610e-01, 5.322180)}, - {1.375000e+04, std::complex(-5.078200e-01, 5.355320)}, - {1.500000e+04, std::complex(-5.143100e-01, 5.385630)}, - {1.625000e+04, std::complex(-5.208080e-01, 5.413580)}, - {1.750000e+04, std::complex(-5.258070e-01, 5.440400)}, - {1.875000e+04, std::complex(-5.337290e-01, 5.463660)}, - {2.000000e+04, std::complex(-5.400840e-01, 5.486300)}, - {2.125000e+04, std::complex(-5.446100e-01, 5.508630)}, - {2.250000e+04, std::complex(-5.485740e-01, 5.525210)}, - {2.375000e+04, std::complex(-5.562090e-01, 5.543070)}, - {2.500000e+04, std::complex(-5.248800e-01, 5.588220)}, - {2.625000e+04, std::complex(-5.674120e-01, 5.585320)}, - {2.750000e+04, std::complex(-5.731940e-01, 5.601780)}, - {2.875000e+04, std::complex(-5.789180e-01, 5.617530)}, - {3.000000e+04, std::complex(-5.845250e-01, 5.632620)}, - {3.125000e+04, std::complex(-5.900550e-01, 5.647070)}, - {3.250000e+04, std::complex(-5.954660e-01, 5.661010)}, - {3.375000e+04, std::complex(-6.008260e-01, 5.674400)}, - {3.500000e+04, std::complex(-6.060870e-01, 5.687340)}, - {3.625000e+04, std::complex(-6.112750e-01, 5.699800)}, - {3.750000e+04, std::complex(-6.164020e-01, 5.711880)}, - {3.875000e+04, std::complex(-6.214450e-01, 5.723540)}, - {4.000000e+04, std::complex(-6.263970e-01, 5.734860)}, - {4.125000e+04, std::complex(-6.312700e-01, 5.745830)}, - {4.250000e+04, std::complex(-6.360560e-01, 5.756480)}, - {4.375000e+04, std::complex(-6.408450e-01, 5.766830)}, - {4.500000e+04, std::complex(-6.457050e-01, 5.776760)}, - {4.625000e+04, std::complex(-6.503670e-01, 5.786530)}, - {4.750000e+04, std::complex(-6.547850e-01, 5.796100)}, - {4.875000e+04, std::complex(-6.594220e-01, 5.805320)}, - {5.000000e+04, std::complex(-6.637540e-01, 5.814450)}, - {5.250000e+04, std::complex(-6.724940e-01, 5.831850)}, - {5.500000e+04, std::complex(-6.806730e-01, 5.848680)}, - {5.750000e+04, std::complex(-6.889350e-01, 5.864560)}, - {6.000000e+04, std::complex(-6.973210e-01, 5.879680)}, - {6.250000e+04, std::complex(-7.053950e-01, 5.894190)}, - {6.500000e+04, std::complex(-7.130550e-01, 5.908250)}, - {6.750000e+04, std::complex(-7.202690e-01, 5.921980)}, - {7.000000e+04, std::complex(-7.279810e-01, 5.934910)}, - {7.250000e+04, std::complex(-7.349080e-01, 5.947620)}, - {7.500000e+04, std::complex(-7.421590e-01, 5.959740)}, - {7.750000e+04, std::complex(-7.489310e-01, 5.971620)}, - {8.000000e+04, std::complex(-7.558540e-01, 5.982990)}, - {8.250000e+04, std::complex(-7.630040e-01, 5.993840)}, - {8.500000e+04, std::complex(-7.692540e-01, 6.004730)}, - {8.750000e+04, std::complex(-7.760400e-01, 6.015000)}, - {9.000000e+04, std::complex(-7.819260e-01, 6.025360)}, - {9.250000e+04, std::complex(-7.883920e-01, 6.035080)}, - {9.500000e+04, std::complex(-7.945700e-01, 6.044670)}, - {9.750000e+04, std::complex(-8.002950e-01, 6.054170)}, - {1.000000e+05, std::complex(-8.060720e-01, 6.063380)}, - {1.025000e+05, std::complex(-8.123860e-01, 6.072040)}, - {1.050000e+05, std::complex(-8.184380e-01, 6.080510)}, - {1.075000e+05, std::complex(-8.236750e-01, 6.089250)}, - {1.100000e+05, std::complex(-8.293480e-01, 6.097460)}, - {1.125000e+05, std::complex(-8.347930e-01, 6.105660)}, - {1.150000e+05, std::complex(-8.400500e-01, 6.113680)}, - {1.175000e+05, std::complex(-8.458380e-01, 6.121140)}, - {1.200000e+05, std::complex(-8.505530e-01, 6.129080)}, - {1.225000e+05, std::complex(-8.564450e-01, 6.136180)}, - {1.250000e+05, std::complex(-8.614150e-01, 6.143510)}, - {1.375000e+05, std::complex(-8.858380e-01, 6.178060)}, - {1.500000e+05, std::complex(-9.091280e-01, 6.209430)}, - {1.625000e+05, std::complex(-9.310480e-01, 6.238410)}, - {1.750000e+05, std::complex(-9.516100e-01, 6.265350)}, - {1.875000e+05, std::complex(-9.717480e-01, 6.290160)}, - {2.000000e+05, std::complex(-9.903380e-01, 6.313530)}, - {2.125000e+05, std::complex(-1.008530, 6.335540)}, - {2.250000e+05, std::complex(-1.025850, 6.356120)}, - {2.375000e+05, std::complex(-1.042680, 6.375730)}, - {2.500000e+05, std::complex(-1.040430, 6.358410)} - }; - - return data; -} - -std::complex linear_interpolation( - double x, const std::map >& data) -{ - auto right = data.upper_bound(x); - - if (right == data.begin()) { - ++right; - } else if (right == data.end()) { - --right; - } - - auto left = right; - --left; - - const double x_left = (x - right->first) / (left->first - right->first); - const double x_right = (x - left->first) / (right->first - left->first); - - return left->second * x_left + right->second * x_right; -} - -std::complex quadratic_interpolation( - double x, const std::map >& data) -{ - auto right = data.upper_bound(x); - auto begin = data.begin(); - - if (right == begin) { - ++right; - ++right; - } else if (right == ++begin) { - ++right; - } else if (right == data.end()) { - --right; - } - - auto center = right; - --center; - auto left = center; - --left; - - const double x_left = (x - center->first) * (x - right->first) - / ((left->first - center->first) * (left->first - right->first)); - const double x_center = (x - left->first) * (x - right->first) - / ((center->first - left->first) * (center->first - right->first)); - const double x_right = (x - left->first) * (x - center->first) - / ((right->first - left->first) * (right->first - center->first)); - - return left->second * x_left + center->second * x_center - + right->second * x_right; -} - -} // anonymous namespace - -std::complex scaling_function(double tau) -{ - std::complex result; - - if (tau > 1) { - result = -0.25 * sqr(std::log((1.0 + std::sqrt(1.0 - 1.0 / tau)) / - (1.0 - std::sqrt(1.0 - 1.0 / tau))) - std::complex(0,1) * Pi); - } else if (tau == 1.0) { - result = 0.25 * sqr(Pi); - } else { - result = sqr(std::asin(std::sqrt(tau))); - } - - return result; -} - -std::complex AS0(double tau) -{ - return -(tau - scaling_function(tau)) / sqr(tau); -} - -std::complex AS12(double tau) -{ - return 2.0 * (tau + (tau - 1.0) * scaling_function(tau)) / sqr(tau); -} - -std::complex AS1(double tau) -{ - return -(2.0 * sqr(tau) + 3.0 * tau + 3.0 * (2.0 * tau - 1.0) - * scaling_function(tau)) / sqr(tau); -} - -std::complex AP12(double tau) -{ - return scaling_function(tau) / tau; -} - -std::complex scalar_diphoton_fermion_loop( - double m_decay, double m_loop) -{ - const double tau = 0.25 * sqr(m_decay) / sqr(m_loop); - const double tau_min = 75.0; - - const auto& data = get_scalar_fermion_loop_data(); - - std::complex result; - if (tau < tau_min) { - const bool do_linear_interp = false; - if (do_linear_interp) { - result = linear_interpolation(tau, data); - } else { - result = quadratic_interpolation(tau, data); - } - } else { - // analytic expression in the m_loop -> 0 limit - const std::complex limit = - -(sqr(std::log(4.0 * tau)) - sqr(Pi)) / 18.0 - 2.0 * std::log(4.0 * tau) / 3.0 - + 2.0 * std::log(tau) + 22.0 / std::log(4.0 * tau) + std::complex(0,1) - * Pi * (std::log(4.0 * tau) / 3.0 + 2.) / 3.0; - - const std::complex min_value = (data.lower_bound(tau_min))->second; - - const std::complex constant = min_value - + (sqr(std::log(4.0 * tau_min)) - sqr(Pi)) / 18.0 + 2.0 * std::log(4.0 * tau_min) - / 3.0 - 2.0 * std::log(tau_min) - 22.0 / std::log(4.0 * tau_min) - - std::complex(0,1) * Pi * (std::log(4.0 * tau_min) / 3.0 + 2.) - / 3.0; - - result = limit + constant; - } - - return result; -} - -std::complex pseudoscalar_diphoton_fermion_loop( - double m_decay, double m_loop) -{ - const double tau = 0.25 * sqr(m_decay) / sqr(m_loop); - const double tau_min = 75.0; - - const std::map > data - = get_pseudoscalar_fermion_loop_data(); - - std::complex result; - if (tau < tau_min) { - const bool do_linear_interp = false; - if (do_linear_interp) { - result = linear_interpolation(tau, data); - } else { - result = quadratic_interpolation(tau, data); - } - } else { - // analytic expression in the m_loop -> 0 limit - const std::complex limit = - -(sqr(std::log(4.0 * tau)) - sqr(Pi)) / 18.0 - 2.0 * std::log(4.0 * tau) / 3.0 - + 2.0 * std::log(tau) + 21.0 / std::log(4.0 * tau) + std::complex(0,1) - * Pi * (std::log(4.0 * tau) / 3.0 + 2.) / 3.0; - - const std::complex min_value = (data.lower_bound(tau_min))->second; - - const std::complex constant = min_value - + (sqr(std::log(4.0 * tau_min)) - sqr(Pi)) / 18.0 + 2.0 * std::log(4.0 * tau_min) - / 3.0 - 2.0 * std::log(tau_min) - 21.0 / std::log(4.0 * tau_min) - - std::complex(0,1) * Pi * (std::log(4.0 * tau_min) / 3.0 + 2.) - / 3.0; - - result = limit + constant; - } - - return result; -} - -} // namespace effective_couplings - -} // namespace flexiblesusy diff --git a/src/effective_couplings.hpp b/src/effective_couplings.hpp deleted file mode 100644 index d3f43c3e67..0000000000 --- a/src/effective_couplings.hpp +++ /dev/null @@ -1,47 +0,0 @@ -// ==================================================================== -// This file is part of FlexibleSUSY. -// -// FlexibleSUSY 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. -// -// FlexibleSUSY 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 FlexibleSUSY. If not, see -// . -// ==================================================================== - -#ifndef EFFECTIVE_COUPLINGS_H -#define EFFECTIVE_COUPLINGS_H - -#include - -namespace flexiblesusy { - -namespace effective_couplings { - -// loop functions of hep-ph/9504378, Eq. (53) -std::complex scaling_function(double tau); -std::complex AS0(double tau); -std::complex AS12(double tau); -std::complex AS1(double tau); -std::complex AP12(double tau); - -/// QCD corrections to the diphoton decay width -/// for scalars and pseudoscalars, at the scale -/// m_decay / 2 -std::complex scalar_diphoton_fermion_loop( - double m_decay, double m_loop); -std::complex pseudoscalar_diphoton_fermion_loop( - double m_decay, double m_loop); - -} // namespace effective_couplings - -} // namespace flexiblesusy - -#endif diff --git a/src/module.mk b/src/module.mk index f6fb6ee865..447683fe50 100644 --- a/src/module.mk +++ b/src/module.mk @@ -20,7 +20,6 @@ LIBFLEXI_SRC := \ $(DIR)/decays/flexibledecay_settings.cpp \ $(DIR)/decays/one_loop_decay_diagrams.cpp \ $(DIR)/dilog.cpp \ - $(DIR)/effective_couplings.cpp \ $(DIR)/global_thread_pool.cpp \ $(DIR)/gm2calc_interface.cpp \ $(DIR)/gsl_multimin_fminimizer.cpp \ @@ -83,7 +82,6 @@ LIBFLEXI_HDR := \ $(DIR)/decays/one_loop_decay_diagrams.hpp \ $(DIR)/derivative.hpp \ $(DIR)/dilog.hpp \ - $(DIR)/effective_couplings.hpp \ $(DIR)/eigen_utils.hpp \ $(DIR)/eigen_tensor.hpp \ $(DIR)/error.hpp \ diff --git a/templates/effective_couplings.cpp.in b/templates/effective_couplings.cpp.in deleted file mode 100644 index 88f17a4530..0000000000 --- a/templates/effective_couplings.cpp.in +++ /dev/null @@ -1,150 +0,0 @@ -// ==================================================================== -// This file is part of FlexibleSUSY. -// -// FlexibleSUSY 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. -// -// FlexibleSUSY 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 FlexibleSUSY. If not, see -// . -// ==================================================================== - - -#include "@ModelName@_effective_couplings.hpp" - -#include "effective_couplings.hpp" -#include "wrappers.hpp" - -namespace flexiblesusy { - -using namespace effective_couplings; - -#define INPUTPARAMETER(parameter) model.get_input().parameter -#define MODELPARAMETER(parameter) model.get_##parameter() -#define DERIVEDPARAMETER(parameter) model.##parameter() -#define PHASE(parameter) model.get_##parameter() -#define PHYSICAL(parameter) model.get_physical().parameter - -@ModelName@_effective_couplings::@ModelName@_effective_couplings( - const @ModelName@_mass_eigenstates& model_, - const softsusy::QedQcd& qedqcd_, - const Physical_input& input_) - : model(model_), qedqcd(qedqcd_), physical_input(input_) - , rg_improve(true), include_qcd_corrections(true) -@mixingMatricesInit@ -@loopCouplingsInit@ -{ -} - -void @ModelName@_effective_couplings::calculate_effective_couplings() -{ - const standard_model::Standard_model sm(initialise_SM()); - -@calculateLoopCouplings@ -} - -void @ModelName@_effective_couplings::set_model(const @ModelName@_mass_eigenstates& model_) -{ - model = model_; - copy_mixing_matrices_from_model(); -} - -void @ModelName@_effective_couplings::copy_mixing_matrices_from_model() -{ -@copyMixingMatrices@ -} - -standard_model::Standard_model @ModelName@_effective_couplings::initialise_SM() const -{ - standard_model::Standard_model sm; - - sm.set_loops(2); - sm.set_thresholds(2); - sm.set_physical_input(physical_input); - - sm.initialise_from_input(qedqcd); - - return sm; -} - -void @ModelName@_effective_couplings::run_SM_strong_coupling_to(standard_model::Standard_model sm, double m) -{ - sm.run_to(m); - -@setSMStrongCoupling@ -} - -std::complex @ModelName@_effective_couplings::scalar_scalar_qcd_factor(double m_decay, double m_loop) const -{ - std::complex result(1.0, 0.0); - - if (include_qcd_corrections) { -@calculateScalarScalarLoopQCDFactor@ - } - - return result; -} - -std::complex @ModelName@_effective_couplings::scalar_fermion_qcd_factor(double m_decay, double m_loop) const -{ - std::complex result(1.0, 0.0); - - if (include_qcd_corrections) { -@calculateScalarFermionLoopQCDFactor@ - } - - return result; -} - -std::complex @ModelName@_effective_couplings::pseudoscalar_fermion_qcd_factor(double m_decay, double m_loop) const -{ - std::complex result(1.0, 0.0); - - if (include_qcd_corrections) { -@calculatePseudoscalarFermionLoopQCDFactor@ - } - - return result; -} - -double @ModelName@_effective_couplings::number_of_active_flavours(double m) const -{ - if (m < qedqcd.displayMbMb()) { - return 4.0; - } else if (m < qedqcd.displayPoleMt()) { - return 5.0; - } else { - return 6.0; - } -} - -double @ModelName@_effective_couplings::scalar_scaling_factor(double m) const -{ - const double Nf = number_of_active_flavours(m); - const double mtpole = qedqcd.displayPoleMt(); - const double l = Log(Sqr(m) / Sqr(mtpole)); - -@calculateScalarQCDScalingFactor@ - return Sqrt(1.0 + nlo_qcd + nnlo_qcd + nnnlo_qcd); -} - -double @ModelName@_effective_couplings::pseudoscalar_scaling_factor(double m) const -{ - const double Nf = number_of_active_flavours(m); - const double mtpole = qedqcd.displayPoleMt(); - const double l = Log(Sqr(m) / Sqr(mtpole)); - -@calculatePseudoscalarQCDScalingFactor@ - return Sqrt(1.0 + nlo_qcd + nnlo_qcd + nnnlo_qcd); -} - -@partialWidthGetters@ -@loopCouplingsFunctions@ -} // namespace flexiblesusy diff --git a/templates/effective_couplings.hpp.in b/templates/effective_couplings.hpp.in deleted file mode 100644 index 33c820de64..0000000000 --- a/templates/effective_couplings.hpp.in +++ /dev/null @@ -1,86 +0,0 @@ -// ==================================================================== -// This file is part of FlexibleSUSY. -// -// FlexibleSUSY 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. -// -// FlexibleSUSY 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 FlexibleSUSY. If not, see -// . -// ==================================================================== - - -#ifndef @ModelName@_EFFECTIVE_COUPLINGS_H -#define @ModelName@_EFFECTIVE_COUPLINGS_H - -#include "@ModelName@_mass_eigenstates.hpp" -#include "lowe.h" -#include "physical_input.hpp" -#include "standard_model.hpp" - -#include -#include - -namespace flexiblesusy { - -namespace standard_model { -class Standard_model; -} - -class @ModelName@_effective_couplings { -public: - @ModelName@_effective_couplings(const @ModelName@_mass_eigenstates&, - const softsusy::QedQcd&, - const Physical_input&); - - void do_run_couplings(bool flag) { rg_improve = flag; } - bool do_run_couplings() const { return rg_improve; } - void do_include_qcd_corrections(bool flag) { include_qcd_corrections = flag; } - bool do_include_qcd_corrections() const { return include_qcd_corrections; } - void set_physical_inputs(const Physical_input& inputs_) { physical_input = inputs_; } - void set_low_energy_data(const softsusy::QedQcd& qedqcd_) { qedqcd = qedqcd_; } - void set_model(const @ModelName@_mass_eigenstates& model_); - -@partialWidthGetterPrototypes@ -@loopCouplingsGetters@ - void calculate_effective_couplings(); - -@loopCouplingsPrototypes@ -private: - @ModelName@_mass_eigenstates model; - softsusy::QedQcd qedqcd; - Physical_input physical_input; - bool rg_improve; - bool include_qcd_corrections; - - void copy_mixing_matrices_from_model(); - - standard_model::Standard_model initialise_SM() const; - void run_SM_strong_coupling_to(standard_model::Standard_model, double m); - - // higher order corrections to the amplitudes for - // effective coupling to photons - std::complex scalar_scalar_qcd_factor(double, double) const; - std::complex scalar_fermion_qcd_factor(double, double) const; - std::complex pseudoscalar_fermion_qcd_factor(double, double) const; - - // higher order corrections to the leading order - // effective couplings to gluons - double number_of_active_flavours(double) const; - double scalar_scaling_factor(double) const; - double pseudoscalar_scaling_factor(double) const; - -@mixingMatricesDefs@ -@loopCouplingsDefs@ -}; - -} // namespace flexiblesusy - -#endif diff --git a/templates/module.mk b/templates/module.mk index 85fd55b9aa..73a13618c7 100644 --- a/templates/module.mk +++ b/templates/module.mk @@ -28,8 +28,6 @@ BASE_TEMPLATES := \ $(DIR)/convergence_tester.hpp.in \ $(DIR)/ewsb_solver.hpp.in \ $(DIR)/ewsb_solver_interface.hpp.in \ - $(DIR)/effective_couplings.hpp.in \ - $(DIR)/effective_couplings.cpp.in \ $(DIR)/high_scale_constraint.hpp.in \ $(DIR)/info.hpp.in \ $(DIR)/info.cpp.in \ diff --git a/templates/module.mk.in b/templates/module.mk.in index e3269e4610..c09a12daa8 100644 --- a/templates/module.mk.in +++ b/templates/module.mk.in @@ -60,7 +60,6 @@ LIB@CLASSNAME@_SRC := \ $(DIR)/@CLASSNAME@_f_to_f_conversion.cpp \ $(DIR)/@CLASSNAME@_l_to_lgamma.cpp \ $(DIR)/@CLASSNAME@_b_to_s_gamma.cpp \ - $(DIR)/@CLASSNAME@_effective_couplings.cpp \ $(DIR)/@CLASSNAME@_info.cpp \ $(DIR)/@CLASSNAME@_input_parameters.cpp \ $(DIR)/@CLASSNAME@_mass_eigenstates.cpp \ @@ -97,7 +96,6 @@ LIB@CLASSNAME@_HDR := \ $(DIR)/@CLASSNAME@_f_to_f_conversion.hpp \ $(DIR)/@CLASSNAME@_l_to_lgamma.hpp \ $(DIR)/@CLASSNAME@_b_to_s_gamma.hpp \ - $(DIR)/@CLASSNAME@_effective_couplings.hpp \ $(DIR)/@CLASSNAME@_ewsb_solver.hpp \ $(DIR)/@CLASSNAME@_ewsb_solver_interface.hpp \ $(DIR)/@CLASSNAME@_high_scale_constraint.hpp \ diff --git a/templates/observables.cpp.in b/templates/observables.cpp.in index 7ce42c9c40..636ca19a8d 100644 --- a/templates/observables.cpp.in +++ b/templates/observables.cpp.in @@ -24,7 +24,6 @@ #include "@ModelName@_l_to_lgamma.hpp" #include "@ModelName@_b_to_s_gamma.hpp" #include "@ModelName@_f_to_f_conversion.hpp" -#include "@ModelName@_effective_couplings.hpp" #include "config.h" #include "eigen_utils.hpp" #include "numerics2.hpp" @@ -47,10 +46,6 @@ #define LToLGamma1(pIn,idxIn,pOut,idxOut,spec) pIn ## _to_ ## pOut ## _ ## spec #define FToFConversion1(pIn,idxIn,pOut,idxOut,nuclei,qedqcd) pIn ## _to_ ## pOut ## _in_ ## nuclei #define BSGAMMA b_to_s_gamma -#define EFFCPHIGGSPHOTONPHOTON eff_cp_higgs_photon_photon -#define EFFCPHIGGSGLUONGLUON eff_cp_higgs_gluon_gluon -#define EFFCPPSEUDOSCALARPHOTONPHOTON eff_cp_pseudoscalar_photon_photon -#define EFFCPPSEUDOSCALARGLUONGLUON eff_cp_pseudoscalar_gluon_gluon #define ALPHA_S_MZ qedqcd.displayAlpha(softsusy::ALPHAS) #define MWPole qedqcd.displayPoleMW() diff --git a/test/module.mk b/test/module.mk index e678ca0e08..7a958cddc3 100644 --- a/test/module.mk +++ b/test/module.mk @@ -53,7 +53,6 @@ TEST_SRC := \ $(DIR)/test_ckm.cpp \ $(DIR)/test_logger.cpp \ $(DIR)/test_derivative.cpp \ - $(DIR)/test_effective_couplings.cpp \ $(DIR)/test_eigen_utils.cpp \ $(DIR)/test_ewsb_solver.cpp \ $(DIR)/test_error.cpp \ @@ -439,11 +438,6 @@ TEST_SRC += \ $(DIR)/test_CMSSM_NMSSM_linking.cpp endif -ifeq ($(WITH_CMSSM),yes) -TEST_SRC += \ - $(DIR)/test_CMSSM_effective_couplings.cpp -endif - ifeq ($(WITH_CMSSMNoFV),yes) TEST_SH += \ $(DIR)/test_CMSSMNoFV_profile.sh @@ -538,7 +532,6 @@ endif ifeq ($(WITH_SM),yes) TEST_SRC += \ $(DIR)/test_SM_beta_functions.cpp \ - $(DIR)/test_SM_effective_couplings.cpp \ $(DIR)/test_SM_gmm2.cpp \ $(DIR)/test_SM_low_scale_constraint.cpp \ $(DIR)/test_SM_mass_eigenstates_interface.cpp \ @@ -1116,8 +1109,6 @@ $(DIR)/test_CMSSMCKM_tree_level_spectrum.x: \ $(DIR)/test_CMSSMCKM_spectrum.sh: $(RUN_SOFTPOINT_EXE) -$(DIR)/test_CMSSM_effective_couplings.x: $(LIBCMSSM) - $(DIR)/test_CMSSM_weinberg_angle.x: $(LIBCMSSM) $(DIR)/test_CMSSM_weinberg_angle_meta.x: $(LIBCMSSM) @@ -1181,8 +1172,6 @@ $(DIR)/test_CMSSMNoFV_low_scale_constraint.x: $(LIBCMSSM) $(LIBCMSSMNoFV) $(DIR)/test_SM_beta_functions.x: $(LIBSM) -$(DIR)/test_SM_effective_couplings.x: $(LIBSM) - $(DIR)/test_SM_gmm2.x: $(LIBSM) $(DIR)/test_SM_higgs_loop_corrections.x: $(LIBSM) diff --git a/test/test_CMSSM_effective_couplings.cpp b/test/test_CMSSM_effective_couplings.cpp deleted file mode 100644 index 4e1a5379de..0000000000 --- a/test/test_CMSSM_effective_couplings.cpp +++ /dev/null @@ -1,1143 +0,0 @@ - -#define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE test_CMSSM_effective_couplings - -#include - -#include "effective_couplings.hpp" -#include "CMSSM_mass_eigenstates.hpp" -#include "CMSSM_effective_couplings.hpp" - -#include "effective_couplings.hpp" -#include "ew_input.hpp" -#include "linalg2.hpp" -#include "wrappers.hpp" - -using namespace flexiblesusy; -using namespace effective_couplings; - -class MSSM_loop_decays { -public: - MSSM_loop_decays(const CMSSM_mass_eigenstates& model_, - const softsusy::QedQcd& qedqcd_, - const Physical_input& physical_inputs_) - : model(model_) - , qedqcd(qedqcd_) - , physical_inputs(physical_inputs_) - {} - - void do_rg_improve(bool flag) { rg_improve = flag; } - void set_model(const CMSSM_mass_eigenstates& model_) { model = model_; } - - std::complex get_eff_CphhVPVP(int); - std::complex get_eff_CphhVGVG(int); - std::complex get_eff_CpAhVPVP(); - std::complex get_eff_CpAhVGVG(); - -private: - CMSSM_mass_eigenstates model{}; - softsusy::QedQcd qedqcd{}; - Physical_input physical_inputs{}; - bool rg_improve{true}; - - double get_higgs_mixing_angle() const; - void run_SM_strong_coupling_to(double); - - Eigen::Matrix,2,2> get_up_type_squark_couplings( - int, int) const; - Eigen::Matrix,2,2> get_down_type_squark_couplings( - int, int) const; - Eigen::Matrix,2,2> get_slepton_couplings( - int, int) const; - - std::complex get_hhVPVP_VWm_contribution(int) const; - std::complex get_hhVPVP_Hpm_contribution(int) const; - std::complex get_hhVPVP_Cha_contribution(int) const; - std::complex get_hhVPVP_Su_contribution(int, int) const; - std::complex get_hhVPVP_Sd_contribution(int, int) const; - std::complex get_hhVPVP_Se_contribution(int, int) const; - std::complex get_hhVPVP_Fu_contribution(int, int) const; - std::complex get_hhVPVP_Fd_contribution(int, int) const; - std::complex get_hhVPVP_Fe_contribution(int, int) const; - std::complex get_hhVGVG_Su_contribution(int, int) const; - std::complex get_hhVGVG_Sd_contribution(int, int) const; - std::complex get_hhVGVG_Fu_contribution(int, int) const; - std::complex get_hhVGVG_Fd_contribution(int, int) const; - std::complex get_AhVPVP_Cha_contribution() const; - std::complex get_AhVPVP_Fu_contribution(int) const; - std::complex get_AhVPVP_Fd_contribution(int) const; - std::complex get_AhVPVP_Fe_contribution(int) const; - std::complex get_AhVGVG_Fu_contribution(int) const; - std::complex get_AhVGVG_Fd_contribution(int) const; -}; - -double MSSM_loop_decays::get_higgs_mixing_angle() const -{ - const auto ZH = model.get_physical().ZH; - return ArcTan(ZH(1,1) / ZH(1,0)); -} - -void MSSM_loop_decays::run_SM_strong_coupling_to(double scale) -{ - standard_model::Standard_model sm; - - sm.set_loops(2); - sm.set_thresholds(2); - sm.set_physical_input(physical_inputs); - - sm.initialise_from_input(qedqcd); - - sm.run_to(scale); - - model.set_g3(sm.get_g3()); -} - -Eigen::Matrix,2,2> MSSM_loop_decays::get_up_type_squark_couplings( - int idx, int gen) const -{ - const double Qf = 2. / 3.; - const double I3Lf = 0.5; - const double gY = Sqrt(3. / 5.) * model.get_g1(); - const double g2 = model.get_g2(); - const double gbar = Sqrt(Sqr(g2) + Sqr(gY)); - const double sw = gY / gbar; - const double vd = model.get_vd(); - const double vu = model.get_vu(); - const double v = Sqrt(Sqr(vd) + Sqr(vu)); - const double beta = ArcTan(vu / vd); - - const double vf = vu; - const double yf = model.get_Yu(gen, gen); - const double Tf = model.get_TYu(gen, gen); - const double mu = model.get_Mu(); - const double mf = yf * vf / Sqrt(2.); - const double mz = 0.5 * gbar * v; - const double alpha = get_higgs_mixing_angle(); - - Eigen::Matrix,2,2> Cff; - if (idx == 0) { - const double s1q = Cos(alpha) / Sin(beta); - const double s2q = Sin(alpha) / Sin(beta); - Cff(0,0) = -(I3Lf - Qf* Sqr(sw)) * Sqr(mz) * Sin(beta + alpha) - + Sqr(mf) * s1q; - Cff(0,1) = 0.5 * vf * (Tf * s1q + yf * mu * s2q) / Sqrt(2.); - Cff(1,0) = Cff(0,1); - Cff(1,1) = -Qf * Sqr(sw) * Sqr(mz) * Sin(beta + alpha) - + Sqr(mf) * s1q; - } else { - const double r1q = Sin(alpha) / Sin(beta); - const double r2q = -Cos(alpha) / Sin(beta); - Cff(0,0) = (I3Lf - Qf * Sqr(sw)) * Sqr(mz) * Cos(beta + alpha) - + Sqr(mf) * r1q; - Cff(0,1) = 0.5 * vf * (Tf * r1q + yf * mu * r2q) / Sqrt(2.); - Cff(1,0) = Cff(0,1); - Cff(1,1) = Qf * Sqr(sw) * Sqr(mz) * Cos(beta + alpha) - + Sqr(mf) * r1q; - } - - return Cff; -} - -Eigen::Matrix,2,2> MSSM_loop_decays::get_down_type_squark_couplings( - int idx, int gen) const -{ - const double Qf = -1. / 3.; - const double I3Lf = -0.5; - const double gY = Sqrt(3. / 5.) * model.get_g1(); - const double g2 = model.get_g2(); - const double gbar = Sqrt(Sqr(g2) + Sqr(gY)); - const double sw = gY / gbar; - const double vd = model.get_vd(); - const double vu = model.get_vu(); - const double v = Sqrt(Sqr(vd) + Sqr(vu)); - const double beta = ArcTan(vu / vd); - - const double vf = vd; - const double yf = model.get_Yd(gen, gen); - const double Tf = model.get_TYd(gen, gen); - const double mu = model.get_Mu(); - const double mf = yf * vf / Sqrt(2.); - const double mz = 0.5 * gbar * v; - const double alpha = get_higgs_mixing_angle(); - - Eigen::Matrix,2,2> Cff; - if (idx == 0) { - const double s1q = -Sin(alpha) / Cos(beta); - const double s2q = -Cos(alpha) / Cos(beta); - Cff(0,0) = -(I3Lf - Qf * Sqr(sw)) * Sqr(mz) * Sin(beta + alpha) - + Sqr(mf) * s1q; - Cff(0,1) = 0.5 * vf * (Tf * s1q + yf * mu * s2q) / Sqrt(2.); - Cff(1,0) = Cff(0,1); - Cff(1,1) = -Qf * Sqr(sw) * Sqr(mz) * Sin(beta + alpha) - + Sqr(mf) * s1q; - } else { - const double r1q = Cos(alpha) / Cos(beta); - const double r2q = -Sin(alpha) / Cos(beta); - Cff(0,0) = (I3Lf - Qf * Sqr(sw)) * Sqr(mz) * Cos(beta + alpha) - + Sqr(mf) * r1q; - Cff(0,1) = 0.5 * vf * (Tf * r1q + yf * mu * r2q) / Sqrt(2.); - Cff(1,0) = Cff(0,1); - Cff(1,1) = Qf * Sqr(sw) * Sqr(mz) * Cos(beta + alpha) - + Sqr(mf) * r1q; - } - - return Cff; -} - -Eigen::Matrix,2,2> MSSM_loop_decays::get_slepton_couplings( - int idx, int gen) const -{ - const double Qf = -1.; - const double I3Lf = -0.5; - const double gY = Sqrt(3. / 5.) * model.get_g1(); - const double g2 = model.get_g2(); - const double gbar = Sqrt(Sqr(g2) + Sqr(gY)); - const double sw = gY / gbar; - const double vd = model.get_vd(); - const double vu = model.get_vu(); - const double v = Sqrt(Sqr(vd) + Sqr(vu)); - const double beta = ArcTan(vu / vd); - - const double vf = vd; - const double yf = model.get_Ye(gen, gen); - const double Tf = model.get_TYe(gen, gen); - const double mu = model.get_Mu(); - const double mf = yf * vf / Sqrt(2.); - const double mz = 0.5 * gbar * v; - const double alpha = get_higgs_mixing_angle(); - - Eigen::Matrix,2,2> Cff; - if (idx == 0) { - const double s1q = -Sin(alpha) / Cos(beta); - const double s2q = -Cos(alpha) / Cos(beta); - Cff(0,0) = -(I3Lf - Qf* Sqr(sw)) * Sqr(mz) * Sin(beta + alpha) - + Sqr(mf) * s1q; - Cff(0,1) = 0.5 * vf * (Tf * s1q + yf * mu * s2q) / Sqrt(2.); - Cff(1,0) = Cff(0,1); - Cff(1,1) = -Qf * Sqr(sw) * Sqr(mz) * Sin(beta + alpha) - + Sqr(mf) * s1q; - } else { - const double r1q = Cos(alpha) / Cos(beta); - const double r2q = -Sin(alpha) / Cos(beta); - Cff(0,0) = (I3Lf - Qf * Sqr(sw)) * Sqr(mz) * Cos(beta + alpha) - + Sqr(mf) * r1q; - Cff(0,1) = 0.5 * vf * (Tf * r1q + yf * mu * r2q) / Sqrt(2.); - Cff(1,0) = Cff(0,1); - Cff(1,1) = Qf * Sqr(sw) * Sqr(mz) * Cos(beta + alpha) - + Sqr(mf) * r1q; - } - - return Cff; -} - -std::complex MSSM_loop_decays::get_hhVPVP_VWm_contribution( - int idx) const -{ - const double vd = model.get_vd(); - const double vu = model.get_vu(); - const double beta = ArcTan(vu / vd); - const double alpha = get_higgs_mixing_angle(); - - std::complex coupling; - if (idx == 0) { - coupling = Sin(beta - alpha); - } else { - coupling = Cos(beta - alpha); - } - - const double MVWm = model.get_MVWm(); - const auto Mhh = model.get_physical().Mhh; - const double tau = 0.25 * Sqr(Mhh(idx)) / Sqr(MVWm); - - return coupling * AS1(tau); -} - -std::complex MSSM_loop_decays::get_hhVPVP_Hpm_contribution( - int idx) const -{ - const double g1 = model.get_g1(); - const double g2 = model.get_g2(); - const double cw = g2 / Sqrt(Sqr(g2) + 0.6 * Sqr(g1)); - const double vd = model.get_vd(); - const double vu = model.get_vu(); - const double beta = ArcTan(vu / vd); - const double alpha = get_higgs_mixing_angle(); - - std::complex coupling; - if (idx == 0) { - coupling = Cos(2. * beta) * Sin(beta + alpha) - + 2. * Sqr(cw) * Sin(beta - alpha); - } else { - coupling = -Cos(2. * beta) * Cos(beta + alpha) - + 2. * Sqr(cw) * Cos(beta - alpha); - } - - const double MHpm = model.get_MHpm(1); - const auto Mhh = model.get_physical().Mhh; - const double tau = 0.25 * Sqr(Mhh(idx)) / Sqr(MHpm); - - return 0.125 * (Sqr(g2) + 0.6 * Sqr(g1)) * (Sqr(vd) + Sqr(vu)) - * coupling * AS0(tau) / Sqr(MHpm); -} - -std::complex MSSM_loop_decays::get_hhVPVP_Cha_contribution( - int idx) const -{ - const double g2 = model.get_g2(); - const double vd = model.get_vd(); - const double vu = model.get_vu(); - const double v = Sqrt(Sqr(vd) + Sqr(vu)); - - const double alpha = get_higgs_mixing_angle(); - - const auto U = (model.get_UM()).conjugate(); - const auto V = model.get_UP(); - std::complex coupling_light; - std::complex coupling_heavy; - if (idx == 0) { - coupling_light = (-Sin(alpha) * V(0,0) * U(0,1) - + Cos(alpha) * V(0,1) * U(0,0)) / Sqrt(2.); - coupling_heavy = (-Sin(alpha) * V(1,0) * U(1,1) - + Cos(alpha) * V(1,1) * U(1,0)) / Sqrt(2.); - } else { - coupling_light = (Cos(alpha) * V(0,0) * U(0,1) - + Sin(alpha) * V(0,1) * U(0,0)) / Sqrt(2.); - coupling_heavy = (Cos(alpha) * V(1,0) * U(1,1) - + Sin(alpha) * V(1,1) * U(1,0)) / Sqrt(2.); - } - - const auto MCha = model.get_MCha(); - const auto Mhh = model.get_physical().Mhh; - const double tau_light = 0.25 * Sqr(Mhh(idx)) / Sqr(MCha(0)); - const double tau_heavy = 0.25 * Sqr(Mhh(idx)) / Sqr(MCha(1)); - - return g2 * v * coupling_light * AS12(tau_light) / MCha(0) - + g2 * v * coupling_heavy * AS12(tau_heavy) / MCha(1); -} - -std::complex MSSM_loop_decays::get_hhVPVP_Su_contribution( - int idx, int gen) const -{ - const int Nc = 3; - const double Qf = 2. / 3.; - const double I3Lf = 0.5; - const double gY = Sqrt(3. / 5.) * model.get_g1(); - const double g2 = model.get_g2(); - const double gbar = Sqrt(Sqr(g2) + Sqr(gY)); - const double sw = gY / gbar; - const double vd = model.get_vd(); - const double vu = model.get_vu(); - const double v = Sqrt(Sqr(vd) + Sqr(vu)); - const double beta = ArcTan(vu / vd); - - const double vf = vu; - const double vo = vd; - const double mLf2 = model.get_mq2(gen, gen); - const double mRf2 = model.get_mu2(gen, gen); - const double yf = model.get_Yu(gen, gen); - const double Tf = model.get_TYu(gen, gen); - const double mu = model.get_Mu(); - const double mf = yf * vf / Sqrt(2.); - const double mix = (Tf * vf - yf * mu * vo) / Sqrt(2.); - const double mz = 0.5 * gbar * v; - - Eigen::Matrix,2,2> Cff - = get_up_type_squark_couplings(idx, gen); - - const double mLL2 = mLf2 + (I3Lf - Qf * Sqr(sw)) * Sqr(mz) - * Cos(2. * beta); - const double mRR2 = mRf2 + Qf * Sqr(sw) * Sqr(mz) * Cos(2. * beta); - - Eigen::Matrix mass_matrix; - mass_matrix << mLL2 + Sqr(mf), mix, mix, mRR2 + Sqr(mf); - - Eigen::Array masses; - Eigen::Matrix,2,2> mixings; - fs_diagonalize_symmetric(mass_matrix, masses, mixings); - - const double msf12 = masses(0); - const double msf22 = masses(1); - - const Eigen::Matrix,2,2> gff = - mixings * Cff * mixings.transpose(); - - const auto Mhh = model.get_physical().Mhh; - const double tau_light = 0.25 * Sqr(Mhh(idx)) / msf12; - const double tau_heavy = 0.25 * Sqr(Mhh(idx)) / msf22; - - return Nc * Sqr(Qf) * gff(0,0) * AS0(tau_light) / msf12 - + Nc * Sqr(Qf) * gff(1,1) * AS0(tau_heavy) / msf22; -} - -std::complex MSSM_loop_decays::get_hhVPVP_Sd_contribution( - int idx, int gen) const -{ - const int Nc = 3; - const double Qf = -1. / 3.; - const double I3Lf = -0.5; - const double gY = Sqrt(3. / 5.) * model.get_g1(); - const double g2 = model.get_g2(); - const double gbar = Sqrt(Sqr(g2) + Sqr(gY)); - const double sw = gY / gbar; - const double vd = model.get_vd(); - const double vu = model.get_vu(); - const double v = Sqrt(Sqr(vd) + Sqr(vu)); - const double beta = ArcTan(vu / vd); - - const double vf = vd; - const double vo = vu; - const double mLf2 = model.get_mq2(gen, gen); - const double mRf2 = model.get_md2(gen, gen); - const double yf = model.get_Yd(gen, gen); - const double Tf = model.get_TYd(gen, gen); - const double mu = model.get_Mu(); - const double mf = yf * vf / Sqrt(2.); - const double mix = (Tf * vf - yf * mu * vo) / Sqrt(2.); - const double mz = 0.5 * gbar * v; - - Eigen::Matrix,2,2> Cff - = get_down_type_squark_couplings(idx, gen); - - const double mLL2 = mLf2 + (I3Lf - Qf * Sqr(sw)) * Sqr(mz) - * Cos(2. * beta); - const double mRR2 = mRf2 + Qf * Sqr(sw) * Sqr(mz) * Cos(2. * beta); - - Eigen::Matrix mass_matrix; - mass_matrix << mLL2 + Sqr(mf), mix, mix, mRR2 + Sqr(mf); - - Eigen::Array masses; - Eigen::Matrix,2,2> mixings; - fs_diagonalize_symmetric(mass_matrix, masses, mixings); - - const double msf12 = masses(0); - const double msf22 = masses(1); - - const Eigen::Matrix,2,2> gff = - mixings * Cff * mixings.transpose(); - - const auto Mhh = model.get_physical().Mhh; - const double tau_light = 0.25 * Sqr(Mhh(idx)) / msf12; - const double tau_heavy = 0.25 * Sqr(Mhh(idx)) / msf22; - - return Nc * Sqr(Qf) * gff(0,0) * AS0(tau_light) / msf12 - + Nc * Sqr(Qf) * gff(1,1) * AS0(tau_heavy) / msf22; -} - -std::complex MSSM_loop_decays::get_hhVPVP_Se_contribution( - int idx, int gen) const -{ - const int Nc = 1; - const double Qf = -1.; - const double I3Lf = -0.5; - const double gY = Sqrt(3. / 5.) * model.get_g1(); - const double g2 = model.get_g2(); - const double gbar = Sqrt(Sqr(g2) + Sqr(gY)); - const double sw = gY / gbar; - const double vd = model.get_vd(); - const double vu = model.get_vu(); - const double v = Sqrt(Sqr(vd) + Sqr(vu)); - const double beta = ArcTan(vu / vd); - - const double vf = vd; - const double vo = vu; - const double mLf2 = model.get_ml2(gen, gen); - const double mRf2 = model.get_me2(gen, gen); - const double yf = model.get_Ye(gen, gen); - const double Tf = model.get_TYe(gen, gen); - const double mu = model.get_Mu(); - const double mf = yf * vf / Sqrt(2.); - const double mix = (Tf * vf - yf * mu * vo) / Sqrt(2.); - const double mz = 0.5 * gbar * v; - - Eigen::Matrix,2,2> Cff - = get_slepton_couplings(idx, gen); - - const double mLL2 = mLf2 + (I3Lf - Qf * Sqr(sw)) * Sqr(mz) - * Cos(2. * beta); - const double mRR2 = mRf2 + Qf * Sqr(sw) * Sqr(mz) * Cos(2. * beta); - - Eigen::Matrix mass_matrix; - mass_matrix << mLL2 + Sqr(mf), mix, mix, mRR2 + Sqr(mf); - - Eigen::Array masses; - Eigen::Matrix,2,2> mixings; - fs_diagonalize_symmetric(mass_matrix, masses, mixings); - - const double msf12 = masses(0); - const double msf22 = masses(1); - - const Eigen::Matrix,2,2> gff = - mixings * Cff * mixings.transpose(); - - const auto Mhh = model.get_physical().Mhh; - const double tau_light = 0.25 * Sqr(Mhh(idx)) / msf12; - const double tau_heavy = 0.25 * Sqr(Mhh(idx)) / msf22; - - return Nc * Sqr(Qf) * gff(0,0) * AS0(tau_light) / msf12 - + Nc * Sqr(Qf) * gff(1,1) * AS0(tau_heavy) / msf22; -} - -std::complex MSSM_loop_decays::get_hhVPVP_Fu_contribution( - int idx, int gen) const -{ - const int Nc = 3; - const double Qf = 2. / 3.; - const double alpha = get_higgs_mixing_angle(); - const double beta = ArcTan(model.get_vu() / model.get_vd()); - - std::complex coupling; - if (idx == 0) { - coupling = Cos(alpha) / Sin(beta); - } else { - coupling = Sin(alpha) / Sin(beta); - } - - const auto Mhh = model.get_physical().Mhh; - const auto MFu = model.get_MFu(); - const double tau = 0.25 * Sqr(Mhh(idx)) / Sqr(MFu(gen)); - - return Nc * Sqr(Qf) * coupling * AS12(tau); -} - -std::complex MSSM_loop_decays::get_hhVPVP_Fd_contribution( - int idx, int gen) const -{ - const int Nc = 3; - const double Qf = -1. / 3.; - const double alpha = get_higgs_mixing_angle(); - const double beta = ArcTan(model.get_vu() / model.get_vd()); - - std::complex coupling; - if (idx == 0) { - coupling = -Sin(alpha) / Cos(beta); - } else { - coupling = Cos(alpha) / Cos(beta); - } - - const auto Mhh = model.get_physical().Mhh; - const auto MFd = model.get_MFd(); - const double tau = 0.25 * Sqr(Mhh(idx)) / Sqr(MFd(gen)); - - return Nc * Sqr(Qf) * coupling * AS12(tau); -} - -std::complex MSSM_loop_decays::get_hhVPVP_Fe_contribution( - int idx, int gen) const -{ - const double Qf = -1.; - const double alpha = get_higgs_mixing_angle(); - const double beta = ArcTan(model.get_vu() / model.get_vd()); - - std::complex coupling; - if (idx == 0) { - coupling = -Sin(alpha) / Cos(beta); - } else { - coupling = Cos(alpha) / Cos(beta); - } - - const auto Mhh = model.get_physical().Mhh; - const auto MFe = model.get_MFe(); - const double tau = 0.25 * Sqr(Mhh(idx)) / Sqr(MFe(gen)); - - return Sqr(Qf) * coupling * AS12(tau); -} - -std::complex MSSM_loop_decays::get_hhVGVG_Su_contribution( - int idx, int gen) const -{ - const double Qf = 2. / 3.; - const double I3Lf = 0.5; - const double gY = Sqrt(3. / 5.) * model.get_g1(); - const double g2 = model.get_g2(); - const double gbar = Sqrt(Sqr(g2) + Sqr(gY)); - const double sw = gY / gbar; - const double vd = model.get_vd(); - const double vu = model.get_vu(); - const double v = Sqrt(Sqr(vd) + Sqr(vu)); - const double beta = ArcTan(vu / vd); - - const double vf = vu; - const double vo = vd; - const double mLf2 = model.get_mq2(gen, gen); - const double mRf2 = model.get_mu2(gen, gen); - const double yf = model.get_Yu(gen, gen); - const double Tf = model.get_TYu(gen, gen); - const double mu = model.get_Mu(); - const double mf = yf * vf / Sqrt(2.); - const double mix = (Tf * vf - yf * mu * vo) / Sqrt(2.); - const double mz = 0.5 * gbar * v; - - Eigen::Matrix,2,2> Cff - = get_up_type_squark_couplings(idx, gen); - - const double mLL2 = mLf2 + (I3Lf - Qf * Sqr(sw)) * Sqr(mz) - * Cos(2. * beta); - const double mRR2 = mRf2 + Qf * Sqr(sw) * Sqr(mz) * Cos(2. * beta); - - Eigen::Matrix mass_matrix; - mass_matrix << mLL2 + Sqr(mf), mix, mix, mRR2 + Sqr(mf); - - Eigen::Array masses; - Eigen::Matrix,2,2> mixings; - fs_diagonalize_symmetric(mass_matrix, masses, mixings); - - const double msf12 = masses(0); - const double msf22 = masses(1); - - const Eigen::Matrix,2,2> gff = - mixings * Cff * mixings.transpose(); - - const auto Mhh = model.get_physical().Mhh; - const double tau_light = 0.25 * Sqr(Mhh(idx)) / msf12; - const double tau_heavy = 0.25 * Sqr(Mhh(idx)) / msf22; - - return gff(0,0) * AS0(tau_light) / msf12 - + gff(1,1) * AS0(tau_heavy) / msf22; -} - -std::complex MSSM_loop_decays::get_hhVGVG_Sd_contribution( - int idx, int gen) const -{ - const double Qf = -1. / 3.; - const double I3Lf = -0.5; - const double gY = Sqrt(3. / 5.) * model.get_g1(); - const double g2 = model.get_g2(); - const double gbar = Sqrt(Sqr(g2) + Sqr(gY)); - const double sw = gY / gbar; - const double vd = model.get_vd(); - const double vu = model.get_vu(); - const double v = Sqrt(Sqr(vd) + Sqr(vu)); - const double beta = ArcTan(vu / vd); - - const double vf = vd; - const double vo = vu; - const double mLf2 = model.get_mq2(gen, gen); - const double mRf2 = model.get_md2(gen, gen); - const double yf = model.get_Yd(gen, gen); - const double Tf = model.get_TYd(gen, gen); - const double mu = model.get_Mu(); - const double mf = yf * vf / Sqrt(2.); - const double mix = (Tf * vf - yf * mu * vo) / Sqrt(2.); - const double mz = 0.5 * gbar * v; - - Eigen::Matrix,2,2> Cff - = get_down_type_squark_couplings(idx, gen); - - const double mLL2 = mLf2 + (I3Lf - Qf * Sqr(sw)) * Sqr(mz) - * Cos(2. * beta); - const double mRR2 = mRf2 + Qf * Sqr(sw) * Sqr(mz) * Cos(2. * beta); - - Eigen::Matrix mass_matrix; - mass_matrix << mLL2 + Sqr(mf), mix, mix, mRR2 + Sqr(mf); - - Eigen::Array masses; - Eigen::Matrix,2,2> mixings; - fs_diagonalize_symmetric(mass_matrix, masses, mixings); - - const double msf12 = masses(0); - const double msf22 = masses(1); - - const Eigen::Matrix,2,2> gff = - mixings * Cff * mixings.transpose(); - - const auto Mhh = model.get_physical().Mhh; - const double tau_light = 0.25 * Sqr(Mhh(idx)) / msf12; - const double tau_heavy = 0.25 * Sqr(Mhh(idx)) / msf22; - - return gff(0,0) * AS0(tau_light) / msf12 - + gff(1,1) * AS0(tau_heavy) / msf22; -} - -std::complex MSSM_loop_decays::get_hhVGVG_Fu_contribution( - int idx, int gen) const -{ - const double alpha = get_higgs_mixing_angle(); - const double beta = ArcTan(model.get_vu() / model.get_vd()); - - std::complex coupling; - if (idx == 0) { - coupling = Cos(alpha) / Sin(beta); - } else { - coupling = Sin(alpha) / Sin(beta); - } - - const auto Mhh = model.get_physical().Mhh; - const auto MFu = model.get_MFu(); - const double tau = 0.25 * Sqr(Mhh(idx)) / Sqr(MFu(gen)); - - return coupling * AS12(tau); -} - -std::complex MSSM_loop_decays::get_hhVGVG_Fd_contribution( - int idx, int gen) const -{ - const double alpha = get_higgs_mixing_angle(); - const double beta = ArcTan(model.get_vu() / model.get_vd()); - - std::complex coupling; - if (idx == 0) { - coupling = -Sin(alpha) / Cos(beta); - } else { - coupling = Cos(alpha) / Cos(beta); - } - - const auto Mhh = model.get_physical().Mhh; - const auto MFd = model.get_MFd(); - const double tau = 0.25 * Sqr(Mhh(idx)) / Sqr(MFd(gen)); - - return coupling * AS12(tau); -} - -std::complex MSSM_loop_decays::get_AhVPVP_Cha_contribution() const -{ - const double g2 = model.get_g2(); - const double vd = model.get_vd(); - const double vu = model.get_vu(); - const double v = Sqrt(Sqr(vd) + Sqr(vu)); - - const auto ZA = model.get_physical().ZA; - const auto U = (model.get_UM()).conjugate(); - const auto V = model.get_UP(); - const std::complex coupling_light - = (-ZA(1,0) * V(0,0) * U(0,1) - - ZA(1,1) * V(0,1) * U(0,0)) / Sqrt(2.) - * std::complex(0.,1.); - std::complex coupling_heavy - = (-ZA(1,0) * V(1,0) * U(1,1) - - ZA(1,1) * V(1,1) * U(1,0)) / Sqrt(2.) - * std::complex(0.,1.); - - const auto MCha = model.get_MCha(); - const auto MAh = model.get_physical().MAh; - const double tau_light = 0.25 * Sqr(MAh(1)) / Sqr(MCha(0)); - const double tau_heavy = 0.25 * Sqr(MAh(1)) / Sqr(MCha(1)); - - return g2 * v * coupling_light * 2. * AP12(tau_light) / MCha(0) - + g2 * v * coupling_heavy * 2. * AP12(tau_heavy) / MCha(1); -} - -std::complex MSSM_loop_decays::get_AhVPVP_Fu_contribution( - int gen) const -{ - const int Nc = 3; - const double Qf = 2. / 3.; - const auto ZA = model.get_physical().ZA; - const double beta = ArcTan(model.get_vu() / model.get_vd()); - const std::complex coupling = ZA(1,1) / Sin(beta) - * std::complex(0., 1.); - - const auto MAh = model.get_physical().MAh; - const auto MFu = model.get_MFu(); - const double tau = 0.25 * Sqr(MAh(1)) / Sqr(MFu(gen)); - - return Nc * Sqr(Qf) * coupling * 2. * AP12(tau); -} - -std::complex MSSM_loop_decays::get_AhVPVP_Fd_contribution( - int gen) const -{ - const int Nc = 3; - const double Qf = -1. / 3.; - const auto ZA = model.get_physical().ZA; - const double beta = ArcTan(model.get_vu() / model.get_vd()); - const std::complex coupling = ZA(1,0) / Cos(beta) - * std::complex(0., 1.); - - const auto MAh = model.get_physical().MAh; - const auto MFd = model.get_MFd(); - const double tau = 0.25 * Sqr(MAh(1)) / Sqr(MFd(gen)); - - return Nc * Sqr(Qf) * coupling * 2. * AP12(tau); -} - -std::complex MSSM_loop_decays::get_AhVPVP_Fe_contribution( - int gen) const -{ - const double Qf = -1.; - const auto ZA = model.get_physical().ZA; - const double beta = ArcTan(model.get_vu() / model.get_vd()); - const std::complex coupling = ZA(1,0) / Cos(beta) - * std::complex(0., 1.); - - const auto MAh = model.get_physical().MAh; - const auto MFe = model.get_MFe(); - const double tau = 0.25 * Sqr(MAh(1)) / Sqr(MFe(gen)); - - return Sqr(Qf) * coupling * 2. * AP12(tau); -} - -std::complex MSSM_loop_decays::get_AhVGVG_Fu_contribution( - int gen) const -{ - const auto ZA = model.get_physical().ZA; - const double beta = ArcTan(model.get_vu() / model.get_vd()); - const std::complex coupling = ZA(1,1) / Sin(beta) - * std::complex(0., 1.); - - const auto MAh = model.get_physical().MAh; - const auto MFu = model.get_MFu(); - const double tau = 0.25 * Sqr(MAh(1)) / Sqr(MFu(gen)); - - return coupling * 2. * AP12(tau); -} - -std::complex MSSM_loop_decays::get_AhVGVG_Fd_contribution( - int gen) const -{ - const auto ZA = model.get_physical().ZA; - const double beta = ArcTan(model.get_vu() / model.get_vd()); - const std::complex coupling = ZA(1,0) / Cos(beta) - * std::complex(0., 1.); - - const auto MAh = model.get_physical().MAh; - const auto MFd = model.get_MFd(); - const double tau = 0.25 * Sqr(MAh(1)) / Sqr(MFd(gen)); - - return coupling * 2. * AP12(tau); -} - -std::complex MSSM_loop_decays::get_eff_CphhVPVP(int idx) -{ - const auto Mhh = model.get_physical().Mhh; - if (rg_improve && model.get_scale() > Mhh(idx)) { - model.run_to(Mhh(idx)); - } - model.calculate_DRbar_masses(); - - std::complex result = get_hhVPVP_VWm_contribution(idx); - result += get_hhVPVP_Hpm_contribution(idx); - result += get_hhVPVP_Cha_contribution(idx); - for (int gen = 0; gen < 3; ++gen) { - result += get_hhVPVP_Su_contribution(idx, gen); - result += get_hhVPVP_Sd_contribution(idx, gen); - result += get_hhVPVP_Se_contribution(idx, gen); - result += get_hhVPVP_Fu_contribution(idx, gen); - result += get_hhVPVP_Fd_contribution(idx, gen); - result += get_hhVPVP_Fe_contribution(idx, gen); - } - const double prefactor = 0.1892681907127351 - * physical_inputs.get(Physical_input::alpha_em_0) - * Sqrt(qedqcd.displayFermiConstant()); - - return prefactor * result; -} - -std::complex MSSM_loop_decays::get_eff_CphhVGVG(int idx) -{ - const double old_g3 = model.get_g3(); - const auto Mhh = model.get_physical().Mhh; - if (rg_improve && model.get_scale() > Mhh(idx)) { - model.run_to(Mhh(idx)); - } - run_SM_strong_coupling_to(Mhh(idx)); - model.calculate_DRbar_masses(); - - std::complex result = std::complex(0.,0.); - for (int gen = 0; gen < 3; ++gen) { - result += get_hhVGVG_Su_contribution(idx, gen); - result += get_hhVGVG_Sd_contribution(idx, gen); - result += get_hhVGVG_Fu_contribution(idx, gen); - result += get_hhVGVG_Fd_contribution(idx, gen); - } - result *= 0.75; - - const double alpha_s = 0.07957747154594767*Sqr(model.get_g3()); - const double prefactor = 0.12617879380849006 * alpha_s - * Sqrt(qedqcd.displayFermiConstant()); - - model.set_g3(old_g3); - - return prefactor * result; -} - -std::complex MSSM_loop_decays::get_eff_CpAhVPVP() -{ - const auto MAh = model.get_physical().MAh; - if (rg_improve && model.get_scale() > MAh(1)) { - model.run_to(MAh(1)); - } - model.calculate_DRbar_masses(); - - std::complex result = get_AhVPVP_Cha_contribution(); - for (int gen = 0; gen < 3; ++gen) { - result += get_AhVPVP_Fu_contribution(gen); - result += get_AhVPVP_Fd_contribution(gen); - result += get_AhVPVP_Fe_contribution(gen); - } - const double prefactor = 0.1892681907127351 - * physical_inputs.get(Physical_input::alpha_em_0) - * Sqrt(qedqcd.displayFermiConstant()); - - return prefactor * result; -} - -std::complex MSSM_loop_decays::get_eff_CpAhVGVG() -{ - const double old_g3 = model.get_g3(); - const auto MAh = model.get_physical().MAh; - if (rg_improve && model.get_scale() > MAh(1)) { - model.run_to(MAh(1)); - } - run_SM_strong_coupling_to(MAh(1)); - model.calculate_DRbar_masses(); - - std::complex result = std::complex(0.,0.); - for (int gen = 0; gen < 3; ++gen) { - result += get_AhVGVG_Fu_contribution(gen); - result += get_AhVGVG_Fd_contribution(gen); - } - result *= 0.75; - - const double alpha_s = 0.07957747154594767*Sqr(model.get_g3()); - const double prefactor = 0.12617879380849006 * alpha_s - * Sqrt(qedqcd.displayFermiConstant()); - - model.set_g3(old_g3); - - return prefactor * result; -} -void set_test_model_parameters(CMSSM_mass_eigenstates& model, - CMSSM_input_parameters& input, - const softsusy::QedQcd& qedqcd) -{ - input.m0 = 125.; - input.m12 = 500.; - input.Azero = 0.; - input.TanBeta = 10.0; - - const double scale = 864.196350; - - const double g1 = Sqrt(5. / 3.) * 0.362388869; - const double g2 = 0.643064079; - const double g3 = 1.06292111; - const double Mu = 623.398163; - const double BMu = 53774.7440; - const double vd = 25.0988057; - const double vu = 242.826920; - - Eigen::Matrix Yu(Eigen::Matrix::Zero()); - Eigen::Matrix Yd(Eigen::Matrix::Zero()); - Eigen::Matrix Ye(Eigen::Matrix::Zero()); - - Yu(0,0) = 7.32901347e-6; - Yu(1,1) = 3.35149154e-3; - Yu(2,2) = qedqcd.displayPoleMt()* Sqrt(2.) / vu; - - Yd(0,0) = 1.41183630e-4; - Yd(1,1) = 3.09118035e-3; - Yd(2,2) = 1.33272717e-1; - - Ye(0,0) = 2.89560942e-5; - Ye(1,1) = 5.98720208e-3; - Ye(2,2) = 1.00698298e-1; - - Eigen::Matrix AYu(Eigen::Matrix::Zero()); - Eigen::Matrix AYd(Eigen::Matrix::Zero()); - Eigen::Matrix AYe(Eigen::Matrix::Zero()); - - AYu(0,0) = -1130.62590; - AYu(1,1) = -1130.62089; - AYu(2,2) = -872.799086; - - AYd(0,0) = -1384.23875; - AYd(1,1) = -1384.23410; - AYd(2,2) = -1293.85753; - - AYe(0,0) = -299.168792; - AYe(1,1) = -299.163003; - AYe(2,2) = -297.531417; - - Eigen::Matrix TYu = (Yu.array() * AYu.array()).matrix(); - Eigen::Matrix TYd = (Yd.array() * AYd.array()).matrix(); - Eigen::Matrix TYe = (Ye.array() * AYe.array()).matrix(); - - Eigen::Matrix mq2(Eigen::Matrix::Zero()); - Eigen::Matrix ml2(Eigen::Matrix::Zero()); - Eigen::Matrix md2(Eigen::Matrix::Zero()); - Eigen::Matrix mu2(Eigen::Matrix::Zero()); - Eigen::Matrix me2(Eigen::Matrix::Zero()); - - mq2(0,0) = 1.01310643e6; - mq2(1,1) = 1.01310128e6; - mq2(2,2) = 8.61071428e5; - - ml2(0,0) = 1.24941646e5; - ml2(1,1) = 1.24939130e5; - ml2(2,2) = 1.24230841e5; - - md2(0,0) = 9.27220763e5; - md2(1,1) = 9.27215601e5; - md2(2,2) = 9.18044968e5; - - mu2(0,0) = 9.36437027e5; - mu2(1,1) = 9.36431757e5; - mu2(2,2) = 6.34856659e5; - - me2(0,0) = 4.93863949e4; - me2(1,1) = 4.93812597e4; - me2(2,2) = 4.79356909e4; - - const double mHd2 = 1.09303956e5; - const double mHu2 = -3.76666907e5; - const double MassB = 209.081139; - const double MassWB = 387.961620; - const double MassG = 1114.07969; - - model.set_input_parameters(input); - model.set_scale(scale); - model.set_loops(2); - model.set_thresholds(3); - model.set_g1(g1); - model.set_g2(g2); - model.set_g3(g3); - model.set_Yu(Yu); - model.set_Yd(Yd); - model.set_Ye(Ye); - model.set_Mu(Mu); - model.set_vd(vd); - model.set_vu(vu); - model.set_BMu(BMu); - model.set_MassB(MassB); - model.set_MassG(MassWB); - model.set_MassWB(MassG); - model.set_mq2(mq2); - model.set_ml2(ml2); - model.set_md2(md2); - model.set_mu2(mu2); - model.set_me2(me2); - model.set_mHd2(mHd2); - model.set_mHu2(mHu2); - model.set_TYu(TYu); - model.set_TYd(TYd); - model.set_TYe(TYe); - - model.calculate_DRbar_masses(); - model.solve_ewsb(); - model.calculate_spectrum(); -} - -BOOST_AUTO_TEST_CASE( test_LO_scalar_diphoton_couplings ) -{ - softsusy::QedQcd qedqcd; - Physical_input physical_inputs; - - CMSSM_input_parameters input; - CMSSM_mass_eigenstates model; - set_test_model_parameters(model, input, qedqcd); - - CMSSM_effective_couplings eff_cp(model, qedqcd, physical_inputs); - eff_cp.do_run_couplings(false); - eff_cp.do_include_qcd_corrections(false); - eff_cp.calculate_effective_couplings(); - - const std::complex obtained_cphhVPVP_0 = eff_cp.get_eff_CphhVPVP(0); - const std::complex obtained_cphhVPVP_1 = eff_cp.get_eff_CphhVPVP(1); - - MSSM_loop_decays mssm_tester(model, qedqcd, physical_inputs); - mssm_tester.do_rg_improve(false); - - const std::complex expected_cphhVPVP_0 - = mssm_tester.get_eff_CphhVPVP(0); - const std::complex expected_cphhVPVP_1 - = mssm_tester.get_eff_CphhVPVP(1); - - BOOST_CHECK_CLOSE_FRACTION(-Re(expected_cphhVPVP_0), - Re(obtained_cphhVPVP_0), 1.0e-10); - BOOST_CHECK_CLOSE_FRACTION(-Im(expected_cphhVPVP_0), - Im(obtained_cphhVPVP_0), 1.0e-10); - BOOST_CHECK_CLOSE_FRACTION(-Re(expected_cphhVPVP_1), - Re(obtained_cphhVPVP_1), 1.0e-10); - BOOST_CHECK_CLOSE_FRACTION(-Im(expected_cphhVPVP_1), - Im(obtained_cphhVPVP_1), 1.0e-10); -} - -BOOST_AUTO_TEST_CASE( test_LO_scalar_digluon_couplings ) -{ - softsusy::QedQcd qedqcd; - Physical_input physical_inputs; - - CMSSM_input_parameters input; - CMSSM_mass_eigenstates model; - set_test_model_parameters(model, input, qedqcd); - - CMSSM_effective_couplings eff_cp(model, qedqcd, physical_inputs); - eff_cp.do_run_couplings(false); - eff_cp.do_include_qcd_corrections(false); - eff_cp.calculate_effective_couplings(); - - const std::complex obtained_cphhVGVG_0 = eff_cp.get_eff_CphhVGVG(0); - const std::complex obtained_cphhVGVG_1 = eff_cp.get_eff_CphhVGVG(1); - - MSSM_loop_decays mssm_tester(model, qedqcd, physical_inputs); - mssm_tester.do_rg_improve(false); - - const std::complex expected_cphhVGVG_0 - = mssm_tester.get_eff_CphhVGVG(0); - const std::complex expected_cphhVGVG_1 - = mssm_tester.get_eff_CphhVGVG(1); - - BOOST_CHECK_CLOSE_FRACTION(-Re(expected_cphhVGVG_0), - Re(obtained_cphhVGVG_0), 1.0e-10); - BOOST_CHECK_CLOSE_FRACTION(-Im(expected_cphhVGVG_0), - Im(obtained_cphhVGVG_0), 1.0e-10); - BOOST_CHECK_CLOSE_FRACTION(-Re(expected_cphhVGVG_1), - Re(obtained_cphhVGVG_1), 1.0e-10); - BOOST_CHECK_CLOSE_FRACTION(-Im(expected_cphhVGVG_1), - Im(obtained_cphhVGVG_1), 1.0e-10); -} - -BOOST_AUTO_TEST_CASE( test_LO_pseudoscalar_diphoton_couplings ) -{ - softsusy::QedQcd qedqcd; - Physical_input physical_inputs; - - CMSSM_input_parameters input; - CMSSM_mass_eigenstates model; - set_test_model_parameters(model, input, qedqcd); - - CMSSM_effective_couplings eff_cp(model, qedqcd, physical_inputs); - eff_cp.do_run_couplings(false); - eff_cp.do_include_qcd_corrections(false); - eff_cp.calculate_effective_couplings(); - - const std::complex obtained_cpAhVPVP_1 = eff_cp.get_eff_CpAhVPVP(1); - - MSSM_loop_decays mssm_tester(model, qedqcd, physical_inputs); - mssm_tester.do_rg_improve(false); - - const std::complex expected_cpAhVPVP_1 - = mssm_tester.get_eff_CpAhVPVP(); - - BOOST_CHECK_CLOSE_FRACTION(-Re(expected_cpAhVPVP_1), - Re(obtained_cpAhVPVP_1), 1.0e-10); - BOOST_CHECK_CLOSE_FRACTION(-Im(expected_cpAhVPVP_1), - Im(obtained_cpAhVPVP_1), 1.0e-10); -} - -BOOST_AUTO_TEST_CASE( test_LO_pseudoscalar_digluon_couplings ) -{ - softsusy::QedQcd qedqcd; - Physical_input physical_inputs; - - CMSSM_input_parameters input; - CMSSM_mass_eigenstates model; - set_test_model_parameters(model, input, qedqcd); - - CMSSM_effective_couplings eff_cp(model, qedqcd, physical_inputs); - eff_cp.do_run_couplings(false); - eff_cp.do_include_qcd_corrections(false); - eff_cp.calculate_effective_couplings(); - - const std::complex obtained_cpAhVGVG_1 = eff_cp.get_eff_CpAhVGVG(1); - - MSSM_loop_decays mssm_tester(model, qedqcd, physical_inputs); - mssm_tester.do_rg_improve(false); - - const std::complex expected_cpAhVGVG_1 - = mssm_tester.get_eff_CpAhVGVG(); - - BOOST_CHECK_CLOSE_FRACTION(-Re(expected_cpAhVGVG_1), - Re(obtained_cpAhVGVG_1), 1.0e-10); - BOOST_CHECK_CLOSE_FRACTION(-Im(expected_cpAhVGVG_1), - Im(obtained_cpAhVGVG_1), 1.0e-10); -} diff --git a/test/test_SM_effective_couplings.cpp b/test/test_SM_effective_couplings.cpp deleted file mode 100644 index a29f1392bb..0000000000 --- a/test/test_SM_effective_couplings.cpp +++ /dev/null @@ -1,259 +0,0 @@ - -#define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE test_SM_effective_couplings - -#include - -#include "effective_couplings.hpp" -#include "SM_mass_eigenstates.hpp" -#include "SM_effective_couplings.hpp" -#include "physical_input.hpp" -#include "standard_model.hpp" -#include "wrappers.hpp" - -#include - -using namespace flexiblesusy; -using namespace effective_couplings; - -class Standard_model_tester { -public: - Standard_model_tester(const SM_mass_eigenstates& model_, - softsusy::QedQcd qedqcd_, - Physical_input physical_inputs_) - : model(model_) - , qedqcd(qedqcd_) - , physical_inputs(physical_inputs_) - , rg_improve(true) - , include_qcd_corrections(true) {} - ~Standard_model_tester() {} - void do_rg_improve(bool flag) { rg_improve = flag; } - void do_include_qcd_corrections(bool flag) { include_qcd_corrections = flag; } - void set_model(const SM_mass_eigenstates& model_) { model = model_; } - - std::complex get_eff_CphhVPVP(); - std::complex get_eff_CphhVGVG(); - -private: - SM_mass_eigenstates model; - softsusy::QedQcd qedqcd; - Physical_input physical_inputs; - bool rg_improve; - bool include_qcd_corrections; - - double number_of_active_flavours(double m) const; - double qcd_scaling_factor(double m) const; - void run_SM_gauge_couplings_to(double m); -}; - -double Standard_model_tester::number_of_active_flavours(double m) const -{ - if (m < qedqcd.displayMbMb()) { - return 4.0; - } else if (m < qedqcd.displayPoleMt()) { - return 5.0; - } else { - return 6.0; - } -} - -double Standard_model_tester::qcd_scaling_factor(double m) const -{ - const double Nf = number_of_active_flavours(m); - const double mtpole = qedqcd.displayPoleMt(); - const double l = Log(Sqr(m) / Sqr(mtpole)); - const double g3 = model.get_g3(); - - const double nlo_qcd = 0.025330295910584444*(23.75 - 1.1666666666666667*Nf)* - Sqr(g3); - const double nnlo_qcd = 0.000641623890917771*Power(g3,4)*(370.1956513893174 - + 2.375*l + (-47.18640261449638 + 0.6666666666666666*l)*Nf + - 0.9017702481178881*Sqr(Nf)); - const double nnnlo_qcd = 0.000016252523020247696*Power(g3,6)*(467.683620788 - + 122.440972222*l + 10.9409722222*Sqr(l)); - - return Sqrt(1.0 + nlo_qcd + nnlo_qcd + nnnlo_qcd); -} - -void Standard_model_tester::run_SM_gauge_couplings_to(double m) -{ - using namespace standard_model; - - Standard_model sm; - - sm.set_loops(2); - sm.set_thresholds(2); - sm.set_physical_input(physical_inputs); - - sm.initialise_from_input(qedqcd); - sm.run_to(m); - - model.set_g3(sm.get_g3()); -} - -// @note in the current mixed scheme, the LO expressions -// are not correctly reproduced, i.e. the ratios coupling * vev / mass -// do not reduce to 1 - this should be fixed -std::complex Standard_model_tester::get_eff_CphhVPVP() -{ - const double scale = model.get_scale(); - const Eigen::ArrayXd saved_pars(model.get()); - - const double Mhh = model.get_physical().Mhh; - - run_SM_gauge_couplings_to(0.5 * Mhh); - - Eigen::Array MFu(model.get_physical().MFu); - const Eigen::Array MFd(model.get_physical().MFd); - const Eigen::Array MFe(model.get_physical().MFe); - const double MVWp = model.get_physical().MVWp; - - double qcd_fermion = 1.0; - if (include_qcd_corrections) { - qcd_fermion = 1.0 - Sqr(model.get_g3()) / (4.0 * Sqr(Pi)); - } - - std::complex result = AS1(0.25 * Sqr(Mhh) / Sqr(MVWp)); - - for (int i = 0; i < 3; ++i) { - if (MFu(i) > Mhh) { - result += 4.0 * qcd_fermion * AS12(0.25 * Sqr(Mhh) / Sqr(MFu(i))) / 3.0; - } else { - result += 4.0 * AS12(0.25 * Sqr(Mhh) / Sqr(MFu(i))) / 3.0; - } - if (MFd(i) > Mhh) { - result += qcd_fermion * AS12(0.25 * Sqr(Mhh) / Sqr(MFd(i))) / 3.0; - } else { - result += AS12(0.25 * Sqr(Mhh) / Sqr(MFd(i))) / 3.0; - } - result += AS12(0.25 * Sqr(Mhh) / Sqr(MFe(i))); - } - - result *= physical_inputs.get(Physical_input::alpha_em_0) - * Sqrt(qedqcd.displayFermiConstant()) / (Power(2.0, 0.75) * Pi); - - model.set_scale(scale); - model.set(saved_pars); - - return result; -} - -std::complex Standard_model_tester::get_eff_CphhVGVG() -{ - const double scale = model.get_scale(); - const Eigen::ArrayXd saved_pars(model.get()); - - const double Mhh = model.get_physical().Mhh; - - run_SM_gauge_couplings_to(Mhh); - model.calculate_DRbar_masses(); - - Eigen::Array MFu(model.get_physical().MFu); - MFu(2) = qedqcd.displayPoleMt(); - const Eigen::Array MFd(model.get_physical().MFd); - - double qcd_fermion = 1.0; - if (include_qcd_corrections) { - qcd_fermion = 1.0 + 2.0 * Sqr(model.get_g3()) / (3.0 * Sqr(Pi)); - } - - std::complex result; - - for (int i = 0; i < 3; ++i) { - result += qcd_fermion * AS12(0.25 * Sqr(Mhh) / Sqr(MFd(i))); - result += qcd_fermion * AS12(0.25 * Sqr(Mhh) / Sqr(MFu(i))); - } - result *= std::complex(0.75,0); - - if (include_qcd_corrections) { - result *= qcd_scaling_factor(Mhh); - } - - const double alpha_s = 0.07957747154594767*Sqr(model.get_g3()); - result *= alpha_s * Sqrt(qedqcd.displayFermiConstant()) - * Power(2.0, 0.25) / (3.0 * Pi); - - model.set(saved_pars); - model.set_scale(scale); - - return result; -} - -void set_test_model_parameters(SM_mass_eigenstates& model, const softsusy::QedQcd& qedqcd) -{ - model.do_calculate_sm_pole_masses(true); - - - const double v = 1.0 / Sqrt(qedqcd.displayFermiConstant() * Sqrt(2.0)); - - const double g1 = Sqrt(5.0 / 3.0) * 3.58533449e-1; - const double g2 = 6.47712483e-1; - const double g3 = 1.16182994; - - Eigen::Matrix Yu; - Eigen::Matrix Yd; - Eigen::Matrix Ye; - - Yu << 7.55665947e-6, 0.0, 0.0, - 0.0, 3.45513221e-3, 0.0, - 0.0, 0.0, Sqrt(2.0) * qedqcd.displayPoleMt() / v; - - Yd << 1.50336005e-5, 0.0, 0.0, - 0.0, 3.29156700e-4, 0.0, - 0.0, 0.0, 1.56338961e-2; - - Ye << 2.87235703e-6, 0.0, 0.0, - 0.0, 5.93912276e-4, 0.0, - 0.0, 0.0, 1.00093274e-2; - - const double Lambdax = 0.252805415; - const double mu2 = 8555.44881e3; - - model.set_g1(g1); - model.set_g2(g2); - model.set_g3(g3); - model.set_Yu(Yu); - model.set_Yd(Yd); - model.set_Ye(Ye); - model.set_Lambdax(Lambdax); - model.set_mu2(mu2); - model.set_v(v); - - model.set_scale(173.34); - - // necessary to match LO expressions above - model.set_pole_mass_loop_order(0); - model.set_ewsb_loop_order(0); - model.calculate_DRbar_masses(); - model.solve_ewsb_tree_level(); - model.calculate_spectrum(); -} - -BOOST_AUTO_TEST_CASE( test_LO_effective_couplings ) -{ - softsusy::QedQcd qedqcd; - Physical_input physical_inputs; - - SM_mass_eigenstates model; - set_test_model_parameters(model, qedqcd); - - Standard_model_tester sm_tester(model, qedqcd, physical_inputs); - sm_tester.do_rg_improve(false); - sm_tester.do_include_qcd_corrections(false); - - const std::complex expected_cphhVPVP = sm_tester.get_eff_CphhVPVP(); - const std::complex expected_cphhVGVG = sm_tester.get_eff_CphhVGVG(); - - SM_effective_couplings eff_cp(model, qedqcd, physical_inputs); - eff_cp.do_run_couplings(false); - eff_cp.do_include_qcd_corrections(false); - eff_cp.calculate_effective_couplings(); - - const std::complex obtained_cphhVPVP = eff_cp.get_eff_CphhVPVP(); - const std::complex obtained_cphhVGVG = eff_cp.get_eff_CphhVGVG(); - - BOOST_CHECK_CLOSE_FRACTION(-Re(expected_cphhVPVP), Re(obtained_cphhVPVP), 1.0e-10); - BOOST_CHECK_CLOSE_FRACTION(-Im(expected_cphhVPVP), Im(obtained_cphhVPVP), 1.0e-10); - BOOST_CHECK_CLOSE_FRACTION(-Re(expected_cphhVGVG), Re(obtained_cphhVGVG), 1.0e-10); - BOOST_CHECK_CLOSE_FRACTION(-Im(expected_cphhVGVG), Im(obtained_cphhVGVG), 1.0e-10); -} diff --git a/test/test_effective_couplings.cpp b/test/test_effective_couplings.cpp deleted file mode 100644 index d0b06d3090..0000000000 --- a/test/test_effective_couplings.cpp +++ /dev/null @@ -1,85 +0,0 @@ - -#define BOOST_TEST_DYN_LINK -#define BOOST_TEST_MODULE test_effective_couplings - -#include - -#include "effective_couplings.hpp" -#include "wrappers.hpp" - -using namespace flexiblesusy; -using namespace effective_couplings; - -BOOST_AUTO_TEST_CASE( test_scaling_function ) -{ - BOOST_CHECK_EQUAL(Re(scaling_function(0.)), 0.); - BOOST_CHECK_EQUAL(Im(scaling_function(0.)), 0.); - BOOST_CHECK_CLOSE_FRACTION(Re(scaling_function(0.5)), 0.616850275068085, 1.0e-14); - BOOST_CHECK_EQUAL(Im(scaling_function(0.5)), 0.); - BOOST_CHECK_CLOSE_FRACTION(Re(scaling_function(0.75)), 1.0966227112321507, 1.0e-14); - BOOST_CHECK_EQUAL(Im(scaling_function(0.75)), 0.); - BOOST_CHECK_CLOSE_FRACTION(Re(scaling_function(1.)), 2.4674011002723395, 1.0e-14); - BOOST_CHECK_EQUAL(Im(scaling_function(1.)), 0.); - BOOST_CHECK_CLOSE_FRACTION(Re(scaling_function(1.5)), 2.0338065747041805, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Im(scaling_function(1.5)), 2.0686726270330347, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Re(scaling_function(2.)), 1.6905817003766437, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Im(scaling_function(2.)), 2.7689167860486803, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Re(scaling_function(10.)), -0.8393464248213007, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Im(scaling_function(10.)), 5.712818037269832, 1.0e-14); -} - -BOOST_AUTO_TEST_CASE( test_AS0 ) -{ - BOOST_CHECK_CLOSE_FRACTION(Re(AS0(0.5)), 0.46740110027233994, 1.0e-14); - BOOST_CHECK_EQUAL(Im(AS0(0.5)), 0.); - BOOST_CHECK_CLOSE_FRACTION(Re(AS0(0.95)), 0.9526716202288444, 1.0e-14); - BOOST_CHECK_EQUAL(Im(AS0(0.95)), 0.); - BOOST_CHECK_CLOSE_FRACTION(Re(AS0(1.)), 1.4674011002723395, 1.0e-14); - BOOST_CHECK_EQUAL(Im(AS0(1.)), 0.); - BOOST_CHECK_CLOSE_FRACTION(Re(AS0(1.02)), 1.3721001820578436, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Im(AS0(1.02)), 0.4256252450396851, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Re(AS0(3.2)), -0.20877378813795655, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Im(AS0(3.2)), 0.363685421601937, 1.0e-14); -} - -BOOST_AUTO_TEST_CASE( test_AS12 ) -{ - BOOST_CHECK_CLOSE_FRACTION(Re(AS12(0.2)), 1.4012357867134255, 1.0e-14); - BOOST_CHECK_EQUAL(Im(AS12(0.2)), 0.); - BOOST_CHECK_CLOSE_FRACTION(Re(AS12(0.8)), 1.7338885729293136, 1.0e-14); - BOOST_CHECK_EQUAL(Im(AS12(0.8)), 0.); - BOOST_CHECK_EQUAL(Re(AS12(1.)), 2.); - BOOST_CHECK_EQUAL(Im(AS12(1.)), 0.); - BOOST_CHECK_CLOSE_FRACTION(Re(AS12(1.3)), 2.317171235447624, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Im(AS12(1.3)), 0.5838721970979124, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Re(AS12(4.)), 0.7748836242498889, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Im(AS12(4.)), 1.5515044702747753, 1.0e-14); -} - -BOOST_AUTO_TEST_CASE( test_AS1 ) -{ - BOOST_CHECK_CLOSE_FRACTION(Re(AS1(0.05)), -7.075200061042707, 1.0e-14); - BOOST_CHECK_EQUAL(Im(AS1(0.05)), 0.); - BOOST_CHECK_EQUAL(Re(AS1(0.5)), -8.); - BOOST_CHECK_EQUAL(Im(AS1(0.5)), 0.); - BOOST_CHECK_CLOSE_FRACTION(Re(AS1(0.95)), -10.57221337461788, 1.0e-14); - BOOST_CHECK_EQUAL(Im(AS1(0.95)), 0.); - BOOST_CHECK_CLOSE_FRACTION(Re(AS1(1.)), -12.402203300817018, 1.0e-14); - BOOST_CHECK_EQUAL(Im(AS1(1.)), 0.); - BOOST_CHECK_CLOSE_FRACTION(Re(AS1(1.4)), -9.960646594444304, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Im(AS1(1.4)), -5.162564739778429, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Re(AS1(6.7)), -2.3587910058759363, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Im(AS1(6.7)), -4.177455742756774, 1.0e-14); -} - -BOOST_AUTO_TEST_CASE( test_AP12 ) -{ - BOOST_CHECK_CLOSE_FRACTION(Re(AP12(0.3)), 1.119940762029675, 1.0e-14); - BOOST_CHECK_EQUAL(Im(AP12(0.3)), 0.); - BOOST_CHECK_CLOSE_FRACTION(Re(AP12(1.)), 2.4674011002723395, 1.0e-14); - BOOST_CHECK_EQUAL(Im(AP12(1.)), 0.); - BOOST_CHECK_CLOSE_FRACTION(Re(AP12(1.1)), 2.1550612079680067, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Im(AP12(1.1)), 0.8887315770636819, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Re(AP12(9.8)), -0.08170543420654755, 1.0e-14); - BOOST_CHECK_CLOSE_FRACTION(Im(AP12(9.8)), 0.5795253251779525, 1.0e-14); -} From e68c22aa10f32a0de49d389946c009b59c11a857 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 10 Jun 2021 14:08:55 +0200 Subject: [PATCH 002/477] speedup 1L decay amplitudes --- meta/generic_loop_decay_diagram_classes.m | 2 +- src/decays/one_loop_decay_diagrams.cpp | 1607 ++++++++++------- utils/loop_decays/meta/generate_loop_decays.m | 52 +- 3 files changed, 1008 insertions(+), 653 deletions(-) diff --git a/meta/generic_loop_decay_diagram_classes.m b/meta/generic_loop_decay_diagram_classes.m index 91fc19c1af..26aaed04dc 100644 --- a/meta/generic_loop_decay_diagram_classes.m +++ b/meta/generic_loop_decay_diagram_classes.m @@ -1,4 +1,4 @@ -(* Generated at Sat 4 Jan 2020 00:13:09 *) +(* Generated at Wed 2 Jun 2021 20:27:47 *) {{"diagram_SSS_t1g1n1_FFF", {{0, 0, 0, 1, 0, 0}, {0, 0, 0, 0, 1, 0}, {0, 0, 0, 0, 0, 1}, {1, 0, 0, 0, 1, 1}, {0, 1, 0, 1, 0, 1}, {0, 0, 1, 1, 1, 0}}, {{1, 4} -> Field[1], {2, 5} -> Field[2], diff --git a/src/decays/one_loop_decay_diagrams.cpp b/src/decays/one_loop_decay_diagrams.cpp index 497a66fcd2..29266ce899 100644 --- a/src/decays/one_loop_decay_diagrams.cpp +++ b/src/decays/one_loop_decay_diagrams.cpp @@ -59,14 +59,17 @@ Decay_amplitude_SSS calculate_diagram_SSS_t1g1n1_FFF( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto c0tmp2 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLF4*mLF4, mLF6*mLF6, mLF5*mLF5, scale*scale); - const auto c1tmp3 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLF4*mLF4, mLF6*mLF6, mLF5*mLF5, scale*scale); - const auto c2tmp4 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLF4*mLF4, mLF6*mLF6, mLF5*mLF5, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLF5*mLF5, mLF6*mLF6, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLF4*mLF4, mLF6*mLF6, + mLF5*mLF5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c1tmp3 = C_coeffs.at(1); + const auto c2tmp4 = C_coeffs.at(2); Decay_amplitude_SSS result; @@ -137,8 +140,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t1g2n2_SSS( { auto& lib = Loop_library::get(); - const auto c0tmp1 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLS5*mLS5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLS4*mLS4, mLS6*mLS6, + mLS5*mLS5, scale*scale); + + const auto c0tmp1 = C_coeffs.at(0); Decay_amplitude_SSS result; @@ -176,8 +182,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t1g3n3_UUU( { auto& lib = Loop_library::get(); - const auto c0tmp1 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLU4*mLU4, mLU6*mLU6, mLU5*mLU5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLU4*mLU4, mLU6*mLU6, + mLU5*mLU5, scale*scale); + + const auto c0tmp1 = C_coeffs.at(0); Decay_amplitude_SSS result; @@ -215,14 +224,17 @@ Decay_amplitude_SSS calculate_diagram_SSS_t1g4n4_SSV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto c0tmp2 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLS5*mLS5, scale*scale); - const auto c1tmp3 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLS5*mLS5, scale*scale); - const auto c2tmp4 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLS5*mLS5, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLS5*mLS5, mLV6*mLV6, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLS4*mLS4, mLV6*mLV6, + mLS5*mLS5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c1tmp3 = C_coeffs.at(1); + const auto c2tmp4 = C_coeffs.at(2); Decay_amplitude_SSS result; @@ -263,14 +275,17 @@ Decay_amplitude_SSS calculate_diagram_SSS_t1g5n5_SVS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLS6*mLS6, mLV5*mLV5, - scale*scale); - const auto c0tmp2 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLV5*mLV5, scale*scale); - const auto c1tmp3 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLV5*mLV5, scale*scale); - const auto c2tmp4 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLV5*mLV5, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLS6*mLS6, mLV5*mLV5, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLS4*mLS4, mLS6*mLS6, + mLV5*mLV5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c1tmp3 = C_coeffs.at(1); + const auto c2tmp4 = C_coeffs.at(2); Decay_amplitude_SSS result; @@ -311,14 +326,17 @@ Decay_amplitude_SSS calculate_diagram_SSS_t1g6n6_VSS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLS5*mLS5, mLS6*mLS6, - scale*scale); - const auto c0tmp2 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c1tmp3 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c2tmp4 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLS5*mLS5, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLS5*mLS5, mLS6*mLS6, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLV4*mLV4, mLS6*mLS6, + mLS5*mLS5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c1tmp3 = C_coeffs.at(1); + const auto c2tmp4 = C_coeffs.at(2); Decay_amplitude_SSS result; @@ -359,14 +377,17 @@ Decay_amplitude_SSS calculate_diagram_SSS_t1g7n7_SVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLV5*mLV5, mLV6*mLV6, - scale*scale); - const auto c0tmp2 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c1tmp3 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c2tmp4 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLV5*mLV5, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLV5*mLV5, mLV6*mLV6, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLS4*mLS4, mLV6*mLV6, + mLV5*mLV5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c1tmp3 = C_coeffs.at(1); + const auto c2tmp4 = C_coeffs.at(2); Decay_amplitude_SSS result; @@ -407,14 +428,17 @@ Decay_amplitude_SSS calculate_diagram_SSS_t1g8n8_VSV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto c0tmp2 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLS5*mLS5, scale*scale); - const auto c1tmp3 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLS5*mLS5, scale*scale); - const auto c2tmp4 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLS5*mLS5, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLS5*mLS5, mLV6*mLV6, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLV4*mLV4, mLV6*mLV6, + mLS5*mLS5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c1tmp3 = C_coeffs.at(1); + const auto c2tmp4 = C_coeffs.at(2); Decay_amplitude_SSS result; @@ -455,14 +479,17 @@ Decay_amplitude_SSS calculate_diagram_SSS_t1g9n9_VVS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLS6*mLS6, mLV5*mLV5, - scale*scale); - const auto c0tmp2 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLV5*mLV5, scale*scale); - const auto c1tmp3 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLV5*mLV5, scale*scale); - const auto c2tmp4 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLV5*mLV5, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLS6*mLS6, mLV5*mLV5, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLV4*mLV4, mLS6*mLS6, + mLV5*mLV5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c1tmp3 = C_coeffs.at(1); + const auto c2tmp4 = C_coeffs.at(2); Decay_amplitude_SSS result; @@ -503,8 +530,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t1g10n10_VVV( { auto& lib = Loop_library::get(); - const auto c0tmp1 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLV5*mLV5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLV4*mLV4, mLV6*mLV6, + mLV5*mLV5, scale*scale); + + const auto c0tmp1 = C_coeffs.at(0); Decay_amplitude_SSS result; @@ -540,7 +570,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t2g1n11_SS( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLS5*mLS5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLS5*mLS5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SSS result; @@ -576,7 +609,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t2g2n12_SV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV5*mLV5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV5*mLV5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SSS result; @@ -612,7 +648,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t3g1n13_SS( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLS5*mLS5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLS5*mLS5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SSS result; @@ -648,7 +687,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t3g2n14_SV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV5*mLV5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV5*mLV5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SSS result; @@ -684,8 +726,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t4g1n15_SS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLS4*mLS4, mLS5*mLS5, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS4*mLS4, mLS5*mLS5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSS result; @@ -720,8 +764,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t4g2n16_VV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLV4*mLV4, mLV5*mLV5, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLV4*mLV4, mLV5*mLV5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSS result; @@ -757,7 +803,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t5g1n17_SS( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLS5*mLS5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLS5*mLS5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SSS result; @@ -793,7 +842,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t5g2n18_SV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV5*mLV5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV5*mLV5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SSS result; @@ -829,8 +881,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t6g1n19_SS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLS4*mLS4, mLS5*mLS5, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLS4*mLS4, mLS5*mLS5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSS result; @@ -865,8 +919,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t6g2n20_VV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLV4*mLV4, mLV5*mLV5, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLV4*mLV4, mLV5*mLV5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSS result; @@ -902,8 +958,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t7g1n21_SS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLS4*mLS4, mLS5*mLS5, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLS4*mLS4, mLS5*mLS5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSS result; @@ -938,8 +996,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t7g2n22_VV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLV4*mLV4, mLV5*mLV5, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLV4*mLV4, mLV5*mLV5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSS result; @@ -980,11 +1040,15 @@ Decay_amplitude_SSS calculate_diagram_SSS_t8g1n23_SFF( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLF6*mLF6, scale*scale); - const auto b0tmp2 = lib.B0(mext3*mext3, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b1tmp3 = lib.B1(mext3*mext3, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLF6*mLF6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b1tmp3 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -1025,8 +1089,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t8g2n24_SSS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLS5*mLS5, mLS6*mLS6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSS result; @@ -1064,8 +1130,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t8g3n25_SUU( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLU5*mLU5, mLU6*mLU6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLU5*mLU5, mLU6*mLU6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSS result; @@ -1104,11 +1172,15 @@ Decay_amplitude_SSS calculate_diagram_SSS_t8g4n26_SSV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV6*mLV6, scale*scale); - const auto b0tmp2 = lib.B0(mext3*mext3, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto b1tmp3 = lib.B1(mext3*mext3, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV6*mLV6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b1tmp3 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -1147,8 +1219,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t8g5n27_SVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSS result; @@ -1191,10 +1265,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t8g6n28_VFF( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b1tmp2 = lib.B1(mext3*mext3, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -1235,10 +1310,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t8g7n29_VSS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLS5*mLS5, mLS6*mLS6, - scale*scale); - const auto b1tmp2 = lib.B1(mext3*mext3, mLS5*mLS5, mLS6*mLS6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -1279,10 +1355,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t8g8n30_VUU( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLU5*mLU5, mLU6*mLU6, - scale*scale); - const auto b1tmp2 = lib.B1(mext3*mext3, mLU5*mLU5, mLU6*mLU6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLU5*mLU5, mLU6*mLU6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -1322,10 +1399,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t8g9n31_VSV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto b1tmp2 = lib.B1(mext3*mext3, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -1366,10 +1444,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t8g10n32_VVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLV5*mLV5, mLV6*mLV6, - scale*scale); - const auto b1tmp2 = lib.B1(mext3*mext3, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -1411,11 +1490,15 @@ Decay_amplitude_SSS calculate_diagram_SSS_t9g1n33_SFF( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLF6*mLF6, scale*scale); - const auto b0tmp2 = lib.B0(mext2*mext2, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b1tmp3 = lib.B1(mext2*mext2, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLF6*mLF6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b1tmp3 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -1456,8 +1539,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t9g2n34_SSS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLS5*mLS5, mLS6*mLS6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSS result; @@ -1495,8 +1580,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t9g3n35_SUU( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLU5*mLU5, mLU6*mLU6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLU5*mLU5, mLU6*mLU6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSS result; @@ -1535,11 +1622,15 @@ Decay_amplitude_SSS calculate_diagram_SSS_t9g4n36_SSV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV6*mLV6, scale*scale); - const auto b0tmp2 = lib.B0(mext2*mext2, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto b1tmp3 = lib.B1(mext2*mext2, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV6*mLV6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b1tmp3 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -1578,8 +1669,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t9g5n37_SVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSS result; @@ -1622,10 +1715,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t9g6n38_VFF( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b1tmp2 = lib.B1(mext2*mext2, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -1666,10 +1760,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t9g7n39_VSS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLS5*mLS5, mLS6*mLS6, - scale*scale); - const auto b1tmp2 = lib.B1(mext2*mext2, mLS5*mLS5, mLS6*mLS6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -1710,10 +1805,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t9g8n40_VUU( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLU5*mLU5, mLU6*mLU6, - scale*scale); - const auto b1tmp2 = lib.B1(mext2*mext2, mLU5*mLU5, mLU6*mLU6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLU5*mLU5, mLU6*mLU6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -1753,10 +1849,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t9g9n41_VSV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto b1tmp2 = lib.B1(mext2*mext2, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -1797,10 +1894,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t9g10n42_VVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLV5*mLV5, mLV6*mLV6, - scale*scale); - const auto b1tmp2 = lib.B1(mext2*mext2, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -1842,11 +1940,15 @@ Decay_amplitude_SSS calculate_diagram_SSS_t10g1n43_SFF( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLF6*mLF6, scale*scale); - const auto b0tmp2 = lib.B0(mext1*mext1, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b1tmp3 = lib.B1(mext1*mext1, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLF6*mLF6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b1tmp3 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -1887,8 +1989,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t10g2n44_SSS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLS5*mLS5, mLS6*mLS6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSS result; @@ -1926,8 +2030,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t10g3n45_SUU( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLU5*mLU5, mLU6*mLU6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLU5*mLU5, mLU6*mLU6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSS result; @@ -1966,11 +2072,15 @@ Decay_amplitude_SSS calculate_diagram_SSS_t10g4n46_SSV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV6*mLV6, scale*scale); - const auto b0tmp2 = lib.B0(mext1*mext1, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto b1tmp3 = lib.B1(mext1*mext1, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV6*mLV6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b1tmp3 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -2009,8 +2119,10 @@ Decay_amplitude_SSS calculate_diagram_SSS_t10g5n47_SVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSS result; @@ -2053,10 +2165,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t10g6n48_VFF( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -2097,10 +2210,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t10g7n49_VSS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLS5*mLS5, mLS6*mLS6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLS5*mLS5, mLS6*mLS6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -2141,10 +2255,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t10g8n50_VUU( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLU5*mLU5, mLU6*mLU6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLU5*mLU5, mLU6*mLU6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLU5*mLU5, mLU6*mLU6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -2184,10 +2299,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t10g9n51_VSV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -2228,10 +2344,11 @@ Decay_amplitude_SSS calculate_diagram_SSS_t10g10n52_VVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLV5*mLV5, mLV6*mLV6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSS result; @@ -2279,20 +2396,20 @@ Decay_amplitude_SVV calculate_diagram_SVV_t1g1n1_FFF( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto c0tmp2 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLF4*mLF4, mLF6*mLF6, mLF5*mLF5, scale*scale); - const auto c00tmp3 = lib.C00(mext2*mext2, mext3*mext3, mext1* - mext1, mLF4*mLF4, mLF6*mLF6, mLF5*mLF5, scale*scale); - const auto c1tmp4 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLF4*mLF4, mLF6*mLF6, mLF5*mLF5, scale*scale); - const auto c12tmp5 = lib.C12(mext2*mext2, mext3*mext3, mext1* - mext1, mLF4*mLF4, mLF6*mLF6, mLF5*mLF5, scale*scale); - const auto c2tmp6 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLF4*mLF4, mLF6*mLF6, mLF5*mLF5, scale*scale); - const auto c22tmp7 = lib.C22(mext2*mext2, mext3*mext3, mext1* - mext1, mLF4*mLF4, mLF6*mLF6, mLF5*mLF5, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLF5*mLF5, mLF6*mLF6, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLF4*mLF4, mLF6*mLF6, + mLF5*mLF5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c00tmp3 = C_coeffs.at(3); + const auto c1tmp4 = C_coeffs.at(1); + const auto c12tmp5 = C_coeffs.at(5); + const auto c2tmp6 = C_coeffs.at(2); + const auto c22tmp7 = C_coeffs.at(6); Decay_amplitude_SVV result; @@ -2436,14 +2553,14 @@ Decay_amplitude_SVV calculate_diagram_SVV_t1g2n2_SSS( { auto& lib = Loop_library::get(); - const auto c00tmp1 = lib.C00(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c12tmp2 = lib.C12(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c2tmp3 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c22tmp4 = lib.C22(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLS5*mLS5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLS4*mLS4, mLS6*mLS6, + mLS5*mLS5, scale*scale); + + const auto c00tmp1 = C_coeffs.at(3); + const auto c12tmp2 = C_coeffs.at(5); + const auto c2tmp3 = C_coeffs.at(2); + const auto c22tmp4 = C_coeffs.at(6); Decay_amplitude_SVV result; @@ -2489,14 +2606,14 @@ Decay_amplitude_SVV calculate_diagram_SVV_t1g3n3_UUU( { auto& lib = Loop_library::get(); - const auto c00tmp1 = lib.C00(mext2*mext2, mext3*mext3, mext1* - mext1, mLU4*mLU4, mLU6*mLU6, mLU5*mLU5, scale*scale); - const auto c12tmp2 = lib.C12(mext2*mext2, mext3*mext3, mext1* - mext1, mLU4*mLU4, mLU6*mLU6, mLU5*mLU5, scale*scale); - const auto c2tmp3 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLU4*mLU4, mLU6*mLU6, mLU5*mLU5, scale*scale); - const auto c22tmp4 = lib.C22(mext2*mext2, mext3*mext3, mext1* - mext1, mLU4*mLU4, mLU6*mLU6, mLU5*mLU5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLU4*mLU4, mLU6*mLU6, + mLU5*mLU5, scale*scale); + + const auto c00tmp1 = C_coeffs.at(3); + const auto c12tmp2 = C_coeffs.at(5); + const auto c2tmp3 = C_coeffs.at(2); + const auto c22tmp4 = C_coeffs.at(6); Decay_amplitude_SVV result; @@ -2542,8 +2659,11 @@ Decay_amplitude_SVV calculate_diagram_SVV_t1g4n4_SSV( { auto& lib = Loop_library::get(); - const auto c0tmp1 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLS5*mLS5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLS4*mLS4, mLV6*mLV6, + mLS5*mLS5, scale*scale); + + const auto c0tmp1 = C_coeffs.at(0); Decay_amplitude_SVV result; @@ -2582,14 +2702,14 @@ Decay_amplitude_SVV calculate_diagram_SVV_t1g5n5_SVS( { auto& lib = Loop_library::get(); - const auto c00tmp1 = lib.C00(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLV5*mLV5, scale*scale); - const auto c12tmp2 = lib.C12(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLV5*mLV5, scale*scale); - const auto c2tmp3 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLV5*mLV5, scale*scale); - const auto c22tmp4 = lib.C22(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLV5*mLV5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLS4*mLS4, mLS6*mLS6, + mLV5*mLV5, scale*scale); + + const auto c00tmp1 = C_coeffs.at(3); + const auto c12tmp2 = C_coeffs.at(5); + const auto c2tmp3 = C_coeffs.at(2); + const auto c22tmp4 = C_coeffs.at(6); Decay_amplitude_SVV result; @@ -2636,18 +2756,16 @@ Decay_amplitude_SVV calculate_diagram_SVV_t1g6n6_VSS( { auto& lib = Loop_library::get(); - const auto c0tmp1 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c00tmp2 = lib.C00(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c1tmp3 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c12tmp4 = lib.C12(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c2tmp5 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c22tmp6 = lib.C22(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLS5*mLS5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLV4*mLV4, mLS6*mLS6, + mLS5*mLS5, scale*scale); + + const auto c0tmp1 = C_coeffs.at(0); + const auto c00tmp2 = C_coeffs.at(3); + const auto c1tmp3 = C_coeffs.at(1); + const auto c12tmp4 = C_coeffs.at(5); + const auto c2tmp5 = C_coeffs.at(2); + const auto c22tmp6 = C_coeffs.at(6); Decay_amplitude_SVV result; @@ -2700,20 +2818,20 @@ Decay_amplitude_SVV calculate_diagram_SVV_t1g7n7_SVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLV5*mLV5, mLV6*mLV6, - scale*scale); - const auto c0tmp2 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c00tmp3 = lib.C00(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c1tmp4 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c12tmp5 = lib.C12(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c2tmp6 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c22tmp7 = lib.C22(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLV5*mLV5, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLV5*mLV5, mLV6*mLV6, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLS4*mLS4, mLV6*mLV6, + mLV5*mLV5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c00tmp3 = C_coeffs.at(3); + const auto c1tmp4 = C_coeffs.at(1); + const auto c12tmp5 = C_coeffs.at(5); + const auto c2tmp6 = C_coeffs.at(2); + const auto c22tmp7 = C_coeffs.at(6); Decay_amplitude_SVV result; @@ -2765,20 +2883,20 @@ Decay_amplitude_SVV calculate_diagram_SVV_t1g8n8_VSV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto c0tmp2 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLS5*mLS5, scale*scale); - const auto c00tmp3 = lib.C00(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLS5*mLS5, scale*scale); - const auto c1tmp4 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLS5*mLS5, scale*scale); - const auto c12tmp5 = lib.C12(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLS5*mLS5, scale*scale); - const auto c2tmp6 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLS5*mLS5, scale*scale); - const auto c22tmp7 = lib.C22(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLS5*mLS5, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLS5*mLS5, mLV6*mLV6, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLV4*mLV4, mLV6*mLV6, + mLS5*mLS5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c00tmp3 = C_coeffs.at(3); + const auto c1tmp4 = C_coeffs.at(1); + const auto c12tmp5 = C_coeffs.at(5); + const auto c2tmp6 = C_coeffs.at(2); + const auto c22tmp7 = C_coeffs.at(6); Decay_amplitude_SVV result; @@ -2831,8 +2949,11 @@ Decay_amplitude_SVV calculate_diagram_SVV_t1g9n9_VVS( { auto& lib = Loop_library::get(); - const auto c0tmp1 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLV5*mLV5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLV4*mLV4, mLS6*mLS6, + mLV5*mLV5, scale*scale); + + const auto c0tmp1 = C_coeffs.at(0); Decay_amplitude_SVV result; @@ -2874,20 +2995,20 @@ Decay_amplitude_SVV calculate_diagram_SVV_t1g10n10_VVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLV5*mLV5, mLV6*mLV6, - scale*scale); - const auto c0tmp2 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c00tmp3 = lib.C00(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c1tmp4 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c12tmp5 = lib.C12(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c2tmp6 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c22tmp7 = lib.C22(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLV5*mLV5, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLV5*mLV5, mLV6*mLV6, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLV4*mLV4, mLV6*mLV6, + mLV5*mLV5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c00tmp3 = C_coeffs.at(3); + const auto c1tmp4 = C_coeffs.at(1); + const auto c12tmp5 = C_coeffs.at(5); + const auto c2tmp6 = C_coeffs.at(2); + const auto c22tmp7 = C_coeffs.at(6); Decay_amplitude_SVV result; @@ -2938,7 +3059,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t2g1n11_VS( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLS5*mLS5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLS5*mLS5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SVV result; @@ -2980,7 +3104,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t2g2n12_VV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV5*mLV5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV5*mLV5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SVV result; @@ -3017,7 +3144,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t3g1n13_VS( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLS5*mLS5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLS5*mLS5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SVV result; @@ -3059,7 +3189,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t3g2n14_VV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV5*mLV5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV5*mLV5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SVV result; @@ -3096,8 +3229,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t4g1n15_SS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLS4*mLS4, mLS5*mLS5, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS4*mLS4, mLS5*mLS5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SVV result; @@ -3138,8 +3273,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t4g2n16_VV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLV4*mLV4, mLV5*mLV5, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLV4*mLV4, mLV5*mLV5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SVV result; @@ -3175,7 +3312,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t5g1n17_SS( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLS5*mLS5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLS5*mLS5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SVV result; @@ -3211,7 +3351,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t5g2n18_SV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV5*mLV5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV5*mLV5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SVV result; @@ -3247,8 +3390,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t6g1n19_SV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLS4*mLS4, mLV5*mLV5, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLS4*mLS4, mLV5*mLV5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SVV result; @@ -3283,8 +3428,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t7g1n20_SV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLS4*mLS4, mLV5*mLV5, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLS4*mLS4, mLV5*mLV5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SVV result; @@ -3328,13 +3475,16 @@ Decay_amplitude_SVV calculate_diagram_SVV_t8g6n26_VFF( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLF6*mLF6, scale*scale); - const auto b0tmp2 = lib.B0(mext3*mext3, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b00tmp3 = lib.B00(mext3*mext3, mLF5*mLF5, mLF6* - mLF6, scale*scale); - const auto b1tmp4 = lib.B1(mext3*mext3, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLF6*mLF6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b00tmp3 = B_coeffs.at(2); + const auto b1tmp4 = B_coeffs.at(1); Decay_amplitude_SVV result; @@ -3378,8 +3528,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t8g7n27_VSS( { auto& lib = Loop_library::get(); - const auto b00tmp1 = lib.B00(mext3*mext3, mLS5*mLS5, mLS6* - mLS6, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b00tmp1 = B_coeffs.at(2); Decay_amplitude_SVV result; @@ -3417,8 +3569,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t8g8n28_VUU( { auto& lib = Loop_library::get(); - const auto b00tmp1 = lib.B00(mext3*mext3, mLU5*mLU5, mLU6* - mLU6, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLU5*mLU5, mLU6*mLU6, scale*scale); + + const auto b00tmp1 = B_coeffs.at(2); Decay_amplitude_SVV result; @@ -3456,8 +3610,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t8g9n29_VSV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SVV result; @@ -3499,13 +3655,16 @@ Decay_amplitude_SVV calculate_diagram_SVV_t8g10n30_VVV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV6*mLV6, scale*scale); - const auto b0tmp2 = lib.B0(mext3*mext3, mLV5*mLV5, mLV6*mLV6, - scale*scale); - const auto b00tmp3 = lib.B00(mext3*mext3, mLV5*mLV5, mLV6* - mLV6, scale*scale); - const auto b1tmp4 = lib.B1(mext3*mext3, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV6*mLV6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b00tmp3 = B_coeffs.at(2); + const auto b1tmp4 = B_coeffs.at(1); Decay_amplitude_SVV result; @@ -3553,13 +3712,16 @@ Decay_amplitude_SVV calculate_diagram_SVV_t9g6n36_VFF( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLF6*mLF6, scale*scale); - const auto b0tmp2 = lib.B0(mext2*mext2, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b00tmp3 = lib.B00(mext2*mext2, mLF5*mLF5, mLF6* - mLF6, scale*scale); - const auto b1tmp4 = lib.B1(mext2*mext2, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLF6*mLF6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b00tmp3 = B_coeffs.at(2); + const auto b1tmp4 = B_coeffs.at(1); Decay_amplitude_SVV result; @@ -3603,8 +3765,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t9g7n37_VSS( { auto& lib = Loop_library::get(); - const auto b00tmp1 = lib.B00(mext2*mext2, mLS5*mLS5, mLS6* - mLS6, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b00tmp1 = B_coeffs.at(2); Decay_amplitude_SVV result; @@ -3642,8 +3806,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t9g8n38_VUU( { auto& lib = Loop_library::get(); - const auto b00tmp1 = lib.B00(mext2*mext2, mLU5*mLU5, mLU6* - mLU6, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLU5*mLU5, mLU6*mLU6, scale*scale); + + const auto b00tmp1 = B_coeffs.at(2); Decay_amplitude_SVV result; @@ -3681,8 +3847,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t9g9n39_VSV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SVV result; @@ -3724,13 +3892,16 @@ Decay_amplitude_SVV calculate_diagram_SVV_t9g10n40_VVV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV6*mLV6, scale*scale); - const auto b0tmp2 = lib.B0(mext2*mext2, mLV5*mLV5, mLV6*mLV6, - scale*scale); - const auto b00tmp3 = lib.B00(mext2*mext2, mLV5*mLV5, mLV6* - mLV6, scale*scale); - const auto b1tmp4 = lib.B1(mext2*mext2, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV6*mLV6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b00tmp3 = B_coeffs.at(2); + const auto b1tmp4 = B_coeffs.at(1); Decay_amplitude_SVV result; @@ -3774,11 +3945,15 @@ Decay_amplitude_SVV calculate_diagram_SVV_t10g1n41_SFF( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLF6*mLF6, scale*scale); - const auto b0tmp2 = lib.B0(mext1*mext1, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b1tmp3 = lib.B1(mext1*mext1, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLF6*mLF6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b1tmp3 = B_coeffs.at(1); Decay_amplitude_SVV result; @@ -3819,8 +3994,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t10g2n42_SSS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLS5*mLS5, mLS6*mLS6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SVV result; @@ -3858,8 +4035,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t10g3n43_SUU( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLU5*mLU5, mLU6*mLU6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLU5*mLU5, mLU6*mLU6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SVV result; @@ -3898,11 +4077,15 @@ Decay_amplitude_SVV calculate_diagram_SVV_t10g4n44_SSV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV6*mLV6, scale*scale); - const auto b0tmp2 = lib.B0(mext1*mext1, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto b1tmp3 = lib.B1(mext1*mext1, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV6*mLV6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b1tmp3 = B_coeffs.at(1); Decay_amplitude_SVV result; @@ -3941,8 +4124,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t10g5n45_SVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SVV result; @@ -3987,10 +4172,11 @@ Decay_amplitude_SVV calculate_diagram_SVV_t10g6n46_VFF( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SVV result; @@ -4033,10 +4219,11 @@ Decay_amplitude_SVV calculate_diagram_SVV_t10g7n47_VSS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLS5*mLS5, mLS6*mLS6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLS5*mLS5, mLS6*mLS6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SVV result; @@ -4077,8 +4264,10 @@ Decay_amplitude_SVV calculate_diagram_SVV_t10g8n48_VUU( { auto& lib = Loop_library::get(); - const auto b1tmp1 = lib.B1(mext1*mext1, mLU5*mLU5, mLU6*mLU6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLU5*mLU5, mLU6*mLU6, scale*scale); + + const auto b1tmp1 = B_coeffs.at(1); Decay_amplitude_SVV result; @@ -4120,10 +4309,11 @@ Decay_amplitude_SVV calculate_diagram_SVV_t10g9n49_VSV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SVV result; @@ -4166,10 +4356,11 @@ Decay_amplitude_SVV calculate_diagram_SVV_t10g10n50_VVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLV5*mLV5, mLV6*mLV6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SVV result; @@ -4215,14 +4406,17 @@ Decay_amplitude_SSV calculate_diagram_SSV_t1g1n1_FFF( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto c0tmp2 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLF4*mLF4, mLF6*mLF6, mLF5*mLF5, scale*scale); - const auto c1tmp3 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLF4*mLF4, mLF6*mLF6, mLF5*mLF5, scale*scale); - const auto c2tmp4 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLF4*mLF4, mLF6*mLF6, mLF5*mLF5, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLF5*mLF5, mLF6*mLF6, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLF4*mLF4, mLF6*mLF6, + mLF5*mLF5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c1tmp3 = C_coeffs.at(1); + const auto c2tmp4 = C_coeffs.at(2); Decay_amplitude_SSV result; @@ -4277,12 +4471,13 @@ Decay_amplitude_SSV calculate_diagram_SSV_t1g2n2_SSS( { auto& lib = Loop_library::get(); - const auto c0tmp1 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c1tmp2 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c2tmp3 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLS5*mLS5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLS4*mLS4, mLS6*mLS6, + mLS5*mLS5, scale*scale); + + const auto c0tmp1 = C_coeffs.at(0); + const auto c1tmp2 = C_coeffs.at(1); + const auto c2tmp3 = C_coeffs.at(2); Decay_amplitude_SSV result; @@ -4320,12 +4515,13 @@ Decay_amplitude_SSV calculate_diagram_SSV_t1g3n3_UUU( { auto& lib = Loop_library::get(); - const auto c0tmp1 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLU4*mLU4, mLU6*mLU6, mLU5*mLU5, scale*scale); - const auto c1tmp2 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLU4*mLU4, mLU6*mLU6, mLU5*mLU5, scale*scale); - const auto c2tmp3 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLU4*mLU4, mLU6*mLU6, mLU5*mLU5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLU4*mLU4, mLU6*mLU6, + mLU5*mLU5, scale*scale); + + const auto c0tmp1 = C_coeffs.at(0); + const auto c1tmp2 = C_coeffs.at(1); + const auto c2tmp3 = C_coeffs.at(2); Decay_amplitude_SSV result; @@ -4363,12 +4559,13 @@ Decay_amplitude_SSV calculate_diagram_SSV_t1g4n4_SSV( { auto& lib = Loop_library::get(); - const auto c0tmp1 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLS5*mLS5, scale*scale); - const auto c1tmp2 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLS5*mLS5, scale*scale); - const auto c2tmp3 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLS5*mLS5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLS4*mLS4, mLV6*mLV6, + mLS5*mLS5, scale*scale); + + const auto c0tmp1 = C_coeffs.at(0); + const auto c1tmp2 = C_coeffs.at(1); + const auto c2tmp3 = C_coeffs.at(2); Decay_amplitude_SSV result; @@ -4407,12 +4604,13 @@ Decay_amplitude_SSV calculate_diagram_SSV_t1g5n5_SVS( { auto& lib = Loop_library::get(); - const auto c0tmp1 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLV5*mLV5, scale*scale); - const auto c1tmp2 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLV5*mLV5, scale*scale); - const auto c2tmp3 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLS6*mLS6, mLV5*mLV5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLS4*mLS4, mLS6*mLS6, + mLV5*mLV5, scale*scale); + + const auto c0tmp1 = C_coeffs.at(0); + const auto c1tmp2 = C_coeffs.at(1); + const auto c2tmp3 = C_coeffs.at(2); Decay_amplitude_SSV result; @@ -4451,20 +4649,17 @@ Decay_amplitude_SSV calculate_diagram_SSV_t1g6n6_VSS( { auto& lib = Loop_library::get(); - const auto c0tmp1 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c00tmp2 = lib.C00(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c1tmp3 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c11tmp4 = lib.C11(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c12tmp5 = lib.C12(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c2tmp6 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLS5*mLS5, scale*scale); - const auto c22tmp7 = lib.C22(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLS5*mLS5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLV4*mLV4, mLS6*mLS6, + mLS5*mLS5, scale*scale); + + const auto c0tmp1 = C_coeffs.at(0); + const auto c00tmp2 = C_coeffs.at(3); + const auto c1tmp3 = C_coeffs.at(1); + const auto c11tmp4 = C_coeffs.at(4); + const auto c12tmp5 = C_coeffs.at(5); + const auto c2tmp6 = C_coeffs.at(2); + const auto c22tmp7 = C_coeffs.at(6); Decay_amplitude_SSV result; @@ -4511,22 +4706,21 @@ Decay_amplitude_SSV calculate_diagram_SSV_t1g7n7_SVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLV5*mLV5, mLV6*mLV6, - scale*scale); - const auto c0tmp2 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c00tmp3 = lib.C00(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c1tmp4 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c11tmp5 = lib.C11(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c12tmp6 = lib.C12(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c2tmp7 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c22tmp8 = lib.C22(mext2*mext2, mext3*mext3, mext1* - mext1, mLS4*mLS4, mLV6*mLV6, mLV5*mLV5, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLV5*mLV5, mLV6*mLV6, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLS4*mLS4, mLV6*mLV6, + mLV5*mLV5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c00tmp3 = C_coeffs.at(3); + const auto c1tmp4 = C_coeffs.at(1); + const auto c11tmp5 = C_coeffs.at(4); + const auto c12tmp6 = C_coeffs.at(5); + const auto c2tmp7 = C_coeffs.at(2); + const auto c22tmp8 = C_coeffs.at(6); Decay_amplitude_SSV result; @@ -4570,12 +4764,13 @@ Decay_amplitude_SSV calculate_diagram_SSV_t1g8n8_VSV( { auto& lib = Loop_library::get(); - const auto c0tmp1 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLS5*mLS5, scale*scale); - const auto c1tmp2 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLS5*mLS5, scale*scale); - const auto c2tmp3 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLS5*mLS5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLV4*mLV4, mLV6*mLV6, + mLS5*mLS5, scale*scale); + + const auto c0tmp1 = C_coeffs.at(0); + const auto c1tmp2 = C_coeffs.at(1); + const auto c2tmp3 = C_coeffs.at(2); Decay_amplitude_SSV result; @@ -4613,12 +4808,13 @@ Decay_amplitude_SSV calculate_diagram_SSV_t1g9n9_VVS( { auto& lib = Loop_library::get(); - const auto c0tmp1 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLV5*mLV5, scale*scale); - const auto c1tmp2 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLV5*mLV5, scale*scale); - const auto c2tmp3 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLS6*mLS6, mLV5*mLV5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLV4*mLV4, mLS6*mLS6, + mLV5*mLV5, scale*scale); + + const auto c0tmp1 = C_coeffs.at(0); + const auto c1tmp2 = C_coeffs.at(1); + const auto c2tmp3 = C_coeffs.at(2); Decay_amplitude_SSV result; @@ -4658,12 +4854,13 @@ Decay_amplitude_SSV calculate_diagram_SSV_t1g10n10_VVV( { auto& lib = Loop_library::get(); - const auto c0tmp1 = lib.C0(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c1tmp2 = lib.C1(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLV5*mLV5, scale*scale); - const auto c2tmp3 = lib.C2(mext2*mext2, mext3*mext3, mext1* - mext1, mLV4*mLV4, mLV6*mLV6, mLV5*mLV5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext3*mext3, mext1*mext1, mLV4*mLV4, mLV6*mLV6, + mLV5*mLV5, scale*scale); + + const auto c0tmp1 = C_coeffs.at(0); + const auto c1tmp2 = C_coeffs.at(1); + const auto c2tmp3 = C_coeffs.at(2); Decay_amplitude_SSV result; @@ -4699,7 +4896,10 @@ Decay_amplitude_SSV calculate_diagram_SSV_t2g1n11_VS( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLS5*mLS5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLS5*mLS5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SSV result; @@ -4741,7 +4941,10 @@ Decay_amplitude_SSV calculate_diagram_SSV_t2g2n12_VV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV5*mLV5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV5*mLV5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SSV result; @@ -4778,7 +4981,10 @@ Decay_amplitude_SSV calculate_diagram_SSV_t3g1n13_SS( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLS5*mLS5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLS5*mLS5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SSV result; @@ -4814,7 +5020,10 @@ Decay_amplitude_SSV calculate_diagram_SSV_t3g2n14_SV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV5*mLV5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV5*mLV5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SSV result; @@ -4851,10 +5060,11 @@ Decay_amplitude_SSV calculate_diagram_SSV_t4g1n15_SV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLS4*mLS4, mLV5*mLV5, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLS4*mLS4, mLV5*mLV5, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS4*mLS4, mLV5*mLV5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -4890,7 +5100,10 @@ Decay_amplitude_SSV calculate_diagram_SSV_t5g1n16_SS( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLS5*mLS5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLS5*mLS5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SSV result; @@ -4926,7 +5139,10 @@ Decay_amplitude_SSV calculate_diagram_SSV_t5g2n17_SV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV5*mLV5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV5*mLV5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SSV result; @@ -4963,10 +5179,11 @@ Decay_amplitude_SSV calculate_diagram_SSV_t6g1n18_SV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLS4*mLS4, mLV5*mLV5, - scale*scale); - const auto b1tmp2 = lib.B1(mext2*mext2, mLS4*mLS4, mLV5*mLV5, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLS4*mLS4, mLV5*mLV5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -5011,13 +5228,16 @@ Decay_amplitude_SSV calculate_diagram_SSV_t8g6n26_VFF( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLF6*mLF6, scale*scale); - const auto b0tmp2 = lib.B0(mext3*mext3, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b00tmp3 = lib.B00(mext3*mext3, mLF5*mLF5, mLF6* - mLF6, scale*scale); - const auto b1tmp4 = lib.B1(mext3*mext3, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLF6*mLF6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b00tmp3 = B_coeffs.at(2); + const auto b1tmp4 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -5061,8 +5281,10 @@ Decay_amplitude_SSV calculate_diagram_SSV_t8g7n27_VSS( { auto& lib = Loop_library::get(); - const auto b00tmp1 = lib.B00(mext3*mext3, mLS5*mLS5, mLS6* - mLS6, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b00tmp1 = B_coeffs.at(2); Decay_amplitude_SSV result; @@ -5100,8 +5322,10 @@ Decay_amplitude_SSV calculate_diagram_SSV_t8g9n29_VSV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSV result; @@ -5143,13 +5367,16 @@ Decay_amplitude_SSV calculate_diagram_SSV_t8g10n30_VVV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV6*mLV6, scale*scale); - const auto b0tmp2 = lib.B0(mext3*mext3, mLV5*mLV5, mLV6*mLV6, - scale*scale); - const auto b00tmp3 = lib.B00(mext3*mext3, mLV5*mLV5, mLV6* - mLV6, scale*scale); - const auto b1tmp4 = lib.B1(mext3*mext3, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV6*mLV6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b00tmp3 = B_coeffs.at(2); + const auto b1tmp4 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -5193,11 +5420,15 @@ Decay_amplitude_SSV calculate_diagram_SSV_t9g1n31_SFF( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLF6*mLF6, scale*scale); - const auto b0tmp2 = lib.B0(mext2*mext2, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b1tmp3 = lib.B1(mext2*mext2, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLF6*mLF6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b1tmp3 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -5238,8 +5469,10 @@ Decay_amplitude_SSV calculate_diagram_SSV_t9g2n32_SSS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLS5*mLS5, mLS6*mLS6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSV result; @@ -5277,8 +5510,10 @@ Decay_amplitude_SSV calculate_diagram_SSV_t9g3n33_SUU( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLU5*mLU5, mLU6*mLU6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLU5*mLU5, mLU6*mLU6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSV result; @@ -5317,11 +5552,15 @@ Decay_amplitude_SSV calculate_diagram_SSV_t9g4n34_SSV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV6*mLV6, scale*scale); - const auto b0tmp2 = lib.B0(mext2*mext2, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto b1tmp3 = lib.B1(mext2*mext2, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV6*mLV6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b1tmp3 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -5360,8 +5599,10 @@ Decay_amplitude_SSV calculate_diagram_SSV_t9g5n35_SVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSV result; @@ -5404,10 +5645,11 @@ Decay_amplitude_SSV calculate_diagram_SSV_t9g6n36_VFF( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b1tmp2 = lib.B1(mext2*mext2, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -5448,10 +5690,11 @@ Decay_amplitude_SSV calculate_diagram_SSV_t9g7n37_VSS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLS5*mLS5, mLS6*mLS6, - scale*scale); - const auto b1tmp2 = lib.B1(mext2*mext2, mLS5*mLS5, mLS6*mLS6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -5489,8 +5732,10 @@ Decay_amplitude_SSV calculate_diagram_SSV_t9g8n38_VUU( { auto& lib = Loop_library::get(); - const auto b1tmp1 = lib.B1(mext2*mext2, mLU5*mLU5, mLU6*mLU6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLU5*mLU5, mLU6*mLU6, scale*scale); + + const auto b1tmp1 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -5529,10 +5774,11 @@ Decay_amplitude_SSV calculate_diagram_SSV_t9g9n39_VSV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto b1tmp2 = lib.B1(mext2*mext2, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -5572,10 +5818,11 @@ Decay_amplitude_SSV calculate_diagram_SSV_t9g10n40_VVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLV5*mLV5, mLV6*mLV6, - scale*scale); - const auto b1tmp2 = lib.B1(mext2*mext2, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -5616,11 +5863,15 @@ Decay_amplitude_SSV calculate_diagram_SSV_t10g1n41_SFF( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLF6*mLF6, scale*scale); - const auto b0tmp2 = lib.B0(mext1*mext1, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b1tmp3 = lib.B1(mext1*mext1, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLF6*mLF6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b1tmp3 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -5661,8 +5912,10 @@ Decay_amplitude_SSV calculate_diagram_SSV_t10g2n42_SSS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLS5*mLS5, mLS6*mLS6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSV result; @@ -5700,8 +5953,10 @@ Decay_amplitude_SSV calculate_diagram_SSV_t10g3n43_SUU( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLU5*mLU5, mLU6*mLU6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLU5*mLU5, mLU6*mLU6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSV result; @@ -5740,11 +5995,15 @@ Decay_amplitude_SSV calculate_diagram_SSV_t10g4n44_SSV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV6*mLV6, scale*scale); - const auto b0tmp2 = lib.B0(mext1*mext1, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto b1tmp3 = lib.B1(mext1*mext1, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV6*mLV6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b1tmp3 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -5783,8 +6042,10 @@ Decay_amplitude_SSV calculate_diagram_SSV_t10g5n45_SVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SSV result; @@ -5827,10 +6088,11 @@ Decay_amplitude_SSV calculate_diagram_SSV_t10g6n46_VFF( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -5871,10 +6133,11 @@ Decay_amplitude_SSV calculate_diagram_SSV_t10g7n47_VSS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLS5*mLS5, mLS6*mLS6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLS5*mLS5, mLS6*mLS6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -5912,8 +6175,10 @@ Decay_amplitude_SSV calculate_diagram_SSV_t10g8n48_VUU( { auto& lib = Loop_library::get(); - const auto b1tmp1 = lib.B1(mext1*mext1, mLU5*mLU5, mLU6*mLU6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLU5*mLU5, mLU6*mLU6, scale*scale); + + const auto b1tmp1 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -5952,10 +6217,11 @@ Decay_amplitude_SSV calculate_diagram_SSV_t10g9n49_VSV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -5995,10 +6261,11 @@ Decay_amplitude_SSV calculate_diagram_SSV_t10g10n50_VVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLV5*mLV5, mLV6*mLV6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SSV result; @@ -6041,14 +6308,17 @@ Decay_amplitude_SFF calculate_diagram_SFF_t1g1n1_FFS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLF5*mLF5, mLS6*mLS6, - scale*scale); - const auto c0tmp2 = lib.C0(mext1*mext1, mext3*mext3, mext2* - mext2, mLF4*mLF4, mLF5*mLF5, mLS6*mLS6, scale*scale); - const auto c1tmp3 = lib.C1(mext1*mext1, mext3*mext3, mext2* - mext2, mLF4*mLF4, mLF5*mLF5, mLS6*mLS6, scale*scale); - const auto c2tmp4 = lib.C2(mext1*mext1, mext3*mext3, mext2* - mext2, mLF4*mLF4, mLF5*mLF5, mLS6*mLS6, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLF5*mLF5, mLS6*mLS6, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext1*mext1, mext3*mext3, mext2*mext2, mLF4*mLF4, mLF5*mLF5, + mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c1tmp3 = C_coeffs.at(1); + const auto c2tmp4 = C_coeffs.at(2); Decay_amplitude_SFF result; @@ -6108,12 +6378,13 @@ Decay_amplitude_SFF calculate_diagram_SFF_t1g2n2_SSF( { auto& lib = Loop_library::get(); - const auto c0tmp1 = lib.C0(mext2*mext2, mext1*mext1, mext3* - mext3, mLF6*mLF6, mLS4*mLS4, mLS5*mLS5, scale*scale); - const auto c1tmp2 = lib.C1(mext2*mext2, mext1*mext1, mext3* - mext3, mLF6*mLF6, mLS4*mLS4, mLS5*mLS5, scale*scale); - const auto c2tmp3 = lib.C2(mext2*mext2, mext1*mext1, mext3* - mext3, mLF6*mLF6, mLS4*mLS4, mLS5*mLS5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext1*mext1, mext3*mext3, mLF6*mLF6, mLS4*mLS4, + mLS5*mLS5, scale*scale); + + const auto c0tmp1 = C_coeffs.at(0); + const auto c1tmp2 = C_coeffs.at(1); + const auto c2tmp3 = C_coeffs.at(2); Decay_amplitude_SFF result; @@ -6164,14 +6435,17 @@ Decay_amplitude_SFF calculate_diagram_SFF_t1g3n3_FFV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLF5*mLF5, mLV6*mLV6, - scale*scale); - const auto c0tmp2 = lib.C0(mext1*mext1, mext3*mext3, mext2* - mext2, mLF4*mLF4, mLF5*mLF5, mLV6*mLV6, scale*scale); - const auto c1tmp3 = lib.C1(mext1*mext1, mext3*mext3, mext2* - mext2, mLF4*mLF4, mLF5*mLF5, mLV6*mLV6, scale*scale); - const auto c2tmp4 = lib.C2(mext1*mext1, mext3*mext3, mext2* - mext2, mLF4*mLF4, mLF5*mLF5, mLV6*mLV6, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLF5*mLF5, mLV6*mLV6, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext1*mext1, mext3*mext3, mext2*mext2, mLF4*mLF4, mLF5*mLF5, + mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c1tmp3 = C_coeffs.at(1); + const auto c2tmp4 = C_coeffs.at(2); Decay_amplitude_SFF result; @@ -6231,14 +6505,17 @@ Decay_amplitude_SFF calculate_diagram_SFF_t1g4n4_SVF( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLF6*mLF6, mLV5*mLV5, - scale*scale); - const auto c0tmp2 = lib.C0(mext2*mext2, mext1*mext1, mext3* - mext3, mLF6*mLF6, mLS4*mLS4, mLV5*mLV5, scale*scale); - const auto c1tmp3 = lib.C1(mext2*mext2, mext1*mext1, mext3* - mext3, mLF6*mLF6, mLS4*mLS4, mLV5*mLV5, scale*scale); - const auto c2tmp4 = lib.C2(mext2*mext2, mext1*mext1, mext3* - mext3, mLF6*mLF6, mLS4*mLS4, mLV5*mLV5, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLF6*mLF6, mLV5*mLV5, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext1*mext1, mext3*mext3, mLF6*mLF6, mLS4*mLS4, + mLV5*mLV5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c1tmp3 = C_coeffs.at(1); + const auto c2tmp4 = C_coeffs.at(2); Decay_amplitude_SFF result; @@ -6294,14 +6571,17 @@ Decay_amplitude_SFF calculate_diagram_SFF_t1g5n5_VSF( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLF6*mLF6, mLS5*mLS5, - scale*scale); - const auto c0tmp2 = lib.C0(mext2*mext2, mext1*mext1, mext3* - mext3, mLF6*mLF6, mLV4*mLV4, mLS5*mLS5, scale*scale); - const auto c1tmp3 = lib.C1(mext2*mext2, mext1*mext1, mext3* - mext3, mLF6*mLF6, mLV4*mLV4, mLS5*mLS5, scale*scale); - const auto c2tmp4 = lib.C2(mext2*mext2, mext1*mext1, mext3* - mext3, mLF6*mLF6, mLV4*mLV4, mLS5*mLS5, scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLF6*mLF6, mLS5*mLS5, scale*scale); + + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext1*mext1, mext3*mext3, mLF6*mLF6, mLV4*mLV4, + mLS5*mLS5, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto c0tmp2 = C_coeffs.at(0); + const auto c1tmp3 = C_coeffs.at(1); + const auto c2tmp4 = C_coeffs.at(2); Decay_amplitude_SFF result; @@ -6362,12 +6642,13 @@ Decay_amplitude_SFF calculate_diagram_SFF_t1g6n6_VVF( { auto& lib = Loop_library::get(); - const auto c0tmp1 = lib.C0(mext2*mext2, mext1*mext1, mext3* - mext3, mLF6*mLF6, mLV4*mLV4, mLV5*mLV5, scale*scale); - const auto c1tmp2 = lib.C1(mext2*mext2, mext1*mext1, mext3* - mext3, mLF6*mLF6, mLV4*mLV4, mLV5*mLV5, scale*scale); - const auto c2tmp3 = lib.C2(mext2*mext2, mext1*mext1, mext3* - mext3, mLF6*mLF6, mLV4*mLV4, mLV5*mLV5, scale*scale); + looplibrary::Ccoeff_t C_coeffs; + lib.C(C_coeffs, mext2*mext2, mext1*mext1, mext3*mext3, mLF6*mLF6, mLV4*mLV4, + mLV5*mLV5, scale*scale); + + const auto c0tmp1 = C_coeffs.at(0); + const auto c1tmp2 = C_coeffs.at(1); + const auto c2tmp3 = C_coeffs.at(2); Decay_amplitude_SFF result; @@ -6408,7 +6689,10 @@ Decay_amplitude_SFF calculate_diagram_SFF_t2g1n7_SS( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLS5*mLS5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLS5*mLS5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SFF result; @@ -6447,7 +6731,10 @@ Decay_amplitude_SFF calculate_diagram_SFF_t2g2n8_SV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV5*mLV5, scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV5*mLV5, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); Decay_amplitude_SFF result; @@ -6492,10 +6779,11 @@ Decay_amplitude_SFF calculate_diagram_SFF_t3g1n9_FFS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLF5*mLF5, mLS6*mLS6, - scale*scale); - const auto b1tmp2 = lib.B1(mext3*mext3, mLF5*mLF5, mLS6*mLS6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLF5*mLF5, mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SFF result; @@ -6548,10 +6836,11 @@ Decay_amplitude_SFF calculate_diagram_SFF_t3g2n10_FFV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext3*mext3, mLF5*mLF5, mLV6*mLV6, - scale*scale); - const auto b1tmp2 = lib.B1(mext3*mext3, mLF5*mLF5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext3*mext3, mLF5*mLF5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SFF result; @@ -6602,10 +6891,11 @@ Decay_amplitude_SFF calculate_diagram_SFF_t4g1n11_FFS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLF5*mLF5, mLS6*mLS6, - scale*scale); - const auto b1tmp2 = lib.B1(mext2*mext2, mLF5*mLF5, mLS6*mLS6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLF5*mLF5, mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SFF result; @@ -6658,10 +6948,11 @@ Decay_amplitude_SFF calculate_diagram_SFF_t4g2n12_FFV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext2*mext2, mLF5*mLF5, mLV6*mLV6, - scale*scale); - const auto b1tmp2 = lib.B1(mext2*mext2, mLF5*mLF5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext2*mext2, mLF5*mLF5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SFF result; @@ -6712,11 +7003,15 @@ Decay_amplitude_SFF calculate_diagram_SFF_t5g1n13_SFF( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLF6*mLF6, scale*scale); - const auto b0tmp2 = lib.B0(mext1*mext1, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b1tmp3 = lib.B1(mext1*mext1, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLF6*mLF6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b1tmp3 = B_coeffs.at(1); Decay_amplitude_SFF result; @@ -6764,8 +7059,10 @@ Decay_amplitude_SFF calculate_diagram_SFF_t5g2n14_SSS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLS5*mLS5, mLS6*mLS6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SFF result; @@ -6807,8 +7104,10 @@ Decay_amplitude_SFF calculate_diagram_SFF_t5g3n15_SUU( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLU5*mLU5, mLU6*mLU6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLU5*mLU5, mLU6*mLU6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SFF result; @@ -6851,11 +7150,15 @@ Decay_amplitude_SFF calculate_diagram_SFF_t5g4n16_SSV( { auto& lib = Loop_library::get(); - const auto a0tmp1 = lib.A0(mLV6*mLV6, scale*scale); - const auto b0tmp2 = lib.B0(mext1*mext1, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto b1tmp3 = lib.B1(mext1*mext1, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Acoeff_t A_coeffs; + lib.A(A_coeffs, mLV6*mLV6, scale*scale); + + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto a0tmp1 = A_coeffs.at(0); + const auto b0tmp2 = B_coeffs.at(0); + const auto b1tmp3 = B_coeffs.at(1); Decay_amplitude_SFF result; @@ -6899,8 +7202,10 @@ Decay_amplitude_SFF calculate_diagram_SFF_t5g5n17_SVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); Decay_amplitude_SFF result; @@ -6951,10 +7256,11 @@ Decay_amplitude_SFF calculate_diagram_SFF_t5g6n18_VFF( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLF5*mLF5, mLF6*mLF6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLF5*mLF5, mLF6*mLF6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLF5*mLF5, mLF6*mLF6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SFF result; @@ -7004,10 +7310,11 @@ Decay_amplitude_SFF calculate_diagram_SFF_t5g7n19_VSS( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLS5*mLS5, mLS6*mLS6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLS5*mLS5, mLS6*mLS6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS5*mLS5, mLS6*mLS6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SFF result; @@ -7053,8 +7360,10 @@ Decay_amplitude_SFF calculate_diagram_SFF_t5g8n20_VUU( { auto& lib = Loop_library::get(); - const auto b1tmp1 = lib.B1(mext1*mext1, mLU5*mLU5, mLU6*mLU6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLU5*mLU5, mLU6*mLU6, scale*scale); + + const auto b1tmp1 = B_coeffs.at(1); Decay_amplitude_SFF result; @@ -7101,10 +7410,11 @@ Decay_amplitude_SFF calculate_diagram_SFF_t5g9n21_VSV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLS5*mLS5, mLV6*mLV6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLS5*mLS5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLS5*mLS5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SFF result; @@ -7152,10 +7462,11 @@ Decay_amplitude_SFF calculate_diagram_SFF_t5g10n22_VVV( { auto& lib = Loop_library::get(); - const auto b0tmp1 = lib.B0(mext1*mext1, mLV5*mLV5, mLV6*mLV6, - scale*scale); - const auto b1tmp2 = lib.B1(mext1*mext1, mLV5*mLV5, mLV6*mLV6, - scale*scale); + looplibrary::Bcoeff_t B_coeffs; + lib.B(B_coeffs, mext1*mext1, mLV5*mLV5, mLV6*mLV6, scale*scale); + + const auto b0tmp1 = B_coeffs.at(0); + const auto b1tmp2 = B_coeffs.at(1); Decay_amplitude_SFF result; diff --git a/utils/loop_decays/meta/generate_loop_decays.m b/utils/loop_decays/meta/generate_loop_decays.m index 9a0d46aa5b..2fc85d3960 100644 --- a/utils/loop_decays/meta/generate_loop_decays.m +++ b/utils/loop_decays/meta/generate_loop_decays.m @@ -450,17 +450,61 @@ CreateLoopMassCString[arg]; CallLoopFunction[fn_[args__], renScale_String] := - Module[{argsStr}, + Module[{argsStr, funcType = First@Characters@ToString[fn], returnType}, argsStr = StringJoin[Riffle[CreateLoopFunctionArgumentName /@ List[args], ", "]]; - "lib." <> ToString[fn] <> "(" <> argsStr <> ", " <> renScale <> "*" <> renScale <> ")" - ]; + returnType = "looplibrary::" <> funcType <> "coeff_t"; + returnType <> " " <> funcType <> "_coeffs;\n" <> + "lib." <> funcType <> "(" <> funcType <> "_coeffs, " <> argsStr <> ", " <> renScale <> "*" <> renScale <> ");\n\n" + ]; + +GetLoopFunctionFromCoefficient[fn_[args__]] := + Module[{funcType = First@Characters@ToString[fn], coeffIndexAsStr, coeffIndexAsInt}, + coeffIndexAsStr = StringJoin@Drop[Characters@ToString[fn], 1]; + coeffIndexAsInt = + Switch[funcType, + "A", + Switch[coeffIndexAsStr, + "0", 0, + _, Print[coeffIndexAsStr <> "is and unknown type of A function"]; Quit[1]; + ], + "B", + Switch[coeffIndexAsStr, + "0", 0, + "1", 1, + "00", 2, + _, Print[coeffIndexAsStr <> "is an unknown type of B function"]; Quit[1]; + ], + "C", + Switch[coeffIndexAsStr, + "0", 0, + "1", 1, + "2", 2, + "00", 3, + "11", 4, + "12", 5, + "22", 6, + _, Print[coeffIndexAsStr <> "is an unknown type of C function"]; Quit[1]; + ], + _, Print["Unknown loop function"]; Quit[1]; + ]; + funcType <> "_coeffs.at(" <> ToString@coeffIndexAsInt <> ")" + ]; + SaveLoopIntegrals[diagram_, renScale_String] := Module[{formFactors, loopFunctions, tmpVars, savedValues, subs}, formFactors = Last[diagram]; loopFunctions = Sort[DeleteDuplicates[Cases[formFactors, fn_[args__] /; IsSARAHLoopFunction[fn], {0, Infinity}]]]; tmpVars = MapIndexed[(CreateSavedLoopFunctionName[#1] <> ToString[First[#2]])&, loopFunctions]; - savedValues = MapThread[("const auto " <> #1 <> " = " <> CallLoopFunction[#2, renScale] <> ";\n")&, {tmpVars, loopFunctions}]; + If[Max[{ + CountDistinct[List @@@ Select[loopFunctions, First@Characters@ToString@Head[#] == "A"&]], + CountDistinct[List @@@ Select[loopFunctions, First@Characters@ToString@Head[#] == "B"&]], + CountDistinct[List @@@ Select[loopFunctions, First@Characters@ToString@Head[#] == "C"&]] + }] > 1, + Print["Not all loop functions of the same type (e.g. C*) are called with the same arguments"]; Quit[1] + ]; + savedValues = StringJoin[DeleteDuplicates[CallLoopFunction[#, renScale]& /@ loopFunctions]]; + savedValues = savedValues <> MapThread[("const auto " <> #1 <> " = " <> GetLoopFunctionFromCoefficient[#2] <> ";\n")&, {tmpVars, loopFunctions}]; savedValues = StringJoin[savedValues]; subs = MapThread[Rule[#1, Symbol[#2]]&, {loopFunctions, tmpVars}]; {savedValues, subs} From 21ed4cc6b2bb72542f1c5cc9c1608933e3543ce7 Mon Sep 17 00:00:00 2001 From: dhjjacob <48706289+dhjjacob@users.noreply.github.com> Date: Thu, 10 Jun 2021 22:16:44 +1000 Subject: [PATCH 003/477] require emitting FFV particles to be charged under V --- CHANGES.rst | 3 +++ meta/FFVFormFactors.m | 34 +++++++++++++++++++++++------- meta/TreeMasses.m | 12 ++++++++--- model_files/BLSM/FlexibleSUSY.m.in | 2 ++ 4 files changed, 40 insertions(+), 11 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 1115a226b3..94346af360 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -10,6 +10,9 @@ Changes Fixed bugs ---------- +* [commit ]: Fix error in FFV form factors module cased by models where + SARAH generates non zero photon (gluon) couplings to QED (QCD) singlets. + FlexibleSUSY 2.6.0 [June, 10 2021] ================================== diff --git a/meta/FFVFormFactors.m b/meta/FFVFormFactors.m index c2ff3bba88..48d9d5d6ee 100644 --- a/meta/FFVFormFactors.m +++ b/meta/FFVFormFactors.m @@ -34,6 +34,10 @@ why such a weird numbering? because some procedure uses this order for fermion number flow."; FFVContributingDiagramsForGraph::usage = ""; +IsDiagramSupported::usage = "For the input FFV graph, determines whether +the input diagram is valid, by checking whether the internal structure is +supported and the emitting fields can in fact emit the vector." +IsChargedUnder::usage="Returns whether or not a field is charged under a given vectors gauge"; Begin["Private`"]; @@ -51,6 +55,7 @@ EmitterL[diagram_] := diagram[[3,2]]; EmitterR[diagram_] := diagram[[2,2]]; Spectator[diagram_] := diagram[[2,3]]; +EmittedV[diagram_] := diagram[[3,3]]; FFVContributingDiagramsForGraph[graph_, Fj_ -> {Fi_, V_}] := Module[{diagrams}, @@ -65,19 +70,22 @@ ]; IsDiagramSupported[graph_, diagram_] := - Module[{photonEmitter, exchangeParticle, photonEmitterAfter}, + Module[{vectorEmitter, exchangeParticle, vectorEmitterAfter, vectorBoson}, - photonEmitter = diagram[[3,2]]; (* Edge between vertices ? and ? (3rd edge of vertex 4) *) - photonEmitterAfter = diagram[[2,2]]; - exchangeParticle = diagram[[2,3]]; (* Edge between vertices ? and ? (2nd edge of vertex 4) *) + vectorEmitter = EmitterL[diagram]; (* Edge between vertices ? and ? (3rd edge of vertex 4) *) + vectorEmitterAfter = EmitterR[diagram]; + exchangeParticle = Spectator[diagram]; (* Edge between vertices ? and ? (2nd edge of vertex 4) *) + vectorBoson = EmittedV[diagram]; - If[TreeMasses`IsFermion[photonEmitter] && - TreeMasses`IsFermion[photonEmitterAfter] - && TreeMasses`IsScalar[exchangeParticle], + If[Not[IsChargedUnder[vectorEmitter,vectorBoson] && IsChargedUnder[vectorEmitterAfter,vectorBoson]], + Return[False]; + ]; + + If[TreeMasses`IsFermion[vectorEmitter] && TreeMasses`IsFermion[vectorEmitterAfter] && TreeMasses`IsScalar[exchangeParticle], Return[True] ]; - If[TreeMasses`IsFermion[exchangeParticle] && TreeMasses`IsScalar[photonEmitter] &&TreeMasses`IsScalar[photonEmitterAfter], + If[TreeMasses`IsFermion[exchangeParticle] && TreeMasses`IsScalar[vectorEmitter] &&TreeMasses`IsScalar[vectorEmitterAfter], Return[True] ]; @@ -89,6 +97,16 @@ Return[False]; ]; +IsChargedUnder[field_, vector_?IsVector] := + Which[(*Check 2 special cases first which are quicker*) + TreeMasses`IsPhoton[vector], TreeMasses`IsElectricallyCharged[field], + TreeMasses`IsGluon[vector], TreeMasses`ColorChargedQ[field], + (*Else check that this field coupled with its anti-field can emit this vector*) + (*Note this will not work for vectors that couple to two different fields, e.g. W-bosons*) + True, SARAH`Vertex[{SARAH`AntiField[field], field, + vector}, UseDependences -> True][[2, 1]] =!= 0 + ] + FFVFormFactorsCreateInterfaceFunction[Fj_ -> {Fi_, V_}, topologies_, diagrams_] := Module[{prototype, definition, numberOfIndices1 = CXXDiagrams`NumberOfFieldIndices[Fj], diff --git a/meta/TreeMasses.m b/meta/TreeMasses.m index 0803248bea..3ea2938d9e 100644 --- a/meta/TreeMasses.m +++ b/meta/TreeMasses.m @@ -157,7 +157,7 @@ CreateDependencePrototypes::usage=""; CreateDependenceFunctions::usage=""; -ColorChargedQ::usage=""; +ColorChargedQ::usage="Checks whether or not input field has color property"; FieldInfo::usage=""; includeLorentzIndices::usage=""; @@ -182,8 +182,9 @@ IsUnmixed::usage=""; IsQuark::usage=""; IsLepton::usage=""; -IsPhoton::usage=""; +IsPhoton::usage="Checks whether input field is a Photon"; IsZBoson::usage=""; +IsGluon::usage="Checks whether input field is a Gluon"; IsSMChargedLepton::usage=""; IsSMNeutralLepton::usage=""; IsSMLepton::usage=""; @@ -196,7 +197,7 @@ the element is a SM-like field or not. The function assumes that BSM fields are always heavier than the SM fields."; -IsElectricallyCharged::usage=""; +IsElectricallyCharged::usage="Returns whether or not a field has Electric Charge"; ContainsGoldstone::usage=""; FSAntiField::usage = "Returns the anti-field of a given field"; @@ -524,6 +525,11 @@ IsZBoson[sym_[___]] := IsZBoson[sym]; IsZBoson[field_Symbol] := field === GetZBoson[]; +IsGluon[Susyno`LieGroups`conj[sym_]] := IsGluon[sym]; +IsGluon[SARAH`bar[sym_]] := IsGluon[sym]; +IsGluon[sym_[___]] := IsGluon[sym]; +IsGluon[field_Symbol] := field === GetGluon[]; + IsSMChargedLepton[Susyno`LieGroups`conj[sym_]] := IsSMChargedLepton[sym]; IsSMChargedLepton[SARAH`bar[sym_]] := IsSMChargedLepton[sym]; IsSMChargedLepton[sym_[__]] := IsSMChargedLepton[sym]; diff --git a/model_files/BLSM/FlexibleSUSY.m.in b/model_files/BLSM/FlexibleSUSY.m.in index 66efd501f2..4c87841bdd 100644 --- a/model_files/BLSM/FlexibleSUSY.m.in +++ b/model_files/BLSM/FlexibleSUSY.m.in @@ -61,6 +61,8 @@ InitialGuessAtLowScale = { PotentialLSPParticles = {}; ExtraSLHAOutputBlocks = { + {FlexibleSUSYLowEnergy, + {{21, FlexibleSUSYObservable`aMuon} } }, {FlexibleSUSYOutput, {{1, Hold[SUSYScale]}, {2, Hold[LowScale]} } } From c507ae472b8ecc6d2a1203d5a22c8cde35fd8e9a Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Fri, 11 Jun 2021 08:33:09 +0200 Subject: [PATCH 004/477] allow user to use different doxygen build --- doc/module.mk | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/doc/module.mk b/doc/module.mk index cc17f4f08c..56c8cec294 100644 --- a/doc/module.mk +++ b/doc/module.mk @@ -27,6 +27,7 @@ INDEX_PAGE := $(HTML_OUTPUT_DIR)/index.html MAN_PAGE := $(MAN_OUTPUT_DIR)/index.html DOXYFILE := $(DIR)/Doxyfile DOXYGEN_MAINPAGE:= $(DIR)/mainpage.dox +DOXYGEN ?= doxygen .PHONY: all-$(MODNAME) clean-$(MODNAME) distclean-$(MODNAME) \ $(INDEX_PAGE) $(MAN_PAGE) doc doc-html doc-man doc-pdf @@ -63,7 +64,7 @@ clean:: clean-$(MODNAME) distclean:: distclean-$(MODNAME) $(INDEX_PAGE): - ( cat $(DOXYFILE) ; \ + $(Q)( cat $(DOXYFILE) ; \ echo "INPUT = $(MODULES) $(README_FILE)" ; \ echo "OUTPUT_DIRECTORY = $(HTML_OUTPUT_DIR)" ; \ echo "EXCLUDE = $(ALLDEP) $(META_SRC) $(TEMPLATES) \ @@ -71,10 +72,10 @@ $(INDEX_PAGE): echo "EXCLUDE_PATTERNS = */meta/* */test/*"; \ echo "IMAGE_PATH = $(IMAGE_DIR)"; \ echo "INCLUDE_PATH = $(MODULES)"; \ - ) | doxygen - + ) | $(DOXYGEN) - $(MAN_PAGE): - ( cat $(DOXYFILE) ; \ + $(Q)( cat $(DOXYFILE) ; \ echo "INPUT = $(MODULES) $(README_FILE)" ; \ echo "OUTPUT_DIRECTORY = $(MAN_OUTPUT_DIR)" ; \ echo "EXCLUDE = $(ALLDEP) $(META_SRC) $(TEMPLATES) \ @@ -84,4 +85,4 @@ $(MAN_PAGE): echo "INCLUDE_PATH = $(MODULES)"; \ echo "GENERATE_MAN = YES"; \ echo "GENERATE_HTML = NO"; \ - ) | doxygen - + ) | $(DOXYGEN) - From 5a8afc24a47ce48eb82982fa1ec5ddee6bdc5858 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Fri, 11 Jun 2021 12:32:53 +0200 Subject: [PATCH 005/477] organize FS dependencies on CI image (#341) --- .github/workflows/package-models.yml | 19 ++++++------ .github/workflows/tests.yml | 44 +++++++++++++++++----------- 2 files changed, 37 insertions(+), 26 deletions(-) diff --git a/.github/workflows/package-models.yml b/.github/workflows/package-models.yml index 5a0c86cef6..bb576cf1b1 100644 --- a/.github/workflows/package-models.yml +++ b/.github/workflows/package-models.yml @@ -1,4 +1,4 @@ -name: Package models +name: package models on: release: @@ -45,19 +45,20 @@ jobs: PART: ${{ matrix.part }} run: | models=$(ruby -e "MODELS=ARGV.drop(1); puts MODELS.each_slice(MODELS.length/2).to_a[ARGV[0].to_i-1].join(',')" -- $PART $MODELS) + FS_DEPENDENCIES_DIR="/fs_dependencies/gcc" ./release/generate-models.sh \ --number-of-jobs=2 \ --directory=release/$FS_TAG \ --with-models=$models \ - --with-himalaya-incdir=/Himalaya-g++/include \ - --with-himalaya-libdir=/Himalaya-g++/lib64 \ - --with-tsil-incdir=/tsil-g++ \ - --with-tsil-libdir=/tsil-g++ \ + --with-himalaya-incdir=$FS_DEPENDENCIES_DIR/Himalaya/include \ + --with-himalaya-libdir=$FS_DEPENDENCIES_DIR/Himalaya/lib64 \ + --with-tsil-incdir=$FS_DEPENDENCIES_DIR/tsil \ + --with-tsil-libdir=$FS_DEPENDENCIES_DIR/tsil \ --with-loop-libraries=collier,looptools \ - --with-looptools-incdir=/LoopTools-g++/include \ - --with-looptools-libdir=/LoopTools-g++/lib64 \ - --with-collier-incdir=/COLLIER/include \ - --with-collier-libdir=/COLLIER/lib + --with-looptools-incdir=$FS_DEPENDENCIES_DIR/LoopTools/include \ + --with-looptools-libdir=$FS_DEPENDENCIES_DIR/LoopTools/lib64 \ + --with-collier-incdir=$FS_DEPENDENCIES_DIR/COLLIER/include \ + --with-collier-libdir=$FS_DEPENDENCIES_DIR/COLLIER/lib ./release/generate-slha-output.sh --directory=release/${FS_TAG}-slha - name: Upload artifacts diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b343a37116..73782c12ea 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -119,7 +119,7 @@ jobs: runs-on: ubuntu-20.04 container: - image: navir/opensuseleap-for-flexiblesusy:0.6.1 + image: navir/opensuseleap-for-flexiblesusy:0.9.0 strategy: matrix: @@ -150,11 +150,11 @@ jobs: - name: Install FormCalc run: | - cd / + cd /fs_dependencies/gcc wget -q -O - http://www.feynarts.de/formcalc/FormCalc-$FORMCALC_VERSION.tar.gz | tar xzf - cd FormCalc-$FORMCALC_VERSION ./compile - echo 'AppendTo[$Path, "/FormCalc-$FORMCALC_VERSION"];' >> /root/.WolframEngine/Kernel/init.m + echo 'AppendTo[$Path, "/fs_dependencies/gcc/FormCalc-$FORMCALC_VERSION"];' >> /root/.WolframEngine/Kernel/init.m - name: Create models env: @@ -163,6 +163,16 @@ jobs: models=$(ruby -e "MODELS=ARGV.drop(1); puts MODELS.each_slice(MODELS.length/2).to_a[ARGV[0].to_i-1].join(' ')" -- $PART $MODELS) for m in $models; do ./createmodel --name=$m; done + - name: "Set FS dependency directory" + env: + compiler: ${{ matrix.CXXCOMPILER }} + run: | + case "$compiler" in + "g++") echo "FS_DEPENDENCIES_DIR=/fs_dependencies/gcc" >> $GITHUB_ENV ;; + "clang++") echo "FS_DEPENDENCIES_DIR=/fs_dependencies/clang" >> $GITHUB_ENV ;; + *) exit 1 ;; + esac + - name: Configure env: CXXCOMPILER: ${{ matrix.CXXCOMPILER }} @@ -173,18 +183,18 @@ jobs: --with-cxx=$CXXCOMPILER \ --with-models=$models \ --with-loop-libraries=collier,looptools \ - --with-looptools-incdir=/LoopTools-$CXXCOMPILER/include \ - --with-looptools-libdir=/LoopTools-$CXXCOMPILER/lib64 \ - --with-collier-incdir=/COLLIER/include \ - --with-collier-libdir=/COLLIER/lib \ + --with-looptools-incdir=$FS_DEPENDENCIES_DIR/LoopTools/include \ + --with-looptools-libdir=$FS_DEPENDENCIES_DIR/LoopTools/lib64 \ + --with-collier-incdir=/fs_dependencies/gcc/COLLIER/include \ + --with-collier-libdir=/fs_dependencies/gcc/COLLIER/lib \ --enable-himalaya \ - --with-himalaya-incdir=/Himalaya-$CXXCOMPILER/include \ - --with-himalaya-libdir=/Himalaya-$CXXCOMPILER/lib64 \ + --with-himalaya-incdir=$FS_DEPENDENCIES_DIR/Himalaya/include \ + --with-himalaya-libdir=$FS_DEPENDENCIES_DIR/Himalaya/lib64 \ --enable-gm2calc \ - --with-gm2calc-incdir=/GM2Calc-$CXXCOMPILER/include \ - --with-gm2calc-libdir=/GM2Calc-$CXXCOMPILER/lib64 \ - --with-tsil-incdir=/tsil-$CXXCOMPILER \ - --with-tsil-libdir=/tsil-$CXXCOMPILER \ + --with-gm2calc-incdir=$FS_DEPENDENCIES_DIR/GM2Calc/include \ + --with-gm2calc-libdir=$FS_DEPENDENCIES_DIR/GM2Calc/lib64 \ + --with-tsil-incdir=$FS_DEPENDENCIES_DIR/tsil \ + --with-tsil-libdir=$FS_DEPENDENCIES_DIR/tsil \ --with-optional-modules=test \ --enable-librarylink \ --with-cxxflags="-std=c++14 -O2 -fPIC -Wall -Wpedantic -pipe" @@ -236,10 +246,10 @@ jobs: --with-cxx=$CXXCOMPILER \ --with-models=SM \ --with-loop-libraries=collier,looptools \ - --with-looptools-incdir=/LoopTools-$CXXCOMPILER/include \ - --with-looptools-libdir=/LoopTools-$CXXCOMPILER/lib64 \ - --with-collier-incdir=/COLLIER/include \ - --with-collier-libdir=/COLLIER/lib \ + --with-looptools-incdir=$FS_DEPENDENCIES_DIR/LoopTools/include \ + --with-looptools-libdir=$FS_DEPENDENCIES_DIR/LoopTools/lib64 \ + --with-collier-incdir=/fs_dependencies/gcc/COLLIER/include \ + --with-collier-libdir=/fs_dependencies/gcc/COLLIER/lib \ --disable-meta \ --with-optional-modules=test make -j2 From 97281b71869b586742ba3c2e010bcf31d85f1c75 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Fri, 11 Jun 2021 17:29:50 +0200 Subject: [PATCH 006/477] fixed FormCalc path on CI --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 73782c12ea..79105ff7a5 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -154,7 +154,7 @@ jobs: wget -q -O - http://www.feynarts.de/formcalc/FormCalc-$FORMCALC_VERSION.tar.gz | tar xzf - cd FormCalc-$FORMCALC_VERSION ./compile - echo 'AppendTo[$Path, "/fs_dependencies/gcc/FormCalc-$FORMCALC_VERSION"];' >> /root/.WolframEngine/Kernel/init.m + echo "AppendTo[\$Path, \"/fs_dependencies/gcc/FormCalc-$FORMCALC_VERSION\"];" >> /root/.WolframEngine/Kernel/init.m - name: Create models env: From a0bbda56933f32519d0c938a8e70e849a4f9f06e Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Mon, 14 Jun 2021 16:19:08 +0200 Subject: [PATCH 007/477] update required Mathematica version to 10.1 (#343) needed by FlexibleDecay --- README.rst | 2 +- configure | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 49299e38b3..6bdbed925a 100644 --- a/README.rst +++ b/README.rst @@ -81,7 +81,7 @@ Requirements * C++ compiler (g++ >= 5.0.0 or clang++ >= 3.8.1 or icpc >= 17.0.0) * Fortran compiler (gfortran, ifort) -* Mathematica (version 7.0 or higher) +* Mathematica (version 10.1 or higher) * SARAH_ (version 4.11.0 or higher) * Boost_ (version 1.37.0 or higher) * `Eigen 3`_ (version 3.1 or higher) diff --git a/configure b/configure index 2997024cdd..09b8f339fa 100755 --- a/configure +++ b/configure @@ -245,7 +245,7 @@ required_icpc_compiler_version="17.0.0" required_boost_version="1.37.0" # required Mathematica version -required_mathematica_version="7" +required_mathematica_version="10.1" # required SARAH version required_sarah_major="4" From 12e123174ab2eb10087a2cb42d7e192e1a6306e1 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Mon, 14 Jun 2021 23:47:52 +0200 Subject: [PATCH 008/477] update ChangeLog --- CHANGES.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/CHANGES.rst b/CHANGES.rst index 94346af360..8b5766ec0c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -13,6 +13,10 @@ Fixed bugs * [commit ]: Fix error in FFV form factors module cased by models where SARAH generates non zero photon (gluon) couplings to QED (QCD) singlets. +* [commit a0bbda569]: Correcting check for required Mathematica version + 10.1, needed by FlexibleDecay. + + FlexibleSUSY 2.6.0 [June, 10 2021] ================================== From fbd10e69ee266e5fb1734dd19dadd5134872558b Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Tue, 15 Jun 2021 09:14:08 +0200 Subject: [PATCH 009/477] adding FlexibleEFTHiggs reference to .bib file --- doc/references.bib | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/doc/references.bib b/doc/references.bib index 0e69c09dbf..3c1e3308ca 100644 --- a/doc/references.bib +++ b/doc/references.bib @@ -76,6 +76,18 @@ @article{Harlander:2017kuc SLACcitation = "%%CITATION = ARXIV:1708.05720;%%" } +% FlexibleDecay +% \cite{Athron:2021kve} +@article{Athron:2021kve, + author = {Athron, Peter and B\"uchner, Adam and Harries, Dylan and Kotlarski, Wojciech and St\"ockinger, Dominik and Voigt, Alexander}, + title = "{FlexibleDecay: An automated calculator of scalar decay widths}", + eprint = "2106.05038", + archivePrefix = "arXiv", + primaryClass = "hep-ph", + month = "6", + year = "2021" +} + % \cite{Harlander:2018yhj} @article{Harlander:2018yhj, author = "Harlander, R. V. and Klappert, J. and Ochoa Franco, A. D. From a2fbcb180fdaf98fed7c877cb9fc8265402f8ba8 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Tue, 15 Jun 2021 09:17:26 +0200 Subject: [PATCH 010/477] adding FlexibleDecay reference to generated bibtex file --- meta/FlexibleSUSY.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index f9217e41fe..28c46b8c9b 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -3176,6 +3176,10 @@ corresponding tadpole is real or imaginary (only in models with CP References`AddReference["Athron:2016fuq"]; ]; + If[FlexibleSUSY`FSCalculateDecays, + References`AddReference["Athron:2021kve"]; + ]; + If[FlexibleSUSY`UseYukawa3LoopQCD || FlexibleSUSY`FlexibleEFTHiggs, Print["Adding 3-loop SM QCD corrections to yt from ", "[arxiv:hep-ph/9911434, arxiv:hep-ph/9912391]"]; From 1c6f955ed0e5a75df137ceb04d89f75d5d63f1ae Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Sat, 19 Jun 2021 22:59:26 +0200 Subject: [PATCH 011/477] require Mathematica 11.0 at least to prevent a Mathematica context issue in the *_vertices_1.cpp files See issue #344. fixes #344 --- CHANGES.rst | 2 +- README.rst | 2 +- configure | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 8b5766ec0c..d5967d595a 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -14,7 +14,7 @@ Fixed bugs SARAH generates non zero photon (gluon) couplings to QED (QCD) singlets. * [commit a0bbda569]: Correcting check for required Mathematica version - 10.1, needed by FlexibleDecay. + 11.0, needed by FlexibleDecay. FlexibleSUSY 2.6.0 [June, 10 2021] diff --git a/README.rst b/README.rst index 6bdbed925a..43ace2778e 100644 --- a/README.rst +++ b/README.rst @@ -81,7 +81,7 @@ Requirements * C++ compiler (g++ >= 5.0.0 or clang++ >= 3.8.1 or icpc >= 17.0.0) * Fortran compiler (gfortran, ifort) -* Mathematica (version 10.1 or higher) +* Mathematica (version 11.0 or higher) * SARAH_ (version 4.11.0 or higher) * Boost_ (version 1.37.0 or higher) * `Eigen 3`_ (version 3.1 or higher) diff --git a/configure b/configure index 09b8f339fa..fe0c7373bb 100755 --- a/configure +++ b/configure @@ -245,7 +245,7 @@ required_icpc_compiler_version="17.0.0" required_boost_version="1.37.0" # required Mathematica version -required_mathematica_version="10.1" +required_mathematica_version="11.0" # required SARAH version required_sarah_major="4" From 98e78332f3e88b311c692dec48fe6bfe40d648aa Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sun, 20 Jun 2021 16:09:11 +0200 Subject: [PATCH 012/477] removed functions FSReIm and FSBooleanQ These functions were introduced for compatibility with WL < 10.0 and 10.1. Since we now reguire WL >= 11.0, they are no longer needed. --- meta/BtoSGamma.m | 2 +- meta/Decays.m | 2 +- meta/FFVFormFactors.m | 2 +- meta/Utils.m | 13 ------------- 4 files changed, 3 insertions(+), 16 deletions(-) diff --git a/meta/BtoSGamma.m b/meta/BtoSGamma.m index a3abd9ccf9..cee508670a 100644 --- a/meta/BtoSGamma.m +++ b/meta/BtoSGamma.m @@ -61,7 +61,7 @@ outFermion = GetStrangeQuark[], dimensionInFermion = TreeMasses`GetDimension[TreeMasses`GetSMBottomQuarkMultiplet[]], dimensionOutFermion = TreeMasses`GetDimension[TreeMasses`GetSMStrangeQuarkMultiplet[]]}, - Utils`AssertWithMessage[Utils`FSBooleanQ[matchingOn], + Utils`AssertWithMessage[BooleanQ[matchingOn], "BtoSGamma`CreateInterfaceBtoSGamma[]: Error, argument must be either True or False."]; If[matchingOn, diff --git a/meta/Decays.m b/meta/Decays.m index 40be6b5210..3ecff1872b 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -1942,7 +1942,7 @@ would violate Ward identity (as at the level of dim 4 If[Head[cf] === Complex, (* complex colour factor *) "std::complex " <> ToString@colorFac <> " " <> - ToString[N[#, 16]& /@ FSReIm @ cf], + ToString[N[#, 16]& /@ ReIm @ cf], (* real color factor *) "double " <> ToString@colorFac <> " {" <> diff --git a/meta/FFVFormFactors.m b/meta/FFVFormFactors.m index 48d9d5d6ee..36c82192c1 100644 --- a/meta/FFVFormFactors.m +++ b/meta/FFVFormFactors.m @@ -176,7 +176,7 @@ CreateCall[Fj_, Fi_, V_, topology_, diagram_] := "val += std::complex " <> - ToString @ N @ FSReIm @ CXXDiagrams`ExtractColourFactor @ CXXDiagrams`ColorFactorForDiagram[topology, diagram] <> " * FFV_" <> + ToString @ N @ ReIm @ CXXDiagrams`ExtractColourFactor @ CXXDiagrams`ColorFactorForDiagram[topology, diagram] <> " * FFV_" <> StringJoin @@ (ToString /@ SARAH`getType /@ {EmitterL[diagram], EmitterR[diagram], Spectator[diagram]}) <> "<" <> StringJoin @ Riffle[CXXDiagrams`CXXNameOfField /@ {Fj, Fi, V, EmitterL[diagram], EmitterR[diagram], Spectator[diagram]}, ","] <> ">::value(indices1, indices2, context, discard_SM_contributions);\n"; diff --git a/meta/Utils.m b/meta/Utils.m index eac4b47ac8..3ca8995d28 100644 --- a/meta/Utils.m +++ b/meta/Utils.m @@ -210,8 +210,6 @@ occurrence of the given rule is replaced (if it exists) or added (if as a list of Strings representing the lines in the file. Warning: This function may ignore empty lines."; -FSReIm::usage = "FS replacement for the mathematica's function ReIm"; -FSBooleanQ::usage = "FS replacement for the mathematica's function BooleanQ"; MathIndexToCPP::usage = "Converts integer-literal index from mathematica to c/c++ convention"; FSPermutationSign::usage = "Returns the sign of a permutation given in a Cycles form"; @@ -538,17 +536,6 @@ occurrence of the given rule is replaced (if it exists) or added (if lines ] -FSReIm[z_/;NumberQ[z]] := If[$VersionNumber >= 10.1, - ReIm[z], - {Re[z], Im[z]} -]; - -FSBooleanQ[b_] := - If[$VersionNumber >= 10.0, - BooleanQ[b], - If[b === True || b === False, True, False] - ]; - (* MathIndexToCPP *) MathIndexToCPP[i_Integer /; i>0] := i-1; From 4a29d6ec78f83c542e3922f4158d527e6518592a Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Mon, 21 Jun 2021 12:38:05 +0200 Subject: [PATCH 013/477] update referenced SARAH version --- .github/workflows/tests.yml | 2 ++ README.rst | 2 +- install-sarah | 2 +- 3 files changed, 4 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 79105ff7a5..f79c7ecf15 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -13,6 +13,7 @@ on: - 'AUTHORS' - 'COPYING' - 'doc/**' + - 'install-sarah' pull_request: branches: @@ -23,6 +24,7 @@ on: - 'AUTHORS' - 'COPYING' - 'doc/**' + - 'install-sarah' jobs: no-meta: diff --git a/README.rst b/README.rst index 43ace2778e..42f80d02a4 100644 --- a/README.rst +++ b/README.rst @@ -128,7 +128,7 @@ FlexibleSUSY requires SARAH to be installed and to be loadable with the ``Needs["SARAH`"]`` command from inside Mathematica. We recommend the following setup:: - SARAH_VERSION=4.14.3 + SARAH_VERSION=4.14.5 cd ~/.Mathematica/Applications/ wget https://sarah.hepforge.org/downloads/SARAH-${SARAH_VERSION}.tar.gz tar -xf SARAH-${SARAH_VERSION}.tar.gz diff --git a/install-sarah b/install-sarah index 23714dab59..8a222bea8f 100755 --- a/install-sarah +++ b/install-sarah @@ -13,7 +13,7 @@ ABSBASEDIR=$(cd $BASEDIR; pwd) operating_system="`(uname -s) 2>/dev/null || echo unknown`" # default SARAH version -sarah_version="4.14.3" +sarah_version="4.14.5" # determine Mathematica user directory case "$operating_system" in From 41c060be475fa5c4e4343d4a9476f2a2212fbc5b Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Mon, 21 Jun 2021 14:53:58 +0200 Subject: [PATCH 014/477] added minimal bash syntax highlighting to README --- README.rst | 206 +++++++++++++++++++++++++++++++++++++++-------------- 1 file changed, 152 insertions(+), 54 deletions(-) diff --git a/README.rst b/README.rst index 42f80d02a4..a5d0098e26 100644 --- a/README.rst +++ b/README.rst @@ -54,7 +54,9 @@ modification, extension and reuse. Quick start =========== -Install required libraries and packages (if not already done):: +Install required libraries and packages (if not already done) + +.. code-block:: shell pip install conan conan install . --build=missing @@ -62,13 +64,17 @@ Install required libraries and packages (if not already done):: ./install-sarah Build a spectrum generator (here: HSSUSY [1710.03760]_ -[1804.09410]_):: +[1804.09410]_) + +.. code-block:: shell ./createmodel --name=HSSUSY ./configure --with-models=HSSUSY make -j4 -Run the spectrum generator:: +Run the spectrum generator + +.. code-block:: shell ./models/HSSUSY/run_HSSUSY.x --slha-input-file=model_files/HSSUSY/LesHouches.in.HSSUSY @@ -103,17 +109,23 @@ Installation of required/optional libraries The required and optional libraries Boost_, `Eigen 3`_, GM2Calc_, LoopTools_, Himalaya_ and TSIL_ can be installed using the Conan_ package manager. If not already installed, Conan can be installed -with pip:: +with pip + +.. code-block:: shell pip install conan -To install the libraries required by FlexibleSUSY, run:: +To install the libraries required by FlexibleSUSY, run + +.. code-block:: shell conan install . --build=missing The `GNU scientific library`_ can currently not be installed via Conan_. One may use the package manager of the operating system to -install it. On Debian/Ubuntu one may run for example:: +install it. On Debian/Ubuntu one may run for example + +.. code-block:: shell sudo apt-get install libgsl-dev @@ -126,7 +138,9 @@ Installation of SARAH FlexibleSUSY requires SARAH to be installed and to be loadable with the ``Needs["SARAH`"]`` command from inside Mathematica. We recommend -the following setup:: +the following setup + +.. code-block:: shell SARAH_VERSION=4.14.5 cd ~/.Mathematica/Applications/ @@ -138,7 +152,9 @@ the following setup:: echo "AppendTo[\$Path, \"${HOME}/.Mathematica/Applications/SARAH/\"];" >> init.m All the above steps can be executed at once with the ``install-sarah`` -script:: +script + +.. code-block:: shell ./install-sarah @@ -151,7 +167,9 @@ If you want FlexibleSUSY to use FeynArts_ or FormCalc_ you will need to install these packages first. Also — as with SARAH — they need to be loadable with the ``Needs[]`` command from inside Mathematica. We recommend using the installation script ``FeynInstall`` provided on -the FeynArts web page. e.g.:: +the FeynArts web page. e.g. + +.. code-block:: shell cd ~/.local wget http://www.feynarts.de/FeynInstall @@ -175,7 +193,9 @@ Building a FlexibleSUSY model already plenty of pre-installed model files in FlexibleSUSY's and SARAH's model directories that can be used. -1. Create a new or re-initialize an existing FlexibleSUSY model:: +1. Create a new or re-initialize an existing FlexibleSUSY model + + .. code-block:: shell ./createmodel --name= @@ -193,7 +213,9 @@ Building a FlexibleSUSY model documentation of the `FlexibleSUSY model file`_ and `FlexibleEFTHiggs`_. -2. Create the Makefile and register your model(s):: +2. Create the Makefile and register your model(s) + + .. code-block:: shell ./configure --with-models= @@ -214,7 +236,9 @@ Building a FlexibleSUSY model * ``models//run_.x``: command line spectrum generator * ``models//run_.m``: Mathematica interface -Example:: +Example + +.. code-block:: shell ./createmodel --name=HSSUSY ./configure --with-models=HSSUSY @@ -252,13 +276,17 @@ Command line For each model FlexibleSUSY creates an executable ``models//run_.x`` that can be run from the command line. The executable accepts the input in the SLHA format, for -example in form of a file:: +example in form of a file + +.. code-block:: shell ./models/MSSM/run_MSSM.x \ --slha-input-file=models/MSSM/LesHouches.in.MSSM \ --slha-output-file=LesHouches.out.MSSM -or as a stream:: +or as a stream + +.. code-block:: shell cat models/MSSM/LesHouches.in.MSSM \ | ./models/MSSM/run_MSSM.x --slha-input-file=- --slha-output-file=LesHouches.out.MSSM @@ -267,7 +295,9 @@ For a documentation of FlexibleSUSY-specific switches in the SLHA input see the section on `SLHA input parameters`_. By default the executable writes the output in SLHA format to stdout. -The output can also be appended to an SQLite database:: +The output can also be appended to an SQLite database + +.. code-block:: shell ./models/MSSM/run_MSSM.x \ --slha-input-file=models/MSSM/LesHouches.in.MSSM \ @@ -282,7 +312,9 @@ Mass spectrum and renormalization group running The pole mass spectrum and the RG flow can be written to text files for easy plotting. In the MSSM for example these text files can be -generated via:: +generated via + +.. code-block:: shell ./models/MSSM/run_MSSM.x \ --slha-input-file=model_files/MSSM/LesHouches.in.MSSM \ @@ -291,7 +323,9 @@ generated via:: The generated files ``MSSM_rgflow.dat`` and ``MSSM_spectrum.dat`` can be plotted for example with the gnuplot scripts in the model -directory:: +directory + +.. code-block:: shell gnuplot -persist -e "filename='MSSM_spectrum.dat'" \ models/MSSM/MSSM_plot_spectrum.gnuplot @@ -341,7 +375,9 @@ Example For each model, FlexibleSUSY creates an example Mathematica script which illustrates the use of the Mathematica interface. The generated example can be found in ``models//run_.m`` which can be -run for example as:: +run for example as + +.. code-block:: shell math -run "<< \"models//run_.m\"" @@ -375,7 +411,9 @@ Examples: To perform a scan over :math:`\tan\beta(M_Z)` in the CMSSM (given in the SLHA input file in the ``MINPAR[3]`` field) and print out the the values of :math:`\tan\beta(M_Z)`, :math:`M_h` (``MASS[25]``) and -:math:`y_t(M_{\text{SUSY}})` (``YU[2,2]``) run:: +:math:`y_t(M_{\text{SUSY}})` (``YU[2,2]``) run + +.. code-block:: shell utils/scan-slha.sh \ --spectrum-generator=models/CMSSM/run_CMSSM.x \ @@ -384,7 +422,8 @@ values of :math:`\tan\beta(M_Z)`, :math:`M_h` (``MASS[25]``) and --output=MINPAR[3],MASS[25],YU[2:2] Alternatively, the SLHA input can be piped into the script as -:: + +.. code-block:: shell cat model_files/CMSSM/LesHouches.in.CMSSM \ | utils/scan-slha.sh \ @@ -395,7 +434,9 @@ Alternatively, the SLHA input can be piped into the script as The spectrum generator executable is specified using the ``--spectrum-generator=`` option. The parameter to be scanned over as well as the scan range and the number of steps must be specified using -the ``--scan-range=`` option. The syntax is:: +the ``--scan-range=`` option. The syntax is + +.. code-block:: shell --scan-range=[]=~: @@ -407,7 +448,9 @@ size is linear. Alternatively, a logarithmic step size can be chosen by passing ``--step-size=log`` to the script. See also ``utils/scan-slha.sh --help``. The parameters to print to the output stream must be defined using the ``--output=`` option. The syntax -is:: +is + +.. code-block:: shell --output=[] @@ -423,7 +466,9 @@ Database output As an alternative, all parameters calculated during a scan can be written to a SQLite database using the ``scan-database.sh`` script. -Examples:: +Examples + +.. code-block:: shell utils/scan-database.sh \ --spectrum-generator=models/CMSSM/run_CMSSM.x \ @@ -431,7 +476,9 @@ Examples:: --scan-range=MINPAR[3]=1~30:10 \ --database-output-file=scan.db -or:: +or + +.. code-block:: shell cat model_files/CMSSM/LesHouches.in.CMSSM \ | ./utils/scan-database.sh \ @@ -451,7 +498,9 @@ file (``FlexibleSUSY.m.in``). The conversion is not perfect, because it is usually not unique. Therefore one should check the generated ``FlexibleSUSY.m.in`` file. -Example:: +Example + +.. code-block:: shell cat << EOF | math -noprompt > FlexibleSUSY.m.in sphenoFile = "~/.Mathematica/Applications/SARAH/Models/MSSM/SPheno.m"; @@ -467,7 +516,9 @@ Generating source code files only (no compilation) If you want to only create the C++ source files for your model, but do not want to compile the code, you can use the ``--disable-compile`` -configure option:: +configure option + +.. code-block:: shell ./configure --with-models=MSSM --disable-compile make @@ -482,7 +533,9 @@ Compile only (don't generate source code) ----------------------------------------- If you want to only compile already created the C++ source files for -your model, you can use the ``--disable-meta`` configure option:: +your model, you can use the ``--disable-meta`` configure option + +.. code-block:: shell ./configure --with-models=MSSM --disable-meta make @@ -508,12 +561,15 @@ code for the specified model(s) (but without the Mathematica meta code), can be exported to a new directory. The exported source code is a complete standalone package, with it's own build system. To export the code, one has to set the target directory during -configuration via the ``--with-install-dir=`` option. For example:: +configuration via the ``--with-install-dir=`` option. For example + +.. code-block:: shell ./configure --with-models= --with-install-dir=/path/to/export/directory Afterwards -:: + +.. code-block:: shell make install-src @@ -521,7 +577,9 @@ must be executed, which will copy the generated C++ source code for all ```` to ``/path/to/export/directory``, together with the non-model specific source code from ``config/``, ``doc/``, ``slhaea/`` and ``src/``. Afterwards, the standalone package can be build like -this:: +this + +.. code-block:: shell cd /path/to/export/directory ./configure @@ -532,7 +590,8 @@ the generated source code for a given model, but does not contain the whole FlexibleSUSY build system. This is useful when the source code for a model should be generated on one computer and later transferred to another one to be compiled. To create such a "model package" run -:: + +.. code-block:: shell make pack--src @@ -550,7 +609,9 @@ libraries, which is the default) you need to pass the name extension for the shared libraries as well as the command to build them can be overwritten using the ``--with-shared-lib-ext=`` ``--with-shared-lib-cmd=``. parameters. For example, when Intel -compilers should be used, replace gcc by icc or icpc:: +compilers should be used, replace gcc by icc or icpc + +.. code-block:: shell ./configure --with-models=CMSSM,NMSSM \ --enable-shared-libs \ @@ -564,7 +625,8 @@ This means that, if you for example move the FlexibleSUSY directory to another location, the executables will no longer find the libraries. To make the executables find the libraries again, you have to relink them via -:: + +.. code-block:: shell make clean-executables make allexec @@ -578,12 +640,16 @@ executables by passing ``--enable-static`` to configure. This is useful when the executable should be transferred to another computer, where some libraries are not available. -Example:: +Example + +.. code-block:: shell ./configure --with-models=CMSSM --enable-static If ``--enable-static`` is used, the following linker flags and -additional libraries will be used:: +additional libraries will be used + +.. code-block:: shell LDFLAGS = -static LDLIBS = -ldl @@ -592,7 +658,9 @@ These linker-specific flags and additional libraries can be overwritten using ``--with-static-ldflags=`` and ``--with-static-ldlibs=`` -Example:: +Example + +.. code-block:: shell ./configure --with-models=CMSSM \ --enable-static \ @@ -617,14 +685,18 @@ functions can be used: * FFlite (a thread-safe variant of LoopTools_, shipped with FlexibleSUSY) The loop function libraries can be enabled by passing -``--with-loop-libraries=`` to the ``configure`` script:: +``--with-loop-libraries=`` to the ``configure`` script + +.. code-block:: shell ./configure --with-loop-libraries= where ```` can be any (or a combination) of ``collier``, ``looptools`` or ``fflite``. -Example:: +Example + +.. code-block:: shell ./configure --with-loop-libraries=collier,looptools @@ -657,11 +729,15 @@ LoopTools support It is possible to use LoopTools_ for calculating the loop functions, instead of using SOFTSUSY's loop functions. To enable LoopTools, -configure FlexibleSUSY via :: +configure FlexibleSUSY via + +.. code-block:: shell ./configure --enable-looptools -or:: +or + +.. code-block:: shell ./configure --with-loop-libraries=looptools @@ -670,7 +746,8 @@ automatically find the paths to the LoopTools library. To use the LoopTools library and header files from a specific directory, run ``configure`` via -:: + +.. code-block:: shell LOOPTOOL_DIR=/path/to/looptools/build @@ -681,7 +758,8 @@ directory, run ``configure`` via Note: LoopTools 2.8 or higher is required. Also, if FlexibleSUSY is compiled with LibraryLink (default) then LoopTools has to be compiled with ``-fPIC`` option. This is achieved by setting the ``FFLAGS`` variable during LoopTools configuration as -:: + +.. code-block:: shell FFLAGS=-fPIC ./configure @@ -690,12 +768,16 @@ COLLIER support It is possible to use COLLIER_ for calculating the loop functions, instead of using SOFTSUSY's loop functions. To enable COLLIER -configure FlexibleSUSY via :: +configure FlexibleSUSY via + +.. code-block:: shell ./configure --with-loop-libraries=collier To use the COLLIER library and header files from a specific -directory configure via :: +directory configure via + +.. code-block:: shell COLLIER_DIR=/path/to/COLLIER-x.y.z @@ -715,7 +797,9 @@ such models are activated (via ``./configure --with-models=``), FlexibleSUSY requires TSIL to be available. If TSIL is installed in a system directory or installed via Conan_, FlexibleSUSY will find the TSIL automatically. To use TSIL from a a non-standard directory, -configure FlexibleSUSY like this:: +configure FlexibleSUSY like this + +.. code-block:: shell $TSIL_DIR=/path/to/tsil @@ -724,7 +808,9 @@ configure FlexibleSUSY like this:: --with-tsil-libdir=$TSIL_DIR Note also that TSIL must be compiled with ``-fPIC``, which can be -achieved by setting in the TSIL ``Makefile``:: +achieved by setting in the TSIL ``Makefile`` + +.. code-block:: shell TSIL_OPT = -O3 -funroll-loops -fPIC @@ -734,7 +820,9 @@ Creating an addon A FlexibleSUSY addon is a program or library, which uses parts of the FlexibleSUSY libraries or the generated models or is integrated into -FlexibleSUSY. An addon can be created via :: +FlexibleSUSY. An addon can be created via + +.. code-block:: shell ./createaddon --name= @@ -744,20 +832,24 @@ module ``addons//module.mk``. If an addon has been created with the above script, the user may edit the makefile module (``addons//module.mk``) to add source files in to the three variables -:: + +.. code-block:: shell LIB@ADDON@_SRC # list of source files to be included in library EXE@ADDON@_SRC # list of source files with a main() LIB@ADDON@_HDR # list of header files -Example:: +Example + +.. code-block:: shell LIB@ADDON@_SRC := $(DIR)/file1.cpp EXE@ADDON@_SRC := $(DIR)/run.cpp LIB@ADDON@_HDR := $(DIR)/file1.hpp To configure and compile the addon run -:: + +.. code-block:: shell ./configure --with-addons= make @@ -773,23 +865,29 @@ Creating the source code documentation FlexibleSUSY's source code documentation (including the generated source code files) can be generated with Doxygen in HTML or man -format. To generate the HTML documentation please run:: +format. To generate the HTML documentation please run + +.. code-block:: shell make doc-html The generated HTML index file can then be found in ``doc/html/index.html`` and can be viewed with any HTML browser, e.g. -:: + +.. code-block:: shell firefox doc/html/index.html -To generate the man documentation please run:: +To generate the man documentation please run + +.. code-block:: shell make doc-man The generated man pages can then be found in ``doc/man/man3/`` and can be viewed as -:: + +.. code-block:: shell man doc/man/man3/model_file_options.3 From abdb33f42fb56bd6094fa9918236be2edea204d3 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Mon, 28 Jun 2021 08:00:33 +0200 Subject: [PATCH 015/477] fix GM2Calc link --- README.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index a5d0098e26..ceec4c31bd 100644 --- a/README.rst +++ b/README.rst @@ -34,6 +34,9 @@ modification, extension and reuse. please cite [1005.5709]_, [1708.05720]_, [1807.03509]_ and [1910.03595]_. + If you use **FlexibleSUSY+GM2Calc** in your work, please cite + [1510.08071]_. + If you use **FlexibleDecay** in your work, please cite [2106.05038]_. @@ -994,7 +997,7 @@ References ========== .. _slhaea: https://github.com/fthomas/slhaea -.. _GM2Calc: https://arxiv.org/abs/1510.08071 +.. _GM2Calc: https://github.com/GM2Calc/GM2Calc .. _SARAH: http://sarah.hepforge.org .. _SOFTSUSY: http://softsusy.hepforge.org .. _Boost: http://www.boost.org @@ -1022,6 +1025,7 @@ References .. [1309.7223] `CPC 185 (2014) 1773-1790 `_ [`arxiv:1309.7223 `_] .. [1311.7659] `CPC 185 (2014) 2322 `_ [`arxiv:1311.7659 `_] .. [1406.2319] `CPC 190 (2015) 139-172 `_ [`arxiv:1406.2319 `_] +.. [1510.08071] `Eur. Phys. J. C76 (2016) no. 2, 62 `_ [`arXiv:1510.08071 `_] .. [1609.00371] `JHEP 1701 (2017) 079 `_ [`arxiv:1609.00371 `_] .. [1708.05720] `Eur.Phys.J. C77 (2017) no.12, 814 `_ [`arxiv:1708.05720 `_] .. [1710.03760] `CPC 230 (2018) 145-217 `_ [`arXiv:1710.03760 `_] From 45be951f1c9073ea77b07efac83eef7995e1bc0c Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Mon, 5 Jul 2021 19:16:45 +0200 Subject: [PATCH 016/477] Optimization of FFV calculation (#347) * avoid replace function by faster calculation of powers * avoid redundant re-evaluation of 1-loop functions --- templates/FFV_form_factors.cpp.in | 90 ++++++++++++++++--------------- templates/l_to_lgamma.cpp.in | 12 ++--- 2 files changed, 54 insertions(+), 48 deletions(-) diff --git a/templates/FFV_form_factors.cpp.in b/templates/FFV_form_factors.cpp.in index d879ed74fc..1611ab1d9b 100644 --- a/templates/FFV_form_factors.cpp.in +++ b/templates/FFV_form_factors.cpp.in @@ -114,7 +114,7 @@ double OneLoopFunctionA(double r) } else { return (2.0 - 9.0 * r + 18.0 * r * r - 11.0 * r * r * r + 6.0 * r * r * r * std::log(r)) / - pow(1.0 - r, 4); + Power4(1.0 - r); } } @@ -145,7 +145,7 @@ double OneLoopFunctionB(double r) return 2. * (1.0 - 6.0 * r + 3.0 * r * r + 2.0 * r * r * r - 6.0 * r * r * std::log(r)) / - pow(1.0 - r, 4); + Power4(1.0 - r); } } @@ -173,7 +173,7 @@ double OneLoopFunctionC(double r) 0.0220588235294117647 * y * y * y * y * y * y * y * y * y * y * y * y * y * y - 0.0196078431372549020 * y * y * y * y * y * y * y * y * y * y * y * y * y * y * y); } else { - return 3. * (1.0 - r * r + 2.0 * r * std::log(r)) / pow(1.0 - r, 3); + return 3. * (1.0 - r * r + 2.0 * r * std::log(r)) / Power3(1.0 - r); } } @@ -184,7 +184,7 @@ double OneLoopFunctionD(double r) } else { return (16.0 - 45.0 * r + 36.0 * r * r - 7.0 * r * r * r + 6.0 * (2.0 - 3.0 * r) * std::log(r)) / - pow(1.0 - r, 4); + Power4(1.0 - r); } } @@ -214,7 +214,7 @@ double OneLoopFunctionE(double r) } else { return 2. * (2.0 + 3.0 * r - 6.0 * r * r + r * r * r + 6.0 * r * std::log(r)) / - pow(1.0 - r, 4); + Power4(1.0 - r); } } @@ -223,8 +223,8 @@ double OneLoopFunctionF(double r) const double y = r - 1.0; if (std::abs(y) < 0.155) { // error around x=1 is <= 10^-13 on an intel i7 - return (1.0 - - 0.75 * y + + return (1.0 - + 0.75 * y + 0.6 * y * y - 0.50000000000000000000 * y * y * y + 0.4285714285714285714 * y * y * y * y - @@ -241,7 +241,7 @@ double OneLoopFunctionF(double r) 0.16666666666666666667 * y * y * y * y * y * y * y * y * y * y * y * y * y * y * y); } else { return 3. / 2. * (-3.0 + 4.0 * r - r * r - 2.0 * std::log(r)) / - pow(1.0 - r, 3); + Power3(1.0 - r); } } @@ -272,7 +272,7 @@ std::valarray> FFV_SSF::value( for (const auto& indexIn: index_range()) { for (const auto& indexOut: index_range()) { - // cycle if generations of external fermions are different then requested + // cycle if generations of external fermions are different then requested const auto jFieldIndices = VertexFBarFjSBar::template indices_of_field<2>(indexIn); const auto iFieldIndices = VertexFiBarFS::template indices_of_field<0>(indexOut); if (jFieldIndices != indices_in || iFieldIndices != indices_out) @@ -287,7 +287,7 @@ std::valarray> FFV_SSF::value( // match indices of the scalar in the loop const auto scalarFieldIndicesIn = VertexFBarFjSBar::template indices_of_field<1>(indexIn); const auto scalarIndicesOut = VertexFiBarFS::template indices_of_field<1>(indexOut); - if (scalarFieldIndicesIn != scalarIndicesOut) + if (scalarFieldIndicesIn != scalarIndicesOut) continue; if (discard_SM_contributions) { @@ -304,29 +304,32 @@ std::valarray> FFV_SSF::value( const auto mS = context.mass(scalarFieldIndicesIn); const auto mF = context.mass(fermionFieldIndicesIn); - const auto x = pow(mF/mS, 2); + const auto x = Power2(mF/mS); + const auto oneLoopFunctionA = OneLoopFunctionA(x); + const auto oneLoopFunctionB = OneLoopFunctionB(x); + const auto oneLoopFunctionC = OneLoopFunctionC(x); // TODO: check the sign convention of this coupling std::complex vector_boson_coupling {-vertexEmit.value(1,0)}; // eq. 15 of hep-ph/9510309 (possibly with different sign) const std::complex A1L = - - 1./18. * vertexOut.right() * vertexIn.left() * OneLoopFunctionA(x); + - 1./18. * vertexOut.right() * vertexIn.left() * oneLoopFunctionA; // eq. 16 of hep-ph/9510309 (possibly with different sign) - const std::complex A2L = - - vertexOut.left() * vertexIn.right() * OneLoopFunctionB(x)/12. - - vertexOut.left()* vertexIn.left() * mF/mj * OneLoopFunctionC(x)/3. - - mi/mj * vertexOut.right() * vertexIn.left() * OneLoopFunctionB(x)/12.; + const std::complex A2L = + - vertexOut.left() * vertexIn.right() * oneLoopFunctionB/12. + - vertexOut.left()* vertexIn.left() * mF/mj * oneLoopFunctionC/3. + - mi/mj * vertexOut.right() * vertexIn.left() * oneLoopFunctionB/12.; // eq. 15 & 16 of hep-ph/9510309 after replacement L <-> R (possibly with different sign) - const std::complex A1R = - - 1./18. * vertexOut.left() * vertexIn.right() * OneLoopFunctionA(x); - const std::complex A2R = - - vertexOut.right() * vertexIn.left() * OneLoopFunctionB(x)/12. - - vertexOut.right()* vertexIn.right() * mF/mj * OneLoopFunctionC(x)/3. - - mi/mj * vertexOut.left() * vertexIn.right() * OneLoopFunctionB(x)/12.; + const std::complex A1R = + - 1./18. * vertexOut.left() * vertexIn.right() * oneLoopFunctionA; + const std::complex A2R = + - vertexOut.right() * vertexIn.left() * oneLoopFunctionB/12. + - vertexOut.right()* vertexIn.right() * mF/mj * oneLoopFunctionC/3. + - mi/mj * vertexOut.left() * vertexIn.right() * oneLoopFunctionB/12.; - const std::complex massFactor = pow(mS,-2); + const std::complex massFactor = 1.0/Power2(mS); res += oneOver32PiSqr * vector_boson_coupling * massFactor * std::valarray> {A1L, A1R, A2L, A2R}; @@ -346,14 +349,14 @@ std::valarray> FFV_FFS::value( { static_assert( - std::is_same::type::value, + std::is_same::type::value, "Internal fermions in the FFV_FFS instantiation must be of the same type." ); using VertexFBarFjSBar = Vertex; using VertexFiBarFS = Vertex; using VertexFBarFVBar = Vertex; - + // masses of external fermions const auto mj = context.mass(indices_in); const auto mi = context.mass(indices_out); @@ -363,7 +366,7 @@ std::valarray> FFV_FFS::value( for (const auto& indexIn: index_range()) { for (const auto& indexOut: index_range()) { - // cycle if generations of external fermions are different then requested + // cycle if generations of external fermions are different then requested const auto jFieldIndices = VertexFBarFjSBar::template indices_of_field<2>(indexIn); const auto iFieldIndices = VertexFiBarFS::template indices_of_field<0>(indexOut); if (jFieldIndices != indices_in || iFieldIndices != indices_out) @@ -376,7 +379,7 @@ std::valarray> FFV_FFS::value( const auto scalarFieldIndicesIn = VertexFBarFjSBar::template indices_of_field<0>(indexIn); const auto scalarIndicesOut = VertexFiBarFS::template indices_of_field<2>(indexOut); - if (scalarFieldIndicesIn != scalarIndicesOut) + if (scalarFieldIndicesIn != scalarIndicesOut) continue; if (discard_SM_contributions) { @@ -387,34 +390,37 @@ std::valarray> FFV_FFS::value( const auto vertexIn = VertexFBarFjSBar::evaluate(indexIn, context); const auto vertexOut = VertexFiBarFS::evaluate(indexOut, context); - + const auto indexEmit = concatenate(fermionFieldIndicesIn, fermionFieldIndicesIn); const auto vertexEmit = VertexFBarFVBar::evaluate(indexEmit, context); const auto mF = context.mass(fermionFieldIndicesIn); const auto mS = context.mass(scalarFieldIndicesIn); - const auto x = pow(mF/mS, 2); + const auto x = Power2(mF/mS); + const auto oneLoopFunctionD = OneLoopFunctionD(x); + const auto oneLoopFunctionE = OneLoopFunctionE(x); + const auto oneLoopFunctionF = OneLoopFunctionF(x); std::complex vector_boson_coupling {vertexEmit.left()}; // eq. 18 of hep-ph/9510309 (possibly with different sign) const std::complex A1L = - - 1./18. * vertexOut.right() * vertexIn.left() * OneLoopFunctionD(x); + - 1./18. * vertexOut.right() * vertexIn.left() * oneLoopFunctionD; // eq. 19 of hep-ph/9510309 (possibly with different sign) - const std::complex A2L = - - vertexOut.left() * vertexIn.right() * OneLoopFunctionE(x)/12.0 - - vertexOut.left()* vertexIn.left() * mF/mj * OneLoopFunctionF(x) * 2./3. - - mi/mj * vertexOut.right() * vertexIn.left() * OneLoopFunctionE(x)/12.0; + const std::complex A2L = + - vertexOut.left() * vertexIn.right() * oneLoopFunctionE/12.0 + - vertexOut.left()* vertexIn.left() * mF/mj * oneLoopFunctionF * 2./3. + - mi/mj * vertexOut.right() * vertexIn.left() * oneLoopFunctionE/12.0; // eq. 18 & 18 of hep-ph/9510309 after replacement L <-> R (possibly with different sign) - const std::complex A1R = - - 1./18. * vertexOut.left() * vertexIn.right() * OneLoopFunctionD(x); - const std::complex A2R = - - vertexOut.right() * vertexIn.left() * OneLoopFunctionE(x)/12.0 - - vertexOut.right()* vertexIn.right() * mF/mj * OneLoopFunctionF(x) * 2./3. - - mi/mj * vertexOut.left() * vertexIn.right() * OneLoopFunctionE(x)/12.0; - - const std::complex massFactor = pow(mS,-2); + const std::complex A1R = + - 1./18. * vertexOut.left() * vertexIn.right() * oneLoopFunctionD; + const std::complex A2R = + - vertexOut.right() * vertexIn.left() * oneLoopFunctionE/12.0 + - vertexOut.right()* vertexIn.right() * mF/mj * oneLoopFunctionF * 2./3. + - mi/mj * vertexOut.left() * vertexIn.right() * oneLoopFunctionE/12.0; + + const std::complex massFactor = 1.0/Power2(mS); res += oneOver32PiSqr * vector_boson_coupling * massFactor * std::valarray> {A1L, A1R, A2L, A2R}; diff --git a/templates/l_to_lgamma.cpp.in b/templates/l_to_lgamma.cpp.in index d2fae9040c..b494c37449 100644 --- a/templates/l_to_lgamma.cpp.in +++ b/templates/l_to_lgamma.cpp.in @@ -53,16 +53,16 @@ double lepton_total_decay_width( const auto leptonInMass = context.mass(indices1); const auto leptonOutMass = context.mass(indices2); - const auto r = pow(leptonOutMass/leptonInMass, 2); - const auto GF2 = pow(qedqcd.displayFermiConstant(), 2); - const double Alpha = Sqr(FIn::electric_charge * unit_charge(context))/(4*Pi); + const auto r = Power2(leptonOutMass/leptonInMass); + const auto GF2 = Power2(qedqcd.displayFermiConstant()); + const double Alpha = Power2(FIn::electric_charge * unit_charge(context))/(4*Pi); // eq. 10.6 of http://pdg.lbl.gov/2018/reviews/rpp2018-rev-standard-model.pdf - return + return // tree-level (with massless outgoing lepton) - GF2*pow(leptonInMass,5)/(192.0*pow(Pi,3)) + GF2*Power5(leptonInMass)/(192.0*Power3(Pi)) // outgoing lepton mass correction - * (1 - 8*r + 8*pow(r,3) - pow(r,4) - 12*r*r*std::log(r)); + * (1 - 8*r + 8*Power3(r) - Power4(r) - 12*r*r*std::log(r)); // higher order correction //* (1.0 + 0.5 * Alpha * (6.25-Sqr(Pi))/Pi) } From c00c3d95fdda7225a4a11b0f092ed905ce8ee434 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Tue, 6 Jul 2021 16:56:21 +0200 Subject: [PATCH 017/477] adapt code to changes in the paper before submission to CPC --- meta/Decays.m | 5 ++++- test/test_MSSMCPV_FlexibleDecay.cpp | 2 +- test/test_MSSM_FlexibleDecay.cpp | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/meta/Decays.m b/meta/Decays.m index 3ecff1872b..9058556249 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -1890,7 +1890,10 @@ would violate Ward identity (as at the level of dim 4 "vertexId" <> ToString@First@#2 <> "::template indices_of_field<" <> ToString@Utils`MathIndexToCPP@First@First@pos1 <> ">(indexId" <> ToString@First@#2 <> ") == " <> "vertexId" <> ToString@First@#2 <> "::template indices_of_field<" <> ToString@Utils`MathIndexToCPP@First@First@pos2 <> ">(indexId" <> ToString@First@#2 <> ")" ])&, verticesForFACp]," &&\n"] <> - "\n&& result.m_decay/mInternal1 < 0.8\n" + (* mPhi/mq < 0.8 *) + "\n&& result.m_decay/mInternal1 < 0.8" <> + (* mZ/mPhi < 0.75 *) + " && " <> If[TreeMasses`IsZBoson[diagram[[2]]], "result.m_vector_1", "result.m_vector_2"] <> "/result.m_decay < 0.75\n" ] <> ") {\n" <> (* eq. 2.57 of hep-ph/0503172 *) diff --git a/test/test_MSSMCPV_FlexibleDecay.cpp b/test/test_MSSMCPV_FlexibleDecay.cpp index 9ad3a72db0..3e9bbe38aa 100644 --- a/test/test_MSSMCPV_FlexibleDecay.cpp +++ b/test/test_MSSMCPV_FlexibleDecay.cpp @@ -790,7 +790,7 @@ Block ImMSOFT Q= 2.00000000E+03 // with 2L QCD for squark BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 1), 5.3089300093115946e-06, 5e-10); // h -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 1), 5.2147958529458097e-07, 7e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 1), 5.1994372474535712e-07, 7e-11); // ----------------------------------------------------- // decays without higher-order SM corrections diff --git a/test/test_MSSM_FlexibleDecay.cpp b/test/test_MSSM_FlexibleDecay.cpp index dc65f1f72f..92b2c22a2e 100644 --- a/test/test_MSSM_FlexibleDecay.cpp +++ b/test/test_MSSM_FlexibleDecay.cpp @@ -683,7 +683,7 @@ Block MSOFT Q= 8.61574711E+02 // with 2L QCD for squark BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 0), 7.271047934944202e-06, 4e-11); // h -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 0), 2.2268180468443525e-06, 2e-10); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 0), 2.2198080013381038e-06, 2e-10); // pseudoscalar Higgs BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00043378057279629952, 4e-13); From 85b1ae7c09cce7b163e7308f0aba3555e2eeade8 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 7 Jul 2021 04:53:16 +0200 Subject: [PATCH 018/477] added link to Mathematica --- README.rst | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/README.rst b/README.rst index ceec4c31bd..6968440b06 100644 --- a/README.rst +++ b/README.rst @@ -90,7 +90,7 @@ Requirements * C++ compiler (g++ >= 5.0.0 or clang++ >= 3.8.1 or icpc >= 17.0.0) * Fortran compiler (gfortran, ifort) -* Mathematica (version 11.0 or higher) +* `Mathematica/Wolfram Engine`_ (version 11.0 or higher) * SARAH_ (version 4.11.0 or higher) * Boost_ (version 1.37.0 or higher) * `Eigen 3`_ (version 3.1 or higher) @@ -1005,11 +1005,12 @@ References .. _Eigen 3: http://eigen.tuxfamily.org .. _FeynArts: http://www.feynarts.de .. _FormCalc: http://www.feynarts.de/formcalc -.. _GNU scientific library: http://www.gnu.org/software/gsl/ -.. _LoopTools: http://www.feynarts.de/looptools/ -.. _COLLIER: https://collier.hepforge.org/ +.. _GNU scientific library: http://www.gnu.org/software/gsl +.. _`Mathematica/Wolfram Engine`: https://www.wolfram.com +.. _LoopTools: http://www.feynarts.de/looptools +.. _COLLIER: https://collier.hepforge.org .. _Himalaya: https://github.com/Himalaya-Library/Himalaya -.. _TSIL: https://www.niu.edu/spmartin/tsil/ +.. _TSIL: https://www.niu.edu/spmartin/tsil .. _`FlexibleSUSY model file`: doc/model_file.rst .. _`FlexibleEFTHiggs`: doc/FlexibleEFTHiggs.rst From 36f24f3d3974bb212f357699319df568815c865b Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 7 Jul 2021 11:55:37 +0200 Subject: [PATCH 019/477] updated changelog; bumped FS version to 2.6.1 --- CHANGES.rst | 4 +++- configure | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index d5967d595a..afcb0bd69c 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -6,11 +6,13 @@ Changes * Removed code computing Higgs effective couplings. This code has been superseded by FlexibleDecay. +* FlexibleDecay: 2-loop QCD corrections to `$\Phi \to \Gamma Z$` applied + only if `$m_Z/m_\Phi < 0.75$`. Fixed bugs ---------- -* [commit ]: Fix error in FFV form factors module cased by models where +* [commit 21ed4cc6b]: Fix error in FFV form factors module cased by models where SARAH generates non zero photon (gluon) couplings to QED (QCD) singlets. * [commit a0bbda569]: Correcting check for required Mathematica version diff --git a/configure b/configure index fe0c7373bb..b20d5d0649 100755 --- a/configure +++ b/configure @@ -6,7 +6,7 @@ PROGRAM_NAME=FlexibleSUSY FLEXIBLESUSY_MAJOR=2 FLEXIBLESUSY_MINOR=6 -FLEXIBLESUSY_PATCH=0 +FLEXIBLESUSY_PATCH=1 FLEXIBLESUSY_EXTRA="" FLEXIBLESUSY_VERSION="${FLEXIBLESUSY_MAJOR}.${FLEXIBLESUSY_MINOR}.${FLEXIBLESUSY_PATCH}${FLEXIBLESUSY_EXTRA}" GIT_COMMIT=$(git rev-parse HEAD 2> /dev/null || echo unknown) From 804e8b39105dd96fc2ff0d3b20a874c2472defaf Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Thu, 8 Jul 2021 09:05:31 +0200 Subject: [PATCH 020/477] version 2.6.1 --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index afcb0bd69c..496223b211 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,4 +1,4 @@ -FlexibleSUSY 2.6.1 [?, ?? 202?] +FlexibleSUSY 2.6.1 [July, 08 2021] ================================== Changes From b6cf33906bfb4abf4f1eb598e2e4ce675ade967c Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Fri, 9 Jul 2021 05:23:17 +0200 Subject: [PATCH 021/477] fixed format of EPJC references --- README.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.rst b/README.rst index 6968440b06..9e33a15349 100644 --- a/README.rst +++ b/README.rst @@ -1028,9 +1028,9 @@ References .. [1406.2319] `CPC 190 (2015) 139-172 `_ [`arxiv:1406.2319 `_] .. [1510.08071] `Eur. Phys. J. C76 (2016) no. 2, 62 `_ [`arXiv:1510.08071 `_] .. [1609.00371] `JHEP 1701 (2017) 079 `_ [`arxiv:1609.00371 `_] -.. [1708.05720] `Eur.Phys.J. C77 (2017) no.12, 814 `_ [`arxiv:1708.05720 `_] +.. [1708.05720] `Eur. Phys. J. C77 (2017) no. 12, 814 `_ [`arxiv:1708.05720 `_] .. [1710.03760] `CPC 230 (2018) 145-217 `_ [`arXiv:1710.03760 `_] -.. [1804.09410] `Eur.Phys.J. C78 (2018) no.7, 573 `_ [`arxiv:1804.09410 `_] -.. [1807.03509] `Eur.Phys.J. C78 (2018) no.10, 874 `_ [`arxiv:1807.03509 `_] -.. [1910.03595] `Eur.Phys.J. `_ [`arxiv:1910.03595 `_] +.. [1804.09410] `Eur. Phys. J. C78 (2018) no. 7, 573 `_ [`arxiv:1804.09410 `_] +.. [1807.03509] `Eur. Phys. J. C78 (2018) no. 10, 874 `_ [`arxiv:1807.03509 `_] +.. [1910.03595] `Eur. Phys. J. C80 (2020) no. 3, 186 `_ [`arxiv:1910.03595 `_] .. [2106.05038] [`arxiv:2106.05038 `_] From a6f4e62130be904f3ec0a170ebe2f1d6b09a5b9f Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sat, 17 Jul 2021 20:15:35 +0200 Subject: [PATCH 022/477] added ColorMath reference to the list of references --- doc/references.bib | 17 +++++++++++++++++ meta/FlexibleSUSY.m | 1 + 2 files changed, 18 insertions(+) diff --git a/doc/references.bib b/doc/references.bib index 3c1e3308ca..a60a58b49d 100644 --- a/doc/references.bib +++ b/doc/references.bib @@ -88,6 +88,23 @@ @article{Athron:2021kve year = "2021" } +% ColorMath +% \cite{Sjodahl:2012nk} +@article{Sjodahl:2012nk, + author = {Sj\"odahl, Malin}, + title = "{ColorMath - A package for color summed calculations in SU(Nc)}", + eprint = "1211.2099", + archivePrefix = "arXiv", + primaryClass = "hep-ph", + reportNumber = "LU-TP-12-40, MCNET-13-04", + doi = "10.1140/epjc/s10052-013-2310-4", + journal = "Eur. Phys. J. C", + volume = "73", + number = "2", + pages = "2310", + year = "2013" +} + % \cite{Harlander:2018yhj} @article{Harlander:2018yhj, author = "Harlander, R. V. and Klappert, J. and Ochoa Franco, A. D. diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index 28c46b8c9b..0e33f75ab2 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -3178,6 +3178,7 @@ corresponding tadpole is real or imaginary (only in models with CP If[FlexibleSUSY`FSCalculateDecays, References`AddReference["Athron:2021kve"]; + References`AddReference["Sjodahl:2012nk"]; ]; If[FlexibleSUSY`UseYukawa3LoopQCD || FlexibleSUSY`FlexibleEFTHiggs, From efc8aeb8c685e847655f6e6815d4c17c86d064be Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sun, 18 Jul 2021 13:49:10 +0200 Subject: [PATCH 023/477] fixed uncompleted sentence in documentation --- doc/observables/FlexibleDecay.rst | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/doc/observables/FlexibleDecay.rst b/doc/observables/FlexibleDecay.rst index 2af666d913..094dcb982f 100644 --- a/doc/observables/FlexibleDecay.rst +++ b/doc/observables/FlexibleDecay.rst @@ -13,7 +13,7 @@ Creating model with decays Whether decays are created for a given model is controled by the viariable .. code-block:: mathematica - + FSCalculateDecays = True; in the model's ``FlexibleSUSY.m.in`` file. @@ -23,7 +23,7 @@ In models distributed with FlexibleSUSY which support decays we do set it explic Which decays are included is controled by :mathematica:`FSDecayParticles` variable. It's possible values are :mathematica:`Automatic` or a list of scalars present in the model. -By default it's set to +By default it's set to .. code-block:: mathematica @@ -35,7 +35,7 @@ As an example, in SARAH's THDM-II, :mathematica:`Automatic` is equivalen to sett .. code-block:: mathematica FSDecayParticles = {hh, Ah, Hpm}; - + One can also add other scalar. For example, to add squark decays in the SARAH's MSSM one would write @@ -74,7 +74,7 @@ The flags are: 0. Turn calculation of decay on/off (default = 1). #. Minimal branching ratio to print (default = 1e-5). -#. Maximal order of included higher order corrections (default = 4). Note that not all such corrections. +#. Maximal order of included higher order corrections (default = 4). Note that corrections up to a given order are not avaliable for all processes. #. Use α in the Thomson limit instead of a running one in decays to γγ and γZ. This should minimize higher order corrections. Flag 4 controls treatment of Higgs decay to gauge bosons @@ -152,7 +152,7 @@ SLHA 1.44211112E-03 2 22 23 # BR(hh -> VP VZ) 2.63348187E-04 2 -3 3 # BR(hh -> barFd(2) Fd(2)) 2.20054695E-04 2 -13 13 # BR(hh -> barFe(2) Fe(2)) - + The output conforms to the SLHA standard. LibraryLink @@ -162,16 +162,16 @@ LibraryLink { SM -> { - hh -> { + hh -> { 25, 0.00198076, { - {25, {-15,15}, 0.000157635}, - {25, {23,23}, 3.16863*10^-7}, - {25, {-24,24}, 1.14636*10^-6}, + {25, {-15,15}, 0.000157635}, + {25, {23,23}, 3.16863*10^-7}, + {25, {-24,24}, 1.14636*10^-6}, {25, {-3,3}, 7.44681*10^-7}, - {25, {22,22}, 1.8801*10^-6}, - {25, {-13,13}, 5.58985*10^-7}, - {25, {-5,5}, 0.00164052}, - {25, {-4,4}, 0.0000812031}, + {25, {22,22}, 1.8801*10^-6}, + {25, {-13,13}, 5.58985*10^-7}, + {25, {-5,5}, 0.00164052}, + {25, {-4,4}, 0.0000812031}, {25, {21,21}, 0.0000967487} } } @@ -184,5 +184,5 @@ The output for every channel, e.g. .. code-block:: mathematica {25, {-15,15}, 0.000157635} - + contains PDG identifiers for in and out particles and a partial width in GeV. From a7ae46a899df76b7d23269bbf98c6035704764d6 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Mon, 19 Jul 2021 09:43:55 +0200 Subject: [PATCH 024/477] let the complex exp() function do the range reduction --- src/dilog.cpp | 40 ++++------------------------------------ 1 file changed, 4 insertions(+), 36 deletions(-) diff --git a/src/dilog.cpp b/src/dilog.cpp index fc6f15c1b7..74566995c8 100644 --- a/src/dilog.cpp +++ b/src/dilog.cpp @@ -63,24 +63,8 @@ namespace { */ double clausen_2(double x) noexcept { - const double PI = 3.141592653589793; - const std::complex i(0.0, 1.0); - - while (x >= 2*PI) { - x -= 2*PI; - } - - while (x < 0.0) { - x += 2*PI; - } - - if (std::abs(x) < std::numeric_limits::epsilon() || - std::abs(x - PI) < std::numeric_limits::epsilon() || - std::abs(x - 2*PI) < std::numeric_limits::epsilon()) { - return 0.0; - } - - return std::imag(dilog(std::exp(i*x))); + const std::complex ix(0.0, x); + return std::imag(dilog(std::exp(ix))); } /** @@ -90,24 +74,8 @@ double clausen_2(double x) noexcept */ long double clausen_2(long double x) noexcept { - const long double PI = 3.14159265358979323846264338327950288L; - const std::complex i(0.0L, 1.0L); - - while (x >= 2*PI) { - x -= 2*PI; - } - - while (x < 0.0L) { - x += 2*PI; - } - - if (std::abs(x) < std::numeric_limits::epsilon() || - std::abs(x - PI) < std::numeric_limits::epsilon() || - std::abs(x - 2*PI) < std::numeric_limits::epsilon()) { - return 0.0L; - } - - return std::imag(dilog(std::exp(i*x))); + const std::complex ix(0.0L, x); + return std::imag(dilog(std::exp(ix))); } /** From cc5ddd63d2fb17a5d36c7eb82b4b60874667fdfe Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Mon, 19 Jul 2021 15:32:22 +0200 Subject: [PATCH 025/477] require GSL version 2.0.0 or higher --- configure | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/configure b/configure index b20d5d0649..9dd9b59dd2 100755 --- a/configure +++ b/configure @@ -1865,9 +1865,16 @@ check_gsl_config() { message " use $0 --with-gsl-config=" exit 1 else - result "found $cmd" + local GSL_VERSION=$($cmd --version) + result "found $cmd (version ${GSL_VERSION})" GSLFLAGS=$($cmd --cflags) GSLLIBS=$($cmd --libs) + + version_at_least "$GSL_VERSION" "2.0.0" || { + message "Error: An old version of GSL has been detected ($GSL_VERSION)." + message " Please upgrade to version 2.0.0 (or higher)." + exit 1 + } fi } From 7c3035aba91688411dd935e13bcb39dc5cdb7eb7 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 22 Jul 2021 20:44:54 +0200 Subject: [PATCH 026/477] updated Wolfram Engine on CI --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index f79c7ecf15..163303c106 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -121,7 +121,7 @@ jobs: runs-on: ubuntu-20.04 container: - image: navir/opensuseleap-for-flexiblesusy:0.9.0 + image: navir/opensuseleap-for-flexiblesusy:0.9.2 strategy: matrix: From af2a5789fceedc26aba6e1eb0897427b79c0690d Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Mon, 26 Jul 2021 18:05:55 +0200 Subject: [PATCH 027/477] removed M_PI --- model_specific/SM/weinberg_angle.cpp | 5 +---- src/convergence_tester_drbar.hpp | 4 ++-- src/ew_input.hpp | 10 ++++++---- src/gm2calc_interface.cpp | 6 +++--- src/lowe.cpp | 19 ++++++++++--------- src/mathdefs.hpp | 5 +++-- test/test_QedQcd.cpp | 4 ++-- 7 files changed, 27 insertions(+), 26 deletions(-) diff --git a/model_specific/SM/weinberg_angle.cpp b/model_specific/SM/weinberg_angle.cpp index 61d4c50d3f..91f191924d 100644 --- a/model_specific/SM/weinberg_angle.cpp +++ b/model_specific/SM/weinberg_angle.cpp @@ -22,6 +22,7 @@ #include "logger.hpp" #include "numerics.h" #include "numerics2.hpp" +#include "wrappers.hpp" #include #include @@ -41,10 +42,6 @@ namespace flexiblesusy { namespace { -constexpr double Pi = 3.141592653589793; - -constexpr double oneOver16PiSqr = 1.0/(16.0*Pi*Pi); - double sqr(double x) noexcept { return x*x; } } // anonymous namespace diff --git a/src/convergence_tester_drbar.hpp b/src/convergence_tester_drbar.hpp index 42e7e54973..0bb01c1427 100644 --- a/src/convergence_tester_drbar.hpp +++ b/src/convergence_tester_drbar.hpp @@ -23,8 +23,8 @@ #include "error.hpp" #include "logger.hpp" #include "numerics2.hpp" +#include "wrappers.hpp" -#include #include #include @@ -97,7 +97,7 @@ bool Convergence_tester_DRbar::accuracy_goal_reached() if (it_count > 0) { run_to_scale(); - const double scale_accuracy_goal = accuracy_goal * 16*M_PI*M_PI; + const double scale_accuracy_goal = accuracy_goal * 16*Sqr(Pi); if (rel_scale_difference() < scale_accuracy_goal) { current_accuracy = max_rel_diff(); precision_reached = current_accuracy < accuracy_goal; diff --git a/src/ew_input.hpp b/src/ew_input.hpp index 4423355bb5..91c1b3f96d 100644 --- a/src/ew_input.hpp +++ b/src/ew_input.hpp @@ -19,6 +19,8 @@ #ifndef ELECTROWEAK_INPUT_H #define ELECTROWEAK_INPUT_H +#include "wrappers.hpp" + #include namespace flexiblesusy { @@ -63,10 +65,10 @@ namespace Electroweak_constants { constexpr double alpha1 = 5.0 * aem / (3.0 * (1.0 - sinThetaW2)); constexpr double alpha2 = aem / sinThetaW2; constexpr double alpha3 = 0.1184; // at MZ from PDG - const double e = sqrt(4.0 * M_PI * aem); - const double g1 = sqrt(4.0 * M_PI * alpha1); - const double g2 = sqrt(4.0 * M_PI * alpha2); - const double g3 = sqrt(4.0 * M_PI * alpha3); + const double e = sqrt(4.0 * Pi * aem); + const double g1 = sqrt(4.0 * Pi * alpha1); + const double g2 = sqrt(4.0 * Pi * alpha2); + const double g3 = sqrt(4.0 * Pi * alpha3); constexpr double gYSM = 3.57232027E-01; ///< gY MS-bar in the SM at Q = MZ const double g1SM = sqrt(5./3.) * gYSM; ///< g1 MS-bar in the SM at Q = MZ constexpr double g2SM = 6.51103848E-01; ///< g2 MS-bar in the SM at Q = MZ diff --git a/src/gm2calc_interface.cpp b/src/gm2calc_interface.cpp index e7d184dc70..f195d260c4 100644 --- a/src/gm2calc_interface.cpp +++ b/src/gm2calc_interface.cpp @@ -32,18 +32,18 @@ #include "gm2calc/gm2_uncertainty.hpp" #include "gm2calc/MSSMNoFV_onshell.hpp" #include "logger.hpp" -#include +#include "wrappers.hpp" namespace flexiblesusy { namespace { double calculate_e(double alpha) { - return std::sqrt(4. * M_PI * alpha); + return std::sqrt(4. * Pi * alpha); } double calculate_alpha(double e) { - return e * e / (4. * M_PI); + return e * e / (4. * Pi); } gm2calc::MSSMNoFV_onshell setup(const GM2Calc_data& data) diff --git a/src/lowe.cpp b/src/lowe.cpp index 1df3ab6121..8ba8704814 100644 --- a/src/lowe.cpp +++ b/src/lowe.cpp @@ -28,6 +28,7 @@ #include "error.hpp" #include "ew_input.hpp" #include "string_format.hpp" +#include "wrappers.hpp" #include #include @@ -48,13 +49,13 @@ constexpr double sqr(double a) noexcept { return a*a; } // it's a very good approximation at these scales, better than 10^-3 accuracy double getAsmt(double mtop, double alphasMz, double mz) { return alphasMz / - (1.0 - 23.0 * alphasMz / (6.0 * M_PI) * std::log(mz / mtop)); + (1.0 - 23.0 * alphasMz / (6.0 * flexiblesusy::Pi) * std::log(mz / mtop)); } // Input pole mass of top and alphaS(mt), outputs running mass mt(mt) // including one-loop standard model correction only double getRunMt(double poleMt, double asmt) { - return poleMt / (1.0 + (4.0 / (3.0 * M_PI)) * asmt); + return poleMt / (1.0 + (4.0 / (3.0 * flexiblesusy::Pi)) * asmt); } // Given pole mass and alphaS(MZ), returns running top mass -- one loop qcd @@ -246,14 +247,14 @@ double QedQcd::qedBeta() const { if (get_scale() > mf(mTau - 1)) { x += 2.0 / 3.0; } if (get_scale() > displayPoleMW()) { x += -7.0 / 2.0; } - return (x * sqr(a(ALPHA - 1)) / M_PI); + return (x * sqr(a(ALPHA - 1)) / flexiblesusy::Pi); } /// Returns QCD beta function to 3 loops in QCD for the SM(5). Note /// that if quark masses are running, the number of active quarks will /// be taken into account. double QedQcd::qcdBeta() const { - static const double INVPI = 1.0 / M_PI; + static const double INVPI = 1.0 / flexiblesusy::Pi; const int quarkFlavours = flavours(get_scale()); const double qb0 = (11.0e0 - (2.0e0 / 3.0e0 * quarkFlavours)) / 4.0; const double qb1 = (102.0e0 - (38.0e0 * quarkFlavours) / 3.0e0) / 16.0; @@ -283,7 +284,7 @@ double QedQcd::qcdBeta() const { /// returns fermion mass beta functions Eigen::Array QedQcd::massBeta() const { - static const double INVPI = 1.0 / M_PI, ZETA3 = 1.202056903159594; + static const double INVPI = 1.0 / flexiblesusy::Pi; // qcd bits: 1,2,3 loop resp. double qg1 = 0., qg2 = 0., qg3 = 0.; @@ -297,7 +298,7 @@ Eigen::Array QedQcd::massBeta() const { } if (get_loops() > 2) { qg3 = (1.249e3 - ((2.216e3 * quarkFlavours) / 27.0e0 + - 1.6e2 * ZETA3 * quarkFlavours / 3.0e0) - + 1.6e2 * flexiblesusy::zeta3 * quarkFlavours / 3.0e0) - 140.0e0 * quarkFlavours * quarkFlavours / 81.0e0) * sqr(INVPI) * INVPI / 64.0; } @@ -347,15 +348,15 @@ double QedQcd::extractPoleMb(double alphasMb) double delta = 0.0; if (get_loops() > 0) { - delta = delta + 4.0 / 3.0 * alphasMb / M_PI; + delta = delta + 4.0 / 3.0 * alphasMb / flexiblesusy::Pi; } if (get_loops() > 1) { - delta = delta + sqr(alphasMb / M_PI) * + delta = delta + sqr(alphasMb / flexiblesusy::Pi) * (9.2778 + (displayMass(mUp) + displayMass(mDown) + displayMass(mCharm) + displayMass(mStrange)) / mbPole); } if (get_loops() > 2) { - delta = delta + 94.4182 * alphasMb / M_PI * sqr(alphasMb / M_PI); + delta = delta + 94.4182 * alphasMb / flexiblesusy::Pi * sqr(alphasMb / flexiblesusy::Pi); } const double mbPole = displayMass(mBottom) * (1.0 + delta); diff --git a/src/mathdefs.hpp b/src/mathdefs.hpp index b856473781..0a8d933682 100644 --- a/src/mathdefs.hpp +++ b/src/mathdefs.hpp @@ -1,6 +1,7 @@ #ifndef mathdefs_hpp #define mathdefs_hpp +#include "wrappers.hpp" #include #include @@ -12,8 +13,8 @@ using Real = double; using Comp = std::complex; -const double pi = M_PI; -const double r2 = M_SQRT2; +constexpr double pi = Pi; +constexpr double r2 = 1.4142135623730950; const Real epsilon = std::numeric_limits::epsilon(); diff --git a/test/test_QedQcd.cpp b/test/test_QedQcd.cpp index 203f5e2ac5..ba7f4494fa 100644 --- a/test/test_QedQcd.cpp +++ b/test/test_QedQcd.cpp @@ -18,7 +18,7 @@ BOOST_AUTO_TEST_CASE( test_QedQcd_to ) q1.to(91.); q2.to(91.); - BOOST_CHECK(ToDoubleVector(q1.get()) == q2.display()); + BOOST_CHECK_LT((Eigen::ArrayXd::Constant(q1.get().size(), 1.0) - q1.get() / ToEigenArray(q2.display())).abs().maxCoeff(), 3e-16); } BOOST_AUTO_TEST_CASE( test_QedQcd_toMz ) @@ -29,7 +29,7 @@ BOOST_AUTO_TEST_CASE( test_QedQcd_toMz ) q1.toMz(); q2.toMz(); - BOOST_CHECK_LT((q1.get() - ToEigenArray(q2.display())).abs().maxCoeff(), 2e-3); + BOOST_CHECK_LT((Eigen::ArrayXd::Constant(q1.get().size(), 1.0) - q1.get() / ToEigenArray(q2.display())).abs().maxCoeff(), 3e-3); } BOOST_AUTO_TEST_CASE( test_QedQcd_to_above_Mt ) From 1f0075f03d772882ad7170158af398c63f2fe562 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 28 Jul 2021 16:18:06 +0200 Subject: [PATCH 028/477] Barr-Zee diagrams for muon g-2 (#352) The calculation needs to be validates and therefore is not yet added to the final result. --- meta/AMuon.m | 88 ++++++- meta/FlexibleSUSY.m | 30 ++- src/wrappers.hpp | 3 +- templates/a_muon.cpp.in | 558 +++++++++++++++++++++++++++++++++++++++- test/test_wrappers.cpp | 6 +- 5 files changed, 670 insertions(+), 15 deletions(-) diff --git a/meta/AMuon.m b/meta/AMuon.m index 6797f09b22..4845f1ace8 100644 --- a/meta/AMuon.m +++ b/meta/AMuon.m @@ -24,18 +24,102 @@ AMuonGetMuon::usage=""; AMuonGetMSUSY::usage=""; +AMuonContributingGraphs::usage=""; +AMuonContributingDiagramsForGraph::usage=""; +CXXEvaluatorForDiagramFromGraph::usage=""; Begin["`Private`"]; +barZeeGraph = {{0,0,0,1,0,0,0,0}, + {0,0,0,0,1,0,0,0}, + {0,0,0,0,0,0,0,1}, + {1,0,0,0,1,1,0,0}, + {0,1,0,1,0,0,1,0}, + {0,0,0,1,0,0,1,1}, + {0,0,0,0,1,1,0,1}, + {0,0,1,0,0,1,1,0}}; + +contributingGraphs = {barZeeGraph}; + +AMuonContributingGraphs[] := contributingGraphs; + AMuonGetMuon[] := If[TreeMasses`GetDimension[TreeMasses`GetSMMuonLeptonMultiplet[]] =!= 1, TreeMasses`GetSMMuonLeptonMultiplet[], Cases[SARAH`ParticleDefinitions[FlexibleSUSY`FSEigenstates], {p_, {Description -> "Muon", ___}} -> p, 1][[1]] - ] + ]; GetCXXMuonIndex[] := If[TreeMasses`GetDimension[TreeMasses`GetSMMuonLeptonMultiplet[]] =!= 1, 1, - Null] + Null]; + +AMuonContributingDiagramsForGraph[graph_] := + Module[{diagrams}, + diagrams = CXXDiagrams`FeynmanDiagramsOfType[graph, + {1 -> AMuonGetMuon[], 2 -> SARAH`AntiField[AMuonGetMuon[]], 3 -> GetPhoton[]}]; + + Select[diagrams,IsDiagramSupported[graph,#] &] + ] + +IsDiagramSupported[barZeeGraph, diagram_] := + Module[{photonEmitter,exchangeParticle1,exchangeParticle2}, + + photonEmitter = diagram[[8,3]]; + exchangeParticle1 = diagram[[4,3]]; + exchangeParticle2 = diagram[[5,3]]; + If[diagram[[8]] =!= {TreeMasses`GetPhoton[],CXXDiagrams`LorentzConjugate[photonEmitter],photonEmitter}, + Return[False]]; + If[exchangeParticle1 == TreeMasses`GetPhoton[] && TreeMasses`IsScalar[exchangeParticle2] && TreeMasses`IsFermion[photonEmitter] && photonEmitter == diagram[[7,2]], + Return[True]]; + If[exchangeParticle1 == TreeMasses`GetZBoson[] && TreeMasses`IsScalar[exchangeParticle2] && TreeMasses`IsFermion[photonEmitter] && photonEmitter == diagram[[7,2]], + Return[True]]; + If[exchangeParticle1 == TreeMasses`GetPhoton[] && TreeMasses`IsScalar[exchangeParticle2] && TreeMasses`IsScalar[photonEmitter] && photonEmitter == diagram[[7,2]], + Return[True]]; + If[exchangeParticle1 == TreeMasses`GetPhoton[] && TreeMasses`IsScalar[exchangeParticle2] && TreeMasses`IsVector[photonEmitter] && photonEmitter == diagram[[7,2]], + Return[True]]; + + Return[False]; + ]; + +CXXEvaluatorForDiagramFromGraph[diagram_, barZeeGraph] := + Module[{photonEmitter,exchangeParticle1,exchangeParticle2}, + + photonEmitter = diagram[[8,3]]; + exchangeParticle1 = diagram[[4,3]]; + exchangeParticle2 = diagram[[5,3]]; + If[diagram[[8]] =!= {TreeMasses`GetPhoton[],CXXDiagrams`LorentzConjugate[photonEmitter],photonEmitter}, + Return["(unknown diagram)"]]; + If[exchangeParticle1 == TreeMasses`GetPhoton[] && TreeMasses`IsScalar[exchangeParticle2] && TreeMasses`IsFermion[photonEmitter], + Return[CXXEvaluatorBZFL[photonEmitter,exchangeParticle2]]]; + If[exchangeParticle1 == TreeMasses`GetZBoson[] && TreeMasses`IsScalar[exchangeParticle2] && TreeMasses`IsFermion[photonEmitter], + Return[CXXEvaluatorBZFLZ[photonEmitter,exchangeParticle2]]]; + If[exchangeParticle1 == TreeMasses`GetPhoton[] && TreeMasses`IsScalar[exchangeParticle2] && TreeMasses`IsScalar[photonEmitter], + Return[CXXEvaluatorBZSL[photonEmitter,exchangeParticle2]]]; + If[exchangeParticle1 == TreeMasses`GetPhoton[] && TreeMasses`IsScalar[exchangeParticle2] && TreeMasses`IsVector[photonEmitter], + Return[CXXEvaluatorBZVL[photonEmitter,exchangeParticle2]]]; + + Return["(unknown diagram)"]; + ]; + +CXXEvaluatorBZFL[photonEmitter_,exchangeParticle_] := + "AMuonBarZeeFermionLoop<" <> + CXXDiagrams`CXXNameOfField[photonEmitter] <> ", " <> + CXXDiagrams`CXXNameOfField[exchangeParticle] <> ">"; + +CXXEvaluatorBZFLZ[photonEmitter_,exchangeParticle_] := + "AMuonBarZeeFermionLoopZ<" <> + CXXDiagrams`CXXNameOfField[photonEmitter] <> ", " <> + CXXDiagrams`CXXNameOfField[exchangeParticle] <> ">"; + +CXXEvaluatorBZSL[photonEmitter_,exchangeParticle_] := + "AMuonBarZeeScalarLoop<" <> + CXXDiagrams`CXXNameOfField[photonEmitter] <> ", " <> + CXXDiagrams`CXXNameOfField[exchangeParticle] <> ">"; + +CXXEvaluatorBZVL[photonEmitter_,exchangeParticle_] := + "AMuonBarZeeVectorLoop<" <> + CXXDiagrams`CXXNameOfField[photonEmitter] <> ", " <> + CXXDiagrams`CXXNameOfField[exchangeParticle] <> ">"; GetMinMass[particle_] := Module[{dim = TreeMasses`GetDimension[particle], diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index 0e33f75ab2..342c070aa3 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -2404,7 +2404,8 @@ corresponding tadpole is real or imaginary (only in models with CP otherwise we assume it's the second particle in the lepton multiplet *) muonIndex = If[TreeMasses`GetDimension[AMuon`AMuonGetMuon[]] =!= 1, "1", ""], (* we want to calculate an offset of g-2 compared to the SM *) - discardSMcontributions = CConversion`CreateCBoolValue[True]}, + discardSMcontributions = CConversion`CreateCBoolValue[True], + graphs, diagrams, vertices, barZee = ""}, calculation = If[calcAMu, @@ -2419,14 +2420,35 @@ corresponding tadpole is real or imaginary (only in models with CP getMSUSY = AMuon`AMuonGetMSUSY[]; + graphs = AMuon`AMuonContributingGraphs[]; + diagrams = Outer[AMuon`AMuonContributingDiagramsForGraph, graphs, 1]; + + vertices = Flatten[CXXDiagrams`VerticesForDiagram /@ Flatten[diagrams, 1], 1]; + + For[i = 1, i <= Length[graphs], i++, + For[j = 1, j <= Length[diagrams[[i]]], j++, + barZee = barZee <> + "valBarZee += std::complex " <> ToString @ N[ + ReIm @ CXXDiagrams`ColourFactorForIndexedDiagramFromGraph[ + CXXDiagrams`IndexDiagramFromGraph[diagrams[[i,j]], graphs[[i]]], + graphs[[i]] + ], 16] <> " * " <> + ToString @ AMuon`CXXEvaluatorForDiagramFromGraph[diagrams[[i,j]], graphs[[i]]] <> + "::value({" <> muonIndex <> "}, context, qedqcd);\n" + ]; + ]; + WriteOut`ReplaceInFiles[files, {"@AMuon_MuonField@" -> CXXDiagrams`CXXNameOfField[AMuon`AMuonGetMuon[]], + "@AMuon_ZBosonField@" -> CXXDiagrams`CXXNameOfField[TreeMasses`GetZBoson[]], "@AMuon_Calculation@" -> TextFormatting`IndentText[calculation], "@AMuon_GetMSUSY@" -> TextFormatting`IndentText[WrapLines[getMSUSY]], "@AMuon_MuonIndex@" -> muonIndex, + "@AMuon_BarZeeCalculation@" -> TextFormatting`IndentText[barZee], Sequence @@ GeneralReplacementRules[] }]; + vertices ]; GetBVPSolverHeaderName[solver_] := @@ -3989,7 +4011,7 @@ corresponding tadpole is real or imaginary (only in models with CP MakeFlexibleSUSY[OptionsPattern[]] := Module[{nPointFunctions, runInputFile, initialGuesserInputFile, - edmVertices, edmFields, + aMuonVertices, edmVertices, edmFields, QToQGammaFields = {}, LToLGammaFields = {}, LToLConversionFields = {}, FFMasslessVVertices = {}, conversionVertices = {}, cxxQFTTemplateDir, cxxQFTOutputDir, cxxQFTFiles, @@ -4935,7 +4957,7 @@ corresponding tadpole is real or imaginary (only in models with CP ]; Print["Creating AMuon class ..."]; - WriteAMuonClass[MemberQ[Observables`GetRequestedObservables[extraSLHAOutputBlocks], FlexibleSUSYObservable`aMuon], + aMuonVertices = WriteAMuonClass[MemberQ[Observables`GetRequestedObservables[extraSLHAOutputBlocks], FlexibleSUSYObservable`aMuon], {{FileNameJoin[{$flexiblesusyTemplateDir, "a_muon.hpp.in"}], FileNameJoin[{FSOutputDir, FlexibleSUSY`FSModelName <> "_a_muon.hpp"}]}, {FileNameJoin[{$flexiblesusyTemplateDir, "a_muon.cpp.in"}], @@ -4962,7 +4984,7 @@ corresponding tadpole is real or imaginary (only in models with CP If[DirectoryQ[cxxQFTOutputDir] === False, CreateDirectory[cxxQFTOutputDir]]; WriteCXXDiagramClass[ - Join[edmVertices, FFMasslessVVertices, conversionVertices, decaysVertices], + Join[aMuonVertices, edmVertices, FFMasslessVVertices, conversionVertices, decaysVertices], cxxQFTFiles, cxxQFTVerticesTemplate, cxxQFTOutputDir, cxxQFTVerticesMakefileTemplates diff --git a/src/wrappers.hpp b/src/wrappers.hpp index cc75149024..4759866477 100644 --- a/src/wrappers.hpp +++ b/src/wrappers.hpp @@ -49,11 +49,12 @@ static constexpr double twoLoop = 4.010149318236068752e-05; static constexpr double threeLoop = 2.539456721913701978e-07; static constexpr double fourLoop = 1.608129755454920543e-09; static constexpr double fiveLoop = 1.018360064207223307e-11; -static constexpr bool True = true; +static constexpr bool True = true; static constexpr double zeta2 = 1.6449340668482264; // Zeta[2] static constexpr double zeta3 = 1.2020569031595943; // Zeta[3] static constexpr double zeta4 = 1.0823232337111382; // Zeta[4] static constexpr double zeta5 = 1.0369277551433699; // Zeta[5] +static constexpr double ln2 = 0.69314718055994531; // Abs ///////////////////////////////////////////////////////////////// diff --git a/templates/a_muon.cpp.in b/templates/a_muon.cpp.in index 95eb5e7461..9c27455660 100644 --- a/templates/a_muon.cpp.in +++ b/templates/a_muon.cpp.in @@ -33,15 +33,233 @@ #include "wrappers.hpp" #include "numerics2.hpp" #include "logger.hpp" +#include "dilog.hpp" + +#define DERIVEDPARAMETER(p) context.model.p() using namespace flexiblesusy; using namespace @ModelName@_cxx_diagrams; using Muon = fields::@AMuon_MuonField@; +using VZ = fields::@AMuon_ZBosonField@; namespace { double get_QED_2L(context_base&, const softsusy::QedQcd&); +double BarZeeLoopFPS(double); +double BarZeeLoopFS(double); +double BarZeeLoopS(double); +double BarZeeLoopV(double); + +/** + * @class AMuonBarZeeFermionLoop + * @brief A template that calculate contributions to the + * anomalous magnetic dipole moment of a given particle in + * a BarZee diagram with a fermion loop and scalar/Photon exchange + * particle. (for diagram type see arXiv:1502.04199 Figure 2, (1)) + * @tparam Args Specifies in order the field of which to + * calculate the electric magnetic moment, + * the photon emitter and the exchange particle + * in a BarZee diagram where the photon emitter + * is a Fermion and the exchange particle a scalar particle. + * + * This template evaluates the contribution to the magnetic + * dipole moment of a BarZee diagram with fields given by + * \a Args. + */ +template +struct AMuonBarZeeFermionLoop { + static double value(const typename field_indices::type& indices, + const context_base& context, + const softsusy::QedQcd& qedqcd); +}; + +/** + * @class AMuonBarZeeFermionZLoop + * @brief A template that calculate contributions to the + * anomalous magnetic dipole moment of a given particle in + * a BarZee diagram with a fermion loop and scalar/Z-boson exchange + * particle. + * @tparam Args Specifies in order the field of which to + * calculate the electric magnetic moment, + * the photon emitter and the exchange particle + * in a BarZee diagram where the photon emitter + * is a Fermion and the exchange particle a scalar particle. + * + * This template evaluates the contribution to the magnetic + * dipole moment of a BarZee diagram with fields given by + * \a Args. + */ +template +struct AMuonBarZeeFermionLoopZ { + static double value(const typename field_indices::type& indices, + const context_base& context, + const softsusy::QedQcd& qedqcd); +}; + +/** + * @class AMuonBarZeeScalarLoop + * @brief A template that calculate contributions to the + * anomalous dipole moment of a given particle in + * a BarZee diagram with a scalar loop and scalar exchange + * particle. (for diagram type see arXiv:1502.04199 Figure 2, (2)) + * @tparam Args Specifies in order the field of which to + * calculate the magnetic dipole moment, + * the photon emitter and the exchange particle + * in a BarZee diagram where the photon emitter + * is a scalar particle and the exchange particle a scalar particle. + * + * This template evaluates the contribution to the magnetic + * dipole moment of a BarZee diagram with fields given by + * \a Args. + */ +template +struct AMuonBarZeeScalarLoop { + static double value(const typename field_indices::type& indices, + const context_base& context, + const softsusy::QedQcd& qedqcd); +}; + +/** + * @class AMuonBarZeeVectorLoop + * @brief A template that calculate contributions to the + * anomalous dipole moment of a given particle in + * a BarZee diagram with a scalar loop and scalar exchange + * particle. (for diagram type see arXiv:1502.04199 Figure 2, (3)) + * @tparam Args Specifies in order the field of which to + * calculate the magnetic dipole moment, + * the photon emitter and the exchange particle + * in a BarZee diagram where the photon emitter + * is a scalar particle and the exchange particle a scalar particle. + * + * This template evaluates the contribution to the magnetic + * dipole moment of a BarZee diagram with fields given by + * \a Args. + */ +template +struct AMuonBarZeeVectorLoop { + static double value(const typename field_indices::type& indices, + const context_base& context, + const softsusy::QedQcd& qedqcd); +}; + +/** + Loop function needed for the calculation of the BarZeeDiagram with + fermion loop. (arXiv:1502.04199 Equation 26) + + @param respective squared mass ratio. +*/ + +double BarZeeLoopFPS(double m) { + // @todo(alex): check stability for small values + if (m == 0) { + return 0; + } + + if (m == 0.25) { + return ln2; + } + + double r1, theta1, r2, theta2; + if (m <= 0.25) { + const double y = std::sqrt(1.0-4.0*m); + r1 = 1.0 - (1.0 - y)/(2*m); + r2 = 1.0 - (1.0 + y)/(2*m); + if (r1 > 0) { + theta1 = 0.0; + } + else { + r1 *= -1; + theta1 = Pi; + } + if (r2 > 0) { + theta2 = 0.0; + } + else { + r2 *= -1; + theta2 = Pi; + } + return m / y * (dilog(std::polar(r1, theta1)).real() - dilog(std::polar(r2, theta2)).real()); + } + else { + const double y = std::sqrt(-1.0+4.0*m); + const double real = 1 - 1/(2*m); + r1 = r2 = 1.0; + + theta1 = std::atan2(y/(2*m), real); + theta2 = std::atan2(-y/(2*m), real); + + return m / y * (dilog(std::polar(r1, theta1)).imag() - dilog(std::polar(r2, theta2)).imag()); + } +} + +/** + Loop function needed for the calculation of the BarZeeDiagram with + fermion loop. (arXiv:1502.04199 Equation 25) + + @param respective squared mass ratio. +*/ + +double BarZeeLoopFS(double m) +{ + if (m == 0) { + return 0; + } + + return (2*m - 1) * BarZeeLoopFPS(m) - m * (2 + std::log(m)); +} + +/** + Loop function needed for the calculation of the BarZeeDiagram with + fermion loop. (arXiv:1502.04199 Equation 27) + + @param respective squared mass ratio. +*/ + +double BarZeeLoopS(const double m) +{ + return 1 + std::log(m)/2 - BarZeeLoopFPS(m); +} + +/** + Loop function needed for the calculation of the BarZeeDiagram with + fermion loop. (arXiv:1502.04199 Equation 28) + + @param respective squared mass ratio. +*/ + +double BarZeeLoopV(const double m) { + if (m == 0.25) { + return 4.75; + } + + double j; + + double r1, theta1, r2, theta2; + + if (m < 0.25) { + const double y = std::sqrt(1.0-4.0*m); + r1 = 2 / (1-y); + theta1 = std::atan2(0, r1); + r1 = std::abs(r1); + r2 = 2 / (1+y); + theta2 = std::atan2(0, r2); + r2 = std::abs(r2); + + j = 1/y * (std::log(std::abs(y-1) / (y+1)) * std::log(m) + dilog(std::polar(r1, theta1)).real() - dilog(std::polar(r2, theta2)).real()); + } + else { + const double y = std::sqrt(-1.0+4.0*m); + r1 = r2 = std::sqrt(1/m); + const double real = 1/(2*m); + const double imag = y/(2*m); + theta1 = std::atan2(imag, real); + theta2 = std::atan2(-imag, real); + j = 1/y * ( (std::atan2(y, -1) - std::atan2(y, 1)) * std::log(m) + dilog(std::polar(r1, theta1)).imag() - dilog(std::polar(r2, theta2)).imag()); + } + + return BarZeeLoopS(m) + 15.0/2.0 * m * (2.0 + std::log(m)) + m/2 * (19 - 12*m) * j - 9*m * BarZeeLoopFPS(m); +} double get_MSUSY(const @ModelName@_mass_eigenstates_interface& model) { @@ -51,7 +269,7 @@ double get_MSUSY(const @ModelName@_mass_eigenstates_interface& model) void run_to_MSUSY(@ModelName@_mass_eigenstates& model) { const double precision_goal = model.get_precision(); - const int Nmax = static_cast(-log10(precision_goal) * 10); + const int Nmax = static_cast(-std::log10(precision_goal) * 10); int it = 0; double precision = 0.; double MSUSY_old = 0., MSUSY_new = 0.; @@ -92,7 +310,7 @@ double calculate_a_muon_impl(const @ModelName@_mass_eigenstates& model, const so VERBOSE_MSG("@ModelName@_a_muon: calculating a_mu at Q = " << model.get_scale()); context_base context{ model }; - + using namespace @ModelName@_cxx_diagrams::fields; @AMuon_Calculation@ @@ -102,19 +320,31 @@ double calculate_a_muon_impl(const @ModelName@_mass_eigenstates& model, const so return std::numeric_limits::quiet_NaN(); } - double val = + double val = // vector form factor 1./2.*(form_factors[2] + form_factors[3]).real() - // reinstate the mass that was factored out in definition of form factor - * context.mass({@AMuon_MuonIndex@}) + // reinstate the mass that was factored out in definition of form factor + * context.mass({@AMuon_MuonIndex@}) // factor out e/(2*muon pole mass) - / (unit_charge(context_base{model})/(2.*muonPhysicalMass(qedqcd))) + / (unit_charge(context_base{model})/(2.*muonPhysicalMass(qedqcd))) // definition of photon momentum flow for g-2 is opposite than for form factors * (-1.); // add 2-loop QED logarithms val *= 1. + get_QED_2L(context, qedqcd); + std::complex valBarZee {0., 0.}; + +@AMuon_BarZeeCalculation@ + + if (!is_zero(valBarZee.imag())) { + ERROR("Error in the g-2 calculation! Form factor F2 should be real"); + return std::numeric_limits::quiet_NaN(); + } else { + // @todo: enable once the calculation of Barr-Zee contributions is validated + // val += valBarZee.real(); + } + return val; } @@ -222,4 +452,320 @@ double get_QED_2L(context_base& context, const softsusy::QedQcd& qedqcd) return qed_2L; } +template +double AMuonBarZeeFermionLoop< +Fermion, Scalar +>::value(const typename field_indices::type& indices, const context_base& context, const softsusy::QedQcd& qedqcd) +{ + using MuonVertex = Vertex< + Scalar, + typename Muon::lorentz_conjugate, + Muon + >; + + using FermionVertex = Vertex< + Scalar, + Fermion, + typename Fermion::lorentz_conjugate + >; + + double res = 0.0; + for (const auto& index1: index_range()) { + for (const auto& index2: index_range()) { + const auto muonIndices = MuonVertex::template indices_of_field<2>(index1); + + if (muonIndices != indices) + continue; + + const auto scalarIndices = MuonVertex::template indices_of_field<0>(index1); + const auto fermionIndices = FermionVertex::template indices_of_field<1>(index2); + + if (isSMField(fermionIndices) && + isSMField(scalarIndices)) + continue; + + if (scalarIndices != FermionVertex::template indices_of_field<0>(index2)) + continue; + + if (fermionIndices != FermionVertex::template indices_of_field<2>(index2)) + continue; + + const auto muonVertex = MuonVertex::evaluate(index1, context); + const auto fermionVertex = FermionVertex::evaluate(index2, context); + + const auto fermionMass = context.mass(fermionIndices); + const auto scalarMass = context.mass(scalarIndices); + const auto muonMass = context.mass(muonIndices); + + const double fermionChargeCount = + Fermion::electric_charge / Muon::electric_charge; + + const std::complex zrm = muonVertex.right(); + const std::complex zlm = muonVertex.left(); + const std::complex zrf = fermionVertex.right(); + const std::complex zlf = fermionVertex.left(); + + const std::complex coeffA = (zrf + zlf) * (zrm + zlm); + const std::complex coeffB = (zlf - zrf) * (zrm - zlm); + + const double massRatioSquared = Sqr(fermionMass / scalarMass); + + const double part1 = coeffA.real() * BarZeeLoopFS(massRatioSquared); + const double part2 = coeffB.real() * BarZeeLoopFPS(massRatioSquared); + + const double preFactor = Sqr(unit_charge(context))/(64*Power4(Pi)) * fermionChargeCount * fermionChargeCount + * muonPhysicalMass(qedqcd) / fermionMass; + + res += preFactor * (part1 + part2); + } + } + + return res; +} + +template +double AMuonBarZeeFermionLoopZ< +Fermion, Scalar +>::value(const typename field_indices::type& indices, const context_base& context, const softsusy::QedQcd& qedqcd) +{ + using MuonVertex = Vertex< + Scalar, + typename Muon::lorentz_conjugate, + Muon + >; + + using MuonZVertex = Vertex< + VZ, + Muon, + typename Muon::lorentz_conjugate + >; + + using FermionVertex = Vertex< + Scalar, + Fermion, + typename Fermion::lorentz_conjugate + >; + + using FermionZVertex = Vertex< + VZ, + typename Fermion::lorentz_conjugate, + Fermion + >; + + double res = 0.0; + for (const auto& index1: index_range()) { + for (const auto& index2: index_range()) { + for (const auto& indexMuonZ: index_range()) { + for (const auto& indexFermionZ: index_range()) { + + const auto muonIndices = MuonVertex::template indices_of_field<2>(index1); + + if (muonIndices != indices) + continue; + + if ((muonIndices != MuonZVertex::template indices_of_field<2>(indexMuonZ)) || + (muonIndices != MuonZVertex::template indices_of_field<1>(indexMuonZ))) + continue; + + const auto scalarIndices = MuonVertex::template indices_of_field<0>(index1); + const auto fermionIndices = FermionVertex::template indices_of_field<1>(index2); + + if (isSMField(fermionIndices) && + isSMField(scalarIndices)) + continue; + + if (scalarIndices != FermionVertex::template indices_of_field<0>(index2)) + continue; + + if (fermionIndices != FermionVertex::template indices_of_field<2>(index2)) + continue; + + if ((fermionIndices != FermionZVertex::template indices_of_field<2>(indexFermionZ)) || + (fermionIndices != FermionZVertex::template indices_of_field<1>(indexFermionZ))) + continue; + + const auto muonVertex = MuonVertex::evaluate(index1, context); + const auto fermionVertex = FermionVertex::evaluate(index2, context); + const auto muonZVertex = MuonZVertex::evaluate(indexMuonZ, context); + const auto fermionZVertex = FermionZVertex::evaluate(indexFermionZ, context); + + const auto fermionMass = context.mass(fermionIndices); + const auto scalarMass = context.mass(scalarIndices); + const auto muonMass = context.mass(muonIndices); + const auto zMass = context.mass({ }); + const auto ThetaW = DERIVEDPARAMETER(ThetaW); + const double cw = Cos(ThetaW); + const double sw = Sin(ThetaW); + + if (is_zero(zMass - scalarMass, 3e-13)) { + continue; + } + + const double fermionChargeCount = + Fermion::electric_charge / Muon::electric_charge; + + const std::complex zrm = muonVertex.right(); + const std::complex zlm = muonVertex.left(); + const std::complex zrf = fermionVertex.right(); + const std::complex zlf = fermionVertex.left(); + const std::complex zmzr = muonZVertex.right(); + const std::complex zfzr = fermionZVertex.right(); + + const double gvm = (0.5) * (zmzr.real()/unit_charge(context) + sw/cw); + const double gvf = (0.5) * (zfzr.real()/unit_charge(context) - fermionChargeCount*sw/cw); + const std::complex coeffA = (zrf + zlf) * (zrm + zlm); + const std::complex coeffB = (zlf - zrf) * (zrm - zlm); + + const double massRatioSquared = Sqr(fermionMass / scalarMass); + + const double part1 = coeffA.real() * Sqr(scalarMass) / (Sqr(scalarMass) - Sqr(zMass)) * (BarZeeLoopFS(massRatioSquared) - BarZeeLoopFS(Sqr(fermionMass / zMass))); + const double part2 = coeffB.real() * Sqr(scalarMass) / (Sqr(scalarMass) - Sqr(zMass)) * (BarZeeLoopFPS(massRatioSquared) - BarZeeLoopFPS(Sqr(fermionMass / zMass))); + + const double preFactor = - Sqr(unit_charge(context))/(64*Power4(Pi)) * fermionChargeCount * gvm * gvf + * muonPhysicalMass(qedqcd) / fermionMass; + + res += preFactor * (part1 + part2); + } + } + } + } + + return res; +} + +template +double AMuonBarZeeScalarLoop< +ChargedScalar, NeutralScalar +>::value(const typename field_indices::type& indices, const context_base& context, const softsusy::QedQcd& qedqcd) +{ + using MuonVertex = Vertex< + NeutralScalar, + typename Muon::lorentz_conjugate, + Muon + >; + + using ScalarVertex = Vertex< + NeutralScalar, + ChargedScalar, + typename ChargedScalar::lorentz_conjugate + >; + + double res = 0.0; + for (const auto& index1: index_range()) { + for (const auto& index2: index_range()) { + const auto muonIndices = MuonVertex::template indices_of_field<2>(index1); + + if (muonIndices != indices) + continue; + + const auto neutralScalarIndices = MuonVertex::template indices_of_field<0>(index1); + const auto chargedScalarIndices = ScalarVertex::template indices_of_field<1>(index2); + + if (isSMField(chargedScalarIndices) && + isSMField(neutralScalarIndices)) + { + continue; + } + + if (neutralScalarIndices != ScalarVertex::template indices_of_field<0>(index2)) + continue; + + if (chargedScalarIndices != ScalarVertex::template indices_of_field<2>(index2)) + continue; + + const auto muonVertex = MuonVertex::evaluate(index1, context); + const auto scalarVertex = ScalarVertex::evaluate(index2, context); + + const auto chargedScalarMass = context.mass(chargedScalarIndices); + const auto neutralScalarMass = context.mass(neutralScalarIndices); + const auto muonMass = context.mass(muonIndices); + + const double scalarChargeCount = + ChargedScalar::electric_charge / Muon::electric_charge; + + const std::complex zrm = muonVertex.right(); + const std::complex zlm = muonVertex.left(); + const std::complex zss = scalarVertex.value(); + + const std::complex coeff = (zrm + zlm) * zss; + + const double massRatioSquared = Sqr(chargedScalarMass / neutralScalarMass); + + const double preFactor = Sqr(unit_charge(context))/(64*Power4(Pi)) * scalarChargeCount * scalarChargeCount + * muonPhysicalMass(qedqcd) / (neutralScalarMass * neutralScalarMass); + + res += preFactor * coeff.real() * BarZeeLoopS(massRatioSquared); + } + } + + return res; +} + +template +double AMuonBarZeeVectorLoop< +Vector, Scalar +>::value(const typename field_indices::type& indices, const context_base& context, const softsusy::QedQcd& qedqcd) +{ + + using MuonVertex = Vertex< + Scalar, + typename Muon::lorentz_conjugate, + Muon + >; + + using VectorVertex = Vertex< + Scalar, + Vector, + typename Vector::lorentz_conjugate + >; + + double res = 0.0; + for (const auto& index1: index_range()) { + for (const auto& index2: index_range()) { + const auto muonIndices = MuonVertex::template indices_of_field<2>(index1); + + if (muonIndices != indices) + continue; + + const auto scalarIndices = MuonVertex::template indices_of_field<0>(index1); + const auto vectorIndices = VectorVertex::template indices_of_field<1>(index2); + + if (isSMField(vectorIndices) && + isSMField(scalarIndices)) + continue; + + if (scalarIndices != VectorVertex::template indices_of_field<0>(index2)) + continue; + + if (vectorIndices != VectorVertex::template indices_of_field<2>(index2)) + continue; + + const auto muonVertex = MuonVertex::evaluate(index1, context); + const auto vectorVertex = VectorVertex::evaluate(index2, context); + + const auto vectorMass = context.mass(vectorIndices); + const auto scalarMass = context.mass(scalarIndices); + const auto muonMass = context.mass(muonIndices); + + const double vectorChargeCount = + Vector::electric_charge / Muon::electric_charge; + + const std::complex zrm = muonVertex.right(); + const std::complex zlm = muonVertex.left(); + const std::complex zsv = vectorVertex.value(); + + const std::complex coeff = (zrm + zlm) * zsv; + + const double massRatioSquared = Sqr(vectorMass / scalarMass); + + const double preFactor = - Sqr(unit_charge(context))/(128*Power4(Pi)) * vectorChargeCount * vectorChargeCount + * muonPhysicalMass(qedqcd) / (vectorMass * vectorMass); + + res += preFactor * coeff.real() * BarZeeLoopV(massRatioSquared); + } + } + + return res; +} + } // anonymous namespace diff --git a/test/test_wrappers.cpp b/test/test_wrappers.cpp index 2df0997f2f..340a54ef5c 100644 --- a/test/test_wrappers.cpp +++ b/test/test_wrappers.cpp @@ -25,6 +25,7 @@ #include "stopwatch.hpp" #include #include +#include #if defined(__CYGWIN__) || defined(__FreeBSD__) // std::to_string is missing on Cygwin and FreeBSD @@ -46,10 +47,11 @@ BOOST_AUTO_TEST_CASE( test_Constants ) BOOST_CHECK_EQUAL(fourLoop , 1.608129755454920445735606800552522082e-9); BOOST_CHECK_EQUAL(fiveLoop , 1.018360064207223287777021556086771147e-11); BOOST_CHECK(True); - BOOST_CHECK_EQUAL(zeta2 , boost::math::zeta(2)); - BOOST_CHECK_EQUAL(zeta3 , boost::math::zeta(3)); + BOOST_CHECK_EQUAL(zeta2 , boost::math::constants::zeta_two()); + BOOST_CHECK_EQUAL(zeta3 , boost::math::constants::zeta_three()); BOOST_CHECK_EQUAL(zeta4 , boost::math::zeta(4)); BOOST_CHECK_EQUAL(zeta5 , boost::math::zeta(5)); + BOOST_CHECK_EQUAL(ln2 , boost::math::constants::ln_two()); } BOOST_AUTO_TEST_CASE( test_Abs ) From 290a185fe56c4305be6302186a832fcc3049c8b2 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 11 Aug 2021 13:57:57 +0200 Subject: [PATCH 029/477] reduced precision of THDM FlexibleDecay tests --- test/test_THDMII_FlexibleDecay.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_THDMII_FlexibleDecay.cpp b/test/test_THDMII_FlexibleDecay.cpp index b2ec020ec8..e1d18d3146 100644 --- a/test/test_THDMII_FlexibleDecay.cpp +++ b/test/test_THDMII_FlexibleDecay.cpp @@ -270,10 +270,10 @@ Block UERMIX // h -> b bbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFdFd(&m, 0, 2, 2), - 0.00074272223389794053, 2e-15); + 0.00074272223389794053, 2e-13); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFuFu(&m, 0, 1, 1), - 0.00011992760375249642, 2e-16); + 0.00011992760375249642, 6e-15); // h -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFeFe(&m, 0, 2, 2), 7.9645091090513334e-05, 1e-15); From 270b5bf81b60721418f24f1f352eebdb3923fc9b Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sat, 14 Aug 2021 05:41:34 +0200 Subject: [PATCH 030/477] fixed 'malloc_consolidate(): invalid chunk size' error --- test/test_SM_matching_selfenergy_Fd.cpp.in | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/test/test_SM_matching_selfenergy_Fd.cpp.in b/test/test_SM_matching_selfenergy_Fd.cpp.in index dc885c5765..68d4057489 100644 --- a/test/test_SM_matching_selfenergy_Fd.cpp.in +++ b/test/test_SM_matching_selfenergy_Fd.cpp.in @@ -58,7 +58,10 @@ namespace npointfunctions namespace { -static constexpr int number_of_random_samples = 50; +// too big number of samples triggers +// malloc_consolidate(): invalid chunk size +// error +static constexpr int number_of_random_samples = 20; } BOOST_AUTO_TEST_SUITE( selfenergy_test_suite, @@ -68,7 +71,7 @@ BOOST_DATA_TEST_CASE( test_selfenergies, random_SM_dataset( number_of_random_samples ), index, FS_TEST_SM_PARAMETER_SEQUENCE ) { - Loop_library::set(0); + Loop_library::set(-1); auto input_parameters = wrap_SM_parameters( FS_TEST_SM_PARAMETER_SEQUENCE ); auto model = calculate_spectrum( input_parameters ); @@ -78,8 +81,8 @@ BOOST_DATA_TEST_CASE( test_selfenergies, "There was an error calculating the spectrum: " << problems << "Skipping data point..." ); - if( problems.have_problem() == false ) - { + if (!problems.have_problem()) + { auto fs_selfenergy_Fd_1 = model.self_energy_Fd_1loop_1(0, INCOMING_FERMION_INDEX, OUTGOING_FERMION_INDEX); auto np_selfenergy_Fd_1 = SM_cxx_diagrams::npointfunctions::selfenergy_Fd_1loop( @@ -90,8 +93,9 @@ BOOST_DATA_TEST_CASE( test_selfenergies, TEST_COMPLEX_EQUALITY( np_selfenergy_Fd_1.at(0), fs_selfenergy_Fd_1 ); TEST_COMPLEX_EQUALITY( np_selfenergy_Fd_1.at(1), fs_selfenergy_Fd_1 ); - } else + } else { BOOST_TEST( true ); + } } BOOST_AUTO_TEST_SUITE_END() From d5cea35b5cbe665796092177e6b9457f9034409c Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Tue, 7 Sep 2021 15:29:23 +0200 Subject: [PATCH 031/477] working decays of an octet to a symmetric final state --- meta/CXXDiagrams.m | 18 ++++++++---------- meta/ColorMath.m | 6 ++++-- meta/Decays.m | 15 ++++----------- model_files/MRSSM2/FlexibleSUSY.m.in | 2 +- templates/decays/decays.hpp.in | 27 +++++++++++++++++++++++++++ test/test_MRSSM2_FlexibleDecay.cpp | 8 ++++++++ 6 files changed, 52 insertions(+), 24 deletions(-) diff --git a/meta/CXXDiagrams.m b/meta/CXXDiagrams.m index c2fc766fbf..0feaa4f105 100644 --- a/meta/CXXDiagrams.m +++ b/meta/CXXDiagrams.m @@ -674,14 +674,11 @@ If[(Times @@ colorMathExpressions) === 1, 1, ColorMathToSARAHConvention[ With[{colorFac = ColorMath`CSimplify[Times @@ colorMathExpressions]}, - If[!FreeQ[colorFac, Superscript[CMo, {__}]], - (* RemoveFD converts f and d color structures into a sum of ColorMath`o *) - ColorMath`CSimplify[Times @@ colorMathExpressions, RemoveFD -> False], - (* on the other hand, without RemoveFD -> True expression - {ct94450, ct94453}ct94448 {ct94450, ct94453, ct94454} - 4 CMt CMf - ct94455 - is not simplified *) + If[ColorMath`ContainsO[colorFac], + ColorMath`SortIndices[ + colorFac /. + Superscript[ColorMath`CMo, idx_List] /; Length[idx]===3 :> ColorMath`TR/2 (0 I Superscript[ColorMath`CMf, idx] + Superscript[ColorMath`CMd, idx]) + ], colorFac ] ] @@ -1655,9 +1652,10 @@ ExtractColourFactor[colourfactor_ * SARAH`Delta[ctIndex1_, ctIndex2_] /; NumericQ[colourfactor]] := colourfactor; ExtractColourFactor[SARAH`Delta[ctIndex1_, ctIndex2_]] := 1; ExtractColourFactor[colourfactor_ /; NumericQ[colourfactor]] := colourfactor; +(* currently from 8->88 we only handle symmetric structure (i.e d, not f) *) +(* ExtractColourFactor[colourfactor_ * Superscript[CMf, {ctIndex1_, ctIndex2_, ctIndex3_}] /; NumericQ[colourfactor]] := colourfactor; *) +ExtractColourFactor[colourfactor_ * Superscript[CMd, {ctIndex1_, ctIndex2_, ctIndex3_}] /; NumericQ[colourfactor]] := colourfactor; (* cases for 8->88 amplitudes -ExtractColourFactor[colourfactor_ * Superscript[CMf, {ctIndex1_, ctIndex2_, ctIndex3_}] /; NumericQ[colourfactor]] := ?; -ExtractColourFactor[colourfactor_ * Superscript[CMd, {ctIndex1_, ctIndex2_, ctIndex3_}] /; NumericQ[colourfactor]] := ?; ExtractColourFactor[colourfactor1_ * Superscript[CMf, {ctIndex1_, ctIndex2_, ctIndex3_} + colourfactor2_ * Superscript[CMd, {ctIndex1_, ctIndex2_, ctIndex3_}] /; NumericQ[colourfactor1]] && NumericQ[colourfactor2]] := ?; *) ExtractColourFactor[args___] := diff --git a/meta/ColorMath.m b/meta/ColorMath.m index f828b2f8c3..2afdaaff7e 100644 --- a/meta/ColorMath.m +++ b/meta/ColorMath.m @@ -22,6 +22,8 @@ CMDelta::usage = ""; CMo::usage = ""; CMd::usage = ""; +ContainsO::usage = ""; +SortIndices::usage = ""; Begin["Private`"]; Unprotect[Conjugate]; @@ -135,9 +137,9 @@ all gluon indices (external and dummy) in the expression Expr." CMf[G1$_, G2$_, G3$_] := Superscript[CMf, {G1$, G2$, G3$}] -d[G1$_, G2$_, G3$_] := Superscript[CMd, {G1$, G2$, G3$}] +CMd[G1$_, G2$_, G3$_] := Superscript[CMd, {G1$, G2$, G3$}] -o[Gs$_] := Superscript[CMo, Gs$] +CMo[Gs$_] := Superscript[CMo, Gs$] AllPairs[CMExpr$_] := Select[FindSymbols[CMExpr$], Count[FindSymbols[CMExpr$], #1] == 2 & ] diff --git a/meta/Decays.m b/meta/Decays.m index 9058556249..d2cd511552 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -324,23 +324,16 @@ finalStateReps = Sort[TreeMasses`GetColorRepresentation /@ finalState]; Switch[initialStateRep, S, result = ((finalStateReps === {S, S}) || - (finalStateReps === {T, T}) || - (finalStateReps === {-T, -T}) || (finalStateReps === Sort[{-T, T}]) || (finalStateReps === {O, O}));, - T|-T, result = ((finalStateReps === Sort[{T, S}]) || - (finalStateReps === Sort[{-T, S}]) || + T|-T, result = ((finalStateReps === Sort[{initialStateRep, S}]) || (finalStateReps === Sort[{O, T}]) || (finalStateReps === Sort[{O, -T}]));, O, result = ((finalStateReps === Sort[{O, S}]) || - (finalStateReps === {T, T}) || - (finalStateReps === {-T, -T}) || (finalStateReps === Sort[{-T, T}]) - (* uncomment to enable O -> OO decays once - the handling of multiple color structures - is introduced - || (finalStateReps === Sort[{O, O}])*));, - _, result = True; (* unhandled case *) + (* for now we only handle octet decays to symmetric final state *) + || (finalStateReps === {O, O} && SameQ@@finalState));, + _, result = False; (* unhandled case *) ]; ]; result diff --git a/model_files/MRSSM2/FlexibleSUSY.m.in b/model_files/MRSSM2/FlexibleSUSY.m.in index d956f7c262..ec7cc486b0 100644 --- a/model_files/MRSSM2/FlexibleSUSY.m.in +++ b/model_files/MRSSM2/FlexibleSUSY.m.in @@ -99,7 +99,7 @@ ExtraSLHAOutputBlocks = { }; FSCalculateDecays = True; -FSDecayParticles = {hh, Ah, Hpm}; +FSDecayParticles = {hh, Ah, Hpm, sigmaO, phiO}; DefaultPoleMassPrecision = HighPrecision; HighPoleMassPrecision = {hh, Ah, Hpm}; diff --git a/templates/decays/decays.hpp.in b/templates/decays/decays.hpp.in index 5313106002..33ecb50118 100644 --- a/templates/decays/decays.hpp.in +++ b/templates/decays/decays.hpp.in @@ -250,6 +250,33 @@ std::enable_if_t< > squared_color_generator() {return 1./2.;} +// 8 -> 8, 8 with identical particles in the final state +// because of symmetry of the final state it must be proportional to d^2 +template +constexpr +std::enable_if_t< +@ModelName@_cxx_diagrams::fields::is_octet_v && +@ModelName@_cxx_diagrams::fields::is_octet_v && +@ModelName@_cxx_diagrams::fields::is_octet_v && +std::is_same::value +, double> +// color: d^2 = (2 (4 - 5 Nc^2 + Nc^4) TR)/Nc = 40/3 +// average: 1/8 +squared_color_generator() {return 40/24.;} + +// 8 -> 8, 8 with differnt particles in the final state +template +constexpr +std::enable_if_t< +@ModelName@_cxx_diagrams::fields::is_octet_v && +@ModelName@_cxx_diagrams::fields::is_octet_v && +@ModelName@_cxx_diagrams::fields::is_octet_v && +!std::is_same::value +, double> +// color: f^2 = 2 Nc (-1 + Nc^2) TR = 24 +// average: 1/8 +squared_color_generator() {return 3.;} + // generic decay of FieldIn -> FieldOut1 FieldOut2 template double @ModelName@_decays::get_partial_width( diff --git a/test/test_MRSSM2_FlexibleDecay.cpp b/test/test_MRSSM2_FlexibleDecay.cpp index b5195c91f9..867d915983 100644 --- a/test/test_MRSSM2_FlexibleDecay.cpp +++ b/test/test_MRSSM2_FlexibleDecay.cpp @@ -760,4 +760,12 @@ Block FlexibleSUSYLowEnergy Q= 1.00000000E+03 BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VGVG(&m, 0), 0.00012423136936565911, 7e-11); // h -> gamma Z BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVZ(&m, 0), 6.391735378735319e-06, 5e-11); + + // scalar sgluon + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_phiO_to_VGVG(&m), 7.5701751945543629e-09, 3e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_phiO_to_barFuFu(&m, 2, 2), 2.2040853636396876e-05, 2e-12); + + // pseudoscalar sgluon + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_sigmaO_to_VGVG(&m), 0, 1e-16); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_sigmaO_to_barFuFu(&m, 2, 2), 2.1375623871457065e-11, 8e-12); } From fc5d82519e995fd0e6978fdd523c59876d44da4c Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Fri, 10 Sep 2021 10:43:52 +0200 Subject: [PATCH 032/477] avoid useless multiplication with zero --- src/dilog.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/dilog.cpp b/src/dilog.cpp index 74566995c8..09344318f7 100644 --- a/src/dilog.cpp +++ b/src/dilog.cpp @@ -29,8 +29,8 @@ namespace { template T horner(T x, const T (&c)[N]) noexcept { - T p = 0; - for (int i = N - 1; i >= 0; --i) { + T p = c[N - 1]; + for (int i = N - 2; i >= 0; --i) { p = p*x + c[i]; } return p; From dc70aa23a8493a022f84165ce1daaa28c5274ba2 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Fri, 10 Sep 2021 11:00:30 +0200 Subject: [PATCH 033/477] improve performance of Clausen function Cl2 taken from the polylogarithm package version 6.4.0 --- src/dilog.cpp | 184 ++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 180 insertions(+), 4 deletions(-) diff --git a/src/dilog.cpp b/src/dilog.cpp index 09344318f7..d556cad04d 100644 --- a/src/dilog.cpp +++ b/src/dilog.cpp @@ -60,22 +60,198 @@ namespace { * @brief Clausen function \f$\mathrm{Cl}_2(\theta) = \mathrm{Im}(\mathrm{Li}_2(e^{i\theta}))\f$ * @param x real angle * @return \f$\mathrm{Cl}_2(\theta)\f$ + * @author Alexander Voigt + * @note Implemented as economized Padé approximation. */ double clausen_2(double x) noexcept { - const std::complex ix(0.0, x); - return std::imag(dilog(std::exp(ix))); + const double PI = 3.14159265358979324; + const double PI2 = 2*PI, PIH = PI/2, PI28 = PI*PI/8; + double sgn = 1; + + if (x < 0) { + x = -x; + sgn = -1; + } + + if (x >= PI2) { + x = std::fmod(x, PI2); + } + + if (x > PI) { + const double p0 = 6.28125; + const double p1 = 0.0019353071795864769253; + x = (p0 - x) + p1; + sgn = -sgn; + } + + if (x == 0 || x == PI) { + return 0; + } + + double h = 0; + + if (x < PIH) { + const double P[] = { + 2.7951565822419270e-02, -8.8865360514541522e-04, + 6.8282348222485902e-06, -7.5276232403566808e-09 + }; + const double Q[] = { + 1.0000000000000000e+00, -3.6904397961160525e-02, + 3.7342870576106476e-04, -8.7460760866531179e-07 + }; + const double y = x*x; + const double z = y - PI28; + const double z2 = z*z; + const double p = P[0] + z * P[1] + z2 * (P[2] + z * P[3]); + const double q = Q[0] + z * Q[1] + z2 * (Q[2] + z * Q[3]); + + h = x*(1 - std::log(x) + y*p/q/2); + } else { + const double P[] = { + 6.4005702446195512e-01, -2.0641655351338783e-01, + 2.4175305223497718e-02, -1.2355955287855728e-03, + 2.5649833551291124e-05, -1.4783829128773320e-07 + }; + const double Q[] = { + 1.0000000000000000e+00, -2.5299102015666356e-01, + 2.2148751048467057e-02, -7.8183920462457496e-04, + 9.5432542196310670e-06, -1.8184302880448247e-08 + }; + const double y = PI - x; + const double z = y*y - PI28; + const double z2 = z*z; + const double z4 = z2*z2; + const double p = P[0] + z * P[1] + z2 * (P[2] + z * P[3]) + + z4 * (P[4] + z * P[5]); + const double q = Q[0] + z * Q[1] + z2 * (Q[2] + z * Q[3]) + + z4 * (Q[4] + z * Q[5]); + + h = y*p/q; + } + + return sgn*h; } /** * @brief Clausen function \f$\mathrm{Cl}_2(\theta) = \mathrm{Im}(\mathrm{Li}_2(e^{i\theta}))\f$ with long double precision * @param x real angle * @return \f$\mathrm{Cl}_2(\theta)\f$ + * @author Alexander Voigt + * + * Implemented as an economized Padé approximation with a maximum + * error of approximately 3.26e-41 (for long double and quadruple + * precision). */ long double clausen_2(long double x) noexcept { - const std::complex ix(0.0L, x); - return std::imag(dilog(std::exp(ix))); + const long double PI = 3.14159265358979323846264338327950288L; + const long double PI2 = 2*PI, PIH = PI/2, PI28 = PI*PI/8; + long double sgn = 1; + + if (x < 0) { + x = -x; + sgn = -1; + } + + if (x >= PI2) { + x = std::fmod(x, PI2); + } + + if (x > PI) { + const long double p0 = 6.28125L; + const long double p1 = 0.0019353071795864769252867665590057683943L; + x = (p0 - x) + p1; + sgn = -sgn; + } + + if (x == 0 || x == PI) { + return 0; + } + + long double h = 0; + + if (x < PIH) { + const long double P[] = { + 2.795156582241927046412081735910646612854e-02L, + -2.704528039782130831727668760352473119745e-03L, + 1.058576547177802928762582430994046913011e-04L, + -2.147507975446829791077479076828450780219e-06L, + 2.401415296681270093111305488326496124531e-08L, + -1.450571790543608936928129678333156785370e-10L, + 4.280534901040925211965221454555516657749e-13L, + -4.792802237226483806823208684186867186935e-16L, + 8.883657381852830471176782778999368430017e-20L + }; + const long double Q[] = { + 1.000000000000000000000000000000000000000e+00L, + -1.018694323414614410071369720193716012304e-01L, + 4.248408782245281612900840467370146443889e-03L, + -9.337710301347963985908084056584187570954e-05L, + 1.159379163193822053103946363960603543601e-06L, + -8.083352720393357000801675734774176899515e-09L, + 2.949313240431512997069808854213308209519e-11L, + -4.742700419624204182400715964695278593777e-14L, + 2.158380636740175386190809152807629331877e-17L + }; + const long double y = x*x; + const long double z = y - PI28; + const long double z2 = z*z; + const long double z4 = z2*z2; + const long double z8 = z4*z4; + const long double p = P[0] + z * P[1] + z2 * (P[2] + z * P[3]) + + z4 * (P[4] + z * P[5] + z2 * (P[6] + z * P[7])) + z8 * P[8]; + const long double q = Q[0] + z * Q[1] + z2 * (Q[2] + z * Q[3]) + + z4 * (Q[4] + z * Q[5] + z2 * (Q[6] + z * Q[7])) + z8 * Q[8]; + + h = x*(1 - std::log(x) + y*p/q/2); + } else { + const long double P[] = { + 6.400570244619551220929428522356830562481e-01L, + -4.651631624886004423703445967760673575997e-01L, + 1.487130845262105644024901814213146749895e-01L, + -2.749665174801454303884783494225610407035e-02L, + 3.251522465413666561950482170352156048203e-03L, + -2.567438381297475310848635518657180974512e-04L, + 1.372076105130164861564020074178493529151e-05L, + -4.924179093673498700461153483531075799113e-07L, + 1.153267936031337440182387313169828395860e-08L, + -1.667578310677508029208023423625588832295e-10L, + 1.348437292247918547169070120217729056878e-12L, + -5.052245092698477071447850656280954693011e-15L, + 5.600638109466570497480415519182233229048e-18L, + }; + const long double Q[] = { + 1.000000000000000000000000000000000000000e+00L, + -6.572465772185054284667746526549393897676e-01L, + 1.886234634096976582977630140163583172173e-01L, + -3.103347567899737687117030083178445406132e-02L, + 3.230860399291224478336071920154030050234e-03L, + -2.216546569335921728108984951507368387512e-04L, + 1.011949972138985643994631167412420906088e-05L, + -3.033400935206767852937290458763547850384e-07L, + 5.748454611964843057644023468691231929690e-09L, + -6.408350048413952604351408631173781906861e-11L, + 3.678584366662951864267349037579031493395e-13L, + -8.240439699357036167611014086997683837396e-16L, + 3.041049046123062158788159773779755292771e-19L + }; + const long double y = PI - x; + const long double z = y*y - PI28; + const long double z2 = z*z; + const long double z4 = z2*z2; + const long double z8 = z4*z4; + const long double p = P[0] + z * P[1] + z2 * (P[2] + z * P[3]) + + z4 * (P[4] + z * P[5] + z2 * (P[6] + z * P[7])) + + z8 * (P[8] + z * P[9] + z2 * (P[10] + z * P[11]) + z4 * P[12]); + const long double q = Q[0] + z * Q[1] + z2 * (Q[2] + z * Q[3]) + + z4 * (Q[4] + z * Q[5] + z2 * (Q[6] + z * Q[7])) + + z8 * (Q[8] + z * Q[9] + z2 * (Q[10] + z * Q[11]) + z4 * Q[12]); + + h = y*p/q; + } + + return sgn*h; } /** From 2df1cc0aba2276a332df6cd63af073f817650e3d Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sat, 11 Sep 2021 05:47:21 +0200 Subject: [PATCH 034/477] temporarily disable FormCalc Update to FormCalc on 6.09 seems to have broken something. The configure script hangs on "checking FormCalc" --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 163303c106..078e71612f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -156,7 +156,7 @@ jobs: wget -q -O - http://www.feynarts.de/formcalc/FormCalc-$FORMCALC_VERSION.tar.gz | tar xzf - cd FormCalc-$FORMCALC_VERSION ./compile - echo "AppendTo[\$Path, \"/fs_dependencies/gcc/FormCalc-$FORMCALC_VERSION\"];" >> /root/.WolframEngine/Kernel/init.m + # echo "AppendTo[\$Path, \"/fs_dependencies/gcc/FormCalc-$FORMCALC_VERSION\"];" >> /root/.WolframEngine/Kernel/init.m - name: Create models env: From b8b1927d4e53636d7f6e170c889bc73c3808adfa Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Tue, 14 Sep 2021 04:15:43 +0200 Subject: [PATCH 035/477] added decays to some NMSSM variants --- model_files/NUHNMSSM/FlexibleSUSY.m.in | 2 ++ model_files/NUTNMSSM/FlexibleSUSY.m.in | 2 ++ model_files/lowNMSSM/FlexibleSUSY.m.in | 2 ++ model_files/lowNMSSMTanBetaAtMZ/FlexibleSUSY.m.in | 2 ++ 4 files changed, 8 insertions(+) diff --git a/model_files/NUHNMSSM/FlexibleSUSY.m.in b/model_files/NUHNMSSM/FlexibleSUSY.m.in index 51b25a7991..3b56453d7f 100644 --- a/model_files/NUHNMSSM/FlexibleSUSY.m.in +++ b/model_files/NUHNMSSM/FlexibleSUSY.m.in @@ -178,3 +178,5 @@ ExtraSLHAOutputBlocks = { {5, \[Lambda] vS / Sqrt[2]}, {10, ms2} } } }; + +FSCalculateDecays = True; diff --git a/model_files/NUTNMSSM/FlexibleSUSY.m.in b/model_files/NUTNMSSM/FlexibleSUSY.m.in index 20a1314a58..8a6e02fbb9 100644 --- a/model_files/NUTNMSSM/FlexibleSUSY.m.in +++ b/model_files/NUTNMSSM/FlexibleSUSY.m.in @@ -107,3 +107,5 @@ ExtraSLHAOutputBlocks = { {5, \[Lambda] vS / Sqrt[2]}, {10, ms2} } } }; + +FSCalculateDecays = True; diff --git a/model_files/lowNMSSM/FlexibleSUSY.m.in b/model_files/lowNMSSM/FlexibleSUSY.m.in index 68f54130d5..6051ebef02 100644 --- a/model_files/lowNMSSM/FlexibleSUSY.m.in +++ b/model_files/lowNMSSM/FlexibleSUSY.m.in @@ -163,3 +163,5 @@ ExtraSLHAOutputBlocks = { {5, \[Lambda] vS / Sqrt[2]}, {10, ms2} } } }; + +FSCalculateDecays = True; diff --git a/model_files/lowNMSSMTanBetaAtMZ/FlexibleSUSY.m.in b/model_files/lowNMSSMTanBetaAtMZ/FlexibleSUSY.m.in index 383cdc8308..b25f1643bb 100644 --- a/model_files/lowNMSSMTanBetaAtMZ/FlexibleSUSY.m.in +++ b/model_files/lowNMSSMTanBetaAtMZ/FlexibleSUSY.m.in @@ -161,3 +161,5 @@ ExtraSLHAOutputBlocks = { {5, \[Lambda] vS / Sqrt[2]}, {10, ms2} } } }; + +FSCalculateDecays = True; From 8b238de782b52c816aa8c96f8e252b68db2877fa Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Mon, 20 Sep 2021 16:21:53 +0200 Subject: [PATCH 036/477] fix decay calculation via run_cmd --- meta/FlexibleSUSY.m | 8 ++++++-- templates/run_cmd_line.cpp.in | 1 + 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index 342c070aa3..2d3290be7e 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -2565,8 +2565,12 @@ corresponding tadpole is real or imaginary (only in models with CP ExampleCalculateCmdLineDecays[] := FlexibleSUSY`FSModelName <> "_decays decays;" <> -"if (settings.get(Spectrum_generator_settings::calculate_sm_masses)) { - decays = " <> FlexibleSUSY`FSModelName <> "_decays(std::get<0>(models), qedqcd, physical_input, flexibledecay_settings); +"decays = " <> FlexibleSUSY`FSModelName <> "_decays(std::get<0>(models), qedqcd, physical_input, flexibledecay_settings); +const bool loop_library_for_decays = + (Loop_library::get_type() == Loop_library::Library::Collier) || + (Loop_library::get_type() == Loop_library::Library::Looptools); +if (spectrum_generator.get_exit_code() == 0 && loop_library_for_decays) { + decays.calculate_decays(); }"; WriteExampleCmdLineOutput[enableDecays_] := diff --git a/templates/run_cmd_line.cpp.in b/templates/run_cmd_line.cpp.in index 48bc8ab4e3..c3d505cf8f 100644 --- a/templates/run_cmd_line.cpp.in +++ b/templates/run_cmd_line.cpp.in @@ -88,6 +88,7 @@ int run_solver(int loop_library, const @ModelName@_input_parameters& input) settings.set(Spectrum_generator_settings::precision, 1.0e-4); settings.set(Spectrum_generator_settings::loop_library, loop_library); settings.set(Spectrum_generator_settings::calculate_bsm_masses, 1.0); + settings.set(Spectrum_generator_settings::calculate_sm_masses, 1.0); @ModelName@_spectrum_generator spectrum_generator; spectrum_generator.set_settings(settings); From ed70bf81639f3be34082c00fa7bc2fb29ee83976 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 22 Sep 2021 03:11:44 +0200 Subject: [PATCH 037/477] removed duplicate lines in lowNMSSM model files --- model_files/lowNMSSM/FlexibleSUSY.m.in | 2 -- model_files/lowNMSSMTanBetaAtMZ/FlexibleSUSY.m.in | 2 -- 2 files changed, 4 deletions(-) diff --git a/model_files/lowNMSSM/FlexibleSUSY.m.in b/model_files/lowNMSSM/FlexibleSUSY.m.in index 6051ebef02..b10d131243 100644 --- a/model_files/lowNMSSM/FlexibleSUSY.m.in +++ b/model_files/lowNMSSM/FlexibleSUSY.m.in @@ -68,8 +68,6 @@ SUSYScaleInput = { {mq2[1,1], mq1Input^2}, {mq2[2,2], mq2Input^2}, {mq2[3,3], mq3Input^2}, - {me2[1,1], me1Input^2}, - {me2[2,2], me2Input^2}, {T[Yu][3,3], AtInput Yu[3,3]}, {T[Yd][3,3], AbInput Yd[3,3]}, {T[Ye][3,3], ATauInput Ye[3,3]} diff --git a/model_files/lowNMSSMTanBetaAtMZ/FlexibleSUSY.m.in b/model_files/lowNMSSMTanBetaAtMZ/FlexibleSUSY.m.in index b25f1643bb..b68e084ccd 100644 --- a/model_files/lowNMSSMTanBetaAtMZ/FlexibleSUSY.m.in +++ b/model_files/lowNMSSMTanBetaAtMZ/FlexibleSUSY.m.in @@ -67,8 +67,6 @@ SUSYScaleInput = { {mq2[1,1], mq1Input^2}, {mq2[2,2], mq2Input^2}, {mq2[3,3], mq3Input^2}, - {me2[1,1], me1Input^2}, - {me2[2,2], me2Input^2}, {T[Yu][3,3], AtInput Yu[3,3]}, {T[Yd][3,3], AbInput Yd[3,3]}, {T[Ye][3,3], ATauInput Ye[3,3]} From 802bafa34b6a5b69498c6954dd1462dc381d87f4 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 23 Sep 2021 22:05:23 +0200 Subject: [PATCH 038/477] Revert "temporarily disable FormCalc" This reverts commit 2df1cc0aba2276a332df6cd63af073f817650e3d. --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 078e71612f..163303c106 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -156,7 +156,7 @@ jobs: wget -q -O - http://www.feynarts.de/formcalc/FormCalc-$FORMCALC_VERSION.tar.gz | tar xzf - cd FormCalc-$FORMCALC_VERSION ./compile - # echo "AppendTo[\$Path, \"/fs_dependencies/gcc/FormCalc-$FORMCALC_VERSION\"];" >> /root/.WolframEngine/Kernel/init.m + echo "AppendTo[\$Path, \"/fs_dependencies/gcc/FormCalc-$FORMCALC_VERSION\"];" >> /root/.WolframEngine/Kernel/init.m - name: Create models env: From dcd987eb77548a4a70aa44f3355701f7127250dd Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Sun, 17 Oct 2021 12:49:26 +0200 Subject: [PATCH 039/477] update SLHAea to commit 7d0f81833731da which fixes a potential bug --- slhaea/slhaea.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/slhaea/slhaea.h b/slhaea/slhaea.h index 746e7c9c8e..d7f34dcd2e 100644 --- a/slhaea/slhaea.h +++ b/slhaea/slhaea.h @@ -838,7 +838,7 @@ class Block { if (++def_count > 1) { - is.seekg(-line_str.length()-1, std::ios_base::cur); + is.seekg(-static_cast(line_str.length() + 1), std::ios_base::cur); break; } if (nameless) From be36d45d9b787cb70d173ea1d05b3bd5d689575e Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sat, 16 Oct 2021 14:25:35 +0200 Subject: [PATCH 040/477] fixed wrong comment --- templates/l_to_lgamma.hpp.in | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/l_to_lgamma.hpp.in b/templates/l_to_lgamma.hpp.in index b57350116e..795539f763 100644 --- a/templates/l_to_lgamma.hpp.in +++ b/templates/l_to_lgamma.hpp.in @@ -18,7 +18,7 @@ /** - * @file @ModelName@_edm.hpp + * @file @ModelName@_l_to_lgamma.hpp * * This file was generated with FlexibleSUSY @FlexibleSUSYVersion@ and SARAH @SARAHVersion@ . */ From 4d47f521d2243bd6aeb137ac6cd23137473fe0bd Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 20 Oct 2021 18:27:28 +0200 Subject: [PATCH 041/477] fixed bug giving non-unitary rotation matrix (#364) --- src/linalg2.hpp | 33 +++++++++++++++++++++++++-------- test/test_linalg2.cpp | 17 +++++++++++++++++ 2 files changed, 42 insertions(+), 8 deletions(-) diff --git a/src/linalg2.hpp b/src/linalg2.hpp index f50f8a2bd3..3e7ac77f32 100644 --- a/src/linalg2.hpp +++ b/src/linalg2.hpp @@ -483,14 +483,31 @@ void diagonalize_symmetric_errbd Real *s_errbd = 0, Eigen::Array *u_errbd = 0) { - if (!u) { - svd_errbd(m, s, u, u, s_errbd, u_errbd); - return; - } - Eigen::Matrix, N, N> vh; - svd_errbd(m, s, u, &vh, s_errbd, u_errbd); - // see Eq. (5) of https://doi.org/10.1016/j.amc.2014.01.170 - *u *= (u->adjoint() * vh.transpose()).sqrt().eval(); + if (!u) { + svd_errbd(m, s, u, u, s_errbd, u_errbd); + return; + } + Eigen::Matrix, N, N> vh; + svd_errbd(m, s, u, &vh, s_errbd, u_errbd); + // see Eq. (5) of https://doi.org/10.1016/j.amc.2014.01.170 + Eigen::Matrix, N, N> const Z = u->adjoint() * vh.transpose(); + Eigen::Matrix, N, N> Zsqrt = Z.sqrt().eval(); + if (!Zsqrt.isUnitary()) { + // The formula assumes that sqrt of a unitary matrix is also unitary. + // This is not always true when using Eigen's build in sqrt function + // so we use a more generic matrixFunction in those cases. + // n-th derivative of sqrt(x) + const auto sqrtfn = + [](std::complex x, int n) { + static constexpr Real Pi = 3.141592653589793238462643383279503L; + return std::sqrt(Pi*x)/(2*std::tgamma(static_cast(1.5)-n)*std::pow(x, n)); + }; + Zsqrt = Z.matrixFunction(sqrtfn).eval(); + if (!Zsqrt.isUnitary()) { + std::runtime_error("Zsqrt matrix must be unitary"); + } + } + *u *= Zsqrt; } /** diff --git a/test/test_linalg2.cpp b/test/test_linalg2.cpp index c347145a6d..70ac9c21ed 100644 --- a/test/test_linalg2.cpp +++ b/test/test_linalg2.cpp @@ -770,4 +770,21 @@ BOOST_AUTO_TEST_CASE(test_calculate_dirac_singlet_mass) BOOST_CHECK_CLOSE(std::arg(phase), Pi/4., 1e-13); } +BOOST_AUTO_TEST_CASE(test_diagonalize_symmetric_errbd) +{ + Matrix, 4, 4> m; + m << + 0. , 0., 0., complex(-4.4299349683288838e-06,7.0893778912230837e-06), + 0. , 0., 0., 4.1620179585196247e-05, + 0. , 0., 0., 3.7871449517912927e-05, + complex(-4.4299349683288838e-06,7.0893778912230837e-06), 4.1620179585196247e-05, 3.7871449517912927e-05, 90.229999999964136; + + Array s; + Matrix, 4, 4> u; + double s_errbd = 0; + Array u_errbd; + fs_diagonalize_symmetric_errbd(m, s, &u, &s_errbd, &u_errbd); + BOOST_CHECK(u.isUnitary()); +} + #endif // TEST_LINALG2_PART8 From a5420f205c6019804c8d023c5ba23782931cf537 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Wed, 20 Oct 2021 21:31:08 +0200 Subject: [PATCH 042/477] Reset default shared lib command when compiler is changed (#366) --- configure | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/configure b/configure index 9dd9b59dd2..0f2121aff9 100755 --- a/configure +++ b/configure @@ -3387,12 +3387,12 @@ add_metaflags() { #_____________________________________________________________________ replace_markers() { sed -e "s|@FLEXIBLESUSY_VERSION@|$FLEXIBLESUSY_VERSION|" \ - -e "s|@OPERATING_SYSTEM@|$operating_system|" \ + -e "s|@OPERATING_SYSTEM@|$operating_system|" \ -e "s|@FLEXIBLESUSY_MAJOR@|$FLEXIBLESUSY_MAJOR|" \ -e "s|@FLEXIBLESUSY_MINOR@|$FLEXIBLESUSY_MINOR|" \ -e "s|@FLEXIBLESUSY_PATCH@|$FLEXIBLESUSY_PATCH|" \ -e "s|@FLEXIBLESUSY_EXTRA@|$FLEXIBLESUSY_EXTRA|" \ - -e "s|@GIT_COMMIT@|$GIT_COMMIT|" \ + -e "s|@GIT_COMMIT@|$GIT_COMMIT|" \ -e "s|@PKGNAME@|$PROGRAM_NAME|" \ -e "s|@ABSBASEDIR@|$ABSBASEDIR|" \ -e "s|@ADDONS@|$ADDONS|" \ @@ -3412,16 +3412,16 @@ replace_markers() { -e "s|@FFLAGS@|$FFLAGS|" \ -e "s|@FLIBS@|$FLIBS|" \ -e "s|@FUTILIBS@|$FUTILIBS|" \ - -e "s|@FMOD@|$FMOD|" \ - -e "s|@FSTD@|$FSTD|" \ + -e "s|@FMOD@|$FMOD|" \ + -e "s|@FSTD@|$FSTD|" \ -e "s|@FSCONFIG@|$FSCONFIG|" \ -e "s|@EIGENFLAGS@|$EIGENFLAGS|" \ -e "s|@GSLLIBS@|$GSLLIBS|" \ -e "s|@GSLFLAGS@|$GSLFLAGS|" \ - -e "s|@LDFLAGS@|$LDFLAGS|" \ - -e "s|@LDLIBS@|$LDLIBS|" \ - -e "s|@LLFLAGS@|$LLFLAGS|" \ - -e "s|@LLLIBS@|$LLLIBS|" \ + -e "s|@LDFLAGS@|$LDFLAGS|" \ + -e "s|@LDLIBS@|$LDLIBS|" \ + -e "s|@LLFLAGS@|$LLFLAGS|" \ + -e "s|@LLLIBS@|$LLLIBS|" \ -e "s|@ENABLE_COLORS@|$enable_colors|" \ -e "s|@ENABLE_COMPILE@|$enable_compile|" \ -e "s|@ENABLE_COMPILER_WARNINGS@|$enable_compiler_warnings|" \ @@ -3635,7 +3635,10 @@ if test $# -gt 0 ; then --with-boost-libdir=*) boost_lib_dir=$optarg ;; --with-boost-incdir=*) boost_inc_dir=$optarg ;; --with-cppflags=*) CPPFLAGS=$optarg ;; - --with-cxx=*) CXX=$optarg ;; + --with-cxx=*) CXX=$optarg + SHARED_LIB_CMD="$CXX -shared -o" + LIBLNK_MAKE_LIB_CMD="$SHARED_LIB_CMD" + ;; --with-cxxflags=*) CXXFLAGS=$optarg ;; --with-collier-libdir=*) collier_lib_dir=$optarg ;; --with-collier-incdir=*) collier_inc_dir=$optarg ;; From 26f5262ad3a8936ae6297305d2ee92a71b17da09 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 20 Oct 2021 20:47:02 +0200 Subject: [PATCH 043/477] fixed LFV decays output via mathlink --- CHANGES.rst | 12 ++++++++++++ meta/FSMathLink.m | 14 +++++++++++++- meta/Observables.m | 2 +- templates/observables.cpp.in | 2 +- 4 files changed, 27 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 496223b211..d7ea1cd3fc 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,15 @@ +FlexibleSUSY 2.6.2 [July, 08 2021] +================================== + +Changes +------- + +Fixed bugs +---------- + +* [commit ]: Branching ratio of L'->LGamma was breaking printing of + observables via the mathlink interface. + FlexibleSUSY 2.6.1 [July, 08 2021] ================================== diff --git a/meta/FSMathLink.m b/meta/FSMathLink.m index 3594962493..f45c7eda63 100644 --- a/meta/FSMathLink.m +++ b/meta/FSMathLink.m @@ -20,7 +20,7 @@ *) -BeginPackage["FSMathLink`", {"CConversion`", "Parameters`", "Utils`"}]; +BeginPackage["FSMathLink`", {"CConversion`", "Parameters`", "Utils`", "TreeMasses`"}]; GetNumberOfInputParameterRules::usage = ""; GetNumberOfSpectrumEntries::usage = ""; @@ -204,6 +204,18 @@ HeadsToStr[{}] := ""; HeadsToStr[l_List] := ", {" <> StringJoin[Riffle[HeadToStr /@ l, ", "]] <> "}"; +PutObservable[FlexibleSUSYObservable`BrLToLGamma[p1_[idx1_Integer]->{p2_[idx2_Integer], V_}], type_, link_String, heads_:{}] /; V === TreeMasses`GetPhoton[] := " +MLPutFunction(link, \"Rule\", 2); +MLPutFunction(link, \"FlexibleSUSYObservable`BrLToLGamma\", 1); +MLPutFunction(link, \"Rule\", 2); +MLPutFunction(link, \"" <> ToString[p1] <> "\", 1); +MLPutInteger(link, " <> ToString[idx1] <> "); +MLPutFunction(link, \"List\", 2); +MLPutFunction(link, \"" <> ToString[p2] <> "\", 1); +MLPutInteger(link, " <> ToString[idx2] <> "); +MLPutSymbol(link, \"" <> ToString[V] <> "\"); +MLPutReal(link, OBSERVABLE(" <> ToString[p1] <> ToString[idx1] <> "_to_" <> ToString[p2] <> ToString[idx2] <> "_" <> ToString[V] <> "));" + PutObservable[obs_[sub_], type_, link_String, heads_:{}] := PutObservable[sub, type, link, Join[heads, {obs}]]; diff --git a/meta/Observables.m b/meta/Observables.m index 10ed8351bf..357284f5b5 100644 --- a/meta/Observables.m +++ b/meta/Observables.m @@ -73,7 +73,7 @@ GetObservableName[obs_ /; obs === FlexibleSUSYObservable`aMuonGM2CalcUncertainty] := "a_muon_gm2calc_uncertainty"; GetObservableName[FlexibleSUSYObservable`EDM[p_[idx_]]] := GetObservableName[FlexibleSUSYObservable`EDM[p]] <> "_" <> ToString[idx]; GetObservableName[FlexibleSUSYObservable`EDM[p_]] := "edm_" <> CConversion`ToValidCSymbolString[p]; -GetObservableName[FlexibleSUSYObservable`BrLToLGamma[pIn_[_] -> {pOut_[_], spectator_}]] := CConversion`ToValidCSymbolString[pIn] <> "_to_" <> CConversion`ToValidCSymbolString[pOut] <> "_" <> CConversion`ToValidCSymbolString[spectator]; +GetObservableName[FlexibleSUSYObservable`BrLToLGamma[pIn_[idxIn_] -> {pOut_[idxOut_], spectator_}]] := CConversion`ToValidCSymbolString[pIn] <> ToString[idxIn] <> "_to_" <> CConversion`ToValidCSymbolString[pOut] <> ToString[idxOut] <> "_" <> CConversion`ToValidCSymbolString[spectator]; GetObservableName[FlexibleSUSYObservable`BrLToLGamma[pIn_ -> {pOut_, spectator_}]] := CConversion`ToValidCSymbolString[pIn] <> "_to_" <> CConversion`ToValidCSymbolString[pOut] <> "_" <> CConversion`ToValidCSymbolString[spectator]; GetObservableName[FlexibleSUSYObservable`FToFConversionInNucleus[pIn_[idxIn_] -> pOut_[idxOut_], nucleus_]] := CConversion`ToValidCSymbolString[pIn] <> "_to_" <> CConversion`ToValidCSymbolString[pOut] <> "_in_" <> ToString@nucleus; GetObservableName[obs_ /; obs === FlexibleSUSYObservable`bsgamma] := "b_to_s_gamma"; diff --git a/templates/observables.cpp.in b/templates/observables.cpp.in index 636ca19a8d..0ca559433d 100644 --- a/templates/observables.cpp.in +++ b/templates/observables.cpp.in @@ -43,7 +43,7 @@ #define EDM0(p) edm_ ## p #define EDM1(p,idx) edm_ ## p ## _ ## idx #define LToLGamma0(pIn, pOut, spec) pIn ## _to_ ## pOut ## _ ## spec -#define LToLGamma1(pIn,idxIn,pOut,idxOut,spec) pIn ## _to_ ## pOut ## _ ## spec +#define LToLGamma1(pIn,idxIn,pOut,idxOut,spec) pIn ## idxIn ## _to_ ## pOut ## idxOut ## _ ## spec #define FToFConversion1(pIn,idxIn,pOut,idxOut,nuclei,qedqcd) pIn ## _to_ ## pOut ## _in_ ## nuclei #define BSGAMMA b_to_s_gamma From ae1eae8e4d373eec531d6e5774977da2f12e88c8 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 21 Oct 2021 23:07:31 +0200 Subject: [PATCH 044/477] mathematica style lepton indexing in LToLGamma via mathlink --- meta/FSMathLink.m | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/meta/FSMathLink.m b/meta/FSMathLink.m index f45c7eda63..b3ac960d03 100644 --- a/meta/FSMathLink.m +++ b/meta/FSMathLink.m @@ -208,12 +208,12 @@ MLPutFunction(link, \"Rule\", 2); MLPutFunction(link, \"FlexibleSUSYObservable`BrLToLGamma\", 1); MLPutFunction(link, \"Rule\", 2); -MLPutFunction(link, \"" <> ToString[p1] <> "\", 1); -MLPutInteger(link, " <> ToString[idx1] <> "); +MLPutFunction(link, " <> ObsToStr[p1] <> ", 1); +MLPutInteger(link, " <> ObsToStr[idx1] <> "); MLPutFunction(link, \"List\", 2); -MLPutFunction(link, \"" <> ToString[p2] <> "\", 1); -MLPutInteger(link, " <> ToString[idx2] <> "); -MLPutSymbol(link, \"" <> ToString[V] <> "\"); +MLPutFunction(link, " <> ObsToStr[p2] <> ", 1); +MLPutInteger(link, " <> ObsToStr[idx2] <> "); +MLPutSymbol(link, " <> ObsToStr[V] <> "); MLPutReal(link, OBSERVABLE(" <> ToString[p1] <> ToString[idx1] <> "_to_" <> ToString[p2] <> ToString[idx2] <> "_" <> ToString[V] <> "));" PutObservable[obs_[sub_], type_, link_String, heads_:{}] := From 6fa9da60492ef39aa7478e0fd7b559108c54933c Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Mon, 25 Oct 2021 11:51:08 +0200 Subject: [PATCH 045/477] updated GM2Calc on CI --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 163303c106..c5d27c7f63 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -121,7 +121,7 @@ jobs: runs-on: ubuntu-20.04 container: - image: navir/opensuseleap-for-flexiblesusy:0.9.2 + image: navir/opensuseleap-for-flexiblesusy:0.9.7 strategy: matrix: From d000567efdfa28a60ac9948dca8149df1bf93229 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Mon, 25 Oct 2021 14:30:57 +0200 Subject: [PATCH 046/477] run tests from CMSSMNoFV to check GM2Calc interface --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c5d27c7f63..5687e9859c 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -130,7 +130,7 @@ jobs: env: FORMCALC_VERSION: '9.9' - MODELS: 'MSSM CMSSM CMSSMCKM MSSMCPV MSSMNoFV NUHMSSMNoFVHimalaya ScalarLeptoquarks LRLR E6SSM SM THDMII MRSSM2 MRSSM2CKM' + MODELS: 'MSSM CMSSM CMSSMNoFV CMSSMCKM MSSMCPV MSSMNoFV NUHMSSMNoFVHimalaya ScalarLeptoquarks LRLR E6SSM SM THDMII MRSSM2 MRSSM2CKM' steps: From 702003c74ddf71957f3c83d875445c7e09a793f8 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Tue, 26 Oct 2021 04:51:31 +0200 Subject: [PATCH 047/477] removed unneeded comments --- meta/Decays.m | 4 ---- 1 file changed, 4 deletions(-) diff --git a/meta/Decays.m b/meta/Decays.m index d2cd511552..167801aab9 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -584,7 +584,6 @@ would violate Ward identity (as at the level of dim 4 decays = Map[ ( - (* @todo StringPadRigh was introduced only in 10.1 *) WriteString["stdout", StringPadRight[" - Creating amplitude for " <> ToString@particle <> " -> " <> ToString@#, 64, "."]]; temp = FSParticleDecay[particle, #, GetContributingGraphsForDecay[particle, #]]; Print[" Done."]; @@ -1977,9 +1976,6 @@ that returns a total (sumed over internal insertions) 1-loop amplitude for a giv externalFieldsList, templatePars = "", args = "", body = ""}, - (* @todo StringPadRigh was introduced only in 10.1 *) - (*WriteString["stdout", StringPadRight[" - Creating code for " <> ToString@initialParticle <> " -> " <> ToString@finalState, 64, "."]];*) - (* decay amplitude type, e.g. Decay_amplitude_FSS *) returnType = GetDecayAmplitudeType[decay]; From 7581e6415ff795a0d3b2e88d5b836c7b934c3408 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sun, 24 Oct 2021 12:18:09 +0200 Subject: [PATCH 048/477] close parallel kernels between calls --- meta/CXXDiagrams.m | 4 +++- meta/Decays.m | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/meta/CXXDiagrams.m b/meta/CXXDiagrams.m index 0feaa4f105..748c7642d9 100644 --- a/meta/CXXDiagrams.m +++ b/meta/CXXDiagrams.m @@ -1157,6 +1157,7 @@ contextsToDistribute = {"SARAH`", "Susyno`LieGroups`", "FlexibleSUSY`", "CConversion`", "Himalaya`"}}, If[FlexibleSUSY`FSEnableParallelism, + LaunchKernels[]; (* without this CForm includes context in name of symbols such that we get for example SARAH_g1 instead of g1 in generated C++ code *) @@ -1204,7 +1205,8 @@ AbsoluteTiming@ParallelMap[ CreateVertex, DeleteDuplicates[vertices], DistributedContexts->All - ], + ]; + CloseKernels[];, cxxVertices = AbsoluteTiming@Map[ CreateVertex, diff --git a/meta/Decays.m b/meta/Decays.m index 167801aab9..f3cd3b92bd 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -2231,13 +2231,15 @@ that returns a total (sumed over internal insertions) 1-loop amplitude for a giv FSFancyLine[]; Print["Creating a C++ code for decay amplitudes..."]; If[FlexibleSUSY`FSEnableParallelism, + LaunchKernels[]; ParallelEvaluate[(BeginPackage[#];EndPackage[];)& /@ contextsToDistribute, DistributedContexts->All]; specializations = AbsoluteTiming@ParallelMap[ CreateTotalAmplitudeSpecialization[#, modelName]&, Flatten[Last @@@ particleDecays, 1], DistributedContexts -> All, Method -> "FinestGrained" - ], + ]; + CloseKernels[], specializations = AbsoluteTiming@Map[ ( From 8be3978839c7b8625853a1254828535ac35c3c3f Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Mon, 25 Oct 2021 14:24:03 +0200 Subject: [PATCH 049/477] run tests from CMSSMNoFV to check GM2Calc interface --- meta/CXXDiagrams.m | 6 +++++- meta/Decays.m | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/meta/CXXDiagrams.m b/meta/CXXDiagrams.m index 748c7642d9..1976016786 100644 --- a/meta/CXXDiagrams.m +++ b/meta/CXXDiagrams.m @@ -1206,7 +1206,11 @@ CreateVertex, DeleteDuplicates[vertices], DistributedContexts->All ]; - CloseKernels[];, + Needs["Parallel`Developer`"]; + Parallel`Developer`ClearDistributedDefinitions[]; + Parallel`Developer`ClearKernels[]; + CloseKernels[] + , cxxVertices = AbsoluteTiming@Map[ CreateVertex, diff --git a/meta/Decays.m b/meta/Decays.m index f3cd3b92bd..aa83fc1aec 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -2239,7 +2239,11 @@ that returns a total (sumed over internal insertions) 1-loop amplitude for a giv Flatten[Last @@@ particleDecays, 1], DistributedContexts -> All, Method -> "FinestGrained" ]; - CloseKernels[], + Needs["Parallel`Developer`"]; + Parallel`Developer`ClearDistributedDefinitions[]; + Parallel`Developer`ClearKernels[]; + CloseKernels[] + , specializations = AbsoluteTiming@Map[ ( From 790ab65d9f9b0367a6f7827dbea993d2ac7f0b99 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Fri, 29 Oct 2021 20:20:59 +0200 Subject: [PATCH 050/477] Soft links for model_files can be used. --- createmodel | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/createmodel b/createmodel index 8805c11a65..30da8357c5 100755 --- a/createmodel +++ b/createmodel @@ -218,7 +218,7 @@ check_model_name() { local _model="$1" - if [ -z $(echo "${_model}" | grep -E "^[a-zA-Z][0-9a-zA-Z_]*$") ]; then + if [ -z $(echo "${_model}" | grep -E "^[a-zA-Z][0-9a-zA-Z_]*$") ]; then printf "Error: invalid model name ${_model}. " if [ -n "$(echo "${_model}" | grep -E -o "^[0-9]")" ]; then printf "Model name must start with a letter. " @@ -504,7 +504,7 @@ if test ! -d "$targetdir" ; then message "done" fi -set -- $(find $model_file_dir -type f -iname LesHouches.in\* -not -iname \*~ -exec basename {} \; | tr '\n' ' ') +set -- $(find -L $model_file_dir -type f -iname LesHouches.in\* -not -iname \*~ -exec basename {} \; | tr '\n' ' ') SLHA_input_files="$*" SLHA_input_files_in_mk=$(echo "$SLHA_input_files" | From 49f18376a715f0a5dff0e1f59df57f81c52fe7e7 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sat, 30 Oct 2021 21:35:44 +0200 Subject: [PATCH 051/477] removed mathematica warning from creation of c++ code for decays FlexibleSUSY`M::shdw: Symbol M appears in multiple contexts {FlexibleSUSY`, Susyno`LieGroups`} ; definitions in context FlexibleSUSY` may shadow or be shadowed by other definitions. --- meta/Decays.m | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/meta/Decays.m b/meta/Decays.m index aa83fc1aec..a6f3aaaa25 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -2236,8 +2236,7 @@ that returns a total (sumed over internal insertions) 1-loop amplitude for a giv specializations = AbsoluteTiming@ParallelMap[ CreateTotalAmplitudeSpecialization[#, modelName]&, - Flatten[Last @@@ particleDecays, 1], - DistributedContexts -> All, Method -> "FinestGrained" + Flatten[Last @@@ particleDecays, 1], Method -> "FinestGrained" ]; Needs["Parallel`Developer`"]; Parallel`Developer`ClearDistributedDefinitions[]; From dbbcf669ec6d2e3c767777f38013a6d40cb2c89b Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 3 Nov 2021 15:49:47 +0100 Subject: [PATCH 052/477] fix contexts from Himalaya interface --- meta/CXXDiagrams.m | 2 +- meta/Decays.m | 2 +- meta/Himalaya.m | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/meta/CXXDiagrams.m b/meta/CXXDiagrams.m index 1976016786..f13ab55921 100644 --- a/meta/CXXDiagrams.m +++ b/meta/CXXDiagrams.m @@ -1154,7 +1154,7 @@ vertices:{{__}...}, OptionsPattern[{MaximumVerticesLimit -> 500}]] := Module[{cxxVertices, vertexPartition, - contextsToDistribute = {"SARAH`", "Susyno`LieGroups`", "FlexibleSUSY`", "CConversion`", "Himalaya`"}}, + contextsToDistribute = {"SARAH`", "Susyno`LieGroups`", "FlexibleSUSY`", "CConversion`"}}, If[FlexibleSUSY`FSEnableParallelism, LaunchKernels[]; diff --git a/meta/Decays.m b/meta/Decays.m index a6f3aaaa25..6ccb7237d6 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -2226,7 +2226,7 @@ that returns a total (sumed over internal insertions) 1-loop amplitude for a giv CreateTotalAmplitudeSpecializations[particleDecays_List, modelName_] := Module[{specializations, vertices = {}, listing = {}, - contextsToDistribute = {"SARAH`", "Susyno`LieGroups`", "FlexibleSUSY`", "CConversion`", "Himalaya`"}}, + contextsToDistribute = {"SARAH`", "Susyno`LieGroups`", "FlexibleSUSY`", "CConversion`"}}, Print[""]; FSFancyLine[]; Print["Creating a C++ code for decay amplitudes..."]; diff --git a/meta/Himalaya.m b/meta/Himalaya.m index 05d9c38bb7..2d62645ca3 100644 --- a/meta/Himalaya.m +++ b/meta/Himalaya.m @@ -27,7 +27,7 @@ struct."; { RenormalizationScheme, Lambda3L, Lambda3LUncertainty, - \[Mu], SARAH`g1, Susyno`LieGroups`g2, g3, vd, vu, + \[Mu], SARAH`g1, Susyno`LieGroups`g2, SARAH`g3, SARAH`vd, SARAH`vu, MSQ2, MSD2, MSU2, MSL2, MSE2, Au, Ad, Ae, Yu, Yd, Ye, M1, M2, M3, mA }; From d015c179c1f5d017065899a92ab278046770cd03 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 3 Nov 2021 23:45:04 +0100 Subject: [PATCH 053/477] Parallelize flexibledecay (#373) parallelize decay creation --- CHANGES.rst | 17 +++++++ meta/CXXDiagrams.m | 9 +--- meta/Decays.m | 20 ++++---- meta/FlexibleSUSY.m | 61 +++++++++++++++++++++--- meta/Utils.m | 6 +-- meta/Vertices.m | 27 +++++++---- src/decays/H_SM_decays/decay_H_to_WW.inc | 1 - src/decays/H_SM_decays/decay_H_to_ZZ.inc | 1 - 8 files changed, 106 insertions(+), 36 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index d7ea1cd3fc..b709abf782 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -4,6 +4,23 @@ FlexibleSUSY 2.6.2 [July, 08 2021] Changes ------- +* Parallelized calculation of decay amplitudes during the mathematica phase. + Example speedup: + + .. list-table:: + :widths: 25 25 50 + :header-rows: 1 + + * - model + - sequential + - parallel + * - `MSSM` + - 190s + - 140s + * - `MRSSM2` + - 555s + - 395s + Fixed bugs ---------- diff --git a/meta/CXXDiagrams.m b/meta/CXXDiagrams.m index f13ab55921..871771ff5f 100644 --- a/meta/CXXDiagrams.m +++ b/meta/CXXDiagrams.m @@ -1162,12 +1162,7 @@ such that we get for example SARAH_g1 instead of g1 in generated C++ code *) ParallelEvaluate[ - (BeginPackage[#];EndPackage[]; - (* prevent shdw warning with Susyno`LieGroups`M: *) - Off[Remove::remal]; - Remove[Susyno`LieGroups`M]; - On[Remove::remal]; - )& /@ contextsToDistribute, + (BeginPackage[#];EndPackage[];)& /@ contextsToDistribute, DistributedContexts->Automatic ]; (* without this CForm converts complex numbers using @@ -1204,7 +1199,7 @@ cxxVertices = AbsoluteTiming@ParallelMap[ CreateVertex, - DeleteDuplicates[vertices], DistributedContexts->All + DeleteDuplicates[vertices] ]; Needs["Parallel`Developer`"]; Parallel`Developer`ClearDistributedDefinitions[]; diff --git a/meta/Decays.m b/meta/Decays.m index 6ccb7237d6..6366710c9a 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -577,20 +577,21 @@ would violate Ward identity (as at the level of dim 4 concreteFinalStates = Join @@ (GetParticleCombinationsOfType[#, allowedFinalStateParticles, isPossibleDecay]& /@ genericFinalStates); concreteFinalStates = OrderFinalState[particle, #] & /@ concreteFinalStates; - Print[""]; - Print["Creating amplitudes for ", particle, " decays..."]; - (*ParallelEvaluate[Get["/home/wojciech/HEP-software/mathematica/SARAH-4.14.3/SARAH.m"]] - ParallelEvaluate[Start["MSSM"]];*) + If[!FlexibleSUSY`FSEnableParallelism, + Print[""]; + Print["Creating amplitudes for ", particle, " decays..."]; + ]; decays = Map[ ( - WriteString["stdout", StringPadRight[" - Creating amplitude for " <> ToString@particle <> " -> " <> ToString@#, 64, "."]]; + If[!FlexibleSUSY`FSEnableParallelism, + WriteString["stdout", StringPadRight[" - Creating amplitude for " <> ToString@particle <> " -> " <> ToString@#, 64, "."]]; + ]; temp = FSParticleDecay[particle, #, GetContributingGraphsForDecay[particle, #]]; - Print[" Done."]; + If[!FlexibleSUSY`FSEnableParallelism, Print[" Done."]]; temp )&, - concreteFinalStates(*, - DistributedContexts -> All*) + concreteFinalStates ]; decays = Select[decays, GetDecayTopologiesAndDiagrams[#] =!= {}&]; @@ -2236,7 +2237,8 @@ that returns a total (sumed over internal insertions) 1-loop amplitude for a giv specializations = AbsoluteTiming@ParallelMap[ CreateTotalAmplitudeSpecialization[#, modelName]&, - Flatten[Last @@@ particleDecays, 1], Method -> "FinestGrained" + Flatten[Last @@@ particleDecays, 1], + DistributedContexts -> All, Method -> "FinestGrained" ]; Needs["Parallel`Developer`"]; Parallel`Developer`ClearDistributedDefinitions[]; diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index 2d3290be7e..51c862f53b 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -1986,18 +1986,65 @@ corresponding tadpole is real or imaginary (only in models with CP partialWidthCalculationPrototypes = "", partialWidthCalculationFunctions = "", calcAmplitudeSpecializationDecls = "", calcAmplitudeSpecializationDefs = "", partialWidthSpecializationDecls = "", partialWidthSpecializationDefs = "", - smParticleAliases, solverIncludes = "", solver = ""}, + smParticleAliases, solverIncludes = "", solver = "", contentOfPath = $Path, modelName}, + + modelName = + If[SARAH`submodeldir =!= False, + SARAH`modelDir <> "/" <> SARAH`submodeldir, + SARAH`modelDir + ]; (solverIncludes = solverIncludes <> EnableSpectrumGenerator[#])& /@ FlexibleSUSY`FSBVPSolvers; numberOfDecayParticles = Plus @@ (TreeMasses`GetDimensionWithoutGoldstones /@ decayParticles); - (* create list containing elements {field, {FSParticleDecay 'objects'}} *) - decaysLists = - AbsoluteTiming@Map[ - {#, Decays`GetDecaysForParticle[#, maxFinalStateParticles, finalStateParticles]}&, - decayParticles - ]; + (* in parallel model decay of every particle is computed in a separate theread + but if we have only one particle then turning parallelism on only introduces + an overhead with no speed up *) + Block[{FlexibleSUSY`FSEnableParallelism = If[Length[decayParticles] < 2, False, FlexibleSUSY`FSEnableParallelism]}, + (* create list containing elements {field, {FSParticleDecay 'objects'}} *) + If[FlexibleSUSY`FSEnableParallelism, + If[Head[SARAH`VertexList3] === Symbol || Length[SARAH`VertexList3] === 0, + SA`CurrentStates = FlexibleSUSY`FSEigenstates; + SARAH`InitVertexCalculation[FlexibleSUSY`FSEigenstates, False]; + SARAH`partDefinition = ParticleDefinitions[FlexibleSUSY`FSEigenstates]; + SARAH`Particles[SARAH`Current] = SARAH`Particles[FlexibleSUSY`FSEigenstates]; + SARAH`ReadVertexList[FlexibleSUSY`FSEigenstates, False, False, True]; + SARAH`MakeCouplingLists; + ]; + LaunchKernels[]; + DistributeDefinitions[contentOfPath, modelName]; + ParallelEvaluate[ + (* subkernels have different $Path variable than the main kernel + https://mathematica.stackexchange.com/questions/11595/package-found-with-needs-but-not-with-parallelneeds *) + $Path = contentOfPath; + (* don't pollute terminal with SARAH initialization message *) + Block[{Print}, + << SARAH`; + Start@modelName; + ];, + DistributedContexts -> None + ]; + DistributeDefinitions[SARAH`VertexList3, SARAH`VertexList4]; + decaysLists = + AbsoluteTiming @ ParallelMap[ + {#, Decays`GetDecaysForParticle[#, maxFinalStateParticles, finalStateParticles]}&, + decayParticles, + DistributedContexts -> All, + Method -> "FinestGrained" + ]; + Needs["Parallel`Developer`"]; + Parallel`Developer`ClearDistributedDefinitions[]; + Parallel`Developer`ClearKernels[]; + CloseKernels[]; + , + decaysLists = + AbsoluteTiming @ Map[ + {#, Decays`GetDecaysForParticle[#, maxFinalStateParticles, finalStateParticles]}&, + decayParticles + ]; + ] + ]; Print[""]; Print["Creation of decay amplitudes took ", Round[First@decaysLists, 0.1], "s"]; decaysLists = Last@decaysLists; diff --git a/meta/Utils.m b/meta/Utils.m index 3ca8995d28..6d97175047 100644 --- a/meta/Utils.m +++ b/meta/Utils.m @@ -410,7 +410,7 @@ occurrence of the given rule is replaced (if it exists) or added (if Quit[1]; ]; ]; -SetAttributes[{AssertOrQuit,internalAssertOrQuit},{HoldAll,Locked,Protected}]; +SetAttributes[{AssertOrQuit,internalAssertOrQuit},{HoldAll, Protected}]; EvaluateOrQuit::errNotDefined = AssertOrQuit::errNotDefined; EvaluateOrQuit::errStrokes = AssertOrQuit::errStrokes; @@ -461,7 +461,7 @@ occurrence of the given rule is replaced (if it exists) or added (if ); Internal`HandlerBlock[{"MessageTextFilter", Filter}, expression] ]; -SetAttributes[{EvaluateOrQuit,internalEvaluateOrQuit},{HoldAll,Locked,Protected}]; +SetAttributes[{EvaluateOrQuit,internalEvaluateOrQuit},{HoldAll, Protected}]; internalOrQuitInputCheck[func_,message_,insertions___] := Module[{nStrokes,controlSubstrings}, @@ -483,7 +483,7 @@ occurrence of the given rule is replaced (if it exists) or added (if internalAssertOrQuit[TrueQ[Max@controlSubstrings<=Length@{insertions}], func::errInsertions,{insertions},Max@checkedControl,message] ]; -SetAttributes[internalOrQuitInputCheck,{HoldFirst,Locked,Protected}]; +SetAttributes[internalOrQuitInputCheck,{HoldFirst, Protected}]; MakeUnknownInputDefinition[sym_Symbol] := Module[{usageString,info,parsedInfo,infoString,symbolAsString}, diff --git a/meta/Vertices.m b/meta/Vertices.m index 65e30c2761..b15d42c32d 100644 --- a/meta/Vertices.m +++ b/meta/Vertices.m @@ -61,6 +61,24 @@ Begin["`Private`"] +FSVertex[sortedFields_, UseDependences_:False] := FSVertex[sortedFields, UseDependences] = +Module[{vertexList, vertex}, + + vertexList = + Switch[Length[sortedFields], + 3, SARAH`VertexList3, + 4, SARAH`VertexList4, + _, Print["Only three- and four-point vertices are supported"]; Quit[1] + ]; + + vertex = Select[vertexList, Vertices`StripFieldIndices[#[[1]]] === sortedFields &, 1]; + + If[vertex =!= {}, + First@vertex, + SARAH`Vertex[sortedFields, UseDependences -> useDependences] + ] +]; + (* cached 3-point vertices, with and without dependencies imposed *) cachedVertices[3, False] = {}; cacjedVertices[3, True] = {}; @@ -786,14 +804,7 @@ are scalars without (generation) indices. This alone does not yet IsNonZeroVertex[fields_List, vertexList_:{}, useDependences_:False] := Module[{sortedFields, cached, vertex}, sortedFields = SortFieldsInCp[fields]; - If[vertexList =!= {}, - cached = DeleteDuplicates[Select[vertexList, StripFieldIndices[#[[1]]] === sortedFields &, 1]]; - If[cached =!= {}, - Return[Or @@ (MemberQ[#[[2 ;;]][[All, 1]], Except[0]]& /@ cached)]; - ]; - ]; - vertex = SARAH`Vertex[sortedFields, UseDependences -> useDependences]; - AddToCachedVertices[vertex, useDependences]; + vertex = FSVertex[sortedFields, UseDependences -> useDependences]; MemberQ[vertex[[2 ;;]][[All, 1]], Except[0]] ]; diff --git a/src/decays/H_SM_decays/decay_H_to_WW.inc b/src/decays/H_SM_decays/decay_H_to_WW.inc index 1096a418bc..beb07eae88 100644 --- a/src/decays/H_SM_decays/decay_H_to_WW.inc +++ b/src/decays/H_SM_decays/decay_H_to_WW.inc @@ -1,5 +1,4 @@ // special case for H -> W+ W- -// TODO: implement higher order corrections template <> double CLASSNAME::get_partial_width::type, W>( diff --git a/src/decays/H_SM_decays/decay_H_to_ZZ.inc b/src/decays/H_SM_decays/decay_H_to_ZZ.inc index 53d56c9d05..07c9c26c35 100644 --- a/src/decays/H_SM_decays/decay_H_to_ZZ.inc +++ b/src/decays/H_SM_decays/decay_H_to_ZZ.inc @@ -1,5 +1,4 @@ // special case for Higgs -> Z Z -// TODO: implement higher order corrections struct my_f_params {double mHOS; double mVOS; double GammaV;}; From 8ddc9a0417dfebfa796bb8a14f65865b98dc0e6e Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Thu, 4 Nov 2021 19:07:52 +0100 Subject: [PATCH 054/477] Remove appropriate folders if the version is changed. --- configure | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/configure b/configure index 0f2121aff9..938ef28c7f 100755 --- a/configure +++ b/configure @@ -2885,6 +2885,8 @@ check_feynarts() { if test "x$enable_feynarts" = "xno"; then return; fi checking_msg "FeynArts installation" + local oldVersion="" + [ -f "${feynartsconfig}" ] && oldVersion=$(cat "${feynartsconfig}") rm -f ${feynartsconfig} "$MATH" < /dev/null Needs["FeynArts\`"]; @@ -2929,6 +2931,27 @@ EOF message " Please make sure Needs[\"FeynArts\`\"] works correctly." exit 1 fi + + # Removing NPointFunctions, FormCalc, FeynArts output folders + [ "${enable_feynarts}" = "yes" ] && { + [ "${FEYNARTS_VERSION}" = "${oldVersion}" ] || { + local models="$(echo $MODELS | tr ',' ' ')" + for m in ${models}; do + local eigenstate=$(grep 'FSEigenstates' "models/$m/FlexibleSUSY.m" \ + | sed 's/ //g' \ + | sed 's/.*`\(.*\);/\1/') + local output=$(grep -m1 'OutputDirectory' "models/$m/start.m" \ + | sed 's/ //g' \ + | sed 's/.*\"\(.*\)\".*/\1/') + local dir="${output}/$m/${eigenstate}/FeynArts" + [ -d "${dir}" ] && { rm -rf ${dir}; } + dir="${output}/$m/${eigenstate}/FormCalc" + [ -d "${dir}" ] && { rm -rf ${dir}; } + dir="${output}/$m/${eigenstate}/NPointFunctions" + [ -d "${dir}" ] && { rm -rf ${dir}; } + done + } + } } #_____________________________________________________________________ @@ -2936,6 +2959,8 @@ check_formcalc() { if test "x$enable_formcalc" = "xno"; then return; fi checking_msg "FormCalc installation" + local oldVersion="" + [ -f "${formcalcconfig}" ] && oldVersion=$(cat "${formcalcconfig}") rm -f ${formcalcconfig} "$MATH" < /dev/null Needs["FormCalc\`"]; @@ -2980,6 +3005,26 @@ EOF exit 1 fi + # Removing NPointFunctions, FormCalc output folders + + [ "${enable_formcalc}" = "yes" ] && { + [ "${FORMCALC_VERSION}" = "${oldVersion}" ] || { + local models="$(echo $MODELS | tr ',' ' ')" + for m in ${models}; do + local eigenstate=$(grep 'FSEigenstates' "models/$m/FlexibleSUSY.m" \ + | sed 's/ //g' \ + | sed 's/.*`\(.*\);/\1/') + local output=$(grep -m1 'OutputDirectory' "models/$m/start.m" \ + | sed 's/ //g' \ + | sed 's/.*\"\(.*\)\".*/\1/') + local dir="${output}/$m/${eigenstate}/FormCalc" + [ -d "${dir}" ] && { rm -rf ${dir}; } + dir="${output}/$m/${eigenstate}/NPointFunctions" + [ -d "${dir}" ] && { rm -rf ${dir}; } + done + } + } + if test "x$enable_formcalc" != "xno"; then checking_msg "working FormCalc" From a3ba7ec30ffade7ece22c07efa94593924d1972c Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Thu, 4 Nov 2021 19:35:31 +0100 Subject: [PATCH 055/477] Delete all files. --- configure | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/configure b/configure index 938ef28c7f..c32921b147 100755 --- a/configure +++ b/configure @@ -2935,19 +2935,21 @@ EOF # Removing NPointFunctions, FormCalc, FeynArts output folders [ "${enable_feynarts}" = "yes" ] && { [ "${FEYNARTS_VERSION}" = "${oldVersion}" ] || { - local models="$(echo $MODELS | tr ',' ' ')" - for m in ${models}; do - local eigenstate=$(grep 'FSEigenstates' "models/$m/FlexibleSUSY.m" \ + for m in "models"/*; do + [ -e "$m/FlexibleSUSY.m" ] || continue + [ -e "$m/start.m" ] || continue + local eigenstate=$(grep 'FSEigenstates' "$m/FlexibleSUSY.m" \ | sed 's/ //g' \ | sed 's/.*`\(.*\);/\1/') - local output=$(grep -m1 'OutputDirectory' "models/$m/start.m" \ + local output=$(grep -m1 'OutputDirectory' "$m/start.m" \ | sed 's/ //g' \ | sed 's/.*\"\(.*\)\".*/\1/') - local dir="${output}/$m/${eigenstate}/FeynArts" + output=$(echo $m | sed "s/models/${output}/") + local dir="${output}/${eigenstate}/FeynArts" [ -d "${dir}" ] && { rm -rf ${dir}; } - dir="${output}/$m/${eigenstate}/FormCalc" + dir="${output}/${eigenstate}/FormCalc" [ -d "${dir}" ] && { rm -rf ${dir}; } - dir="${output}/$m/${eigenstate}/NPointFunctions" + dir="${output}/${eigenstate}/NPointFunctions" [ -d "${dir}" ] && { rm -rf ${dir}; } done } @@ -3009,14 +3011,16 @@ EOF [ "${enable_formcalc}" = "yes" ] && { [ "${FORMCALC_VERSION}" = "${oldVersion}" ] || { - local models="$(echo $MODELS | tr ',' ' ')" - for m in ${models}; do + for m in "models"/*; do + [ -e "$m/FlexibleSUSY.m" ] || continue + [ -e "$m/start.m" ] || continue local eigenstate=$(grep 'FSEigenstates' "models/$m/FlexibleSUSY.m" \ | sed 's/ //g' \ | sed 's/.*`\(.*\);/\1/') local output=$(grep -m1 'OutputDirectory' "models/$m/start.m" \ | sed 's/ //g' \ | sed 's/.*\"\(.*\)\".*/\1/') + output=$(echo $m | sed "s/models/${output}/") local dir="${output}/$m/${eigenstate}/FormCalc" [ -d "${dir}" ] && { rm -rf ${dir}; } dir="${output}/$m/${eigenstate}/NPointFunctions" From bccfb97a26c6b0964636f8511f01c91fe404ab97 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Sat, 6 Nov 2021 00:22:56 +0100 Subject: [PATCH 056/477] Fix the bug. --- configure | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/configure b/configure index c32921b147..863b5d50e0 100755 --- a/configure +++ b/configure @@ -2867,7 +2867,7 @@ WriteString["stderr", \$sarahModelDir]; EOF ) - if [ -z "$SARAH_MODEL_DIR" ] ; then + [ -z "$SARAH_MODEL_DIR" -o \( ! -z "$SARAH_MODEL_DIR" -a ! -d "$SARAH_MODEL_DIR" \) ] && { message "Error: Could not determine the SARAH model directory." message " Please check that Mathematica and SARAH are installed correctly." message " To do that, you may run \`${MATH}' and then copy and paste:\n" @@ -2877,7 +2877,7 @@ If[Needs[\"SARAH\`\"] === \$Failed, Print[\"SARAH successfully loaded.\"]; Quit[0] ];" exit 1 - fi + } } #_____________________________________________________________________ From 64500974e2373462e9773207dd124dad0955f3f5 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Tue, 9 Nov 2021 16:49:20 +0100 Subject: [PATCH 057/477] Fancy warnings. --- meta/Utils.m | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/meta/Utils.m b/meta/Utils.m index 6d97175047..0fafb4794e 100644 --- a/meta/Utils.m +++ b/meta/Utils.m @@ -135,6 +135,8 @@ occurrence of the given rule is replaced (if it exists) or added (if FSFancyLine::usage = "Print separator line in command line mode"; +FSFancyWarning::usage = "Print a warning with a style." + PrintHeadline::usage = "Print fancy head line"; PrintAndReturn::usage = "Print result and return it"; @@ -412,6 +414,17 @@ occurrence of the given rule is replaced (if it exists) or added (if ]; SetAttributes[{AssertOrQuit,internalAssertOrQuit},{HoldAll, Protected}]; +FSFancyWarning[string_String, len_Integer:70] := +Module[{warning, chopped}, + warning = If[!$Notebooks, + "\033[1;33mWarning\033[1;0m: ", + Style["Warning: ", Yellow] + ]; + chopped = InsertLinebreaks[StringReplace[string, "\n"-> " "], len-9]; + chopped = StringReplace[chopped, "\n"-> "\n "]; + WriteString["stdout", warning <> chopped <> "\n"] +]; + EvaluateOrQuit::errNotDefined = AssertOrQuit::errNotDefined; EvaluateOrQuit::errStrokes = AssertOrQuit::errStrokes; EvaluateOrQuit::errControl = AssertOrQuit::errControl; From 6de95d47e2ae71ac7f969c3e492782bb5e8b27fa Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Tue, 9 Nov 2021 17:04:50 +0100 Subject: [PATCH 058/477] Cyan color for warnings. --- meta/Utils.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meta/Utils.m b/meta/Utils.m index 0fafb4794e..55b6b2fbba 100644 --- a/meta/Utils.m +++ b/meta/Utils.m @@ -417,8 +417,8 @@ occurrence of the given rule is replaced (if it exists) or added (if FSFancyWarning[string_String, len_Integer:70] := Module[{warning, chopped}, warning = If[!$Notebooks, - "\033[1;33mWarning\033[1;0m: ", - Style["Warning: ", Yellow] + "\033[1;36mWarning\033[1;0m: ", + Style["Warning: ", Cyan] ]; chopped = InsertLinebreaks[StringReplace[string, "\n"-> " "], len-9]; chopped = StringReplace[chopped, "\n"-> "\n "]; From e5323b7a68a5a70288541a4035be1a7f529ddd03 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Tue, 9 Nov 2021 21:09:28 +0100 Subject: [PATCH 059/477] A switcher for FSFancyWarning. --- configure | 10 ++++++++++ meta/FlexibleSUSY.m | 5 +++-- meta/Utils.m | 12 +++++++++--- 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/configure b/configure index 863b5d50e0..14767c324e 100755 --- a/configure +++ b/configure @@ -3408,6 +3408,9 @@ add_metaflags() { local tfc_='FSFormCalcAvailable = ' local fc_="${tfc_}$(test $enable_formcalc = 'yes' && echo 'True' || echo 'False');" + local tcol_='FSColorsAvailable = ' + local col_="${tcol_}$(test $enable_colors = 'yes' && echo 'True' || echo 'False');" + local c_='' local fs_='' for m in ${MODELS}; do @@ -3430,6 +3433,13 @@ add_metaflags() { [ "$c_" != '' ] && sed -i "s/${tfc_}.*/${fc_}/g" $fs_ || echo "$fc_" >> $fs_ fi + c_=$(grep "$tcol_" $fs_) + if [ "$c_" != "$col_" ]; then + [ "$c_" != '' ] && \ + sed -i "s/${tcol_}.*/${col_}/g" $fs_ || \ + echo "$col_" >> $fs_ + fi + done } diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index 51c862f53b..2ac5311cdf 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -366,6 +366,7 @@ FlexibleSUSY model file (FlexibleSUSY.m). FSFeynArtsAvailable = False; FSFormCalcAvailable = False; +FSColorsAvailable = False; Begin["`Private`"]; @@ -2890,7 +2891,7 @@ corresponding tadpole is real or imaginary (only in models with CP ]; WriteUtilitiesClass[massMatrices_List, betaFun_List, inputParameters_List, extraParameters_List, - lesHouchesParameters_List, extraSLHAOutputBlocks_List, + lesHouchesParameters_List, extraSLHAOutputBlocks_List, decaysSLHAIncludeFiles_List, files_List] := Module[{k, particles, susyParticles, smParticles, minpar, extpar, imminpar, imextpar, extraSLHAInputParameters, @@ -2905,7 +2906,7 @@ corresponding tadpole is real or imaginary (only in models with CP isLowEnergyModel = "false", isSupersymmetricModel = "false", isFlexibleEFTHiggs = "false", - getPDGCodeFromParticleEnumNoIndex = "", getPDGCodeFromParticleEnumIndex = "", + getPDGCodeFromParticleEnumNoIndex = "", getPDGCodeFromParticleEnumIndex = "", setParticleMultipletNameAndIndexFromPDG = "", fillInputParametersFromMINPAR = "", fillInputParametersFromEXTPAR = "", fillInputParametersFromIMMINPAR = "", diff --git a/meta/Utils.m b/meta/Utils.m index 55b6b2fbba..9e08881c77 100644 --- a/meta/Utils.m +++ b/meta/Utils.m @@ -384,9 +384,12 @@ occurrence of the given rule is replaced (if it exists) or added (if If[!$Notebooks, internalAssertOrQuit[assertion_,HoldPattern@MessageName[sym_, tag_],insertions___] := Module[{RedString,WriteOut,MultilineToDummy,replacedMessage}, - If[assertion === True,Return@True]; + If[TrueQ@assertion, Return@True]; + If[TrueQ@FlexibleSUSY`FSColorsAvailable, + RedString[str_] := "\033[1;31m"<>str<>"\033[1;0m";, + RedString[str_] := str; + ]; - RedString[str_] := "\033[1;31m"<>str<>"\033[1;0m"; WriteOut[str__] := WriteString["stdout"~OutputStream~1,StringJoin@str]; MultilineToDummy[args___] := Sequence@@(StringReplace[ToString@#,"\n"->"dummy_n"]&/@{args}); replacedMessage = StringReplace[sym~MessageName~tag,"\n"->"dummy_n"]; @@ -417,7 +420,10 @@ occurrence of the given rule is replaced (if it exists) or added (if FSFancyWarning[string_String, len_Integer:70] := Module[{warning, chopped}, warning = If[!$Notebooks, - "\033[1;36mWarning\033[1;0m: ", + If[TrueQ@FlexibleSUSY`FSColorsAvailable, + "\033[1;36mWarning\033[1;0m: ", + "Warning: " + ], Style["Warning: ", Cyan] ]; chopped = InsertLinebreaks[StringReplace[string, "\n"-> " "], len-9]; From 76dcf2b6b1558bb369dd4a67a7e4fa06f87b598f Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Wed, 10 Nov 2021 11:57:27 +0100 Subject: [PATCH 060/477] Change for FSColorsAvailable to FSEnableColors. --- configure | 2 +- meta/FlexibleSUSY.m | 2 +- meta/Utils.m | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/configure b/configure index 14767c324e..b10854a10e 100755 --- a/configure +++ b/configure @@ -3408,7 +3408,7 @@ add_metaflags() { local tfc_='FSFormCalcAvailable = ' local fc_="${tfc_}$(test $enable_formcalc = 'yes' && echo 'True' || echo 'False');" - local tcol_='FSColorsAvailable = ' + local tcol_='FSEnableColors = ' local col_="${tcol_}$(test $enable_colors = 'yes' && echo 'True' || echo 'False');" local c_='' diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index 2ac5311cdf..f8beae7575 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -366,7 +366,7 @@ FlexibleSUSY model file (FlexibleSUSY.m). FSFeynArtsAvailable = False; FSFormCalcAvailable = False; -FSColorsAvailable = False; +FSEnableColors = False; Begin["`Private`"]; diff --git a/meta/Utils.m b/meta/Utils.m index 9e08881c77..0cc691a5fd 100644 --- a/meta/Utils.m +++ b/meta/Utils.m @@ -385,7 +385,7 @@ occurrence of the given rule is replaced (if it exists) or added (if internalAssertOrQuit[assertion_,HoldPattern@MessageName[sym_, tag_],insertions___] := Module[{RedString,WriteOut,MultilineToDummy,replacedMessage}, If[TrueQ@assertion, Return@True]; - If[TrueQ@FlexibleSUSY`FSColorsAvailable, + If[TrueQ@FlexibleSUSY`FSEnableColors, RedString[str_] := "\033[1;31m"<>str<>"\033[1;0m";, RedString[str_] := str; ]; @@ -420,7 +420,7 @@ occurrence of the given rule is replaced (if it exists) or added (if FSFancyWarning[string_String, len_Integer:70] := Module[{warning, chopped}, warning = If[!$Notebooks, - If[TrueQ@FlexibleSUSY`FSColorsAvailable, + If[TrueQ@FlexibleSUSY`FSEnableColors, "\033[1;36mWarning\033[1;0m: ", "Warning: " ], From 6cdec718d2e8f4ba7ae6713c542439a3565962a8 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Wed, 10 Nov 2021 12:58:28 +0100 Subject: [PATCH 061/477] Fix for Notebook output. --- meta/Utils.m | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/meta/Utils.m b/meta/Utils.m index 0cc691a5fd..5c74ece0c2 100644 --- a/meta/Utils.m +++ b/meta/Utils.m @@ -429,6 +429,10 @@ occurrence of the given rule is replaced (if it exists) or added (if chopped = InsertLinebreaks[StringReplace[string, "\n"-> " "], len-9]; chopped = StringReplace[chopped, "\n"-> "\n "]; WriteString["stdout", warning <> chopped <> "\n"] + If[!$Notebooks, + WriteString["stdout", warning <> chopped <> "\n"];, + Print[warning, chopped]; + ]; ]; EvaluateOrQuit::errNotDefined = AssertOrQuit::errNotDefined; From f29572f6c4006831ec0dbbcdaadf2cd06bde8ad3 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 11 Nov 2021 06:06:03 +0100 Subject: [PATCH 062/477] fixed small mathematica syntax errors --- meta/FFVFormFactors.m | 2 +- meta/FlexibleSUSY.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/meta/FFVFormFactors.m b/meta/FFVFormFactors.m index 36c82192c1..c30a59ad3a 100644 --- a/meta/FFVFormFactors.m +++ b/meta/FFVFormFactors.m @@ -39,7 +39,7 @@ supported and the emitting fields can in fact emit the vector." IsChargedUnder::usage="Returns whether or not a field is charged under a given vectors gauge"; -Begin["Private`"]; +Begin["`Private`"]; vertexCorrectionGraph = { {0, 1, 0, 0, 0, 0}, diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index 51c862f53b..ff7cb8d56b 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -4888,7 +4888,7 @@ corresponding tadpole is real or imaginary (only in models with CP ]; With[{f = FileNameJoin[{"test", "FlexibleDecay.mk"}]}, - If[FileExistsQ[f], DeleteFile[f]] + If[FileExistsQ[f], DeleteFile[f]]; WriteString[f, "ENABLE_FLEXIBLEDECAY := yes"] ]; , From 84c48872723a396c446eb528fbb9af99bd416064 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 11 Nov 2021 06:48:05 +0100 Subject: [PATCH 063/477] updated the changelog --- CHANGES.rst | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index b709abf782..0abd8c6948 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,7 +1,7 @@ -FlexibleSUSY 2.6.2 [July, 08 2021] +FlexibleSUSY 2.?.? [?, ? 202?] ================================== -Changes +New features ------- * Parallelized calculation of decay amplitudes during the mathematica phase. @@ -21,10 +21,16 @@ Changes - 555s - 395s +Changes +------- + +* [commit ae1eae8e4d373eec531d6e5774977da2f12e88c8]: Mathematica-style indexing (starting from 1) of + leptons in L'->LGamma via the mathlink interface. + Fixed bugs ---------- -* [commit ]: Branching ratio of L'->LGamma was breaking printing of +* [commit 26f5262ad3a8936ae6297305d2ee92a71b17da09]: Branching ratio of L'->LGamma was breaking printing of observables via the mathlink interface. FlexibleSUSY 2.6.1 [July, 08 2021] From e5a997ab32764b5b06ce5f128fbb5ffec185abd0 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Thu, 11 Nov 2021 09:22:27 +0100 Subject: [PATCH 064/477] Fix for a fix for output. --- meta/Utils.m | 1 - 1 file changed, 1 deletion(-) diff --git a/meta/Utils.m b/meta/Utils.m index 5c74ece0c2..f15ece9206 100644 --- a/meta/Utils.m +++ b/meta/Utils.m @@ -428,7 +428,6 @@ occurrence of the given rule is replaced (if it exists) or added (if ]; chopped = InsertLinebreaks[StringReplace[string, "\n"-> " "], len-9]; chopped = StringReplace[chopped, "\n"-> "\n "]; - WriteString["stdout", warning <> chopped <> "\n"] If[!$Notebooks, WriteString["stdout", warning <> chopped <> "\n"];, Print[warning, chopped]; From 7761a38c2a735c3c9e402d42ffc2d6322a5f4bd4 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 11 Nov 2021 15:54:07 +0100 Subject: [PATCH 065/477] use Utils`FSFancyWarning in few places --- meta/Decays.m | 6 +++--- meta/FFVFormFactors.m | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/meta/Decays.m b/meta/Decays.m index 6366710c9a..8f152692f3 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -378,7 +378,7 @@ unsupportedVertices = Complement[vertexTypes, CXXDiagrams`VertexTypes[]]; If[unsupportedVertices =!= {}, MapIndexed[(If[!MemberQ[CXXDiagrams`VertexTypes[], vertexTypes[[First[#2]]]], - Print["Warning: vertex with fields ", #1, " is not currently supported."]; + Utils`FSFancyWarning["vertex with fields " <> ToString[#1] <> " is not currently supported."]; Print[" Diagrams involving this vertex will be discarded."]; ];)&, vertices]; ]; @@ -1020,7 +1020,7 @@ would violate Ward identity (as at the level of dim 4 ChiralVertex, "Decay_amplitude_SFF", MomentumDifferenceVertex, "Decay_amplitude_SSV", InverseMetricVertex, "Decay_amplitude_SVV", - _, Print["Warning: decay ", initialParticle, " -> ", finalState, " is not supported."]; + _, Utils`FSFancyWarning["decay " <> ToString[initialParticle] <> " -> " <> ToString[finalState <> " is not supported."]; "Unknown_amplitude_type" ] ]; @@ -1031,7 +1031,7 @@ would violate Ward identity (as at the level of dim 4 Switch[{vertexType, GetFeynArtsTypeName@Last@finalState}, {ChiralVertex, S}, "Decay_amplitude_FFS", {ChiralVertex, V}, "Decay_amplitude_FFV", - _, Print["Warning: decay ", initialParticle, " -> ", finalState, " is not supported."]; + _, Utils`FSFancyWarning["decay ", initialParticle, " -> ", finalState, " is not supported."]; "Unknown_amplitude_type" ] ]; diff --git a/meta/FFVFormFactors.m b/meta/FFVFormFactors.m index c30a59ad3a..efbcd729db 100644 --- a/meta/FFVFormFactors.m +++ b/meta/FFVFormFactors.m @@ -89,7 +89,7 @@ Return[True] ]; - Print["Warning: Diagram with internal particles of type ", + Utils`FSFancyWarning["Diagram with internal particles of type " <> StringJoin @@ (ToString /@ SARAH`getType /@ {EmitterL[diagram], EmitterR[diagram], Spectator[diagram]})]; Print[" is currently not supported."]; Print[" Discarding diagram with particles ", From 5f35b9d70d0d2d2380b5bea20e09815037252876 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Fri, 12 Nov 2021 11:49:57 +0100 Subject: [PATCH 066/477] fixed bracket missing in 7761a38c2a735c3c9e402d42ffc2d6322a5f4bd4 --- meta/Decays.m | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/meta/Decays.m b/meta/Decays.m index 8f152692f3..652cf20331 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -1020,7 +1020,7 @@ would violate Ward identity (as at the level of dim 4 ChiralVertex, "Decay_amplitude_SFF", MomentumDifferenceVertex, "Decay_amplitude_SSV", InverseMetricVertex, "Decay_amplitude_SVV", - _, Utils`FSFancyWarning["decay " <> ToString[initialParticle] <> " -> " <> ToString[finalState <> " is not supported."]; + _, Utils`FSFancyWarning["decay " <> ToString[initialParticle] <> " -> " <> ToString[finalState] <> " is not supported."]; "Unknown_amplitude_type" ] ]; @@ -1031,7 +1031,7 @@ would violate Ward identity (as at the level of dim 4 Switch[{vertexType, GetFeynArtsTypeName@Last@finalState}, {ChiralVertex, S}, "Decay_amplitude_FFS", {ChiralVertex, V}, "Decay_amplitude_FFV", - _, Utils`FSFancyWarning["decay ", initialParticle, " -> ", finalState, " is not supported."]; + _, Utils`FSFancyWarning["decay " <> ToString[initialParticle] <> " -> " <> ToString[finalState] <> " is not supported."]; "Unknown_amplitude_type" ] ]; From 4ce35d9b16eaf0471c87d251ffb785bbf3106efd Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Fri, 12 Nov 2021 19:42:56 +0100 Subject: [PATCH 067/477] Check for an equality of timestamps. --- configure | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/configure b/configure index b10854a10e..90e4120c19 100755 --- a/configure +++ b/configure @@ -3171,12 +3171,15 @@ update_module_mk() { local math_cmd="${4:-math}" [ -e "$model_file" ] || return - { find "$mkfile" -newer "$model_file" | grep ^; } > /dev/null 2>&1 && - return + if [ ! "${mkfile}" -nt "${model_file}" ] && \ + [ ! "${mkfile}" -ot "${model_file}" ]; then + return + fi message -n " Updating model-specific modules in $mkfile ... " local ho="$(get_model_specific_corrections "$model_file" "$math_cmd")" sed -i -e "s|^\(MOD${name}_MOD[[:space:]]*:=\).*$|\1 $ho|" "$mkfile" + touch "${mkfile}" "${model_file}" message "($ho)" logmsg " Depends on model-specific modules: ${ho}" } From e0530881f03d80d074b6fd6b1dda316e6d49adff Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Fri, 12 Nov 2021 21:01:47 +0100 Subject: [PATCH 068/477] Do not run mathematica if there is no need. --- configure | 43 +++++++++++++++++++++++++++---------------- 1 file changed, 27 insertions(+), 16 deletions(-) diff --git a/configure b/configure index b10854a10e..2e066923b6 100755 --- a/configure +++ b/configure @@ -3141,22 +3141,33 @@ get_model_specific_corrections() { return 1 } - mma_symbol_is "$model_file" "$math_cmd" "UseHiggs2LoopSM" "True" && ho="${ho} SM" - mma_symbol_is "$model_file" "$math_cmd" "UseHiggs3LoopSM" "True" && ho="${ho} SM" - mma_symbol_is "$model_file" "$math_cmd" "UseHiggs4LoopSM" "True" && ho="${ho} SM" - mma_symbol_is "$model_file" "$math_cmd" "UseSMAlphaS3Loop" "True" && ho="${ho} SM" - mma_symbol_is "$model_file" "$math_cmd" "UseSMAlphaS4Loop" "True" && ho="${ho} SM" - mma_symbol_is "$model_file" "$math_cmd" "FlexibleEFTHiggs" "True" && ho="${ho} SM" - mma_symbol_is "$model_file" "$math_cmd" "UseSMYukawa2Loop" "True" && ho="${ho} SM_thresholds" - - mma_symbol_is "$model_file" "$math_cmd" "UseHiggs2LoopMSSM" "True" && ho="${ho} MSSM_higgs" - mma_symbol_is "$model_file" "$math_cmd" "UseHiggs3LoopMSSM" "True" && ho="${ho} MSSM_higgs" - mma_symbol_is "$model_file" "$math_cmd" "UseMSSMAlphaS2Loop" "True" && ho="${ho} MSSM_thresholds" - mma_symbol_is "$model_file" "$math_cmd" "UseMSSMYukawa2Loop" "True" && ho="${ho} MSSM_thresholds" - - mma_symbol_is "$model_file" "$math_cmd" "UseHiggs2LoopNMSSM" "True" && ho="${ho} MSSM_higgs NMSSM_higgs" - - mma_symbol_is "$model_file" "$math_cmd" "UseHiggs3LoopSplit" "True" && ho="${ho} SplitMSSM" + grep -q 'UseSMYukawa2Loop' "${model_file}" && \ + mma_symbol_is "$model_file" "$math_cmd" "UseSMYukawa2Loop" "True" && \ + ho="${ho} SM_thresholds" + + grep -q 'UseHiggs2LoopMSSM' "${model_file}" && \ + mma_symbol_is "$model_file" "$math_cmd" "UseHiggs2LoopMSSM" "True" && \ + ho="${ho} MSSM_higgs" + + grep -q 'UseHiggs3LoopMSSM' "${model_file}" && \ + mma_symbol_is "$model_file" "$math_cmd" "UseHiggs3LoopMSSM" "True" && \ + ho="${ho} MSSM_higgs" + + grep -q 'UseMSSMAlphaS2Loop' "${model_file}" && \ + mma_symbol_is "$model_file" "$math_cmd" "UseMSSMAlphaS2Loop" "True" && \ + ho="${ho} MSSM_thresholds" + + grep -q 'UseMSSMYukawa2Loop' "${model_file}" && \ + mma_symbol_is "$model_file" "$math_cmd" "UseMSSMYukawa2Loop" "True" && \ + ho="${ho} MSSM_thresholds" + + grep -q 'UseHiggs2LoopNMSSM' "${model_file}" && \ + mma_symbol_is "$model_file" "$math_cmd" "UseHiggs2LoopNMSSM" "True" && \ + ho="${ho} MSSM_higgs NMSSM_higgs" + + grep -q 'UseHiggs3LoopSplit' "${model_file}" && \ + mma_symbol_is "$model_file" "$math_cmd" "UseHiggs3LoopSplit" "True" && \ + ho="${ho} SplitMSSM" ho=$(make_unique "${ho}") ho=$(string_trim "${ho}") From 1dee05fa974f721f52b975ba180357b8a7602568 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sat, 13 Nov 2021 12:54:48 +0100 Subject: [PATCH 069/477] supress clang-tidy warning about unsorted header includes (#387) * supress clang-tidy warning about unsorted header includes * don't trigger tests on change to .clang-* --- .clang-tidy | 1 + .github/workflows/tests.yml | 4 ++++ 2 files changed, 5 insertions(+) diff --git a/.clang-tidy b/.clang-tidy index 154c1689d7..cbc43c8bb6 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -20,3 +20,4 @@ Checks: > -readability-else-after-return, -readability-implicit-bool-conversion, -readability-isolate-declaration, + -llvm-include-order diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 5687e9859c..a836d73756 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -10,6 +10,8 @@ on: - development paths-ignore: - '*.rst' + - '.clang-tidy' + - '.clang-format' - 'AUTHORS' - 'COPYING' - 'doc/**' @@ -21,6 +23,8 @@ on: - development paths-ignore: - '*.rst' + - '.clang-tidy' + - '.clang-format' - 'AUTHORS' - 'COPYING' - 'doc/**' From 1a50dd68d3b8deaba2cfca5e5b533a4efeaa6de7 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sun, 14 Nov 2021 12:42:36 +0100 Subject: [PATCH 070/477] static analysis of shell scripts (#385) --- .github/workflows/static-analysis.yml | 36 +++++++++++++++++++++ config/mathematica_include_paths.sh | 8 ++--- configure | 12 +++---- test/test_THDMIIMSSMBCFull_approximation.sh | 1 + 4 files changed, 45 insertions(+), 12 deletions(-) create mode 100644 .github/workflows/static-analysis.yml diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml new file mode 100644 index 0000000000..3367aa589c --- /dev/null +++ b/.github/workflows/static-analysis.yml @@ -0,0 +1,36 @@ +name: static analysis + +on: + push: + paths: + - 'configure' + - 'createmodel' + - 'install-sarah' + - 'createaddon' + - 'config/*.sh' + - 'utils/*.sh' + - 'test/test_*.sh' + + pull_request: + paths: + - 'configure' + - 'createmodel' + - 'install-sarah' + - 'createaddon' + - 'config/*.sh' + - 'utils/*.sh' + - 'test/test_*.sh' + +jobs: + check-scripts: + runs-on: ubuntu-latest + container: + image: navir/opensuseleap-for-flexiblesusy:latest + + steps: + + - name: Checkout + uses: actions/checkout@v2 + + - name: Check scripts + run: shellcheck -S error configure createmodel install-sarah createaddon config/*.sh utils/*.sh test/test_*.sh diff --git a/config/mathematica_include_paths.sh b/config/mathematica_include_paths.sh index b683240c57..e8837c6f07 100755 --- a/config/mathematica_include_paths.sh +++ b/config/mathematica_include_paths.sh @@ -23,12 +23,8 @@ find_math_dirs() { get_librarylink_incpath() { find_math_dirs - for p in \ - "$topdir/SystemFiles/IncludeFiles/C" ; do - test -d "$p" && break - done - - echo "$p" + [ -d "${topdir}/SystemFiles/IncludeFiles/C" ] && \ + echo "${topdir}/SystemFiles/IncludeFiles/C" } get_mathlink_incpath() { diff --git a/configure b/configure index 2e066923b6..634200af34 100755 --- a/configure +++ b/configure @@ -1792,7 +1792,7 @@ check_eigen_incl() { [ -z "$eigen_inc_dir" ] && \ type pkg-config > /dev/null && \ - [ -n ${eigen_name} ] && \ + [ -n "${eigen_name}" ] && \ [ -f ${eigen_name}.pc ] && \ { message -n "Checking for Eigen library using local ${eigen_name}.pc ... " @@ -2083,7 +2083,7 @@ check_gm2calc() { [ -z "$gm2calc_inc_dir" ] && \ [ -z "$gm2calc_lib_dir" ] && \ type pkg-config > /dev/null && \ - [ -n ${gm2calc_name} ] && \ + [ -n "${gm2calc_name}" ] && \ [ -f ${gm2calc_name}.pc ] && \ { message -n "Checking GM2Calc using local ${gm2calc_name}.pc ... " @@ -2195,7 +2195,7 @@ check_himalaya() { [ -z "$himalaya_inc_dir" ] && \ [ -z "$himalaya_lib_dir" ] && \ type pkg-config > /dev/null && \ - [ -n ${himalaya_name} ] && \ + [ -n "${himalaya_name}" ] && \ [ -f ${himalaya_name}.pc ] && \ { message -n "Checking Himalaya using local ${himalaya_name}.pc ... " @@ -2347,7 +2347,7 @@ check_looptools() { [ -z "$looptools_inc_dir" ] && \ [ -z "$looptools_lib_dir" ] && \ type pkg-config > /dev/null && \ - [ -n ${looptools_name} ] && \ + [ -n "${looptools_name}" ] && \ [ -f ${looptools_name}.pc ] && \ { message -n "Checking LoopTools using local ${looptools_name}.pc ... " @@ -2420,7 +2420,7 @@ check_collier() { [ -z "$collier_inc_dir" ] && \ [ -z "$collier_lib_dir" ] && \ type pkg-config > /dev/null && \ - [ -n ${collier_name} ] && \ + [ -n "${collier_name}" ] && \ [ -f ${collier_name}.pc ] && \ { message -n "Checking COLLIER using local ${collier_name}.pc ... " @@ -2642,7 +2642,7 @@ check_tsil() { [ -z "$tsil_inc_dir" ] && \ [ -z "$tsil_lib_dir" ] && \ type pkg-config > /dev/null && \ - [ -n ${tsil_name} ] && \ + [ -n "${tsil_name}" ] && \ [ -f ${tsil_name}.pc ] && \ { message -n "Checking TSIL using local ${tsil_name}.pc ... " diff --git a/test/test_THDMIIMSSMBCFull_approximation.sh b/test/test_THDMIIMSSMBCFull_approximation.sh index 76b50a2786..498adcdeee 100755 --- a/test/test_THDMIIMSSMBCFull_approximation.sh +++ b/test/test_THDMIIMSSMBCFull_approximation.sh @@ -1,3 +1,4 @@ +#!/bin/sh BASEDIR=$(dirname $0) HOMEDIR="${BASEDIR}/.." From f7d0628a51dfa331cfc722d8826d4af0127a23b9 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Sun, 14 Nov 2021 16:37:52 +0100 Subject: [PATCH 071/477] More specific definition for newer. --- configure | 19 ++++++++++++------- createmodel | 1 + 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/configure b/configure index f394fcfed9..24eece9ea3 100755 --- a/configure +++ b/configure @@ -3182,8 +3182,13 @@ update_module_mk() { local math_cmd="${4:-math}" [ -e "$model_file" ] || return - if [ ! "${mkfile}" -nt "${model_file}" ] && \ - [ ! "${mkfile}" -ot "${model_file}" ]; then + + local mk_date model_date date_tolerance + mk_date="$(date -r "${mkfile}" +%s)" + model_date="$(date -r "${model_file}" +%s)" + date_tolerance="5" # Seconds + if [ "0" = "$(( $mk_date + $date_tolerance < $model_date ))" ] && \ + [ "0" = "$(( $model_date < $mk_date - $date_tolerance ))" ]; then return fi @@ -3203,12 +3208,12 @@ update_model_makefiles() { message "Checking model makefiles" + local model_name model_file mkfile for m in ${MODELS}; do - local model_name=$(echo ${m} | sed -e 's|models/||') - local model_file="${m}/FlexibleSUSY.m" - local mkfile="$m/module.mk" - - update_module_mk "$model_name" "$mkfile" "$model_file" "$MATH" + model_name="$(echo ${m} | sed -e 's|models/||')" + model_file="${m}/FlexibleSUSY.m" + mkfile="$m/module.mk" + update_module_mk "$model_name" "$mkfile" "$model_file" "$MATH" done } diff --git a/createmodel b/createmodel index 30da8357c5..dd1e965ce9 100755 --- a/createmodel +++ b/createmodel @@ -539,6 +539,7 @@ sed -e "s|@DIR@|$targetdir|g" \ -e "s|@CLASSNAME@|$name|g" \ -e "s|FSModelName\([[:blank:]]*=[[:blank:]]*\)[^;][^;]*|FSModelName\1\"$name\"|g" \ < $model_file_dir/FlexibleSUSY.m.in > $targetdir/FlexibleSUSY.m +touch -d "1 min ago" "${targetdir}/FlexibleSUSY.m" message "done" for slha_in in $SLHA_input_files; do From 729b8ec026696428a210ae8927a82a8c7fae1c64 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Sun, 14 Nov 2021 19:19:51 +0100 Subject: [PATCH 072/477] Fix: SC2155: Declare and assign separately to avoid masking return values. --- configure | 150 +++++++++++-------- test/test_CMSSMSemiAnalytic_spectrum.sh | 3 +- test/test_MSSMEFTHiggs.sh | 19 ++- test/test_MSSMNoFVEFTHiggs.sh | 20 ++- test/test_lowNUHMSSMSemiAnalytic_spectrum.sh | 3 +- 5 files changed, 116 insertions(+), 79 deletions(-) diff --git a/configure b/configure index f394fcfed9..04d237930c 100755 --- a/configure +++ b/configure @@ -344,7 +344,8 @@ log_package_information() { #_____________________________________________________________________ guess_machine_word_size() { - local chip="$(uname -m | tr '[A-Z]' '[a-z]')" + local chip + chip="$(uname -m | tr '[A-Z]' '[a-z]')" exists_in_path getconf && chip="${chip}$(getconf LONG_BIT)" case "$chip" in *32|i[36]86) @@ -960,7 +961,8 @@ check_solvers() { fi checking_msg "RGE solvers" - local algs="$(echo $SOLVERS | tr ',' ' ')" + local algs + algs="$(echo $SOLVERS | tr ',' ' ')" SOLVERS="" for a in ${algs}; do case "$a" in @@ -992,7 +994,8 @@ check_models() { fi checking_msg "models" - local models="$(echo $MODELS | tr ',' ' ')" + local models + models="$(echo $MODELS | tr ',' ' ')" MODELS="" for a in ${models}; do case "$a" in @@ -1036,7 +1039,8 @@ check_models() { fi done - local model_names="$(echo ${MODELS} | sed -e 's|models/||g' -e 's/^ *//' -e 's/ *$//')" + local model_names + model_names="$(echo ${MODELS} | sed -e 's|models/||g' -e 's/^ *//' -e 's/ *$//')" result "ok (${model_names})" logmsg " Models: ${MODELS}" @@ -1050,7 +1054,8 @@ check_addons() { fi checking_msg "addons" - local addons="$(echo $ADDONS | tr ',' ' ')" + local addons + addons="$(echo $ADDONS | tr ',' ' ')" ADDONS="" for a in ${addons}; do case "$a" in @@ -1080,7 +1085,8 @@ check_addons() { fi done - local addon_names="$(echo ${ADDONS} | sed -e 's|addons/||g' -e 's/^ *//' -e 's/ *$//')" + local addon_names + addon_names="$(echo ${ADDONS} | sed -e 's|addons/||g' -e 's/^ *//' -e 's/ *$//')" result "ok (${addon_names})" logmsg " Addons: ${ADDONS}" @@ -1094,7 +1100,8 @@ check_optional_modules() { fi checking_msg "optional modules" - local optional_modules="$(echo $OPTIONAL_MODULES | tr ',' ' ')" + local optional_modules + optional_modules="$(echo $OPTIONAL_MODULES | tr ',' ' ')" OPTIONAL_MODULES="" for a in ${optional_modules}; do if test -d "$BASEDIR/$a" ; then @@ -1118,7 +1125,8 @@ check_optional_modules() { fi done - local module_names="$(echo ${OPTIONAL_MODULES} | sed -e 's|addons/||g' -e 's/^ *//' -e 's/ *$//')" + local module_names + module_names="$(echo ${OPTIONAL_MODULES} | sed -e 's|addons/||g' -e 's/^ *//' -e 's/ *$//')" result "ok (${module_names})" logmsg " Optional modules: ${OPTIONAL_MODULES}" @@ -1229,7 +1237,8 @@ ${MATH_INSTDIR}/SystemFiles/Links/MathLink/DeveloperKit/CompilerAdditions" exit 1 fi - local mathlink_lib=-l$(echo "$found_lib" | sed 's/^lib\(.*\)\..*$/\1/') + local mathlink_lib + mathlink_lib=-l$(echo "$found_lib" | sed 's/^lib\(.*\)\..*$/\1/') mathlink_lib_flags="-L${found_dir} ${mathlink_lib} -lc++ -framework Foundation" ;; esac @@ -1311,7 +1320,8 @@ check_platform() { #_____________________________________________________________________ reset_default_static_linker_cmd() { - local os_=$( (uname -s) 2>/dev/null || echo unknown) + local os_ + os_=$( (uname -s) 2>/dev/null || echo unknown) case "$os_" in Linux) STATIC_LIB_CMD="ar cruU";; @@ -1431,7 +1441,8 @@ check_boost_test_libs() { message "Warning: libboost_unit_test_framework(-mt) must be installed" message " to compile and run the tests, see http://www.boost.org" else - local BOOSTTESTLIBS_=-l$( + local BOOSTTESTLIBS_ + BOOSTTESTLIBS_=-l$( echo "$found_lib" | sed 's/^lib\(.*\)\..*$/\1/') if [ -z "$boost_lib_dir" ]; then # assume that the linker will look in the default paths @@ -1462,7 +1473,8 @@ check_boost_thread_libs() { message " You can disable the lattice method with the --with-solvers= flag." exit 1 fi - local BOOSTTHREADLIBS_=-l$(echo "$found_lib" | sed 's/^lib\(.*\)\..*$/\1/') + local BOOSTTHREADLIBS_ + BOOSTTHREADLIBS_=-l$(echo "$found_lib" | sed 's/^lib\(.*\)\..*$/\1/') check_library "libboost_system libboost_system-mt" \ "$boost_lib_dir" "$default_lib_paths" @@ -1668,14 +1680,17 @@ get_gpp_version() { output=$($compiler -dM -E -x c++ /dev/null) || { message "Warning: could not determine $compiler version because" message " execution of $compiler failed." - return 1 + return 1 } - local major=$(printf "%s" "$output" | - sed 's/^.*__GNUC__[[:space:]]*\([[:digit:]]*\).*$/\1/p;d') - local minor=$(printf "%s" "$output" | - sed 's/^.*__GNUC_MINOR__[[:space:]]*\([[:digit:]]*\).*$/\1/p;d') - local patch=$(printf "%s" "$output" | - sed 's/^.*__GNUC_PATCHLEVEL__[[:space:]]*\([[:digit:]]*\).*$/\1/p;d') + local major + major=$(printf "%s" "$output" | + sed 's/^.*__GNUC__[[:space:]]*\([[:digit:]]*\).*$/\1/p;d') + local minor + minor=$(printf "%s" "$output" | + sed 's/^.*__GNUC_MINOR__[[:space:]]*\([[:digit:]]*\).*$/\1/p;d') + local patch + patch=$(printf "%s" "$output" | + sed 's/^.*__GNUC_PATCHLEVEL__[[:space:]]*\([[:digit:]]*\).*$/\1/p;d') eval "$ret_var=\"$major.$minor.$patch\"" } @@ -1694,10 +1709,11 @@ get_icpc_version() { output=$($compiler -dM -E -x c++ /dev/null) || { message "Warning: could not determine $compiler version because" message " execution of $compiler failed." - return 1 + return 1 } - local version=$(printf "%s" "$output" | - sed 's/^.*__INTEL_COMPILER[[:space:]]*\([[:digit:]]*\)\([[:digit:]]\)\([[:digit:]]\).*$/\1.\2.\3/p;d') + local version + version=$(printf "%s" "$output" | + sed 's/^.*__INTEL_COMPILER[[:space:]]*\([[:digit:]]*\)\([[:digit:]]\)\([[:digit:]]\).*$/\1.\2.\3/p;d') eval "$ret_var=\"$version\"" } @@ -1725,12 +1741,13 @@ get_clang_version() { message " execution of $compiler failed." return 1 } - local major=$(printf "%s" "$output" | - sed 's/^.*__clang_major__[[:space:]]*\([[:digit:]]*\).*$/\1/p;d') - local minor=$(printf "%s" "$output" | - sed 's/^.*__clang_minor__[[:space:]]*\([[:digit:]]*\).*$/\1/p;d') - local patch=$(printf "%s" "$output" | - sed 's/^.*__clang_patchlevel__[[:space:]]*\([[:digit:]]*\).*$/\1/p;d') + local major minor patch + major=$(printf "%s" "$output" | + sed 's/^.*__clang_major__[[:space:]]*\([[:digit:]]*\).*$/\1/p;d') + minor=$(printf "%s" "$output" | + sed 's/^.*__clang_minor__[[:space:]]*\([[:digit:]]*\).*$/\1/p;d') + patch=$(printf "%s" "$output" | + sed 's/^.*__clang_patchlevel__[[:space:]]*\([[:digit:]]*\).*$/\1/p;d') eval "$ret_var=\"$major.$minor.$patch\"" } @@ -1865,7 +1882,8 @@ check_gsl_config() { message " use $0 --with-gsl-config=" exit 1 else - local GSL_VERSION=$($cmd --version) + local GSL_VERSION + GSL_VERSION=$($cmd --version) result "found $cmd (version ${GSL_VERSION})" GSLFLAGS=$($cmd --cflags) GSLLIBS=$($cmd --libs) @@ -2221,7 +2239,8 @@ check_required_libs() { message "Checking model files for required third party libraries" for m in ${MODELS}; do - local model_name=$(echo ${m} | sed -e 's|models/||') + local model_name + model_name=$(echo ${m} | sed -e 's|models/||') local model_file="models/${model_name}/FlexibleSUSY.m" [ -e "${model_file}" ] || continue @@ -2302,7 +2321,8 @@ check_looptools_libs() { fi case "$operating_system" in Darwin) - local gcc_=$(${CXX} -print-search-dirs | sed -n -e '/libraries:/s/libraries: *=//p') + local gcc_ + gcc_=$(${CXX} -print-search-dirs | sed -n -e '/libraries:/s/libraries: *=//p') check_library "libgcc" "$gcc_" "$default_lib_paths" if test "x$found_lib" = "x" ; then message "Error: libgcc not found in $gcc_ $default_lib_paths" @@ -2613,11 +2633,13 @@ check_tsil_incl() { #_____________________________________________________________________ check_tsil_size() { - local tsil_dir=$([ -n "$tsil_inc_dir" ] && echo "$tsil_inc_dir" || echo "$tsil_lib_dir") + local tsil_dir + tsil_dir=$([ -n "$tsil_inc_dir" ] && echo "$tsil_inc_dir" || echo "$tsil_lib_dir") if [ -f "${tsil_dir}/Makefile" ] ; then - local tsil_makefile="${tsil_dir}/Makefile" - local tsil_size=$({ echo "first: ; @echo \$(TSIL_SIZE)" + local tsil_makefile tsil_size + tsil_makefile="${tsil_dir}/Makefile" + tsil_size=$({ echo "first: ; @echo \$(TSIL_SIZE)" cat "$tsil_makefile" } | make -f - first ) @@ -2666,11 +2688,8 @@ check_tsil() { #_____________________________________________________________________ find_symbol_using_pkgconfig() { - local symbol - local pkg - local ldpaths - local libnames - local pkg_flags=$([ "x$enable_static" = xyes ] && echo "--static") + local symbol pkg ldpaths libnames pkg_flags + pkg_flags=$([ "x$enable_static" = xyes ] && echo "--static") pkg="$1" linker_flags="" type pkg-config > /dev/null 2>&1 || { @@ -2938,14 +2957,15 @@ EOF for m in "models"/*; do [ -e "$m/FlexibleSUSY.m" ] || continue [ -e "$m/start.m" ] || continue - local eigenstate=$(grep 'FSEigenstates' "$m/FlexibleSUSY.m" \ + local eigenstate output dir + eigenstate=$(grep 'FSEigenstates' "$m/FlexibleSUSY.m" \ | sed 's/ //g' \ | sed 's/.*`\(.*\);/\1/') - local output=$(grep -m1 'OutputDirectory' "$m/start.m" \ + output=$(grep -m1 'OutputDirectory' "$m/start.m" \ | sed 's/ //g' \ | sed 's/.*\"\(.*\)\".*/\1/') output=$(echo $m | sed "s/models/${output}/") - local dir="${output}/${eigenstate}/FeynArts" + dir="${output}/${eigenstate}/FeynArts" [ -d "${dir}" ] && { rm -rf ${dir}; } dir="${output}/${eigenstate}/FormCalc" [ -d "${dir}" ] && { rm -rf ${dir}; } @@ -3014,14 +3034,15 @@ EOF for m in "models"/*; do [ -e "$m/FlexibleSUSY.m" ] || continue [ -e "$m/start.m" ] || continue - local eigenstate=$(grep 'FSEigenstates' "models/$m/FlexibleSUSY.m" \ + local eigenstate output dir + eigenstate=$(grep 'FSEigenstates' "models/$m/FlexibleSUSY.m" \ | sed 's/ //g' \ | sed 's/.*`\(.*\);/\1/') - local output=$(grep -m1 'OutputDirectory' "models/$m/start.m" \ + output=$(grep -m1 'OutputDirectory' "models/$m/start.m" \ | sed 's/ //g' \ | sed 's/.*\"\(.*\)\".*/\1/') output=$(echo $m | sed "s/models/${output}/") - local dir="${output}/$m/${eigenstate}/FormCalc" + dir="${output}/$m/${eigenstate}/FormCalc" [ -d "${dir}" ] && { rm -rf ${dir}; } dir="${output}/$m/${eigenstate}/NPointFunctions" [ -d "${dir}" ] && { rm -rf ${dir}; } @@ -3188,7 +3209,8 @@ update_module_mk() { fi message -n " Updating model-specific modules in $mkfile ... " - local ho="$(get_model_specific_corrections "$model_file" "$math_cmd")" + local ho + ho="$(get_model_specific_corrections "$model_file" "$math_cmd")" sed -i -e "s|^\(MOD${name}_MOD[[:space:]]*:=\).*$|\1 $ho|" "$mkfile" touch "${mkfile}" "${model_file}" message "($ho)" @@ -3204,11 +3226,12 @@ update_model_makefiles() { message "Checking model makefiles" for m in ${MODELS}; do - local model_name=$(echo ${m} | sed -e 's|models/||') + local model_name + model_name=$(echo ${m} | sed -e 's|models/||') local model_file="${m}/FlexibleSUSY.m" - local mkfile="$m/module.mk" + local mkfile="$m/module.mk" - update_module_mk "$model_name" "$mkfile" "$model_file" "$MATH" + update_module_mk "$model_name" "$mkfile" "$model_file" "$MATH" done } @@ -3402,28 +3425,33 @@ enable_defines() { done for a in ${ADDONS}; do - local addon_name="$(basename ${a})" + local addon_name + addon_name="$(basename ${a})" DEFINE_ENABLE_ADDONS="${DEFINE_ENABLE_ADDONS}@n@#define ENABLE_${addon_name} 1" done } #_____________________________________________________________________ add_metaflags() { - local tlib_='FSLoopLibraries = { FSSOFTSUSY' - local lib_="$tlib_" - test $enable_looptools = 'yes' && lib_="${lib_}, FSLoopTools" - test $enable_fflite = 'yes' && lib_="${lib_}, FSFFlite" - test $enable_collier = 'yes' && lib_="${lib_}, FSCOLLIER" + local tlib_ lib_ + tlib_='FSLoopLibraries = { FSSOFTSUSY' + lib_="${tlib_}" + test ${enable_looptools} = 'yes' && lib_="${lib_}, FSLoopTools" + test ${enable_fflite} = 'yes' && lib_="${lib_}, FSFFlite" + test ${enable_collier} = 'yes' && lib_="${lib_}, FSCOLLIER" lib_="${lib_} };" - local tfa_='FSFeynArtsAvailable = ' - local fa_="${tfa_}$(test $enable_feynarts = 'yes' && echo 'True' || echo 'False');" + local tfa_ fa_ + tfa_='FSFeynArtsAvailable = ' + fa_="${tfa_}$(test ${enable_feynarts} = 'yes' && echo 'True' || echo 'False');" - local tfc_='FSFormCalcAvailable = ' - local fc_="${tfc_}$(test $enable_formcalc = 'yes' && echo 'True' || echo 'False');" + local tfc_ fc_ + tfc_='FSFormCalcAvailable = ' + fc_="${tfc_}$(test ${enable_formcalc} = 'yes' && echo 'True' || echo 'False');" - local tcol_='FSEnableColors = ' - local col_="${tcol_}$(test $enable_colors = 'yes' && echo 'True' || echo 'False');" + local tcol_ col_ + tcol_='FSEnableColors = ' + col_="${tcol_}$(test ${enable_colors} = 'yes' && echo 'True' || echo 'False');" local c_='' local fs_='' diff --git a/test/test_CMSSMSemiAnalytic_spectrum.sh b/test/test_CMSSMSemiAnalytic_spectrum.sh index a6b859d364..6a8d25eda2 100755 --- a/test/test_CMSSMSemiAnalytic_spectrum.sh +++ b/test/test_CMSSMSemiAnalytic_spectrum.sh @@ -74,7 +74,8 @@ remove_extra_blocks() { } sign() { - local a=$(echo "$1" | sed -e 's/[eE]+*/*10^/') + local a + a=$(echo "$1" | sed -e 's/[eE]+*/*10^/') cat <= 0) return(1) diff --git a/test/test_MSSMEFTHiggs.sh b/test/test_MSSMEFTHiggs.sh index 3acd0efe0c..77da1a5c00 100755 --- a/test/test_MSSMEFTHiggs.sh +++ b/test/test_MSSMEFTHiggs.sh @@ -125,22 +125,25 @@ Block EXTPAR run_sg() { local SG="$1" local type="$2" - local calcBSM=$(test "x$type" = xtower ; echo $?) - local loops=$(if [ "x$type" = xtower ] ; then echo 1; else echo 2; fi) + local calcBSM loops + calcBSM=$(test "x$type" = xtower ; echo $?) + loops=$(if [ "x$type" = xtower ] ; then echo 1; else echo 2; fi) # set loops=2 to have perfect agreement at large MS # (but this spoils agreement at MS < Mt) loops=2 - local MS2=$(echo "scale=5; ${MS}^2" | bc) - local At=$(echo "scale=10; (1./${TB} + ${Xt}) * ${MS}" | bc) - local Au=$(echo "scale=10; (1./${TB} + 0) * ${MS}" | bc) - local Ad=$(echo "scale=10; (${TB} + 0) * ${MS}" | bc) + local MS2 At Au Ad + MS2=$(echo "scale=5; ${MS}^2" | bc) + At=$(echo "scale=10; (1./${TB} + ${Xt}) * ${MS}" | bc) + Au=$(echo "scale=10; (1./${TB} + 0) * ${MS}" | bc) + Ad=$(echo "scale=10; (${TB} + 0) * ${MS}" | bc) local Ae="$Ad" local slha_output= local block= local value= local slha_input= - local output_block=$(echo "${output}" | cut -d'-' -f1) - local output_entry=$(echo "${output}" | cut -d'-' -f2) + local output_block output_entry + output_block=$(echo "${output}" | cut -d'-' -f1) + output_entry=$(echo "${output}" | cut -d'-' -f2) slha_input=$( { echo "$slha_tmpl" ; \ diff --git a/test/test_MSSMNoFVEFTHiggs.sh b/test/test_MSSMNoFVEFTHiggs.sh index 6f6fe043c6..11aa6850f6 100755 --- a/test/test_MSSMNoFVEFTHiggs.sh +++ b/test/test_MSSMNoFVEFTHiggs.sh @@ -103,8 +103,10 @@ run_sg() { local SG="$1" local slha_input="$2" local output="$3" - local output_block=$(echo "${output}" | cut -d'-' -f1) - local output_entry=$(echo "${output}" | cut -d'-' -f2) + local output_block + output_block=$(echo "${output}" | cut -d'-' -f1) + local output_entry + output_entry=$(echo "${output}" | cut -d'-' -f2) local slha_output= local block= local value= @@ -122,9 +124,10 @@ run_sg() { run_MSSMEFTHiggs() { local SG="$1" - local MS2=$(echo "scale=5; ${MS}^2" | bc) - local At=$(echo "scale=10; (1./${TB} + ${Xt}) * ${MS}" | bc) - local Ab=$(echo "scale=10; (${TB} + ${Xb}) * ${MS}" | bc) + local MS2 At Ab + MS2=$(echo "scale=5; ${MS}^2" | bc) + At=$(echo "scale=10; (1./${TB} + ${Xt}) * ${MS}" | bc) + Ab=$(echo "scale=10; (${TB} + ${Xb}) * ${MS}" | bc) local slha_input="\ ${slha_tmpl} Block EXTPAR # Input parameters @@ -174,9 +177,10 @@ Block AEIN run_MSSMNoFVEFTHiggs() { local SG="$1" - local MS2=$(echo "scale=5; ${MS}^2" | bc) - local At=$(echo "scale=10; (1./${TB} + ${Xt}) * ${MS}" | bc) - local Ab=$(echo "scale=10; (${TB} + ${Xb}) * ${MS}" | bc) + local MS2 At Ab + MS2=$(echo "scale=5; ${MS}^2" | bc) + At=$(echo "scale=10; (1./${TB} + ${Xt}) * ${MS}" | bc) + Ab=$(echo "scale=10; (${TB} + ${Xb}) * ${MS}" | bc) local slha_input="\ ${slha_tmpl} Block EXTPAR diff --git a/test/test_lowNUHMSSMSemiAnalytic_spectrum.sh b/test/test_lowNUHMSSMSemiAnalytic_spectrum.sh index 91a8a9f787..cbef07f11d 100755 --- a/test/test_lowNUHMSSMSemiAnalytic_spectrum.sh +++ b/test/test_lowNUHMSSMSemiAnalytic_spectrum.sh @@ -79,7 +79,8 @@ remove_mixing_and_input_blocks() { } sign() { - local a=$(echo "$1" | sed -e 's/[eE]+*/*10^/') + local a + a=$(echo "$1" | sed -e 's/[eE]+*/*10^/') cat <= 0) return(1) From 2675c873e5a41627625c2cbe9ada6c74b3f8181c Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Sun, 14 Nov 2021 19:32:26 +0100 Subject: [PATCH 073/477] Massage indentation. --- configure | 29 +++++++++++++---------------- 1 file changed, 13 insertions(+), 16 deletions(-) diff --git a/configure b/configure index 04d237930c..1a20a0d808 100755 --- a/configure +++ b/configure @@ -1238,7 +1238,7 @@ ${MATH_INSTDIR}/SystemFiles/Links/MathLink/DeveloperKit/CompilerAdditions" fi local mathlink_lib - mathlink_lib=-l$(echo "$found_lib" | sed 's/^lib\(.*\)\..*$/\1/') + mathlink_lib=-l$(echo "$found_lib" | sed 's/^lib\(.*\)\..*$/\1/') mathlink_lib_flags="-L${found_dir} ${mathlink_lib} -lc++ -framework Foundation" ;; esac @@ -1320,12 +1320,12 @@ check_platform() { #_____________________________________________________________________ reset_default_static_linker_cmd() { - local os_ + local os_ os_=$( (uname -s) 2>/dev/null || echo unknown) - case "$os_" in - Linux) - STATIC_LIB_CMD="ar cruU";; - esac + case "$os_" in + Linux) + STATIC_LIB_CMD="ar cruU";; + esac } #_____________________________________________________________________ @@ -1442,8 +1442,7 @@ check_boost_test_libs() { message " to compile and run the tests, see http://www.boost.org" else local BOOSTTESTLIBS_ - BOOSTTESTLIBS_=-l$( - echo "$found_lib" | sed 's/^lib\(.*\)\..*$/\1/') + BOOSTTESTLIBS_=-l$(echo "$found_lib" | sed 's/^lib\(.*\)\..*$/\1/') if [ -z "$boost_lib_dir" ]; then # assume that the linker will look in the default paths BOOSTTESTLIBS="$BOOSTTESTLIBS_" @@ -1682,13 +1681,11 @@ get_gpp_version() { message " execution of $compiler failed." return 1 } - local major + local major minor patch major=$(printf "%s" "$output" | sed 's/^.*__GNUC__[[:space:]]*\([[:digit:]]*\).*$/\1/p;d') - local minor minor=$(printf "%s" "$output" | sed 's/^.*__GNUC_MINOR__[[:space:]]*\([[:digit:]]*\).*$/\1/p;d') - local patch patch=$(printf "%s" "$output" | sed 's/^.*__GNUC_PATCHLEVEL__[[:space:]]*\([[:digit:]]*\).*$/\1/p;d') @@ -1883,7 +1880,7 @@ check_gsl_config() { exit 1 else local GSL_VERSION - GSL_VERSION=$($cmd --version) + GSL_VERSION=$($cmd --version) result "found $cmd (version ${GSL_VERSION})" GSLFLAGS=$($cmd --cflags) GSLLIBS=$($cmd --libs) @@ -3036,11 +3033,11 @@ EOF [ -e "$m/start.m" ] || continue local eigenstate output dir eigenstate=$(grep 'FSEigenstates' "models/$m/FlexibleSUSY.m" \ - | sed 's/ //g' \ - | sed 's/.*`\(.*\);/\1/') + | sed 's/ //g' \ + | sed 's/.*`\(.*\);/\1/') output=$(grep -m1 'OutputDirectory' "models/$m/start.m" \ - | sed 's/ //g' \ - | sed 's/.*\"\(.*\)\".*/\1/') + | sed 's/ //g' \ + | sed 's/.*\"\(.*\)\".*/\1/') output=$(echo $m | sed "s/models/${output}/") dir="${output}/$m/${eigenstate}/FormCalc" [ -d "${dir}" ] && { rm -rf ${dir}; } From 435a64490595d18c01b21d43173b370dca7c6b56 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Sun, 14 Nov 2021 19:40:17 +0100 Subject: [PATCH 074/477] Fix: Use 'cd ... || exit' or 'cd ... || return' in case cd fails. --- config/mathematica_include_paths.sh | 2 +- configure | 2 +- createmodel | 2 +- install-sarah | 2 +- test/test_looplibrary_environment.sh | 2 +- test/test_pv_crosschecks.sh | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/config/mathematica_include_paths.sh b/config/mathematica_include_paths.sh index e8837c6f07..d33fe8b6da 100755 --- a/config/mathematica_include_paths.sh +++ b/config/mathematica_include_paths.sh @@ -17,7 +17,7 @@ find_math_dirs() { ${DLLTOOL:-dlltool} --help | grep x86-64 > /dev/null || sysid=Windows } - topdir=`cd "$topdir" ; echo $PWD` + topdir=`cd "$topdir" && echo $PWD` } get_librarylink_incpath() { diff --git a/configure b/configure index 1a20a0d808..f1b5f8ae60 100755 --- a/configure +++ b/configure @@ -17,7 +17,7 @@ HIMALAYA_VERSION="unknown" BASEDIR=$(dirname $0) # absolute path to this script -ABSBASEDIR=$(cd "$BASEDIR"; pwd | sed 's/ /\\\\ /g') +ABSBASEDIR=$(cd "$BASEDIR" && pwd | sed 's/ /\\\\ /g') # config directory CONFIGDIR="${BASEDIR}/config" diff --git a/createmodel b/createmodel index 30da8357c5..735bc79e92 100755 --- a/createmodel +++ b/createmodel @@ -7,7 +7,7 @@ BASEDIR=$(dirname $0) # absolute path to this script -ABSBASEDIR=$(cd $BASEDIR; pwd) +ABSBASEDIR=$(cd $BASEDIR && pwd) # operating system operating_system="`(uname -s) 2>/dev/null || echo unknown`" diff --git a/install-sarah b/install-sarah index 8a222bea8f..11f2caff3f 100755 --- a/install-sarah +++ b/install-sarah @@ -7,7 +7,7 @@ BASEDIR=$(dirname $0) # absolute path to this script -ABSBASEDIR=$(cd $BASEDIR; pwd) +ABSBASEDIR=$(cd $BASEDIR && pwd) # operating system operating_system="`(uname -s) 2>/dev/null || echo unknown`" diff --git a/test/test_looplibrary_environment.sh b/test/test_looplibrary_environment.sh index 017abd9a7d..bc819efd75 100755 --- a/test/test_looplibrary_environment.sh +++ b/test/test_looplibrary_environment.sh @@ -8,7 +8,7 @@ body_test () { [ $TEST_LOOPLIBRARY = "lib<$2>" ] || exit_code=1 } -cd test +cd test || exit 1 body_test '0' 'Softsusy' body_test 'not an integer' 'Softsusy' diff --git a/test/test_pv_crosschecks.sh b/test/test_pv_crosschecks.sh index 6bbf52a3d4..b6e0239ca6 100755 --- a/test/test_pv_crosschecks.sh +++ b/test/test_pv_crosschecks.sh @@ -2,7 +2,7 @@ exit_code=0 -cd test +cd test || exit 1 ./test_pv_fflite.x | ./test_pv_looptools.x --log_level=test_suite || exit_code=1 From ac883994100cf418ac3ddc2df223a116a8b7d805 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Sun, 14 Nov 2021 20:41:06 +0100 Subject: [PATCH 075/477] Fix: SC2154: is referenced but not assigned. --- configure | 21 ++++++++------------- createmodel | 17 +++++++++-------- install-sarah | 4 ++++ test/test_CMSSMCKM_spectrum.sh | 2 +- test/test_CMSSMNoFV_GM2Calc.sh | 1 + test/test_CMSSM_streams.sh | 2 ++ 6 files changed, 25 insertions(+), 22 deletions(-) diff --git a/configure b/configure index f1b5f8ae60..b5b9d877a4 100755 --- a/configure +++ b/configure @@ -631,12 +631,7 @@ check_symbol() { # Check if we got a specific argument as to where the library # is to be found symbolfile=$symbollib - exts=".so .lib .dylib" - if test ! "x$shared" = "xno" ; then - exts="$exts .a" - else - exts=".a $exts" - fi + exts=".so .lib .dylib .a" usrlib="/usr/lib" if test "x$machine_word_size" = "x32" ; then @@ -1134,11 +1129,13 @@ check_optional_modules() { #_____________________________________________________________________ check_librarylink_incl() { + # sysid is defined in config/mathematica_include_paths.sh + # shellcheck disable=SC2154 local default_llincdir="\ ${MATH_INSTDIR}/SystemFiles/IncludeFiles/C:\ ${MATH_INSTDIR}/SystemFiles/Links/MathLink/DeveloperKit/${MATH_SYSTEMID}/CompilerAdditions:\ ${MATH_INSTDIR}/SystemFiles/Links/MathLink/DeveloperKit/CompilerAdditions:\ -${MATH_INSTDIR}/AddOns/MathLink/DeveloperKit/$sysid/CompilerAdditions" +${MATH_INSTDIR}/AddOns/MathLink/DeveloperKit/${sysid}/CompilerAdditions" check_header "WolframLibrary.h" "$default_llincdir" \ "$default_inc_paths" @@ -1571,14 +1568,11 @@ check_cxx_compiler_type() { case "$cxx_compiler_type" in gnu) result "GNU" - required_cxx_compiler_version="$required_gpp_compiler_version" - std_cxx11_compiler_version="$std_cxx11_gpp_version" ;; + required_cxx_compiler_version="$required_gpp_compiler_version" ;; clang) result "Clang" - required_cxx_compiler_version="$required_clang_compiler_version" - std_cxx11_compiler_version="$std_cxx11_clang_version" ;; + required_cxx_compiler_version="$required_clang_compiler_version" ;; intel) result "Intel" - required_cxx_compiler_version="$required_icpc_compiler_version" - std_cxx11_compiler_version="$std_cxx11_icpc_version" ;; + required_cxx_compiler_version="$required_icpc_compiler_version" ;; *) result "unknown" ;; esac @@ -3691,6 +3685,7 @@ if test $# -gt 0 ; then --enable-*) f=$(echo "$1" | sed -e 's/--//' -e 's/-/_/g') eval prev='$'$(echo "${f}") + # shellcheck disable=SC2154 if test "x${prev}" = "xyes"; then echo "INFO: $1: already enabled by default." fi diff --git a/createmodel b/createmodel index 735bc79e92..e2b02a990a 100755 --- a/createmodel +++ b/createmodel @@ -389,23 +389,24 @@ if test $# -gt 0 ; then --enable-*) f=`echo $1 | sed -e 's/--//' -e 's/-/_/g'` eval prev='$'`echo ${f}` + # shellcheck disable=SC2154 if test "x${prev}" = "xyes"; then message "INFO: $1: already enabled by default." fi - if test ! "x`message ${deprecated_options} | grep ${f}`" = "x"; then - message "WARNING: option $1 is deprecated and ignored"'!' - fi + #if test ! "x`message ${deprecated_options} | grep ${f}`" = "x"; then + # message "WARNING: option $1 is deprecated and ignored"'!' + #fi eval ${f}=yes for c in $options ; do if test "x$c" = "x$f" ; then f="" fi done - for c in $deprecated_options ; do - if test "x$c" = "x$f" ; then - f="" - fi - done + #for c in $deprecated_options ; do + # if test "x$c" = "x$f" ; then + # f="" + # fi + #done if test "x$f" != "x" ; then message "Invalid option '$1'. Try $0 --help" ; exit 1 ; fi diff --git a/install-sarah b/install-sarah index 11f2caff3f..8990b45e80 100755 --- a/install-sarah +++ b/install-sarah @@ -15,6 +15,10 @@ operating_system="`(uname -s) 2>/dev/null || echo unknown`" # default SARAH version sarah_version="4.14.5" +# exit codes +exit_ok="0" +exit_syntax_error="1" + # determine Mathematica user directory case "$operating_system" in Darwin) mathematica_dir="${HOME}/Library/Mathematica" ;; diff --git a/test/test_CMSSMCKM_spectrum.sh b/test/test_CMSSMCKM_spectrum.sh index 6c4757fa6a..ecebc3454a 100755 --- a/test/test_CMSSMCKM_spectrum.sh +++ b/test/test_CMSSMCKM_spectrum.sh @@ -73,7 +73,7 @@ diff_without_comments=`echo $diff | $sed_cmd -e '/^ *#/d' | $sed_cmd -e '/^+++/d exit_code=0 if [ -n "$diff_without_comments" ]; then - echo "Error: difference between $semi_analytic_output and $two_scale_output larger than $rel_error" + echo "Error: difference between ${FS_out} and ${SS_out} larger than ${rel_error}" echo "$diff" echo "" echo "Test result: FAIL" diff --git a/test/test_CMSSMNoFV_GM2Calc.sh b/test/test_CMSSMNoFV_GM2Calc.sh index 88eb5a92b8..05775be617 100755 --- a/test/test_CMSSMNoFV_GM2Calc.sh +++ b/test/test_CMSSMNoFV_GM2Calc.sh @@ -10,6 +10,7 @@ print_block="$BASEDIR/../utils/print_slha_block.awk" if [ -e GM2Calc.pc ] ; then eval $(grep '^prefix=' GM2Calc.pc) + # shellcheck disable=SC2154 GM2CALC_EXE="${prefix}/bin/gm2calc.x" fi diff --git a/test/test_CMSSM_streams.sh b/test/test_CMSSM_streams.sh index da215cc7ff..ad6fe32029 100755 --- a/test/test_CMSSM_streams.sh +++ b/test/test_CMSSM_streams.sh @@ -19,6 +19,8 @@ Block MINPAR # Input parameters EOF ) +exit_code="1" + if [ -n "$CMSSM_STD_OUTPUT" ] ; then echo "Error: output was written to cout:" echo "" From 7fd5449f48bc94e70fd7e5b938271b118ec4ef47 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Sun, 14 Nov 2021 21:23:12 +0100 Subject: [PATCH 076/477] Fix: SC2046: Quote this to prevent word splitting. --- config/mathematica_include_paths.sh | 5 +++-- configure | 7 ++++--- createmodel | 7 ++++--- test/test_CMSSMNoFV_GM2Calc.sh | 5 +++-- test/test_MSSMNoFVEFTHiggs.sh | 4 ++-- test/test_SM_observable_problems.sh | 2 +- test/test_SplitMSSMEFTHiggs.sh | 2 ++ test/test_cCMSSM.sh | 2 +- test/test_flexiblesusy-config.sh | 2 +- test/test_run_all_spectrum_generators.sh | 2 +- test/test_run_examples.sh | 4 ++-- utils/slha_sort_blocks.sh | 2 +- 12 files changed, 25 insertions(+), 19 deletions(-) diff --git a/config/mathematica_include_paths.sh b/config/mathematica_include_paths.sh index d33fe8b6da..47e7f94ba7 100755 --- a/config/mathematica_include_paths.sh +++ b/config/mathematica_include_paths.sh @@ -7,10 +7,11 @@ math_cmd=math find_math_dirs() { - eval eval `printf "%s" ' + # shellcheck disable=SC2046 + eval eval $(printf "%s" ' Print["sysid=\"", $SystemID, "\""]; Print["topdir=\"", $TopDirectory, "\""]; - Exit[]' | "${math_cmd}" -noprompt | tr '\r' ' ' | tail -2` + Exit[]' | "${math_cmd}" -noprompt | tr '\r' ' ' | tail -2) # check whether Cygwin's dlltool can handle 64-bit DLLs test "$sysid" = Windows-x86-64 && { diff --git a/configure b/configure index b5b9d877a4..d3b30cfbb7 100755 --- a/configure +++ b/configure @@ -700,8 +700,9 @@ split_version() { local minor_var="$3" local patch_var="$4" + # shellcheck disable=SC2046 set -- $(printf "%s" "$version" | - sed 's/^\([[:digit:].]*\).*$/\1/' | tr . ' ') + sed 's/^\([[:digit:].]*\).*$/\1/' | tr . ' ') eval "$major_var=\"${1:-0}\"" eval "$minor_var=\"${2:-0}\"" eval "$patch_var=\"${3:-0}\"" @@ -3684,7 +3685,7 @@ if test $# -gt 0 ; then case $1 in --enable-*) f=$(echo "$1" | sed -e 's/--//' -e 's/-/_/g') - eval prev='$'$(echo "${f}") + eval prev='$'"$(echo "${f}")" # shellcheck disable=SC2154 if test "x${prev}" = "xyes"; then echo "INFO: $1: already enabled by default." @@ -3709,7 +3710,7 @@ if test $# -gt 0 ; then ;; --disable-*) f=$(echo "$1" | sed -e 's/--disable/enable/' -e 's/-/_/g') - eval prev='$'$(echo "${f}") + eval prev='$'"$(echo "${f}")" if test "x${prev}" = "xno"; then echo "INFO: $1: already disabled by default." fi diff --git a/createmodel b/createmodel index e2b02a990a..99570c118d 100755 --- a/createmodel +++ b/createmodel @@ -218,7 +218,7 @@ check_model_name() { local _model="$1" - if [ -z $(echo "${_model}" | grep -E "^[a-zA-Z][0-9a-zA-Z_]*$") ]; then + if [ -z "$(echo "${_model}" | grep -E "^[a-zA-Z][0-9a-zA-Z_]*$")" ]; then printf "Error: invalid model name ${_model}. " if [ -n "$(echo "${_model}" | grep -E -o "^[0-9]")" ]; then printf "Model name must start with a letter. " @@ -388,7 +388,7 @@ if test $# -gt 0 ; then case $1 in --enable-*) f=`echo $1 | sed -e 's/--//' -e 's/-/_/g'` - eval prev='$'`echo ${f}` + eval prev='$'"$(echo "${f}")" # shellcheck disable=SC2154 if test "x${prev}" = "xyes"; then message "INFO: $1: already enabled by default." @@ -413,7 +413,7 @@ if test $# -gt 0 ; then ;; --disable-*) f=`echo $1 | sed -e 's/--disable/enable/' -e 's/-/_/g'` - eval prev='$'`echo ${f}` + eval prev='$'"$(echo "${f}")" if test "x${prev}" = "xno"; then message "INFO: $1: already disabled by default." fi @@ -505,6 +505,7 @@ if test ! -d "$targetdir" ; then message "done" fi +# shellcheck disable=SC2046 set -- $(find -L $model_file_dir -type f -iname LesHouches.in\* -not -iname \*~ -exec basename {} \; | tr '\n' ' ') SLHA_input_files="$*" diff --git a/test/test_CMSSMNoFV_GM2Calc.sh b/test/test_CMSSMNoFV_GM2Calc.sh index 05775be617..9945f565bb 100755 --- a/test/test_CMSSMNoFV_GM2Calc.sh +++ b/test/test_CMSSMNoFV_GM2Calc.sh @@ -9,6 +9,7 @@ SLHA_OUT="${BASEDIR}/test_CMSSMNoFV_GM2Calc.out.spc" print_block="$BASEDIR/../utils/print_slha_block.awk" if [ -e GM2Calc.pc ] ; then + # shellcheck disable=SC2046 eval $(grep '^prefix=' GM2Calc.pc) # shellcheck disable=SC2154 GM2CALC_EXE="${prefix}/bin/gm2calc.x" @@ -20,12 +21,12 @@ if [ ! -x "${GM2CALC_EXE}" ] ; then exit fi -[ $("$FSCONFIG" --with-CMSSMNoFV) = yes -a -x ${CMSSMNoFV_EXE} ] || { +[ "$("$FSCONFIG" --with-CMSSMNoFV)" = yes -a -x "${CMSSMNoFV_EXE}" ] || { echo "Error: CMSSMNoFV needs to be build!" exit 1; } -[ $("$FSCONFIG" --enable-gm2calc) = yes ] || { +[ "$("$FSCONFIG" --enable-gm2calc)" = yes ] || { echo "Error: FlexibleSUSY must be configured with GM2Calc!" exit 1; } diff --git a/test/test_MSSMNoFVEFTHiggs.sh b/test/test_MSSMNoFVEFTHiggs.sh index 11aa6850f6..aba1be00cb 100755 --- a/test/test_MSSMNoFVEFTHiggs.sh +++ b/test/test_MSSMNoFVEFTHiggs.sh @@ -172,7 +172,7 @@ Block AEIN 3 3 ${Ab} # Ad(3,3) " - echo $(run_sg "$SG" "$slha_input" "MASS-25") + echo "$(run_sg "$SG" "$slha_input" "MASS-25")" } run_MSSMNoFVEFTHiggs() { @@ -217,7 +217,7 @@ Block EXTPAR 49 ${MS} " - echo $(run_sg "$SG" "$slha_input" "MASS-25") + echo "$(run_sg "$SG" "$slha_input" "MASS-25")" } scan() { diff --git a/test/test_SM_observable_problems.sh b/test/test_SM_observable_problems.sh index ec99e34389..2facbf5b47 100755 --- a/test/test_SM_observable_problems.sh +++ b/test/test_SM_observable_problems.sh @@ -8,7 +8,7 @@ SLHA_IN="${BASEDIR}/../models/SM/LesHouches.in.SM" SLHA_OUT="${BASEDIR}/test_SM_observable_problems.out.spc" print_block="$BASEDIR/../utils/print_slha_block.awk" -[ $("$FSCONFIG" --with-SM) = yes -a -x ${SM_EXE} ] || { +[ "$("$FSCONFIG" --with-SM)" = yes -a -x ${SM_EXE} ] || { echo "Error: SM needs to be build!" exit 1; } diff --git a/test/test_SplitMSSMEFTHiggs.sh b/test/test_SplitMSSMEFTHiggs.sh index 90bce57e84..780c5d0477 100755 --- a/test/test_SplitMSSMEFTHiggs.sh +++ b/test/test_SplitMSSMEFTHiggs.sh @@ -187,12 +187,14 @@ error=0 # check equality of lambdas in full theory and EFT at matching scale +# shellcheck disable=SC2046 set -- $(run_sg "$MODELDIR/SplitMSSMEFTHiggs/run_SplitMSSMEFTHiggs.x" 0) CHECK_EQUAL_FRACTION "$1" "$2" "0.0001" || error=$(expr $error + 1) # check approximate equality of lambdas in full theory and EFT at matching scale # this would fail if difference between vev normalizations # in full theory and SM were ignored, see commit e5473865150da98e1426f2282baf31d54541169a +# shellcheck disable=SC2046 set -- $(run_sg "$MODELDIR/SplitMSSMEFTHiggs/run_SplitMSSMEFTHiggs.x" 1) CHECK_EQUAL_FRACTION "$1" "$2" "0.03" || error=$(expr $error + 1) diff --git a/test/test_cCMSSM.sh b/test/test_cCMSSM.sh index 6723068bf8..eca2622b3d 100755 --- a/test/test_cCMSSM.sh +++ b/test/test_cCMSSM.sh @@ -57,7 +57,7 @@ apply_abs() { # convert scientific notation to bc friendly input bc_friendly=$(echo "${entry}" | $sed_cmd -e 's/[eE]/\*10\^/' | $sed_cmd -e 's/\^+/\^/') # apply abs - printf "%s " $(echo "scale=15; abs(${bc_friendly})" | bc $BASEDIR/abs.bc) + printf "%s " "$(echo "scale=15; abs(${bc_friendly})" | bc "${BASEDIR}/abs.bc")" done printf "\n" continue ;; diff --git a/test/test_flexiblesusy-config.sh b/test/test_flexiblesusy-config.sh index f488579044..f5fb0027e1 100755 --- a/test/test_flexiblesusy-config.sh +++ b/test/test_flexiblesusy-config.sh @@ -26,7 +26,7 @@ for m in ${MODELS} ; do source="${BASEDIR}/../models/${m}" dest="${BASEDIR}/${m}" - [ $("$FSCONFIG" --with-${m}) = no ] && { echo "Warning: ${m} is not configured" ; continue; } + [ "$("$FSCONFIG" --with-${m})" = no ] && { echo "Warning: ${m} is not configured" ; continue; } echo "> copying ${source} -> ${dest}" diff --git a/test/test_run_all_spectrum_generators.sh b/test/test_run_all_spectrum_generators.sh index f88b3821ce..f0ce1f3db1 100755 --- a/test/test_run_all_spectrum_generators.sh +++ b/test/test_run_all_spectrum_generators.sh @@ -140,7 +140,7 @@ do echo "== $model ====================================" - if [ $("$FSCONFIG" --with-${model}) = no ] ; then + if [ "$("$FSCONFIG" --with-${model})" = no ] ; then echo "> skipping, because the model is not configured" continue fi diff --git a/test/test_run_examples.sh b/test/test_run_examples.sh index a02e15d2d4..adfed55db4 100755 --- a/test/test_run_examples.sh +++ b/test/test_run_examples.sh @@ -9,9 +9,9 @@ FSCONFIG="$BASEDIR/../flexiblesusy-config" program_dirs="" -[ $("$FSCONFIG" --with-CMSSM) = yes ] && +[ "$("$FSCONFIG" --with-CMSSM)" = yes ] && program_dirs="$program_dirs customized-betas" -[ $("$FSCONFIG" --with-MSSMD5O) = yes -a $("$FSCONFIG" --with-MSSMRHN) = yes ] && +[ "$("$FSCONFIG" --with-MSSMD5O)" = yes -a "$("$FSCONFIG" --with-MSSMRHN)" = yes ] && program_dirs="$program_dirs tower" exit_code=0 diff --git a/utils/slha_sort_blocks.sh b/utils/slha_sort_blocks.sh index 3b79efa26b..03bda4d2e3 100755 --- a/utils/slha_sort_blocks.sh +++ b/utils/slha_sort_blocks.sh @@ -15,5 +15,5 @@ input=$(cat ${input}) blocks=$(echo "${input}" | awk '{ if (tolower($1) ~ "block") print $2 }' | sort) for block in ${blocks} ; do - echo "${input}" | awk -f $(dirname $0)/print_slha_block.awk -v block="${block}" -v omit_comments=1 + echo "${input}" | awk -f "$(dirname "$0")/print_slha_block.awk" -v block="${block}" -v omit_comments=1 done From d5b49c1d5959caf094a36617131b6cbb14b001a6 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Sun, 14 Nov 2021 21:44:59 +0100 Subject: [PATCH 077/477] Fix: SC2166: Prefer [ p ] || [ q ] as [ p -o q ] is not well defined. --- configure | 44 +++++++++++++++++------------ test/test_CMSSMNoFV_GM2Calc.sh | 2 +- test/test_SM_observable_problems.sh | 2 +- test/test_SplitMSSMEFTHiggs.sh | 2 +- test/test_run_examples.sh | 2 +- utils/slha_sort_blocks.sh | 2 +- 6 files changed, 31 insertions(+), 23 deletions(-) diff --git a/configure b/configure index d3b30cfbb7..1fad1e87a6 100755 --- a/configure +++ b/configure @@ -777,7 +777,7 @@ try_compile_run_cpp_program() { # output through stdout and stderr is stored in cpp_output # and whose exit code is stored in cpp_exit. - if [ $# -lt 1 -o $# -gt 3 ]; then + if [ $# -lt 1 ] || [ $# -gt 3 ]; then echo "try_compile_run_cpp_program: 1, 2, or 3 arguments required!" exit 1 fi @@ -1617,7 +1617,7 @@ check_icpc_features() { # disable multi-threading for versions < 14.0.0 if ! major_minor_patch_at_least $major $minor $patch "14" "0" "0" && - [ "$enable_threads" = "yes" -o "$enable_threads" = "automatic" ]; then + { [ "$enable_threads" = "yes" ] || [ "$enable_threads" = "automatic" ] ;} ; then message "" message " Warning: multi-threading support requires $compiler 14.0.0 or newer." enable_threads="no" @@ -1770,7 +1770,7 @@ check_cxxflags() { fi fi - if [ "x$enable_shared_libs" = "xyes" -o "x$enable_librarylink" = "xyes" ] ; then + if [ "x$enable_shared_libs" = "xyes" ] || [ "x$enable_librarylink" = "xyes" ] ; then # check if -fPIC is in CXXFLAGS case "${CXX}" in g++*|clang++*|icpc*) @@ -1945,7 +1945,7 @@ check_fflags() { esac # check if -fPIC is in FFLAGS - if [ "x$enable_shared_libs" = "xyes" -o "x$enable_librarylink" = "xyes" ] ; then + if [ "x$enable_shared_libs" = "xyes" ] || [ "x$enable_librarylink" = "xyes" ] ; then case "${FC}" in gfortran*|ifort*) if contains_not "${FFLAGS}" "-fPIC" ; then @@ -2227,7 +2227,7 @@ check_himalaya() { #_____________________________________________________________________ check_required_libs() { - if [ "$enable_meta" = yes -a -n "${MATH}" ] ; then + if [ "$enable_meta" = yes ] && [ -n "${MATH}" ] ; then message "Checking model files for required third party libraries" for m in ${MODELS}; do @@ -2750,8 +2750,10 @@ check_math_cmd() { exists_in_path "$MATH" if [ -z "$cmd" ] ; then result "not found" - MATH="" - [ "${enable_meta}" = "yes" -o "$enable_librarylink" = "yes" ] || return + MATH="" + if [ ! "${enable_meta}" = "yes" ] || [ ! "$enable_librarylink" = "yes" ]; then + return + fi message "Error: Mathematica needs to be installed to run the meta code or to enable LibraryLink!" message " You can use the --with-math-cmd= option to specify the location of" @@ -2804,13 +2806,15 @@ EOF if $_ok; then result "ok (version ${MATH_VERSION} for ${MATH_SYSTEMID} in ${MATH_INSTDIR})" else - if [ "$_exit_status" = 2 ]; then - result "not ok (version ${MATH_VERSION} for ${MATH_SYSTEMID} in ${MATH_INSTDIR})" - else - result "not ok" - fi - MATH="" - [ "${enable_meta}" = "yes" -o "$enable_librarylink" = "yes" ] || return + if [ "$_exit_status" = 2 ]; then + result "not ok (version ${MATH_VERSION} for ${MATH_SYSTEMID} in ${MATH_INSTDIR})" + else + result "not ok" + fi + MATH="" + if [ ! "${enable_meta}" = "yes" ] || [ ! "$enable_librarylink" = "yes" ]; then + return + fi message "Error: Mathematica ${required_mathematica_version} or higher needs to be installed!" exit 1 @@ -2878,7 +2882,8 @@ WriteString["stderr", \$sarahModelDir]; EOF ) - [ -z "$SARAH_MODEL_DIR" -o \( ! -z "$SARAH_MODEL_DIR" -a ! -d "$SARAH_MODEL_DIR" \) ] && { + if [ -z "$SARAH_MODEL_DIR" ] || \ + { [ ! -z "$SARAH_MODEL_DIR" ] && [ ! -d "$SARAH_MODEL_DIR" ] ;} ;then message "Error: Could not determine the SARAH model directory." message " Please check that Mathematica and SARAH are installed correctly." message " To do that, you may run \`${MATH}' and then copy and paste:\n" @@ -2888,7 +2893,7 @@ If[Needs[\"SARAH\`\"] === \$Failed, Print[\"SARAH successfully loaded.\"]; Quit[0] ];" exit 1 - } + fi } #_____________________________________________________________________ @@ -3213,7 +3218,9 @@ update_module_mk() { update_model_makefiles() { # If Mathematica is disabled, dependences on model-specific # modules should have been already resolved. - [ "$enable_meta" != yes -o -z "${MATH}" ] && return + if [ "$enable_meta" != yes ] || [ -z "${MATH}" ]; then + return + fi message "Checking model makefiles" @@ -3784,7 +3791,8 @@ check_install_dir # check for Mathematica if meta code generation is enabled or we # compile with LibraryLink -if [ "$enable_meta" = yes -o \( "$enable_compile" = yes -a "$enable_librarylink" != no \) ]; then +if [ "$enable_meta" = yes ] || \ + { [ "$enable_compile" = yes ] && [ "$enable_librarylink" != no ] ;} ; then check_math_cmd check_mathematica_info else diff --git a/test/test_CMSSMNoFV_GM2Calc.sh b/test/test_CMSSMNoFV_GM2Calc.sh index 9945f565bb..01e13a9311 100755 --- a/test/test_CMSSMNoFV_GM2Calc.sh +++ b/test/test_CMSSMNoFV_GM2Calc.sh @@ -21,7 +21,7 @@ if [ ! -x "${GM2CALC_EXE}" ] ; then exit fi -[ "$("$FSCONFIG" --with-CMSSMNoFV)" = yes -a -x "${CMSSMNoFV_EXE}" ] || { +[ "$("$FSCONFIG" --with-CMSSMNoFV)" = yes ] && [ -x "${CMSSMNoFV_EXE}" ] || { echo "Error: CMSSMNoFV needs to be build!" exit 1; } diff --git a/test/test_SM_observable_problems.sh b/test/test_SM_observable_problems.sh index 2facbf5b47..e11051f842 100755 --- a/test/test_SM_observable_problems.sh +++ b/test/test_SM_observable_problems.sh @@ -8,7 +8,7 @@ SLHA_IN="${BASEDIR}/../models/SM/LesHouches.in.SM" SLHA_OUT="${BASEDIR}/test_SM_observable_problems.out.spc" print_block="$BASEDIR/../utils/print_slha_block.awk" -[ "$("$FSCONFIG" --with-SM)" = yes -a -x ${SM_EXE} ] || { +[ "$("$FSCONFIG" --with-SM)" = yes ] && [ -x "${SM_EXE}" ] || { echo "Error: SM needs to be build!" exit 1; } diff --git a/test/test_SplitMSSMEFTHiggs.sh b/test/test_SplitMSSMEFTHiggs.sh index 780c5d0477..156f04f996 100755 --- a/test/test_SplitMSSMEFTHiggs.sh +++ b/test/test_SplitMSSMEFTHiggs.sh @@ -175,7 +175,7 @@ EOF awk -v block="SMSM" "$print_slha_block_awk" | awk -v keys="2" "$print_block_entry_awk" | tail -n 1) - if [ -z "$lambdaFull" -o -z "$lambdaEFT" ]; then + if [ -z "$lambdaFull" ] || [ -z "$lambdaEFT" ]; then lambdaFull=0 lambdaEFT=1 fi diff --git a/test/test_run_examples.sh b/test/test_run_examples.sh index adfed55db4..1153e2e0f1 100755 --- a/test/test_run_examples.sh +++ b/test/test_run_examples.sh @@ -11,7 +11,7 @@ program_dirs="" [ "$("$FSCONFIG" --with-CMSSM)" = yes ] && program_dirs="$program_dirs customized-betas" -[ "$("$FSCONFIG" --with-MSSMD5O)" = yes -a "$("$FSCONFIG" --with-MSSMRHN)" = yes ] && +[ "$("$FSCONFIG" --with-MSSMD5O)" = yes ] && [ "$("$FSCONFIG" --with-MSSMRHN)" = yes ] && program_dirs="$program_dirs tower" exit_code=0 diff --git a/utils/slha_sort_blocks.sh b/utils/slha_sort_blocks.sh index 03bda4d2e3..d4362e1582 100755 --- a/utils/slha_sort_blocks.sh +++ b/utils/slha_sort_blocks.sh @@ -8,7 +8,7 @@ # # cat input.slha | slha_sort_blocks.sh -[ $# -ge 1 -a -f "$1" ] && input="$1" || input="-" +[ $# -ge 1 ] && [ -f "$1" ] && input="$1" || input="-" input=$(cat ${input}) From ea58ba999eb0e4cc3f44b2fa2c498d34546b5541 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sun, 14 Nov 2021 21:57:16 +0100 Subject: [PATCH 078/477] updated CI image --- .github/workflows/tests.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a836d73756..9732347cfd 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -123,9 +123,9 @@ jobs: # forks FS github doesn't try to run tests on their code. if: (!github.event.pull_request && github.repository == 'FlexibleSUSY/FlexibleSUSY') || github.event.pull_request.head.repo.url == 'https://api.github.com/repos/FlexibleSUSY/FlexibleSUSY' - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest container: - image: navir/opensuseleap-for-flexiblesusy:0.9.7 + image: navir/opensuseleap-for-flexiblesusy:0.10.0 strategy: matrix: From 98d752847a3ef380c0d9345b5766ce0252cd23d4 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Sun, 14 Nov 2021 22:23:03 +0100 Subject: [PATCH 079/477] Fix: SC2034: ___ appears unused. Verify use (or export if used externally). --- configure | 34 ++++++++++--------- createaddon | 4 --- createmodel | 17 +--------- install-sarah | 6 ---- test/test_CMSSMCKM_spectrum.sh | 2 -- test/test_CMSSMNoFV_profile.sh | 1 - test/test_CMSSM_memory_leaks.sh | 1 - test/test_CMSSM_profile.sh | 1 - test/test_MSSMEFTHiggs_profile.sh | 1 - test/test_NMSSM_profile.sh | 1 - test/test_SMSemiAnalytic_spectrum.sh | 4 --- test/test_SSMSemiAnalytic_spectrum.sh | 4 --- ...est_THDMIIEWSBAtMZSemiAnalytic_spectrum.sh | 4 --- test/test_munuSSMSemiAnalytic_spectrum.sh | 4 --- utils/scan-database.sh | 1 + 15 files changed, 20 insertions(+), 65 deletions(-) diff --git a/configure b/configure index 1fad1e87a6..fc6ca67bda 100755 --- a/configure +++ b/configure @@ -886,7 +886,11 @@ is_empty_dir() { return 1 fi - find "$1" -maxdepth 0 -empty | read v + if [ -n "$(ls -A "$1")" ]; then + return 1 + else + return 0 + fi } #_____________________________________________________________________ @@ -2683,29 +2687,27 @@ find_symbol_using_pkgconfig() { local symbol pkg ldpaths libnames pkg_flags pkg_flags=$([ "x$enable_static" = xyes ] && echo "--static") pkg="$1" - linker_flags="" type pkg-config > /dev/null 2>&1 || { - logmsg "pkg-config not found" - return 1 + logmsg "pkg-config not found" + return 1 } pkg-config --exists "$pkg" || { - logmsg "pkg-config does not manage $pkg" - return 1 + logmsg "pkg-config does not manage $pkg" + return 1 } ldpaths=$(pkg-config ${pkg_flags} --libs-only-L "$pkg") libnames=$(pkg-config ${pkg_flags} --libs-only-l "$pkg") shift for symbol; do - for dopt in $default_lib_paths $ldpaths; do - for lopt in $libnames; do - if check_symbol "$symbol" "$lopt" "$dopt"; then - logmsg "found $symbol in $dopt $lopt" - linker_flags=$(pkg-config ${pkg_flags} --libs "$pkg") - continue 3 - fi - done - done - return 1 + for dopt in $default_lib_paths $ldpaths; do + for lopt in $libnames; do + if check_symbol "$symbol" "$lopt" "$dopt"; then + logmsg "found $symbol in $dopt $lopt" + continue 3 + fi + done + done + return 1 done return 0 } diff --git a/createaddon b/createaddon index d0941363bc..a8ce3d8103 100755 --- a/createaddon +++ b/createaddon @@ -3,9 +3,6 @@ # addon creation script for FlexibleSUSY # Author: Alexander Voigt -# directory of this script -BASEDIR=$(dirname $0) - overwrite="no" name="" @@ -13,7 +10,6 @@ name="" exit_ok="0" exit_syntax_error="1" exit_addon_dir_exists="2" -exit_no_default_addon="3" #_____________________________________________________________________ help() { diff --git a/createmodel b/createmodel index 99570c118d..010ae8f263 100755 --- a/createmodel +++ b/createmodel @@ -6,22 +6,6 @@ # directory of this script BASEDIR=$(dirname $0) -# absolute path to this script -ABSBASEDIR=$(cd $BASEDIR && pwd) - -# operating system -operating_system="`(uname -s) 2>/dev/null || echo unknown`" - -# determine Mathematica user directory -case "$operating_system" in - Darwin) mathematica_dir="${HOME}/Library/Mathematica" ;; - CYGWIN_NT*) mathematica_dir="${USERPROFILE}/AppData/Roaming/Mathematica" ;; - # Linux, *BSD - *) mathematica_dir="${HOME}/.Mathematica" ;; -esac - -mathematica_applications_dir="${mathematica_dir}/Applications" -sarah_default_dir="${mathematica_applications_dir}/SARAH" flexiblesusy_sarah_dir="${BASEDIR}/sarah" mathematica_kernel="math" @@ -179,6 +163,7 @@ is_executable () { return 1 fi + # shellcheck disable=SC2034 cmd=$(command -v -- "$1") } diff --git a/install-sarah b/install-sarah index 8990b45e80..8236df13f4 100755 --- a/install-sarah +++ b/install-sarah @@ -3,12 +3,6 @@ # SARAH installation script # Author: Alexander Voigt -# directory of this script -BASEDIR=$(dirname $0) - -# absolute path to this script -ABSBASEDIR=$(cd $BASEDIR && pwd) - # operating system operating_system="`(uname -s) 2>/dev/null || echo unknown`" diff --git a/test/test_CMSSMCKM_spectrum.sh b/test/test_CMSSMCKM_spectrum.sh index ecebc3454a..c1a722f781 100755 --- a/test/test_CMSSMCKM_spectrum.sh +++ b/test/test_CMSSMCKM_spectrum.sh @@ -3,8 +3,6 @@ BASEDIR=$(dirname $0) UTILSDIR=${BASEDIR}/../utils print_block="$UTILSDIR/print_slha_block.awk" -print_block_entry="$UTILSDIR/print_slha_block_entry.awk" -remove_block="$UTILSDIR/remove_slha_block.awk" slha_in="$BASEDIR/test_CMSSMCKM_spectrum.spc.in" FS_out="$BASEDIR/test_CMSSMCKM_spectrum.spc.out.FS" diff --git a/test/test_CMSSMNoFV_profile.sh b/test/test_CMSSMNoFV_profile.sh index 0466b0d3b5..4c3d600e21 100755 --- a/test/test_CMSSMNoFV_profile.sh +++ b/test/test_CMSSMNoFV_profile.sh @@ -3,7 +3,6 @@ # directory of this script BASEDIR=$(dirname $0) -FSCONFIG="$BASEDIR/../flexiblesusy-config" VALGRIND="`command -v valgrind`" CMSSMNoFV_EXE="$BASEDIR/../models/CMSSMNoFV/run_CMSSMNoFV.x" CMSSMNoFV_INPUT="$BASEDIR/../model_files/CMSSMNoFV/LesHouches.in.CMSSMNoFV" diff --git a/test/test_CMSSM_memory_leaks.sh b/test/test_CMSSM_memory_leaks.sh index 11b258fb22..657a1a1517 100755 --- a/test/test_CMSSM_memory_leaks.sh +++ b/test/test_CMSSM_memory_leaks.sh @@ -3,7 +3,6 @@ # directory of this script BASEDIR=$(dirname $0) -FSCONFIG="$BASEDIR/../flexiblesusy-config" VALGRIND="`command -v valgrind`" CMSSM_EXE="$BASEDIR/../models/CMSSM/run_CMSSM.x" CMSSM_INPUT="$BASEDIR/../model_files/CMSSM/LesHouches.in.CMSSM" diff --git a/test/test_CMSSM_profile.sh b/test/test_CMSSM_profile.sh index 249400f6dc..7638ecb2f5 100755 --- a/test/test_CMSSM_profile.sh +++ b/test/test_CMSSM_profile.sh @@ -3,7 +3,6 @@ # directory of this script BASEDIR=$(dirname $0) -FSCONFIG="$BASEDIR/../flexiblesusy-config" VALGRIND="`command -v valgrind`" CMSSM_EXE="$BASEDIR/../models/CMSSM/run_CMSSM.x" CMSSM_INPUT="$BASEDIR/../model_files/CMSSM/LesHouches.in.CMSSM" diff --git a/test/test_MSSMEFTHiggs_profile.sh b/test/test_MSSMEFTHiggs_profile.sh index ba0404a83f..4db98319c0 100755 --- a/test/test_MSSMEFTHiggs_profile.sh +++ b/test/test_MSSMEFTHiggs_profile.sh @@ -3,7 +3,6 @@ # directory of this script BASEDIR=$(dirname $0) -FSCONFIG="$BASEDIR/../flexiblesusy-config" VALGRIND="`command -v valgrind`" MSSMEFTHiggs_EXE="$BASEDIR/../models/MSSMEFTHiggs/run_MSSMEFTHiggs.x" MSSMEFTHiggs_INPUT="$BASEDIR/../model_files/MSSMEFTHiggs/LesHouches.in.MSSMEFTHiggs" diff --git a/test/test_NMSSM_profile.sh b/test/test_NMSSM_profile.sh index c34a21847c..4c689549e7 100755 --- a/test/test_NMSSM_profile.sh +++ b/test/test_NMSSM_profile.sh @@ -3,7 +3,6 @@ # directory of this script BASEDIR=$(dirname $0) -FSCONFIG="$BASEDIR/../flexiblesusy-config" VALGRIND="`command -v valgrind`" NMSSM_EXE="$BASEDIR/../models/NMSSM/run_NMSSM.x" NMSSM_INPUT="$BASEDIR/../model_files/NMSSM/LesHouches.in.NMSSM" diff --git a/test/test_SMSemiAnalytic_spectrum.sh b/test/test_SMSemiAnalytic_spectrum.sh index 807a51c9e7..92f7fe54d3 100755 --- a/test/test_SMSemiAnalytic_spectrum.sh +++ b/test/test_SMSemiAnalytic_spectrum.sh @@ -5,10 +5,6 @@ # the same. BASEDIR=$(dirname $0) -UTILSDIR=${BASEDIR}/../utils -print_block="$UTILSDIR/print_slha_block.awk" -print_block_entry="$UTILSDIR/print_slha_block_entry.awk" -remove_block="$UTILSDIR/remove_slha_block.awk" semi_analytic_model="SMSemiAnalytic" two_scale_model="SM" diff --git a/test/test_SSMSemiAnalytic_spectrum.sh b/test/test_SSMSemiAnalytic_spectrum.sh index 16641e1eeb..b1f3b139b9 100755 --- a/test/test_SSMSemiAnalytic_spectrum.sh +++ b/test/test_SSMSemiAnalytic_spectrum.sh @@ -5,10 +5,6 @@ # the same. BASEDIR=$(dirname $0) -UTILSDIR=${BASEDIR}/../utils -print_block="$UTILSDIR/print_slha_block.awk" -print_block_entry="$UTILSDIR/print_slha_block_entry.awk" -remove_block="$UTILSDIR/remove_slha_block.awk" semi_analytic_model="SSMSemiAnalytic" two_scale_model="SSM" diff --git a/test/test_THDMIIEWSBAtMZSemiAnalytic_spectrum.sh b/test/test_THDMIIEWSBAtMZSemiAnalytic_spectrum.sh index 1ad5d36b29..b0b2265839 100755 --- a/test/test_THDMIIEWSBAtMZSemiAnalytic_spectrum.sh +++ b/test/test_THDMIIEWSBAtMZSemiAnalytic_spectrum.sh @@ -5,10 +5,6 @@ # the same. BASEDIR=$(dirname $0) -UTILSDIR=${BASEDIR}/../utils -print_block="$UTILSDIR/print_slha_block.awk" -print_block_entry="$UTILSDIR/print_slha_block_entry.awk" -remove_block="$UTILSDIR/remove_slha_block.awk" semi_analytic_model="THDMIIEWSBAtMZSemiAnalytic" two_scale_model="THDMII" diff --git a/test/test_munuSSMSemiAnalytic_spectrum.sh b/test/test_munuSSMSemiAnalytic_spectrum.sh index 0819785c89..460932cfcb 100755 --- a/test/test_munuSSMSemiAnalytic_spectrum.sh +++ b/test/test_munuSSMSemiAnalytic_spectrum.sh @@ -5,10 +5,6 @@ # the same. BASEDIR=$(dirname $0) -UTILSDIR=${BASEDIR}/../utils -print_block="$UTILSDIR/print_slha_block.awk" -print_block_entry="$UTILSDIR/print_slha_block_entry.awk" -remove_block="$UTILSDIR/remove_slha_block.awk" semi_analytic_model="munuSSMSemiAnalytic" two_scale_model="munuSSM" diff --git a/utils/scan-database.sh b/utils/scan-database.sh index d08c5721bf..c932d1a79e 100755 --- a/utils/scan-database.sh +++ b/utils/scan-database.sh @@ -149,6 +149,7 @@ EOF esac # run the spectrum generator + # shellcheck disable=SC2034 slha_output=$( { echo "$slha_input" ; \ cat < Date: Sun, 14 Nov 2021 22:39:13 +0100 Subject: [PATCH 080/477] Fix: SC2115: Use \"${var:?}\" to ensure this never expands to / . --- test/test_run_examples.sh | 4 ++-- test/test_standalone.sh | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/test_run_examples.sh b/test/test_run_examples.sh index 1153e2e0f1..208ad0abc5 100755 --- a/test/test_run_examples.sh +++ b/test/test_run_examples.sh @@ -19,7 +19,7 @@ exit_code=0 for dir in ${program_dirs} do echo "> cleaning: rm -rf ${BASEDIR}/${dir}" - rm -rf ${BASEDIR}/${dir} + rm -rf ${BASEDIR:?}/${dir} echo "> copying: cp -r ${examples_dir}/${dir}/ ${BASEDIR}" cp -r ${examples_dir}/${dir}/ ${BASEDIR} @@ -61,7 +61,7 @@ do fi echo "> cleaning: rm -rf ${BASEDIR}/${dir}" - rm -rf ${BASEDIR}/${dir}/ + rm -rf ${BASEDIR:?}/${dir}/ done exit ${exit_code} diff --git a/test/test_standalone.sh b/test/test_standalone.sh index 45dfd85baa..06a299b937 100755 --- a/test/test_standalone.sh +++ b/test/test_standalone.sh @@ -10,7 +10,7 @@ standalone_dirs="standalone-model standalone-rge" for dir in ${standalone_dirs} do echo "> cleaning: rm -rf ${BASEDIR}/${dir}" - rm -rf ${BASEDIR}/${dir} + rm -rf ${BASEDIR:?}/${dir} echo "> copying: cp -r ${examples_dir}/${dir}/ ${BASEDIR}" cp -r ${examples_dir}/${dir}/ ${BASEDIR} @@ -34,7 +34,7 @@ do fi echo "> cleaning: rm -rf ${BASEDIR}/${dir}" - rm -rf ${BASEDIR}/${dir}/ + rm -rf ${BASEDIR:?}/${dir}/ done exit ${exit_code} From 3c5d434cabf5dedfd4075491d8f6c42194e79894 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Sun, 14 Nov 2021 22:46:59 +0100 Subject: [PATCH 081/477] Fix: SC2154: remove_block is referenced but not assigned. --- test/test_SMSemiAnalytic_spectrum.sh | 2 ++ test/test_SSMSemiAnalytic_spectrum.sh | 2 ++ test/test_THDMIIEWSBAtMZSemiAnalytic_spectrum.sh | 2 ++ test/test_munuSSMSemiAnalytic_spectrum.sh | 2 ++ 4 files changed, 8 insertions(+) diff --git a/test/test_SMSemiAnalytic_spectrum.sh b/test/test_SMSemiAnalytic_spectrum.sh index 92f7fe54d3..5c6f832c29 100755 --- a/test/test_SMSemiAnalytic_spectrum.sh +++ b/test/test_SMSemiAnalytic_spectrum.sh @@ -5,6 +5,8 @@ # the same. BASEDIR=$(dirname $0) +UTILSDIR=${BASEDIR}/../utils +remove_block="$UTILSDIR/remove_slha_block.awk" semi_analytic_model="SMSemiAnalytic" two_scale_model="SM" diff --git a/test/test_SSMSemiAnalytic_spectrum.sh b/test/test_SSMSemiAnalytic_spectrum.sh index b1f3b139b9..b09ca55147 100755 --- a/test/test_SSMSemiAnalytic_spectrum.sh +++ b/test/test_SSMSemiAnalytic_spectrum.sh @@ -5,6 +5,8 @@ # the same. BASEDIR=$(dirname $0) +UTILSDIR=${BASEDIR}/../utils +remove_block="$UTILSDIR/remove_slha_block.awk" semi_analytic_model="SSMSemiAnalytic" two_scale_model="SSM" diff --git a/test/test_THDMIIEWSBAtMZSemiAnalytic_spectrum.sh b/test/test_THDMIIEWSBAtMZSemiAnalytic_spectrum.sh index b0b2265839..1f23ca19ff 100755 --- a/test/test_THDMIIEWSBAtMZSemiAnalytic_spectrum.sh +++ b/test/test_THDMIIEWSBAtMZSemiAnalytic_spectrum.sh @@ -5,6 +5,8 @@ # the same. BASEDIR=$(dirname $0) +UTILSDIR=${BASEDIR}/../utils +remove_block="$UTILSDIR/remove_slha_block.awk" semi_analytic_model="THDMIIEWSBAtMZSemiAnalytic" two_scale_model="THDMII" diff --git a/test/test_munuSSMSemiAnalytic_spectrum.sh b/test/test_munuSSMSemiAnalytic_spectrum.sh index 460932cfcb..03c250d07d 100755 --- a/test/test_munuSSMSemiAnalytic_spectrum.sh +++ b/test/test_munuSSMSemiAnalytic_spectrum.sh @@ -5,6 +5,8 @@ # the same. BASEDIR=$(dirname $0) +UTILSDIR=${BASEDIR}/../utils +remove_block="$UTILSDIR/remove_slha_block.awk" semi_analytic_model="munuSSMSemiAnalytic" two_scale_model="munuSSM" From 3b9ba2299f8373b06101162247989ece9263eeb4 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Sun, 14 Nov 2021 22:51:52 +0100 Subject: [PATCH 082/477] Fix: SC2091: Remove surrounding $() to avoid executing output. --- configure | 1 + 1 file changed, 1 insertion(+) diff --git a/configure b/configure index fc6ca67bda..6eacd6bd47 100755 --- a/configure +++ b/configure @@ -1344,6 +1344,7 @@ check_multiarch() { if test "x$linuxdist" = "xmultiarch"; then if type dpkg-architecture > /dev/null 2>&1 ; then + # shellcheck disable=SC2091 if $(dpkg-architecture -qDEB_HOST_MULTIARCH > /dev/null 2>&1) ; then checking_msg "dpkg-architecture" debmultiarch=$(dpkg-architecture -qDEB_HOST_MULTIARCH 2> /dev/null) From 997d508cb73b35e298336c35f9799862026c484e Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Sun, 14 Nov 2021 22:59:16 +0100 Subject: [PATCH 083/477] Fix: SC1090: Cannot follow non-constant source. Use a directive to specify location. --- test/test_MSSMEFTHiggs.sh | 1 + test/test_MSSMEFTHiggs_librarylink.sh | 1 + test/test_MSSMNoFVEFTHiggs.sh | 1 + test/test_NMSSMEFTHiggs.sh | 89 ++++++++++++++------------- test/test_NUHMSSMaltEFTHiggs.sh | 1 + test/test_SMEFTHiggs.sh | 1 + test/test_SplitMSSMEFTHiggs.sh | 1 + 7 files changed, 51 insertions(+), 44 deletions(-) diff --git a/test/test_MSSMEFTHiggs.sh b/test/test_MSSMEFTHiggs.sh index 77da1a5c00..594f175481 100755 --- a/test/test_MSSMEFTHiggs.sh +++ b/test/test_MSSMEFTHiggs.sh @@ -13,6 +13,7 @@ Xt=0 output="MASS-25" scan_data="$BASEDIR/test_MSSMEFTHiggs.dat" +# shellcheck source=test.sh . "$BASEDIR/test.sh" # prints SLHA block diff --git a/test/test_MSSMEFTHiggs_librarylink.sh b/test/test_MSSMEFTHiggs_librarylink.sh index 7d707fac94..88d1b7c433 100755 --- a/test/test_MSSMEFTHiggs_librarylink.sh +++ b/test/test_MSSMEFTHiggs_librarylink.sh @@ -5,6 +5,7 @@ UTILSDIR=${BASEDIR}/../utils MODELSDIR=${BASEDIR}/../models MATH=${MATH_CMD:-math} +# shellcheck source=test.sh . "$BASEDIR/test.sh" slha_input=" diff --git a/test/test_MSSMNoFVEFTHiggs.sh b/test/test_MSSMNoFVEFTHiggs.sh index aba1be00cb..9b3b9ed50d 100755 --- a/test/test_MSSMNoFVEFTHiggs.sh +++ b/test/test_MSSMNoFVEFTHiggs.sh @@ -8,6 +8,7 @@ TB=5 Xt=0 Xb=0 +# shellcheck source=test.sh . "$BASEDIR/test.sh" # prints SLHA block diff --git a/test/test_NMSSMEFTHiggs.sh b/test/test_NMSSMEFTHiggs.sh index f4fa02098e..e46798c143 100755 --- a/test/test_NMSSMEFTHiggs.sh +++ b/test/test_NMSSMEFTHiggs.sh @@ -3,6 +3,7 @@ BASEDIR=$(dirname $0) MODELDIR=${BASEDIR}/../models +# shellcheck source=test.sh . "$BASEDIR/test.sh" # prints SLHA block @@ -81,50 +82,50 @@ Block FlexibleSUSY 28 1 # Higgs 3-loop corrections O(alpha_t^2 alpha_s) 29 1 # Higgs 3-loop corrections O(alpha_t^3) 30 1 # Higgs 4-loop corrections O(alpha_t alpha_s^3) -BLOCK SMINPUTS # -1 128.962 # -2 0.000011663900000000002 # -3 0.1172 # -4 91.1876 # -5 4.2 # -6 172.9 # -7 1.777 # -9 80.385 # -11 0.00051099891 # -13 1.10565836 # -21 0.00495 # -22 0.0025 # -23 0.1 # -24 1.42 # -BLOCK EXTPAR # -0 1000. # -1 200. # -2 400. # -3 2000. # -11 1000. # -12 1000. # -13 1000. # -25 3. # -31 1500. # -32 1500. # -33 1500. # -34 1500. # -35 1500. # -36 1500. # -41 1500. # -42 1500. # -43 1000. # -44 1500. # -45 1500. # -46 1000. # -47 1500. # -48 1500. # -49 1500. # -61 0.67 # -62 0.1 # -63 650. # -64 -10. # -65 200. # +BLOCK SMINPUTS # +1 128.962 # +2 0.000011663900000000002 # +3 0.1172 # +4 91.1876 # +5 4.2 # +6 172.9 # +7 1.777 # +9 80.385 # +11 0.00051099891 # +13 1.10565836 # +21 0.00495 # +22 0.0025 # +23 0.1 # +24 1.42 # +BLOCK EXTPAR # +0 1000. # +1 200. # +2 400. # +3 2000. # +11 1000. # +12 1000. # +13 1000. # +25 3. # +31 1500. # +32 1500. # +33 1500. # +34 1500. # +35 1500. # +36 1500. # +41 1500. # +42 1500. # +43 1000. # +44 1500. # +45 1500. # +46 1000. # +47 1500. # +48 1500. # +49 1500. # +61 0.67 # +62 0.1 # +63 650. # +64 -10. # +65 200. # " input_NMSSMEFTHiggs=" diff --git a/test/test_NUHMSSMaltEFTHiggs.sh b/test/test_NUHMSSMaltEFTHiggs.sh index c6fde6acc4..11e766b0fe 100755 --- a/test/test_NUHMSSMaltEFTHiggs.sh +++ b/test/test_NUHMSSMaltEFTHiggs.sh @@ -3,6 +3,7 @@ BASEDIR=$(dirname $0) MODELDIR=${BASEDIR}/../models +# shellcheck source=test.sh . "$BASEDIR/test.sh" # prints SLHA block diff --git a/test/test_SMEFTHiggs.sh b/test/test_SMEFTHiggs.sh index 519c89f1bf..05849cee57 100755 --- a/test/test_SMEFTHiggs.sh +++ b/test/test_SMEFTHiggs.sh @@ -3,6 +3,7 @@ BASEDIR=$(dirname $0) MODELDIR=${BASEDIR}/../models +# shellcheck source=test.sh . "$BASEDIR/test.sh" # prints SLHA block diff --git a/test/test_SplitMSSMEFTHiggs.sh b/test/test_SplitMSSMEFTHiggs.sh index 156f04f996..a931153c9f 100755 --- a/test/test_SplitMSSMEFTHiggs.sh +++ b/test/test_SplitMSSMEFTHiggs.sh @@ -3,6 +3,7 @@ BASEDIR="$(dirname $0)" MODELDIR="${BASEDIR}/../models" +# shellcheck source=test.sh . "$BASEDIR/test.sh" # prints SLHA block From fabb12520be1a7170dc37c1f9b6c9945a45b9e2a Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Mon, 15 Nov 2021 09:28:00 +0100 Subject: [PATCH 084/477] Fix: SC2065: This is interpreted as a shell file redirection, not a comparison. --- utils/scan-slha.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/scan-slha.sh b/utils/scan-slha.sh index bb800840b2..778a36d7fd 100755 --- a/utils/scan-slha.sh +++ b/utils/scan-slha.sh @@ -130,10 +130,10 @@ Examples: --output=MINPAR[3],MASS[25],Yu[3:3] \\ > scan-slha.dat - $ echo "set xlabel \"tan(beta)\"; + $ echo "set xlabel \"tan(beta)\"; set ylabel \"mh / GeV\"; plot 'scan-slha.dat' u 1:2 w linespoints" \\ - | gnuplot -p + | gnuplot -p EOF } @@ -334,7 +334,7 @@ EOF if test "$check_present" -eq 1 ; then # check if entry exists # if entry exists, set value=1, otherwise set value=0 - test -z "$value" > /dev/null + [ -z "${value}" ] value=$? fi From 8e8afff7d583c62eed85463949f5b1bdd2e8fa99 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Mon, 15 Nov 2021 10:09:07 +0100 Subject: [PATCH 085/477] Warning for a weird Lorentz index combination. --- meta/FlexibleSUSY.m | 1 + meta/Wrappers.m | 50 +++++++++++++++++++++++++++++++++++++++++++++ meta/module.mk | 1 + 3 files changed, 52 insertions(+) create mode 100644 meta/Wrappers.m diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index e40fb7159c..6d018fbc80 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -60,6 +60,7 @@ "FSMathLink`", "FlexibleTower`", "WeinbergAngle`", + "Wrappers`", "Himalaya`" }]; diff --git a/meta/Wrappers.m b/meta/Wrappers.m new file mode 100644 index 0000000000..f99e316d95 --- /dev/null +++ b/meta/Wrappers.m @@ -0,0 +1,50 @@ +(* :Copyright: + + ==================================================================== + This file is part of FlexibleSUSY. + + FlexibleSUSY 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. + + FlexibleSUSY 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 FlexibleSUSY. If not, see + . + ==================================================================== + +*) + +Needs["Utils`"]; +Needs["TreeMasses`"]; + +BeginPackage["Wrappers`"]; +Begin["`Private`"]; + +Module[{status = True, res}, + SARAH`Vertex[fields:{Repeated[_?TreeMasses`IsVector, {4}]}, + opts___]/; status := + Module[{naked}, + status = False; + res = SARAH`Vertex[fields, opts]; + naked = Sort@Cases[First@res, {___, lt_}:> lt, Infinity]; + If[Not@MatchQ[naked, {SARAH`lt1, SARAH`lt2, SARAH`lt3, SARAH`lt4}], + Utils`FSFancyWarning["Input fields are "<>ToString@fields<> + ". It leads to the combination of Lorentz indices in the vertex "<> + ToString@First@res<>", which is not equal to {lt1, lt2, lt3, lt4}"<> + " up to a permutation. Most likely, it will give an incorrect form"<> + " of the vertex. Please, cross-check the input!" + ]; + ]; + status = True; + res + ]; +]; + +End[]; +Block[{$ContextPath}, EndPackage[]]; diff --git a/meta/module.mk b/meta/module.mk index ca6abfca05..ec3b233b87 100644 --- a/meta/module.mk +++ b/meta/module.mk @@ -114,6 +114,7 @@ META_SRC := \ $(DIR)/Utils.m \ $(DIR)/Vertices.m \ $(DIR)/WeinbergAngle.m \ + $(DIR)/Wrappers.m \ $(DIR)/WriteOut.m \ $(DIR)/writeRGE.m \ $(DIR)/writeNRGE.m \ From 2b5375487c01aeca7f7610be1405707532497458 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Mon, 15 Nov 2021 13:48:44 +0100 Subject: [PATCH 086/477] added static analysis badge in README --- README.rst | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 9e33a15349..ee0bae0426 100644 --- a/README.rst +++ b/README.rst @@ -4,11 +4,13 @@ FlexibleSUSY ============ -|release| |tests| +|release| |static-analysis| |tests| .. |release| image:: https://img.shields.io/github/v/release/FlexibleSUSY/FlexibleSUSY +.. |static-analysis| image:: https://github.com/FlexibleSUSY/FlexibleSUSY/workflows/static%20analysis/badge.svg?branch=development + :target: https://github.com/FlexibleSUSY/FlexibleSUSY/actions/workflows/static-analysis.yml .. |tests| image:: https://github.com/FlexibleSUSY/FlexibleSUSY/workflows/tests/badge.svg?branch=development - :target: https://github.com/FlexibleSUSY/FlexibleSUSY/actions + :target: https://github.com/FlexibleSUSY/FlexibleSUSY/actions/workflows/tests.yml .. image:: doc/images/FS-logo.png :align: right From fe589949674f5366acd812b14762cf3852ff2394 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Mon, 15 Nov 2021 20:58:53 +0100 Subject: [PATCH 087/477] A test added. Message was changed. Output stream for warnings and errors is changed. --- meta/Utils.m | 6 ++--- meta/Wrappers.m | 13 ++++----- test/module.mk | 2 ++ test/test_SM_vvvv.m | 66 +++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+), 9 deletions(-) create mode 100644 test/test_SM_vvvv.m diff --git a/meta/Utils.m b/meta/Utils.m index f15ece9206..b02fc987a1 100644 --- a/meta/Utils.m +++ b/meta/Utils.m @@ -390,7 +390,7 @@ occurrence of the given rule is replaced (if it exists) or added (if RedString[str_] := str; ]; - WriteOut[str__] := WriteString["stdout"~OutputStream~1,StringJoin@str]; + WriteOut[str__] := WriteString[$Output, StringJoin@str]; MultilineToDummy[args___] := Sequence@@(StringReplace[ToString@#,"\n"->"dummy_n"]&/@{args}); replacedMessage = StringReplace[sym~MessageName~tag,"\n"->"dummy_n"]; @@ -429,7 +429,7 @@ occurrence of the given rule is replaced (if it exists) or added (if chopped = InsertLinebreaks[StringReplace[string, "\n"-> " "], len-9]; chopped = StringReplace[chopped, "\n"-> "\n "]; If[!$Notebooks, - WriteString["stdout", warning <> chopped <> "\n"];, + WriteString[$Output, warning <> chopped <> "\n"];, Print[warning, chopped]; ]; ]; @@ -461,7 +461,7 @@ occurrence of the given rule is replaced (if it exists) or added (if TextFormatting`WrapLines[#,70,""]&,#&], WriteOut,WriteColourless,Filter }, - WriteOut[string__] := WriteString[OutputStream["stdout",1],StringJoin@string]; + WriteOut[string__] := WriteString[$Output, StringJoin@string]; WriteColourless[string__] := WriteOut@CutString@StringJoin@string; Filter[ System`Dump`str_, diff --git a/meta/Wrappers.m b/meta/Wrappers.m index f99e316d95..53eea7b335 100644 --- a/meta/Wrappers.m +++ b/meta/Wrappers.m @@ -26,6 +26,12 @@ BeginPackage["Wrappers`"]; Begin["`Private`"]; +warnVVVV[fields:{_, _, _, _}, vertex:{__}] := + "Input fields "<> ToString@fields<> " lead to the following combination "<> + "of Lorentz indices in the vertex "<> ToString@First@vertex<> ". "<> + "They should be equal to {lt1, lt2, lt3, lt4} up to any permutation! "<> + "Most likely the vertex is wrong. Please, cross-check the input!"; + Module[{status = True, res}, SARAH`Vertex[fields:{Repeated[_?TreeMasses`IsVector, {4}]}, opts___]/; status := @@ -34,12 +40,7 @@ res = SARAH`Vertex[fields, opts]; naked = Sort@Cases[First@res, {___, lt_}:> lt, Infinity]; If[Not@MatchQ[naked, {SARAH`lt1, SARAH`lt2, SARAH`lt3, SARAH`lt4}], - Utils`FSFancyWarning["Input fields are "<>ToString@fields<> - ". It leads to the combination of Lorentz indices in the vertex "<> - ToString@First@res<>", which is not equal to {lt1, lt2, lt3, lt4}"<> - " up to a permutation. Most likely, it will give an incorrect form"<> - " of the vertex. Please, cross-check the input!" - ]; + Utils`FSFancyWarning@warnVVVV[fields, res]; ]; status = True; res diff --git a/test/module.mk b/test/module.mk index 7a958cddc3..8dd0902086 100644 --- a/test/module.mk +++ b/test/module.mk @@ -530,6 +530,8 @@ TEST_SH += \ endif ifeq ($(WITH_SM),yes) +TEST_META += \ + $(DIR)/test_SM_vvvv.m TEST_SRC += \ $(DIR)/test_SM_beta_functions.cpp \ $(DIR)/test_SM_gmm2.cpp \ diff --git a/test/test_SM_vvvv.m b/test/test_SM_vvvv.m new file mode 100644 index 0000000000..b6c498ee2e --- /dev/null +++ b/test/test_SM_vvvv.m @@ -0,0 +1,66 @@ +(* :Copyright: + + ==================================================================== + This file is part of FlexibleSUSY. + + FlexibleSUSY 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. + + FlexibleSUSY 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 FlexibleSUSY. If not, see + . + ==================================================================== + +*) + +Needs["TestSuite`", "TestSuite.m"]; +Block[{Print}, (* We do not test SARAH, so let us reduce output. *) + Needs["SARAH`"]; + Start@"SM"; +]; + +FlexibleSUSY`FSEnableColors = False; (* Desired by Utils`FSFancyWarning *) +FlexibleSUSY`FSEigenstates = EWSB; (* Required by TreeMasses`Private`IsOfType *) +Needs["Wrappers`", "Wrappers.m"]; + +check[fields:{_, _, _, _}] := Module[{lhs, rhs, vertex, stream, out}, + Print["\ncheck"]; + out = $Output; + stream = OpenWrite[]; + $Output = {stream}; + vertex = Vertex@fields; + lhs = ReadString[stream[[1]]]; + $Output = out; + Close[stream]; + + stream = OpenWrite[]; + AppendTo[$Output, stream]; + Utils`FSFancyWarning@Wrappers`Private`warnVVVV[fields, vertex]; + rhs = ReadString[stream[[1]]]; + $Output = Most[$Output]; + Close[stream]; + {lhs, rhs} +]; + +Utils`FSFancyLine[]; +Print["Wrong input"]; +TestEquality@@ check@{conj[VWp[{lt1}]], VZ[{lt2}], VWp[{lt3}], VZ[{1}]}; +TestEquality@@ check@{conj[VWp[{lt1}]], VZ[{lt2}], VWp[{lt3}], VZ[{"oops"}]}; +TestEquality@@ check@{conj[VWp[{lt1}]], VZ[{lt1}], VWp[{lt3}], VZ}; +TestEquality@@ check@{conj[VWp], VZ[{lt1}], VWp[{lt3}], VZ}; + +Utils`FSFancyLine[]; +Print["Correct but weird input"]; +TestEquality[First@check@{conj[VWp[{lt1}]], VZ[{lt2}], VWp[{lt3}], VZ}, + EndOfFile]; +TestEquality[First@check@{conj[VWp[{lt2}]], VZ[{lt1}], VWp[{lt3}], VZ}, + EndOfFile]; + +PrintTestSummary[]; From 0c271c21ac2933c87bb5fbbdb83c04fad0d4f394 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Tue, 16 Nov 2021 18:05:36 +0100 Subject: [PATCH 088/477] 'Fix': SC2039: In POSIX sh, 'local' is undefined. --- .github/workflows/static-analysis.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 3367aa589c..6df43cc93b 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -33,4 +33,6 @@ jobs: uses: actions/checkout@v2 - name: Check scripts - run: shellcheck -S error configure createmodel install-sarah createaddon config/*.sh utils/*.sh test/test_*.sh + run: | + echo "We assume, that shell understands 'local' command!" + shellcheck -e SC2039 -S warning configure createmodel install-sarah createaddon config/*.sh utils/*.sh test/test_*.sh From 3d0d0f763f6d31614ac3cce4905513f15098deb8 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Tue, 16 Nov 2021 22:17:02 +0100 Subject: [PATCH 089/477] removed some unused variables (#391) --- meta/Decays.m | 12 ++++++------ meta/FlexibleSUSY.m | 18 ++++++++---------- 2 files changed, 14 insertions(+), 16 deletions(-) diff --git a/meta/Decays.m b/meta/Decays.m index 652cf20331..96dd88a9bf 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -766,7 +766,7 @@ would violate Ward identity (as at the level of dim 4 If[numIndices == 0 || dim <= 1, result = result <> " {};\n";, result = result <> " {{" <> ToString[indexVal] <> - StringJoin[Table[", 0", {i, 1, numIndices - 1}]] <> "}};\n"; + StringJoin[ConstantArray[", 0", numIndices - 1]] <> "}};\n"; ]; result ]; @@ -1554,7 +1554,7 @@ would violate Ward identity (as at the level of dim 4 @todo: There is an ambiguity whether Field[n] -> somefield or Field[n] -> AntiField[somefield] *) GetFieldsAssociations[concreteFieldOnEdgeBetweenVertices_, fieldNumberOnEdgeBetweenVertices_, fieldTypes_, diagram_, verticesInFieldTypesForFACp_] := - Module[{temp = {}, concreteFieldOnEdgeBetweenVerticesLocal, verticesForFACp, temp2}, + Module[{temp = {}, concreteFieldOnEdgeBetweenVerticesLocal}, concreteFieldOnEdgeBetweenVerticesLocal = concreteFieldOnEdgeBetweenVertices; temp = SortBy[Reverse /@ fieldNumberOnEdgeBetweenVertices, Last]; @@ -1624,7 +1624,7 @@ would violate Ward identity (as at the level of dim 4 externalEdges, matchExternalFieldIndicesCode, matchInternalFieldIndicesCode = "", functionBody = "", verticesInFieldTypesForFACp, verticesForFACp, colorFac = "colorFac", symmetryFac = "symmetryFac", FinitePart = False, - whereToConj, verticesForFACp2, + verticesForFACp2, (* colour triplet fermions *) quarkLike = Select[GetColoredParticles[], IsFermion[#] && (GetColorRepresentation[#] == T || GetColorRepresentation[#] == -T) &] }, @@ -1809,7 +1809,7 @@ would violate Ward identity (as at the level of dim 4 "auto temp_result = " <> ampCall <> ";\n" <> "if (static_cast(flexibledecay_settings.get(FlexibleDecay_settings::include_higher_order_corrections)) > 0 &&\n" <> TextFormatting`IndentText[ - Module[{pos1, post2, res}, + Module[{pos1, pos2}, StringJoin@Riffle[ MapIndexed[ (pos1 = Position[#1, First@fieldsInLoop, 1]; @@ -1834,7 +1834,7 @@ would violate Ward identity (as at the level of dim 4 If[!SA`CPViolationHiggsSector && Length[fieldsInLoop] === 1 && And@@Join[TreeMasses`IsScalar /@ fieldsInLoop, TreeMasses`ColorChargedQ /@ fieldsInLoop], "\nif (static_cast(flexibledecay_settings.get(FlexibleDecay_settings::include_higher_order_corrections)) > 0 &&\n" <> TextFormatting`IndentText[ - Module[{pos1, post2, res}, + Module[{pos1, pos2}, StringJoin@Riffle[ MapIndexed[ (pos1 = Position[#1, First@fieldsInLoop, 1]; @@ -1874,7 +1874,7 @@ would violate Ward identity (as at the level of dim 4 "auto temp_result = " <> ampCall <> ";\n" <> "if (static_cast(flexibledecay_settings.get(FlexibleDecay_settings::include_higher_order_corrections)) > 0 &&\n" <> TextFormatting`IndentText[ - Module[{pos1, post2, res}, + Module[{pos1, pos2}, StringJoin@Riffle[ MapIndexed[ (pos1 = Position[#1, First@fieldsInLoop, 1]; diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index 6d018fbc80..39091c22d0 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -1226,7 +1226,7 @@ FlexibleSUSY model file (FlexibleSUSY.m). ]; FindVEV[gauge_] := - Module[{result, vev}, + Module[{vev}, vev = Cases[SARAH`DEFINITION[FlexibleSUSY`FSEigenstates][SARAH`VEVs], {_,{v_,_},{gauge,_},{p_,_},___} | {_,{v_,_},{s_,_},{gauge,_},___} :> v]; If[vev === {}, @@ -1238,7 +1238,7 @@ FlexibleSUSY model file (FlexibleSUSY.m). (* returns VEV normalization w.r.t. the corresponding gauge eigenstate *) FindVEVNormalization[gauge_] := - Module[{result, vev}, + Module[{vev}, vev = Cases[SARAH`DEFINITION[FlexibleSUSY`FSEigenstates][SARAH`VEVs], {_,{v_,n_},{gauge,m_},{p_,_},___} | {_,{v_,n_},{s_,_},{gauge,m_},___} :> Abs[n/m]]; If[vev === {}, @@ -1608,7 +1608,6 @@ corresponding tadpole is real or imaginary (only in models with CP slhaPoleMassGetters = "", slhaPoleMixingMatrixGetters = "", higgsMassGetters = "", higgsToEWSBEqAssociation, tadpoleEqPrototypes = "", tadpoleEqFunctions = "", - numberOfEWSBEquations = Length[ewsbEquations], calculateTreeLevelTadpoles = "", divideTadpoleByVEV = "", calculateOneLoopTadpoles = "", calculateTwoLoopTadpoles = "", physicalMassesDef = "", mixingMatricesDef = "", @@ -2212,8 +2211,7 @@ corresponding tadpole is real or imaginary (only in models with CP WriteObservables[extraSLHAOutputBlocks_, files_List] := Module[{requestedObservables, numberOfObservables, observablesDef, observablesInit, getObservables, getObservablesNames, - clearObservables, setObservables, calculateObservables, - loopCouplingsPrototypes, loopCouplingsFunctions}, + clearObservables, setObservables, calculateObservables}, requestedObservables = Observables`GetRequestedObservables[extraSLHAOutputBlocks]; numberOfObservables = Observables`CountNumberOfObservables[requestedObservables]; observablesDef = Observables`CreateObservablesDefinitions[requestedObservables]; @@ -2547,7 +2545,7 @@ corresponding tadpole is real or imaginary (only in models with CP ]; RunEnabledSpectrumGenerator[solver_] := - Module[{key = "", class = "", macro = "", body = "", result = ""}, + Module[{key = "", class = "", body = "", result = ""}, key = GetBVPSolverSLHAOptionKey[solver]; class = GetBVPSolverTemplateParameter[solver]; body = "exit_code = run_solver<" <> class <> ">(\n" @@ -2562,7 +2560,7 @@ corresponding tadpole is real or imaginary (only in models with CP ]; ScanEnabledSpectrumGenerator[solver_] := - Module[{key = "", class = "", macro = "", body = "", result = ""}, + Module[{key = "", class = "", body = "", result = ""}, key = GetBVPSolverSLHAOptionKey[solver]; class = GetBVPSolverTemplateParameter[solver]; body = "result = run_parameter_point<" <> class <> ">(loop_library, qedqcd, input);\n" @@ -2572,7 +2570,7 @@ corresponding tadpole is real or imaginary (only in models with CP ]; RunCmdLineEnabledSpectrumGenerator[solver_] := - Module[{key = "", class = "", macro = "", body = "", result = ""}, + Module[{key = "", class = "", body = "", result = ""}, key = GetBVPSolverSLHAOptionKey[solver]; class = GetBVPSolverTemplateParameter[solver]; body = "exit_code = run_solver<" <> class <> ">(loop_library,input);\n" @@ -4063,7 +4061,7 @@ corresponding tadpole is real or imaginary (only in models with CP }; MakeFlexibleSUSY[OptionsPattern[]] := - Module[{nPointFunctions, runInputFile, initialGuesserInputFile, + Module[{nPointFunctions, initialGuesserInputFile, aMuonVertices, edmVertices, edmFields, QToQGammaFields = {}, LToLGammaFields = {}, LToLConversionFields = {}, FFMasslessVVertices = {}, conversionVertices = {}, @@ -4085,7 +4083,7 @@ corresponding tadpole is real or imaginary (only in models with CP extraSLHAOutputBlocks, deltaVBwave, deltaVBvertex, deltaVBbox, vertexRules, vertexRuleFileName, - Lat$massMatrices, spectrumGeneratorFiles = {}, spectrumGeneratorInputFile, + Lat$massMatrices, spectrumGeneratorInputFile, semiAnalyticBCs, semiAnalyticSolns, semiAnalyticHighScaleFiles, semiAnalyticSUSYScaleFiles, semiAnalyticLowScaleFiles, semiAnalyticSolnsOutputFile, semiAnalyticEWSBSubstitutions = {}, semiAnalyticInputScale = "", From 0919750fb74001484f81bc5a7d0b208e8aef0200 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Tue, 16 Nov 2021 22:17:52 +0100 Subject: [PATCH 090/477] script for static analysis of mathematica code --- utils/static_analysis.wl | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 utils/static_analysis.wl diff --git a/utils/static_analysis.wl b/utils/static_analysis.wl new file mode 100644 index 0000000000..94f7b970d0 --- /dev/null +++ b/utils/static_analysis.wl @@ -0,0 +1,21 @@ +files = + DeleteCases[ + If[!FileExistsQ[#], Print["Argument ", #, " is not a file name"], #]& /@ DeleteDuplicates@Drop[$ScriptCommandLine, 1], + Null + ]; + +If[files === {}, + Print["Error: No files specified"]; + Print["Usage: wolframscript -f static_analysis.wl FILE(S)"]; + Quit[1]; +]; + +Needs["CodeInspector`"]; + +(WriteString[$Output, #]; Print[];) &/@ + Map[ + CodeInspectSummarize[File[#], SeverityExclusions -> {}]&, + files + ]; + +Quit[0]; From 466a4aeedbf1c355d3195aca8b3a2e9532cd7ad9 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Wed, 17 Nov 2021 18:13:32 +0100 Subject: [PATCH 091/477] Replace most 'Warning:' messages by FSFancyWarning. --- meta/BtoSGamma.m | 6 +- meta/Constraint.m | 23 ++++--- meta/EWSB.m | 56 ++++++++++------- meta/FFVFormFactors.m | 18 +++--- meta/FlexibleSUSY.m | 120 +++++++++++++++++++++++------------- meta/LoopMasses.m | 30 +++++---- meta/NPointFunctions.m | 6 +- meta/Observables.m | 43 ++++++------- meta/Parameters.m | 60 +++++++++++------- meta/ThresholdCorrections.m | 2 +- meta/Utils.m | 15 +++-- meta/WeinbergAngle.m | 17 ++--- meta/WriteOut.m | 40 +++++++----- 13 files changed, 265 insertions(+), 171 deletions(-) diff --git a/meta/BtoSGamma.m b/meta/BtoSGamma.m index cee508670a..9efbe0fa7d 100644 --- a/meta/BtoSGamma.m +++ b/meta/BtoSGamma.m @@ -73,8 +73,10 @@ ""] <> "const auto mW = context.mass<" <> CXXDiagrams`CXXNameOfField[TreeMasses`GetWBoson[]] <> ">(" <> If[TreeMasses`GetDimension[TreeMasses`GetWBoson[]] =!= 1, - Print["Warning: b->s gamma module does not work reliable with multiple W bosons.\n" <> - "We assume the first element is SM W boson"]; + Utils`FSFancyWarning[ + "b->s gamma module does not work reliable with multiple W bosons.", + " We assume the first element is SM W boson" + ]; "{0}", "{}"] <> ");\n" <> "constexpr bool discard_SM_contribution = true;\n" <> diff --git a/meta/Constraint.m b/meta/Constraint.m index 7b51eb1a6f..7e06db4537 100644 --- a/meta/Constraint.m +++ b/meta/Constraint.m @@ -396,10 +396,13 @@ If[isInitial, modelPars = Parameters`FSModelParameters /. Parameters`FindAllParametersClassified[value]; If[Intersection[modelPars, Parameters`GetModelParameters[]] =!= {}, - Print["Warning: In constraint ", constraintName, ": ", InputForm[patt]]; - Print[" ", modelPars, " on the r.h.s. are model parameters, which may initially be zero!"]; - ]; - ]; + Utils`FSFancyWarning[ + "In constraint ", constraintName, ": ", InputForm[patt], + " ", ToString@modelPars, + " on the r.h.s. are model parameters, which may initially be zero!" + ]; + ]; + ]; True ]; @@ -436,12 +439,12 @@ For[y = 1, y <= Length[yukawas], y++, If[(ValueQ /@ yukawas)[[y]] && FreeQ[setParameters, yukawas[[y]]], - Print["Warning: Yukawa coupling ", yukawas[[y]], - " not set", - If[constraintName != "", " in the " <> constraintName, ""], - "."]; - ]; - ]; + Utils`FSFancyWarning[ + "Yukawa coupling ", yukawas[[y]], + " not set"<> If[constraintName != ""," in the " <> constraintName, ""] + ]; + ]; + ]; ]; CalculateScale[Null, _] := ""; diff --git a/meta/EWSB.m b/meta/EWSB.m index 934800edac..a91f6690a4 100644 --- a/meta/EWSB.m +++ b/meta/EWSB.m @@ -184,17 +184,21 @@ type = CConversion`ScalarType[CConversion`realScalarCType]; ctype = CConversion`CreateCType[type]; If[dim < dimEq, - Print["Warning: number of Higgs bosons (", dim, - ") < number of EWSB eqs. (",dimEq,")." - "The EWSB eqs. ", dim, "...", dimEq, - " will be ignored"]; - ]; + Utils`FSFancyWarning[ + "Number of Higgs bosons (", dim, + ") < number of EWSB eqs. (", dimEq, ").", + " The EWSB eqs. ", dim, "...", dimEq, + " will be ignored" + ]; + ]; If[dim > dimEq, - Print["Warning: number of physical Higgs bosons (", dim, - ") > number of EWSB eqs. (",dimEq,").", - "The EWSB eqs. for the fields ", higgs, "(n), n >= ", - dimEq, ", will be set to zero."]; - ]; + Utils`FSFancyWarning[ + "Number of physical Higgs bosons (", dim, + ") > number of EWSB eqs. (", dimEq, ").", + " The EWSB eqs. for the fields ", higgs, + "(n), n >= ", dimEq, ", will be set to zero." + ]; + ]; For[i = 1, i <= dim, i++, result = result <> ctype <> " CLASSNAME::get_ewsb_eq_" <> @@ -249,9 +253,11 @@ Module[{i}, For[i = 1, i <= Length[initialGuess], i++, If[!MatchQ[initialGuess[[i]], {_,_}], - Print["Warning: ignoring invalid initial guess: ", initialGuess[[i]]]; - ]; - ]; + Utils`FSFancyWarning[ + "Ignoring invalid initial guess: ", initialGuess[[i]] + ]; + ]; + ]; Cases[initialGuess, {_,_}] ]; @@ -259,9 +265,11 @@ Module[{i}, For[i = 1, i <= Length[substitutions], i++, If[!MatchQ[substitutions[[i]], {_,_}], - Print["Warning: ignoring invalid EWSB substitution: ", substitutions[[i]]]; - ]; - ]; + Utils`FSFancyWarning[ + "Ignoring invalid EWSB substitution: ", substitutions[[i]] + ]; + ]; + ]; Cases[substitutions, {_,_}] ]; @@ -271,10 +279,12 @@ If[Parameters`IsRealParameter[par], guess = par, guess = Abs[par]];, guess = Cases[initialGuesses, {p_ /; p === par, val_} :> val]; If[Length[guess] > 1, - Print["Warning: multiple initial guesses given for ", par]; - ]; + Utils`FSFancyWarning[ + "Multiple initial guesses given for ", par + ]; + ]; guess = First[guess]; - ]; + ]; guess ]; @@ -663,8 +673,10 @@ Return[{sol1}]; ]; If[!PossibleZeroQ[sol1[[2]] + sol2[[2]]], - Print["Warning: cannot reduce solution for ", par]; - Print[" because the two solutions are not related by a global sign."]; + Utils`FSFancyWarning[ + "Cannot reduce solution for ", par, + " because the two solutions are not related by a global sign." + ]; Return[{}]; ]; DebugPrint["The two solutions for ", par, @@ -692,7 +704,7 @@ ]; ]; If[Length[reducedSolution] != Length[sol1], - Print["Warning: analytic reduction of EWSB solutions failed."]; + Utils`FSFancyWarning["Analytic reduction of EWSB solutions failed."]; Return[{{},{}}]; ]; Return[{reducedSolution, freePhases}]; diff --git a/meta/FFVFormFactors.m b/meta/FFVFormFactors.m index efbcd729db..a1aed37a4a 100644 --- a/meta/FFVFormFactors.m +++ b/meta/FFVFormFactors.m @@ -34,7 +34,7 @@ why such a weird numbering? because some procedure uses this order for fermion number flow."; FFVContributingDiagramsForGraph::usage = ""; -IsDiagramSupported::usage = "For the input FFV graph, determines whether +IsDiagramSupported::usage = "For the input FFV graph, determines whether the input diagram is valid, by checking whether the internal structure is supported and the emitting fields can in fact emit the vector." IsChargedUnder::usage="Returns whether or not a field is charged under a given vectors gauge"; @@ -89,21 +89,23 @@ Return[True] ]; - Utils`FSFancyWarning["Diagram with internal particles of type " <> - StringJoin @@ (ToString /@ SARAH`getType /@ {EmitterL[diagram], EmitterR[diagram], Spectator[diagram]})]; - Print[" is currently not supported."]; - Print[" Discarding diagram with particles ", - {EmitterL[diagram], EmitterR[diagram], Spectator[diagram]}, "."]; + Utils`FSFancyWarning[ + "Diagram with internal particles of type ", + StringJoin[ToString/@ SARAH`getType/@ {EmitterL[diagram], EmitterR[diagram], Spectator[diagram]}], + " is currently not supported. Discarding diagram with particles ", + ToString@{EmitterL[diagram], EmitterR[diagram], Spectator[diagram]}, + "." + ]; Return[False]; ]; -IsChargedUnder[field_, vector_?IsVector] := +IsChargedUnder[field_, vector_?IsVector] := Which[(*Check 2 special cases first which are quicker*) TreeMasses`IsPhoton[vector], TreeMasses`IsElectricallyCharged[field], TreeMasses`IsGluon[vector], TreeMasses`ColorChargedQ[field], (*Else check that this field coupled with its anti-field can emit this vector*) (*Note this will not work for vectors that couple to two different fields, e.g. W-bosons*) - True, SARAH`Vertex[{SARAH`AntiField[field], field, + True, SARAH`Vertex[{SARAH`AntiField[field], field, vector}, UseDependences -> True][[2, 1]] =!= 0 ] diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index 39091c22d0..2bf42be39e 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -463,8 +463,12 @@ FlexibleSUSY model file (FlexibleSUSY.m). SetAttributes[CheckParticleInPrecision, HoldFirst]; CheckParticleInPrecision[precision_] := If[!SubsetQ[TreeMasses`GetParticles[], precision], - Print["Warning: Particle(s) ", Complement[precision, TreeMasses`GetParticles[]], - " cannot be used in ", Unevaluated@precision, " as it is not part of ", FSModelName, ". Removing it/them."]; + Utils`FSFancyWarning["Particle(s) ", + Complement[precision, TreeMasses`GetParticles[]], + " cannot be used in ", Unevaluated@precision, + " as it is not part of ", ToString@FSModelName, + ". Removing it/them." + ]; precision = Intersection[precision, TreeMasses`GetParticles[]] ]; CheckParticleInPrecision /@ @@ -472,9 +476,11 @@ FlexibleSUSY model file (FlexibleSUSY.m). (* decay calculation require 3- and 4-point loop functions *) If[FlexibleSUSY`FSCalculateDecays && DisjointQ[FSLoopLibraries, {FSLoopTools, FSCOLLIER}], - Print["Warning: Decay calculation requires a dedicated loop library. Currently it's either ", - "LoopTools or Collier but FlexibleSUSY was only configured with internal libraries. ", - "Disabling decays." + Utils`FSFancyWarning[ + "Decay calculation requires a dedicated loop library.", + " Currently it's either LoopTools or Collier but", + " FlexibleSUSY was only configured with internal libraries.", + " Disabling decays." ]; FlexibleSUSY`FSCalculateDecays = False ]; @@ -527,7 +533,11 @@ FlexibleSUSY model file (FlexibleSUSY.m). CheckDecaysOptions[] := If[FlexibleSUSY`FSDecayParticles =!= Automatic && FlexibleSUSY`FSDecayParticles =!= All && !ListQ[FlexibleSUSY`FSDecayParticles], - Print["Warning: Allowed values for FSDecayParticles are Automatic, All or list of particles. Got ", FlexibleSUSY`FSDecayParticles, ". Disabling decays. "]; + Utils`FSFancyWarning[ + "Allowed values for FSDecayParticles are Automatic, All or", + " list of particles. Got ", FlexibleSUSY`FSDecayParticles, + ". Disabling decays." + ]; FlexibleSUSY`FSCalculateDecays = False, If[FlexibleSUSY`FSDecayParticles === Automatic, FlexibleSUSY`FSDecayParticles = @@ -535,8 +545,10 @@ FlexibleSUSY model file (FlexibleSUSY.m). If[FlexibleSUSY`FSDecayParticles === All, FlexibleSUSY`FSDecayParticles = TreeMasses`GetParticles[], If[!SubsetQ[TreeMasses`GetParticles[], FlexibleSUSY`FSDecayParticles], - Print["Warning: Requested decay of particles ", Complement[FlexibleSUSY`FSDecayParticles, TreeMasses`GetParticles[]], - " which are not part of the model. Removing them."]; + Utils`FSFancyWarning[ + "Requested decay of particles ", + Complement[FlexibleSUSY`FSDecayParticles, TreeMasses`GetParticles[]], + " which are not part of the model. Removing them."]; FlexibleSUSY`FSDecayParticles = Intersection[TreeMasses`GetParticles[], FlexibleSUSY`FSDecayParticles] ] ] @@ -553,8 +565,10 @@ FlexibleSUSY model file (FlexibleSUSY.m). Module[{}, (* FlexibleSUSY model name *) If[!ValueQ[FlexibleSUSY`FSModelName] || Head[FlexibleSUSY`FSModelName] =!= String, - Print["Warning: FlexibleSUSY`FSModelName not defined!", - " I'm using Model`Name from SARAH: ", Model`Name]; + Utils`FSFancyWarning[ + "FlexibleSUSY`FSModelName not defined!", + " I'm using Model`Name from SARAH: ", Model`Name + ]; FlexibleSUSY`FSModelName = Model`Name; ]; (* Set OnlyLowEnergyFlexibleSUSY to False by default *) @@ -575,16 +589,18 @@ FlexibleSUSY model file (FlexibleSUSY.m). (* HighScale *) If[!ValueQ[FlexibleSUSY`HighScale], If[!FlexibleSUSY`OnlyLowEnergyFlexibleSUSY, - Print["Warning: FlexibleSUSY`HighScale should be", - " set in the model file!"]; - ]; + Utils`FSFancyWarning[ + "FlexibleSUSY`HighScale should be set in the model file!" + ]; + ]; FlexibleSUSY`HighScale := 2 10^16; ]; If[!ValueQ[FlexibleSUSY`HighScaleFirstGuess], If[!FlexibleSUSY`OnlyLowEnergyFlexibleSUSY, - Print["Warning: FlexibleSUSY`HighScaleFirstGuess should be", - " set in the model file!"]; - ]; + Utils`FSFancyWarning[ + "FlexibleSUSY`HighScaleFirstGuess should be set in the model file!" + ]; + ]; FlexibleSUSY`HighScaleFirstGuess = 2.0 10^16; ]; If[Head[FlexibleSUSY`HighScaleInput] =!= List, @@ -592,13 +608,15 @@ FlexibleSUSY model file (FlexibleSUSY.m). ]; (* LowScale *) If[!ValueQ[FlexibleSUSY`LowScale], - Print["Warning: FlexibleSUSY`LowScale should be", - " set in the model file!"]; + Utils`FSFancyWarning[ + "FlexibleSUSY`LowScale should be set in the model file!" + ]; FlexibleSUSY`LowScale := LowEnergyConstant[MZ]; ]; If[!ValueQ[FlexibleSUSY`LowScaleFirstGuess], - Print["Warning: FlexibleSUSY`LowScaleFirstGuess should be", - " set in the model file!"]; + Utils`FSFancyWarning[ + "FlexibleSUSY`LowScaleFirstGuess should be set in the model file!" + ]; FlexibleSUSY`LowScaleFirstGuess = LowEnergyConstant[MZ]; ]; If[Head[FlexibleSUSY`LowScaleInput] =!= List, @@ -606,13 +624,15 @@ FlexibleSUSY model file (FlexibleSUSY.m). ]; (* SUSYScale *) If[!ValueQ[FlexibleSUSY`SUSYScale], - Print["Warning: FlexibleSUSY`SUSYScale should be", - " set in the model file!"]; + Utils`FSFancyWarning[ + "FlexibleSUSY`SUSYScale should be set in the model file!" + ]; FlexibleSUSY`SUSYScale := 1000; ]; If[!ValueQ[FlexibleSUSY`SUSYScaleFirstGuess], - Print["Warning: FlexibleSUSY`SUSYScaleFirstGuess should be", - " set in the model file!"]; + Utils`FSFancyWarning[ + "FlexibleSUSY`SUSYScaleFirstGuess should be set in the model file!" + ]; FlexibleSUSY`SUSYScaleFirstGuess = 1000; ]; If[Head[FlexibleSUSY`SUSYScaleInput] =!= List, @@ -620,7 +640,9 @@ FlexibleSUSY model file (FlexibleSUSY.m). ]; If[Head[FlexibleSUSY`SUSYScaleMatching] === List && Head[FlexibleSUSY`MatchingScaleInput] =!= List, - Print["Warning: SUSYScaleMatching is deprecated. Please use MatchingScaleInput instead!"]; + Utils`FSFancyWarning[ + "SUSYScaleMatching is deprecated. Please use MatchingScaleInput instead!" + ]; FlexibleSUSY`MatchingScaleInput = FlexibleSUSY`SUSYScaleMatching; ]; @@ -643,8 +665,10 @@ FlexibleSUSY model file (FlexibleSUSY.m). FlexibleSUSY`ExtraSLHAOutputBlocks = {}; ]; If[MemberQ[FlexibleSUSY`ExtraSLHAOutputBlocks, {FlexibleSUSY`EFFHIGGSCOUPLINGS, __}], - Print["Warning: Effective coupling module has been disabled since v2.6.0."]; - Print[" Please use FlexibleDecay instead."]; + Utils`FSFancyWarning[ + "Effective coupling module has been disabled since v2.6.0.", + " Please use FlexibleDecay instead." + ]; FlexibleSUSY`ExtraSLHAOutputBlocks = DeleteCases[FlexibleSUSY`ExtraSLHAOutputBlocks, {FlexibleSUSY`EFFHIGGSCOUPLINGS, __}]; ]; @@ -692,9 +716,10 @@ FlexibleSUSY model file (FlexibleSUSY.m). usedCases = Function[par, !FreeQ[#, par]& /@ boundaryConditions] /@ parameters; multiplyUsedPars = Position[Count[#, True]& /@ usedCases, n_ /; n > 1]; If[multiplyUsedPars =!= {}, - Print["Warning: the following auxiliary parameters appear at"]; - Print[" multiple scales, but do not run:"]; - Print[" ", Extract[parameters, multiplyUsedPars]]; + Utils`FSFancyWarning[ + "The following auxiliary parameters appear at multiple", + " scales, but do not run: ", Extract[parameters, multiplyUsedPars] + ]; ]; ]; @@ -3526,15 +3551,19 @@ corresponding tadpole is real or imaginary (only in models with CP If[solution === {}, (* Fixed-point iteration can only be used if an analytic EWSB solution exists *) If[MemberQ[validSolvers, FlexibleSUSY`FPIRelative], - Print["Warning: FPIRelative was selected, but no analytic"]; - Print[" solution to the EWSB eqs. is provided."]; - Print[" FPIRelative will be removed from the list of EWSB solvers."]; + Utils`FSFancyWarning[ + "FPIRelative was selected, but no analytic solution", + " to the EWSB eqs. is provided. FPIRelative will be", + " removed from the list of EWSB solvers." + ]; validSolvers = Cases[validSolvers, Except[FlexibleSUSY`FPIRelative]]; ]; If[MemberQ[validSolvers, FlexibleSUSY`FPIAbsolute], - Print["Warning: FPIAbsolute was selected, but no analytic"]; - Print[" solution to the EWSB eqs. is provided."]; - Print[" FPIAbsolute will be removed from the list of EWSB solvers."]; + Utils`FSFancyWarning[ + "FPIAbsolute was selected, but no analytic solution", + " to the EWSB eqs. is provided. FPIAbsolute will be", + " removed from the list of EWSB solvers." + ]; validSolvers = Cases[validSolvers, Except[FlexibleSUSY`FPIAbsolute]]; ]; ]; @@ -4174,8 +4203,10 @@ corresponding tadpole is real or imaginary (only in models with CP If[FlexibleSUSY`FSUnfixedParameters =!= {} && FlexibleSUSY`AutomaticInputAtMSUSY =!= True, - Print["Warning: the following parameters are not fixed by any constraint:"]; - Print[" ", FlexibleSUSY`FSUnfixedParameters]; + Utils`FSFancyWarning[ + "The following parameters are not fixed by any constraint: ", + FlexibleSUSY`FSUnfixedParameters + ]; ]; (* add the unfixed parameters to the susy scale constraint *) @@ -4430,8 +4461,10 @@ corresponding tadpole is real or imaginary (only in models with CP FlexibleSUSY`FSDecayParticles = Select[FlexibleSUSY`FSDecayParticles, Decays`IsSupportedDecayParticle]; If[FlexibleSUSY`FSDecayParticles === {}, - Print["Warning: no supported particles to calculate decays for were found."]; - Print[" Generation of decays code will be skipped."]; + Utils`FSFancyWarning[ + "No supported particles to calculate decays for were found.", + " Generation of decays code will be skipped." + ]; FlexibleSUSY`FSCalculateDecays = False; , decaysSLHAIncludeFiles = {FlexibleSUSY`FSModelName <> "_decays.hpp"}; @@ -4929,9 +4962,10 @@ corresponding tadpole is real or imaginary (only in models with CP ]; wrongFields = Complement[LToLGammaFields, properStates]; If[wrongFields =!= {}, - Print[ - "Warning: BrLToLGamma function works only for leptons and a photon. Removing requested process(es): " <> - StringJoin@Riffle[ToString /@ wrongFields, ", "] + Utils`FSFancyWarning[ + "BrLToLGamma function works only for leptons and a photon.", + " Removing requested process(es): " + Riffle[ToString/@ wrongFields, ", "] ]; LToLGammaFields = properStates; ]; diff --git a/meta/LoopMasses.m b/meta/LoopMasses.m index cf455d4f72..9c9481f33b 100644 --- a/meta/LoopMasses.m +++ b/meta/LoopMasses.m @@ -912,9 +912,10 @@ be set to the (positive) tree-level mass. M_tree (* return pole mass of a singlet as a function of p *) Create1DimPoleMassPrototype[particle_Symbol] := If[GetDimension[particle] > 1, - Print["Warning: cannot generate extra pole mass" - " calculation function for ", particle, ", because" - " it has more than 1 generation"]; + Utils`FSFancyWarning[ + "Cannot generate extra pole mass calculation function for", + " ", particle, ", because it has more than 1 generation" + ]; "", "double " <> CreateLoopMassFunctionName[particle] <> "(double);\n" ]; @@ -923,9 +924,10 @@ be set to the (positive) tree-level mass. M_tree Create1DimPoleMassFunction[particle_Symbol] := Module[{result, body = "", particleName, massName, mTree}, If[GetDimension[particle] > 1, - Print["Warning: cannot generate extra pole mass" - " calculation function for ", particle, ", because" - " it has more than 1 generation"]; + Utils`FSFancyWarning[ + "Cannot generate extra pole mass calculation function for", + " ", particle, ", because it has more than 1 generation" + ]; Return[""]; ]; If[!(IsUnmixed[particle] && GetMassOfUnmixedParticle[particle] === 0), @@ -1228,13 +1230,19 @@ be set to the (positive) tree-level mass. M_tree ]; If[FlexibleSUSY`UseYukawa3LoopQCD === True && FlexibleSUSY`FSRenormalizationScheme =!= FlexibleSUSY`MSbar, - Print["Warning: UseYukawa3LoopQCD == True, but the renormalization scheme is not MSbar!"]; - Print[" The 3-loop QCD corrections to the top Yukawa coupling will be disabled."]; - ]; + Utils`FSFancyWarning[ + "UseYukawa3LoopQCD == True, but the", + " renormalization scheme is not MSbar! The 3-loop QCD", + " corrections to the top Yukawa coupling will be disabled." + ]; + ]; If[FlexibleSUSY`UseYukawa4LoopQCD === True && FlexibleSUSY`FSRenormalizationScheme =!= FlexibleSUSY`MSbar, - Print["Warning: UseYukawa4LoopQCD == True, but the renormalization scheme is not MSbar!"]; - Print[" The 4-loop QCD corrections to the top Yukawa coupling will be disabled."]; + Utils`FSFancyWarning[ + "UseYukawa4LoopQCD == True, but the renormalization", + " scheme is not MSbar! The 4-loop QCD corrections to the", + " top Yukawa coupling will be disabled." + ]; ]; If[FlexibleSUSY`UseYukawa3LoopQCD === True || FlexibleSUSY`UseYukawa3LoopQCD === Automatic, diff --git a/meta/NPointFunctions.m b/meta/NPointFunctions.m index 02121976b6..87909278f2 100644 --- a/meta/NPointFunctions.m +++ b/meta/NPointFunctions.m @@ -1265,8 +1265,8 @@ means that one can simply remove them (as well as corresponding "After projection element `1` still is not a number." -getColourFactor::warnTryingIdentity= -"Warning: There are no colour projectors of the given type. Trying to apply Identity." +getColourFactor::warnTryingIdentity = +"There are no colour projectors of the given type. Trying to apply Identity." getColourFactor[colourfactors:{`type`classColorFactors..}, projection:`type`colourProjector] := Module[ { @@ -1278,7 +1278,7 @@ means that one can simply remove them (as well as corresponding uniqueColourStructs=DeleteDuplicates@Cases[colourfactors,projection[__],Infinity]; Utils`AssertOrQuit[Length@uniqueColourStructs<=1,getColourFactor::errMultipleColourStructures,uniqueColourStructs]; If[Length@uniqueColourStructs===0, - Print[getColourFactor::warnTryingIdentity]; + Utils`FSFancyWarning[getColourFactor::warnTryingIdentity]; colourfactors, colourfactors/.Rule[uniqueColourStructs[[1]],1] ] diff --git a/meta/Observables.m b/meta/Observables.m index 357284f5b5..f17f440b8c 100644 --- a/meta/Observables.m +++ b/meta/Observables.m @@ -59,9 +59,10 @@ Cases[observables, FlexibleSUSYObservable`BrLToLGamma[fin_?IsLepton -> {fout_?IsLepton, vout_ /; vout === GetPhoton[]}]] ]; If[test =!= {}, - Print["Warning: BrLToLGamma function works only for leptons and a photon."]; - Print[" Removing requested process(es):"]; - Print[" " <> ToString@test]; + Utils`FSFancyWarning[ + "BrLToLGamma function works only for leptons and a photon.", + " Removing requested process(es): ", test + ]; observables = Complement[observables, test]; ]; observables @@ -116,11 +117,11 @@ For[i = 1, i <= Length[observables], i++, If[IsObservable[observables[[i]]], number += BetaFunction`CountNumberOfParameters[GetObservableType[observables[[i]]]];, - Print["Warning: ignoring invalid observable ", observables[[i]]]; - ]; - ]; + Utils`FSFancyWarning["Ignoring invalid observable ", observables[[i]]]; + ]; + ]; number - ]; + ]; CreateObservablesDefinitions[observables_List] := Module[{i, type, name, description, definitions = ""}, @@ -130,11 +131,11 @@ description = GetObservableDescription[observables[[i]]]; type = CConversion`CreateCType[GetObservableType[observables[[i]]]]; definitions = definitions <> type <> " " <> name <> "; ///< " <> description <> "\n";, - Print["Warning: ignoring invalid observable ", observables[[i]]]; - ]; - ]; + Utils`FSFancyWarning["Ignoring invalid observable ", observables[[i]]]; + ]; + ]; definitions - ]; + ]; CreateObservablesInitialization[observables_List] := Module[{i, name, type, init = ""}, @@ -146,11 +147,11 @@ init = ": " <> CConversion`CreateDefaultConstructor[name, type] <> "\n";, init = init <> ", " <> CConversion`CreateDefaultConstructor[name, type] <> "\n"; ];, - Print["Warning: ignoring invalid observable ", observables[[i]]]; - ]; - ]; + Utils`FSFancyWarning["Ignoring invalid observable ", observables[[i]]]; + ]; + ]; init - ]; + ]; CreateSetAndDisplayObservablesFunctions[observables_List] := Module[{numObservables, i, name, type, paramCount = 0, nAssignments, assignment, @@ -175,9 +176,9 @@ {assignment, nAssignments} = Parameters`CreateStdVectorNamesAssignment[name, paramCount, type]; displayNames = displayNames <> assignment; paramCount += nAssignments;, - Print["Warning: ignoring invalid observable ", observables[[i]]]; - ]; - ];, + Utils`FSFancyWarning["Ignoring invalid observable ", observables[[i]]]; + ]; + ];, display = "Eigen::ArrayXd vec(1);\n\nvec(0) = 0.;\n"; set = ""; displayNames = "std::vector names(1);\n\n" @@ -193,9 +194,9 @@ name = GetObservableName[observables[[i]]]; type = GetObservableType[observables[[i]]]; result = result <> CConversion`SetToDefault[name, type];, - Print["Warning: ignoring invalid observable ", observables[[i]]]; - ]; - ]; + Utils`FSFancyWarning["Ignoring invalid observable ", observables[[i]]]; + ]; + ]; result ]; diff --git a/meta/Parameters.m b/meta/Parameters.m index 331322a623..ac0fdc2b06 100644 --- a/meta/Parameters.m +++ b/meta/Parameters.m @@ -417,10 +417,12 @@ ProcessParameterInfo[{parameter_ /; (IsModelParameter[parameter] || IsOutputParameter[parameter]), {__}}] := Block[{}, - Print["Warning: the properties of ", parameter, " are set"]; - Print[" in the SARAH model files and cannot be overridden."]; - Print[" Ignoring property settings for ", parameter]; - ]; + Utils`FSFancyWarning[ + "The properties of ", parameter, " are set", + " in the SARAH model files and cannot be overridden.", + " Ignoring property settings for ", parameter + ]; + ]; ProcessParameterInfo[{parameter_?IsInputParameter, properties_List}] := Module[{i, inputBlock, ignored = {}, validProperties = properties, property, setting}, @@ -434,10 +436,14 @@ AddMassDimensionInfo[parameter, setting], property === SARAH`LesHouches, SetInputParameterSLHABlock[parameter, setting], - True, Print["Warning: unrecognized property for parameter ", parameter, ": ", property] - ]; - ]; - ]; + True, + Utils`FSFancyWarning[ + "Unrecognized property for parameter", + " ", parameter, ": ", property + ]; + ]; + ]; + ]; ProcessParameterInfo[{parameter_?IsExtraParameter, properties_List}] := Module[{i, property, setting}, @@ -454,10 +460,14 @@ Print["Error: ", parameter, " is defined as an input parameter"]; Print[" but is being treated as an extra parameter."]; Quit[1];, - True, Print["Warning: unrecognized property for parameter ", parameter, ": ", property] - ]; - ]; - ]; + True, + Utils`FSFancyWarning[ + "Unrecognized property for parameter", + " ", parameter, ": ", property + ]; + ]; + ]; + ]; ProcessParameterInfo[{parameter_, properties_List}] := Block[{inputOptions, isInput = False}, @@ -552,10 +562,10 @@ Return[0]; ]; If[Length[symDef] > 1, - Print["Warning: ", sym, " defined multiple times"]; - ]; + Utils`FSFancyWarning[sym, " defined multiple times"]; + ]; symDef[[1]] - ]; + ]; FindAllParametersFromList[expr_, parameters_List] := Module[{symbols, compactExpr}, @@ -1607,9 +1617,10 @@ Return[Null]; ]; If[Length[parameter] > 1, - Print["Warning: Parameter with description \"", description, - "\" not unique."]; - ]; + Utils`FSFancyWarning[ + "Parameter with description \"", description, "\" not unique." + ]; + ]; parameter[[1]] ]; @@ -1625,9 +1636,10 @@ Return[Null]; ]; If[Length[particle] > 1, - Print["Warning: Particle with description \"", description, - "\" not unique."]; - ]; + Utils`FSFancyWarning[ + "Particle with description \"", description, "\" not unique." + ]; + ]; particle[[1]] ]; @@ -1834,7 +1846,11 @@ GetThirdGeneration[par_] := Which[IsScalar[par], par, IsMatrix[par], par[2,2], - True, Print["Warning: GetThirdGeneration[",par,"]: unknown type"]; par + True, + Utils`FSFancyWarning[ + "GetThirdGeneration[", par, "]: unknown type" + ]; + par ]; GetSARAHParameters[] := diff --git a/meta/ThresholdCorrections.m b/meta/ThresholdCorrections.m index dc4fef504d..38e7a4519f 100644 --- a/meta/ThresholdCorrections.m +++ b/meta/ThresholdCorrections.m @@ -518,7 +518,7 @@ If[weinbergAngle === None || weinbergAngle === Null, weinbergAngle = expr /. subst; If[weinbergAngle === None || weinbergAngle === Null, - Print["Warning: No expression for the Weinberg angle defined, setting it to 0."]; + Utils`FSFancyWarning["No expression for the Weinberg angle defined, setting it to 0."]; weinbergAngle = 0; ]; ]; diff --git a/meta/Utils.m b/meta/Utils.m index b02fc987a1..e234794539 100644 --- a/meta/Utils.m +++ b/meta/Utils.m @@ -269,7 +269,7 @@ occurrence of the given rule is replaced (if it exists) or added (if 0, Print["Error: option ", opt, " not found"]; Null, 1, values[[1]], - _, Print["Warning: option ", opt, " not unique"]; + _, FSFancyWarning["Option ", opt, " is not unique"]; values[[1]] ] ]; @@ -417,16 +417,21 @@ occurrence of the given rule is replaced (if it exists) or added (if ]; SetAttributes[{AssertOrQuit,internalAssertOrQuit},{HoldAll, Protected}]; -FSFancyWarning[string_String, len_Integer:70] := -Module[{warning, chopped}, +Options[FSFancyWarning] = { + PageWidth-> 70 +}; + +FSFancyWarning[input__, OptionsPattern[]] := +Module[{warning, chopped, string}, + string = StringReplace[StringJoin[ToString/@ {input}], "\n"-> " "]; warning = If[!$Notebooks, If[TrueQ@FlexibleSUSY`FSEnableColors, - "\033[1;36mWarning\033[1;0m: ", + "\033[1;36mWarning:\033[1;0m ", "Warning: " ], Style["Warning: ", Cyan] ]; - chopped = InsertLinebreaks[StringReplace[string, "\n"-> " "], len-9]; + chopped = InsertLinebreaks[string, OptionValue[PageWidth]-9]; chopped = StringReplace[chopped, "\n"-> "\n "]; If[!$Notebooks, WriteString[$Output, warning <> chopped <> "\n"];, diff --git a/meta/WeinbergAngle.m b/meta/WeinbergAngle.m index d3bdfad613..e97762667b 100644 --- a/meta/WeinbergAngle.m +++ b/meta/WeinbergAngle.m @@ -416,11 +416,11 @@ intparticles = ({SARAH`Internal[1], SARAH`Internal[2]} /. diagr[[2]]) /. {SARAH`bar[p_] :> p, Susyno`LieGroups`conj[p_] :> p}; If[Select[intparticles, TreeMasses`IsFermion] === {}, - Print["Warning: no internal fermion in wave function diagram"]; + Utils`FSFancyWarning["No internal fermion in wave function diagram"]; Return[0]]; intfermion = Select[intparticles, TreeMasses`IsFermion][[1]]; If[Select[intparticles, TreeMasses`IsScalar] === {}, - Print["Warning: no internal scalar in wave function diagram"]; + Utils`FSFancyWarning["No internal scalar in wave function diagram"]; Return[0]]; intscalar = Select[intparticles, TreeMasses`IsScalar][[1]]; result = -coupl Susyno`LieGroups`conj[coupl] * @@ -548,7 +548,7 @@ factor = 1, If[scalarsoutin === {inscalar, outscalar}, factor = -1, - Print["Warning: scalar direction could not be determined"]; + Utils`FSFancyWarning["Scalar direction could not be determined"]; Return[0]]]; couplSSV = factor couplSSV; couplFFSout = (diagr[[1, extoutindex]] /. C[a__] -> SARAH`Cp[a])[SARAH`PR]; @@ -640,7 +640,8 @@ Switch[{nFermions, nScalars}, {1, 2}, VertexResultFSS[diagr, includeGoldstones], {2, 1}, VertexResultFFS[diagr, includeGoldstones], - _, Print["Warning: vertex diagram type not supported"]; 0] + _, Utils`FSFancyWarning["Vertex diagram type not supported"]; + 0] ]; (*calculates tree-level vertex result for normalization of one-loop results*) @@ -766,10 +767,10 @@ SARAH`Internal[3], SARAH`Internal[4]} /. diagr[[2]]) /. {SARAH`bar[p_] :> p, Susyno`LieGroups`conj[p_] :> p}; If[Length[Select[intparticles, TreeMasses`IsFermion]] != 2, - Print["Warning: not 2 internal fermions in box diagram"]; + Utils`FSFancyWarning["Not 2 internal fermions in box diagram"]; Return[0]]; If[Length[Select[intparticles, TreeMasses`IsScalar]] != 2, - Print["Warning: not 2 internal scalars in box diagram"]; + Utils`FSFancyWarning["Not 2 internal scalars in box diagram"]; Return[0]]; intfermions = Select[intparticles, TreeMasses`IsFermion]; toponr = WeinbergAngle`topoNr /. diagr[[2]]; @@ -949,7 +950,7 @@ GetWPlusBoson[]][SARAH`PL]; (*follow vertex conventions:*) coupl = Vertices`SortCp[coupl]; - (*omit a possible minus sign:*) + (*omit a possible minus sign:*) If[MatchQ[coupl, Times[-1, _]], coupl = -coupl]; coupl = SelfEnergies`CreateCouplingSymbol[coupl]; For[k = 0, k <= 2, k++, @@ -995,7 +996,7 @@ CreateDeltaVBCalculation[deltaVBcontris_List] := Module[{type, result = "", boxcontri, vertexcontris, wavecontris}, If[!(TreeMasses`FindMixingMatrixSymbolFor[TreeMasses`GetSMNeutralLeptons[][[1]]] === Null), - Print["Warning: neutrino mixing is not considered in muon decay"]]; + Utils`FSFancyWarning["Neutrino mixing is not considered in muon decay"]]; type = CConversion`CreateCType[CConversion`ScalarType[CConversion`complexScalarCType]]; boxcontri = Cases[deltaVBcontris, WeinbergAngle`DeltaVB[{WeinbergAngle`fsbox, __}, _]]; If[boxcontri === {}, diff --git a/meta/WriteOut.m b/meta/WriteOut.m index 36832df0a1..ae3351e45f 100644 --- a/meta/WriteOut.m +++ b/meta/WriteOut.m @@ -335,10 +335,12 @@ Module[{str, strSLHA, lhs, wrapper}, If[SARAH`getDimParameters[mixingMatrix] === {} || SARAH`getDimParameters[mixingMatrix] === {1}, - Print["Warning: You are trying to create a SLHA matrix block for"]; - Print[" ", mixingMatrix, ", which is not a matrix!"]; - Print[" Please specify a Les Houches index in the SARAH model file."]; - ]; + Utils`FSFancyWarning[ + "You are trying to create a SLHA matrix block for ", + mixingMatrix, ", which is not a matrix! Please specify ", + "a Les Houches index in the SARAH model file." + ]; + ]; str = CConversion`ToValidCSymbolString[mixingMatrix]; (* use SLHA compliant yukawas, trilinears, soft-squared masses *) strSLHA = If[mixingMatrix === SARAH`UpYukawa || @@ -674,8 +676,10 @@ ReadSLHAOutputBlock[{parameter_, {blockName_, pdg_?NumberQ}}] := Block[{}, - Print["Warning: SLHA block name is not a symbol: ", blockName]; - Print[" I'm using: ", CConversion`RValueToCFormString[blockName]]; + Utils`FSFancyWarning[ + "SLHA block name is not a symbol: ", blockName, + " I'm using: ", CConversion`RValueToCFormString[blockName] + ]; ReadSLHAOutputBlock[{parameter, {CConversion`RValueToCFormString[blockName], pdg}}] ]; @@ -928,9 +932,11 @@ CreateSLHAFermionMixingMatrixName[vR] <> ", " <> CreateSLHAFermionMixingMatrixName[vL] <> ");\n"; , - Print["Warning: Cannot convert Yukawa coupling ", #, - " to SLHA, because ", {vL,vR}, " are not defined", - " or have incompatible dimension."]; + Utils`FSFancyWarning[ + "Cannot convert Yukawa coupling ", #, + " to SLHA, because ", {vL,vR}, " are not", + " defined or have incompatible dimension." + ]; result = result <> CreateSLHAYukawaName[#] <> " = MODELPARAMETER(" <> CConversion`ToValidCSymbolString[#] <> ").diagonal().real();\n"; @@ -980,9 +986,11 @@ GetSLHATrilinearCouplingType[#] ] <> ";\n"; , - Print["Warning: Cannot convert Trilinear coupling ", #, - " to SLHA, because ", {vL,vR}, " are not defined", - " or have incompatible dimension."]; + Utils`FSFancyWarning[ + "Cannot convert Trilinear coupling ", #, + " to SLHA, because ", {vL,vR}, " are not", + " defined or have incompatible dimension." + ]; result = result <> CreateSLHATrilinearCouplingName[#] <> " = " <> CConversion`CastTo[ @@ -1052,9 +1060,11 @@ ] <> ";\n"; ]; , - Print["Warning: Cannot convert soft squared mass ", #, - " to SLHA, because ", {vL,vR}, " are not defined", - " or have incompatible dimension."]; + Utils`FSFancyWarning[ + "Cannot convert soft squared mass ", #, + " to SLHA, because ", {vL,vR}, " are not", + " defined or have incompatible dimension." + ]; result = result <> CreateSLHASoftSquaredMassName[#] <> " = " <> CConversion`CastTo[ From 75df3e4021f9506b988bed1c7403c359f61901a8 Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Wed, 17 Nov 2021 22:48:40 +0100 Subject: [PATCH 092/477] Drastically simplify AssertOrQuit. Remove EvaluateOrQuit. --- meta/NPointFunctions.m | 12 +- meta/Utils.m | 244 +++++++++-------------------------------- test/test_Utils.m | 120 +++++++------------- 3 files changed, 92 insertions(+), 284 deletions(-) diff --git a/meta/NPointFunctions.m b/meta/NPointFunctions.m index 87909278f2..1ff71008e7 100644 --- a/meta/NPointFunctions.m +++ b/meta/NPointFunctions.m @@ -740,10 +740,6 @@ @returns subkernel name. @note Mathematica 7 returns KernelObject[__], 11.3 returns {KernelObject[__]} @note for Mathematica 7 some functions have the same names as in SARAH`.`"; -LaunchSubkernelFor::errKernelLaunch= -"Unable to launch subkernel(s) during calculations for -`1` -because of error:"; LaunchSubkernelFor[message_String] /; $VersionNumber===7.0 := Module[{kernelName}, Off[Parallel`Preferences`add::shdw, @@ -752,9 +748,7 @@ Parallel`Preferences`tr::shdw, Parallel`Protected`processes::shdw, SubKernels`Description::shdw]; - kernelName = Utils`EvaluateOrQuit[ - LaunchKernels[1], - LaunchSubkernelFor::errKernelLaunch, message]; + kernelName = LaunchKernels[1]; On[Parallel`Preferences`add::shdw, Parallel`Preferences`set::shdw, Parallel`Preferences`list::shdw, @@ -765,9 +759,7 @@ ]; LaunchSubkernelFor[message_String] := Module[{kernelName}, - kernelName = Utils`EvaluateOrQuit[ - LaunchKernels[1], - LaunchSubkernelFor::errKernelLaunch, message]; + kernelName = LaunchKernels[1]; If[Head@kernelName === List, kernelName[[1]], kernelName] ]; LaunchSubkernelFor // Utils`MakeUnknownInputDefinition; diff --git a/meta/Utils.m b/meta/Utils.m index e234794539..333c007ad5 100644 --- a/meta/Utils.m +++ b/meta/Utils.m @@ -144,67 +144,21 @@ occurrence of the given rule is replaced (if it exists) or added (if AssertWithMessage::usage = "AssertWithMessage[assertion_, message_String]: If assertion does not evaluate to True, print message and Quit[1]."; -AssertOrQuit::usage = -"@brief AssertOrQuit[assertion, sym::tag, insertions...]: -If assertion evaluate to True, returns True. -If assertion evaluate to False, print message with sequence of insertions -and Quit[1]. -@param assertion Some expression which one want to check being True or something -else. -@param sym::tag Controlling MessageName String. It is assumed that symbol \"\" -appears only as controllling one, i.e. in the form \"1\", \"25\" etc. -@param insertions... None or more expressions which are inserted inside sym::tag -controlling String. Its length should be equal or more then the maximal -controlling number in sym::tag. -@note First check controlling sym::tag. -@note __~~\"Private\"~~str__:>str is done because Mathematica prints the names -of Private` variables in a quite weird way. -@note \"\\n->\"dummy_new_line\" because Mathematica's StringForm incorrectly -parses \\n symbol. -@note hard-coded width of output colourless text is 70."; - -EvaluateOrQuit::usage = -"@brief EvaluateOrQuit[expression, sym::tag, insertions...]: -Evaluates expression and returns the result if Wolfram messages aren't -generated. -If any Message is generated it - stops evaluation, - prints message with sequence of insertions, - prints content of Message and - Quit[1]. -@param expression Some expression which one want to evaluate without Wolfram -messages. -@param sym::tag Controlling MessageName String. It is assumed that symbol \"`\" -appears only as controllling one, i.e. in the form \"`1`\", \"`25`\" etc. -@param insertions... None or more expressions which are inserted inside sym::tag -controlling String. Its length should be equal or more then the maximal -controlling number in sym::tag. -@note First check controlling sym::tag. -@note hard-coded width of output colourless text is 70. -@note It seems that function is not working for messages generated in subkernels -if they are running inside expression. -@note __~~\"Private`\"~~str__:>str is done because Mathematica prints the names -of Private` variables in a quite weird way. -@note \"\\n->\"dummy_new_line\" because Mathematica's StringForm incorrectly -parses \\n symbol. -@note Internal`HandlerBlock is not documented, this is why System`Dump` prefix -is used for function arguments to avoid any unexpected behavior."; - -MakeUnknownInputDefinition::usage = -"@brief Creates definition for a given symbol for a case when input is not defined -explicitly, i.e. creates definition for the pattern symbol[args___]. -@example Step 1) Make all desired definitions for a function (here: foo), like -foo[a_Integer] := Module[{<...>},<...>]; -foo[c:{__Integer}] := Module[{<...>},<...>]; -Step 2) Secure the usage of foo for specified above cases simply by writing -foo // Utils`MakeUnknownInputDefinition; -or -Utils`MakeUnknownInputDefinition[foo]; -or -Utils`MakeUnknownInputDefinition@foo; -somewhere in the scope of the package, where foo is defined. -@param sym Symbol to make definition for. -@returns None. +AssertOrQuit::usage = " +@brief If assertion === True, True is returned. + If assertion =!= True, an error message is printed and kernel is killed. +@param assertion Any expression. +@param sym::tag A message string. +@param insertions Expressions inserted into the message via StringTemplate."; + +MakeUnknownInputDefinition::usage = " +@brief After the definition of any function use it like: + + Utils`MakeUnknownInputDefinition[function]; + + It creates a new definition function[args___], which prints an error and + kills the kernel if used in the code. +@param sym A name of a function. @note UpValues for symbol[args___] are not cleared."; ReadLinesInFile::usage = "ReadLinesInFile[fileName_String]: @@ -357,65 +311,31 @@ occurrence of the given rule is replaced (if it exists) or added (if AssertWithMessage[assertion_, message_String] := If[assertion =!= True, Print[message]; Quit[1]]; -AssertOrQuit::errNotDefined = -"Error message \"`1`\" is not defined in the code."; -AssertOrQuit::errStrokes = -"Even number of `.` symbols in sym::tag should be given in: -\"`1`\""; -AssertOrQuit::errControl = -"Only control symbols \"`.`int Number`.`\" and \"`.`.`.`\" are allowed in: -\"`1`\""; -AssertOrQuit::errInsertions = -"The length of insertions -`1` -should large or equal to the max control number `2` in: -\"`3`\""; -AssertOrQuit::errInput = -"Input should be of the following form: -AssertOrQuit[assertion, sym::tag, insertions...] and not -AssertOrQuit@@`1`. - -Read AssertOrQuit::usage for more information."; -AssertOrQuit[assertion_,HoldPattern@MessageName[sym_, tag_],insertions___] := - internalAssertOrQuit[assertion,MessageName[sym,tag],insertions] /; - internalOrQuitInputCheck[AssertOrQuit,MessageName[sym,tag],insertions]; -AssertOrQuit[x___] := - AssertOrQuit[False,AssertOrQuit::errInput,{x}]; -If[!$Notebooks, - internalAssertOrQuit[assertion_,HoldPattern@MessageName[sym_, tag_],insertions___] := - Module[{RedString,WriteOut,MultilineToDummy,replacedMessage}, - If[TrueQ@assertion, Return@True]; +AssertOrQuit[assertion_, + HoldPattern@MessageName[sym_, tag_], + insertions___] := +Module[{RedString, WriteOut}, + If[TrueQ@assertion, Return@True]; + RedString[str_] := If[$Notebooks, + Style[str, Red], If[TrueQ@FlexibleSUSY`FSEnableColors, - RedString[str_] := "\033[1;31m"<>str<>"\033[1;0m";, - RedString[str_] := str; - ]; - - WriteOut[str__] := WriteString[$Output, StringJoin@str]; - MultilineToDummy[args___] := Sequence@@(StringReplace[ToString@#,"\n"->"dummy_n"]&/@{args}); - replacedMessage = StringReplace[sym~MessageName~tag,"\n"->"dummy_n"]; - - Utils`FSFancyLine[]; - WriteOut[Context@sym,StringReplace[ToString@sym,__~~"`"~~str__:>str],": ",RedString@tag,":\n"]; - WriteOut@StringReplace[ToString@StringForm[replacedMessage,MultilineToDummy@insertions],"dummy_n"->"\n"]; - WriteOut["\nWolfram Language kernel session ",RedString@"terminated",".\n"]; - Utils`FSFancyLine[]; - Quit[1]; - ];, - (* Else *) - internalAssertOrQuit[assertion_,HoldPattern@MessageName[sym_, tag_],insertions___] := - Module[{WriteColourless,MultilineToDummy,replacedMessage}, - If[assertion === True,Return@True]; - - MultilineToDummy[args___] := Sequence@@(StringReplace[ToString@#,"\n"->"dummy_n"]&/@{args}); - replacedMessage = StringReplace[sym~MessageName~tag,"\n"->"dummy_n"]; - - Print[Context@sym,StringReplace[ToString@sym,__~~"`"~~str__:>str],": ",Style[tag,Red],":\n", - StringReplace[ToString@StringForm[replacedMessage,MultilineToDummy@insertions],"dummy_n"->"\n"], - "\nWolfram Language kernel session ","terminated"~Style~Red,"."]; - Quit[1]; + "\033[1;31m"<>str<>"\033[1;0m", + str + ] + ]; + WriteOut[str__] := If[$Notebooks, + Print[str], + WriteString[$Output, StringJoin[str]<>"\n"] ]; + WriteOut[Context@sym, SymbolName@sym, ": ", RedString@tag, ":"]; + WriteOut@StringTemplate[MessageName[sym, tag]][insertions]; + WriteOut["Wolfram Language kernel session ", RedString@"terminated", "."]; + Quit[1]; ]; -SetAttributes[{AssertOrQuit,internalAssertOrQuit},{HoldAll, Protected}]; + +AssertOrQuit[x___] := AssertOrQuit[False, AssertOrQuit::errInput, {x}]; +AssertOrQuit ~ SetAttributes ~ {HoldAll, Protected}; +AssertOrQuit::errInput = "Input '`1`' is not supported."; Options[FSFancyWarning] = { PageWidth-> 70 @@ -439,81 +359,8 @@ occurrence of the given rule is replaced (if it exists) or added (if ]; ]; -EvaluateOrQuit::errNotDefined = AssertOrQuit::errNotDefined; -EvaluateOrQuit::errStrokes = AssertOrQuit::errStrokes; -EvaluateOrQuit::errControl = AssertOrQuit::errControl; -EvaluateOrQuit::errInsertions = AssertOrQuit::errInsertions; -EvaluateOrQuit::errInput = -"Input should be of the following form: -EvaluateOrQuit[expression, sym::tag, insertions...] and not -EvaluateOrQuit@@`1`. -Read EvaluateOrQuit::usage for more information."; -EvaluateOrQuit[expression_,HoldPattern@MessageName[sym_, tag_],insertions___] := - internalEvaluateOrQuit[expression,MessageName[sym,tag],insertions] /; - internalOrQuitInputCheck[EvaluateOrQuit,MessageName[sym,tag],insertions]; -EvaluateOrQuit[x___] := - AssertOrQuit[False,EvaluateOrQuit::errInput,{x}]; -internalEvaluateOrQuit[ - expression_, - HoldPattern@MessageName[sym_, tag_], - insertions___ -] := -Module[ - { - ctrlRed=If[!$Notebooks,"\033[1;31m",""], - ctrlBack=If[!$Notebooks,"\033[1;0m",""], - CutString=If[(!$Notebooks)&&MemberQ[$Packages,"TextFormatting`"], - TextFormatting`WrapLines[#,70,""]&,#&], - WriteOut,WriteColourless,Filter - }, - WriteOut[string__] := WriteString[$Output, StringJoin@string]; - WriteColourless[string__] := WriteOut@CutString@StringJoin@string; - Filter[ - System`Dump`str_, - Hold[MessageName[System`Dump`s_, System`Dump`t_]], - Hold[Message[_, System`Dump`args___]] - ] := - ( - Utils`FSFancyLine[]; - WriteOut[Context@sym,StringReplace[ToString@sym,__~~"`"~~str__:>str], - ": ",ctrlRed,tag,ctrlBack,":\n"]; - WriteColourless[#,"\n"]&/@StringSplit[ToString@StringForm[ - StringReplace[MessageName[sym, tag],"\n"->"dummy_n"],insertions], - "dummy_n"]; - WriteColourless[ToString@System`Dump`s,"::",System`Dump`t," ", - ToString@StringForm[System`Dump`str,System`Dump`args]]; - WriteOut["\nWolfram Language kernel session ",ctrlRed,"terminated",ctrlBack,".\n"]; - Utils`FSFancyLine[]; - Quit[1] - ); - Internal`HandlerBlock[{"MessageTextFilter", Filter}, expression] -]; -SetAttributes[{EvaluateOrQuit,internalEvaluateOrQuit},{HoldAll, Protected}]; - -internalOrQuitInputCheck[func_,message_,insertions___] := -Module[{nStrokes,controlSubstrings}, - internalAssertOrQuit[StringQ@message, - func::errNotDefined,message]; - nStrokes = StringCount[message,"`"]; - internalAssertOrQuit[EvenQ@nStrokes, - func::errStrokes,message]; - - If[nStrokes===0,Return@True]; - - controlSubstrings=DeleteDuplicates@StringCases[message,{ - "`.`":>0,(* Ok *) - "`"~~num:DigitCharacter..~~"`":>FromDigits@num,(* Ok *) - "`"~~___~~"`":>-1(* Something bad *) - }]; - internalAssertOrQuit[FreeQ[controlSubstrings,-1], - func::errControl,message]; - internalAssertOrQuit[TrueQ[Max@controlSubstrings<=Length@{insertions}], - func::errInsertions,{insertions},Max@checkedControl,message] -]; -SetAttributes[internalOrQuitInputCheck,{HoldFirst, Protected}]; - MakeUnknownInputDefinition[sym_Symbol] := -Module[{usageString,info,parsedInfo,infoString,symbolAsString}, +Module[{usageString,info,parsedInfo,infoString}, (* Clean existing definitions if they exist for required pattern.. *) Off[Unset::norep]; sym[args___] =.; @@ -530,10 +377,17 @@ occurrence of the given rule is replaced (if it exists) or added (if infoString = StringJoin@Riffle[StringJoin @@ # & /@ parsedInfo, "\n"]; infoString = "The behavior for case"<>If[Length@parsedInfo===1,"\n","s\n"]<>infoString<>"\nis defined only.\n\n"; ]; - symbolAsString=StringReplace[ToString@sym,"`"->"`.`"]; - sym::errUnknownInput = "`1``2`Call\n"<>symbolAsString<>"[`3`]\nis not supported."; - (* Define a new pattern. *) - sym[args___] := AssertOrQuit[False,sym::errUnknownInput,usageString,infoString,StringJoinWithSeparator[{args},", "]]; + + With[{name = ToString@sym}, + sym::errUnknownInput = "`1``2`Call\n`3`[`4`]\nis not supported."; + sym[args___] := AssertOrQuit[False, + sym::errUnknownInput, + usageString, + infoString, + name, + StringJoinWithSeparator[{args},", "] + ]; + ]; ]; MakeUnknownInputDefinition@MakeUnknownInputDefinition; SetAttributes[MakeUnknownInputDefinition,{Locked,Protected}]; diff --git a/test/test_Utils.m b/test/test_Utils.m index 0061699163..77363bda10 100644 --- a/test/test_Utils.m +++ b/test/test_Utils.m @@ -20,97 +20,64 @@ *) -Global`time = AbsoluteTime[]; - -(* THERE IS A NEED TO CHANGE BEHAVIOR OF LOCKED FILE **************************) -fileName = FileNameJoin@{Directory[],"test","test_Utils.temp"}; -Off[Syntax::sntufn]; -subKernel = LaunchKernels[1]; -DistributeDefinitions[fileName]; -ParallelEvaluate[ - Needs["Utils`",FileNameJoin@{Directory[],"meta","Utils.m"}]; - Put[Definition@Utils`Private`internalAssertOrQuit,fileName]; - code = StringJoin@Riffle[Drop[Utils`ReadLinesInFile@fileName,2],"\n"]; - code=StringReplace[code, - { - "\\[Raw"~~Shortest@__~~"m"->"", - "Quit[1];"->"","FSFancyLine[];"->"", - "WriteString"~~__~~x:"StringJoin[Utils`Private`str]"~~"]":> - "(`test`out = `test`out<>"<>x<>")", - "\\nWolfram Language kernel session "->"" - } - ]; - fileHandle = OpenWrite@fileName; - fileHandle ~ WriteString ~ code; - Close@fileHandle; -]; -CloseKernels@subKernel; -On[Syntax::sntufn]; -(* LOAD TEST DEFINITIONS ******************************************************) -`test`out=""; -Get@fileName; -Attributes[Utils`Private`internalAssertOrQuit] = {HoldAll,Protected,Locked}; -DeleteFile@fileName; - -Off[SetDelayed::write,Attributes::locked]; Needs["TestSuite`", "TestSuite.m"]; Needs["Utils`", "Utils.m"]; -On[SetDelayed::write,Attributes::locked]; -(* TEST MULTIDIMENSIONAL CONTEXT***********************************************) +evaluate[call_] := +Block[{Quit, $Output = {OpenWrite[]}, out}, + call; + out = ReadString[$Output[[1, 1]]]; + Close[$Output[[1]]]; + out +]; +evaluate ~ SetAttributes ~ {HoldAll}; + a; a//Utils`MakeUnknownInputDefinition; -a[1]; -TestEquality[`test`out, +TestEquality[evaluate@a[1], "Global`a: errUnknownInput: Call a[1] -is not supported.terminated.\n" +is not supported. +Wolfram Language kernel session terminated.\n" ]; -`test`out=""; `subcontext`b; `subcontext`b//Utils`MakeUnknownInputDefinition; -`subcontext`b[1]; -TestEquality[`test`out, +TestEquality[evaluate@`subcontext`b[1], "Global`subcontext`b: errUnknownInput: Call Global`subcontext`b[1] -is not supported.terminated.\n" +is not supported. +Wolfram Language kernel session terminated.\n" ]; -`test`out=""; `subcontext`subcontext`c; `subcontext`subcontext`c//Utils`MakeUnknownInputDefinition; -`subcontext`subcontext`c[1]; -TestEquality[`test`out, +TestEquality[evaluate@`subcontext`subcontext`c[1], "Global`subcontext`subcontext`c: errUnknownInput: Call Global`subcontext`subcontext`c[1] -is not supported.terminated.\n" +is not supported. +Wolfram Language kernel session terminated.\n" ]; -`test`out=""; d; d::usage="some text"; d//Utils`MakeUnknownInputDefinition; -d[1]; -TestEquality[`test`out, +TestEquality[evaluate@d[1], "Global`d: errUnknownInput: Usage: some text Call d[1] -is not supported.terminated.\n" +is not supported. +Wolfram Language kernel session terminated.\n" ]; -`test`out=""; - -(* TEST INPUT TYPES ***********************************************************) e[x_,y_] = 3; e//Utils`MakeUnknownInputDefinition; -e[1]; -TestEquality[`test`out, +TestEquality[evaluate@e[1], "Global`e: errUnknownInput: The behavior for case 1) e[x_,y_] @@ -118,14 +85,13 @@ Call e[1] -is not supported.terminated.\n" +is not supported. +Wolfram Language kernel session terminated.\n" ]; -`test`out=""; f[x_Integer,y:{_String}:"`"] := Sin[345*x]; f//Utils`MakeUnknownInputDefinition; -f[]; -TestEquality[`test`out, +TestEquality[evaluate@f[], "Global`f: errUnknownInput: The behavior for case 1) f[x_Integer,y:{_String}:\"`\"] @@ -133,14 +99,13 @@ Call f[] -is not supported.terminated.\n" +is not supported. +Wolfram Language kernel session terminated.\n" ]; -`test`out=""; g[a_,3] := g[a,3] = 17; g//Utils`MakeUnknownInputDefinition; -g["monkey"]; -TestEquality[`test`out, +TestEquality[evaluate@g["monkey"], "Global`g: errUnknownInput: The behavior for case 1) g[a_,3] @@ -148,14 +113,13 @@ Call g[monkey] -is not supported.terminated.\n" +is not supported. +Wolfram Language kernel session terminated.\n" ]; -`test`out=""; h /: Dot[h[2,x_,t:String:"34"], somethingelse] = "works"; h//Utils`MakeUnknownInputDefinition; -h[1,4]; -TestEquality[`test`out, +TestEquality[evaluate@h[1, 4], "Global`h: errUnknownInput: The behavior for case 1) h/:h[2,x_,t:String:\"34\"].somethingelse @@ -163,37 +127,35 @@ Call h[1, 4] -is not supported.terminated.\n" +is not supported. +Wolfram Language kernel session terminated.\n" ]; -`test`out=""; -i /: Print[i[n_], i[m_]] := ""; +i /: FUN[i[n_], i[m_]] := ""; i//Utils`MakeUnknownInputDefinition; -Print[i[n_], i[m_,1]]; -TestEquality[`test`out, +TestEquality[evaluate@FUN[i[n_], i[m_,1]], "Global`i: errUnknownInput: The behavior for case -1) Print[i[n_],i[m_]] +1) FUN[i[n_],i[m_]] is defined only. Call i[n_] -is not supported.terminated. +is not supported. +Wolfram Language kernel session terminated. Global`i: errUnknownInput: The behavior for case -1) Print[i[n_],i[m_]] +1) FUN[i[n_],i[m_]] is defined only. Call i[m_, 1] -is not supported.terminated.\n" +is not supported. +Wolfram Language kernel session terminated.\n" ]; -`test`out=""; TestEquality[FSPermutationSign[Cycles[{{1,2}}]], -1]; TestEquality[FSPermutationSign[Cycles[{{1,3,2}}]], 1]; TestEquality[FSPermutationSign[Cycles[{{1,3,2},{5,6}}]], -1]; -Print[StringJoin[">>test>> done in ",ToString@N[AbsoluteTime[]-Global`time,{Infinity,3}]," seconds.\n"]]; - PrintTestSummary[]; From 8b61e8cdd660a36cc976757e651db778ce5f6c5e Mon Sep 17 00:00:00 2001 From: Uladzimir Khasianevich Date: Wed, 17 Nov 2021 23:37:51 +0100 Subject: [PATCH 093/477] Drastically simplify MakeUnknownInputDefinition. --- meta/Utils.m | 35 +++++++++++++++++++++-------------- test/test_Utils.m | 42 +++++++++++++++++++++--------------------- 2 files changed, 42 insertions(+), 35 deletions(-) diff --git a/meta/Utils.m b/meta/Utils.m index 333c007ad5..ad70bcae8b 100644 --- a/meta/Utils.m +++ b/meta/Utils.m @@ -360,22 +360,29 @@ occurrence of the given rule is replaced (if it exists) or added (if ]; MakeUnknownInputDefinition[sym_Symbol] := -Module[{usageString,info,parsedInfo,infoString}, - (* Clean existing definitions if they exist for required pattern.. *) +Module[{up, down, all, usageString, infoString, simplify}, Off[Unset::norep]; - sym[args___] =.; + sym[args___] =.; On[Unset::norep]; - (* Maybe some useful definitions already exist*) - If[MatchQ[sym::usage,_String],usageString="Usage:\n"<>sym::usage<>"\n\n",usageString=""]; - info = MakeBoxes@Definition@sym; - If[MatchQ[info,InterpretationBox["Null",__]],(* True - No, there is no definitions. *) - infoString="", - parsedInfo = Flatten@# &/@ (Cases[info[[1,1]],GridBox[{x:{_}..},__]:>Cases[{x},{_RowBox},1],2]~Flatten~2 //. {RowBox[x_]:>x,StyleBox[x_,_]:>x}); - parsedInfo = MapThread[parsedInfo[[##]]&,{Range@Length@#,First/@#}] &@ (Range@(First@#-1) &@ Position[#,"="|":="|"^="|"^:="] &/@ parsedInfo); - parsedInfo = DeleteCases[DeleteDuplicates@parsedInfo,{"Options",__}|{"Attributes",__}]; - parsedInfo = Array[Join[{ToString@#,") "},parsedInfo[[#]]]&,Length@parsedInfo]; - infoString = StringJoin@Riffle[StringJoin @@ # & /@ parsedInfo, "\n"]; - infoString = "The behavior for case"<>If[Length@parsedInfo===1,"\n","s\n"]<>infoString<>"\nis defined only.\n\n"; + + If[MatchQ[sym::usage, _String], + usageString = StringJoin["Usage:\n", sym::usage, "\n\n"];, + usageString = ""; + ]; + + simplify[expr_] := StringReplace[ToString@expr, + StartOfString ~~ "HoldPattern[" ~~ x___ ~~ "]" ~~ EndOfString :> x]; + + up = simplify/@ First/@ UpValues@ sym; + down = simplify/@ First/@ DownValues@ sym; + all = Join[up, down]; + + If[all === {}, + infoString = "", + infoString = Array[(ToString[#]<>") "<>all[[#]])&, Length@all]; + infoString = StringRiffle[infoString, "\n"]; + infoString = "The behavior for case(s):\n"<>infoString<> + "\nis defined only.\n\n"; ]; With[{name = ToString@sym}, diff --git a/test/test_Utils.m b/test/test_Utils.m index 77363bda10..91ae5ed40c 100644 --- a/test/test_Utils.m +++ b/test/test_Utils.m @@ -33,7 +33,7 @@ evaluate ~ SetAttributes ~ {HoldAll}; a; -a//Utils`MakeUnknownInputDefinition; +a // Utils`MakeUnknownInputDefinition; TestEquality[evaluate@a[1], "Global`a: errUnknownInput: Call @@ -43,7 +43,7 @@ ]; `subcontext`b; -`subcontext`b//Utils`MakeUnknownInputDefinition; +`subcontext`b // Utils`MakeUnknownInputDefinition; TestEquality[evaluate@`subcontext`b[1], "Global`subcontext`b: errUnknownInput: Call @@ -53,7 +53,7 @@ ]; `subcontext`subcontext`c; -`subcontext`subcontext`c//Utils`MakeUnknownInputDefinition; +`subcontext`subcontext`c // Utils`MakeUnknownInputDefinition; TestEquality[evaluate@`subcontext`subcontext`c[1], "Global`subcontext`subcontext`c: errUnknownInput: Call @@ -63,7 +63,7 @@ ]; d; d::usage="some text"; -d//Utils`MakeUnknownInputDefinition; +d // Utils`MakeUnknownInputDefinition; TestEquality[evaluate@d[1], "Global`d: errUnknownInput: Usage: @@ -76,11 +76,11 @@ ]; e[x_,y_] = 3; -e//Utils`MakeUnknownInputDefinition; +e // Utils`MakeUnknownInputDefinition; TestEquality[evaluate@e[1], "Global`e: errUnknownInput: -The behavior for case -1) e[x_,y_] +The behavior for case(s): +1) e[x_, y_] is defined only. Call @@ -90,11 +90,11 @@ ]; f[x_Integer,y:{_String}:"`"] := Sin[345*x]; -f//Utils`MakeUnknownInputDefinition; +f // Utils`MakeUnknownInputDefinition; TestEquality[evaluate@f[], "Global`f: errUnknownInput: -The behavior for case -1) f[x_Integer,y:{_String}:\"`\"] +The behavior for case(s): +1) f[x_Integer, y:{_String}:`] is defined only. Call @@ -104,11 +104,11 @@ ]; g[a_,3] := g[a,3] = 17; -g//Utils`MakeUnknownInputDefinition; +g // Utils`MakeUnknownInputDefinition; TestEquality[evaluate@g["monkey"], "Global`g: errUnknownInput: -The behavior for case -1) g[a_,3] +The behavior for case(s): +1) g[a_, 3] is defined only. Call @@ -118,11 +118,11 @@ ]; h /: Dot[h[2,x_,t:String:"34"], somethingelse] = "works"; -h//Utils`MakeUnknownInputDefinition; +h // Utils`MakeUnknownInputDefinition; TestEquality[evaluate@h[1, 4], "Global`h: errUnknownInput: -The behavior for case -1) h/:h[2,x_,t:String:\"34\"].somethingelse +The behavior for case(s): +1) h[2, x_, t:String:34] . somethingelse is defined only. Call @@ -132,11 +132,11 @@ ]; i /: FUN[i[n_], i[m_]] := ""; -i//Utils`MakeUnknownInputDefinition; +i // Utils`MakeUnknownInputDefinition; TestEquality[evaluate@FUN[i[n_], i[m_,1]], "Global`i: errUnknownInput: -The behavior for case -1) FUN[i[n_],i[m_]] +The behavior for case(s): +1) FUN[i[n_], i[m_]] is defined only. Call @@ -144,8 +144,8 @@ is not supported. Wolfram Language kernel session terminated. Global`i: errUnknownInput: -The behavior for case -1) FUN[i[n_],i[m_]] +The behavior for case(s): +1) FUN[i[n_], i[m_]] is defined only. Call From e3bf2d565290c53f940a4ec8ae5b36db5b6eb559 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Mon, 29 Nov 2021 16:25:54 +0100 Subject: [PATCH 094/477] removed end-of-line whitespaces in the Wilson coefficient output --- templates/b_to_s_gamma.cpp.in | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/templates/b_to_s_gamma.cpp.in b/templates/b_to_s_gamma.cpp.in index c8185d9312..42755af5a9 100644 --- a/templates/b_to_s_gamma.cpp.in +++ b/templates/b_to_s_gamma.cpp.in @@ -61,20 +61,20 @@ void write_wilsoncoeffs(const std::complex& C7NP_bs, const std::complex< wc_json << "{\n\"eft\": \"WET\",\n"; wc_json << "\t\"basis\": \"flavio\",\n"; wc_json << "\t\"scale\": \"" << matching_scale << "\",\n"; - wc_json << "\t\"values\": { \n"; - wc_json << "\t\t\"C7_bs\": { \n"; + wc_json << "\t\"values\": {\n"; + wc_json << "\t\t\"C7_bs\": {\n"; wc_json << "\t\t\t\"Re\": " << Re(C7NP_bs) << ",\n"; wc_json << "\t\t\t\"Im\": " << Im(C7NP_bs) << "\n"; wc_json << "\t\t},\n"; - wc_json << "\t\t\"C7p_bs\": { \n"; + wc_json << "\t\t\"C7p_bs\": {\n"; wc_json << "\t\t\t\"Re\": " << Re(C7pNP_bs) << ",\n"; wc_json << "\t\t\t\"Im\": " << Im(C7pNP_bs) << "\n"; wc_json << "\t\t},\n"; - wc_json << "\t\t\"C8_bs\": { \n"; + wc_json << "\t\t\"C8_bs\": {\n"; wc_json << "\t\t\t\"Re\": " << Re(C8NP_bs) << ",\n"; wc_json << "\t\t\t\"Im\": " << Im(C8NP_bs) << "\n"; wc_json << "\t\t},\n"; - wc_json << "\t\t\"C8p_bs\": { \n"; + wc_json << "\t\t\"C8p_bs\": {\n"; wc_json << "\t\t\t\"Re\": " << Re(C8pNP_bs) << ",\n"; wc_json << "\t\t\t\"Im\": " << Im(C8pNP_bs) << "\n"; wc_json << "\t\t}\n"; From 0d5c68091bfb3a3fd3d1561644f007aa686df38f Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 2 Dec 2021 13:09:35 +0100 Subject: [PATCH 095/477] added JSON library (#399) --- config/Makefile.in | 2 +- config/flexiblesusy-config.in | 2 +- nlohmann/json.hpp | 26753 ++++++++++++++++++++++++++++++++ templates/b_to_s_gamma.cpp.in | 42 +- 4 files changed, 26770 insertions(+), 29 deletions(-) create mode 100644 nlohmann/json.hpp diff --git a/config/Makefile.in b/config/Makefile.in index 3004e1efcc..95c3c32607 100644 --- a/config/Makefile.in +++ b/config/Makefile.in @@ -38,7 +38,7 @@ ENABLE_VERBOSE := @ENABLE_VERBOSE@ # Makefile modules MODELS := @MODELS@ ADDONS := @ADDONS@ -MODULES := config src fflite slhaea doc +MODULES := config src fflite slhaea doc nlohmann # BEGIN: NOT EXPORTED ########################################## MODULES += meta templates # END: NOT EXPORTED ########################################## diff --git a/config/flexiblesusy-config.in b/config/flexiblesusy-config.in index 5b095d58ea..10d52b5118 100644 --- a/config/flexiblesusy-config.in +++ b/config/flexiblesusy-config.in @@ -109,7 +109,7 @@ create_model_specific_modules_list() { } create_module_list() { - echo "config src fflite slhaea doc $models $addons $model_specific_modules $optional_modules" + echo "config src fflite slhaea doc nlohmann $models $addons $model_specific_modules $optional_modules" } create_include_directives_for_FS_modules() { diff --git a/nlohmann/json.hpp b/nlohmann/json.hpp new file mode 100644 index 0000000000..87475ab31e --- /dev/null +++ b/nlohmann/json.hpp @@ -0,0 +1,26753 @@ +/* + __ _____ _____ _____ + __| | __| | | | JSON for Modern C++ +| | |__ | | | | | | version 3.10.4 +|_____|_____|_____|_|___| https://github.com/nlohmann/json + +Licensed under the MIT License . +SPDX-License-Identifier: MIT +Copyright (c) 2013-2019 Niels Lohmann . + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. +*/ + +#ifndef INCLUDE_NLOHMANN_JSON_HPP_ +#define INCLUDE_NLOHMANN_JSON_HPP_ + +#define NLOHMANN_JSON_VERSION_MAJOR 3 +#define NLOHMANN_JSON_VERSION_MINOR 10 +#define NLOHMANN_JSON_VERSION_PATCH 4 + +#include // all_of, find, for_each +#include // nullptr_t, ptrdiff_t, size_t +#include // hash, less +#include // initializer_list +#ifndef JSON_NO_IO + #include // istream, ostream +#endif // JSON_NO_IO +#include // random_access_iterator_tag +#include // unique_ptr +#include // accumulate +#include // string, stoi, to_string +#include // declval, forward, move, pair, swap +#include // vector + +// #include + + +#include +#include + +// #include + + +#include // transform +#include // array +#include // forward_list +#include // inserter, front_inserter, end +#include // map +#include // string +#include // tuple, make_tuple +#include // is_arithmetic, is_same, is_enum, underlying_type, is_convertible +#include // unordered_map +#include // pair, declval +#include // valarray + +// #include + + +#include // exception +#include // runtime_error +#include // to_string +#include // vector + +// #include + + +#include // array +#include // size_t +#include // uint8_t +#include // string + +namespace nlohmann +{ +namespace detail +{ +/////////////////////////// +// JSON type enumeration // +/////////////////////////// + +/*! +@brief the JSON type enumeration + +This enumeration collects the different JSON types. It is internally used to +distinguish the stored values, and the functions @ref basic_json::is_null(), +@ref basic_json::is_object(), @ref basic_json::is_array(), +@ref basic_json::is_string(), @ref basic_json::is_boolean(), +@ref basic_json::is_number() (with @ref basic_json::is_number_integer(), +@ref basic_json::is_number_unsigned(), and @ref basic_json::is_number_float()), +@ref basic_json::is_discarded(), @ref basic_json::is_primitive(), and +@ref basic_json::is_structured() rely on it. + +@note There are three enumeration entries (number_integer, number_unsigned, and +number_float), because the library distinguishes these three types for numbers: +@ref basic_json::number_unsigned_t is used for unsigned integers, +@ref basic_json::number_integer_t is used for signed integers, and +@ref basic_json::number_float_t is used for floating-point numbers or to +approximate integers which do not fit in the limits of their respective type. + +@sa see @ref basic_json::basic_json(const value_t value_type) -- create a JSON +value with the default value for a given type + +@since version 1.0.0 +*/ +enum class value_t : std::uint8_t +{ + null, ///< null value + object, ///< object (unordered set of name/value pairs) + array, ///< array (ordered collection of values) + string, ///< string value + boolean, ///< boolean value + number_integer, ///< number value (signed integer) + number_unsigned, ///< number value (unsigned integer) + number_float, ///< number value (floating-point) + binary, ///< binary array (ordered collection of bytes) + discarded ///< discarded by the parser callback function +}; + +/*! +@brief comparison operator for JSON types + +Returns an ordering that is similar to Python: +- order: null < boolean < number < object < array < string < binary +- furthermore, each type is not smaller than itself +- discarded values are not comparable +- binary is represented as a b"" string in python and directly comparable to a + string; however, making a binary array directly comparable with a string would + be surprising behavior in a JSON file. + +@since version 1.0.0 +*/ +inline bool operator<(const value_t lhs, const value_t rhs) noexcept +{ + static constexpr std::array order = {{ + 0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */, + 1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */, + 6 /* binary */ + } + }; + + const auto l_index = static_cast(lhs); + const auto r_index = static_cast(rhs); + return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index]; +} +} // namespace detail +} // namespace nlohmann + +// #include + + +#include +// #include + + +#include // declval, pair +// #include + + +/* Hedley - https://nemequ.github.io/hedley + * Created by Evan Nemerson + * + * To the extent possible under law, the author(s) have dedicated all + * copyright and related and neighboring rights to this software to + * the public domain worldwide. This software is distributed without + * any warranty. + * + * For details, see . + * SPDX-License-Identifier: CC0-1.0 + */ + +#if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15) +#if defined(JSON_HEDLEY_VERSION) + #undef JSON_HEDLEY_VERSION +#endif +#define JSON_HEDLEY_VERSION 15 + +#if defined(JSON_HEDLEY_STRINGIFY_EX) + #undef JSON_HEDLEY_STRINGIFY_EX +#endif +#define JSON_HEDLEY_STRINGIFY_EX(x) #x + +#if defined(JSON_HEDLEY_STRINGIFY) + #undef JSON_HEDLEY_STRINGIFY +#endif +#define JSON_HEDLEY_STRINGIFY(x) JSON_HEDLEY_STRINGIFY_EX(x) + +#if defined(JSON_HEDLEY_CONCAT_EX) + #undef JSON_HEDLEY_CONCAT_EX +#endif +#define JSON_HEDLEY_CONCAT_EX(a,b) a##b + +#if defined(JSON_HEDLEY_CONCAT) + #undef JSON_HEDLEY_CONCAT +#endif +#define JSON_HEDLEY_CONCAT(a,b) JSON_HEDLEY_CONCAT_EX(a,b) + +#if defined(JSON_HEDLEY_CONCAT3_EX) + #undef JSON_HEDLEY_CONCAT3_EX +#endif +#define JSON_HEDLEY_CONCAT3_EX(a,b,c) a##b##c + +#if defined(JSON_HEDLEY_CONCAT3) + #undef JSON_HEDLEY_CONCAT3 +#endif +#define JSON_HEDLEY_CONCAT3(a,b,c) JSON_HEDLEY_CONCAT3_EX(a,b,c) + +#if defined(JSON_HEDLEY_VERSION_ENCODE) + #undef JSON_HEDLEY_VERSION_ENCODE +#endif +#define JSON_HEDLEY_VERSION_ENCODE(major,minor,revision) (((major) * 1000000) + ((minor) * 1000) + (revision)) + +#if defined(JSON_HEDLEY_VERSION_DECODE_MAJOR) + #undef JSON_HEDLEY_VERSION_DECODE_MAJOR +#endif +#define JSON_HEDLEY_VERSION_DECODE_MAJOR(version) ((version) / 1000000) + +#if defined(JSON_HEDLEY_VERSION_DECODE_MINOR) + #undef JSON_HEDLEY_VERSION_DECODE_MINOR +#endif +#define JSON_HEDLEY_VERSION_DECODE_MINOR(version) (((version) % 1000000) / 1000) + +#if defined(JSON_HEDLEY_VERSION_DECODE_REVISION) + #undef JSON_HEDLEY_VERSION_DECODE_REVISION +#endif +#define JSON_HEDLEY_VERSION_DECODE_REVISION(version) ((version) % 1000) + +#if defined(JSON_HEDLEY_GNUC_VERSION) + #undef JSON_HEDLEY_GNUC_VERSION +#endif +#if defined(__GNUC__) && defined(__GNUC_PATCHLEVEL__) + #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, __GNUC_PATCHLEVEL__) +#elif defined(__GNUC__) + #define JSON_HEDLEY_GNUC_VERSION JSON_HEDLEY_VERSION_ENCODE(__GNUC__, __GNUC_MINOR__, 0) +#endif + +#if defined(JSON_HEDLEY_GNUC_VERSION_CHECK) + #undef JSON_HEDLEY_GNUC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_GNUC_VERSION) + #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GNUC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_MSVC_VERSION) + #undef JSON_HEDLEY_MSVC_VERSION +#endif +#if defined(_MSC_FULL_VER) && (_MSC_FULL_VER >= 140000000) && !defined(__ICL) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 10000000, (_MSC_FULL_VER % 10000000) / 100000, (_MSC_FULL_VER % 100000) / 100) +#elif defined(_MSC_FULL_VER) && !defined(__ICL) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_FULL_VER / 1000000, (_MSC_FULL_VER % 1000000) / 10000, (_MSC_FULL_VER % 10000) / 10) +#elif defined(_MSC_VER) && !defined(__ICL) + #define JSON_HEDLEY_MSVC_VERSION JSON_HEDLEY_VERSION_ENCODE(_MSC_VER / 100, _MSC_VER % 100, 0) +#endif + +#if defined(JSON_HEDLEY_MSVC_VERSION_CHECK) + #undef JSON_HEDLEY_MSVC_VERSION_CHECK +#endif +#if !defined(JSON_HEDLEY_MSVC_VERSION) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (0) +#elif defined(_MSC_VER) && (_MSC_VER >= 1400) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 10000000) + (minor * 100000) + (patch))) +#elif defined(_MSC_VER) && (_MSC_VER >= 1200) + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_FULL_VER >= ((major * 1000000) + (minor * 10000) + (patch))) +#else + #define JSON_HEDLEY_MSVC_VERSION_CHECK(major,minor,patch) (_MSC_VER >= ((major * 100) + (minor))) +#endif + +#if defined(JSON_HEDLEY_INTEL_VERSION) + #undef JSON_HEDLEY_INTEL_VERSION +#endif +#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && !defined(__ICL) + #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, __INTEL_COMPILER_UPDATE) +#elif defined(__INTEL_COMPILER) && !defined(__ICL) + #define JSON_HEDLEY_INTEL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER / 100, __INTEL_COMPILER % 100, 0) +#endif + +#if defined(JSON_HEDLEY_INTEL_VERSION_CHECK) + #undef JSON_HEDLEY_INTEL_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_INTEL_VERSION) + #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_INTEL_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_INTEL_CL_VERSION) + #undef JSON_HEDLEY_INTEL_CL_VERSION +#endif +#if defined(__INTEL_COMPILER) && defined(__INTEL_COMPILER_UPDATE) && defined(__ICL) + #define JSON_HEDLEY_INTEL_CL_VERSION JSON_HEDLEY_VERSION_ENCODE(__INTEL_COMPILER, __INTEL_COMPILER_UPDATE, 0) +#endif + +#if defined(JSON_HEDLEY_INTEL_CL_VERSION_CHECK) + #undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_INTEL_CL_VERSION) + #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_INTEL_CL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_INTEL_CL_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_PGI_VERSION) + #undef JSON_HEDLEY_PGI_VERSION +#endif +#if defined(__PGI) && defined(__PGIC__) && defined(__PGIC_MINOR__) && defined(__PGIC_PATCHLEVEL__) + #define JSON_HEDLEY_PGI_VERSION JSON_HEDLEY_VERSION_ENCODE(__PGIC__, __PGIC_MINOR__, __PGIC_PATCHLEVEL__) +#endif + +#if defined(JSON_HEDLEY_PGI_VERSION_CHECK) + #undef JSON_HEDLEY_PGI_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_PGI_VERSION) + #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PGI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_PGI_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_SUNPRO_VERSION) + #undef JSON_HEDLEY_SUNPRO_VERSION +#endif +#if defined(__SUNPRO_C) && (__SUNPRO_C > 0x1000) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_C >> 16) & 0xf) * 10) + ((__SUNPRO_C >> 12) & 0xf), (((__SUNPRO_C >> 8) & 0xf) * 10) + ((__SUNPRO_C >> 4) & 0xf), (__SUNPRO_C & 0xf) * 10) +#elif defined(__SUNPRO_C) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_C >> 8) & 0xf, (__SUNPRO_C >> 4) & 0xf, (__SUNPRO_C) & 0xf) +#elif defined(__SUNPRO_CC) && (__SUNPRO_CC > 0x1000) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((((__SUNPRO_CC >> 16) & 0xf) * 10) + ((__SUNPRO_CC >> 12) & 0xf), (((__SUNPRO_CC >> 8) & 0xf) * 10) + ((__SUNPRO_CC >> 4) & 0xf), (__SUNPRO_CC & 0xf) * 10) +#elif defined(__SUNPRO_CC) + #define JSON_HEDLEY_SUNPRO_VERSION JSON_HEDLEY_VERSION_ENCODE((__SUNPRO_CC >> 8) & 0xf, (__SUNPRO_CC >> 4) & 0xf, (__SUNPRO_CC) & 0xf) +#endif + +#if defined(JSON_HEDLEY_SUNPRO_VERSION_CHECK) + #undef JSON_HEDLEY_SUNPRO_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_SUNPRO_VERSION) + #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_SUNPRO_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_SUNPRO_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) + #undef JSON_HEDLEY_EMSCRIPTEN_VERSION +#endif +#if defined(__EMSCRIPTEN__) + #define JSON_HEDLEY_EMSCRIPTEN_VERSION JSON_HEDLEY_VERSION_ENCODE(__EMSCRIPTEN_major__, __EMSCRIPTEN_minor__, __EMSCRIPTEN_tiny__) +#endif + +#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK) + #undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_EMSCRIPTEN_VERSION) + #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_EMSCRIPTEN_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_ARM_VERSION) + #undef JSON_HEDLEY_ARM_VERSION +#endif +#if defined(__CC_ARM) && defined(__ARMCOMPILER_VERSION) + #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCOMPILER_VERSION / 1000000, (__ARMCOMPILER_VERSION % 1000000) / 10000, (__ARMCOMPILER_VERSION % 10000) / 100) +#elif defined(__CC_ARM) && defined(__ARMCC_VERSION) + #define JSON_HEDLEY_ARM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ARMCC_VERSION / 1000000, (__ARMCC_VERSION % 1000000) / 10000, (__ARMCC_VERSION % 10000) / 100) +#endif + +#if defined(JSON_HEDLEY_ARM_VERSION_CHECK) + #undef JSON_HEDLEY_ARM_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_ARM_VERSION) + #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_ARM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_ARM_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_IBM_VERSION) + #undef JSON_HEDLEY_IBM_VERSION +#endif +#if defined(__ibmxl__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__ibmxl_version__, __ibmxl_release__, __ibmxl_modification__) +#elif defined(__xlC__) && defined(__xlC_ver__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, (__xlC_ver__ >> 8) & 0xff) +#elif defined(__xlC__) + #define JSON_HEDLEY_IBM_VERSION JSON_HEDLEY_VERSION_ENCODE(__xlC__ >> 8, __xlC__ & 0xff, 0) +#endif + +#if defined(JSON_HEDLEY_IBM_VERSION_CHECK) + #undef JSON_HEDLEY_IBM_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_IBM_VERSION) + #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IBM_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_IBM_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_VERSION) + #undef JSON_HEDLEY_TI_VERSION +#endif +#if \ + defined(__TI_COMPILER_VERSION__) && \ + ( \ + defined(__TMS470__) || defined(__TI_ARM__) || \ + defined(__MSP430__) || \ + defined(__TMS320C2000__) \ + ) +#if (__TI_COMPILER_VERSION__ >= 16000000) + #define JSON_HEDLEY_TI_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif +#endif + +#if defined(JSON_HEDLEY_TI_VERSION_CHECK) + #undef JSON_HEDLEY_TI_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_VERSION) + #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_CL2000_VERSION) + #undef JSON_HEDLEY_TI_CL2000_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C2000__) + #define JSON_HEDLEY_TI_CL2000_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_CL2000_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_CL2000_VERSION) + #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL2000_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_CL2000_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_CL430_VERSION) + #undef JSON_HEDLEY_TI_CL430_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && defined(__MSP430__) + #define JSON_HEDLEY_TI_CL430_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_CL430_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL430_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_CL430_VERSION) + #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL430_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_CL430_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_ARMCL_VERSION) + #undef JSON_HEDLEY_TI_ARMCL_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && (defined(__TMS470__) || defined(__TI_ARM__)) + #define JSON_HEDLEY_TI_ARMCL_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_ARMCL_VERSION_CHECK) + #undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_ARMCL_VERSION) + #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_ARMCL_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_CL6X_VERSION) + #undef JSON_HEDLEY_TI_CL6X_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && defined(__TMS320C6X__) + #define JSON_HEDLEY_TI_CL6X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_CL6X_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_CL6X_VERSION) + #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL6X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_CL6X_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_CL7X_VERSION) + #undef JSON_HEDLEY_TI_CL7X_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && defined(__C7000__) + #define JSON_HEDLEY_TI_CL7X_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_CL7X_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_CL7X_VERSION) + #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CL7X_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_CL7X_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TI_CLPRU_VERSION) + #undef JSON_HEDLEY_TI_CLPRU_VERSION +#endif +#if defined(__TI_COMPILER_VERSION__) && defined(__PRU__) + #define JSON_HEDLEY_TI_CLPRU_VERSION JSON_HEDLEY_VERSION_ENCODE(__TI_COMPILER_VERSION__ / 1000000, (__TI_COMPILER_VERSION__ % 1000000) / 1000, (__TI_COMPILER_VERSION__ % 1000)) +#endif + +#if defined(JSON_HEDLEY_TI_CLPRU_VERSION_CHECK) + #undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TI_CLPRU_VERSION) + #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TI_CLPRU_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_CRAY_VERSION) + #undef JSON_HEDLEY_CRAY_VERSION +#endif +#if defined(_CRAYC) + #if defined(_RELEASE_PATCHLEVEL) + #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, _RELEASE_PATCHLEVEL) + #else + #define JSON_HEDLEY_CRAY_VERSION JSON_HEDLEY_VERSION_ENCODE(_RELEASE_MAJOR, _RELEASE_MINOR, 0) + #endif +#endif + +#if defined(JSON_HEDLEY_CRAY_VERSION_CHECK) + #undef JSON_HEDLEY_CRAY_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_CRAY_VERSION) + #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_CRAY_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_CRAY_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_IAR_VERSION) + #undef JSON_HEDLEY_IAR_VERSION +#endif +#if defined(__IAR_SYSTEMS_ICC__) + #if __VER__ > 1000 + #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE((__VER__ / 1000000), ((__VER__ / 1000) % 1000), (__VER__ % 1000)) + #else + #define JSON_HEDLEY_IAR_VERSION JSON_HEDLEY_VERSION_ENCODE(__VER__ / 100, __VER__ % 100, 0) + #endif +#endif + +#if defined(JSON_HEDLEY_IAR_VERSION_CHECK) + #undef JSON_HEDLEY_IAR_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_IAR_VERSION) + #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_IAR_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_IAR_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_TINYC_VERSION) + #undef JSON_HEDLEY_TINYC_VERSION +#endif +#if defined(__TINYC__) + #define JSON_HEDLEY_TINYC_VERSION JSON_HEDLEY_VERSION_ENCODE(__TINYC__ / 1000, (__TINYC__ / 100) % 10, __TINYC__ % 100) +#endif + +#if defined(JSON_HEDLEY_TINYC_VERSION_CHECK) + #undef JSON_HEDLEY_TINYC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_TINYC_VERSION) + #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_TINYC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_TINYC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_DMC_VERSION) + #undef JSON_HEDLEY_DMC_VERSION +#endif +#if defined(__DMC__) + #define JSON_HEDLEY_DMC_VERSION JSON_HEDLEY_VERSION_ENCODE(__DMC__ >> 8, (__DMC__ >> 4) & 0xf, __DMC__ & 0xf) +#endif + +#if defined(JSON_HEDLEY_DMC_VERSION_CHECK) + #undef JSON_HEDLEY_DMC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_DMC_VERSION) + #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_DMC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_DMC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_COMPCERT_VERSION) + #undef JSON_HEDLEY_COMPCERT_VERSION +#endif +#if defined(__COMPCERT_VERSION__) + #define JSON_HEDLEY_COMPCERT_VERSION JSON_HEDLEY_VERSION_ENCODE(__COMPCERT_VERSION__ / 10000, (__COMPCERT_VERSION__ / 100) % 100, __COMPCERT_VERSION__ % 100) +#endif + +#if defined(JSON_HEDLEY_COMPCERT_VERSION_CHECK) + #undef JSON_HEDLEY_COMPCERT_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_COMPCERT_VERSION) + #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_COMPCERT_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_COMPCERT_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_PELLES_VERSION) + #undef JSON_HEDLEY_PELLES_VERSION +#endif +#if defined(__POCC__) + #define JSON_HEDLEY_PELLES_VERSION JSON_HEDLEY_VERSION_ENCODE(__POCC__ / 100, __POCC__ % 100, 0) +#endif + +#if defined(JSON_HEDLEY_PELLES_VERSION_CHECK) + #undef JSON_HEDLEY_PELLES_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_PELLES_VERSION) + #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_PELLES_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_PELLES_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_MCST_LCC_VERSION) + #undef JSON_HEDLEY_MCST_LCC_VERSION +#endif +#if defined(__LCC__) && defined(__LCC_MINOR__) + #define JSON_HEDLEY_MCST_LCC_VERSION JSON_HEDLEY_VERSION_ENCODE(__LCC__ / 100, __LCC__ % 100, __LCC_MINOR__) +#endif + +#if defined(JSON_HEDLEY_MCST_LCC_VERSION_CHECK) + #undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_MCST_LCC_VERSION) + #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_MCST_LCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_MCST_LCC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_GCC_VERSION) + #undef JSON_HEDLEY_GCC_VERSION +#endif +#if \ + defined(JSON_HEDLEY_GNUC_VERSION) && \ + !defined(__clang__) && \ + !defined(JSON_HEDLEY_INTEL_VERSION) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_ARM_VERSION) && \ + !defined(JSON_HEDLEY_CRAY_VERSION) && \ + !defined(JSON_HEDLEY_TI_VERSION) && \ + !defined(JSON_HEDLEY_TI_ARMCL_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL430_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL2000_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL6X_VERSION) && \ + !defined(JSON_HEDLEY_TI_CL7X_VERSION) && \ + !defined(JSON_HEDLEY_TI_CLPRU_VERSION) && \ + !defined(__COMPCERT__) && \ + !defined(JSON_HEDLEY_MCST_LCC_VERSION) + #define JSON_HEDLEY_GCC_VERSION JSON_HEDLEY_GNUC_VERSION +#endif + +#if defined(JSON_HEDLEY_GCC_VERSION_CHECK) + #undef JSON_HEDLEY_GCC_VERSION_CHECK +#endif +#if defined(JSON_HEDLEY_GCC_VERSION) + #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (JSON_HEDLEY_GCC_VERSION >= JSON_HEDLEY_VERSION_ENCODE(major, minor, patch)) +#else + #define JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) (0) +#endif + +#if defined(JSON_HEDLEY_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_ATTRIBUTE +#endif +#if \ + defined(__has_attribute) && \ + ( \ + (!defined(JSON_HEDLEY_IAR_VERSION) || JSON_HEDLEY_IAR_VERSION_CHECK(8,5,9)) \ + ) +# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) __has_attribute(attribute) +#else +# define JSON_HEDLEY_HAS_ATTRIBUTE(attribute) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE +#endif +#if defined(__has_attribute) + #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) +#else + #define JSON_HEDLEY_GNUC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE +#endif +#if defined(__has_attribute) + #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) +#else + #define JSON_HEDLEY_GCC_HAS_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE +#endif +#if \ + defined(__has_cpp_attribute) && \ + defined(__cplusplus) && \ + (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) __has_cpp_attribute(attribute) +#else + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) (0) +#endif + +#if defined(JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS) + #undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS +#endif +#if !defined(__cplusplus) || !defined(__has_cpp_attribute) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) +#elif \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_IAR_VERSION) && \ + (!defined(JSON_HEDLEY_SUNPRO_VERSION) || JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0)) && \ + (!defined(JSON_HEDLEY_MSVC_VERSION) || JSON_HEDLEY_MSVC_VERSION_CHECK(19,20,0)) + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(ns::attribute) +#else + #define JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(ns,attribute) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE +#endif +#if defined(__has_cpp_attribute) && defined(__cplusplus) + #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) +#else + #define JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE +#endif +#if defined(__has_cpp_attribute) && defined(__cplusplus) + #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) __has_cpp_attribute(attribute) +#else + #define JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_BUILTIN) + #undef JSON_HEDLEY_HAS_BUILTIN +#endif +#if defined(__has_builtin) + #define JSON_HEDLEY_HAS_BUILTIN(builtin) __has_builtin(builtin) +#else + #define JSON_HEDLEY_HAS_BUILTIN(builtin) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_BUILTIN) + #undef JSON_HEDLEY_GNUC_HAS_BUILTIN +#endif +#if defined(__has_builtin) + #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) +#else + #define JSON_HEDLEY_GNUC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_BUILTIN) + #undef JSON_HEDLEY_GCC_HAS_BUILTIN +#endif +#if defined(__has_builtin) + #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) __has_builtin(builtin) +#else + #define JSON_HEDLEY_GCC_HAS_BUILTIN(builtin,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_FEATURE) + #undef JSON_HEDLEY_HAS_FEATURE +#endif +#if defined(__has_feature) + #define JSON_HEDLEY_HAS_FEATURE(feature) __has_feature(feature) +#else + #define JSON_HEDLEY_HAS_FEATURE(feature) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_FEATURE) + #undef JSON_HEDLEY_GNUC_HAS_FEATURE +#endif +#if defined(__has_feature) + #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) +#else + #define JSON_HEDLEY_GNUC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_FEATURE) + #undef JSON_HEDLEY_GCC_HAS_FEATURE +#endif +#if defined(__has_feature) + #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) __has_feature(feature) +#else + #define JSON_HEDLEY_GCC_HAS_FEATURE(feature,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_EXTENSION) + #undef JSON_HEDLEY_HAS_EXTENSION +#endif +#if defined(__has_extension) + #define JSON_HEDLEY_HAS_EXTENSION(extension) __has_extension(extension) +#else + #define JSON_HEDLEY_HAS_EXTENSION(extension) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_EXTENSION) + #undef JSON_HEDLEY_GNUC_HAS_EXTENSION +#endif +#if defined(__has_extension) + #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) +#else + #define JSON_HEDLEY_GNUC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_EXTENSION) + #undef JSON_HEDLEY_GCC_HAS_EXTENSION +#endif +#if defined(__has_extension) + #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) __has_extension(extension) +#else + #define JSON_HEDLEY_GCC_HAS_EXTENSION(extension,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE +#endif +#if defined(__has_declspec_attribute) + #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) __has_declspec_attribute(attribute) +#else + #define JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE +#endif +#if defined(__has_declspec_attribute) + #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) +#else + #define JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE +#endif +#if defined(__has_declspec_attribute) + #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) __has_declspec_attribute(attribute) +#else + #define JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE(attribute,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_HAS_WARNING) + #undef JSON_HEDLEY_HAS_WARNING +#endif +#if defined(__has_warning) + #define JSON_HEDLEY_HAS_WARNING(warning) __has_warning(warning) +#else + #define JSON_HEDLEY_HAS_WARNING(warning) (0) +#endif + +#if defined(JSON_HEDLEY_GNUC_HAS_WARNING) + #undef JSON_HEDLEY_GNUC_HAS_WARNING +#endif +#if defined(__has_warning) + #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) +#else + #define JSON_HEDLEY_GNUC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GNUC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_GCC_HAS_WARNING) + #undef JSON_HEDLEY_GCC_HAS_WARNING +#endif +#if defined(__has_warning) + #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) __has_warning(warning) +#else + #define JSON_HEDLEY_GCC_HAS_WARNING(warning,major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ + defined(__clang__) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,0,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,17) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(8,0,0) || \ + (JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) && defined(__C99_PRAGMA_OPERATOR)) + #define JSON_HEDLEY_PRAGMA(value) _Pragma(#value) +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_PRAGMA(value) __pragma(value) +#else + #define JSON_HEDLEY_PRAGMA(value) +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_PUSH) + #undef JSON_HEDLEY_DIAGNOSTIC_PUSH +#endif +#if defined(JSON_HEDLEY_DIAGNOSTIC_POP) + #undef JSON_HEDLEY_DIAGNOSTIC_POP +#endif +#if defined(__clang__) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("clang diagnostic push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("clang diagnostic pop") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("GCC diagnostic push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("GCC diagnostic pop") +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH __pragma(warning(push)) + #define JSON_HEDLEY_DIAGNOSTIC_POP __pragma(warning(pop)) +#elif JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("pop") +#elif \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,4,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("diag_push") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("diag_pop") +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) + #define JSON_HEDLEY_DIAGNOSTIC_PUSH _Pragma("warning(push)") + #define JSON_HEDLEY_DIAGNOSTIC_POP _Pragma("warning(pop)") +#else + #define JSON_HEDLEY_DIAGNOSTIC_PUSH + #define JSON_HEDLEY_DIAGNOSTIC_POP +#endif + +/* JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ is for + HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ +#endif +#if defined(__cplusplus) +# if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat") +# if JSON_HEDLEY_HAS_WARNING("-Wc++17-extensions") +# if JSON_HEDLEY_HAS_WARNING("-Wc++1z-extensions") +# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ + _Pragma("clang diagnostic ignored \"-Wc++1z-extensions\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP +# else +# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + _Pragma("clang diagnostic ignored \"-Wc++17-extensions\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP +# endif +# else +# define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(xpr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wc++98-compat\"") \ + xpr \ + JSON_HEDLEY_DIAGNOSTIC_POP +# endif +# endif +#endif +#if !defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(x) x +#endif + +#if defined(JSON_HEDLEY_CONST_CAST) + #undef JSON_HEDLEY_CONST_CAST +#endif +#if defined(__cplusplus) +# define JSON_HEDLEY_CONST_CAST(T, expr) (const_cast(expr)) +#elif \ + JSON_HEDLEY_HAS_WARNING("-Wcast-qual") || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) +# define JSON_HEDLEY_CONST_CAST(T, expr) (__extension__ ({ \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL \ + ((T) (expr)); \ + JSON_HEDLEY_DIAGNOSTIC_POP \ + })) +#else +# define JSON_HEDLEY_CONST_CAST(T, expr) ((T) (expr)) +#endif + +#if defined(JSON_HEDLEY_REINTERPRET_CAST) + #undef JSON_HEDLEY_REINTERPRET_CAST +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) (reinterpret_cast(expr)) +#else + #define JSON_HEDLEY_REINTERPRET_CAST(T, expr) ((T) (expr)) +#endif + +#if defined(JSON_HEDLEY_STATIC_CAST) + #undef JSON_HEDLEY_STATIC_CAST +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_STATIC_CAST(T, expr) (static_cast(expr)) +#else + #define JSON_HEDLEY_STATIC_CAST(T, expr) ((T) (expr)) +#endif + +#if defined(JSON_HEDLEY_CPP_CAST) + #undef JSON_HEDLEY_CPP_CAST +#endif +#if defined(__cplusplus) +# if JSON_HEDLEY_HAS_WARNING("-Wold-style-cast") +# define JSON_HEDLEY_CPP_CAST(T, expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wold-style-cast\"") \ + ((T) (expr)) \ + JSON_HEDLEY_DIAGNOSTIC_POP +# elif JSON_HEDLEY_IAR_VERSION_CHECK(8,3,0) +# define JSON_HEDLEY_CPP_CAST(T, expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("diag_suppress=Pe137") \ + JSON_HEDLEY_DIAGNOSTIC_POP +# else +# define JSON_HEDLEY_CPP_CAST(T, expr) ((T) (expr)) +# endif +#else +# define JSON_HEDLEY_CPP_CAST(T, expr) (expr) +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wdeprecated-declarations") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warning(disable:1478 1786)") +#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:1478 1786)) +#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1216,1444,1445") +#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED __pragma(warning(disable:4996)) +#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1215,1444") +#elif \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress 1291,1718") +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && !defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,E_DEPRECATED_ATT,E_DEPRECATED_ATT_MESS)") +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) && defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("error_messages(off,symdeprecated,symdeprecated2)") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("diag_suppress=Pe1444,Pe1215") +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,90,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED _Pragma("warn(disable:2241)") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("clang diagnostic ignored \"-Wunknown-pragmas\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("warning(disable:161)") +#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:161)) +#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 1675") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("GCC diagnostic ignored \"-Wunknown-pragmas\"") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS __pragma(warning(disable:4068)) +#elif \ + JSON_HEDLEY_TI_VERSION_CHECK(16,9,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") +#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 163") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress=Pe161") +#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS _Pragma("diag_suppress 161") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-attributes") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("clang diagnostic ignored \"-Wunknown-attributes\"") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(4,6,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("warning(disable:1292)") +#elif JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:1292)) +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES __pragma(warning(disable:5030)) +#elif JSON_HEDLEY_PGI_VERSION_CHECK(20,7,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097,1098") +#elif JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("error_messages(off,attrskipunsup)") +#elif \ + JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1173") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress=Pe1097") +#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES _Pragma("diag_suppress 1097") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wcast-qual") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("clang diagnostic ignored \"-Wcast-qual\"") +#elif JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("warning(disable:2203 2331)") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL _Pragma("GCC diagnostic ignored \"-Wcast-qual\"") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL +#endif + +#if defined(JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION) + #undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunused-function") + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("clang diagnostic ignored \"-Wunused-function\"") +#elif JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("GCC diagnostic ignored \"-Wunused-function\"") +#elif JSON_HEDLEY_MSVC_VERSION_CHECK(1,0,0) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION __pragma(warning(disable:4505)) +#elif JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION _Pragma("diag_suppress 3142") +#else + #define JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION +#endif + +#if defined(JSON_HEDLEY_DEPRECATED) + #undef JSON_HEDLEY_DEPRECATED +#endif +#if defined(JSON_HEDLEY_DEPRECATED_FOR) + #undef JSON_HEDLEY_DEPRECATED_FOR +#endif +#if \ + JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated("Since " # since)) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated("Since " #since "; use " #replacement)) +#elif \ + (JSON_HEDLEY_HAS_EXTENSION(attribute_deprecated_with_message) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,13,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(18,1,0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(18,1,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,3,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,3,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__("Since " #since))) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__("Since " #since "; use " #replacement))) +#elif defined(__cplusplus) && (__cplusplus >= 201402L) + #define JSON_HEDLEY_DEPRECATED(since) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since)]]) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[deprecated("Since " #since "; use " #replacement)]]) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(deprecated) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) + #define JSON_HEDLEY_DEPRECATED(since) __attribute__((__deprecated__)) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __attribute__((__deprecated__)) +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ + JSON_HEDLEY_PELLES_VERSION_CHECK(6,50,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_DEPRECATED(since) __declspec(deprecated) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) __declspec(deprecated) +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_DEPRECATED(since) _Pragma("deprecated") + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) _Pragma("deprecated") +#else + #define JSON_HEDLEY_DEPRECATED(since) + #define JSON_HEDLEY_DEPRECATED_FOR(since, replacement) +#endif + +#if defined(JSON_HEDLEY_UNAVAILABLE) + #undef JSON_HEDLEY_UNAVAILABLE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(warning) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,3,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_UNAVAILABLE(available_since) __attribute__((__warning__("Not available until " #available_since))) +#else + #define JSON_HEDLEY_UNAVAILABLE(available_since) +#endif + +#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT) + #undef JSON_HEDLEY_WARN_UNUSED_RESULT +#endif +#if defined(JSON_HEDLEY_WARN_UNUSED_RESULT_MSG) + #undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(warn_unused_result) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_WARN_UNUSED_RESULT __attribute__((__warn_unused_result__)) + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) __attribute__((__warn_unused_result__)) +#elif (JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) >= 201907L) + #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard(msg)]]) +#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(nodiscard) + #define JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[nodiscard]]) +#elif defined(_Check_return_) /* SAL */ + #define JSON_HEDLEY_WARN_UNUSED_RESULT _Check_return_ + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) _Check_return_ +#else + #define JSON_HEDLEY_WARN_UNUSED_RESULT + #define JSON_HEDLEY_WARN_UNUSED_RESULT_MSG(msg) +#endif + +#if defined(JSON_HEDLEY_SENTINEL) + #undef JSON_HEDLEY_SENTINEL +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(sentinel) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_SENTINEL(position) __attribute__((__sentinel__(position))) +#else + #define JSON_HEDLEY_SENTINEL(position) +#endif + +#if defined(JSON_HEDLEY_NO_RETURN) + #undef JSON_HEDLEY_NO_RETURN +#endif +#if JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_NO_RETURN __noreturn +#elif \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) +#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L + #define JSON_HEDLEY_NO_RETURN _Noreturn +#elif defined(__cplusplus) && (__cplusplus >= 201103L) + #define JSON_HEDLEY_NO_RETURN JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[noreturn]]) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(noreturn) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,2,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) + #define JSON_HEDLEY_NO_RETURN __attribute__((__noreturn__)) +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_NO_RETURN _Pragma("does_not_return") +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) +#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus) + #define JSON_HEDLEY_NO_RETURN _Pragma("FUNC_NEVER_RETURNS;") +#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) + #define JSON_HEDLEY_NO_RETURN __attribute((noreturn)) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) + #define JSON_HEDLEY_NO_RETURN __declspec(noreturn) +#else + #define JSON_HEDLEY_NO_RETURN +#endif + +#if defined(JSON_HEDLEY_NO_ESCAPE) + #undef JSON_HEDLEY_NO_ESCAPE +#endif +#if JSON_HEDLEY_HAS_ATTRIBUTE(noescape) + #define JSON_HEDLEY_NO_ESCAPE __attribute__((__noescape__)) +#else + #define JSON_HEDLEY_NO_ESCAPE +#endif + +#if defined(JSON_HEDLEY_UNREACHABLE) + #undef JSON_HEDLEY_UNREACHABLE +#endif +#if defined(JSON_HEDLEY_UNREACHABLE_RETURN) + #undef JSON_HEDLEY_UNREACHABLE_RETURN +#endif +#if defined(JSON_HEDLEY_ASSUME) + #undef JSON_HEDLEY_ASSUME +#endif +#if \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_ASSUME(expr) __assume(expr) +#elif JSON_HEDLEY_HAS_BUILTIN(__builtin_assume) + #define JSON_HEDLEY_ASSUME(expr) __builtin_assume(expr) +#elif \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) + #if defined(__cplusplus) + #define JSON_HEDLEY_ASSUME(expr) std::_nassert(expr) + #else + #define JSON_HEDLEY_ASSUME(expr) _nassert(expr) + #endif +#endif +#if \ + (JSON_HEDLEY_HAS_BUILTIN(__builtin_unreachable) && (!defined(JSON_HEDLEY_ARM_VERSION))) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,5,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18,10,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,5) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(10,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_UNREACHABLE() __builtin_unreachable() +#elif defined(JSON_HEDLEY_ASSUME) + #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) +#endif +#if !defined(JSON_HEDLEY_ASSUME) + #if defined(JSON_HEDLEY_UNREACHABLE) + #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, ((expr) ? 1 : (JSON_HEDLEY_UNREACHABLE(), 1))) + #else + #define JSON_HEDLEY_ASSUME(expr) JSON_HEDLEY_STATIC_CAST(void, expr) + #endif +#endif +#if defined(JSON_HEDLEY_UNREACHABLE) + #if \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (JSON_HEDLEY_STATIC_CAST(void, JSON_HEDLEY_ASSUME(0)), (value)) + #else + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) JSON_HEDLEY_UNREACHABLE() + #endif +#else + #define JSON_HEDLEY_UNREACHABLE_RETURN(value) return (value) +#endif +#if !defined(JSON_HEDLEY_UNREACHABLE) + #define JSON_HEDLEY_UNREACHABLE() JSON_HEDLEY_ASSUME(0) +#endif + +JSON_HEDLEY_DIAGNOSTIC_PUSH +#if JSON_HEDLEY_HAS_WARNING("-Wpedantic") + #pragma clang diagnostic ignored "-Wpedantic" +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wc++98-compat-pedantic") && defined(__cplusplus) + #pragma clang diagnostic ignored "-Wc++98-compat-pedantic" +#endif +#if JSON_HEDLEY_GCC_HAS_WARNING("-Wvariadic-macros",4,0,0) + #if defined(__clang__) + #pragma clang diagnostic ignored "-Wvariadic-macros" + #elif defined(JSON_HEDLEY_GCC_VERSION) + #pragma GCC diagnostic ignored "-Wvariadic-macros" + #endif +#endif +#if defined(JSON_HEDLEY_NON_NULL) + #undef JSON_HEDLEY_NON_NULL +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(nonnull) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) + #define JSON_HEDLEY_NON_NULL(...) __attribute__((__nonnull__(__VA_ARGS__))) +#else + #define JSON_HEDLEY_NON_NULL(...) +#endif +JSON_HEDLEY_DIAGNOSTIC_POP + +#if defined(JSON_HEDLEY_PRINTF_FORMAT) + #undef JSON_HEDLEY_PRINTF_FORMAT +#endif +#if defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && !defined(__USE_MINGW_ANSI_STDIO) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(ms_printf, string_idx, first_to_check))) +#elif defined(__MINGW32__) && JSON_HEDLEY_GCC_HAS_ATTRIBUTE(format,4,4,0) && defined(__USE_MINGW_ANSI_STDIO) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(gnu_printf, string_idx, first_to_check))) +#elif \ + JSON_HEDLEY_HAS_ATTRIBUTE(format) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,6,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __attribute__((__format__(__printf__, string_idx, first_to_check))) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(6,0,0) + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) __declspec(vaformat(printf,string_idx,first_to_check)) +#else + #define JSON_HEDLEY_PRINTF_FORMAT(string_idx,first_to_check) +#endif + +#if defined(JSON_HEDLEY_CONSTEXPR) + #undef JSON_HEDLEY_CONSTEXPR +#endif +#if defined(__cplusplus) + #if __cplusplus >= 201103L + #define JSON_HEDLEY_CONSTEXPR JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(constexpr) + #endif +#endif +#if !defined(JSON_HEDLEY_CONSTEXPR) + #define JSON_HEDLEY_CONSTEXPR +#endif + +#if defined(JSON_HEDLEY_PREDICT) + #undef JSON_HEDLEY_PREDICT +#endif +#if defined(JSON_HEDLEY_LIKELY) + #undef JSON_HEDLEY_LIKELY +#endif +#if defined(JSON_HEDLEY_UNLIKELY) + #undef JSON_HEDLEY_UNLIKELY +#endif +#if defined(JSON_HEDLEY_UNPREDICTABLE) + #undef JSON_HEDLEY_UNPREDICTABLE +#endif +#if JSON_HEDLEY_HAS_BUILTIN(__builtin_unpredictable) + #define JSON_HEDLEY_UNPREDICTABLE(expr) __builtin_unpredictable((expr)) +#endif +#if \ + (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect_with_probability) && !defined(JSON_HEDLEY_PGI_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(9,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) +# define JSON_HEDLEY_PREDICT(expr, value, probability) __builtin_expect_with_probability( (expr), (value), (probability)) +# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) __builtin_expect_with_probability(!!(expr), 1 , (probability)) +# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) __builtin_expect_with_probability(!!(expr), 0 , (probability)) +# define JSON_HEDLEY_LIKELY(expr) __builtin_expect (!!(expr), 1 ) +# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect (!!(expr), 0 ) +#elif \ + (JSON_HEDLEY_HAS_BUILTIN(__builtin_expect) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,15,0) && defined(__cplusplus)) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,7,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,1,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,27) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) +# define JSON_HEDLEY_PREDICT(expr, expected, probability) \ + (((probability) >= 0.9) ? __builtin_expect((expr), (expected)) : (JSON_HEDLEY_STATIC_CAST(void, expected), (expr))) +# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) \ + (__extension__ ({ \ + double hedley_probability_ = (probability); \ + ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 1) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 0) : !!(expr))); \ + })) +# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) \ + (__extension__ ({ \ + double hedley_probability_ = (probability); \ + ((hedley_probability_ >= 0.9) ? __builtin_expect(!!(expr), 0) : ((hedley_probability_ <= 0.1) ? __builtin_expect(!!(expr), 1) : !!(expr))); \ + })) +# define JSON_HEDLEY_LIKELY(expr) __builtin_expect(!!(expr), 1) +# define JSON_HEDLEY_UNLIKELY(expr) __builtin_expect(!!(expr), 0) +#else +# define JSON_HEDLEY_PREDICT(expr, expected, probability) (JSON_HEDLEY_STATIC_CAST(void, expected), (expr)) +# define JSON_HEDLEY_PREDICT_TRUE(expr, probability) (!!(expr)) +# define JSON_HEDLEY_PREDICT_FALSE(expr, probability) (!!(expr)) +# define JSON_HEDLEY_LIKELY(expr) (!!(expr)) +# define JSON_HEDLEY_UNLIKELY(expr) (!!(expr)) +#endif +#if !defined(JSON_HEDLEY_UNPREDICTABLE) + #define JSON_HEDLEY_UNPREDICTABLE(expr) JSON_HEDLEY_PREDICT(expr, 1, 0.5) +#endif + +#if defined(JSON_HEDLEY_MALLOC) + #undef JSON_HEDLEY_MALLOC +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(malloc) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_MALLOC __attribute__((__malloc__)) +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_MALLOC _Pragma("returns_new_memory") +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_MALLOC __declspec(restrict) +#else + #define JSON_HEDLEY_MALLOC +#endif + +#if defined(JSON_HEDLEY_PURE) + #undef JSON_HEDLEY_PURE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(pure) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(2,96,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) +# define JSON_HEDLEY_PURE __attribute__((__pure__)) +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) +# define JSON_HEDLEY_PURE _Pragma("does_not_write_global_data") +#elif defined(__cplusplus) && \ + ( \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(2,0,1) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) \ + ) +# define JSON_HEDLEY_PURE _Pragma("FUNC_IS_PURE;") +#else +# define JSON_HEDLEY_PURE +#endif + +#if defined(JSON_HEDLEY_CONST) + #undef JSON_HEDLEY_CONST +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(const) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(2,5,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_CONST __attribute__((__const__)) +#elif \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) + #define JSON_HEDLEY_CONST _Pragma("no_side_effect") +#else + #define JSON_HEDLEY_CONST JSON_HEDLEY_PURE +#endif + +#if defined(JSON_HEDLEY_RESTRICT) + #undef JSON_HEDLEY_RESTRICT +#endif +#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && !defined(__cplusplus) + #define JSON_HEDLEY_RESTRICT restrict +#elif \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_MSVC_VERSION_CHECK(14,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(17,10,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,4) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,14,0) && defined(__cplusplus)) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) || \ + defined(__clang__) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_RESTRICT __restrict +#elif JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,3,0) && !defined(__cplusplus) + #define JSON_HEDLEY_RESTRICT _Restrict +#else + #define JSON_HEDLEY_RESTRICT +#endif + +#if defined(JSON_HEDLEY_INLINE) + #undef JSON_HEDLEY_INLINE +#endif +#if \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L)) || \ + (defined(__cplusplus) && (__cplusplus >= 199711L)) + #define JSON_HEDLEY_INLINE inline +#elif \ + defined(JSON_HEDLEY_GCC_VERSION) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(6,2,0) + #define JSON_HEDLEY_INLINE __inline__ +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,1,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(3,1,0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,2,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(8,0,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_INLINE __inline +#else + #define JSON_HEDLEY_INLINE +#endif + +#if defined(JSON_HEDLEY_ALWAYS_INLINE) + #undef JSON_HEDLEY_ALWAYS_INLINE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(always_inline) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) +# define JSON_HEDLEY_ALWAYS_INLINE __attribute__((__always_inline__)) JSON_HEDLEY_INLINE +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(12,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) +# define JSON_HEDLEY_ALWAYS_INLINE __forceinline +#elif defined(__cplusplus) && \ + ( \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) \ + ) +# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("FUNC_ALWAYS_INLINE;") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) +# define JSON_HEDLEY_ALWAYS_INLINE _Pragma("inline=forced") +#else +# define JSON_HEDLEY_ALWAYS_INLINE JSON_HEDLEY_INLINE +#endif + +#if defined(JSON_HEDLEY_NEVER_INLINE) + #undef JSON_HEDLEY_NEVER_INLINE +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(noinline) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(10,1,0) || \ + JSON_HEDLEY_TI_VERSION_CHECK(15,12,0) || \ + (JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(4,8,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_ARMCL_VERSION_CHECK(5,2,0) || \ + (JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL2000_VERSION_CHECK(6,4,0) || \ + (JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,0,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(4,3,0) || \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) || \ + JSON_HEDLEY_TI_CL7X_VERSION_CHECK(1,2,0) || \ + JSON_HEDLEY_TI_CLPRU_VERSION_CHECK(2,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) || \ + JSON_HEDLEY_IAR_VERSION_CHECK(8,10,0) + #define JSON_HEDLEY_NEVER_INLINE __attribute__((__noinline__)) +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,10,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) +#elif JSON_HEDLEY_PGI_VERSION_CHECK(10,2,0) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("noinline") +#elif JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,0,0) && defined(__cplusplus) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("FUNC_CANNOT_INLINE;") +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) + #define JSON_HEDLEY_NEVER_INLINE _Pragma("inline=never") +#elif JSON_HEDLEY_COMPCERT_VERSION_CHECK(3,2,0) + #define JSON_HEDLEY_NEVER_INLINE __attribute((noinline)) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(9,0,0) + #define JSON_HEDLEY_NEVER_INLINE __declspec(noinline) +#else + #define JSON_HEDLEY_NEVER_INLINE +#endif + +#if defined(JSON_HEDLEY_PRIVATE) + #undef JSON_HEDLEY_PRIVATE +#endif +#if defined(JSON_HEDLEY_PUBLIC) + #undef JSON_HEDLEY_PUBLIC +#endif +#if defined(JSON_HEDLEY_IMPORT) + #undef JSON_HEDLEY_IMPORT +#endif +#if defined(_WIN32) || defined(__CYGWIN__) +# define JSON_HEDLEY_PRIVATE +# define JSON_HEDLEY_PUBLIC __declspec(dllexport) +# define JSON_HEDLEY_IMPORT __declspec(dllimport) +#else +# if \ + JSON_HEDLEY_HAS_ATTRIBUTE(visibility) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ + JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,11,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ + ( \ + defined(__TI_EABI__) && \ + ( \ + (JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,2,0) && defined(__TI_GNU_ATTRIBUTE_SUPPORT__)) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(7,5,0) \ + ) \ + ) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) +# define JSON_HEDLEY_PRIVATE __attribute__((__visibility__("hidden"))) +# define JSON_HEDLEY_PUBLIC __attribute__((__visibility__("default"))) +# else +# define JSON_HEDLEY_PRIVATE +# define JSON_HEDLEY_PUBLIC +# endif +# define JSON_HEDLEY_IMPORT extern +#endif + +#if defined(JSON_HEDLEY_NO_THROW) + #undef JSON_HEDLEY_NO_THROW +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(nothrow) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,3,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_NO_THROW __attribute__((__nothrow__)) +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) + #define JSON_HEDLEY_NO_THROW __declspec(nothrow) +#else + #define JSON_HEDLEY_NO_THROW +#endif + +#if defined(JSON_HEDLEY_FALL_THROUGH) + #undef JSON_HEDLEY_FALL_THROUGH +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(fallthrough) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(7,0,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_FALL_THROUGH __attribute__((__fallthrough__)) +#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS(clang,fallthrough) + #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[clang::fallthrough]]) +#elif JSON_HEDLEY_HAS_CPP_ATTRIBUTE(fallthrough) + #define JSON_HEDLEY_FALL_THROUGH JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_([[fallthrough]]) +#elif defined(__fallthrough) /* SAL */ + #define JSON_HEDLEY_FALL_THROUGH __fallthrough +#else + #define JSON_HEDLEY_FALL_THROUGH +#endif + +#if defined(JSON_HEDLEY_RETURNS_NON_NULL) + #undef JSON_HEDLEY_RETURNS_NON_NULL +#endif +#if \ + JSON_HEDLEY_HAS_ATTRIBUTE(returns_nonnull) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_RETURNS_NON_NULL __attribute__((__returns_nonnull__)) +#elif defined(_Ret_notnull_) /* SAL */ + #define JSON_HEDLEY_RETURNS_NON_NULL _Ret_notnull_ +#else + #define JSON_HEDLEY_RETURNS_NON_NULL +#endif + +#if defined(JSON_HEDLEY_ARRAY_PARAM) + #undef JSON_HEDLEY_ARRAY_PARAM +#endif +#if \ + defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 199901L) && \ + !defined(__STDC_NO_VLA__) && \ + !defined(__cplusplus) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_TINYC_VERSION) + #define JSON_HEDLEY_ARRAY_PARAM(name) (name) +#else + #define JSON_HEDLEY_ARRAY_PARAM(name) +#endif + +#if defined(JSON_HEDLEY_IS_CONSTANT) + #undef JSON_HEDLEY_IS_CONSTANT +#endif +#if defined(JSON_HEDLEY_REQUIRE_CONSTEXPR) + #undef JSON_HEDLEY_REQUIRE_CONSTEXPR +#endif +/* JSON_HEDLEY_IS_CONSTEXPR_ is for + HEDLEY INTERNAL USE ONLY. API subject to change without notice. */ +#if defined(JSON_HEDLEY_IS_CONSTEXPR_) + #undef JSON_HEDLEY_IS_CONSTEXPR_ +#endif +#if \ + JSON_HEDLEY_HAS_BUILTIN(__builtin_constant_p) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,19) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(4,1,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_TI_CL6X_VERSION_CHECK(6,1,0) || \ + (JSON_HEDLEY_SUNPRO_VERSION_CHECK(5,10,0) && !defined(__cplusplus)) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_MCST_LCC_VERSION_CHECK(1,25,10) + #define JSON_HEDLEY_IS_CONSTANT(expr) __builtin_constant_p(expr) +#endif +#if !defined(__cplusplus) +# if \ + JSON_HEDLEY_HAS_BUILTIN(__builtin_types_compatible_p) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(3,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(13,1,0) || \ + JSON_HEDLEY_CRAY_VERSION_CHECK(8,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,4,0) || \ + JSON_HEDLEY_TINYC_VERSION_CHECK(0,9,24) +#if defined(__INTPTR_TYPE__) + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0)), int*) +#else + #include + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) __builtin_types_compatible_p(__typeof__((1 ? (void*) ((intptr_t) ((expr) * 0)) : (int*) 0)), int*) +#endif +# elif \ + ( \ + defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L) && \ + !defined(JSON_HEDLEY_SUNPRO_VERSION) && \ + !defined(JSON_HEDLEY_PGI_VERSION) && \ + !defined(JSON_HEDLEY_IAR_VERSION)) || \ + (JSON_HEDLEY_HAS_EXTENSION(c_generic_selections) && !defined(JSON_HEDLEY_IAR_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,9,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(17,0,0) || \ + JSON_HEDLEY_IBM_VERSION_CHECK(12,1,0) || \ + JSON_HEDLEY_ARM_VERSION_CHECK(5,3,0) +#if defined(__INTPTR_TYPE__) + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((__INTPTR_TYPE__) ((expr) * 0)) : (int*) 0), int*: 1, void*: 0) +#else + #include + #define JSON_HEDLEY_IS_CONSTEXPR_(expr) _Generic((1 ? (void*) ((intptr_t) * 0) : (int*) 0), int*: 1, void*: 0) +#endif +# elif \ + defined(JSON_HEDLEY_GCC_VERSION) || \ + defined(JSON_HEDLEY_INTEL_VERSION) || \ + defined(JSON_HEDLEY_TINYC_VERSION) || \ + defined(JSON_HEDLEY_TI_ARMCL_VERSION) || \ + JSON_HEDLEY_TI_CL430_VERSION_CHECK(18,12,0) || \ + defined(JSON_HEDLEY_TI_CL2000_VERSION) || \ + defined(JSON_HEDLEY_TI_CL6X_VERSION) || \ + defined(JSON_HEDLEY_TI_CL7X_VERSION) || \ + defined(JSON_HEDLEY_TI_CLPRU_VERSION) || \ + defined(__clang__) +# define JSON_HEDLEY_IS_CONSTEXPR_(expr) ( \ + sizeof(void) != \ + sizeof(*( \ + 1 ? \ + ((void*) ((expr) * 0L) ) : \ +((struct { char v[sizeof(void) * 2]; } *) 1) \ + ) \ + ) \ + ) +# endif +#endif +#if defined(JSON_HEDLEY_IS_CONSTEXPR_) + #if !defined(JSON_HEDLEY_IS_CONSTANT) + #define JSON_HEDLEY_IS_CONSTANT(expr) JSON_HEDLEY_IS_CONSTEXPR_(expr) + #endif + #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (JSON_HEDLEY_IS_CONSTEXPR_(expr) ? (expr) : (-1)) +#else + #if !defined(JSON_HEDLEY_IS_CONSTANT) + #define JSON_HEDLEY_IS_CONSTANT(expr) (0) + #endif + #define JSON_HEDLEY_REQUIRE_CONSTEXPR(expr) (expr) +#endif + +#if defined(JSON_HEDLEY_BEGIN_C_DECLS) + #undef JSON_HEDLEY_BEGIN_C_DECLS +#endif +#if defined(JSON_HEDLEY_END_C_DECLS) + #undef JSON_HEDLEY_END_C_DECLS +#endif +#if defined(JSON_HEDLEY_C_DECL) + #undef JSON_HEDLEY_C_DECL +#endif +#if defined(__cplusplus) + #define JSON_HEDLEY_BEGIN_C_DECLS extern "C" { + #define JSON_HEDLEY_END_C_DECLS } + #define JSON_HEDLEY_C_DECL extern "C" +#else + #define JSON_HEDLEY_BEGIN_C_DECLS + #define JSON_HEDLEY_END_C_DECLS + #define JSON_HEDLEY_C_DECL +#endif + +#if defined(JSON_HEDLEY_STATIC_ASSERT) + #undef JSON_HEDLEY_STATIC_ASSERT +#endif +#if \ + !defined(__cplusplus) && ( \ + (defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)) || \ + (JSON_HEDLEY_HAS_FEATURE(c_static_assert) && !defined(JSON_HEDLEY_INTEL_CL_VERSION)) || \ + JSON_HEDLEY_GCC_VERSION_CHECK(6,0,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) || \ + defined(_Static_assert) \ + ) +# define JSON_HEDLEY_STATIC_ASSERT(expr, message) _Static_assert(expr, message) +#elif \ + (defined(__cplusplus) && (__cplusplus >= 201103L)) || \ + JSON_HEDLEY_MSVC_VERSION_CHECK(16,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) +# define JSON_HEDLEY_STATIC_ASSERT(expr, message) JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(static_assert(expr, message)) +#else +# define JSON_HEDLEY_STATIC_ASSERT(expr, message) +#endif + +#if defined(JSON_HEDLEY_NULL) + #undef JSON_HEDLEY_NULL +#endif +#if defined(__cplusplus) + #if __cplusplus >= 201103L + #define JSON_HEDLEY_NULL JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_(nullptr) + #elif defined(NULL) + #define JSON_HEDLEY_NULL NULL + #else + #define JSON_HEDLEY_NULL JSON_HEDLEY_STATIC_CAST(void*, 0) + #endif +#elif defined(NULL) + #define JSON_HEDLEY_NULL NULL +#else + #define JSON_HEDLEY_NULL ((void*) 0) +#endif + +#if defined(JSON_HEDLEY_MESSAGE) + #undef JSON_HEDLEY_MESSAGE +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") +# define JSON_HEDLEY_MESSAGE(msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ + JSON_HEDLEY_PRAGMA(message msg) \ + JSON_HEDLEY_DIAGNOSTIC_POP +#elif \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message msg) +#elif JSON_HEDLEY_CRAY_VERSION_CHECK(5,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(_CRI message msg) +#elif JSON_HEDLEY_IAR_VERSION_CHECK(8,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) +#elif JSON_HEDLEY_PELLES_VERSION_CHECK(2,0,0) +# define JSON_HEDLEY_MESSAGE(msg) JSON_HEDLEY_PRAGMA(message(msg)) +#else +# define JSON_HEDLEY_MESSAGE(msg) +#endif + +#if defined(JSON_HEDLEY_WARNING) + #undef JSON_HEDLEY_WARNING +#endif +#if JSON_HEDLEY_HAS_WARNING("-Wunknown-pragmas") +# define JSON_HEDLEY_WARNING(msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS \ + JSON_HEDLEY_PRAGMA(clang warning msg) \ + JSON_HEDLEY_DIAGNOSTIC_POP +#elif \ + JSON_HEDLEY_GCC_VERSION_CHECK(4,8,0) || \ + JSON_HEDLEY_PGI_VERSION_CHECK(18,4,0) || \ + JSON_HEDLEY_INTEL_VERSION_CHECK(13,0,0) +# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(GCC warning msg) +#elif \ + JSON_HEDLEY_MSVC_VERSION_CHECK(15,0,0) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) +# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_PRAGMA(message(msg)) +#else +# define JSON_HEDLEY_WARNING(msg) JSON_HEDLEY_MESSAGE(msg) +#endif + +#if defined(JSON_HEDLEY_REQUIRE) + #undef JSON_HEDLEY_REQUIRE +#endif +#if defined(JSON_HEDLEY_REQUIRE_MSG) + #undef JSON_HEDLEY_REQUIRE_MSG +#endif +#if JSON_HEDLEY_HAS_ATTRIBUTE(diagnose_if) +# if JSON_HEDLEY_HAS_WARNING("-Wgcc-compat") +# define JSON_HEDLEY_REQUIRE(expr) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((diagnose_if(!(expr), #expr, "error"))) \ + JSON_HEDLEY_DIAGNOSTIC_POP +# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("clang diagnostic ignored \"-Wgcc-compat\"") \ + __attribute__((diagnose_if(!(expr), msg, "error"))) \ + JSON_HEDLEY_DIAGNOSTIC_POP +# else +# define JSON_HEDLEY_REQUIRE(expr) __attribute__((diagnose_if(!(expr), #expr, "error"))) +# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) __attribute__((diagnose_if(!(expr), msg, "error"))) +# endif +#else +# define JSON_HEDLEY_REQUIRE(expr) +# define JSON_HEDLEY_REQUIRE_MSG(expr,msg) +#endif + +#if defined(JSON_HEDLEY_FLAGS) + #undef JSON_HEDLEY_FLAGS +#endif +#if JSON_HEDLEY_HAS_ATTRIBUTE(flag_enum) && (!defined(__cplusplus) || JSON_HEDLEY_HAS_WARNING("-Wbitfield-enum-conversion")) + #define JSON_HEDLEY_FLAGS __attribute__((__flag_enum__)) +#else + #define JSON_HEDLEY_FLAGS +#endif + +#if defined(JSON_HEDLEY_FLAGS_CAST) + #undef JSON_HEDLEY_FLAGS_CAST +#endif +#if JSON_HEDLEY_INTEL_VERSION_CHECK(19,0,0) +# define JSON_HEDLEY_FLAGS_CAST(T, expr) (__extension__ ({ \ + JSON_HEDLEY_DIAGNOSTIC_PUSH \ + _Pragma("warning(disable:188)") \ + ((T) (expr)); \ + JSON_HEDLEY_DIAGNOSTIC_POP \ + })) +#else +# define JSON_HEDLEY_FLAGS_CAST(T, expr) JSON_HEDLEY_STATIC_CAST(T, expr) +#endif + +#if defined(JSON_HEDLEY_EMPTY_BASES) + #undef JSON_HEDLEY_EMPTY_BASES +#endif +#if \ + (JSON_HEDLEY_MSVC_VERSION_CHECK(19,0,23918) && !JSON_HEDLEY_MSVC_VERSION_CHECK(20,0,0)) || \ + JSON_HEDLEY_INTEL_CL_VERSION_CHECK(2021,1,0) + #define JSON_HEDLEY_EMPTY_BASES __declspec(empty_bases) +#else + #define JSON_HEDLEY_EMPTY_BASES +#endif + +/* Remaining macros are deprecated. */ + +#if defined(JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK) + #undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK +#endif +#if defined(__clang__) + #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) (0) +#else + #define JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK(major,minor,patch) JSON_HEDLEY_GCC_VERSION_CHECK(major,minor,patch) +#endif + +#if defined(JSON_HEDLEY_CLANG_HAS_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE +#endif +#define JSON_HEDLEY_CLANG_HAS_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_ATTRIBUTE(attribute) + +#if defined(JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE +#endif +#define JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_CPP_ATTRIBUTE(attribute) + +#if defined(JSON_HEDLEY_CLANG_HAS_BUILTIN) + #undef JSON_HEDLEY_CLANG_HAS_BUILTIN +#endif +#define JSON_HEDLEY_CLANG_HAS_BUILTIN(builtin) JSON_HEDLEY_HAS_BUILTIN(builtin) + +#if defined(JSON_HEDLEY_CLANG_HAS_FEATURE) + #undef JSON_HEDLEY_CLANG_HAS_FEATURE +#endif +#define JSON_HEDLEY_CLANG_HAS_FEATURE(feature) JSON_HEDLEY_HAS_FEATURE(feature) + +#if defined(JSON_HEDLEY_CLANG_HAS_EXTENSION) + #undef JSON_HEDLEY_CLANG_HAS_EXTENSION +#endif +#define JSON_HEDLEY_CLANG_HAS_EXTENSION(extension) JSON_HEDLEY_HAS_EXTENSION(extension) + +#if defined(JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE) + #undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE +#endif +#define JSON_HEDLEY_CLANG_HAS_DECLSPEC_ATTRIBUTE(attribute) JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE(attribute) + +#if defined(JSON_HEDLEY_CLANG_HAS_WARNING) + #undef JSON_HEDLEY_CLANG_HAS_WARNING +#endif +#define JSON_HEDLEY_CLANG_HAS_WARNING(warning) JSON_HEDLEY_HAS_WARNING(warning) + +#endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */ + +// #include + + +#include + +// #include + + +namespace nlohmann +{ +namespace detail +{ +template struct make_void +{ + using type = void; +}; +template using void_t = typename make_void::type; +} // namespace detail +} // namespace nlohmann + + +// https://en.cppreference.com/w/cpp/experimental/is_detected +namespace nlohmann +{ +namespace detail +{ +struct nonesuch +{ + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch(nonesuch const&) = delete; + nonesuch(nonesuch const&&) = delete; + void operator=(nonesuch const&) = delete; + void operator=(nonesuch&&) = delete; +}; + +template class Op, + class... Args> +struct detector +{ + using value_t = std::false_type; + using type = Default; +}; + +template class Op, class... Args> +struct detector>, Op, Args...> +{ + using value_t = std::true_type; + using type = Op; +}; + +template class Op, class... Args> +using is_detected = typename detector::value_t; + +template class Op, class... Args> +struct is_detected_lazy : is_detected { }; + +template class Op, class... Args> +using detected_t = typename detector::type; + +template class Op, class... Args> +using detected_or = detector; + +template class Op, class... Args> +using detected_or_t = typename detected_or::type; + +template class Op, class... Args> +using is_detected_exact = std::is_same>; + +template class Op, class... Args> +using is_detected_convertible = + std::is_convertible, To>; +} // namespace detail +} // namespace nlohmann + + +// This file contains all internal macro definitions +// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them + +// exclude unsupported compilers +#if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) + #if defined(__clang__) + #if (__clang_major__ * 10000 + __clang_minor__ * 100 + __clang_patchlevel__) < 30400 + #error "unsupported Clang version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #elif defined(__GNUC__) && !(defined(__ICC) || defined(__INTEL_COMPILER)) + #if (__GNUC__ * 10000 + __GNUC_MINOR__ * 100 + __GNUC_PATCHLEVEL__) < 40800 + #error "unsupported GCC version - see https://github.com/nlohmann/json#supported-compilers" + #endif + #endif +#endif + +// C++ language standard detection +// if the user manually specified the used c++ version this is skipped +#if !defined(JSON_HAS_CPP_20) && !defined(JSON_HAS_CPP_17) && !defined(JSON_HAS_CPP_14) && !defined(JSON_HAS_CPP_11) + #if (defined(__cplusplus) && __cplusplus >= 202002L) || (defined(_MSVC_LANG) && _MSVC_LANG >= 202002L) + #define JSON_HAS_CPP_20 + #define JSON_HAS_CPP_17 + #define JSON_HAS_CPP_14 + #elif (defined(__cplusplus) && __cplusplus >= 201703L) || (defined(_HAS_CXX17) && _HAS_CXX17 == 1) // fix for issue #464 + #define JSON_HAS_CPP_17 + #define JSON_HAS_CPP_14 + #elif (defined(__cplusplus) && __cplusplus >= 201402L) || (defined(_HAS_CXX14) && _HAS_CXX14 == 1) + #define JSON_HAS_CPP_14 + #endif + // the cpp 11 flag is always specified because it is the minimal required version + #define JSON_HAS_CPP_11 +#endif + +// disable documentation warnings on clang +#if defined(__clang__) + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wdocumentation" + #pragma clang diagnostic ignored "-Wdocumentation-unknown-command" +#endif + +// allow to disable exceptions +#if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) + #define JSON_THROW(exception) throw exception + #define JSON_TRY try + #define JSON_CATCH(exception) catch(exception) + #define JSON_INTERNAL_CATCH(exception) catch(exception) +#else + #include + #define JSON_THROW(exception) std::abort() + #define JSON_TRY if(true) + #define JSON_CATCH(exception) if(false) + #define JSON_INTERNAL_CATCH(exception) if(false) +#endif + +// override exception macros +#if defined(JSON_THROW_USER) + #undef JSON_THROW + #define JSON_THROW JSON_THROW_USER +#endif +#if defined(JSON_TRY_USER) + #undef JSON_TRY + #define JSON_TRY JSON_TRY_USER +#endif +#if defined(JSON_CATCH_USER) + #undef JSON_CATCH + #define JSON_CATCH JSON_CATCH_USER + #undef JSON_INTERNAL_CATCH + #define JSON_INTERNAL_CATCH JSON_CATCH_USER +#endif +#if defined(JSON_INTERNAL_CATCH_USER) + #undef JSON_INTERNAL_CATCH + #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER +#endif + +// allow to override assert +#if !defined(JSON_ASSERT) + #include // assert + #define JSON_ASSERT(x) assert(x) +#endif + +// allow to access some private functions (needed by the test suite) +#if defined(JSON_TESTS_PRIVATE) + #define JSON_PRIVATE_UNLESS_TESTED public +#else + #define JSON_PRIVATE_UNLESS_TESTED private +#endif + +/*! +@brief macro to briefly define a mapping between an enum and JSON +@def NLOHMANN_JSON_SERIALIZE_ENUM +@since version 3.4.0 +*/ +#define NLOHMANN_JSON_SERIALIZE_ENUM(ENUM_TYPE, ...) \ + template \ + inline void to_json(BasicJsonType& j, const ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ + [e](const std::pair& ej_pair) -> bool \ + { \ + return ej_pair.first == e; \ + }); \ + j = ((it != std::end(m)) ? it : std::begin(m))->second; \ + } \ + template \ + inline void from_json(const BasicJsonType& j, ENUM_TYPE& e) \ + { \ + static_assert(std::is_enum::value, #ENUM_TYPE " must be an enum!"); \ + static const std::pair m[] = __VA_ARGS__; \ + auto it = std::find_if(std::begin(m), std::end(m), \ + [&j](const std::pair& ej_pair) -> bool \ + { \ + return ej_pair.second == j; \ + }); \ + e = ((it != std::end(m)) ? it : std::begin(m))->first; \ + } + +// Ugly macros to avoid uglier copy-paste when specializing basic_json. They +// may be removed in the future once the class is split. + +#define NLOHMANN_BASIC_JSON_TPL_DECLARATION \ + template class ObjectType, \ + template class ArrayType, \ + class StringType, class BooleanType, class NumberIntegerType, \ + class NumberUnsignedType, class NumberFloatType, \ + template class AllocatorType, \ + template class JSONSerializer, \ + class BinaryType> + +#define NLOHMANN_BASIC_JSON_TPL \ + basic_json + +// Macros to simplify conversion from/to types + +#define NLOHMANN_JSON_EXPAND( x ) x +#define NLOHMANN_JSON_GET_MACRO(_1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12, _13, _14, _15, _16, _17, _18, _19, _20, _21, _22, _23, _24, _25, _26, _27, _28, _29, _30, _31, _32, _33, _34, _35, _36, _37, _38, _39, _40, _41, _42, _43, _44, _45, _46, _47, _48, _49, _50, _51, _52, _53, _54, _55, _56, _57, _58, _59, _60, _61, _62, _63, _64, NAME,...) NAME +#define NLOHMANN_JSON_PASTE(...) NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_GET_MACRO(__VA_ARGS__, \ + NLOHMANN_JSON_PASTE64, \ + NLOHMANN_JSON_PASTE63, \ + NLOHMANN_JSON_PASTE62, \ + NLOHMANN_JSON_PASTE61, \ + NLOHMANN_JSON_PASTE60, \ + NLOHMANN_JSON_PASTE59, \ + NLOHMANN_JSON_PASTE58, \ + NLOHMANN_JSON_PASTE57, \ + NLOHMANN_JSON_PASTE56, \ + NLOHMANN_JSON_PASTE55, \ + NLOHMANN_JSON_PASTE54, \ + NLOHMANN_JSON_PASTE53, \ + NLOHMANN_JSON_PASTE52, \ + NLOHMANN_JSON_PASTE51, \ + NLOHMANN_JSON_PASTE50, \ + NLOHMANN_JSON_PASTE49, \ + NLOHMANN_JSON_PASTE48, \ + NLOHMANN_JSON_PASTE47, \ + NLOHMANN_JSON_PASTE46, \ + NLOHMANN_JSON_PASTE45, \ + NLOHMANN_JSON_PASTE44, \ + NLOHMANN_JSON_PASTE43, \ + NLOHMANN_JSON_PASTE42, \ + NLOHMANN_JSON_PASTE41, \ + NLOHMANN_JSON_PASTE40, \ + NLOHMANN_JSON_PASTE39, \ + NLOHMANN_JSON_PASTE38, \ + NLOHMANN_JSON_PASTE37, \ + NLOHMANN_JSON_PASTE36, \ + NLOHMANN_JSON_PASTE35, \ + NLOHMANN_JSON_PASTE34, \ + NLOHMANN_JSON_PASTE33, \ + NLOHMANN_JSON_PASTE32, \ + NLOHMANN_JSON_PASTE31, \ + NLOHMANN_JSON_PASTE30, \ + NLOHMANN_JSON_PASTE29, \ + NLOHMANN_JSON_PASTE28, \ + NLOHMANN_JSON_PASTE27, \ + NLOHMANN_JSON_PASTE26, \ + NLOHMANN_JSON_PASTE25, \ + NLOHMANN_JSON_PASTE24, \ + NLOHMANN_JSON_PASTE23, \ + NLOHMANN_JSON_PASTE22, \ + NLOHMANN_JSON_PASTE21, \ + NLOHMANN_JSON_PASTE20, \ + NLOHMANN_JSON_PASTE19, \ + NLOHMANN_JSON_PASTE18, \ + NLOHMANN_JSON_PASTE17, \ + NLOHMANN_JSON_PASTE16, \ + NLOHMANN_JSON_PASTE15, \ + NLOHMANN_JSON_PASTE14, \ + NLOHMANN_JSON_PASTE13, \ + NLOHMANN_JSON_PASTE12, \ + NLOHMANN_JSON_PASTE11, \ + NLOHMANN_JSON_PASTE10, \ + NLOHMANN_JSON_PASTE9, \ + NLOHMANN_JSON_PASTE8, \ + NLOHMANN_JSON_PASTE7, \ + NLOHMANN_JSON_PASTE6, \ + NLOHMANN_JSON_PASTE5, \ + NLOHMANN_JSON_PASTE4, \ + NLOHMANN_JSON_PASTE3, \ + NLOHMANN_JSON_PASTE2, \ + NLOHMANN_JSON_PASTE1)(__VA_ARGS__)) +#define NLOHMANN_JSON_PASTE2(func, v1) func(v1) +#define NLOHMANN_JSON_PASTE3(func, v1, v2) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE2(func, v2) +#define NLOHMANN_JSON_PASTE4(func, v1, v2, v3) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE3(func, v2, v3) +#define NLOHMANN_JSON_PASTE5(func, v1, v2, v3, v4) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE4(func, v2, v3, v4) +#define NLOHMANN_JSON_PASTE6(func, v1, v2, v3, v4, v5) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE5(func, v2, v3, v4, v5) +#define NLOHMANN_JSON_PASTE7(func, v1, v2, v3, v4, v5, v6) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE6(func, v2, v3, v4, v5, v6) +#define NLOHMANN_JSON_PASTE8(func, v1, v2, v3, v4, v5, v6, v7) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE7(func, v2, v3, v4, v5, v6, v7) +#define NLOHMANN_JSON_PASTE9(func, v1, v2, v3, v4, v5, v6, v7, v8) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE8(func, v2, v3, v4, v5, v6, v7, v8) +#define NLOHMANN_JSON_PASTE10(func, v1, v2, v3, v4, v5, v6, v7, v8, v9) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE9(func, v2, v3, v4, v5, v6, v7, v8, v9) +#define NLOHMANN_JSON_PASTE11(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE10(func, v2, v3, v4, v5, v6, v7, v8, v9, v10) +#define NLOHMANN_JSON_PASTE12(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE11(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11) +#define NLOHMANN_JSON_PASTE13(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE12(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12) +#define NLOHMANN_JSON_PASTE14(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE13(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13) +#define NLOHMANN_JSON_PASTE15(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE14(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14) +#define NLOHMANN_JSON_PASTE16(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE15(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15) +#define NLOHMANN_JSON_PASTE17(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE16(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16) +#define NLOHMANN_JSON_PASTE18(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE17(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17) +#define NLOHMANN_JSON_PASTE19(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE18(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18) +#define NLOHMANN_JSON_PASTE20(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE19(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19) +#define NLOHMANN_JSON_PASTE21(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE20(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20) +#define NLOHMANN_JSON_PASTE22(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE21(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21) +#define NLOHMANN_JSON_PASTE23(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE22(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22) +#define NLOHMANN_JSON_PASTE24(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE23(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23) +#define NLOHMANN_JSON_PASTE25(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE24(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24) +#define NLOHMANN_JSON_PASTE26(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE25(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25) +#define NLOHMANN_JSON_PASTE27(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE26(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26) +#define NLOHMANN_JSON_PASTE28(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE27(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27) +#define NLOHMANN_JSON_PASTE29(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE28(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28) +#define NLOHMANN_JSON_PASTE30(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE29(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29) +#define NLOHMANN_JSON_PASTE31(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE30(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30) +#define NLOHMANN_JSON_PASTE32(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE31(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31) +#define NLOHMANN_JSON_PASTE33(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE32(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32) +#define NLOHMANN_JSON_PASTE34(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE33(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33) +#define NLOHMANN_JSON_PASTE35(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE34(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34) +#define NLOHMANN_JSON_PASTE36(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE35(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35) +#define NLOHMANN_JSON_PASTE37(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE36(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36) +#define NLOHMANN_JSON_PASTE38(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE37(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37) +#define NLOHMANN_JSON_PASTE39(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE38(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38) +#define NLOHMANN_JSON_PASTE40(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE39(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39) +#define NLOHMANN_JSON_PASTE41(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE40(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40) +#define NLOHMANN_JSON_PASTE42(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE41(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41) +#define NLOHMANN_JSON_PASTE43(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE42(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42) +#define NLOHMANN_JSON_PASTE44(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE43(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43) +#define NLOHMANN_JSON_PASTE45(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE44(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44) +#define NLOHMANN_JSON_PASTE46(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE45(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45) +#define NLOHMANN_JSON_PASTE47(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE46(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46) +#define NLOHMANN_JSON_PASTE48(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE47(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47) +#define NLOHMANN_JSON_PASTE49(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE48(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48) +#define NLOHMANN_JSON_PASTE50(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE49(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49) +#define NLOHMANN_JSON_PASTE51(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE50(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50) +#define NLOHMANN_JSON_PASTE52(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE51(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51) +#define NLOHMANN_JSON_PASTE53(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE52(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52) +#define NLOHMANN_JSON_PASTE54(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE53(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53) +#define NLOHMANN_JSON_PASTE55(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE54(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54) +#define NLOHMANN_JSON_PASTE56(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE55(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55) +#define NLOHMANN_JSON_PASTE57(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE56(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56) +#define NLOHMANN_JSON_PASTE58(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE57(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57) +#define NLOHMANN_JSON_PASTE59(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE58(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58) +#define NLOHMANN_JSON_PASTE60(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE59(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59) +#define NLOHMANN_JSON_PASTE61(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE60(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60) +#define NLOHMANN_JSON_PASTE62(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE61(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61) +#define NLOHMANN_JSON_PASTE63(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE62(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62) +#define NLOHMANN_JSON_PASTE64(func, v1, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) NLOHMANN_JSON_PASTE2(func, v1) NLOHMANN_JSON_PASTE63(func, v2, v3, v4, v5, v6, v7, v8, v9, v10, v11, v12, v13, v14, v15, v16, v17, v18, v19, v20, v21, v22, v23, v24, v25, v26, v27, v28, v29, v30, v31, v32, v33, v34, v35, v36, v37, v38, v39, v40, v41, v42, v43, v44, v45, v46, v47, v48, v49, v50, v51, v52, v53, v54, v55, v56, v57, v58, v59, v60, v61, v62, v63) + +#define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1; +#define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1); + +/*! +@brief macro +@def NLOHMANN_DEFINE_TYPE_INTRUSIVE +@since version 3.9.0 +*/ +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE(Type, ...) \ + friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + +/*! +@brief macro +@def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE +@since version 3.9.0 +*/ +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE(Type, ...) \ + inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } + + +// inspired from https://stackoverflow.com/a/26745591 +// allows to call any std function as if (e.g. with begin): +// using std::begin; begin(x); +// +// it allows using the detected idiom to retrieve the return type +// of such an expression +#define NLOHMANN_CAN_CALL_STD_FUNC_IMPL(std_name) \ + namespace detail { \ + using std::std_name; \ + \ + template \ + using result_of_##std_name = decltype(std_name(std::declval()...)); \ + } \ + \ + namespace detail2 { \ + struct std_name##_tag \ + { \ + }; \ + \ + template \ + std_name##_tag std_name(T&&...); \ + \ + template \ + using result_of_##std_name = decltype(std_name(std::declval()...)); \ + \ + template \ + struct would_call_std_##std_name \ + { \ + static constexpr auto const value = ::nlohmann::detail:: \ + is_detected_exact::value; \ + }; \ + } /* namespace detail2 */ \ + \ + template \ + struct would_call_std_##std_name : detail2::would_call_std_##std_name \ + { \ + } + +#ifndef JSON_USE_IMPLICIT_CONVERSIONS + #define JSON_USE_IMPLICIT_CONVERSIONS 1 +#endif + +#if JSON_USE_IMPLICIT_CONVERSIONS + #define JSON_EXPLICIT +#else + #define JSON_EXPLICIT explicit +#endif + +#ifndef JSON_DIAGNOSTICS + #define JSON_DIAGNOSTICS 0 +#endif + + +namespace nlohmann +{ +namespace detail +{ + +/*! +@brief replace all occurrences of a substring by another string + +@param[in,out] s the string to manipulate; changed so that all + occurrences of @a f are replaced with @a t +@param[in] f the substring to replace with @a t +@param[in] t the string to replace @a f + +@pre The search string @a f must not be empty. **This precondition is +enforced with an assertion.** + +@since version 2.0.0 +*/ +inline void replace_substring(std::string& s, const std::string& f, + const std::string& t) +{ + JSON_ASSERT(!f.empty()); + for (auto pos = s.find(f); // find first occurrence of f + pos != std::string::npos; // make sure f was found + s.replace(pos, f.size(), t), // replace with t, and + pos = s.find(f, pos + t.size())) // find next occurrence of f + {} +} + +/*! + * @brief string escaping as described in RFC 6901 (Sect. 4) + * @param[in] s string to escape + * @return escaped string + * + * Note the order of escaping "~" to "~0" and "/" to "~1" is important. + */ +inline std::string escape(std::string s) +{ + replace_substring(s, "~", "~0"); + replace_substring(s, "/", "~1"); + return s; +} + +/*! + * @brief string unescaping as described in RFC 6901 (Sect. 4) + * @param[in] s string to unescape + * @return unescaped string + * + * Note the order of escaping "~1" to "/" and "~0" to "~" is important. + */ +static void unescape(std::string& s) +{ + replace_substring(s, "~1", "/"); + replace_substring(s, "~0", "~"); +} + +} // namespace detail +} // namespace nlohmann + +// #include + + +#include // size_t + +namespace nlohmann +{ +namespace detail +{ +/// struct to capture the start position of the current token +struct position_t +{ + /// the total number of characters read + std::size_t chars_read_total = 0; + /// the number of characters read in the current line + std::size_t chars_read_current_line = 0; + /// the number of lines read + std::size_t lines_read = 0; + + /// conversion to size_t to preserve SAX interface + constexpr operator size_t() const + { + return chars_read_total; + } +}; + +} // namespace detail +} // namespace nlohmann + +// #include + + +namespace nlohmann +{ +namespace detail +{ +//////////////// +// exceptions // +//////////////// + +/*! +@brief general exception of the @ref basic_json class + +This class is an extension of `std::exception` objects with a member @a id for +exception ids. It is used as the base class for all exceptions thrown by the +@ref basic_json class. This class can hence be used as "wildcard" to catch +exceptions. + +Subclasses: +- @ref parse_error for exceptions indicating a parse error +- @ref invalid_iterator for exceptions indicating errors with iterators +- @ref type_error for exceptions indicating executing a member function with + a wrong type +- @ref out_of_range for exceptions indicating access out of the defined range +- @ref other_error for exceptions indicating other library errors + +@internal +@note To have nothrow-copy-constructible exceptions, we internally use + `std::runtime_error` which can cope with arbitrary-length error messages. + Intermediate strings are built with static functions and then passed to + the actual constructor. +@endinternal + +@liveexample{The following code shows how arbitrary library exceptions can be +caught.,exception} + +@since version 3.0.0 +*/ +class exception : public std::exception +{ + public: + /// returns the explanatory string + const char* what() const noexcept override + { + return m.what(); + } + + /// the id of the exception + const int id; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) + + protected: + JSON_HEDLEY_NON_NULL(3) + exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} + + static std::string name(const std::string& ename, int id_) + { + return "[json.exception." + ename + "." + std::to_string(id_) + "] "; + } + + template + static std::string diagnostics(const BasicJsonType& leaf_element) + { +#if JSON_DIAGNOSTICS + std::vector tokens; + for (const auto* current = &leaf_element; current->m_parent != nullptr; current = current->m_parent) + { + switch (current->m_parent->type()) + { + case value_t::array: + { + for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i) + { + if (¤t->m_parent->m_value.array->operator[](i) == current) + { + tokens.emplace_back(std::to_string(i)); + break; + } + } + break; + } + + case value_t::object: + { + for (const auto& element : *current->m_parent->m_value.object) + { + if (&element.second == current) + { + tokens.emplace_back(element.first.c_str()); + break; + } + } + break; + } + + case value_t::null: // LCOV_EXCL_LINE + case value_t::string: // LCOV_EXCL_LINE + case value_t::boolean: // LCOV_EXCL_LINE + case value_t::number_integer: // LCOV_EXCL_LINE + case value_t::number_unsigned: // LCOV_EXCL_LINE + case value_t::number_float: // LCOV_EXCL_LINE + case value_t::binary: // LCOV_EXCL_LINE + case value_t::discarded: // LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + break; // LCOV_EXCL_LINE + } + } + + if (tokens.empty()) + { + return ""; + } + + return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, + [](const std::string & a, const std::string & b) + { + return a + "/" + detail::escape(b); + }) + ") "; +#else + static_cast(leaf_element); + return ""; +#endif + } + + private: + /// an exception object as storage for error messages + std::runtime_error m; +}; + +/*! +@brief exception indicating a parse error + +This exception is thrown by the library when a parse error occurs. Parse errors +can occur during the deserialization of JSON text, CBOR, MessagePack, as well +as when using JSON Patch. + +Member @a byte holds the byte index of the last read character in the input +file. + +Exceptions have ids 1xx. + +name / id | example message | description +------------------------------ | --------------- | ------------------------- +json.exception.parse_error.101 | parse error at 2: unexpected end of input; expected string literal | This error indicates a syntax error while deserializing a JSON text. The error message describes that an unexpected token (character) was encountered, and the member @a byte indicates the error position. +json.exception.parse_error.102 | parse error at 14: missing or wrong low surrogate | JSON uses the `\uxxxx` format to describe Unicode characters. Code points above above 0xFFFF are split into two `\uxxxx` entries ("surrogate pairs"). This error indicates that the surrogate pair is incomplete or contains an invalid code point. +json.exception.parse_error.103 | parse error: code points above 0x10FFFF are invalid | Unicode supports code points up to 0x10FFFF. Code points above 0x10FFFF are invalid. +json.exception.parse_error.104 | parse error: JSON patch must be an array of objects | [RFC 6902](https://tools.ietf.org/html/rfc6902) requires a JSON Patch document to be a JSON document that represents an array of objects. +json.exception.parse_error.105 | parse error: operation must have string member 'op' | An operation of a JSON Patch document must contain exactly one "op" member, whose value indicates the operation to perform. Its value must be one of "add", "remove", "replace", "move", "copy", or "test"; other values are errors. +json.exception.parse_error.106 | parse error: array index '01' must not begin with '0' | An array index in a JSON Pointer ([RFC 6901](https://tools.ietf.org/html/rfc6901)) may be `0` or any number without a leading `0`. +json.exception.parse_error.107 | parse error: JSON pointer must be empty or begin with '/' - was: 'foo' | A JSON Pointer must be a Unicode string containing a sequence of zero or more reference tokens, each prefixed by a `/` character. +json.exception.parse_error.108 | parse error: escape character '~' must be followed with '0' or '1' | In a JSON Pointer, only `~0` and `~1` are valid escape sequences. +json.exception.parse_error.109 | parse error: array index 'one' is not a number | A JSON Pointer array index must be a number. +json.exception.parse_error.110 | parse error at 1: cannot read 2 bytes from vector | When parsing CBOR or MessagePack, the byte vector ends before the complete value has been read. +json.exception.parse_error.112 | parse error at 1: error reading CBOR; last byte: 0xF8 | Not all types of CBOR or MessagePack are supported. This exception occurs if an unsupported byte was read. +json.exception.parse_error.113 | parse error at 2: expected a CBOR string; last byte: 0x98 | While parsing a map key, a value that is not a string has been read. +json.exception.parse_error.114 | parse error: Unsupported BSON record type 0x0F | The parsing of the corresponding BSON record type is not implemented (yet). +json.exception.parse_error.115 | parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1A | A UBJSON high-precision number could not be parsed. + +@note For an input with n bytes, 1 is the index of the first character and n+1 + is the index of the terminating null byte or the end of file. This also + holds true when reading a byte vector (CBOR or MessagePack). + +@liveexample{The following code shows how a `parse_error` exception can be +caught.,parse_error} + +@sa - @ref exception for the base class of the library exceptions +@sa - @ref invalid_iterator for exceptions indicating errors with iterators +@sa - @ref type_error for exceptions indicating executing a member function with + a wrong type +@sa - @ref out_of_range for exceptions indicating access out of the defined range +@sa - @ref other_error for exceptions indicating other library errors + +@since version 3.0.0 +*/ +class parse_error : public exception +{ + public: + /*! + @brief create a parse error exception + @param[in] id_ the id of the exception + @param[in] pos the position where the error occurred (or with + chars_read_total=0 if the position cannot be + determined) + @param[in] what_arg the explanatory string + @return parse_error object + */ + template + static parse_error create(int id_, const position_t& pos, const std::string& what_arg, const BasicJsonType& context) + { + std::string w = exception::name("parse_error", id_) + "parse error" + + position_string(pos) + ": " + exception::diagnostics(context) + what_arg; + return parse_error(id_, pos.chars_read_total, w.c_str()); + } + + template + static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, const BasicJsonType& context) + { + std::string w = exception::name("parse_error", id_) + "parse error" + + (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") + + ": " + exception::diagnostics(context) + what_arg; + return parse_error(id_, byte_, w.c_str()); + } + + /*! + @brief byte index of the parse error + + The byte index of the last read character in the input file. + + @note For an input with n bytes, 1 is the index of the first character and + n+1 is the index of the terminating null byte or the end of file. + This also holds true when reading a byte vector (CBOR or MessagePack). + */ + const std::size_t byte; + + private: + parse_error(int id_, std::size_t byte_, const char* what_arg) + : exception(id_, what_arg), byte(byte_) {} + + static std::string position_string(const position_t& pos) + { + return " at line " + std::to_string(pos.lines_read + 1) + + ", column " + std::to_string(pos.chars_read_current_line); + } +}; + +/*! +@brief exception indicating errors with iterators + +This exception is thrown if iterators passed to a library function do not match +the expected semantics. + +Exceptions have ids 2xx. + +name / id | example message | description +----------------------------------- | --------------- | ------------------------- +json.exception.invalid_iterator.201 | iterators are not compatible | The iterators passed to constructor @ref basic_json(InputIT first, InputIT last) are not compatible, meaning they do not belong to the same container. Therefore, the range (@a first, @a last) is invalid. +json.exception.invalid_iterator.202 | iterator does not fit current value | In an erase or insert function, the passed iterator @a pos does not belong to the JSON value for which the function was called. It hence does not define a valid position for the deletion/insertion. +json.exception.invalid_iterator.203 | iterators do not fit current value | Either iterator passed to function @ref erase(IteratorType first, IteratorType last) does not belong to the JSON value from which values shall be erased. It hence does not define a valid range to delete values from. +json.exception.invalid_iterator.204 | iterators out of range | When an iterator range for a primitive type (number, boolean, or string) is passed to a constructor or an erase function, this range has to be exactly (@ref begin(), @ref end()), because this is the only way the single stored value is expressed. All other ranges are invalid. +json.exception.invalid_iterator.205 | iterator out of range | When an iterator for a primitive type (number, boolean, or string) is passed to an erase function, the iterator has to be the @ref begin() iterator, because it is the only way to address the stored value. All other iterators are invalid. +json.exception.invalid_iterator.206 | cannot construct with iterators from null | The iterators passed to constructor @ref basic_json(InputIT first, InputIT last) belong to a JSON null value and hence to not define a valid range. +json.exception.invalid_iterator.207 | cannot use key() for non-object iterators | The key() member function can only be used on iterators belonging to a JSON object, because other types do not have a concept of a key. +json.exception.invalid_iterator.208 | cannot use operator[] for object iterators | The operator[] to specify a concrete offset cannot be used on iterators belonging to a JSON object, because JSON objects are unordered. +json.exception.invalid_iterator.209 | cannot use offsets with object iterators | The offset operators (+, -, +=, -=) cannot be used on iterators belonging to a JSON object, because JSON objects are unordered. +json.exception.invalid_iterator.210 | iterators do not fit | The iterator range passed to the insert function are not compatible, meaning they do not belong to the same container. Therefore, the range (@a first, @a last) is invalid. +json.exception.invalid_iterator.211 | passed iterators may not belong to container | The iterator range passed to the insert function must not be a subrange of the container to insert to. +json.exception.invalid_iterator.212 | cannot compare iterators of different containers | When two iterators are compared, they must belong to the same container. +json.exception.invalid_iterator.213 | cannot compare order of object iterators | The order of object iterators cannot be compared, because JSON objects are unordered. +json.exception.invalid_iterator.214 | cannot get value | Cannot get value for iterator: Either the iterator belongs to a null value or it is an iterator to a primitive type (number, boolean, or string), but the iterator is different to @ref begin(). + +@liveexample{The following code shows how an `invalid_iterator` exception can be +caught.,invalid_iterator} + +@sa - @ref exception for the base class of the library exceptions +@sa - @ref parse_error for exceptions indicating a parse error +@sa - @ref type_error for exceptions indicating executing a member function with + a wrong type +@sa - @ref out_of_range for exceptions indicating access out of the defined range +@sa - @ref other_error for exceptions indicating other library errors + +@since version 3.0.0 +*/ +class invalid_iterator : public exception +{ + public: + template + static invalid_iterator create(int id_, const std::string& what_arg, const BasicJsonType& context) + { + std::string w = exception::name("invalid_iterator", id_) + exception::diagnostics(context) + what_arg; + return invalid_iterator(id_, w.c_str()); + } + + private: + JSON_HEDLEY_NON_NULL(3) + invalid_iterator(int id_, const char* what_arg) + : exception(id_, what_arg) {} +}; + +/*! +@brief exception indicating executing a member function with a wrong type + +This exception is thrown in case of a type error; that is, a library function is +executed on a JSON value whose type does not match the expected semantics. + +Exceptions have ids 3xx. + +name / id | example message | description +----------------------------- | --------------- | ------------------------- +json.exception.type_error.301 | cannot create object from initializer list | To create an object from an initializer list, the initializer list must consist only of a list of pairs whose first element is a string. When this constraint is violated, an array is created instead. +json.exception.type_error.302 | type must be object, but is array | During implicit or explicit value conversion, the JSON type must be compatible to the target type. For instance, a JSON string can only be converted into string types, but not into numbers or boolean types. +json.exception.type_error.303 | incompatible ReferenceType for get_ref, actual type is object | To retrieve a reference to a value stored in a @ref basic_json object with @ref get_ref, the type of the reference must match the value type. For instance, for a JSON array, the @a ReferenceType must be @ref array_t &. +json.exception.type_error.304 | cannot use at() with string | The @ref at() member functions can only be executed for certain JSON types. +json.exception.type_error.305 | cannot use operator[] with string | The @ref operator[] member functions can only be executed for certain JSON types. +json.exception.type_error.306 | cannot use value() with string | The @ref value() member functions can only be executed for certain JSON types. +json.exception.type_error.307 | cannot use erase() with string | The @ref erase() member functions can only be executed for certain JSON types. +json.exception.type_error.308 | cannot use push_back() with string | The @ref push_back() and @ref operator+= member functions can only be executed for certain JSON types. +json.exception.type_error.309 | cannot use insert() with | The @ref insert() member functions can only be executed for certain JSON types. +json.exception.type_error.310 | cannot use swap() with number | The @ref swap() member functions can only be executed for certain JSON types. +json.exception.type_error.311 | cannot use emplace_back() with string | The @ref emplace_back() member function can only be executed for certain JSON types. +json.exception.type_error.312 | cannot use update() with string | The @ref update() member functions can only be executed for certain JSON types. +json.exception.type_error.313 | invalid value to unflatten | The @ref unflatten function converts an object whose keys are JSON Pointers back into an arbitrary nested JSON value. The JSON Pointers must not overlap, because then the resulting value would not be well defined. +json.exception.type_error.314 | only objects can be unflattened | The @ref unflatten function only works for an object whose keys are JSON Pointers. +json.exception.type_error.315 | values in object must be primitive | The @ref unflatten function only works for an object whose keys are JSON Pointers and whose values are primitive. +json.exception.type_error.316 | invalid UTF-8 byte at index 10: 0x7E | The @ref dump function only works with UTF-8 encoded strings; that is, if you assign a `std::string` to a JSON value, make sure it is UTF-8 encoded. | +json.exception.type_error.317 | JSON value cannot be serialized to requested format | The dynamic type of the object cannot be represented in the requested serialization format (e.g. a raw `true` or `null` JSON object cannot be serialized to BSON) | + +@liveexample{The following code shows how a `type_error` exception can be +caught.,type_error} + +@sa - @ref exception for the base class of the library exceptions +@sa - @ref parse_error for exceptions indicating a parse error +@sa - @ref invalid_iterator for exceptions indicating errors with iterators +@sa - @ref out_of_range for exceptions indicating access out of the defined range +@sa - @ref other_error for exceptions indicating other library errors + +@since version 3.0.0 +*/ +class type_error : public exception +{ + public: + template + static type_error create(int id_, const std::string& what_arg, const BasicJsonType& context) + { + std::string w = exception::name("type_error", id_) + exception::diagnostics(context) + what_arg; + return type_error(id_, w.c_str()); + } + + private: + JSON_HEDLEY_NON_NULL(3) + type_error(int id_, const char* what_arg) : exception(id_, what_arg) {} +}; + +/*! +@brief exception indicating access out of the defined range + +This exception is thrown in case a library function is called on an input +parameter that exceeds the expected range, for instance in case of array +indices or nonexisting object keys. + +Exceptions have ids 4xx. + +name / id | example message | description +------------------------------- | --------------- | ------------------------- +json.exception.out_of_range.401 | array index 3 is out of range | The provided array index @a i is larger than @a size-1. +json.exception.out_of_range.402 | array index '-' (3) is out of range | The special array index `-` in a JSON Pointer never describes a valid element of the array, but the index past the end. That is, it can only be used to add elements at this position, but not to read it. +json.exception.out_of_range.403 | key 'foo' not found | The provided key was not found in the JSON object. +json.exception.out_of_range.404 | unresolved reference token 'foo' | A reference token in a JSON Pointer could not be resolved. +json.exception.out_of_range.405 | JSON pointer has no parent | The JSON Patch operations 'remove' and 'add' can not be applied to the root element of the JSON value. +json.exception.out_of_range.406 | number overflow parsing '10E1000' | A parsed number could not be stored as without changing it to NaN or INF. +json.exception.out_of_range.407 | number overflow serializing '9223372036854775808' | UBJSON and BSON only support integer numbers up to 9223372036854775807. (until version 3.8.0) | +json.exception.out_of_range.408 | excessive array size: 8658170730974374167 | The size (following `#`) of an UBJSON array or object exceeds the maximal capacity. | +json.exception.out_of_range.409 | BSON key cannot contain code point U+0000 (at byte 2) | Key identifiers to be serialized to BSON cannot contain code point U+0000, since the key is stored as zero-terminated c-string | + +@liveexample{The following code shows how an `out_of_range` exception can be +caught.,out_of_range} + +@sa - @ref exception for the base class of the library exceptions +@sa - @ref parse_error for exceptions indicating a parse error +@sa - @ref invalid_iterator for exceptions indicating errors with iterators +@sa - @ref type_error for exceptions indicating executing a member function with + a wrong type +@sa - @ref other_error for exceptions indicating other library errors + +@since version 3.0.0 +*/ +class out_of_range : public exception +{ + public: + template + static out_of_range create(int id_, const std::string& what_arg, const BasicJsonType& context) + { + std::string w = exception::name("out_of_range", id_) + exception::diagnostics(context) + what_arg; + return out_of_range(id_, w.c_str()); + } + + private: + JSON_HEDLEY_NON_NULL(3) + out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {} +}; + +/*! +@brief exception indicating other library errors + +This exception is thrown in case of errors that cannot be classified with the +other exception types. + +Exceptions have ids 5xx. + +name / id | example message | description +------------------------------ | --------------- | ------------------------- +json.exception.other_error.501 | unsuccessful: {"op":"test","path":"/baz", "value":"bar"} | A JSON Patch operation 'test' failed. The unsuccessful operation is also printed. + +@sa - @ref exception for the base class of the library exceptions +@sa - @ref parse_error for exceptions indicating a parse error +@sa - @ref invalid_iterator for exceptions indicating errors with iterators +@sa - @ref type_error for exceptions indicating executing a member function with + a wrong type +@sa - @ref out_of_range for exceptions indicating access out of the defined range + +@liveexample{The following code shows how an `other_error` exception can be +caught.,other_error} + +@since version 3.0.0 +*/ +class other_error : public exception +{ + public: + template + static other_error create(int id_, const std::string& what_arg, const BasicJsonType& context) + { + std::string w = exception::name("other_error", id_) + exception::diagnostics(context) + what_arg; + return other_error(id_, w.c_str()); + } + + private: + JSON_HEDLEY_NON_NULL(3) + other_error(int id_, const char* what_arg) : exception(id_, what_arg) {} +}; +} // namespace detail +} // namespace nlohmann + +// #include + +// #include + + +#include // size_t +#include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type +#include // index_sequence, make_index_sequence, index_sequence_for + +// #include + + +namespace nlohmann +{ +namespace detail +{ + +template +using uncvref_t = typename std::remove_cv::type>::type; + +#ifdef JSON_HAS_CPP_14 + +// the following utilities are natively available in C++14 +using std::enable_if_t; +using std::index_sequence; +using std::make_index_sequence; +using std::index_sequence_for; + +#else + +// alias templates to reduce boilerplate +template +using enable_if_t = typename std::enable_if::type; + +// The following code is taken from https://github.com/abseil/abseil-cpp/blob/10cb35e459f5ecca5b2ff107635da0bfa41011b4/absl/utility/utility.h +// which is part of Google Abseil (https://github.com/abseil/abseil-cpp), licensed under the Apache License 2.0. + +//// START OF CODE FROM GOOGLE ABSEIL + +// integer_sequence +// +// Class template representing a compile-time integer sequence. An instantiation +// of `integer_sequence` has a sequence of integers encoded in its +// type through its template arguments (which is a common need when +// working with C++11 variadic templates). `absl::integer_sequence` is designed +// to be a drop-in replacement for C++14's `std::integer_sequence`. +// +// Example: +// +// template< class T, T... Ints > +// void user_function(integer_sequence); +// +// int main() +// { +// // user_function's `T` will be deduced to `int` and `Ints...` +// // will be deduced to `0, 1, 2, 3, 4`. +// user_function(make_integer_sequence()); +// } +template +struct integer_sequence +{ + using value_type = T; + static constexpr std::size_t size() noexcept + { + return sizeof...(Ints); + } +}; + +// index_sequence +// +// A helper template for an `integer_sequence` of `size_t`, +// `absl::index_sequence` is designed to be a drop-in replacement for C++14's +// `std::index_sequence`. +template +using index_sequence = integer_sequence; + +namespace utility_internal +{ + +template +struct Extend; + +// Note that SeqSize == sizeof...(Ints). It's passed explicitly for efficiency. +template +struct Extend, SeqSize, 0> +{ + using type = integer_sequence < T, Ints..., (Ints + SeqSize)... >; +}; + +template +struct Extend, SeqSize, 1> +{ + using type = integer_sequence < T, Ints..., (Ints + SeqSize)..., 2 * SeqSize >; +}; + +// Recursion helper for 'make_integer_sequence'. +// 'Gen::type' is an alias for 'integer_sequence'. +template +struct Gen +{ + using type = + typename Extend < typename Gen < T, N / 2 >::type, N / 2, N % 2 >::type; +}; + +template +struct Gen +{ + using type = integer_sequence; +}; + +} // namespace utility_internal + +// Compile-time sequences of integers + +// make_integer_sequence +// +// This template alias is equivalent to +// `integer_sequence`, and is designed to be a drop-in +// replacement for C++14's `std::make_integer_sequence`. +template +using make_integer_sequence = typename utility_internal::Gen::type; + +// make_index_sequence +// +// This template alias is equivalent to `index_sequence<0, 1, ..., N-1>`, +// and is designed to be a drop-in replacement for C++14's +// `std::make_index_sequence`. +template +using make_index_sequence = make_integer_sequence; + +// index_sequence_for +// +// Converts a typename pack into an index sequence of the same length, and +// is designed to be a drop-in replacement for C++14's +// `std::index_sequence_for()` +template +using index_sequence_for = make_index_sequence; + +//// END OF CODE FROM GOOGLE ABSEIL + +#endif + +// dispatch utility (taken from ranges-v3) +template struct priority_tag : priority_tag < N - 1 > {}; +template<> struct priority_tag<0> {}; + +// taken from ranges-v3 +template +struct static_const +{ + static constexpr T value{}; +}; + +template +constexpr T static_const::value; + +} // namespace detail +} // namespace nlohmann + +// #include + + +namespace nlohmann +{ +namespace detail +{ +// dispatching helper struct +template struct identity_tag {}; +} // namespace detail +} // namespace nlohmann + +// #include + + +#include // numeric_limits +#include // false_type, is_constructible, is_integral, is_same, true_type +#include // declval +#include // tuple + +// #include + + +// #include + + +#include // random_access_iterator_tag + +// #include + +// #include + + +namespace nlohmann +{ +namespace detail +{ +template +struct iterator_types {}; + +template +struct iterator_types < + It, + void_t> +{ + using difference_type = typename It::difference_type; + using value_type = typename It::value_type; + using pointer = typename It::pointer; + using reference = typename It::reference; + using iterator_category = typename It::iterator_category; +}; + +// This is required as some compilers implement std::iterator_traits in a way that +// doesn't work with SFINAE. See https://github.com/nlohmann/json/issues/1341. +template +struct iterator_traits +{ +}; + +template +struct iterator_traits < T, enable_if_t < !std::is_pointer::value >> + : iterator_types +{ +}; + +template +struct iterator_traits::value>> +{ + using iterator_category = std::random_access_iterator_tag; + using value_type = T; + using difference_type = ptrdiff_t; + using pointer = T*; + using reference = T&; +}; +} // namespace detail +} // namespace nlohmann + +// #include + + +// #include + + +namespace nlohmann +{ +NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin); +} // namespace nlohmann + +// #include + + +// #include + + +namespace nlohmann +{ +NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end); +} // namespace nlohmann + +// #include + +// #include + +// #include +#ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_ +#define INCLUDE_NLOHMANN_JSON_FWD_HPP_ + +#include // int64_t, uint64_t +#include // map +#include // allocator +#include // string +#include // vector + +/*! +@brief namespace for Niels Lohmann +@see https://github.com/nlohmann +@since version 1.0.0 +*/ +namespace nlohmann +{ +/*! +@brief default JSONSerializer template argument + +This serializer ignores the template arguments and uses ADL +([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) +for serialization. +*/ +template +struct adl_serializer; + +template class ObjectType = + std::map, + template class ArrayType = std::vector, + class StringType = std::string, class BooleanType = bool, + class NumberIntegerType = std::int64_t, + class NumberUnsignedType = std::uint64_t, + class NumberFloatType = double, + template class AllocatorType = std::allocator, + template class JSONSerializer = + adl_serializer, + class BinaryType = std::vector> +class basic_json; + +/*! +@brief JSON Pointer + +A JSON pointer defines a string syntax for identifying a specific value +within a JSON document. It can be used with functions `at` and +`operator[]`. Furthermore, JSON pointers are the base for JSON patches. + +@sa [RFC 6901](https://tools.ietf.org/html/rfc6901) + +@since version 2.0.0 +*/ +template +class json_pointer; + +/*! +@brief default JSON class + +This type is the default specialization of the @ref basic_json class which +uses the standard template types. + +@since version 1.0.0 +*/ +using json = basic_json<>; + +template +struct ordered_map; + +/*! +@brief ordered JSON class + +This type preserves the insertion order of object keys. + +@since version 3.9.0 +*/ +using ordered_json = basic_json; + +} // namespace nlohmann + +#endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_ + + +namespace nlohmann +{ +/*! +@brief detail namespace with internal helper functions + +This namespace collects functions that should not be exposed, +implementations of some @ref basic_json methods, and meta-programming helpers. + +@since version 2.1.0 +*/ +namespace detail +{ +///////////// +// helpers // +///////////// + +// Note to maintainers: +// +// Every trait in this file expects a non CV-qualified type. +// The only exceptions are in the 'aliases for detected' section +// (i.e. those of the form: decltype(T::member_function(std::declval()))) +// +// In this case, T has to be properly CV-qualified to constraint the function arguments +// (e.g. to_json(BasicJsonType&, const T&)) + +template struct is_basic_json : std::false_type {}; + +NLOHMANN_BASIC_JSON_TPL_DECLARATION +struct is_basic_json : std::true_type {}; + +////////////////////// +// json_ref helpers // +////////////////////// + +template +class json_ref; + +template +struct is_json_ref : std::false_type {}; + +template +struct is_json_ref> : std::true_type {}; + +////////////////////////// +// aliases for detected // +////////////////////////// + +template +using mapped_type_t = typename T::mapped_type; + +template +using key_type_t = typename T::key_type; + +template +using value_type_t = typename T::value_type; + +template +using difference_type_t = typename T::difference_type; + +template +using pointer_t = typename T::pointer; + +template +using reference_t = typename T::reference; + +template +using iterator_category_t = typename T::iterator_category; + +template +using to_json_function = decltype(T::to_json(std::declval()...)); + +template +using from_json_function = decltype(T::from_json(std::declval()...)); + +template +using get_template_function = decltype(std::declval().template get()); + +// trait checking if JSONSerializer::from_json(json const&, udt&) exists +template +struct has_from_json : std::false_type {}; + +// trait checking if j.get is valid +// use this trait instead of std::is_constructible or std::is_convertible, +// both rely on, or make use of implicit conversions, and thus fail when T +// has several constructors/operator= (see https://github.com/nlohmann/json/issues/958) +template +struct is_getable +{ + static constexpr bool value = is_detected::value; +}; + +template +struct has_from_json < BasicJsonType, T, enable_if_t < !is_basic_json::value >> +{ + using serializer = typename BasicJsonType::template json_serializer; + + static constexpr bool value = + is_detected_exact::value; +}; + +// This trait checks if JSONSerializer::from_json(json const&) exists +// this overload is used for non-default-constructible user-defined-types +template +struct has_non_default_from_json : std::false_type {}; + +template +struct has_non_default_from_json < BasicJsonType, T, enable_if_t < !is_basic_json::value >> +{ + using serializer = typename BasicJsonType::template json_serializer; + + static constexpr bool value = + is_detected_exact::value; +}; + +// This trait checks if BasicJsonType::json_serializer::to_json exists +// Do not evaluate the trait when T is a basic_json type, to avoid template instantiation infinite recursion. +template +struct has_to_json : std::false_type {}; + +template +struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json::value >> +{ + using serializer = typename BasicJsonType::template json_serializer; + + static constexpr bool value = + is_detected_exact::value; +}; + + +/////////////////// +// is_ functions // +/////////////////// + +// https://en.cppreference.com/w/cpp/types/conjunction +template struct conjunction : std::true_type { }; +template struct conjunction : B1 { }; +template +struct conjunction +: std::conditional, B1>::type {}; + +// https://en.cppreference.com/w/cpp/types/negation +template struct negation : std::integral_constant < bool, !B::value > { }; + +// Reimplementation of is_constructible and is_default_constructible, due to them being broken for +// std::pair and std::tuple until LWG 2367 fix (see https://cplusplus.github.io/LWG/lwg-defects.html#2367). +// This causes compile errors in e.g. clang 3.5 or gcc 4.9. +template +struct is_default_constructible : std::is_default_constructible {}; + +template +struct is_default_constructible> + : conjunction, is_default_constructible> {}; + +template +struct is_default_constructible> + : conjunction, is_default_constructible> {}; + +template +struct is_default_constructible> + : conjunction...> {}; + +template +struct is_default_constructible> + : conjunction...> {}; + + +template +struct is_constructible : std::is_constructible {}; + +template +struct is_constructible> : is_default_constructible> {}; + +template +struct is_constructible> : is_default_constructible> {}; + +template +struct is_constructible> : is_default_constructible> {}; + +template +struct is_constructible> : is_default_constructible> {}; + + +template +struct is_iterator_traits : std::false_type {}; + +template +struct is_iterator_traits> +{ + private: + using traits = iterator_traits; + + public: + static constexpr auto value = + is_detected::value && + is_detected::value && + is_detected::value && + is_detected::value && + is_detected::value; +}; + +template +struct is_range +{ + private: + using t_ref = typename std::add_lvalue_reference::type; + + using iterator = detected_t; + using sentinel = detected_t; + + // to be 100% correct, it should use https://en.cppreference.com/w/cpp/iterator/input_or_output_iterator + // and https://en.cppreference.com/w/cpp/iterator/sentinel_for + // but reimplementing these would be too much work, as a lot of other concepts are used underneath + static constexpr auto is_iterator_begin = + is_iterator_traits>::value; + + public: + static constexpr bool value = !std::is_same::value && !std::is_same::value && is_iterator_begin; +}; + +template +using iterator_t = enable_if_t::value, result_of_begin())>>; + +template +using range_value_t = value_type_t>>; + +// The following implementation of is_complete_type is taken from +// https://blogs.msdn.microsoft.com/vcblog/2015/12/02/partial-support-for-expression-sfinae-in-vs-2015-update-1/ +// and is written by Xiang Fan who agreed to using it in this library. + +template +struct is_complete_type : std::false_type {}; + +template +struct is_complete_type : std::true_type {}; + +template +struct is_compatible_object_type_impl : std::false_type {}; + +template +struct is_compatible_object_type_impl < + BasicJsonType, CompatibleObjectType, + enable_if_t < is_detected::value&& + is_detected::value >> +{ + using object_t = typename BasicJsonType::object_t; + + // macOS's is_constructible does not play well with nonesuch... + static constexpr bool value = + is_constructible::value && + is_constructible::value; +}; + +template +struct is_compatible_object_type + : is_compatible_object_type_impl {}; + +template +struct is_constructible_object_type_impl : std::false_type {}; + +template +struct is_constructible_object_type_impl < + BasicJsonType, ConstructibleObjectType, + enable_if_t < is_detected::value&& + is_detected::value >> +{ + using object_t = typename BasicJsonType::object_t; + + static constexpr bool value = + (is_default_constructible::value && + (std::is_move_assignable::value || + std::is_copy_assignable::value) && + (is_constructible::value && + std::is_same < + typename object_t::mapped_type, + typename ConstructibleObjectType::mapped_type >::value)) || + (has_from_json::value || + has_non_default_from_json < + BasicJsonType, + typename ConstructibleObjectType::mapped_type >::value); +}; + +template +struct is_constructible_object_type + : is_constructible_object_type_impl {}; + +template +struct is_compatible_string_type +{ + static constexpr auto value = + is_constructible::value; +}; + +template +struct is_constructible_string_type +{ + static constexpr auto value = + is_constructible::value; +}; + +template +struct is_compatible_array_type_impl : std::false_type {}; + +template +struct is_compatible_array_type_impl < + BasicJsonType, CompatibleArrayType, + enable_if_t < + is_detected::value&& + is_iterator_traits>>::value&& +// special case for types like std::filesystem::path whose iterator's value_type are themselves +// c.f. https://github.com/nlohmann/json/pull/3073 + !std::is_same>::value >> +{ + static constexpr bool value = + is_constructible>::value; +}; + +template +struct is_compatible_array_type + : is_compatible_array_type_impl {}; + +template +struct is_constructible_array_type_impl : std::false_type {}; + +template +struct is_constructible_array_type_impl < + BasicJsonType, ConstructibleArrayType, + enable_if_t::value >> + : std::true_type {}; + +template +struct is_constructible_array_type_impl < + BasicJsonType, ConstructibleArrayType, + enable_if_t < !std::is_same::value&& + !is_compatible_string_type::value&& + is_default_constructible::value&& +(std::is_move_assignable::value || + std::is_copy_assignable::value)&& +is_detected::value&& +is_iterator_traits>>::value&& +is_detected::value&& +// special case for types like std::filesystem::path whose iterator's value_type are themselves +// c.f. https://github.com/nlohmann/json/pull/3073 +!std::is_same>::value&& + is_complete_type < + detected_t>::value >> +{ + using value_type = range_value_t; + + static constexpr bool value = + std::is_same::value || + has_from_json::value || + has_non_default_from_json < + BasicJsonType, + value_type >::value; +}; + +template +struct is_constructible_array_type + : is_constructible_array_type_impl {}; + +template +struct is_compatible_integer_type_impl : std::false_type {}; + +template +struct is_compatible_integer_type_impl < + RealIntegerType, CompatibleNumberIntegerType, + enable_if_t < std::is_integral::value&& + std::is_integral::value&& + !std::is_same::value >> +{ + // is there an assert somewhere on overflows? + using RealLimits = std::numeric_limits; + using CompatibleLimits = std::numeric_limits; + + static constexpr auto value = + is_constructible::value && + CompatibleLimits::is_integer && + RealLimits::is_signed == CompatibleLimits::is_signed; +}; + +template +struct is_compatible_integer_type + : is_compatible_integer_type_impl {}; + +template +struct is_compatible_type_impl: std::false_type {}; + +template +struct is_compatible_type_impl < + BasicJsonType, CompatibleType, + enable_if_t::value >> +{ + static constexpr bool value = + has_to_json::value; +}; + +template +struct is_compatible_type + : is_compatible_type_impl {}; + +template +struct is_constructible_tuple : std::false_type {}; + +template +struct is_constructible_tuple> : conjunction...> {}; + +// a naive helper to check if a type is an ordered_map (exploits the fact that +// ordered_map inherits capacity() from std::vector) +template +struct is_ordered_map +{ + using one = char; + + struct two + { + char x[2]; // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + }; + + template static one test( decltype(&C::capacity) ) ; + template static two test(...); + + enum { value = sizeof(test(nullptr)) == sizeof(char) }; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) +}; + +// to avoid useless casts (see https://github.com/nlohmann/json/issues/2893#issuecomment-889152324) +template < typename T, typename U, enable_if_t < !std::is_same::value, int > = 0 > +T conditional_static_cast(U value) +{ + return static_cast(value); +} + +template::value, int> = 0> +T conditional_static_cast(U value) +{ + return value; +} + +} // namespace detail +} // namespace nlohmann + +// #include + + +#ifdef JSON_HAS_CPP_17 + #include +#endif + +namespace nlohmann +{ +namespace detail +{ +template +void from_json(const BasicJsonType& j, typename std::nullptr_t& n) +{ + if (JSON_HEDLEY_UNLIKELY(!j.is_null())) + { + JSON_THROW(type_error::create(302, "type must be null, but is " + std::string(j.type_name()), j)); + } + n = nullptr; +} + +// overloads for basic_json template parameters +template < typename BasicJsonType, typename ArithmeticType, + enable_if_t < std::is_arithmetic::value&& + !std::is_same::value, + int > = 0 > +void get_arithmetic_value(const BasicJsonType& j, ArithmeticType& val) +{ + switch (static_cast(j)) + { + case value_t::number_unsigned: + { + val = static_cast(*j.template get_ptr()); + break; + } + case value_t::number_integer: + { + val = static_cast(*j.template get_ptr()); + break; + } + case value_t::number_float: + { + val = static_cast(*j.template get_ptr()); + break; + } + + case value_t::null: + case value_t::object: + case value_t::array: + case value_t::string: + case value_t::boolean: + case value_t::binary: + case value_t::discarded: + default: + JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()), j)); + } +} + +template +void from_json(const BasicJsonType& j, typename BasicJsonType::boolean_t& b) +{ + if (JSON_HEDLEY_UNLIKELY(!j.is_boolean())) + { + JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(j.type_name()), j)); + } + b = *j.template get_ptr(); +} + +template +void from_json(const BasicJsonType& j, typename BasicJsonType::string_t& s) +{ + if (JSON_HEDLEY_UNLIKELY(!j.is_string())) + { + JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j)); + } + s = *j.template get_ptr(); +} + +template < + typename BasicJsonType, typename ConstructibleStringType, + enable_if_t < + is_constructible_string_type::value&& + !std::is_same::value, + int > = 0 > +void from_json(const BasicJsonType& j, ConstructibleStringType& s) +{ + if (JSON_HEDLEY_UNLIKELY(!j.is_string())) + { + JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j)); + } + + s = *j.template get_ptr(); +} + +template +void from_json(const BasicJsonType& j, typename BasicJsonType::number_float_t& val) +{ + get_arithmetic_value(j, val); +} + +template +void from_json(const BasicJsonType& j, typename BasicJsonType::number_unsigned_t& val) +{ + get_arithmetic_value(j, val); +} + +template +void from_json(const BasicJsonType& j, typename BasicJsonType::number_integer_t& val) +{ + get_arithmetic_value(j, val); +} + +template::value, int> = 0> +void from_json(const BasicJsonType& j, EnumType& e) +{ + typename std::underlying_type::type val; + get_arithmetic_value(j, val); + e = static_cast(val); +} + +// forward_list doesn't have an insert method +template::value, int> = 0> +void from_json(const BasicJsonType& j, std::forward_list& l) +{ + if (JSON_HEDLEY_UNLIKELY(!j.is_array())) + { + JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j)); + } + l.clear(); + std::transform(j.rbegin(), j.rend(), + std::front_inserter(l), [](const BasicJsonType & i) + { + return i.template get(); + }); +} + +// valarray doesn't have an insert method +template::value, int> = 0> +void from_json(const BasicJsonType& j, std::valarray& l) +{ + if (JSON_HEDLEY_UNLIKELY(!j.is_array())) + { + JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j)); + } + l.resize(j.size()); + std::transform(j.begin(), j.end(), std::begin(l), + [](const BasicJsonType & elem) + { + return elem.template get(); + }); +} + +template +auto from_json(const BasicJsonType& j, T (&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) +-> decltype(j.template get(), void()) +{ + for (std::size_t i = 0; i < N; ++i) + { + arr[i] = j.at(i).template get(); + } +} + +template +void from_json_array_impl(const BasicJsonType& j, typename BasicJsonType::array_t& arr, priority_tag<3> /*unused*/) +{ + arr = *j.template get_ptr(); +} + +template +auto from_json_array_impl(const BasicJsonType& j, std::array& arr, + priority_tag<2> /*unused*/) +-> decltype(j.template get(), void()) +{ + for (std::size_t i = 0; i < N; ++i) + { + arr[i] = j.at(i).template get(); + } +} + +template::value, + int> = 0> +auto from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, priority_tag<1> /*unused*/) +-> decltype( + arr.reserve(std::declval()), + j.template get(), + void()) +{ + using std::end; + + ConstructibleArrayType ret; + ret.reserve(j.size()); + std::transform(j.begin(), j.end(), + std::inserter(ret, end(ret)), [](const BasicJsonType & i) + { + // get() returns *this, this won't call a from_json + // method when value_type is BasicJsonType + return i.template get(); + }); + arr = std::move(ret); +} + +template::value, + int> = 0> +void from_json_array_impl(const BasicJsonType& j, ConstructibleArrayType& arr, + priority_tag<0> /*unused*/) +{ + using std::end; + + ConstructibleArrayType ret; + std::transform( + j.begin(), j.end(), std::inserter(ret, end(ret)), + [](const BasicJsonType & i) + { + // get() returns *this, this won't call a from_json + // method when value_type is BasicJsonType + return i.template get(); + }); + arr = std::move(ret); +} + +template < typename BasicJsonType, typename ConstructibleArrayType, + enable_if_t < + is_constructible_array_type::value&& + !is_constructible_object_type::value&& + !is_constructible_string_type::value&& + !std::is_same::value&& + !is_basic_json::value, + int > = 0 > +auto from_json(const BasicJsonType& j, ConstructibleArrayType& arr) +-> decltype(from_json_array_impl(j, arr, priority_tag<3> {}), +j.template get(), +void()) +{ + if (JSON_HEDLEY_UNLIKELY(!j.is_array())) + { + JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j)); + } + + from_json_array_impl(j, arr, priority_tag<3> {}); +} + +template < typename BasicJsonType, typename T, std::size_t... Idx > +std::array from_json_inplace_array_impl(BasicJsonType&& j, + identity_tag> /*unused*/, index_sequence /*unused*/) +{ + return { { std::forward(j).at(Idx).template get()... } }; +} + +template < typename BasicJsonType, typename T, std::size_t N > +auto from_json(BasicJsonType&& j, identity_tag> tag) +-> decltype(from_json_inplace_array_impl(std::forward(j), tag, make_index_sequence {})) +{ + if (JSON_HEDLEY_UNLIKELY(!j.is_array())) + { + JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j)); + } + + return from_json_inplace_array_impl(std::forward(j), tag, make_index_sequence {}); +} + +template +void from_json(const BasicJsonType& j, typename BasicJsonType::binary_t& bin) +{ + if (JSON_HEDLEY_UNLIKELY(!j.is_binary())) + { + JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(j.type_name()), j)); + } + + bin = *j.template get_ptr(); +} + +template::value, int> = 0> +void from_json(const BasicJsonType& j, ConstructibleObjectType& obj) +{ + if (JSON_HEDLEY_UNLIKELY(!j.is_object())) + { + JSON_THROW(type_error::create(302, "type must be object, but is " + std::string(j.type_name()), j)); + } + + ConstructibleObjectType ret; + const auto* inner_object = j.template get_ptr(); + using value_type = typename ConstructibleObjectType::value_type; + std::transform( + inner_object->begin(), inner_object->end(), + std::inserter(ret, ret.begin()), + [](typename BasicJsonType::object_t::value_type const & p) + { + return value_type(p.first, p.second.template get()); + }); + obj = std::move(ret); +} + +// overload for arithmetic types, not chosen for basic_json template arguments +// (BooleanType, etc..); note: Is it really necessary to provide explicit +// overloads for boolean_t etc. in case of a custom BooleanType which is not +// an arithmetic type? +template < typename BasicJsonType, typename ArithmeticType, + enable_if_t < + std::is_arithmetic::value&& + !std::is_same::value&& + !std::is_same::value&& + !std::is_same::value&& + !std::is_same::value, + int > = 0 > +void from_json(const BasicJsonType& j, ArithmeticType& val) +{ + switch (static_cast(j)) + { + case value_t::number_unsigned: + { + val = static_cast(*j.template get_ptr()); + break; + } + case value_t::number_integer: + { + val = static_cast(*j.template get_ptr()); + break; + } + case value_t::number_float: + { + val = static_cast(*j.template get_ptr()); + break; + } + case value_t::boolean: + { + val = static_cast(*j.template get_ptr()); + break; + } + + case value_t::null: + case value_t::object: + case value_t::array: + case value_t::string: + case value_t::binary: + case value_t::discarded: + default: + JSON_THROW(type_error::create(302, "type must be number, but is " + std::string(j.type_name()), j)); + } +} + +template +std::tuple from_json_tuple_impl_base(BasicJsonType&& j, index_sequence /*unused*/) +{ + return std::make_tuple(std::forward(j).at(Idx).template get()...); +} + +template < typename BasicJsonType, class A1, class A2 > +std::pair from_json_tuple_impl(BasicJsonType&& j, identity_tag> /*unused*/, priority_tag<0> /*unused*/) +{ + return {std::forward(j).at(0).template get(), + std::forward(j).at(1).template get()}; +} + +template +void from_json_tuple_impl(BasicJsonType&& j, std::pair& p, priority_tag<1> /*unused*/) +{ + p = from_json_tuple_impl(std::forward(j), identity_tag> {}, priority_tag<0> {}); +} + +template +std::tuple from_json_tuple_impl(BasicJsonType&& j, identity_tag> /*unused*/, priority_tag<2> /*unused*/) +{ + return from_json_tuple_impl_base(std::forward(j), index_sequence_for {}); +} + +template +void from_json_tuple_impl(BasicJsonType&& j, std::tuple& t, priority_tag<3> /*unused*/) +{ + t = from_json_tuple_impl_base(std::forward(j), index_sequence_for {}); +} + +template +auto from_json(BasicJsonType&& j, TupleRelated&& t) +-> decltype(from_json_tuple_impl(std::forward(j), std::forward(t), priority_tag<3> {})) +{ + if (JSON_HEDLEY_UNLIKELY(!j.is_array())) + { + JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j)); + } + + return from_json_tuple_impl(std::forward(j), std::forward(t), priority_tag<3> {}); +} + +template < typename BasicJsonType, typename Key, typename Value, typename Compare, typename Allocator, + typename = enable_if_t < !std::is_constructible < + typename BasicJsonType::string_t, Key >::value >> +void from_json(const BasicJsonType& j, std::map& m) +{ + if (JSON_HEDLEY_UNLIKELY(!j.is_array())) + { + JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j)); + } + m.clear(); + for (const auto& p : j) + { + if (JSON_HEDLEY_UNLIKELY(!p.is_array())) + { + JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()), j)); + } + m.emplace(p.at(0).template get(), p.at(1).template get()); + } +} + +template < typename BasicJsonType, typename Key, typename Value, typename Hash, typename KeyEqual, typename Allocator, + typename = enable_if_t < !std::is_constructible < + typename BasicJsonType::string_t, Key >::value >> +void from_json(const BasicJsonType& j, std::unordered_map& m) +{ + if (JSON_HEDLEY_UNLIKELY(!j.is_array())) + { + JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(j.type_name()), j)); + } + m.clear(); + for (const auto& p : j) + { + if (JSON_HEDLEY_UNLIKELY(!p.is_array())) + { + JSON_THROW(type_error::create(302, "type must be array, but is " + std::string(p.type_name()), j)); + } + m.emplace(p.at(0).template get(), p.at(1).template get()); + } +} + +#ifdef JSON_HAS_CPP_17 +template +void from_json(const BasicJsonType& j, std::filesystem::path& p) +{ + if (JSON_HEDLEY_UNLIKELY(!j.is_string())) + { + JSON_THROW(type_error::create(302, "type must be string, but is " + std::string(j.type_name()), j)); + } + p = *j.template get_ptr(); +} +#endif + +struct from_json_fn +{ + template + auto operator()(const BasicJsonType& j, T&& val) const + noexcept(noexcept(from_json(j, std::forward(val)))) + -> decltype(from_json(j, std::forward(val))) + { + return from_json(j, std::forward(val)); + } +}; +} // namespace detail + +/// namespace to hold default `from_json` function +/// to see why this is required: +/// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html +namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces) +{ +constexpr const auto& from_json = detail::static_const::value; // NOLINT(misc-definitions-in-headers) +} // namespace +} // namespace nlohmann + +// #include + + +#include // copy +#include // begin, end +#include // string +#include // tuple, get +#include // is_same, is_constructible, is_floating_point, is_enum, underlying_type +#include // move, forward, declval, pair +#include // valarray +#include // vector + +// #include + +// #include + + +#include // size_t +#include // input_iterator_tag +#include // string, to_string +#include // tuple_size, get, tuple_element +#include // move + +// #include + +// #include + + +namespace nlohmann +{ +namespace detail +{ +template +void int_to_string( string_type& target, std::size_t value ) +{ + // For ADL + using std::to_string; + target = to_string(value); +} +template class iteration_proxy_value +{ + public: + using difference_type = std::ptrdiff_t; + using value_type = iteration_proxy_value; + using pointer = value_type * ; + using reference = value_type & ; + using iterator_category = std::input_iterator_tag; + using string_type = typename std::remove_cv< typename std::remove_reference().key() ) >::type >::type; + + private: + /// the iterator + IteratorType anchor; + /// an index for arrays (used to create key names) + std::size_t array_index = 0; + /// last stringified array index + mutable std::size_t array_index_last = 0; + /// a string representation of the array index + mutable string_type array_index_str = "0"; + /// an empty string (to return a reference for primitive values) + const string_type empty_str{}; + + public: + explicit iteration_proxy_value(IteratorType it) noexcept + : anchor(std::move(it)) + {} + + /// dereference operator (needed for range-based for) + iteration_proxy_value& operator*() + { + return *this; + } + + /// increment operator (needed for range-based for) + iteration_proxy_value& operator++() + { + ++anchor; + ++array_index; + + return *this; + } + + /// equality operator (needed for InputIterator) + bool operator==(const iteration_proxy_value& o) const + { + return anchor == o.anchor; + } + + /// inequality operator (needed for range-based for) + bool operator!=(const iteration_proxy_value& o) const + { + return anchor != o.anchor; + } + + /// return key of the iterator + const string_type& key() const + { + JSON_ASSERT(anchor.m_object != nullptr); + + switch (anchor.m_object->type()) + { + // use integer array index as key + case value_t::array: + { + if (array_index != array_index_last) + { + int_to_string( array_index_str, array_index ); + array_index_last = array_index; + } + return array_index_str; + } + + // use key from the object + case value_t::object: + return anchor.key(); + + // use an empty key for all primitive types + case value_t::null: + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + return empty_str; + } + } + + /// return value of the iterator + typename IteratorType::reference value() const + { + return anchor.value(); + } +}; + +/// proxy class for the items() function +template class iteration_proxy +{ + private: + /// the container to iterate + typename IteratorType::reference container; + + public: + /// construct iteration proxy from a container + explicit iteration_proxy(typename IteratorType::reference cont) noexcept + : container(cont) {} + + /// return iterator begin (needed for range-based for) + iteration_proxy_value begin() noexcept + { + return iteration_proxy_value(container.begin()); + } + + /// return iterator end (needed for range-based for) + iteration_proxy_value end() noexcept + { + return iteration_proxy_value(container.end()); + } +}; +// Structured Bindings Support +// For further reference see https://blog.tartanllama.xyz/structured-bindings/ +// And see https://github.com/nlohmann/json/pull/1391 +template = 0> +auto get(const nlohmann::detail::iteration_proxy_value& i) -> decltype(i.key()) +{ + return i.key(); +} +// Structured Bindings Support +// For further reference see https://blog.tartanllama.xyz/structured-bindings/ +// And see https://github.com/nlohmann/json/pull/1391 +template = 0> +auto get(const nlohmann::detail::iteration_proxy_value& i) -> decltype(i.value()) +{ + return i.value(); +} +} // namespace detail +} // namespace nlohmann + +// The Addition to the STD Namespace is required to add +// Structured Bindings Support to the iteration_proxy_value class +// For further reference see https://blog.tartanllama.xyz/structured-bindings/ +// And see https://github.com/nlohmann/json/pull/1391 +namespace std +{ +#if defined(__clang__) + // Fix: https://github.com/nlohmann/json/issues/1401 + #pragma clang diagnostic push + #pragma clang diagnostic ignored "-Wmismatched-tags" +#endif +template +class tuple_size<::nlohmann::detail::iteration_proxy_value> + : public std::integral_constant {}; + +template +class tuple_element> +{ + public: + using type = decltype( + get(std::declval < + ::nlohmann::detail::iteration_proxy_value> ())); +}; +#if defined(__clang__) + #pragma clang diagnostic pop +#endif +} // namespace std + +// #include + +// #include + +// #include + + +#ifdef JSON_HAS_CPP_17 + #include +#endif + +namespace nlohmann +{ +namespace detail +{ +////////////////// +// constructors // +////////////////// + +/* + * Note all external_constructor<>::construct functions need to call + * j.m_value.destroy(j.m_type) to avoid a memory leak in case j contains an + * allocated value (e.g., a string). See bug issue + * https://github.com/nlohmann/json/issues/2865 for more information. + */ + +template struct external_constructor; + +template<> +struct external_constructor +{ + template + static void construct(BasicJsonType& j, typename BasicJsonType::boolean_t b) noexcept + { + j.m_value.destroy(j.m_type); + j.m_type = value_t::boolean; + j.m_value = b; + j.assert_invariant(); + } +}; + +template<> +struct external_constructor +{ + template + static void construct(BasicJsonType& j, const typename BasicJsonType::string_t& s) + { + j.m_value.destroy(j.m_type); + j.m_type = value_t::string; + j.m_value = s; + j.assert_invariant(); + } + + template + static void construct(BasicJsonType& j, typename BasicJsonType::string_t&& s) + { + j.m_value.destroy(j.m_type); + j.m_type = value_t::string; + j.m_value = std::move(s); + j.assert_invariant(); + } + + template < typename BasicJsonType, typename CompatibleStringType, + enable_if_t < !std::is_same::value, + int > = 0 > + static void construct(BasicJsonType& j, const CompatibleStringType& str) + { + j.m_value.destroy(j.m_type); + j.m_type = value_t::string; + j.m_value.string = j.template create(str); + j.assert_invariant(); + } +}; + +template<> +struct external_constructor +{ + template + static void construct(BasicJsonType& j, const typename BasicJsonType::binary_t& b) + { + j.m_value.destroy(j.m_type); + j.m_type = value_t::binary; + j.m_value = typename BasicJsonType::binary_t(b); + j.assert_invariant(); + } + + template + static void construct(BasicJsonType& j, typename BasicJsonType::binary_t&& b) + { + j.m_value.destroy(j.m_type); + j.m_type = value_t::binary; + j.m_value = typename BasicJsonType::binary_t(std::move(b)); + j.assert_invariant(); + } +}; + +template<> +struct external_constructor +{ + template + static void construct(BasicJsonType& j, typename BasicJsonType::number_float_t val) noexcept + { + j.m_value.destroy(j.m_type); + j.m_type = value_t::number_float; + j.m_value = val; + j.assert_invariant(); + } +}; + +template<> +struct external_constructor +{ + template + static void construct(BasicJsonType& j, typename BasicJsonType::number_unsigned_t val) noexcept + { + j.m_value.destroy(j.m_type); + j.m_type = value_t::number_unsigned; + j.m_value = val; + j.assert_invariant(); + } +}; + +template<> +struct external_constructor +{ + template + static void construct(BasicJsonType& j, typename BasicJsonType::number_integer_t val) noexcept + { + j.m_value.destroy(j.m_type); + j.m_type = value_t::number_integer; + j.m_value = val; + j.assert_invariant(); + } +}; + +template<> +struct external_constructor +{ + template + static void construct(BasicJsonType& j, const typename BasicJsonType::array_t& arr) + { + j.m_value.destroy(j.m_type); + j.m_type = value_t::array; + j.m_value = arr; + j.set_parents(); + j.assert_invariant(); + } + + template + static void construct(BasicJsonType& j, typename BasicJsonType::array_t&& arr) + { + j.m_value.destroy(j.m_type); + j.m_type = value_t::array; + j.m_value = std::move(arr); + j.set_parents(); + j.assert_invariant(); + } + + template < typename BasicJsonType, typename CompatibleArrayType, + enable_if_t < !std::is_same::value, + int > = 0 > + static void construct(BasicJsonType& j, const CompatibleArrayType& arr) + { + using std::begin; + using std::end; + + j.m_value.destroy(j.m_type); + j.m_type = value_t::array; + j.m_value.array = j.template create(begin(arr), end(arr)); + j.set_parents(); + j.assert_invariant(); + } + + template + static void construct(BasicJsonType& j, const std::vector& arr) + { + j.m_value.destroy(j.m_type); + j.m_type = value_t::array; + j.m_value = value_t::array; + j.m_value.array->reserve(arr.size()); + for (const bool x : arr) + { + j.m_value.array->push_back(x); + j.set_parent(j.m_value.array->back()); + } + j.assert_invariant(); + } + + template::value, int> = 0> + static void construct(BasicJsonType& j, const std::valarray& arr) + { + j.m_value.destroy(j.m_type); + j.m_type = value_t::array; + j.m_value = value_t::array; + j.m_value.array->resize(arr.size()); + if (arr.size() > 0) + { + std::copy(std::begin(arr), std::end(arr), j.m_value.array->begin()); + } + j.set_parents(); + j.assert_invariant(); + } +}; + +template<> +struct external_constructor +{ + template + static void construct(BasicJsonType& j, const typename BasicJsonType::object_t& obj) + { + j.m_value.destroy(j.m_type); + j.m_type = value_t::object; + j.m_value = obj; + j.set_parents(); + j.assert_invariant(); + } + + template + static void construct(BasicJsonType& j, typename BasicJsonType::object_t&& obj) + { + j.m_value.destroy(j.m_type); + j.m_type = value_t::object; + j.m_value = std::move(obj); + j.set_parents(); + j.assert_invariant(); + } + + template < typename BasicJsonType, typename CompatibleObjectType, + enable_if_t < !std::is_same::value, int > = 0 > + static void construct(BasicJsonType& j, const CompatibleObjectType& obj) + { + using std::begin; + using std::end; + + j.m_value.destroy(j.m_type); + j.m_type = value_t::object; + j.m_value.object = j.template create(begin(obj), end(obj)); + j.set_parents(); + j.assert_invariant(); + } +}; + +///////////// +// to_json // +///////////// + +template::value, int> = 0> +void to_json(BasicJsonType& j, T b) noexcept +{ + external_constructor::construct(j, b); +} + +template::value, int> = 0> +void to_json(BasicJsonType& j, const CompatibleString& s) +{ + external_constructor::construct(j, s); +} + +template +void to_json(BasicJsonType& j, typename BasicJsonType::string_t&& s) +{ + external_constructor::construct(j, std::move(s)); +} + +template::value, int> = 0> +void to_json(BasicJsonType& j, FloatType val) noexcept +{ + external_constructor::construct(j, static_cast(val)); +} + +template::value, int> = 0> +void to_json(BasicJsonType& j, CompatibleNumberUnsignedType val) noexcept +{ + external_constructor::construct(j, static_cast(val)); +} + +template::value, int> = 0> +void to_json(BasicJsonType& j, CompatibleNumberIntegerType val) noexcept +{ + external_constructor::construct(j, static_cast(val)); +} + +template::value, int> = 0> +void to_json(BasicJsonType& j, EnumType e) noexcept +{ + using underlying_type = typename std::underlying_type::type; + external_constructor::construct(j, static_cast(e)); +} + +template +void to_json(BasicJsonType& j, const std::vector& e) +{ + external_constructor::construct(j, e); +} + +template < typename BasicJsonType, typename CompatibleArrayType, + enable_if_t < is_compatible_array_type::value&& + !is_compatible_object_type::value&& + !is_compatible_string_type::value&& + !std::is_same::value&& + !is_basic_json::value, + int > = 0 > +void to_json(BasicJsonType& j, const CompatibleArrayType& arr) +{ + external_constructor::construct(j, arr); +} + +template +void to_json(BasicJsonType& j, const typename BasicJsonType::binary_t& bin) +{ + external_constructor::construct(j, bin); +} + +template::value, int> = 0> +void to_json(BasicJsonType& j, const std::valarray& arr) +{ + external_constructor::construct(j, std::move(arr)); +} + +template +void to_json(BasicJsonType& j, typename BasicJsonType::array_t&& arr) +{ + external_constructor::construct(j, std::move(arr)); +} + +template < typename BasicJsonType, typename CompatibleObjectType, + enable_if_t < is_compatible_object_type::value&& !is_basic_json::value, int > = 0 > +void to_json(BasicJsonType& j, const CompatibleObjectType& obj) +{ + external_constructor::construct(j, obj); +} + +template +void to_json(BasicJsonType& j, typename BasicJsonType::object_t&& obj) +{ + external_constructor::construct(j, std::move(obj)); +} + +template < + typename BasicJsonType, typename T, std::size_t N, + enable_if_t < !std::is_constructible::value, // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + int > = 0 > +void to_json(BasicJsonType& j, const T(&arr)[N]) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) +{ + external_constructor::construct(j, arr); +} + +template < typename BasicJsonType, typename T1, typename T2, enable_if_t < std::is_constructible::value&& std::is_constructible::value, int > = 0 > +void to_json(BasicJsonType& j, const std::pair& p) +{ + j = { p.first, p.second }; +} + +// for https://github.com/nlohmann/json/pull/1134 +template>::value, int> = 0> +void to_json(BasicJsonType& j, const T& b) +{ + j = { {b.key(), b.value()} }; +} + +template +void to_json_tuple_impl(BasicJsonType& j, const Tuple& t, index_sequence /*unused*/) +{ + j = { std::get(t)... }; +} + +template::value, int > = 0> +void to_json(BasicJsonType& j, const T& t) +{ + to_json_tuple_impl(j, t, make_index_sequence::value> {}); +} + +#ifdef JSON_HAS_CPP_17 +template +void to_json(BasicJsonType& j, const std::filesystem::path& p) +{ + j = p.string(); +} +#endif + +struct to_json_fn +{ + template + auto operator()(BasicJsonType& j, T&& val) const noexcept(noexcept(to_json(j, std::forward(val)))) + -> decltype(to_json(j, std::forward(val)), void()) + { + return to_json(j, std::forward(val)); + } +}; +} // namespace detail + +/// namespace to hold default `to_json` function +/// to see why this is required: +/// http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/n4381.html +namespace // NOLINT(cert-dcl59-cpp,fuchsia-header-anon-namespaces,google-build-namespaces) +{ +constexpr const auto& to_json = detail::static_const::value; // NOLINT(misc-definitions-in-headers) +} // namespace +} // namespace nlohmann + +// #include + +// #include + + +namespace nlohmann +{ + +template +struct adl_serializer +{ + /*! + @brief convert a JSON value to any value type + + This function is usually called by the `get()` function of the + @ref basic_json class (either explicit or via conversion operators). + + @note This function is chosen for default-constructible value types. + + @param[in] j JSON value to read from + @param[in,out] val value to write to + */ + template + static auto from_json(BasicJsonType && j, TargetType& val) noexcept( + noexcept(::nlohmann::from_json(std::forward(j), val))) + -> decltype(::nlohmann::from_json(std::forward(j), val), void()) + { + ::nlohmann::from_json(std::forward(j), val); + } + + /*! + @brief convert a JSON value to any value type + + This function is usually called by the `get()` function of the + @ref basic_json class (either explicit or via conversion operators). + + @note This function is chosen for value types which are not default-constructible. + + @param[in] j JSON value to read from + + @return copy of the JSON value, converted to @a ValueType + */ + template + static auto from_json(BasicJsonType && j) noexcept( + noexcept(::nlohmann::from_json(std::forward(j), detail::identity_tag {}))) + -> decltype(::nlohmann::from_json(std::forward(j), detail::identity_tag {})) + { + return ::nlohmann::from_json(std::forward(j), detail::identity_tag {}); + } + + /*! + @brief convert any value type to a JSON value + + This function is usually called by the constructors of the @ref basic_json + class. + + @param[in,out] j JSON value to write to + @param[in] val value to read from + */ + template + static auto to_json(BasicJsonType& j, TargetType && val) noexcept( + noexcept(::nlohmann::to_json(j, std::forward(val)))) + -> decltype(::nlohmann::to_json(j, std::forward(val)), void()) + { + ::nlohmann::to_json(j, std::forward(val)); + } +}; +} // namespace nlohmann + +// #include + + +#include // uint8_t, uint64_t +#include // tie +#include // move + +namespace nlohmann +{ + +/*! +@brief an internal type for a backed binary type + +This type extends the template parameter @a BinaryType provided to `basic_json` +with a subtype used by BSON and MessagePack. This type exists so that the user +does not have to specify a type themselves with a specific naming scheme in +order to override the binary type. + +@tparam BinaryType container to store bytes (`std::vector` by + default) + +@since version 3.8.0; changed type of subtypes to std::uint64_t in 3.10.0. +*/ +template +class byte_container_with_subtype : public BinaryType +{ + public: + /// the type of the underlying container + using container_type = BinaryType; + /// the type of the subtype + using subtype_type = std::uint64_t; + + byte_container_with_subtype() noexcept(noexcept(container_type())) + : container_type() + {} + + byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b))) + : container_type(b) + {} + + byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b)))) + : container_type(std::move(b)) + {} + + byte_container_with_subtype(const container_type& b, subtype_type subtype_) noexcept(noexcept(container_type(b))) + : container_type(b) + , m_subtype(subtype_) + , m_has_subtype(true) + {} + + byte_container_with_subtype(container_type&& b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b)))) + : container_type(std::move(b)) + , m_subtype(subtype_) + , m_has_subtype(true) + {} + + bool operator==(const byte_container_with_subtype& rhs) const + { + return std::tie(static_cast(*this), m_subtype, m_has_subtype) == + std::tie(static_cast(rhs), rhs.m_subtype, rhs.m_has_subtype); + } + + bool operator!=(const byte_container_with_subtype& rhs) const + { + return !(rhs == *this); + } + + /*! + @brief sets the binary subtype + + Sets the binary subtype of the value, also flags a binary JSON value as + having a subtype, which has implications for serialization. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @sa see @ref subtype() -- return the binary subtype + @sa see @ref clear_subtype() -- clears the binary subtype + @sa see @ref has_subtype() -- returns whether or not the binary value has a + subtype + + @since version 3.8.0 + */ + void set_subtype(subtype_type subtype_) noexcept + { + m_subtype = subtype_; + m_has_subtype = true; + } + + /*! + @brief return the binary subtype + + Returns the numerical subtype of the value if it has a subtype. If it does + not have a subtype, this function will return subtype_type(-1) as a sentinel + value. + + @return the numerical subtype of the binary value + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @sa see @ref set_subtype() -- sets the binary subtype + @sa see @ref clear_subtype() -- clears the binary subtype + @sa see @ref has_subtype() -- returns whether or not the binary value has a + subtype + + @since version 3.8.0; fixed return value to properly return + subtype_type(-1) as documented in version 3.10.0 + */ + constexpr subtype_type subtype() const noexcept + { + return m_has_subtype ? m_subtype : subtype_type(-1); + } + + /*! + @brief return whether the value has a subtype + + @return whether the value has a subtype + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @sa see @ref subtype() -- return the binary subtype + @sa see @ref set_subtype() -- sets the binary subtype + @sa see @ref clear_subtype() -- clears the binary subtype + + @since version 3.8.0 + */ + constexpr bool has_subtype() const noexcept + { + return m_has_subtype; + } + + /*! + @brief clears the binary subtype + + Clears the binary subtype and flags the value as not having a subtype, which + has implications for serialization; for instance MessagePack will prefer the + bin family over the ext family. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @sa see @ref subtype() -- return the binary subtype + @sa see @ref set_subtype() -- sets the binary subtype + @sa see @ref has_subtype() -- returns whether or not the binary value has a + subtype + + @since version 3.8.0 + */ + void clear_subtype() noexcept + { + m_subtype = 0; + m_has_subtype = false; + } + + private: + subtype_type m_subtype = 0; + bool m_has_subtype = false; +}; + +} // namespace nlohmann + +// #include + +// #include + +// #include + +// #include + + +#include // uint8_t +#include // size_t +#include // hash + +// #include + +// #include + + +namespace nlohmann +{ +namespace detail +{ + +// boost::hash_combine +inline std::size_t combine(std::size_t seed, std::size_t h) noexcept +{ + seed ^= h + 0x9e3779b9 + (seed << 6U) + (seed >> 2U); + return seed; +} + +/*! +@brief hash a JSON value + +The hash function tries to rely on std::hash where possible. Furthermore, the +type of the JSON value is taken into account to have different hash values for +null, 0, 0U, and false, etc. + +@tparam BasicJsonType basic_json specialization +@param j JSON value to hash +@return hash value of j +*/ +template +std::size_t hash(const BasicJsonType& j) +{ + using string_t = typename BasicJsonType::string_t; + using number_integer_t = typename BasicJsonType::number_integer_t; + using number_unsigned_t = typename BasicJsonType::number_unsigned_t; + using number_float_t = typename BasicJsonType::number_float_t; + + const auto type = static_cast(j.type()); + switch (j.type()) + { + case BasicJsonType::value_t::null: + case BasicJsonType::value_t::discarded: + { + return combine(type, 0); + } + + case BasicJsonType::value_t::object: + { + auto seed = combine(type, j.size()); + for (const auto& element : j.items()) + { + const auto h = std::hash {}(element.key()); + seed = combine(seed, h); + seed = combine(seed, hash(element.value())); + } + return seed; + } + + case BasicJsonType::value_t::array: + { + auto seed = combine(type, j.size()); + for (const auto& element : j) + { + seed = combine(seed, hash(element)); + } + return seed; + } + + case BasicJsonType::value_t::string: + { + const auto h = std::hash {}(j.template get_ref()); + return combine(type, h); + } + + case BasicJsonType::value_t::boolean: + { + const auto h = std::hash {}(j.template get()); + return combine(type, h); + } + + case BasicJsonType::value_t::number_integer: + { + const auto h = std::hash {}(j.template get()); + return combine(type, h); + } + + case BasicJsonType::value_t::number_unsigned: + { + const auto h = std::hash {}(j.template get()); + return combine(type, h); + } + + case BasicJsonType::value_t::number_float: + { + const auto h = std::hash {}(j.template get()); + return combine(type, h); + } + + case BasicJsonType::value_t::binary: + { + auto seed = combine(type, j.get_binary().size()); + const auto h = std::hash {}(j.get_binary().has_subtype()); + seed = combine(seed, h); + seed = combine(seed, static_cast(j.get_binary().subtype())); + for (const auto byte : j.get_binary()) + { + seed = combine(seed, std::hash {}(byte)); + } + return seed; + } + + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + return 0; // LCOV_EXCL_LINE + } +} + +} // namespace detail +} // namespace nlohmann + +// #include + + +#include // generate_n +#include // array +#include // ldexp +#include // size_t +#include // uint8_t, uint16_t, uint32_t, uint64_t +#include // snprintf +#include // memcpy +#include // back_inserter +#include // numeric_limits +#include // char_traits, string +#include // make_pair, move +#include // vector + +// #include + +// #include + + +#include // array +#include // size_t +#include // strlen +#include // begin, end, iterator_traits, random_access_iterator_tag, distance, next +#include // shared_ptr, make_shared, addressof +#include // accumulate +#include // string, char_traits +#include // enable_if, is_base_of, is_pointer, is_integral, remove_pointer +#include // pair, declval + +#ifndef JSON_NO_IO + #include // FILE * + #include // istream +#endif // JSON_NO_IO + +// #include + +// #include + + +namespace nlohmann +{ +namespace detail +{ +/// the supported input formats +enum class input_format_t { json, cbor, msgpack, ubjson, bson }; + +//////////////////// +// input adapters // +//////////////////// + +#ifndef JSON_NO_IO +/*! +Input adapter for stdio file access. This adapter read only 1 byte and do not use any + buffer. This adapter is a very low level adapter. +*/ +class file_input_adapter +{ + public: + using char_type = char; + + JSON_HEDLEY_NON_NULL(2) + explicit file_input_adapter(std::FILE* f) noexcept + : m_file(f) + {} + + // make class move-only + file_input_adapter(const file_input_adapter&) = delete; + file_input_adapter(file_input_adapter&&) noexcept = default; + file_input_adapter& operator=(const file_input_adapter&) = delete; + file_input_adapter& operator=(file_input_adapter&&) = delete; + ~file_input_adapter() = default; + + std::char_traits::int_type get_character() noexcept + { + return std::fgetc(m_file); + } + + private: + /// the file pointer to read from + std::FILE* m_file; +}; + + +/*! +Input adapter for a (caching) istream. Ignores a UFT Byte Order Mark at +beginning of input. Does not support changing the underlying std::streambuf +in mid-input. Maintains underlying std::istream and std::streambuf to support +subsequent use of standard std::istream operations to process any input +characters following those used in parsing the JSON input. Clears the +std::istream flags; any input errors (e.g., EOF) will be detected by the first +subsequent call for input from the std::istream. +*/ +class input_stream_adapter +{ + public: + using char_type = char; + + ~input_stream_adapter() + { + // clear stream flags; we use underlying streambuf I/O, do not + // maintain ifstream flags, except eof + if (is != nullptr) + { + is->clear(is->rdstate() & std::ios::eofbit); + } + } + + explicit input_stream_adapter(std::istream& i) + : is(&i), sb(i.rdbuf()) + {} + + // delete because of pointer members + input_stream_adapter(const input_stream_adapter&) = delete; + input_stream_adapter& operator=(input_stream_adapter&) = delete; + input_stream_adapter& operator=(input_stream_adapter&&) = delete; + + input_stream_adapter(input_stream_adapter&& rhs) noexcept + : is(rhs.is), sb(rhs.sb) + { + rhs.is = nullptr; + rhs.sb = nullptr; + } + + // std::istream/std::streambuf use std::char_traits::to_int_type, to + // ensure that std::char_traits::eof() and the character 0xFF do not + // end up as the same value, eg. 0xFFFFFFFF. + std::char_traits::int_type get_character() + { + auto res = sb->sbumpc(); + // set eof manually, as we don't use the istream interface. + if (JSON_HEDLEY_UNLIKELY(res == std::char_traits::eof())) + { + is->clear(is->rdstate() | std::ios::eofbit); + } + return res; + } + + private: + /// the associated input stream + std::istream* is = nullptr; + std::streambuf* sb = nullptr; +}; +#endif // JSON_NO_IO + +// General-purpose iterator-based adapter. It might not be as fast as +// theoretically possible for some containers, but it is extremely versatile. +template +class iterator_input_adapter +{ + public: + using char_type = typename std::iterator_traits::value_type; + + iterator_input_adapter(IteratorType first, IteratorType last) + : current(std::move(first)), end(std::move(last)) + {} + + typename std::char_traits::int_type get_character() + { + if (JSON_HEDLEY_LIKELY(current != end)) + { + auto result = std::char_traits::to_int_type(*current); + std::advance(current, 1); + return result; + } + + return std::char_traits::eof(); + } + + private: + IteratorType current; + IteratorType end; + + template + friend struct wide_string_input_helper; + + bool empty() const + { + return current == end; + } +}; + + +template +struct wide_string_input_helper; + +template +struct wide_string_input_helper +{ + // UTF-32 + static void fill_buffer(BaseInputAdapter& input, + std::array::int_type, 4>& utf8_bytes, + size_t& utf8_bytes_index, + size_t& utf8_bytes_filled) + { + utf8_bytes_index = 0; + + if (JSON_HEDLEY_UNLIKELY(input.empty())) + { + utf8_bytes[0] = std::char_traits::eof(); + utf8_bytes_filled = 1; + } + else + { + // get the current character + const auto wc = input.get_character(); + + // UTF-32 to UTF-8 encoding + if (wc < 0x80) + { + utf8_bytes[0] = static_cast::int_type>(wc); + utf8_bytes_filled = 1; + } + else if (wc <= 0x7FF) + { + utf8_bytes[0] = static_cast::int_type>(0xC0u | ((static_cast(wc) >> 6u) & 0x1Fu)); + utf8_bytes[1] = static_cast::int_type>(0x80u | (static_cast(wc) & 0x3Fu)); + utf8_bytes_filled = 2; + } + else if (wc <= 0xFFFF) + { + utf8_bytes[0] = static_cast::int_type>(0xE0u | ((static_cast(wc) >> 12u) & 0x0Fu)); + utf8_bytes[1] = static_cast::int_type>(0x80u | ((static_cast(wc) >> 6u) & 0x3Fu)); + utf8_bytes[2] = static_cast::int_type>(0x80u | (static_cast(wc) & 0x3Fu)); + utf8_bytes_filled = 3; + } + else if (wc <= 0x10FFFF) + { + utf8_bytes[0] = static_cast::int_type>(0xF0u | ((static_cast(wc) >> 18u) & 0x07u)); + utf8_bytes[1] = static_cast::int_type>(0x80u | ((static_cast(wc) >> 12u) & 0x3Fu)); + utf8_bytes[2] = static_cast::int_type>(0x80u | ((static_cast(wc) >> 6u) & 0x3Fu)); + utf8_bytes[3] = static_cast::int_type>(0x80u | (static_cast(wc) & 0x3Fu)); + utf8_bytes_filled = 4; + } + else + { + // unknown character + utf8_bytes[0] = static_cast::int_type>(wc); + utf8_bytes_filled = 1; + } + } + } +}; + +template +struct wide_string_input_helper +{ + // UTF-16 + static void fill_buffer(BaseInputAdapter& input, + std::array::int_type, 4>& utf8_bytes, + size_t& utf8_bytes_index, + size_t& utf8_bytes_filled) + { + utf8_bytes_index = 0; + + if (JSON_HEDLEY_UNLIKELY(input.empty())) + { + utf8_bytes[0] = std::char_traits::eof(); + utf8_bytes_filled = 1; + } + else + { + // get the current character + const auto wc = input.get_character(); + + // UTF-16 to UTF-8 encoding + if (wc < 0x80) + { + utf8_bytes[0] = static_cast::int_type>(wc); + utf8_bytes_filled = 1; + } + else if (wc <= 0x7FF) + { + utf8_bytes[0] = static_cast::int_type>(0xC0u | ((static_cast(wc) >> 6u))); + utf8_bytes[1] = static_cast::int_type>(0x80u | (static_cast(wc) & 0x3Fu)); + utf8_bytes_filled = 2; + } + else if (0xD800 > wc || wc >= 0xE000) + { + utf8_bytes[0] = static_cast::int_type>(0xE0u | ((static_cast(wc) >> 12u))); + utf8_bytes[1] = static_cast::int_type>(0x80u | ((static_cast(wc) >> 6u) & 0x3Fu)); + utf8_bytes[2] = static_cast::int_type>(0x80u | (static_cast(wc) & 0x3Fu)); + utf8_bytes_filled = 3; + } + else + { + if (JSON_HEDLEY_UNLIKELY(!input.empty())) + { + const auto wc2 = static_cast(input.get_character()); + const auto charcode = 0x10000u + (((static_cast(wc) & 0x3FFu) << 10u) | (wc2 & 0x3FFu)); + utf8_bytes[0] = static_cast::int_type>(0xF0u | (charcode >> 18u)); + utf8_bytes[1] = static_cast::int_type>(0x80u | ((charcode >> 12u) & 0x3Fu)); + utf8_bytes[2] = static_cast::int_type>(0x80u | ((charcode >> 6u) & 0x3Fu)); + utf8_bytes[3] = static_cast::int_type>(0x80u | (charcode & 0x3Fu)); + utf8_bytes_filled = 4; + } + else + { + utf8_bytes[0] = static_cast::int_type>(wc); + utf8_bytes_filled = 1; + } + } + } + } +}; + +// Wraps another input apdater to convert wide character types into individual bytes. +template +class wide_string_input_adapter +{ + public: + using char_type = char; + + wide_string_input_adapter(BaseInputAdapter base) + : base_adapter(base) {} + + typename std::char_traits::int_type get_character() noexcept + { + // check if buffer needs to be filled + if (utf8_bytes_index == utf8_bytes_filled) + { + fill_buffer(); + + JSON_ASSERT(utf8_bytes_filled > 0); + JSON_ASSERT(utf8_bytes_index == 0); + } + + // use buffer + JSON_ASSERT(utf8_bytes_filled > 0); + JSON_ASSERT(utf8_bytes_index < utf8_bytes_filled); + return utf8_bytes[utf8_bytes_index++]; + } + + private: + BaseInputAdapter base_adapter; + + template + void fill_buffer() + { + wide_string_input_helper::fill_buffer(base_adapter, utf8_bytes, utf8_bytes_index, utf8_bytes_filled); + } + + /// a buffer for UTF-8 bytes + std::array::int_type, 4> utf8_bytes = {{0, 0, 0, 0}}; + + /// index to the utf8_codes array for the next valid byte + std::size_t utf8_bytes_index = 0; + /// number of valid bytes in the utf8_codes array + std::size_t utf8_bytes_filled = 0; +}; + + +template +struct iterator_input_adapter_factory +{ + using iterator_type = IteratorType; + using char_type = typename std::iterator_traits::value_type; + using adapter_type = iterator_input_adapter; + + static adapter_type create(IteratorType first, IteratorType last) + { + return adapter_type(std::move(first), std::move(last)); + } +}; + +template +struct is_iterator_of_multibyte +{ + using value_type = typename std::iterator_traits::value_type; + enum + { + value = sizeof(value_type) > 1 + }; +}; + +template +struct iterator_input_adapter_factory::value>> +{ + using iterator_type = IteratorType; + using char_type = typename std::iterator_traits::value_type; + using base_adapter_type = iterator_input_adapter; + using adapter_type = wide_string_input_adapter; + + static adapter_type create(IteratorType first, IteratorType last) + { + return adapter_type(base_adapter_type(std::move(first), std::move(last))); + } +}; + +// General purpose iterator-based input +template +typename iterator_input_adapter_factory::adapter_type input_adapter(IteratorType first, IteratorType last) +{ + using factory_type = iterator_input_adapter_factory; + return factory_type::create(first, last); +} + +// Convenience shorthand from container to iterator +// Enables ADL on begin(container) and end(container) +// Encloses the using declarations in namespace for not to leak them to outside scope + +namespace container_input_adapter_factory_impl +{ + +using std::begin; +using std::end; + +template +struct container_input_adapter_factory {}; + +template +struct container_input_adapter_factory< ContainerType, + void_t()), end(std::declval()))>> + { + using adapter_type = decltype(input_adapter(begin(std::declval()), end(std::declval()))); + + static adapter_type create(const ContainerType& container) +{ + return input_adapter(begin(container), end(container)); +} + }; + +} // namespace container_input_adapter_factory_impl + +template +typename container_input_adapter_factory_impl::container_input_adapter_factory::adapter_type input_adapter(const ContainerType& container) +{ + return container_input_adapter_factory_impl::container_input_adapter_factory::create(container); +} + +#ifndef JSON_NO_IO +// Special cases with fast paths +inline file_input_adapter input_adapter(std::FILE* file) +{ + return file_input_adapter(file); +} + +inline input_stream_adapter input_adapter(std::istream& stream) +{ + return input_stream_adapter(stream); +} + +inline input_stream_adapter input_adapter(std::istream&& stream) +{ + return input_stream_adapter(stream); +} +#endif // JSON_NO_IO + +using contiguous_bytes_input_adapter = decltype(input_adapter(std::declval(), std::declval())); + +// Null-delimited strings, and the like. +template < typename CharT, + typename std::enable_if < + std::is_pointer::value&& + !std::is_array::value&& + std::is_integral::type>::value&& + sizeof(typename std::remove_pointer::type) == 1, + int >::type = 0 > +contiguous_bytes_input_adapter input_adapter(CharT b) +{ + auto length = std::strlen(reinterpret_cast(b)); + const auto* ptr = reinterpret_cast(b); + return input_adapter(ptr, ptr + length); +} + +template +auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N)) // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) +{ + return input_adapter(array, array + N); +} + +// This class only handles inputs of input_buffer_adapter type. +// It's required so that expressions like {ptr, len} can be implicitely casted +// to the correct adapter. +class span_input_adapter +{ + public: + template < typename CharT, + typename std::enable_if < + std::is_pointer::value&& + std::is_integral::type>::value&& + sizeof(typename std::remove_pointer::type) == 1, + int >::type = 0 > + span_input_adapter(CharT b, std::size_t l) + : ia(reinterpret_cast(b), reinterpret_cast(b) + l) {} + + template::iterator_category, std::random_access_iterator_tag>::value, + int>::type = 0> + span_input_adapter(IteratorType first, IteratorType last) + : ia(input_adapter(first, last)) {} + + contiguous_bytes_input_adapter&& get() + { + return std::move(ia); // NOLINT(hicpp-move-const-arg,performance-move-const-arg) + } + + private: + contiguous_bytes_input_adapter ia; +}; +} // namespace detail +} // namespace nlohmann + +// #include + + +#include +#include // string +#include // move +#include // vector + +// #include + +// #include + + +namespace nlohmann +{ + +/*! +@brief SAX interface + +This class describes the SAX interface used by @ref nlohmann::json::sax_parse. +Each function is called in different situations while the input is parsed. The +boolean return value informs the parser whether to continue processing the +input. +*/ +template +struct json_sax +{ + using number_integer_t = typename BasicJsonType::number_integer_t; + using number_unsigned_t = typename BasicJsonType::number_unsigned_t; + using number_float_t = typename BasicJsonType::number_float_t; + using string_t = typename BasicJsonType::string_t; + using binary_t = typename BasicJsonType::binary_t; + + /*! + @brief a null value was read + @return whether parsing should proceed + */ + virtual bool null() = 0; + + /*! + @brief a boolean value was read + @param[in] val boolean value + @return whether parsing should proceed + */ + virtual bool boolean(bool val) = 0; + + /*! + @brief an integer number was read + @param[in] val integer value + @return whether parsing should proceed + */ + virtual bool number_integer(number_integer_t val) = 0; + + /*! + @brief an unsigned integer number was read + @param[in] val unsigned integer value + @return whether parsing should proceed + */ + virtual bool number_unsigned(number_unsigned_t val) = 0; + + /*! + @brief an floating-point number was read + @param[in] val floating-point value + @param[in] s raw token value + @return whether parsing should proceed + */ + virtual bool number_float(number_float_t val, const string_t& s) = 0; + + /*! + @brief a string was read + @param[in] val string value + @return whether parsing should proceed + @note It is safe to move the passed string. + */ + virtual bool string(string_t& val) = 0; + + /*! + @brief a binary string was read + @param[in] val binary value + @return whether parsing should proceed + @note It is safe to move the passed binary. + */ + virtual bool binary(binary_t& val) = 0; + + /*! + @brief the beginning of an object was read + @param[in] elements number of object elements or -1 if unknown + @return whether parsing should proceed + @note binary formats may report the number of elements + */ + virtual bool start_object(std::size_t elements) = 0; + + /*! + @brief an object key was read + @param[in] val object key + @return whether parsing should proceed + @note It is safe to move the passed string. + */ + virtual bool key(string_t& val) = 0; + + /*! + @brief the end of an object was read + @return whether parsing should proceed + */ + virtual bool end_object() = 0; + + /*! + @brief the beginning of an array was read + @param[in] elements number of array elements or -1 if unknown + @return whether parsing should proceed + @note binary formats may report the number of elements + */ + virtual bool start_array(std::size_t elements) = 0; + + /*! + @brief the end of an array was read + @return whether parsing should proceed + */ + virtual bool end_array() = 0; + + /*! + @brief a parse error occurred + @param[in] position the position in the input where the error occurs + @param[in] last_token the last read token + @param[in] ex an exception object describing the error + @return whether parsing should proceed (must return false) + */ + virtual bool parse_error(std::size_t position, + const std::string& last_token, + const detail::exception& ex) = 0; + + json_sax() = default; + json_sax(const json_sax&) = default; + json_sax(json_sax&&) noexcept = default; + json_sax& operator=(const json_sax&) = default; + json_sax& operator=(json_sax&&) noexcept = default; + virtual ~json_sax() = default; +}; + + +namespace detail +{ +/*! +@brief SAX implementation to create a JSON value from SAX events + +This class implements the @ref json_sax interface and processes the SAX events +to create a JSON value which makes it basically a DOM parser. The structure or +hierarchy of the JSON value is managed by the stack `ref_stack` which contains +a pointer to the respective array or object for each recursion depth. + +After successful parsing, the value that is passed by reference to the +constructor contains the parsed value. + +@tparam BasicJsonType the JSON type +*/ +template +class json_sax_dom_parser +{ + public: + using number_integer_t = typename BasicJsonType::number_integer_t; + using number_unsigned_t = typename BasicJsonType::number_unsigned_t; + using number_float_t = typename BasicJsonType::number_float_t; + using string_t = typename BasicJsonType::string_t; + using binary_t = typename BasicJsonType::binary_t; + + /*! + @param[in,out] r reference to a JSON value that is manipulated while + parsing + @param[in] allow_exceptions_ whether parse errors yield exceptions + */ + explicit json_sax_dom_parser(BasicJsonType& r, const bool allow_exceptions_ = true) + : root(r), allow_exceptions(allow_exceptions_) + {} + + // make class move-only + json_sax_dom_parser(const json_sax_dom_parser&) = delete; + json_sax_dom_parser(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + json_sax_dom_parser& operator=(const json_sax_dom_parser&) = delete; + json_sax_dom_parser& operator=(json_sax_dom_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + ~json_sax_dom_parser() = default; + + bool null() + { + handle_value(nullptr); + return true; + } + + bool boolean(bool val) + { + handle_value(val); + return true; + } + + bool number_integer(number_integer_t val) + { + handle_value(val); + return true; + } + + bool number_unsigned(number_unsigned_t val) + { + handle_value(val); + return true; + } + + bool number_float(number_float_t val, const string_t& /*unused*/) + { + handle_value(val); + return true; + } + + bool string(string_t& val) + { + handle_value(val); + return true; + } + + bool binary(binary_t& val) + { + handle_value(std::move(val)); + return true; + } + + bool start_object(std::size_t len) + { + ref_stack.push_back(handle_value(BasicJsonType::value_t::object)); + + if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) + { + JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), *ref_stack.back())); + } + + return true; + } + + bool key(string_t& val) + { + // add null at given key and store the reference for later + object_element = &(ref_stack.back()->m_value.object->operator[](val)); + return true; + } + + bool end_object() + { + ref_stack.back()->set_parents(); + ref_stack.pop_back(); + return true; + } + + bool start_array(std::size_t len) + { + ref_stack.push_back(handle_value(BasicJsonType::value_t::array)); + + if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) + { + JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), *ref_stack.back())); + } + + return true; + } + + bool end_array() + { + ref_stack.back()->set_parents(); + ref_stack.pop_back(); + return true; + } + + template + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, + const Exception& ex) + { + errored = true; + static_cast(ex); + if (allow_exceptions) + { + JSON_THROW(ex); + } + return false; + } + + constexpr bool is_errored() const + { + return errored; + } + + private: + /*! + @invariant If the ref stack is empty, then the passed value will be the new + root. + @invariant If the ref stack contains a value, then it is an array or an + object to which we can add elements + */ + template + JSON_HEDLEY_RETURNS_NON_NULL + BasicJsonType* handle_value(Value&& v) + { + if (ref_stack.empty()) + { + root = BasicJsonType(std::forward(v)); + return &root; + } + + JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object()); + + if (ref_stack.back()->is_array()) + { + ref_stack.back()->m_value.array->emplace_back(std::forward(v)); + return &(ref_stack.back()->m_value.array->back()); + } + + JSON_ASSERT(ref_stack.back()->is_object()); + JSON_ASSERT(object_element); + *object_element = BasicJsonType(std::forward(v)); + return object_element; + } + + /// the parsed JSON value + BasicJsonType& root; + /// stack to model hierarchy of values + std::vector ref_stack {}; + /// helper to hold the reference for the next object element + BasicJsonType* object_element = nullptr; + /// whether a syntax error occurred + bool errored = false; + /// whether to throw exceptions in case of errors + const bool allow_exceptions = true; +}; + +template +class json_sax_dom_callback_parser +{ + public: + using number_integer_t = typename BasicJsonType::number_integer_t; + using number_unsigned_t = typename BasicJsonType::number_unsigned_t; + using number_float_t = typename BasicJsonType::number_float_t; + using string_t = typename BasicJsonType::string_t; + using binary_t = typename BasicJsonType::binary_t; + using parser_callback_t = typename BasicJsonType::parser_callback_t; + using parse_event_t = typename BasicJsonType::parse_event_t; + + json_sax_dom_callback_parser(BasicJsonType& r, + const parser_callback_t cb, + const bool allow_exceptions_ = true) + : root(r), callback(cb), allow_exceptions(allow_exceptions_) + { + keep_stack.push_back(true); + } + + // make class move-only + json_sax_dom_callback_parser(const json_sax_dom_callback_parser&) = delete; + json_sax_dom_callback_parser(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + json_sax_dom_callback_parser& operator=(const json_sax_dom_callback_parser&) = delete; + json_sax_dom_callback_parser& operator=(json_sax_dom_callback_parser&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + ~json_sax_dom_callback_parser() = default; + + bool null() + { + handle_value(nullptr); + return true; + } + + bool boolean(bool val) + { + handle_value(val); + return true; + } + + bool number_integer(number_integer_t val) + { + handle_value(val); + return true; + } + + bool number_unsigned(number_unsigned_t val) + { + handle_value(val); + return true; + } + + bool number_float(number_float_t val, const string_t& /*unused*/) + { + handle_value(val); + return true; + } + + bool string(string_t& val) + { + handle_value(val); + return true; + } + + bool binary(binary_t& val) + { + handle_value(std::move(val)); + return true; + } + + bool start_object(std::size_t len) + { + // check callback for object start + const bool keep = callback(static_cast(ref_stack.size()), parse_event_t::object_start, discarded); + keep_stack.push_back(keep); + + auto val = handle_value(BasicJsonType::value_t::object, true); + ref_stack.push_back(val.second); + + // check object limit + if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) + { + JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), *ref_stack.back())); + } + + return true; + } + + bool key(string_t& val) + { + BasicJsonType k = BasicJsonType(val); + + // check callback for key + const bool keep = callback(static_cast(ref_stack.size()), parse_event_t::key, k); + key_keep_stack.push_back(keep); + + // add discarded value at given key and store the reference for later + if (keep && ref_stack.back()) + { + object_element = &(ref_stack.back()->m_value.object->operator[](val) = discarded); + } + + return true; + } + + bool end_object() + { + if (ref_stack.back()) + { + if (!callback(static_cast(ref_stack.size()) - 1, parse_event_t::object_end, *ref_stack.back())) + { + // discard object + *ref_stack.back() = discarded; + } + else + { + ref_stack.back()->set_parents(); + } + } + + JSON_ASSERT(!ref_stack.empty()); + JSON_ASSERT(!keep_stack.empty()); + ref_stack.pop_back(); + keep_stack.pop_back(); + + if (!ref_stack.empty() && ref_stack.back() && ref_stack.back()->is_structured()) + { + // remove discarded value + for (auto it = ref_stack.back()->begin(); it != ref_stack.back()->end(); ++it) + { + if (it->is_discarded()) + { + ref_stack.back()->erase(it); + break; + } + } + } + + return true; + } + + bool start_array(std::size_t len) + { + const bool keep = callback(static_cast(ref_stack.size()), parse_event_t::array_start, discarded); + keep_stack.push_back(keep); + + auto val = handle_value(BasicJsonType::value_t::array, true); + ref_stack.push_back(val.second); + + // check array limit + if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) + { + JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), *ref_stack.back())); + } + + return true; + } + + bool end_array() + { + bool keep = true; + + if (ref_stack.back()) + { + keep = callback(static_cast(ref_stack.size()) - 1, parse_event_t::array_end, *ref_stack.back()); + if (keep) + { + ref_stack.back()->set_parents(); + } + else + { + // discard array + *ref_stack.back() = discarded; + } + } + + JSON_ASSERT(!ref_stack.empty()); + JSON_ASSERT(!keep_stack.empty()); + ref_stack.pop_back(); + keep_stack.pop_back(); + + // remove discarded value + if (!keep && !ref_stack.empty() && ref_stack.back()->is_array()) + { + ref_stack.back()->m_value.array->pop_back(); + } + + return true; + } + + template + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, + const Exception& ex) + { + errored = true; + static_cast(ex); + if (allow_exceptions) + { + JSON_THROW(ex); + } + return false; + } + + constexpr bool is_errored() const + { + return errored; + } + + private: + /*! + @param[in] v value to add to the JSON value we build during parsing + @param[in] skip_callback whether we should skip calling the callback + function; this is required after start_array() and + start_object() SAX events, because otherwise we would call the + callback function with an empty array or object, respectively. + + @invariant If the ref stack is empty, then the passed value will be the new + root. + @invariant If the ref stack contains a value, then it is an array or an + object to which we can add elements + + @return pair of boolean (whether value should be kept) and pointer (to the + passed value in the ref_stack hierarchy; nullptr if not kept) + */ + template + std::pair handle_value(Value&& v, const bool skip_callback = false) + { + JSON_ASSERT(!keep_stack.empty()); + + // do not handle this value if we know it would be added to a discarded + // container + if (!keep_stack.back()) + { + return {false, nullptr}; + } + + // create value + auto value = BasicJsonType(std::forward(v)); + + // check callback + const bool keep = skip_callback || callback(static_cast(ref_stack.size()), parse_event_t::value, value); + + // do not handle this value if we just learnt it shall be discarded + if (!keep) + { + return {false, nullptr}; + } + + if (ref_stack.empty()) + { + root = std::move(value); + return {true, &root}; + } + + // skip this value if we already decided to skip the parent + // (https://github.com/nlohmann/json/issues/971#issuecomment-413678360) + if (!ref_stack.back()) + { + return {false, nullptr}; + } + + // we now only expect arrays and objects + JSON_ASSERT(ref_stack.back()->is_array() || ref_stack.back()->is_object()); + + // array + if (ref_stack.back()->is_array()) + { + ref_stack.back()->m_value.array->emplace_back(std::move(value)); + return {true, &(ref_stack.back()->m_value.array->back())}; + } + + // object + JSON_ASSERT(ref_stack.back()->is_object()); + // check if we should store an element for the current key + JSON_ASSERT(!key_keep_stack.empty()); + const bool store_element = key_keep_stack.back(); + key_keep_stack.pop_back(); + + if (!store_element) + { + return {false, nullptr}; + } + + JSON_ASSERT(object_element); + *object_element = std::move(value); + return {true, object_element}; + } + + /// the parsed JSON value + BasicJsonType& root; + /// stack to model hierarchy of values + std::vector ref_stack {}; + /// stack to manage which values to keep + std::vector keep_stack {}; + /// stack to manage which object keys to keep + std::vector key_keep_stack {}; + /// helper to hold the reference for the next object element + BasicJsonType* object_element = nullptr; + /// whether a syntax error occurred + bool errored = false; + /// callback function + const parser_callback_t callback = nullptr; + /// whether to throw exceptions in case of errors + const bool allow_exceptions = true; + /// a discarded value for the callback + BasicJsonType discarded = BasicJsonType::value_t::discarded; +}; + +template +class json_sax_acceptor +{ + public: + using number_integer_t = typename BasicJsonType::number_integer_t; + using number_unsigned_t = typename BasicJsonType::number_unsigned_t; + using number_float_t = typename BasicJsonType::number_float_t; + using string_t = typename BasicJsonType::string_t; + using binary_t = typename BasicJsonType::binary_t; + + bool null() + { + return true; + } + + bool boolean(bool /*unused*/) + { + return true; + } + + bool number_integer(number_integer_t /*unused*/) + { + return true; + } + + bool number_unsigned(number_unsigned_t /*unused*/) + { + return true; + } + + bool number_float(number_float_t /*unused*/, const string_t& /*unused*/) + { + return true; + } + + bool string(string_t& /*unused*/) + { + return true; + } + + bool binary(binary_t& /*unused*/) + { + return true; + } + + bool start_object(std::size_t /*unused*/ = std::size_t(-1)) + { + return true; + } + + bool key(string_t& /*unused*/) + { + return true; + } + + bool end_object() + { + return true; + } + + bool start_array(std::size_t /*unused*/ = std::size_t(-1)) + { + return true; + } + + bool end_array() + { + return true; + } + + bool parse_error(std::size_t /*unused*/, const std::string& /*unused*/, const detail::exception& /*unused*/) + { + return false; + } +}; +} // namespace detail + +} // namespace nlohmann + +// #include + + +#include // array +#include // localeconv +#include // size_t +#include // snprintf +#include // strtof, strtod, strtold, strtoll, strtoull +#include // initializer_list +#include // char_traits, string +#include // move +#include // vector + +// #include + +// #include + +// #include + + +namespace nlohmann +{ +namespace detail +{ +/////////// +// lexer // +/////////// + +template +class lexer_base +{ + public: + /// token types for the parser + enum class token_type + { + uninitialized, ///< indicating the scanner is uninitialized + literal_true, ///< the `true` literal + literal_false, ///< the `false` literal + literal_null, ///< the `null` literal + value_string, ///< a string -- use get_string() for actual value + value_unsigned, ///< an unsigned integer -- use get_number_unsigned() for actual value + value_integer, ///< a signed integer -- use get_number_integer() for actual value + value_float, ///< an floating point number -- use get_number_float() for actual value + begin_array, ///< the character for array begin `[` + begin_object, ///< the character for object begin `{` + end_array, ///< the character for array end `]` + end_object, ///< the character for object end `}` + name_separator, ///< the name separator `:` + value_separator, ///< the value separator `,` + parse_error, ///< indicating a parse error + end_of_input, ///< indicating the end of the input buffer + literal_or_value ///< a literal or the begin of a value (only for diagnostics) + }; + + /// return name of values of type token_type (only used for errors) + JSON_HEDLEY_RETURNS_NON_NULL + JSON_HEDLEY_CONST + static const char* token_type_name(const token_type t) noexcept + { + switch (t) + { + case token_type::uninitialized: + return ""; + case token_type::literal_true: + return "true literal"; + case token_type::literal_false: + return "false literal"; + case token_type::literal_null: + return "null literal"; + case token_type::value_string: + return "string literal"; + case token_type::value_unsigned: + case token_type::value_integer: + case token_type::value_float: + return "number literal"; + case token_type::begin_array: + return "'['"; + case token_type::begin_object: + return "'{'"; + case token_type::end_array: + return "']'"; + case token_type::end_object: + return "'}'"; + case token_type::name_separator: + return "':'"; + case token_type::value_separator: + return "','"; + case token_type::parse_error: + return ""; + case token_type::end_of_input: + return "end of input"; + case token_type::literal_or_value: + return "'[', '{', or a literal"; + // LCOV_EXCL_START + default: // catch non-enum values + return "unknown token"; + // LCOV_EXCL_STOP + } + } +}; +/*! +@brief lexical analysis + +This class organizes the lexical analysis during JSON deserialization. +*/ +template +class lexer : public lexer_base +{ + using number_integer_t = typename BasicJsonType::number_integer_t; + using number_unsigned_t = typename BasicJsonType::number_unsigned_t; + using number_float_t = typename BasicJsonType::number_float_t; + using string_t = typename BasicJsonType::string_t; + using char_type = typename InputAdapterType::char_type; + using char_int_type = typename std::char_traits::int_type; + + public: + using token_type = typename lexer_base::token_type; + + explicit lexer(InputAdapterType&& adapter, bool ignore_comments_ = false) noexcept + : ia(std::move(adapter)) + , ignore_comments(ignore_comments_) + , decimal_point_char(static_cast(get_decimal_point())) + {} + + // delete because of pointer members + lexer(const lexer&) = delete; + lexer(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + lexer& operator=(lexer&) = delete; + lexer& operator=(lexer&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + ~lexer() = default; + + private: + ///////////////////// + // locales + ///////////////////// + + /// return the locale-dependent decimal point + JSON_HEDLEY_PURE + static char get_decimal_point() noexcept + { + const auto* loc = localeconv(); + JSON_ASSERT(loc != nullptr); + return (loc->decimal_point == nullptr) ? '.' : *(loc->decimal_point); + } + + ///////////////////// + // scan functions + ///////////////////// + + /*! + @brief get codepoint from 4 hex characters following `\u` + + For input "\u c1 c2 c3 c4" the codepoint is: + (c1 * 0x1000) + (c2 * 0x0100) + (c3 * 0x0010) + c4 + = (c1 << 12) + (c2 << 8) + (c3 << 4) + (c4 << 0) + + Furthermore, the possible characters '0'..'9', 'A'..'F', and 'a'..'f' + must be converted to the integers 0x0..0x9, 0xA..0xF, 0xA..0xF, resp. The + conversion is done by subtracting the offset (0x30, 0x37, and 0x57) + between the ASCII value of the character and the desired integer value. + + @return codepoint (0x0000..0xFFFF) or -1 in case of an error (e.g. EOF or + non-hex character) + */ + int get_codepoint() + { + // this function only makes sense after reading `\u` + JSON_ASSERT(current == 'u'); + int codepoint = 0; + + const auto factors = { 12u, 8u, 4u, 0u }; + for (const auto factor : factors) + { + get(); + + if (current >= '0' && current <= '9') + { + codepoint += static_cast((static_cast(current) - 0x30u) << factor); + } + else if (current >= 'A' && current <= 'F') + { + codepoint += static_cast((static_cast(current) - 0x37u) << factor); + } + else if (current >= 'a' && current <= 'f') + { + codepoint += static_cast((static_cast(current) - 0x57u) << factor); + } + else + { + return -1; + } + } + + JSON_ASSERT(0x0000 <= codepoint && codepoint <= 0xFFFF); + return codepoint; + } + + /*! + @brief check if the next byte(s) are inside a given range + + Adds the current byte and, for each passed range, reads a new byte and + checks if it is inside the range. If a violation was detected, set up an + error message and return false. Otherwise, return true. + + @param[in] ranges list of integers; interpreted as list of pairs of + inclusive lower and upper bound, respectively + + @pre The passed list @a ranges must have 2, 4, or 6 elements; that is, + 1, 2, or 3 pairs. This precondition is enforced by an assertion. + + @return true if and only if no range violation was detected + */ + bool next_byte_in_range(std::initializer_list ranges) + { + JSON_ASSERT(ranges.size() == 2 || ranges.size() == 4 || ranges.size() == 6); + add(current); + + for (auto range = ranges.begin(); range != ranges.end(); ++range) + { + get(); + if (JSON_HEDLEY_LIKELY(*range <= current && current <= *(++range))) + { + add(current); + } + else + { + error_message = "invalid string: ill-formed UTF-8 byte"; + return false; + } + } + + return true; + } + + /*! + @brief scan a string literal + + This function scans a string according to Sect. 7 of RFC 8259. While + scanning, bytes are escaped and copied into buffer token_buffer. Then the + function returns successfully, token_buffer is *not* null-terminated (as it + may contain \0 bytes), and token_buffer.size() is the number of bytes in the + string. + + @return token_type::value_string if string could be successfully scanned, + token_type::parse_error otherwise + + @note In case of errors, variable error_message contains a textual + description. + */ + token_type scan_string() + { + // reset token_buffer (ignore opening quote) + reset(); + + // we entered the function by reading an open quote + JSON_ASSERT(current == '\"'); + + while (true) + { + // get next character + switch (get()) + { + // end of file while parsing string + case std::char_traits::eof(): + { + error_message = "invalid string: missing closing quote"; + return token_type::parse_error; + } + + // closing quote + case '\"': + { + return token_type::value_string; + } + + // escapes + case '\\': + { + switch (get()) + { + // quotation mark + case '\"': + add('\"'); + break; + // reverse solidus + case '\\': + add('\\'); + break; + // solidus + case '/': + add('/'); + break; + // backspace + case 'b': + add('\b'); + break; + // form feed + case 'f': + add('\f'); + break; + // line feed + case 'n': + add('\n'); + break; + // carriage return + case 'r': + add('\r'); + break; + // tab + case 't': + add('\t'); + break; + + // unicode escapes + case 'u': + { + const int codepoint1 = get_codepoint(); + int codepoint = codepoint1; // start with codepoint1 + + if (JSON_HEDLEY_UNLIKELY(codepoint1 == -1)) + { + error_message = "invalid string: '\\u' must be followed by 4 hex digits"; + return token_type::parse_error; + } + + // check if code point is a high surrogate + if (0xD800 <= codepoint1 && codepoint1 <= 0xDBFF) + { + // expect next \uxxxx entry + if (JSON_HEDLEY_LIKELY(get() == '\\' && get() == 'u')) + { + const int codepoint2 = get_codepoint(); + + if (JSON_HEDLEY_UNLIKELY(codepoint2 == -1)) + { + error_message = "invalid string: '\\u' must be followed by 4 hex digits"; + return token_type::parse_error; + } + + // check if codepoint2 is a low surrogate + if (JSON_HEDLEY_LIKELY(0xDC00 <= codepoint2 && codepoint2 <= 0xDFFF)) + { + // overwrite codepoint + codepoint = static_cast( + // high surrogate occupies the most significant 22 bits + (static_cast(codepoint1) << 10u) + // low surrogate occupies the least significant 15 bits + + static_cast(codepoint2) + // there is still the 0xD800, 0xDC00 and 0x10000 noise + // in the result so we have to subtract with: + // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00 + - 0x35FDC00u); + } + else + { + error_message = "invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF"; + return token_type::parse_error; + } + } + else + { + error_message = "invalid string: surrogate U+D800..U+DBFF must be followed by U+DC00..U+DFFF"; + return token_type::parse_error; + } + } + else + { + if (JSON_HEDLEY_UNLIKELY(0xDC00 <= codepoint1 && codepoint1 <= 0xDFFF)) + { + error_message = "invalid string: surrogate U+DC00..U+DFFF must follow U+D800..U+DBFF"; + return token_type::parse_error; + } + } + + // result of the above calculation yields a proper codepoint + JSON_ASSERT(0x00 <= codepoint && codepoint <= 0x10FFFF); + + // translate codepoint into bytes + if (codepoint < 0x80) + { + // 1-byte characters: 0xxxxxxx (ASCII) + add(static_cast(codepoint)); + } + else if (codepoint <= 0x7FF) + { + // 2-byte characters: 110xxxxx 10xxxxxx + add(static_cast(0xC0u | (static_cast(codepoint) >> 6u))); + add(static_cast(0x80u | (static_cast(codepoint) & 0x3Fu))); + } + else if (codepoint <= 0xFFFF) + { + // 3-byte characters: 1110xxxx 10xxxxxx 10xxxxxx + add(static_cast(0xE0u | (static_cast(codepoint) >> 12u))); + add(static_cast(0x80u | ((static_cast(codepoint) >> 6u) & 0x3Fu))); + add(static_cast(0x80u | (static_cast(codepoint) & 0x3Fu))); + } + else + { + // 4-byte characters: 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx + add(static_cast(0xF0u | (static_cast(codepoint) >> 18u))); + add(static_cast(0x80u | ((static_cast(codepoint) >> 12u) & 0x3Fu))); + add(static_cast(0x80u | ((static_cast(codepoint) >> 6u) & 0x3Fu))); + add(static_cast(0x80u | (static_cast(codepoint) & 0x3Fu))); + } + + break; + } + + // other characters after escape + default: + error_message = "invalid string: forbidden character after backslash"; + return token_type::parse_error; + } + + break; + } + + // invalid control characters + case 0x00: + { + error_message = "invalid string: control character U+0000 (NUL) must be escaped to \\u0000"; + return token_type::parse_error; + } + + case 0x01: + { + error_message = "invalid string: control character U+0001 (SOH) must be escaped to \\u0001"; + return token_type::parse_error; + } + + case 0x02: + { + error_message = "invalid string: control character U+0002 (STX) must be escaped to \\u0002"; + return token_type::parse_error; + } + + case 0x03: + { + error_message = "invalid string: control character U+0003 (ETX) must be escaped to \\u0003"; + return token_type::parse_error; + } + + case 0x04: + { + error_message = "invalid string: control character U+0004 (EOT) must be escaped to \\u0004"; + return token_type::parse_error; + } + + case 0x05: + { + error_message = "invalid string: control character U+0005 (ENQ) must be escaped to \\u0005"; + return token_type::parse_error; + } + + case 0x06: + { + error_message = "invalid string: control character U+0006 (ACK) must be escaped to \\u0006"; + return token_type::parse_error; + } + + case 0x07: + { + error_message = "invalid string: control character U+0007 (BEL) must be escaped to \\u0007"; + return token_type::parse_error; + } + + case 0x08: + { + error_message = "invalid string: control character U+0008 (BS) must be escaped to \\u0008 or \\b"; + return token_type::parse_error; + } + + case 0x09: + { + error_message = "invalid string: control character U+0009 (HT) must be escaped to \\u0009 or \\t"; + return token_type::parse_error; + } + + case 0x0A: + { + error_message = "invalid string: control character U+000A (LF) must be escaped to \\u000A or \\n"; + return token_type::parse_error; + } + + case 0x0B: + { + error_message = "invalid string: control character U+000B (VT) must be escaped to \\u000B"; + return token_type::parse_error; + } + + case 0x0C: + { + error_message = "invalid string: control character U+000C (FF) must be escaped to \\u000C or \\f"; + return token_type::parse_error; + } + + case 0x0D: + { + error_message = "invalid string: control character U+000D (CR) must be escaped to \\u000D or \\r"; + return token_type::parse_error; + } + + case 0x0E: + { + error_message = "invalid string: control character U+000E (SO) must be escaped to \\u000E"; + return token_type::parse_error; + } + + case 0x0F: + { + error_message = "invalid string: control character U+000F (SI) must be escaped to \\u000F"; + return token_type::parse_error; + } + + case 0x10: + { + error_message = "invalid string: control character U+0010 (DLE) must be escaped to \\u0010"; + return token_type::parse_error; + } + + case 0x11: + { + error_message = "invalid string: control character U+0011 (DC1) must be escaped to \\u0011"; + return token_type::parse_error; + } + + case 0x12: + { + error_message = "invalid string: control character U+0012 (DC2) must be escaped to \\u0012"; + return token_type::parse_error; + } + + case 0x13: + { + error_message = "invalid string: control character U+0013 (DC3) must be escaped to \\u0013"; + return token_type::parse_error; + } + + case 0x14: + { + error_message = "invalid string: control character U+0014 (DC4) must be escaped to \\u0014"; + return token_type::parse_error; + } + + case 0x15: + { + error_message = "invalid string: control character U+0015 (NAK) must be escaped to \\u0015"; + return token_type::parse_error; + } + + case 0x16: + { + error_message = "invalid string: control character U+0016 (SYN) must be escaped to \\u0016"; + return token_type::parse_error; + } + + case 0x17: + { + error_message = "invalid string: control character U+0017 (ETB) must be escaped to \\u0017"; + return token_type::parse_error; + } + + case 0x18: + { + error_message = "invalid string: control character U+0018 (CAN) must be escaped to \\u0018"; + return token_type::parse_error; + } + + case 0x19: + { + error_message = "invalid string: control character U+0019 (EM) must be escaped to \\u0019"; + return token_type::parse_error; + } + + case 0x1A: + { + error_message = "invalid string: control character U+001A (SUB) must be escaped to \\u001A"; + return token_type::parse_error; + } + + case 0x1B: + { + error_message = "invalid string: control character U+001B (ESC) must be escaped to \\u001B"; + return token_type::parse_error; + } + + case 0x1C: + { + error_message = "invalid string: control character U+001C (FS) must be escaped to \\u001C"; + return token_type::parse_error; + } + + case 0x1D: + { + error_message = "invalid string: control character U+001D (GS) must be escaped to \\u001D"; + return token_type::parse_error; + } + + case 0x1E: + { + error_message = "invalid string: control character U+001E (RS) must be escaped to \\u001E"; + return token_type::parse_error; + } + + case 0x1F: + { + error_message = "invalid string: control character U+001F (US) must be escaped to \\u001F"; + return token_type::parse_error; + } + + // U+0020..U+007F (except U+0022 (quote) and U+005C (backspace)) + case 0x20: + case 0x21: + case 0x23: + case 0x24: + case 0x25: + case 0x26: + case 0x27: + case 0x28: + case 0x29: + case 0x2A: + case 0x2B: + case 0x2C: + case 0x2D: + case 0x2E: + case 0x2F: + case 0x30: + case 0x31: + case 0x32: + case 0x33: + case 0x34: + case 0x35: + case 0x36: + case 0x37: + case 0x38: + case 0x39: + case 0x3A: + case 0x3B: + case 0x3C: + case 0x3D: + case 0x3E: + case 0x3F: + case 0x40: + case 0x41: + case 0x42: + case 0x43: + case 0x44: + case 0x45: + case 0x46: + case 0x47: + case 0x48: + case 0x49: + case 0x4A: + case 0x4B: + case 0x4C: + case 0x4D: + case 0x4E: + case 0x4F: + case 0x50: + case 0x51: + case 0x52: + case 0x53: + case 0x54: + case 0x55: + case 0x56: + case 0x57: + case 0x58: + case 0x59: + case 0x5A: + case 0x5B: + case 0x5D: + case 0x5E: + case 0x5F: + case 0x60: + case 0x61: + case 0x62: + case 0x63: + case 0x64: + case 0x65: + case 0x66: + case 0x67: + case 0x68: + case 0x69: + case 0x6A: + case 0x6B: + case 0x6C: + case 0x6D: + case 0x6E: + case 0x6F: + case 0x70: + case 0x71: + case 0x72: + case 0x73: + case 0x74: + case 0x75: + case 0x76: + case 0x77: + case 0x78: + case 0x79: + case 0x7A: + case 0x7B: + case 0x7C: + case 0x7D: + case 0x7E: + case 0x7F: + { + add(current); + break; + } + + // U+0080..U+07FF: bytes C2..DF 80..BF + case 0xC2: + case 0xC3: + case 0xC4: + case 0xC5: + case 0xC6: + case 0xC7: + case 0xC8: + case 0xC9: + case 0xCA: + case 0xCB: + case 0xCC: + case 0xCD: + case 0xCE: + case 0xCF: + case 0xD0: + case 0xD1: + case 0xD2: + case 0xD3: + case 0xD4: + case 0xD5: + case 0xD6: + case 0xD7: + case 0xD8: + case 0xD9: + case 0xDA: + case 0xDB: + case 0xDC: + case 0xDD: + case 0xDE: + case 0xDF: + { + if (JSON_HEDLEY_UNLIKELY(!next_byte_in_range({0x80, 0xBF}))) + { + return token_type::parse_error; + } + break; + } + + // U+0800..U+0FFF: bytes E0 A0..BF 80..BF + case 0xE0: + { + if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0xA0, 0xBF, 0x80, 0xBF})))) + { + return token_type::parse_error; + } + break; + } + + // U+1000..U+CFFF: bytes E1..EC 80..BF 80..BF + // U+E000..U+FFFF: bytes EE..EF 80..BF 80..BF + case 0xE1: + case 0xE2: + case 0xE3: + case 0xE4: + case 0xE5: + case 0xE6: + case 0xE7: + case 0xE8: + case 0xE9: + case 0xEA: + case 0xEB: + case 0xEC: + case 0xEE: + case 0xEF: + { + if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF})))) + { + return token_type::parse_error; + } + break; + } + + // U+D000..U+D7FF: bytes ED 80..9F 80..BF + case 0xED: + { + if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x9F, 0x80, 0xBF})))) + { + return token_type::parse_error; + } + break; + } + + // U+10000..U+3FFFF F0 90..BF 80..BF 80..BF + case 0xF0: + { + if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x90, 0xBF, 0x80, 0xBF, 0x80, 0xBF})))) + { + return token_type::parse_error; + } + break; + } + + // U+40000..U+FFFFF F1..F3 80..BF 80..BF 80..BF + case 0xF1: + case 0xF2: + case 0xF3: + { + if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0xBF, 0x80, 0xBF, 0x80, 0xBF})))) + { + return token_type::parse_error; + } + break; + } + + // U+100000..U+10FFFF F4 80..8F 80..BF 80..BF + case 0xF4: + { + if (JSON_HEDLEY_UNLIKELY(!(next_byte_in_range({0x80, 0x8F, 0x80, 0xBF, 0x80, 0xBF})))) + { + return token_type::parse_error; + } + break; + } + + // remaining bytes (80..C1 and F5..FF) are ill-formed + default: + { + error_message = "invalid string: ill-formed UTF-8 byte"; + return token_type::parse_error; + } + } + } + } + + /*! + * @brief scan a comment + * @return whether comment could be scanned successfully + */ + bool scan_comment() + { + switch (get()) + { + // single-line comments skip input until a newline or EOF is read + case '/': + { + while (true) + { + switch (get()) + { + case '\n': + case '\r': + case std::char_traits::eof(): + case '\0': + return true; + + default: + break; + } + } + } + + // multi-line comments skip input until */ is read + case '*': + { + while (true) + { + switch (get()) + { + case std::char_traits::eof(): + case '\0': + { + error_message = "invalid comment; missing closing '*/'"; + return false; + } + + case '*': + { + switch (get()) + { + case '/': + return true; + + default: + { + unget(); + continue; + } + } + } + + default: + continue; + } + } + } + + // unexpected character after reading '/' + default: + { + error_message = "invalid comment; expecting '/' or '*' after '/'"; + return false; + } + } + } + + JSON_HEDLEY_NON_NULL(2) + static void strtof(float& f, const char* str, char** endptr) noexcept + { + f = std::strtof(str, endptr); + } + + JSON_HEDLEY_NON_NULL(2) + static void strtof(double& f, const char* str, char** endptr) noexcept + { + f = std::strtod(str, endptr); + } + + JSON_HEDLEY_NON_NULL(2) + static void strtof(long double& f, const char* str, char** endptr) noexcept + { + f = std::strtold(str, endptr); + } + + /*! + @brief scan a number literal + + This function scans a string according to Sect. 6 of RFC 8259. + + The function is realized with a deterministic finite state machine derived + from the grammar described in RFC 8259. Starting in state "init", the + input is read and used to determined the next state. Only state "done" + accepts the number. State "error" is a trap state to model errors. In the + table below, "anything" means any character but the ones listed before. + + state | 0 | 1-9 | e E | + | - | . | anything + ---------|----------|----------|----------|---------|---------|----------|----------- + init | zero | any1 | [error] | [error] | minus | [error] | [error] + minus | zero | any1 | [error] | [error] | [error] | [error] | [error] + zero | done | done | exponent | done | done | decimal1 | done + any1 | any1 | any1 | exponent | done | done | decimal1 | done + decimal1 | decimal2 | decimal2 | [error] | [error] | [error] | [error] | [error] + decimal2 | decimal2 | decimal2 | exponent | done | done | done | done + exponent | any2 | any2 | [error] | sign | sign | [error] | [error] + sign | any2 | any2 | [error] | [error] | [error] | [error] | [error] + any2 | any2 | any2 | done | done | done | done | done + + The state machine is realized with one label per state (prefixed with + "scan_number_") and `goto` statements between them. The state machine + contains cycles, but any cycle can be left when EOF is read. Therefore, + the function is guaranteed to terminate. + + During scanning, the read bytes are stored in token_buffer. This string is + then converted to a signed integer, an unsigned integer, or a + floating-point number. + + @return token_type::value_unsigned, token_type::value_integer, or + token_type::value_float if number could be successfully scanned, + token_type::parse_error otherwise + + @note The scanner is independent of the current locale. Internally, the + locale's decimal point is used instead of `.` to work with the + locale-dependent converters. + */ + token_type scan_number() // lgtm [cpp/use-of-goto] + { + // reset token_buffer to store the number's bytes + reset(); + + // the type of the parsed number; initially set to unsigned; will be + // changed if minus sign, decimal point or exponent is read + token_type number_type = token_type::value_unsigned; + + // state (init): we just found out we need to scan a number + switch (current) + { + case '-': + { + add(current); + goto scan_number_minus; + } + + case '0': + { + add(current); + goto scan_number_zero; + } + + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + add(current); + goto scan_number_any1; + } + + // all other characters are rejected outside scan_number() + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + } + +scan_number_minus: + // state: we just parsed a leading minus sign + number_type = token_type::value_integer; + switch (get()) + { + case '0': + { + add(current); + goto scan_number_zero; + } + + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + add(current); + goto scan_number_any1; + } + + default: + { + error_message = "invalid number; expected digit after '-'"; + return token_type::parse_error; + } + } + +scan_number_zero: + // state: we just parse a zero (maybe with a leading minus sign) + switch (get()) + { + case '.': + { + add(decimal_point_char); + goto scan_number_decimal1; + } + + case 'e': + case 'E': + { + add(current); + goto scan_number_exponent; + } + + default: + goto scan_number_done; + } + +scan_number_any1: + // state: we just parsed a number 0-9 (maybe with a leading minus sign) + switch (get()) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + add(current); + goto scan_number_any1; + } + + case '.': + { + add(decimal_point_char); + goto scan_number_decimal1; + } + + case 'e': + case 'E': + { + add(current); + goto scan_number_exponent; + } + + default: + goto scan_number_done; + } + +scan_number_decimal1: + // state: we just parsed a decimal point + number_type = token_type::value_float; + switch (get()) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + add(current); + goto scan_number_decimal2; + } + + default: + { + error_message = "invalid number; expected digit after '.'"; + return token_type::parse_error; + } + } + +scan_number_decimal2: + // we just parsed at least one number after a decimal point + switch (get()) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + add(current); + goto scan_number_decimal2; + } + + case 'e': + case 'E': + { + add(current); + goto scan_number_exponent; + } + + default: + goto scan_number_done; + } + +scan_number_exponent: + // we just parsed an exponent + number_type = token_type::value_float; + switch (get()) + { + case '+': + case '-': + { + add(current); + goto scan_number_sign; + } + + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + add(current); + goto scan_number_any2; + } + + default: + { + error_message = + "invalid number; expected '+', '-', or digit after exponent"; + return token_type::parse_error; + } + } + +scan_number_sign: + // we just parsed an exponent sign + switch (get()) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + add(current); + goto scan_number_any2; + } + + default: + { + error_message = "invalid number; expected digit after exponent sign"; + return token_type::parse_error; + } + } + +scan_number_any2: + // we just parsed a number after the exponent or exponent sign + switch (get()) + { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + { + add(current); + goto scan_number_any2; + } + + default: + goto scan_number_done; + } + +scan_number_done: + // unget the character after the number (we only read it to know that + // we are done scanning a number) + unget(); + + char* endptr = nullptr; // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + errno = 0; + + // try to parse integers first and fall back to floats + if (number_type == token_type::value_unsigned) + { + const auto x = std::strtoull(token_buffer.data(), &endptr, 10); + + // we checked the number format before + JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size()); + + if (errno == 0) + { + value_unsigned = static_cast(x); + if (value_unsigned == x) + { + return token_type::value_unsigned; + } + } + } + else if (number_type == token_type::value_integer) + { + const auto x = std::strtoll(token_buffer.data(), &endptr, 10); + + // we checked the number format before + JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size()); + + if (errno == 0) + { + value_integer = static_cast(x); + if (value_integer == x) + { + return token_type::value_integer; + } + } + } + + // this code is reached if we parse a floating-point number or if an + // integer conversion above failed + strtof(value_float, token_buffer.data(), &endptr); + + // we checked the number format before + JSON_ASSERT(endptr == token_buffer.data() + token_buffer.size()); + + return token_type::value_float; + } + + /*! + @param[in] literal_text the literal text to expect + @param[in] length the length of the passed literal text + @param[in] return_type the token type to return on success + */ + JSON_HEDLEY_NON_NULL(2) + token_type scan_literal(const char_type* literal_text, const std::size_t length, + token_type return_type) + { + JSON_ASSERT(std::char_traits::to_char_type(current) == literal_text[0]); + for (std::size_t i = 1; i < length; ++i) + { + if (JSON_HEDLEY_UNLIKELY(std::char_traits::to_char_type(get()) != literal_text[i])) + { + error_message = "invalid literal"; + return token_type::parse_error; + } + } + return return_type; + } + + ///////////////////// + // input management + ///////////////////// + + /// reset token_buffer; current character is beginning of token + void reset() noexcept + { + token_buffer.clear(); + token_string.clear(); + token_string.push_back(std::char_traits::to_char_type(current)); + } + + /* + @brief get next character from the input + + This function provides the interface to the used input adapter. It does + not throw in case the input reached EOF, but returns a + `std::char_traits::eof()` in that case. Stores the scanned characters + for use in error messages. + + @return character read from the input + */ + char_int_type get() + { + ++position.chars_read_total; + ++position.chars_read_current_line; + + if (next_unget) + { + // just reset the next_unget variable and work with current + next_unget = false; + } + else + { + current = ia.get_character(); + } + + if (JSON_HEDLEY_LIKELY(current != std::char_traits::eof())) + { + token_string.push_back(std::char_traits::to_char_type(current)); + } + + if (current == '\n') + { + ++position.lines_read; + position.chars_read_current_line = 0; + } + + return current; + } + + /*! + @brief unget current character (read it again on next get) + + We implement unget by setting variable next_unget to true. The input is not + changed - we just simulate ungetting by modifying chars_read_total, + chars_read_current_line, and token_string. The next call to get() will + behave as if the unget character is read again. + */ + void unget() + { + next_unget = true; + + --position.chars_read_total; + + // in case we "unget" a newline, we have to also decrement the lines_read + if (position.chars_read_current_line == 0) + { + if (position.lines_read > 0) + { + --position.lines_read; + } + } + else + { + --position.chars_read_current_line; + } + + if (JSON_HEDLEY_LIKELY(current != std::char_traits::eof())) + { + JSON_ASSERT(!token_string.empty()); + token_string.pop_back(); + } + } + + /// add a character to token_buffer + void add(char_int_type c) + { + token_buffer.push_back(static_cast(c)); + } + + public: + ///////////////////// + // value getters + ///////////////////// + + /// return integer value + constexpr number_integer_t get_number_integer() const noexcept + { + return value_integer; + } + + /// return unsigned integer value + constexpr number_unsigned_t get_number_unsigned() const noexcept + { + return value_unsigned; + } + + /// return floating-point value + constexpr number_float_t get_number_float() const noexcept + { + return value_float; + } + + /// return current string value (implicitly resets the token; useful only once) + string_t& get_string() + { + return token_buffer; + } + + ///////////////////// + // diagnostics + ///////////////////// + + /// return position of last read token + constexpr position_t get_position() const noexcept + { + return position; + } + + /// return the last read token (for errors only). Will never contain EOF + /// (an arbitrary value that is not a valid char value, often -1), because + /// 255 may legitimately occur. May contain NUL, which should be escaped. + std::string get_token_string() const + { + // escape control characters + std::string result; + for (const auto c : token_string) + { + if (static_cast(c) <= '\x1F') + { + // escape control characters + std::array cs{{}}; + (std::snprintf)(cs.data(), cs.size(), "", static_cast(c)); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + result += cs.data(); + } + else + { + // add character as is + result.push_back(static_cast(c)); + } + } + + return result; + } + + /// return syntax error message + JSON_HEDLEY_RETURNS_NON_NULL + constexpr const char* get_error_message() const noexcept + { + return error_message; + } + + ///////////////////// + // actual scanner + ///////////////////// + + /*! + @brief skip the UTF-8 byte order mark + @return true iff there is no BOM or the correct BOM has been skipped + */ + bool skip_bom() + { + if (get() == 0xEF) + { + // check if we completely parse the BOM + return get() == 0xBB && get() == 0xBF; + } + + // the first character is not the beginning of the BOM; unget it to + // process is later + unget(); + return true; + } + + void skip_whitespace() + { + do + { + get(); + } + while (current == ' ' || current == '\t' || current == '\n' || current == '\r'); + } + + token_type scan() + { + // initially, skip the BOM + if (position.chars_read_total == 0 && !skip_bom()) + { + error_message = "invalid BOM; must be 0xEF 0xBB 0xBF if given"; + return token_type::parse_error; + } + + // read next character and ignore whitespace + skip_whitespace(); + + // ignore comments + while (ignore_comments && current == '/') + { + if (!scan_comment()) + { + return token_type::parse_error; + } + + // skip following whitespace + skip_whitespace(); + } + + switch (current) + { + // structural characters + case '[': + return token_type::begin_array; + case ']': + return token_type::end_array; + case '{': + return token_type::begin_object; + case '}': + return token_type::end_object; + case ':': + return token_type::name_separator; + case ',': + return token_type::value_separator; + + // literals + case 't': + { + std::array true_literal = {{char_type('t'), char_type('r'), char_type('u'), char_type('e')}}; + return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true); + } + case 'f': + { + std::array false_literal = {{char_type('f'), char_type('a'), char_type('l'), char_type('s'), char_type('e')}}; + return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false); + } + case 'n': + { + std::array null_literal = {{char_type('n'), char_type('u'), char_type('l'), char_type('l')}}; + return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null); + } + + // string + case '\"': + return scan_string(); + + // number + case '-': + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + return scan_number(); + + // end of input (the null byte is needed when parsing from + // string literals) + case '\0': + case std::char_traits::eof(): + return token_type::end_of_input; + + // error + default: + error_message = "invalid literal"; + return token_type::parse_error; + } + } + + private: + /// input adapter + InputAdapterType ia; + + /// whether comments should be ignored (true) or signaled as errors (false) + const bool ignore_comments = false; + + /// the current character + char_int_type current = std::char_traits::eof(); + + /// whether the next get() call should just return current + bool next_unget = false; + + /// the start position of the current token + position_t position {}; + + /// raw input token string (for error messages) + std::vector token_string {}; + + /// buffer for variable-length tokens (numbers, strings) + string_t token_buffer {}; + + /// a description of occurred lexer errors + const char* error_message = ""; + + // number values + number_integer_t value_integer = 0; + number_unsigned_t value_unsigned = 0; + number_float_t value_float = 0; + + /// the decimal point + const char_int_type decimal_point_char = '.'; +}; +} // namespace detail +} // namespace nlohmann + +// #include + +// #include + + +#include // size_t +#include // declval +#include // string + +// #include + +// #include + + +namespace nlohmann +{ +namespace detail +{ +template +using null_function_t = decltype(std::declval().null()); + +template +using boolean_function_t = + decltype(std::declval().boolean(std::declval())); + +template +using number_integer_function_t = + decltype(std::declval().number_integer(std::declval())); + +template +using number_unsigned_function_t = + decltype(std::declval().number_unsigned(std::declval())); + +template +using number_float_function_t = decltype(std::declval().number_float( + std::declval(), std::declval())); + +template +using string_function_t = + decltype(std::declval().string(std::declval())); + +template +using binary_function_t = + decltype(std::declval().binary(std::declval())); + +template +using start_object_function_t = + decltype(std::declval().start_object(std::declval())); + +template +using key_function_t = + decltype(std::declval().key(std::declval())); + +template +using end_object_function_t = decltype(std::declval().end_object()); + +template +using start_array_function_t = + decltype(std::declval().start_array(std::declval())); + +template +using end_array_function_t = decltype(std::declval().end_array()); + +template +using parse_error_function_t = decltype(std::declval().parse_error( + std::declval(), std::declval(), + std::declval())); + +template +struct is_sax +{ + private: + static_assert(is_basic_json::value, + "BasicJsonType must be of type basic_json<...>"); + + using number_integer_t = typename BasicJsonType::number_integer_t; + using number_unsigned_t = typename BasicJsonType::number_unsigned_t; + using number_float_t = typename BasicJsonType::number_float_t; + using string_t = typename BasicJsonType::string_t; + using binary_t = typename BasicJsonType::binary_t; + using exception_t = typename BasicJsonType::exception; + + public: + static constexpr bool value = + is_detected_exact::value && + is_detected_exact::value && + is_detected_exact::value && + is_detected_exact::value && + is_detected_exact::value && + is_detected_exact::value && + is_detected_exact::value && + is_detected_exact::value && + is_detected_exact::value && + is_detected_exact::value && + is_detected_exact::value && + is_detected_exact::value && + is_detected_exact::value; +}; + +template +struct is_sax_static_asserts +{ + private: + static_assert(is_basic_json::value, + "BasicJsonType must be of type basic_json<...>"); + + using number_integer_t = typename BasicJsonType::number_integer_t; + using number_unsigned_t = typename BasicJsonType::number_unsigned_t; + using number_float_t = typename BasicJsonType::number_float_t; + using string_t = typename BasicJsonType::string_t; + using binary_t = typename BasicJsonType::binary_t; + using exception_t = typename BasicJsonType::exception; + + public: + static_assert(is_detected_exact::value, + "Missing/invalid function: bool null()"); + static_assert(is_detected_exact::value, + "Missing/invalid function: bool boolean(bool)"); + static_assert(is_detected_exact::value, + "Missing/invalid function: bool boolean(bool)"); + static_assert( + is_detected_exact::value, + "Missing/invalid function: bool number_integer(number_integer_t)"); + static_assert( + is_detected_exact::value, + "Missing/invalid function: bool number_unsigned(number_unsigned_t)"); + static_assert(is_detected_exact::value, + "Missing/invalid function: bool number_float(number_float_t, const string_t&)"); + static_assert( + is_detected_exact::value, + "Missing/invalid function: bool string(string_t&)"); + static_assert( + is_detected_exact::value, + "Missing/invalid function: bool binary(binary_t&)"); + static_assert(is_detected_exact::value, + "Missing/invalid function: bool start_object(std::size_t)"); + static_assert(is_detected_exact::value, + "Missing/invalid function: bool key(string_t&)"); + static_assert(is_detected_exact::value, + "Missing/invalid function: bool end_object()"); + static_assert(is_detected_exact::value, + "Missing/invalid function: bool start_array(std::size_t)"); + static_assert(is_detected_exact::value, + "Missing/invalid function: bool end_array()"); + static_assert( + is_detected_exact::value, + "Missing/invalid function: bool parse_error(std::size_t, const " + "std::string&, const exception&)"); +}; +} // namespace detail +} // namespace nlohmann + +// #include + +// #include + + +namespace nlohmann +{ +namespace detail +{ + +/// how to treat CBOR tags +enum class cbor_tag_handler_t +{ + error, ///< throw a parse_error exception in case of a tag + ignore, ///< ignore tags + store ///< store tags as binary type +}; + +/*! +@brief determine system byte order + +@return true if and only if system's byte order is little endian + +@note from https://stackoverflow.com/a/1001328/266378 +*/ +static inline bool little_endianess(int num = 1) noexcept +{ + return *reinterpret_cast(&num) == 1; +} + + +/////////////////// +// binary reader // +/////////////////// + +/*! +@brief deserialization of CBOR, MessagePack, and UBJSON values +*/ +template> +class binary_reader +{ + using number_integer_t = typename BasicJsonType::number_integer_t; + using number_unsigned_t = typename BasicJsonType::number_unsigned_t; + using number_float_t = typename BasicJsonType::number_float_t; + using string_t = typename BasicJsonType::string_t; + using binary_t = typename BasicJsonType::binary_t; + using json_sax_t = SAX; + using char_type = typename InputAdapterType::char_type; + using char_int_type = typename std::char_traits::int_type; + + public: + /*! + @brief create a binary reader + + @param[in] adapter input adapter to read from + */ + explicit binary_reader(InputAdapterType&& adapter) noexcept : ia(std::move(adapter)) + { + (void)detail::is_sax_static_asserts {}; + } + + // make class move-only + binary_reader(const binary_reader&) = delete; + binary_reader(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + binary_reader& operator=(const binary_reader&) = delete; + binary_reader& operator=(binary_reader&&) = default; // NOLINT(hicpp-noexcept-move,performance-noexcept-move-constructor) + ~binary_reader() = default; + + /*! + @param[in] format the binary format to parse + @param[in] sax_ a SAX event processor + @param[in] strict whether to expect the input to be consumed completed + @param[in] tag_handler how to treat CBOR tags + + @return whether parsing was successful + */ + JSON_HEDLEY_NON_NULL(3) + bool sax_parse(const input_format_t format, + json_sax_t* sax_, + const bool strict = true, + const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) + { + sax = sax_; + bool result = false; + + switch (format) + { + case input_format_t::bson: + result = parse_bson_internal(); + break; + + case input_format_t::cbor: + result = parse_cbor_internal(true, tag_handler); + break; + + case input_format_t::msgpack: + result = parse_msgpack_internal(); + break; + + case input_format_t::ubjson: + result = parse_ubjson_internal(); + break; + + case input_format_t::json: // LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + } + + // strict mode: next byte must be EOF + if (result && strict) + { + if (format == input_format_t::ubjson) + { + get_ignore_noop(); + } + else + { + get(); + } + + if (JSON_HEDLEY_UNLIKELY(current != std::char_traits::eof())) + { + return sax->parse_error(chars_read, get_token_string(), + parse_error::create(110, chars_read, exception_message(format, "expected end of input; last byte: 0x" + get_token_string(), "value"), BasicJsonType())); + } + } + + return result; + } + + private: + ////////// + // BSON // + ////////// + + /*! + @brief Reads in a BSON-object and passes it to the SAX-parser. + @return whether a valid BSON-value was passed to the SAX parser + */ + bool parse_bson_internal() + { + std::int32_t document_size{}; + get_number(input_format_t::bson, document_size); + + if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1)))) + { + return false; + } + + if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/false))) + { + return false; + } + + return sax->end_object(); + } + + /*! + @brief Parses a C-style string from the BSON input. + @param[in,out] result A reference to the string variable where the read + string is to be stored. + @return `true` if the \x00-byte indicating the end of the string was + encountered before the EOF; false` indicates an unexpected EOF. + */ + bool get_bson_cstr(string_t& result) + { + auto out = std::back_inserter(result); + while (true) + { + get(); + if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson, "cstring"))) + { + return false; + } + if (current == 0x00) + { + return true; + } + *out++ = static_cast(current); + } + } + + /*! + @brief Parses a zero-terminated string of length @a len from the BSON + input. + @param[in] len The length (including the zero-byte at the end) of the + string to be read. + @param[in,out] result A reference to the string variable where the read + string is to be stored. + @tparam NumberType The type of the length @a len + @pre len >= 1 + @return `true` if the string was successfully parsed + */ + template + bool get_bson_string(const NumberType len, string_t& result) + { + if (JSON_HEDLEY_UNLIKELY(len < 1)) + { + auto last_token = get_token_string(); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, "string length must be at least 1, is " + std::to_string(len), "string"), BasicJsonType())); + } + + return get_string(input_format_t::bson, len - static_cast(1), result) && get() != std::char_traits::eof(); + } + + /*! + @brief Parses a byte array input of length @a len from the BSON input. + @param[in] len The length of the byte array to be read. + @param[in,out] result A reference to the binary variable where the read + array is to be stored. + @tparam NumberType The type of the length @a len + @pre len >= 0 + @return `true` if the byte array was successfully parsed + */ + template + bool get_bson_binary(const NumberType len, binary_t& result) + { + if (JSON_HEDLEY_UNLIKELY(len < 0)) + { + auto last_token = get_token_string(); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::bson, "byte array length cannot be negative, is " + std::to_string(len), "binary"), BasicJsonType())); + } + + // All BSON binary values have a subtype + std::uint8_t subtype{}; + get_number(input_format_t::bson, subtype); + result.set_subtype(subtype); + + return get_binary(input_format_t::bson, len, result); + } + + /*! + @brief Read a BSON document element of the given @a element_type. + @param[in] element_type The BSON element type, c.f. http://bsonspec.org/spec.html + @param[in] element_type_parse_position The position in the input stream, + where the `element_type` was read. + @warning Not all BSON element types are supported yet. An unsupported + @a element_type will give rise to a parse_error.114: + Unsupported BSON record type 0x... + @return whether a valid BSON-object/array was passed to the SAX parser + */ + bool parse_bson_element_internal(const char_int_type element_type, + const std::size_t element_type_parse_position) + { + switch (element_type) + { + case 0x01: // double + { + double number{}; + return get_number(input_format_t::bson, number) && sax->number_float(static_cast(number), ""); + } + + case 0x02: // string + { + std::int32_t len{}; + string_t value; + return get_number(input_format_t::bson, len) && get_bson_string(len, value) && sax->string(value); + } + + case 0x03: // object + { + return parse_bson_internal(); + } + + case 0x04: // array + { + return parse_bson_array(); + } + + case 0x05: // binary + { + std::int32_t len{}; + binary_t value; + return get_number(input_format_t::bson, len) && get_bson_binary(len, value) && sax->binary(value); + } + + case 0x08: // boolean + { + return sax->boolean(get() != 0); + } + + case 0x0A: // null + { + return sax->null(); + } + + case 0x10: // int32 + { + std::int32_t value{}; + return get_number(input_format_t::bson, value) && sax->number_integer(value); + } + + case 0x12: // int64 + { + std::int64_t value{}; + return get_number(input_format_t::bson, value) && sax->number_integer(value); + } + + default: // anything else not supported (yet) + { + std::array cr{{}}; + (std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast(element_type)); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + return sax->parse_error(element_type_parse_position, std::string(cr.data()), parse_error::create(114, element_type_parse_position, "Unsupported BSON record type 0x" + std::string(cr.data()), BasicJsonType())); + } + } + } + + /*! + @brief Read a BSON element list (as specified in the BSON-spec) + + The same binary layout is used for objects and arrays, hence it must be + indicated with the argument @a is_array which one is expected + (true --> array, false --> object). + + @param[in] is_array Determines if the element list being read is to be + treated as an object (@a is_array == false), or as an + array (@a is_array == true). + @return whether a valid BSON-object/array was passed to the SAX parser + */ + bool parse_bson_element_list(const bool is_array) + { + string_t key; + + while (auto element_type = get()) + { + if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::bson, "element list"))) + { + return false; + } + + const std::size_t element_type_parse_position = chars_read; + if (JSON_HEDLEY_UNLIKELY(!get_bson_cstr(key))) + { + return false; + } + + if (!is_array && !sax->key(key)) + { + return false; + } + + if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_internal(element_type, element_type_parse_position))) + { + return false; + } + + // get_bson_cstr only appends + key.clear(); + } + + return true; + } + + /*! + @brief Reads an array from the BSON input and passes it to the SAX-parser. + @return whether a valid BSON-array was passed to the SAX parser + */ + bool parse_bson_array() + { + std::int32_t document_size{}; + get_number(input_format_t::bson, document_size); + + if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1)))) + { + return false; + } + + if (JSON_HEDLEY_UNLIKELY(!parse_bson_element_list(/*is_array*/true))) + { + return false; + } + + return sax->end_array(); + } + + ////////// + // CBOR // + ////////// + + /*! + @param[in] get_char whether a new character should be retrieved from the + input (true) or whether the last read character should + be considered instead (false) + @param[in] tag_handler how CBOR tags should be treated + + @return whether a valid CBOR value was passed to the SAX parser + */ + bool parse_cbor_internal(const bool get_char, + const cbor_tag_handler_t tag_handler) + { + switch (get_char ? get() : current) + { + // EOF + case std::char_traits::eof(): + return unexpect_eof(input_format_t::cbor, "value"); + + // Integer 0x00..0x17 (0..23) + case 0x00: + case 0x01: + case 0x02: + case 0x03: + case 0x04: + case 0x05: + case 0x06: + case 0x07: + case 0x08: + case 0x09: + case 0x0A: + case 0x0B: + case 0x0C: + case 0x0D: + case 0x0E: + case 0x0F: + case 0x10: + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + case 0x16: + case 0x17: + return sax->number_unsigned(static_cast(current)); + + case 0x18: // Unsigned integer (one-byte uint8_t follows) + { + std::uint8_t number{}; + return get_number(input_format_t::cbor, number) && sax->number_unsigned(number); + } + + case 0x19: // Unsigned integer (two-byte uint16_t follows) + { + std::uint16_t number{}; + return get_number(input_format_t::cbor, number) && sax->number_unsigned(number); + } + + case 0x1A: // Unsigned integer (four-byte uint32_t follows) + { + std::uint32_t number{}; + return get_number(input_format_t::cbor, number) && sax->number_unsigned(number); + } + + case 0x1B: // Unsigned integer (eight-byte uint64_t follows) + { + std::uint64_t number{}; + return get_number(input_format_t::cbor, number) && sax->number_unsigned(number); + } + + // Negative integer -1-0x00..-1-0x17 (-1..-24) + case 0x20: + case 0x21: + case 0x22: + case 0x23: + case 0x24: + case 0x25: + case 0x26: + case 0x27: + case 0x28: + case 0x29: + case 0x2A: + case 0x2B: + case 0x2C: + case 0x2D: + case 0x2E: + case 0x2F: + case 0x30: + case 0x31: + case 0x32: + case 0x33: + case 0x34: + case 0x35: + case 0x36: + case 0x37: + return sax->number_integer(static_cast(0x20 - 1 - current)); + + case 0x38: // Negative integer (one-byte uint8_t follows) + { + std::uint8_t number{}; + return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast(-1) - number); + } + + case 0x39: // Negative integer -1-n (two-byte uint16_t follows) + { + std::uint16_t number{}; + return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast(-1) - number); + } + + case 0x3A: // Negative integer -1-n (four-byte uint32_t follows) + { + std::uint32_t number{}; + return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast(-1) - number); + } + + case 0x3B: // Negative integer -1-n (eight-byte uint64_t follows) + { + std::uint64_t number{}; + return get_number(input_format_t::cbor, number) && sax->number_integer(static_cast(-1) + - static_cast(number)); + } + + // Binary data (0x00..0x17 bytes follow) + case 0x40: + case 0x41: + case 0x42: + case 0x43: + case 0x44: + case 0x45: + case 0x46: + case 0x47: + case 0x48: + case 0x49: + case 0x4A: + case 0x4B: + case 0x4C: + case 0x4D: + case 0x4E: + case 0x4F: + case 0x50: + case 0x51: + case 0x52: + case 0x53: + case 0x54: + case 0x55: + case 0x56: + case 0x57: + case 0x58: // Binary data (one-byte uint8_t for n follows) + case 0x59: // Binary data (two-byte uint16_t for n follow) + case 0x5A: // Binary data (four-byte uint32_t for n follow) + case 0x5B: // Binary data (eight-byte uint64_t for n follow) + case 0x5F: // Binary data (indefinite length) + { + binary_t b; + return get_cbor_binary(b) && sax->binary(b); + } + + // UTF-8 string (0x00..0x17 bytes follow) + case 0x60: + case 0x61: + case 0x62: + case 0x63: + case 0x64: + case 0x65: + case 0x66: + case 0x67: + case 0x68: + case 0x69: + case 0x6A: + case 0x6B: + case 0x6C: + case 0x6D: + case 0x6E: + case 0x6F: + case 0x70: + case 0x71: + case 0x72: + case 0x73: + case 0x74: + case 0x75: + case 0x76: + case 0x77: + case 0x78: // UTF-8 string (one-byte uint8_t for n follows) + case 0x79: // UTF-8 string (two-byte uint16_t for n follow) + case 0x7A: // UTF-8 string (four-byte uint32_t for n follow) + case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow) + case 0x7F: // UTF-8 string (indefinite length) + { + string_t s; + return get_cbor_string(s) && sax->string(s); + } + + // array (0x00..0x17 data items follow) + case 0x80: + case 0x81: + case 0x82: + case 0x83: + case 0x84: + case 0x85: + case 0x86: + case 0x87: + case 0x88: + case 0x89: + case 0x8A: + case 0x8B: + case 0x8C: + case 0x8D: + case 0x8E: + case 0x8F: + case 0x90: + case 0x91: + case 0x92: + case 0x93: + case 0x94: + case 0x95: + case 0x96: + case 0x97: + return get_cbor_array(static_cast(static_cast(current) & 0x1Fu), tag_handler); + + case 0x98: // array (one-byte uint8_t for n follows) + { + std::uint8_t len{}; + return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast(len), tag_handler); + } + + case 0x99: // array (two-byte uint16_t for n follow) + { + std::uint16_t len{}; + return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast(len), tag_handler); + } + + case 0x9A: // array (four-byte uint32_t for n follow) + { + std::uint32_t len{}; + return get_number(input_format_t::cbor, len) && get_cbor_array(static_cast(len), tag_handler); + } + + case 0x9B: // array (eight-byte uint64_t for n follow) + { + std::uint64_t len{}; + return get_number(input_format_t::cbor, len) && get_cbor_array(detail::conditional_static_cast(len), tag_handler); + } + + case 0x9F: // array (indefinite length) + return get_cbor_array(std::size_t(-1), tag_handler); + + // map (0x00..0x17 pairs of data items follow) + case 0xA0: + case 0xA1: + case 0xA2: + case 0xA3: + case 0xA4: + case 0xA5: + case 0xA6: + case 0xA7: + case 0xA8: + case 0xA9: + case 0xAA: + case 0xAB: + case 0xAC: + case 0xAD: + case 0xAE: + case 0xAF: + case 0xB0: + case 0xB1: + case 0xB2: + case 0xB3: + case 0xB4: + case 0xB5: + case 0xB6: + case 0xB7: + return get_cbor_object(static_cast(static_cast(current) & 0x1Fu), tag_handler); + + case 0xB8: // map (one-byte uint8_t for n follows) + { + std::uint8_t len{}; + return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast(len), tag_handler); + } + + case 0xB9: // map (two-byte uint16_t for n follow) + { + std::uint16_t len{}; + return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast(len), tag_handler); + } + + case 0xBA: // map (four-byte uint32_t for n follow) + { + std::uint32_t len{}; + return get_number(input_format_t::cbor, len) && get_cbor_object(static_cast(len), tag_handler); + } + + case 0xBB: // map (eight-byte uint64_t for n follow) + { + std::uint64_t len{}; + return get_number(input_format_t::cbor, len) && get_cbor_object(detail::conditional_static_cast(len), tag_handler); + } + + case 0xBF: // map (indefinite length) + return get_cbor_object(std::size_t(-1), tag_handler); + + case 0xC6: // tagged item + case 0xC7: + case 0xC8: + case 0xC9: + case 0xCA: + case 0xCB: + case 0xCC: + case 0xCD: + case 0xCE: + case 0xCF: + case 0xD0: + case 0xD1: + case 0xD2: + case 0xD3: + case 0xD4: + case 0xD8: // tagged item (1 bytes follow) + case 0xD9: // tagged item (2 bytes follow) + case 0xDA: // tagged item (4 bytes follow) + case 0xDB: // tagged item (8 bytes follow) + { + switch (tag_handler) + { + case cbor_tag_handler_t::error: + { + auto last_token = get_token_string(); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor, "invalid byte: 0x" + last_token, "value"), BasicJsonType())); + } + + case cbor_tag_handler_t::ignore: + { + // ignore binary subtype + switch (current) + { + case 0xD8: + { + std::uint8_t subtype_to_ignore{}; + get_number(input_format_t::cbor, subtype_to_ignore); + break; + } + case 0xD9: + { + std::uint16_t subtype_to_ignore{}; + get_number(input_format_t::cbor, subtype_to_ignore); + break; + } + case 0xDA: + { + std::uint32_t subtype_to_ignore{}; + get_number(input_format_t::cbor, subtype_to_ignore); + break; + } + case 0xDB: + { + std::uint64_t subtype_to_ignore{}; + get_number(input_format_t::cbor, subtype_to_ignore); + break; + } + default: + break; + } + return parse_cbor_internal(true, tag_handler); + } + + case cbor_tag_handler_t::store: + { + binary_t b; + // use binary subtype and store in binary container + switch (current) + { + case 0xD8: + { + std::uint8_t subtype{}; + get_number(input_format_t::cbor, subtype); + b.set_subtype(detail::conditional_static_cast(subtype)); + break; + } + case 0xD9: + { + std::uint16_t subtype{}; + get_number(input_format_t::cbor, subtype); + b.set_subtype(detail::conditional_static_cast(subtype)); + break; + } + case 0xDA: + { + std::uint32_t subtype{}; + get_number(input_format_t::cbor, subtype); + b.set_subtype(detail::conditional_static_cast(subtype)); + break; + } + case 0xDB: + { + std::uint64_t subtype{}; + get_number(input_format_t::cbor, subtype); + b.set_subtype(detail::conditional_static_cast(subtype)); + break; + } + default: + return parse_cbor_internal(true, tag_handler); + } + get(); + return get_cbor_binary(b) && sax->binary(b); + } + + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + return false; // LCOV_EXCL_LINE + } + } + + case 0xF4: // false + return sax->boolean(false); + + case 0xF5: // true + return sax->boolean(true); + + case 0xF6: // null + return sax->null(); + + case 0xF9: // Half-Precision Float (two-byte IEEE 754) + { + const auto byte1_raw = get(); + if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "number"))) + { + return false; + } + const auto byte2_raw = get(); + if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "number"))) + { + return false; + } + + const auto byte1 = static_cast(byte1_raw); + const auto byte2 = static_cast(byte2_raw); + + // code from RFC 7049, Appendix D, Figure 3: + // As half-precision floating-point numbers were only added + // to IEEE 754 in 2008, today's programming platforms often + // still only have limited support for them. It is very + // easy to include at least decoding support for them even + // without such support. An example of a small decoder for + // half-precision floating-point numbers in the C language + // is shown in Fig. 3. + const auto half = static_cast((byte1 << 8u) + byte2); + const double val = [&half] + { + const int exp = (half >> 10u) & 0x1Fu; + const unsigned int mant = half & 0x3FFu; + JSON_ASSERT(0 <= exp&& exp <= 32); + JSON_ASSERT(mant <= 1024); + switch (exp) + { + case 0: + return std::ldexp(mant, -24); + case 31: + return (mant == 0) + ? std::numeric_limits::infinity() + : std::numeric_limits::quiet_NaN(); + default: + return std::ldexp(mant + 1024, exp - 25); + } + }(); + return sax->number_float((half & 0x8000u) != 0 + ? static_cast(-val) + : static_cast(val), ""); + } + + case 0xFA: // Single-Precision Float (four-byte IEEE 754) + { + float number{}; + return get_number(input_format_t::cbor, number) && sax->number_float(static_cast(number), ""); + } + + case 0xFB: // Double-Precision Float (eight-byte IEEE 754) + { + double number{}; + return get_number(input_format_t::cbor, number) && sax->number_float(static_cast(number), ""); + } + + default: // anything else (0xFF is handled inside the other types) + { + auto last_token = get_token_string(); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::cbor, "invalid byte: 0x" + last_token, "value"), BasicJsonType())); + } + } + } + + /*! + @brief reads a CBOR string + + This function first reads starting bytes to determine the expected + string length and then copies this number of bytes into a string. + Additionally, CBOR's strings with indefinite lengths are supported. + + @param[out] result created string + + @return whether string creation completed + */ + bool get_cbor_string(string_t& result) + { + if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "string"))) + { + return false; + } + + switch (current) + { + // UTF-8 string (0x00..0x17 bytes follow) + case 0x60: + case 0x61: + case 0x62: + case 0x63: + case 0x64: + case 0x65: + case 0x66: + case 0x67: + case 0x68: + case 0x69: + case 0x6A: + case 0x6B: + case 0x6C: + case 0x6D: + case 0x6E: + case 0x6F: + case 0x70: + case 0x71: + case 0x72: + case 0x73: + case 0x74: + case 0x75: + case 0x76: + case 0x77: + { + return get_string(input_format_t::cbor, static_cast(current) & 0x1Fu, result); + } + + case 0x78: // UTF-8 string (one-byte uint8_t for n follows) + { + std::uint8_t len{}; + return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result); + } + + case 0x79: // UTF-8 string (two-byte uint16_t for n follow) + { + std::uint16_t len{}; + return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result); + } + + case 0x7A: // UTF-8 string (four-byte uint32_t for n follow) + { + std::uint32_t len{}; + return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result); + } + + case 0x7B: // UTF-8 string (eight-byte uint64_t for n follow) + { + std::uint64_t len{}; + return get_number(input_format_t::cbor, len) && get_string(input_format_t::cbor, len, result); + } + + case 0x7F: // UTF-8 string (indefinite length) + { + while (get() != 0xFF) + { + string_t chunk; + if (!get_cbor_string(chunk)) + { + return false; + } + result.append(chunk); + } + return true; + } + + default: + { + auto last_token = get_token_string(); + return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, "expected length specification (0x60-0x7B) or indefinite string type (0x7F); last byte: 0x" + last_token, "string"), BasicJsonType())); + } + } + } + + /*! + @brief reads a CBOR byte array + + This function first reads starting bytes to determine the expected + byte array length and then copies this number of bytes into the byte array. + Additionally, CBOR's byte arrays with indefinite lengths are supported. + + @param[out] result created byte array + + @return whether byte array creation completed + */ + bool get_cbor_binary(binary_t& result) + { + if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::cbor, "binary"))) + { + return false; + } + + switch (current) + { + // Binary data (0x00..0x17 bytes follow) + case 0x40: + case 0x41: + case 0x42: + case 0x43: + case 0x44: + case 0x45: + case 0x46: + case 0x47: + case 0x48: + case 0x49: + case 0x4A: + case 0x4B: + case 0x4C: + case 0x4D: + case 0x4E: + case 0x4F: + case 0x50: + case 0x51: + case 0x52: + case 0x53: + case 0x54: + case 0x55: + case 0x56: + case 0x57: + { + return get_binary(input_format_t::cbor, static_cast(current) & 0x1Fu, result); + } + + case 0x58: // Binary data (one-byte uint8_t for n follows) + { + std::uint8_t len{}; + return get_number(input_format_t::cbor, len) && + get_binary(input_format_t::cbor, len, result); + } + + case 0x59: // Binary data (two-byte uint16_t for n follow) + { + std::uint16_t len{}; + return get_number(input_format_t::cbor, len) && + get_binary(input_format_t::cbor, len, result); + } + + case 0x5A: // Binary data (four-byte uint32_t for n follow) + { + std::uint32_t len{}; + return get_number(input_format_t::cbor, len) && + get_binary(input_format_t::cbor, len, result); + } + + case 0x5B: // Binary data (eight-byte uint64_t for n follow) + { + std::uint64_t len{}; + return get_number(input_format_t::cbor, len) && + get_binary(input_format_t::cbor, len, result); + } + + case 0x5F: // Binary data (indefinite length) + { + while (get() != 0xFF) + { + binary_t chunk; + if (!get_cbor_binary(chunk)) + { + return false; + } + result.insert(result.end(), chunk.begin(), chunk.end()); + } + return true; + } + + default: + { + auto last_token = get_token_string(); + return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::cbor, "expected length specification (0x40-0x5B) or indefinite binary array type (0x5F); last byte: 0x" + last_token, "binary"), BasicJsonType())); + } + } + } + + /*! + @param[in] len the length of the array or std::size_t(-1) for an + array of indefinite size + @param[in] tag_handler how CBOR tags should be treated + @return whether array creation completed + */ + bool get_cbor_array(const std::size_t len, + const cbor_tag_handler_t tag_handler) + { + if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len))) + { + return false; + } + + if (len != std::size_t(-1)) + { + for (std::size_t i = 0; i < len; ++i) + { + if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler))) + { + return false; + } + } + } + else + { + while (get() != 0xFF) + { + if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(false, tag_handler))) + { + return false; + } + } + } + + return sax->end_array(); + } + + /*! + @param[in] len the length of the object or std::size_t(-1) for an + object of indefinite size + @param[in] tag_handler how CBOR tags should be treated + @return whether object creation completed + */ + bool get_cbor_object(const std::size_t len, + const cbor_tag_handler_t tag_handler) + { + if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len))) + { + return false; + } + + if (len != 0) + { + string_t key; + if (len != std::size_t(-1)) + { + for (std::size_t i = 0; i < len; ++i) + { + get(); + if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key))) + { + return false; + } + + if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler))) + { + return false; + } + key.clear(); + } + } + else + { + while (get() != 0xFF) + { + if (JSON_HEDLEY_UNLIKELY(!get_cbor_string(key) || !sax->key(key))) + { + return false; + } + + if (JSON_HEDLEY_UNLIKELY(!parse_cbor_internal(true, tag_handler))) + { + return false; + } + key.clear(); + } + } + } + + return sax->end_object(); + } + + ///////////// + // MsgPack // + ///////////// + + /*! + @return whether a valid MessagePack value was passed to the SAX parser + */ + bool parse_msgpack_internal() + { + switch (get()) + { + // EOF + case std::char_traits::eof(): + return unexpect_eof(input_format_t::msgpack, "value"); + + // positive fixint + case 0x00: + case 0x01: + case 0x02: + case 0x03: + case 0x04: + case 0x05: + case 0x06: + case 0x07: + case 0x08: + case 0x09: + case 0x0A: + case 0x0B: + case 0x0C: + case 0x0D: + case 0x0E: + case 0x0F: + case 0x10: + case 0x11: + case 0x12: + case 0x13: + case 0x14: + case 0x15: + case 0x16: + case 0x17: + case 0x18: + case 0x19: + case 0x1A: + case 0x1B: + case 0x1C: + case 0x1D: + case 0x1E: + case 0x1F: + case 0x20: + case 0x21: + case 0x22: + case 0x23: + case 0x24: + case 0x25: + case 0x26: + case 0x27: + case 0x28: + case 0x29: + case 0x2A: + case 0x2B: + case 0x2C: + case 0x2D: + case 0x2E: + case 0x2F: + case 0x30: + case 0x31: + case 0x32: + case 0x33: + case 0x34: + case 0x35: + case 0x36: + case 0x37: + case 0x38: + case 0x39: + case 0x3A: + case 0x3B: + case 0x3C: + case 0x3D: + case 0x3E: + case 0x3F: + case 0x40: + case 0x41: + case 0x42: + case 0x43: + case 0x44: + case 0x45: + case 0x46: + case 0x47: + case 0x48: + case 0x49: + case 0x4A: + case 0x4B: + case 0x4C: + case 0x4D: + case 0x4E: + case 0x4F: + case 0x50: + case 0x51: + case 0x52: + case 0x53: + case 0x54: + case 0x55: + case 0x56: + case 0x57: + case 0x58: + case 0x59: + case 0x5A: + case 0x5B: + case 0x5C: + case 0x5D: + case 0x5E: + case 0x5F: + case 0x60: + case 0x61: + case 0x62: + case 0x63: + case 0x64: + case 0x65: + case 0x66: + case 0x67: + case 0x68: + case 0x69: + case 0x6A: + case 0x6B: + case 0x6C: + case 0x6D: + case 0x6E: + case 0x6F: + case 0x70: + case 0x71: + case 0x72: + case 0x73: + case 0x74: + case 0x75: + case 0x76: + case 0x77: + case 0x78: + case 0x79: + case 0x7A: + case 0x7B: + case 0x7C: + case 0x7D: + case 0x7E: + case 0x7F: + return sax->number_unsigned(static_cast(current)); + + // fixmap + case 0x80: + case 0x81: + case 0x82: + case 0x83: + case 0x84: + case 0x85: + case 0x86: + case 0x87: + case 0x88: + case 0x89: + case 0x8A: + case 0x8B: + case 0x8C: + case 0x8D: + case 0x8E: + case 0x8F: + return get_msgpack_object(static_cast(static_cast(current) & 0x0Fu)); + + // fixarray + case 0x90: + case 0x91: + case 0x92: + case 0x93: + case 0x94: + case 0x95: + case 0x96: + case 0x97: + case 0x98: + case 0x99: + case 0x9A: + case 0x9B: + case 0x9C: + case 0x9D: + case 0x9E: + case 0x9F: + return get_msgpack_array(static_cast(static_cast(current) & 0x0Fu)); + + // fixstr + case 0xA0: + case 0xA1: + case 0xA2: + case 0xA3: + case 0xA4: + case 0xA5: + case 0xA6: + case 0xA7: + case 0xA8: + case 0xA9: + case 0xAA: + case 0xAB: + case 0xAC: + case 0xAD: + case 0xAE: + case 0xAF: + case 0xB0: + case 0xB1: + case 0xB2: + case 0xB3: + case 0xB4: + case 0xB5: + case 0xB6: + case 0xB7: + case 0xB8: + case 0xB9: + case 0xBA: + case 0xBB: + case 0xBC: + case 0xBD: + case 0xBE: + case 0xBF: + case 0xD9: // str 8 + case 0xDA: // str 16 + case 0xDB: // str 32 + { + string_t s; + return get_msgpack_string(s) && sax->string(s); + } + + case 0xC0: // nil + return sax->null(); + + case 0xC2: // false + return sax->boolean(false); + + case 0xC3: // true + return sax->boolean(true); + + case 0xC4: // bin 8 + case 0xC5: // bin 16 + case 0xC6: // bin 32 + case 0xC7: // ext 8 + case 0xC8: // ext 16 + case 0xC9: // ext 32 + case 0xD4: // fixext 1 + case 0xD5: // fixext 2 + case 0xD6: // fixext 4 + case 0xD7: // fixext 8 + case 0xD8: // fixext 16 + { + binary_t b; + return get_msgpack_binary(b) && sax->binary(b); + } + + case 0xCA: // float 32 + { + float number{}; + return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast(number), ""); + } + + case 0xCB: // float 64 + { + double number{}; + return get_number(input_format_t::msgpack, number) && sax->number_float(static_cast(number), ""); + } + + case 0xCC: // uint 8 + { + std::uint8_t number{}; + return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number); + } + + case 0xCD: // uint 16 + { + std::uint16_t number{}; + return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number); + } + + case 0xCE: // uint 32 + { + std::uint32_t number{}; + return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number); + } + + case 0xCF: // uint 64 + { + std::uint64_t number{}; + return get_number(input_format_t::msgpack, number) && sax->number_unsigned(number); + } + + case 0xD0: // int 8 + { + std::int8_t number{}; + return get_number(input_format_t::msgpack, number) && sax->number_integer(number); + } + + case 0xD1: // int 16 + { + std::int16_t number{}; + return get_number(input_format_t::msgpack, number) && sax->number_integer(number); + } + + case 0xD2: // int 32 + { + std::int32_t number{}; + return get_number(input_format_t::msgpack, number) && sax->number_integer(number); + } + + case 0xD3: // int 64 + { + std::int64_t number{}; + return get_number(input_format_t::msgpack, number) && sax->number_integer(number); + } + + case 0xDC: // array 16 + { + std::uint16_t len{}; + return get_number(input_format_t::msgpack, len) && get_msgpack_array(static_cast(len)); + } + + case 0xDD: // array 32 + { + std::uint32_t len{}; + return get_number(input_format_t::msgpack, len) && get_msgpack_array(static_cast(len)); + } + + case 0xDE: // map 16 + { + std::uint16_t len{}; + return get_number(input_format_t::msgpack, len) && get_msgpack_object(static_cast(len)); + } + + case 0xDF: // map 32 + { + std::uint32_t len{}; + return get_number(input_format_t::msgpack, len) && get_msgpack_object(static_cast(len)); + } + + // negative fixint + case 0xE0: + case 0xE1: + case 0xE2: + case 0xE3: + case 0xE4: + case 0xE5: + case 0xE6: + case 0xE7: + case 0xE8: + case 0xE9: + case 0xEA: + case 0xEB: + case 0xEC: + case 0xED: + case 0xEE: + case 0xEF: + case 0xF0: + case 0xF1: + case 0xF2: + case 0xF3: + case 0xF4: + case 0xF5: + case 0xF6: + case 0xF7: + case 0xF8: + case 0xF9: + case 0xFA: + case 0xFB: + case 0xFC: + case 0xFD: + case 0xFE: + case 0xFF: + return sax->number_integer(static_cast(current)); + + default: // anything else + { + auto last_token = get_token_string(); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::msgpack, "invalid byte: 0x" + last_token, "value"), BasicJsonType())); + } + } + } + + /*! + @brief reads a MessagePack string + + This function first reads starting bytes to determine the expected + string length and then copies this number of bytes into a string. + + @param[out] result created string + + @return whether string creation completed + */ + bool get_msgpack_string(string_t& result) + { + if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::msgpack, "string"))) + { + return false; + } + + switch (current) + { + // fixstr + case 0xA0: + case 0xA1: + case 0xA2: + case 0xA3: + case 0xA4: + case 0xA5: + case 0xA6: + case 0xA7: + case 0xA8: + case 0xA9: + case 0xAA: + case 0xAB: + case 0xAC: + case 0xAD: + case 0xAE: + case 0xAF: + case 0xB0: + case 0xB1: + case 0xB2: + case 0xB3: + case 0xB4: + case 0xB5: + case 0xB6: + case 0xB7: + case 0xB8: + case 0xB9: + case 0xBA: + case 0xBB: + case 0xBC: + case 0xBD: + case 0xBE: + case 0xBF: + { + return get_string(input_format_t::msgpack, static_cast(current) & 0x1Fu, result); + } + + case 0xD9: // str 8 + { + std::uint8_t len{}; + return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result); + } + + case 0xDA: // str 16 + { + std::uint16_t len{}; + return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result); + } + + case 0xDB: // str 32 + { + std::uint32_t len{}; + return get_number(input_format_t::msgpack, len) && get_string(input_format_t::msgpack, len, result); + } + + default: + { + auto last_token = get_token_string(); + return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::msgpack, "expected length specification (0xA0-0xBF, 0xD9-0xDB); last byte: 0x" + last_token, "string"), BasicJsonType())); + } + } + } + + /*! + @brief reads a MessagePack byte array + + This function first reads starting bytes to determine the expected + byte array length and then copies this number of bytes into a byte array. + + @param[out] result created byte array + + @return whether byte array creation completed + */ + bool get_msgpack_binary(binary_t& result) + { + // helper function to set the subtype + auto assign_and_return_true = [&result](std::int8_t subtype) + { + result.set_subtype(static_cast(subtype)); + return true; + }; + + switch (current) + { + case 0xC4: // bin 8 + { + std::uint8_t len{}; + return get_number(input_format_t::msgpack, len) && + get_binary(input_format_t::msgpack, len, result); + } + + case 0xC5: // bin 16 + { + std::uint16_t len{}; + return get_number(input_format_t::msgpack, len) && + get_binary(input_format_t::msgpack, len, result); + } + + case 0xC6: // bin 32 + { + std::uint32_t len{}; + return get_number(input_format_t::msgpack, len) && + get_binary(input_format_t::msgpack, len, result); + } + + case 0xC7: // ext 8 + { + std::uint8_t len{}; + std::int8_t subtype{}; + return get_number(input_format_t::msgpack, len) && + get_number(input_format_t::msgpack, subtype) && + get_binary(input_format_t::msgpack, len, result) && + assign_and_return_true(subtype); + } + + case 0xC8: // ext 16 + { + std::uint16_t len{}; + std::int8_t subtype{}; + return get_number(input_format_t::msgpack, len) && + get_number(input_format_t::msgpack, subtype) && + get_binary(input_format_t::msgpack, len, result) && + assign_and_return_true(subtype); + } + + case 0xC9: // ext 32 + { + std::uint32_t len{}; + std::int8_t subtype{}; + return get_number(input_format_t::msgpack, len) && + get_number(input_format_t::msgpack, subtype) && + get_binary(input_format_t::msgpack, len, result) && + assign_and_return_true(subtype); + } + + case 0xD4: // fixext 1 + { + std::int8_t subtype{}; + return get_number(input_format_t::msgpack, subtype) && + get_binary(input_format_t::msgpack, 1, result) && + assign_and_return_true(subtype); + } + + case 0xD5: // fixext 2 + { + std::int8_t subtype{}; + return get_number(input_format_t::msgpack, subtype) && + get_binary(input_format_t::msgpack, 2, result) && + assign_and_return_true(subtype); + } + + case 0xD6: // fixext 4 + { + std::int8_t subtype{}; + return get_number(input_format_t::msgpack, subtype) && + get_binary(input_format_t::msgpack, 4, result) && + assign_and_return_true(subtype); + } + + case 0xD7: // fixext 8 + { + std::int8_t subtype{}; + return get_number(input_format_t::msgpack, subtype) && + get_binary(input_format_t::msgpack, 8, result) && + assign_and_return_true(subtype); + } + + case 0xD8: // fixext 16 + { + std::int8_t subtype{}; + return get_number(input_format_t::msgpack, subtype) && + get_binary(input_format_t::msgpack, 16, result) && + assign_and_return_true(subtype); + } + + default: // LCOV_EXCL_LINE + return false; // LCOV_EXCL_LINE + } + } + + /*! + @param[in] len the length of the array + @return whether array creation completed + */ + bool get_msgpack_array(const std::size_t len) + { + if (JSON_HEDLEY_UNLIKELY(!sax->start_array(len))) + { + return false; + } + + for (std::size_t i = 0; i < len; ++i) + { + if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal())) + { + return false; + } + } + + return sax->end_array(); + } + + /*! + @param[in] len the length of the object + @return whether object creation completed + */ + bool get_msgpack_object(const std::size_t len) + { + if (JSON_HEDLEY_UNLIKELY(!sax->start_object(len))) + { + return false; + } + + string_t key; + for (std::size_t i = 0; i < len; ++i) + { + get(); + if (JSON_HEDLEY_UNLIKELY(!get_msgpack_string(key) || !sax->key(key))) + { + return false; + } + + if (JSON_HEDLEY_UNLIKELY(!parse_msgpack_internal())) + { + return false; + } + key.clear(); + } + + return sax->end_object(); + } + + //////////// + // UBJSON // + //////////// + + /*! + @param[in] get_char whether a new character should be retrieved from the + input (true, default) or whether the last read + character should be considered instead + + @return whether a valid UBJSON value was passed to the SAX parser + */ + bool parse_ubjson_internal(const bool get_char = true) + { + return get_ubjson_value(get_char ? get_ignore_noop() : current); + } + + /*! + @brief reads a UBJSON string + + This function is either called after reading the 'S' byte explicitly + indicating a string, or in case of an object key where the 'S' byte can be + left out. + + @param[out] result created string + @param[in] get_char whether a new character should be retrieved from the + input (true, default) or whether the last read + character should be considered instead + + @return whether string creation completed + */ + bool get_ubjson_string(string_t& result, const bool get_char = true) + { + if (get_char) + { + get(); // TODO(niels): may we ignore N here? + } + + if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "value"))) + { + return false; + } + + switch (current) + { + case 'U': + { + std::uint8_t len{}; + return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result); + } + + case 'i': + { + std::int8_t len{}; + return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result); + } + + case 'I': + { + std::int16_t len{}; + return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result); + } + + case 'l': + { + std::int32_t len{}; + return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result); + } + + case 'L': + { + std::int64_t len{}; + return get_number(input_format_t::ubjson, len) && get_string(input_format_t::ubjson, len, result); + } + + default: + auto last_token = get_token_string(); + return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "expected length type specification (U, i, I, l, L); last byte: 0x" + last_token, "string"), BasicJsonType())); + } + } + + /*! + @param[out] result determined size + @return whether size determination completed + */ + bool get_ubjson_size_value(std::size_t& result) + { + switch (get_ignore_noop()) + { + case 'U': + { + std::uint8_t number{}; + if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number))) + { + return false; + } + result = static_cast(number); + return true; + } + + case 'i': + { + std::int8_t number{}; + if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number))) + { + return false; + } + result = static_cast(number); // NOLINT(bugprone-signed-char-misuse,cert-str34-c): number is not a char + return true; + } + + case 'I': + { + std::int16_t number{}; + if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number))) + { + return false; + } + result = static_cast(number); + return true; + } + + case 'l': + { + std::int32_t number{}; + if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number))) + { + return false; + } + result = static_cast(number); + return true; + } + + case 'L': + { + std::int64_t number{}; + if (JSON_HEDLEY_UNLIKELY(!get_number(input_format_t::ubjson, number))) + { + return false; + } + result = static_cast(number); + return true; + } + + default: + { + auto last_token = get_token_string(); + return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "expected length type specification (U, i, I, l, L) after '#'; last byte: 0x" + last_token, "size"), BasicJsonType())); + } + } + } + + /*! + @brief determine the type and size for a container + + In the optimized UBJSON format, a type and a size can be provided to allow + for a more compact representation. + + @param[out] result pair of the size and the type + + @return whether pair creation completed + */ + bool get_ubjson_size_type(std::pair& result) + { + result.first = string_t::npos; // size + result.second = 0; // type + + get_ignore_noop(); + + if (current == '$') + { + result.second = get(); // must not ignore 'N', because 'N' maybe the type + if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "type"))) + { + return false; + } + + get_ignore_noop(); + if (JSON_HEDLEY_UNLIKELY(current != '#')) + { + if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "value"))) + { + return false; + } + auto last_token = get_token_string(); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::ubjson, "expected '#' after type information; last byte: 0x" + last_token, "size"), BasicJsonType())); + } + + return get_ubjson_size_value(result.first); + } + + if (current == '#') + { + return get_ubjson_size_value(result.first); + } + + return true; + } + + /*! + @param prefix the previously read or set type prefix + @return whether value creation completed + */ + bool get_ubjson_value(const char_int_type prefix) + { + switch (prefix) + { + case std::char_traits::eof(): // EOF + return unexpect_eof(input_format_t::ubjson, "value"); + + case 'T': // true + return sax->boolean(true); + case 'F': // false + return sax->boolean(false); + + case 'Z': // null + return sax->null(); + + case 'U': + { + std::uint8_t number{}; + return get_number(input_format_t::ubjson, number) && sax->number_unsigned(number); + } + + case 'i': + { + std::int8_t number{}; + return get_number(input_format_t::ubjson, number) && sax->number_integer(number); + } + + case 'I': + { + std::int16_t number{}; + return get_number(input_format_t::ubjson, number) && sax->number_integer(number); + } + + case 'l': + { + std::int32_t number{}; + return get_number(input_format_t::ubjson, number) && sax->number_integer(number); + } + + case 'L': + { + std::int64_t number{}; + return get_number(input_format_t::ubjson, number) && sax->number_integer(number); + } + + case 'd': + { + float number{}; + return get_number(input_format_t::ubjson, number) && sax->number_float(static_cast(number), ""); + } + + case 'D': + { + double number{}; + return get_number(input_format_t::ubjson, number) && sax->number_float(static_cast(number), ""); + } + + case 'H': + { + return get_ubjson_high_precision_number(); + } + + case 'C': // char + { + get(); + if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "char"))) + { + return false; + } + if (JSON_HEDLEY_UNLIKELY(current > 127)) + { + auto last_token = get_token_string(); + return sax->parse_error(chars_read, last_token, parse_error::create(113, chars_read, exception_message(input_format_t::ubjson, "byte after 'C' must be in range 0x00..0x7F; last byte: 0x" + last_token, "char"), BasicJsonType())); + } + string_t s(1, static_cast(current)); + return sax->string(s); + } + + case 'S': // string + { + string_t s; + return get_ubjson_string(s) && sax->string(s); + } + + case '[': // array + return get_ubjson_array(); + + case '{': // object + return get_ubjson_object(); + + default: // anything else + { + auto last_token = get_token_string(); + return sax->parse_error(chars_read, last_token, parse_error::create(112, chars_read, exception_message(input_format_t::ubjson, "invalid byte: 0x" + last_token, "value"), BasicJsonType())); + } + } + } + + /*! + @return whether array creation completed + */ + bool get_ubjson_array() + { + std::pair size_and_type; + if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type))) + { + return false; + } + + if (size_and_type.first != string_t::npos) + { + if (JSON_HEDLEY_UNLIKELY(!sax->start_array(size_and_type.first))) + { + return false; + } + + if (size_and_type.second != 0) + { + if (size_and_type.second != 'N') + { + for (std::size_t i = 0; i < size_and_type.first; ++i) + { + if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second))) + { + return false; + } + } + } + } + else + { + for (std::size_t i = 0; i < size_and_type.first; ++i) + { + if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal())) + { + return false; + } + } + } + } + else + { + if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1)))) + { + return false; + } + + while (current != ']') + { + if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal(false))) + { + return false; + } + get_ignore_noop(); + } + } + + return sax->end_array(); + } + + /*! + @return whether object creation completed + */ + bool get_ubjson_object() + { + std::pair size_and_type; + if (JSON_HEDLEY_UNLIKELY(!get_ubjson_size_type(size_and_type))) + { + return false; + } + + string_t key; + if (size_and_type.first != string_t::npos) + { + if (JSON_HEDLEY_UNLIKELY(!sax->start_object(size_and_type.first))) + { + return false; + } + + if (size_and_type.second != 0) + { + for (std::size_t i = 0; i < size_and_type.first; ++i) + { + if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key))) + { + return false; + } + if (JSON_HEDLEY_UNLIKELY(!get_ubjson_value(size_and_type.second))) + { + return false; + } + key.clear(); + } + } + else + { + for (std::size_t i = 0; i < size_and_type.first; ++i) + { + if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key) || !sax->key(key))) + { + return false; + } + if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal())) + { + return false; + } + key.clear(); + } + } + } + else + { + if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1)))) + { + return false; + } + + while (current != '}') + { + if (JSON_HEDLEY_UNLIKELY(!get_ubjson_string(key, false) || !sax->key(key))) + { + return false; + } + if (JSON_HEDLEY_UNLIKELY(!parse_ubjson_internal())) + { + return false; + } + get_ignore_noop(); + key.clear(); + } + } + + return sax->end_object(); + } + + // Note, no reader for UBJSON binary types is implemented because they do + // not exist + + bool get_ubjson_high_precision_number() + { + // get size of following number string + std::size_t size{}; + auto res = get_ubjson_size_value(size); + if (JSON_HEDLEY_UNLIKELY(!res)) + { + return res; + } + + // get number string + std::vector number_vector; + for (std::size_t i = 0; i < size; ++i) + { + get(); + if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(input_format_t::ubjson, "number"))) + { + return false; + } + number_vector.push_back(static_cast(current)); + } + + // parse number string + using ia_type = decltype(detail::input_adapter(number_vector)); + auto number_lexer = detail::lexer(detail::input_adapter(number_vector), false); + const auto result_number = number_lexer.scan(); + const auto number_string = number_lexer.get_token_string(); + const auto result_remainder = number_lexer.scan(); + + using token_type = typename detail::lexer_base::token_type; + + if (JSON_HEDLEY_UNLIKELY(result_remainder != token_type::end_of_input)) + { + return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number"), BasicJsonType())); + } + + switch (result_number) + { + case token_type::value_integer: + return sax->number_integer(number_lexer.get_number_integer()); + case token_type::value_unsigned: + return sax->number_unsigned(number_lexer.get_number_unsigned()); + case token_type::value_float: + return sax->number_float(number_lexer.get_number_float(), std::move(number_string)); + case token_type::uninitialized: + case token_type::literal_true: + case token_type::literal_false: + case token_type::literal_null: + case token_type::value_string: + case token_type::begin_array: + case token_type::begin_object: + case token_type::end_array: + case token_type::end_object: + case token_type::name_separator: + case token_type::value_separator: + case token_type::parse_error: + case token_type::end_of_input: + case token_type::literal_or_value: + default: + return sax->parse_error(chars_read, number_string, parse_error::create(115, chars_read, exception_message(input_format_t::ubjson, "invalid number text: " + number_lexer.get_token_string(), "high-precision number"), BasicJsonType())); + } + } + + /////////////////////// + // Utility functions // + /////////////////////// + + /*! + @brief get next character from the input + + This function provides the interface to the used input adapter. It does + not throw in case the input reached EOF, but returns a -'ve valued + `std::char_traits::eof()` in that case. + + @return character read from the input + */ + char_int_type get() + { + ++chars_read; + return current = ia.get_character(); + } + + /*! + @return character read from the input after ignoring all 'N' entries + */ + char_int_type get_ignore_noop() + { + do + { + get(); + } + while (current == 'N'); + + return current; + } + + /* + @brief read a number from the input + + @tparam NumberType the type of the number + @param[in] format the current format (for diagnostics) + @param[out] result number of type @a NumberType + + @return whether conversion completed + + @note This function needs to respect the system's endianess, because + bytes in CBOR, MessagePack, and UBJSON are stored in network order + (big endian) and therefore need reordering on little endian systems. + */ + template + bool get_number(const input_format_t format, NumberType& result) + { + // step 1: read input into array with system's byte order + std::array vec{}; + for (std::size_t i = 0; i < sizeof(NumberType); ++i) + { + get(); + if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "number"))) + { + return false; + } + + // reverse byte order prior to conversion if necessary + if (is_little_endian != InputIsLittleEndian) + { + vec[sizeof(NumberType) - i - 1] = static_cast(current); + } + else + { + vec[i] = static_cast(current); // LCOV_EXCL_LINE + } + } + + // step 2: convert array into number of type T and return + std::memcpy(&result, vec.data(), sizeof(NumberType)); + return true; + } + + /*! + @brief create a string by reading characters from the input + + @tparam NumberType the type of the number + @param[in] format the current format (for diagnostics) + @param[in] len number of characters to read + @param[out] result string created by reading @a len bytes + + @return whether string creation completed + + @note We can not reserve @a len bytes for the result, because @a len + may be too large. Usually, @ref unexpect_eof() detects the end of + the input before we run out of string memory. + */ + template + bool get_string(const input_format_t format, + const NumberType len, + string_t& result) + { + bool success = true; + for (NumberType i = 0; i < len; i++) + { + get(); + if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "string"))) + { + success = false; + break; + } + result.push_back(static_cast(current)); + } + return success; + } + + /*! + @brief create a byte array by reading bytes from the input + + @tparam NumberType the type of the number + @param[in] format the current format (for diagnostics) + @param[in] len number of bytes to read + @param[out] result byte array created by reading @a len bytes + + @return whether byte array creation completed + + @note We can not reserve @a len bytes for the result, because @a len + may be too large. Usually, @ref unexpect_eof() detects the end of + the input before we run out of memory. + */ + template + bool get_binary(const input_format_t format, + const NumberType len, + binary_t& result) + { + bool success = true; + for (NumberType i = 0; i < len; i++) + { + get(); + if (JSON_HEDLEY_UNLIKELY(!unexpect_eof(format, "binary"))) + { + success = false; + break; + } + result.push_back(static_cast(current)); + } + return success; + } + + /*! + @param[in] format the current format (for diagnostics) + @param[in] context further context information (for diagnostics) + @return whether the last read character is not EOF + */ + JSON_HEDLEY_NON_NULL(3) + bool unexpect_eof(const input_format_t format, const char* context) const + { + if (JSON_HEDLEY_UNLIKELY(current == std::char_traits::eof())) + { + return sax->parse_error(chars_read, "", + parse_error::create(110, chars_read, exception_message(format, "unexpected end of input", context), BasicJsonType())); + } + return true; + } + + /*! + @return a string representation of the last read byte + */ + std::string get_token_string() const + { + std::array cr{{}}; + (std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast(current)); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + return std::string{cr.data()}; + } + + /*! + @param[in] format the current format + @param[in] detail a detailed error message + @param[in] context further context information + @return a message string to use in the parse_error exceptions + */ + std::string exception_message(const input_format_t format, + const std::string& detail, + const std::string& context) const + { + std::string error_msg = "syntax error while parsing "; + + switch (format) + { + case input_format_t::cbor: + error_msg += "CBOR"; + break; + + case input_format_t::msgpack: + error_msg += "MessagePack"; + break; + + case input_format_t::ubjson: + error_msg += "UBJSON"; + break; + + case input_format_t::bson: + error_msg += "BSON"; + break; + + case input_format_t::json: // LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + } + + return error_msg + " " + context + ": " + detail; + } + + private: + /// input adapter + InputAdapterType ia; + + /// the current character + char_int_type current = std::char_traits::eof(); + + /// the number of characters read + std::size_t chars_read = 0; + + /// whether we can assume little endianess + const bool is_little_endian = little_endianess(); + + /// the SAX parser + json_sax_t* sax = nullptr; +}; +} // namespace detail +} // namespace nlohmann + +// #include + +// #include + +// #include + + +#include // isfinite +#include // uint8_t +#include // function +#include // string +#include // move +#include // vector + +// #include + +// #include + +// #include + +// #include + +// #include + +// #include + +// #include + + +namespace nlohmann +{ +namespace detail +{ +//////////// +// parser // +//////////// + +enum class parse_event_t : std::uint8_t +{ + /// the parser read `{` and started to process a JSON object + object_start, + /// the parser read `}` and finished processing a JSON object + object_end, + /// the parser read `[` and started to process a JSON array + array_start, + /// the parser read `]` and finished processing a JSON array + array_end, + /// the parser read a key of a value in an object + key, + /// the parser finished reading a JSON value + value +}; + +template +using parser_callback_t = + std::function; + +/*! +@brief syntax analysis + +This class implements a recursive descent parser. +*/ +template +class parser +{ + using number_integer_t = typename BasicJsonType::number_integer_t; + using number_unsigned_t = typename BasicJsonType::number_unsigned_t; + using number_float_t = typename BasicJsonType::number_float_t; + using string_t = typename BasicJsonType::string_t; + using lexer_t = lexer; + using token_type = typename lexer_t::token_type; + + public: + /// a parser reading from an input adapter + explicit parser(InputAdapterType&& adapter, + const parser_callback_t cb = nullptr, + const bool allow_exceptions_ = true, + const bool skip_comments = false) + : callback(cb) + , m_lexer(std::move(adapter), skip_comments) + , allow_exceptions(allow_exceptions_) + { + // read first token + get_token(); + } + + /*! + @brief public parser interface + + @param[in] strict whether to expect the last token to be EOF + @param[in,out] result parsed JSON value + + @throw parse_error.101 in case of an unexpected token + @throw parse_error.102 if to_unicode fails or surrogate error + @throw parse_error.103 if to_unicode fails + */ + void parse(const bool strict, BasicJsonType& result) + { + if (callback) + { + json_sax_dom_callback_parser sdp(result, callback, allow_exceptions); + sax_parse_internal(&sdp); + + // in strict mode, input must be completely read + if (strict && (get_token() != token_type::end_of_input)) + { + sdp.parse_error(m_lexer.get_position(), + m_lexer.get_token_string(), + parse_error::create(101, m_lexer.get_position(), + exception_message(token_type::end_of_input, "value"), BasicJsonType())); + } + + // in case of an error, return discarded value + if (sdp.is_errored()) + { + result = value_t::discarded; + return; + } + + // set top-level value to null if it was discarded by the callback + // function + if (result.is_discarded()) + { + result = nullptr; + } + } + else + { + json_sax_dom_parser sdp(result, allow_exceptions); + sax_parse_internal(&sdp); + + // in strict mode, input must be completely read + if (strict && (get_token() != token_type::end_of_input)) + { + sdp.parse_error(m_lexer.get_position(), + m_lexer.get_token_string(), + parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), BasicJsonType())); + } + + // in case of an error, return discarded value + if (sdp.is_errored()) + { + result = value_t::discarded; + return; + } + } + + result.assert_invariant(); + } + + /*! + @brief public accept interface + + @param[in] strict whether to expect the last token to be EOF + @return whether the input is a proper JSON text + */ + bool accept(const bool strict = true) + { + json_sax_acceptor sax_acceptor; + return sax_parse(&sax_acceptor, strict); + } + + template + JSON_HEDLEY_NON_NULL(2) + bool sax_parse(SAX* sax, const bool strict = true) + { + (void)detail::is_sax_static_asserts {}; + const bool result = sax_parse_internal(sax); + + // strict mode: next byte must be EOF + if (result && strict && (get_token() != token_type::end_of_input)) + { + return sax->parse_error(m_lexer.get_position(), + m_lexer.get_token_string(), + parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_of_input, "value"), BasicJsonType())); + } + + return result; + } + + private: + template + JSON_HEDLEY_NON_NULL(2) + bool sax_parse_internal(SAX* sax) + { + // stack to remember the hierarchy of structured values we are parsing + // true = array; false = object + std::vector states; + // value to avoid a goto (see comment where set to true) + bool skip_to_state_evaluation = false; + + while (true) + { + if (!skip_to_state_evaluation) + { + // invariant: get_token() was called before each iteration + switch (last_token) + { + case token_type::begin_object: + { + if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1)))) + { + return false; + } + + // closing } -> we are done + if (get_token() == token_type::end_object) + { + if (JSON_HEDLEY_UNLIKELY(!sax->end_object())) + { + return false; + } + break; + } + + // parse key + if (JSON_HEDLEY_UNLIKELY(last_token != token_type::value_string)) + { + return sax->parse_error(m_lexer.get_position(), + m_lexer.get_token_string(), + parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), BasicJsonType())); + } + if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) + { + return false; + } + + // parse separator (:) + if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator)) + { + return sax->parse_error(m_lexer.get_position(), + m_lexer.get_token_string(), + parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), BasicJsonType())); + } + + // remember we are now inside an object + states.push_back(false); + + // parse values + get_token(); + continue; + } + + case token_type::begin_array: + { + if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1)))) + { + return false; + } + + // closing ] -> we are done + if (get_token() == token_type::end_array) + { + if (JSON_HEDLEY_UNLIKELY(!sax->end_array())) + { + return false; + } + break; + } + + // remember we are now inside an array + states.push_back(true); + + // parse values (no need to call get_token) + continue; + } + + case token_type::value_float: + { + const auto res = m_lexer.get_number_float(); + + if (JSON_HEDLEY_UNLIKELY(!std::isfinite(res))) + { + return sax->parse_error(m_lexer.get_position(), + m_lexer.get_token_string(), + out_of_range::create(406, "number overflow parsing '" + m_lexer.get_token_string() + "'", BasicJsonType())); + } + + if (JSON_HEDLEY_UNLIKELY(!sax->number_float(res, m_lexer.get_string()))) + { + return false; + } + + break; + } + + case token_type::literal_false: + { + if (JSON_HEDLEY_UNLIKELY(!sax->boolean(false))) + { + return false; + } + break; + } + + case token_type::literal_null: + { + if (JSON_HEDLEY_UNLIKELY(!sax->null())) + { + return false; + } + break; + } + + case token_type::literal_true: + { + if (JSON_HEDLEY_UNLIKELY(!sax->boolean(true))) + { + return false; + } + break; + } + + case token_type::value_integer: + { + if (JSON_HEDLEY_UNLIKELY(!sax->number_integer(m_lexer.get_number_integer()))) + { + return false; + } + break; + } + + case token_type::value_string: + { + if (JSON_HEDLEY_UNLIKELY(!sax->string(m_lexer.get_string()))) + { + return false; + } + break; + } + + case token_type::value_unsigned: + { + if (JSON_HEDLEY_UNLIKELY(!sax->number_unsigned(m_lexer.get_number_unsigned()))) + { + return false; + } + break; + } + + case token_type::parse_error: + { + // using "uninitialized" to avoid "expected" message + return sax->parse_error(m_lexer.get_position(), + m_lexer.get_token_string(), + parse_error::create(101, m_lexer.get_position(), exception_message(token_type::uninitialized, "value"), BasicJsonType())); + } + + case token_type::uninitialized: + case token_type::end_array: + case token_type::end_object: + case token_type::name_separator: + case token_type::value_separator: + case token_type::end_of_input: + case token_type::literal_or_value: + default: // the last token was unexpected + { + return sax->parse_error(m_lexer.get_position(), + m_lexer.get_token_string(), + parse_error::create(101, m_lexer.get_position(), exception_message(token_type::literal_or_value, "value"), BasicJsonType())); + } + } + } + else + { + skip_to_state_evaluation = false; + } + + // we reached this line after we successfully parsed a value + if (states.empty()) + { + // empty stack: we reached the end of the hierarchy: done + return true; + } + + if (states.back()) // array + { + // comma -> next value + if (get_token() == token_type::value_separator) + { + // parse a new value + get_token(); + continue; + } + + // closing ] + if (JSON_HEDLEY_LIKELY(last_token == token_type::end_array)) + { + if (JSON_HEDLEY_UNLIKELY(!sax->end_array())) + { + return false; + } + + // We are done with this array. Before we can parse a + // new value, we need to evaluate the new state first. + // By setting skip_to_state_evaluation to false, we + // are effectively jumping to the beginning of this if. + JSON_ASSERT(!states.empty()); + states.pop_back(); + skip_to_state_evaluation = true; + continue; + } + + return sax->parse_error(m_lexer.get_position(), + m_lexer.get_token_string(), + parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_array, "array"), BasicJsonType())); + } + + // states.back() is false -> object + + // comma -> next value + if (get_token() == token_type::value_separator) + { + // parse key + if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::value_string)) + { + return sax->parse_error(m_lexer.get_position(), + m_lexer.get_token_string(), + parse_error::create(101, m_lexer.get_position(), exception_message(token_type::value_string, "object key"), BasicJsonType())); + } + + if (JSON_HEDLEY_UNLIKELY(!sax->key(m_lexer.get_string()))) + { + return false; + } + + // parse separator (:) + if (JSON_HEDLEY_UNLIKELY(get_token() != token_type::name_separator)) + { + return sax->parse_error(m_lexer.get_position(), + m_lexer.get_token_string(), + parse_error::create(101, m_lexer.get_position(), exception_message(token_type::name_separator, "object separator"), BasicJsonType())); + } + + // parse values + get_token(); + continue; + } + + // closing } + if (JSON_HEDLEY_LIKELY(last_token == token_type::end_object)) + { + if (JSON_HEDLEY_UNLIKELY(!sax->end_object())) + { + return false; + } + + // We are done with this object. Before we can parse a + // new value, we need to evaluate the new state first. + // By setting skip_to_state_evaluation to false, we + // are effectively jumping to the beginning of this if. + JSON_ASSERT(!states.empty()); + states.pop_back(); + skip_to_state_evaluation = true; + continue; + } + + return sax->parse_error(m_lexer.get_position(), + m_lexer.get_token_string(), + parse_error::create(101, m_lexer.get_position(), exception_message(token_type::end_object, "object"), BasicJsonType())); + } + } + + /// get next token from lexer + token_type get_token() + { + return last_token = m_lexer.scan(); + } + + std::string exception_message(const token_type expected, const std::string& context) + { + std::string error_msg = "syntax error "; + + if (!context.empty()) + { + error_msg += "while parsing " + context + " "; + } + + error_msg += "- "; + + if (last_token == token_type::parse_error) + { + error_msg += std::string(m_lexer.get_error_message()) + "; last read: '" + + m_lexer.get_token_string() + "'"; + } + else + { + error_msg += "unexpected " + std::string(lexer_t::token_type_name(last_token)); + } + + if (expected != token_type::uninitialized) + { + error_msg += "; expected " + std::string(lexer_t::token_type_name(expected)); + } + + return error_msg; + } + + private: + /// callback function + const parser_callback_t callback = nullptr; + /// the type of the last read token + token_type last_token = token_type::uninitialized; + /// the lexer + lexer_t m_lexer; + /// whether to throw exceptions in case of errors + const bool allow_exceptions = true; +}; + +} // namespace detail +} // namespace nlohmann + +// #include + + +// #include + + +#include // ptrdiff_t +#include // numeric_limits + +// #include + + +namespace nlohmann +{ +namespace detail +{ +/* +@brief an iterator for primitive JSON types + +This class models an iterator for primitive JSON types (boolean, number, +string). It's only purpose is to allow the iterator/const_iterator classes +to "iterate" over primitive values. Internally, the iterator is modeled by +a `difference_type` variable. Value begin_value (`0`) models the begin, +end_value (`1`) models past the end. +*/ +class primitive_iterator_t +{ + private: + using difference_type = std::ptrdiff_t; + static constexpr difference_type begin_value = 0; + static constexpr difference_type end_value = begin_value + 1; + + JSON_PRIVATE_UNLESS_TESTED: + /// iterator as signed integer type + difference_type m_it = (std::numeric_limits::min)(); + + public: + constexpr difference_type get_value() const noexcept + { + return m_it; + } + + /// set iterator to a defined beginning + void set_begin() noexcept + { + m_it = begin_value; + } + + /// set iterator to a defined past the end + void set_end() noexcept + { + m_it = end_value; + } + + /// return whether the iterator can be dereferenced + constexpr bool is_begin() const noexcept + { + return m_it == begin_value; + } + + /// return whether the iterator is at end + constexpr bool is_end() const noexcept + { + return m_it == end_value; + } + + friend constexpr bool operator==(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept + { + return lhs.m_it == rhs.m_it; + } + + friend constexpr bool operator<(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept + { + return lhs.m_it < rhs.m_it; + } + + primitive_iterator_t operator+(difference_type n) noexcept + { + auto result = *this; + result += n; + return result; + } + + friend constexpr difference_type operator-(primitive_iterator_t lhs, primitive_iterator_t rhs) noexcept + { + return lhs.m_it - rhs.m_it; + } + + primitive_iterator_t& operator++() noexcept + { + ++m_it; + return *this; + } + + primitive_iterator_t const operator++(int) noexcept // NOLINT(readability-const-return-type) + { + auto result = *this; + ++m_it; + return result; + } + + primitive_iterator_t& operator--() noexcept + { + --m_it; + return *this; + } + + primitive_iterator_t const operator--(int) noexcept // NOLINT(readability-const-return-type) + { + auto result = *this; + --m_it; + return result; + } + + primitive_iterator_t& operator+=(difference_type n) noexcept + { + m_it += n; + return *this; + } + + primitive_iterator_t& operator-=(difference_type n) noexcept + { + m_it -= n; + return *this; + } +}; +} // namespace detail +} // namespace nlohmann + + +namespace nlohmann +{ +namespace detail +{ +/*! +@brief an iterator value + +@note This structure could easily be a union, but MSVC currently does not allow +unions members with complex constructors, see https://github.com/nlohmann/json/pull/105. +*/ +template struct internal_iterator +{ + /// iterator for JSON objects + typename BasicJsonType::object_t::iterator object_iterator {}; + /// iterator for JSON arrays + typename BasicJsonType::array_t::iterator array_iterator {}; + /// generic iterator for all other types + primitive_iterator_t primitive_iterator {}; +}; +} // namespace detail +} // namespace nlohmann + +// #include + + +#include // iterator, random_access_iterator_tag, bidirectional_iterator_tag, advance, next +#include // conditional, is_const, remove_const + +// #include + +// #include + +// #include + +// #include + +// #include + +// #include + +// #include + + +namespace nlohmann +{ +namespace detail +{ +// forward declare, to be able to friend it later on +template class iteration_proxy; +template class iteration_proxy_value; + +/*! +@brief a template for a bidirectional iterator for the @ref basic_json class +This class implements a both iterators (iterator and const_iterator) for the +@ref basic_json class. +@note An iterator is called *initialized* when a pointer to a JSON value has + been set (e.g., by a constructor or a copy assignment). If the iterator is + default-constructed, it is *uninitialized* and most methods are undefined. + **The library uses assertions to detect calls on uninitialized iterators.** +@requirement The class satisfies the following concept requirements: +- +[BidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator): + The iterator that can be moved can be moved in both directions (i.e. + incremented and decremented). +@since version 1.0.0, simplified in version 2.0.9, change to bidirectional + iterators in version 3.0.0 (see https://github.com/nlohmann/json/issues/593) +*/ +template +class iter_impl +{ + /// the iterator with BasicJsonType of different const-ness + using other_iter_impl = iter_impl::value, typename std::remove_const::type, const BasicJsonType>::type>; + /// allow basic_json to access private members + friend other_iter_impl; + friend BasicJsonType; + friend iteration_proxy; + friend iteration_proxy_value; + + using object_t = typename BasicJsonType::object_t; + using array_t = typename BasicJsonType::array_t; + // make sure BasicJsonType is basic_json or const basic_json + static_assert(is_basic_json::type>::value, + "iter_impl only accepts (const) basic_json"); + + public: + + /// The std::iterator class template (used as a base class to provide typedefs) is deprecated in C++17. + /// The C++ Standard has never required user-defined iterators to derive from std::iterator. + /// A user-defined iterator should provide publicly accessible typedefs named + /// iterator_category, value_type, difference_type, pointer, and reference. + /// Note that value_type is required to be non-const, even for constant iterators. + using iterator_category = std::bidirectional_iterator_tag; + + /// the type of the values when the iterator is dereferenced + using value_type = typename BasicJsonType::value_type; + /// a type to represent differences between iterators + using difference_type = typename BasicJsonType::difference_type; + /// defines a pointer to the type iterated over (value_type) + using pointer = typename std::conditional::value, + typename BasicJsonType::const_pointer, + typename BasicJsonType::pointer>::type; + /// defines a reference to the type iterated over (value_type) + using reference = + typename std::conditional::value, + typename BasicJsonType::const_reference, + typename BasicJsonType::reference>::type; + + iter_impl() = default; + ~iter_impl() = default; + iter_impl(iter_impl&&) noexcept = default; + iter_impl& operator=(iter_impl&&) noexcept = default; + + /*! + @brief constructor for a given JSON instance + @param[in] object pointer to a JSON object for this iterator + @pre object != nullptr + @post The iterator is initialized; i.e. `m_object != nullptr`. + */ + explicit iter_impl(pointer object) noexcept : m_object(object) + { + JSON_ASSERT(m_object != nullptr); + + switch (m_object->m_type) + { + case value_t::object: + { + m_it.object_iterator = typename object_t::iterator(); + break; + } + + case value_t::array: + { + m_it.array_iterator = typename array_t::iterator(); + break; + } + + case value_t::null: + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + { + m_it.primitive_iterator = primitive_iterator_t(); + break; + } + } + } + + /*! + @note The conventional copy constructor and copy assignment are implicitly + defined. Combined with the following converting constructor and + assignment, they support: (1) copy from iterator to iterator, (2) + copy from const iterator to const iterator, and (3) conversion from + iterator to const iterator. However conversion from const iterator + to iterator is not defined. + */ + + /*! + @brief const copy constructor + @param[in] other const iterator to copy from + @note This copy constructor had to be defined explicitly to circumvent a bug + occurring on msvc v19.0 compiler (VS 2015) debug build. For more + information refer to: https://github.com/nlohmann/json/issues/1608 + */ + iter_impl(const iter_impl& other) noexcept + : m_object(other.m_object), m_it(other.m_it) + {} + + /*! + @brief converting assignment + @param[in] other const iterator to copy from + @return const/non-const iterator + @note It is not checked whether @a other is initialized. + */ + iter_impl& operator=(const iter_impl& other) noexcept + { + if (&other != this) + { + m_object = other.m_object; + m_it = other.m_it; + } + return *this; + } + + /*! + @brief converting constructor + @param[in] other non-const iterator to copy from + @note It is not checked whether @a other is initialized. + */ + iter_impl(const iter_impl::type>& other) noexcept + : m_object(other.m_object), m_it(other.m_it) + {} + + /*! + @brief converting assignment + @param[in] other non-const iterator to copy from + @return const/non-const iterator + @note It is not checked whether @a other is initialized. + */ + iter_impl& operator=(const iter_impl::type>& other) noexcept // NOLINT(cert-oop54-cpp) + { + m_object = other.m_object; + m_it = other.m_it; + return *this; + } + + JSON_PRIVATE_UNLESS_TESTED: + /*! + @brief set the iterator to the first value + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + void set_begin() noexcept + { + JSON_ASSERT(m_object != nullptr); + + switch (m_object->m_type) + { + case value_t::object: + { + m_it.object_iterator = m_object->m_value.object->begin(); + break; + } + + case value_t::array: + { + m_it.array_iterator = m_object->m_value.array->begin(); + break; + } + + case value_t::null: + { + // set to end so begin()==end() is true: null is empty + m_it.primitive_iterator.set_end(); + break; + } + + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + { + m_it.primitive_iterator.set_begin(); + break; + } + } + } + + /*! + @brief set the iterator past the last value + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + void set_end() noexcept + { + JSON_ASSERT(m_object != nullptr); + + switch (m_object->m_type) + { + case value_t::object: + { + m_it.object_iterator = m_object->m_value.object->end(); + break; + } + + case value_t::array: + { + m_it.array_iterator = m_object->m_value.array->end(); + break; + } + + case value_t::null: + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + { + m_it.primitive_iterator.set_end(); + break; + } + } + } + + public: + /*! + @brief return a reference to the value pointed to by the iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + reference operator*() const + { + JSON_ASSERT(m_object != nullptr); + + switch (m_object->m_type) + { + case value_t::object: + { + JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end()); + return m_it.object_iterator->second; + } + + case value_t::array: + { + JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end()); + return *m_it.array_iterator; + } + + case value_t::null: + JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object)); + + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + { + if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin())) + { + return *m_object; + } + + JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object)); + } + } + } + + /*! + @brief dereference the iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + pointer operator->() const + { + JSON_ASSERT(m_object != nullptr); + + switch (m_object->m_type) + { + case value_t::object: + { + JSON_ASSERT(m_it.object_iterator != m_object->m_value.object->end()); + return &(m_it.object_iterator->second); + } + + case value_t::array: + { + JSON_ASSERT(m_it.array_iterator != m_object->m_value.array->end()); + return &*m_it.array_iterator; + } + + case value_t::null: + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + { + if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.is_begin())) + { + return m_object; + } + + JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object)); + } + } + } + + /*! + @brief post-increment (it++) + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + iter_impl const operator++(int) // NOLINT(readability-const-return-type) + { + auto result = *this; + ++(*this); + return result; + } + + /*! + @brief pre-increment (++it) + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + iter_impl& operator++() + { + JSON_ASSERT(m_object != nullptr); + + switch (m_object->m_type) + { + case value_t::object: + { + std::advance(m_it.object_iterator, 1); + break; + } + + case value_t::array: + { + std::advance(m_it.array_iterator, 1); + break; + } + + case value_t::null: + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + { + ++m_it.primitive_iterator; + break; + } + } + + return *this; + } + + /*! + @brief post-decrement (it--) + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + iter_impl const operator--(int) // NOLINT(readability-const-return-type) + { + auto result = *this; + --(*this); + return result; + } + + /*! + @brief pre-decrement (--it) + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + iter_impl& operator--() + { + JSON_ASSERT(m_object != nullptr); + + switch (m_object->m_type) + { + case value_t::object: + { + std::advance(m_it.object_iterator, -1); + break; + } + + case value_t::array: + { + std::advance(m_it.array_iterator, -1); + break; + } + + case value_t::null: + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + { + --m_it.primitive_iterator; + break; + } + } + + return *this; + } + + /*! + @brief comparison: equal + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + template < typename IterImpl, detail::enable_if_t < (std::is_same::value || std::is_same::value), std::nullptr_t > = nullptr > + bool operator==(const IterImpl& other) const + { + // if objects are not the same, the comparison is undefined + if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object)) + { + JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", *m_object)); + } + + JSON_ASSERT(m_object != nullptr); + + switch (m_object->m_type) + { + case value_t::object: + return (m_it.object_iterator == other.m_it.object_iterator); + + case value_t::array: + return (m_it.array_iterator == other.m_it.array_iterator); + + case value_t::null: + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + return (m_it.primitive_iterator == other.m_it.primitive_iterator); + } + } + + /*! + @brief comparison: not equal + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + template < typename IterImpl, detail::enable_if_t < (std::is_same::value || std::is_same::value), std::nullptr_t > = nullptr > + bool operator!=(const IterImpl& other) const + { + return !operator==(other); + } + + /*! + @brief comparison: smaller + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + bool operator<(const iter_impl& other) const + { + // if objects are not the same, the comparison is undefined + if (JSON_HEDLEY_UNLIKELY(m_object != other.m_object)) + { + JSON_THROW(invalid_iterator::create(212, "cannot compare iterators of different containers", *m_object)); + } + + JSON_ASSERT(m_object != nullptr); + + switch (m_object->m_type) + { + case value_t::object: + JSON_THROW(invalid_iterator::create(213, "cannot compare order of object iterators", *m_object)); + + case value_t::array: + return (m_it.array_iterator < other.m_it.array_iterator); + + case value_t::null: + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + return (m_it.primitive_iterator < other.m_it.primitive_iterator); + } + } + + /*! + @brief comparison: less than or equal + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + bool operator<=(const iter_impl& other) const + { + return !other.operator < (*this); + } + + /*! + @brief comparison: greater than + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + bool operator>(const iter_impl& other) const + { + return !operator<=(other); + } + + /*! + @brief comparison: greater than or equal + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + bool operator>=(const iter_impl& other) const + { + return !operator<(other); + } + + /*! + @brief add to iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + iter_impl& operator+=(difference_type i) + { + JSON_ASSERT(m_object != nullptr); + + switch (m_object->m_type) + { + case value_t::object: + JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", *m_object)); + + case value_t::array: + { + std::advance(m_it.array_iterator, i); + break; + } + + case value_t::null: + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + { + m_it.primitive_iterator += i; + break; + } + } + + return *this; + } + + /*! + @brief subtract from iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + iter_impl& operator-=(difference_type i) + { + return operator+=(-i); + } + + /*! + @brief add to iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + iter_impl operator+(difference_type i) const + { + auto result = *this; + result += i; + return result; + } + + /*! + @brief addition of distance and iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + friend iter_impl operator+(difference_type i, const iter_impl& it) + { + auto result = it; + result += i; + return result; + } + + /*! + @brief subtract from iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + iter_impl operator-(difference_type i) const + { + auto result = *this; + result -= i; + return result; + } + + /*! + @brief return difference + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + difference_type operator-(const iter_impl& other) const + { + JSON_ASSERT(m_object != nullptr); + + switch (m_object->m_type) + { + case value_t::object: + JSON_THROW(invalid_iterator::create(209, "cannot use offsets with object iterators", *m_object)); + + case value_t::array: + return m_it.array_iterator - other.m_it.array_iterator; + + case value_t::null: + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + return m_it.primitive_iterator - other.m_it.primitive_iterator; + } + } + + /*! + @brief access to successor + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + reference operator[](difference_type n) const + { + JSON_ASSERT(m_object != nullptr); + + switch (m_object->m_type) + { + case value_t::object: + JSON_THROW(invalid_iterator::create(208, "cannot use operator[] for object iterators", *m_object)); + + case value_t::array: + return *std::next(m_it.array_iterator, n); + + case value_t::null: + JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object)); + + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + { + if (JSON_HEDLEY_LIKELY(m_it.primitive_iterator.get_value() == -n)) + { + return *m_object; + } + + JSON_THROW(invalid_iterator::create(214, "cannot get value", *m_object)); + } + } + } + + /*! + @brief return the key of an object iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + const typename object_t::key_type& key() const + { + JSON_ASSERT(m_object != nullptr); + + if (JSON_HEDLEY_LIKELY(m_object->is_object())) + { + return m_it.object_iterator->first; + } + + JSON_THROW(invalid_iterator::create(207, "cannot use key() for non-object iterators", *m_object)); + } + + /*! + @brief return the value of an iterator + @pre The iterator is initialized; i.e. `m_object != nullptr`. + */ + reference value() const + { + return operator*(); + } + + JSON_PRIVATE_UNLESS_TESTED: + /// associated JSON instance + pointer m_object = nullptr; + /// the actual iterator of the associated instance + internal_iterator::type> m_it {}; +}; +} // namespace detail +} // namespace nlohmann + +// #include + +// #include + + +#include // ptrdiff_t +#include // reverse_iterator +#include // declval + +namespace nlohmann +{ +namespace detail +{ +////////////////////// +// reverse_iterator // +////////////////////// + +/*! +@brief a template for a reverse iterator class + +@tparam Base the base iterator type to reverse. Valid types are @ref +iterator (to create @ref reverse_iterator) and @ref const_iterator (to +create @ref const_reverse_iterator). + +@requirement The class satisfies the following concept requirements: +- +[BidirectionalIterator](https://en.cppreference.com/w/cpp/named_req/BidirectionalIterator): + The iterator that can be moved can be moved in both directions (i.e. + incremented and decremented). +- [OutputIterator](https://en.cppreference.com/w/cpp/named_req/OutputIterator): + It is possible to write to the pointed-to element (only if @a Base is + @ref iterator). + +@since version 1.0.0 +*/ +template +class json_reverse_iterator : public std::reverse_iterator +{ + public: + using difference_type = std::ptrdiff_t; + /// shortcut to the reverse iterator adapter + using base_iterator = std::reverse_iterator; + /// the reference type for the pointed-to element + using reference = typename Base::reference; + + /// create reverse iterator from iterator + explicit json_reverse_iterator(const typename base_iterator::iterator_type& it) noexcept + : base_iterator(it) {} + + /// create reverse iterator from base class + explicit json_reverse_iterator(const base_iterator& it) noexcept : base_iterator(it) {} + + /// post-increment (it++) + json_reverse_iterator const operator++(int) // NOLINT(readability-const-return-type) + { + return static_cast(base_iterator::operator++(1)); + } + + /// pre-increment (++it) + json_reverse_iterator& operator++() + { + return static_cast(base_iterator::operator++()); + } + + /// post-decrement (it--) + json_reverse_iterator const operator--(int) // NOLINT(readability-const-return-type) + { + return static_cast(base_iterator::operator--(1)); + } + + /// pre-decrement (--it) + json_reverse_iterator& operator--() + { + return static_cast(base_iterator::operator--()); + } + + /// add to iterator + json_reverse_iterator& operator+=(difference_type i) + { + return static_cast(base_iterator::operator+=(i)); + } + + /// add to iterator + json_reverse_iterator operator+(difference_type i) const + { + return static_cast(base_iterator::operator+(i)); + } + + /// subtract from iterator + json_reverse_iterator operator-(difference_type i) const + { + return static_cast(base_iterator::operator-(i)); + } + + /// return difference + difference_type operator-(const json_reverse_iterator& other) const + { + return base_iterator(*this) - base_iterator(other); + } + + /// access to successor + reference operator[](difference_type n) const + { + return *(this->operator+(n)); + } + + /// return the key of an object iterator + auto key() const -> decltype(std::declval().key()) + { + auto it = --this->base(); + return it.key(); + } + + /// return the value of an iterator + reference value() const + { + auto it = --this->base(); + return it.operator * (); + } +}; +} // namespace detail +} // namespace nlohmann + +// #include + +// #include + + +#include // all_of +#include // isdigit +#include // max +#include // accumulate +#include // string +#include // move +#include // vector + +// #include + +// #include + +// #include + +// #include + + +namespace nlohmann +{ +template +class json_pointer +{ + // allow basic_json to access private members + NLOHMANN_BASIC_JSON_TPL_DECLARATION + friend class basic_json; + + public: + /*! + @brief create JSON pointer + + Create a JSON pointer according to the syntax described in + [Section 3 of RFC6901](https://tools.ietf.org/html/rfc6901#section-3). + + @param[in] s string representing the JSON pointer; if omitted, the empty + string is assumed which references the whole JSON value + + @throw parse_error.107 if the given JSON pointer @a s is nonempty and does + not begin with a slash (`/`); see example below + + @throw parse_error.108 if a tilde (`~`) in the given JSON pointer @a s is + not followed by `0` (representing `~`) or `1` (representing `/`); see + example below + + @liveexample{The example shows the construction several valid JSON pointers + as well as the exceptional behavior.,json_pointer} + + @since version 2.0.0 + */ + explicit json_pointer(const std::string& s = "") + : reference_tokens(split(s)) + {} + + /*! + @brief return a string representation of the JSON pointer + + @invariant For each JSON pointer `ptr`, it holds: + @code {.cpp} + ptr == json_pointer(ptr.to_string()); + @endcode + + @return a string representation of the JSON pointer + + @liveexample{The example shows the result of `to_string`.,json_pointer__to_string} + + @since version 2.0.0 + */ + std::string to_string() const + { + return std::accumulate(reference_tokens.begin(), reference_tokens.end(), + std::string{}, + [](const std::string & a, const std::string & b) + { + return a + "/" + detail::escape(b); + }); + } + + /// @copydoc to_string() + operator std::string() const + { + return to_string(); + } + + /*! + @brief append another JSON pointer at the end of this JSON pointer + + @param[in] ptr JSON pointer to append + @return JSON pointer with @a ptr appended + + @liveexample{The example shows the usage of `operator/=`.,json_pointer__operator_add} + + @complexity Linear in the length of @a ptr. + + @sa see @ref operator/=(std::string) to append a reference token + @sa see @ref operator/=(std::size_t) to append an array index + @sa see @ref operator/(const json_pointer&, const json_pointer&) for a binary operator + + @since version 3.6.0 + */ + json_pointer& operator/=(const json_pointer& ptr) + { + reference_tokens.insert(reference_tokens.end(), + ptr.reference_tokens.begin(), + ptr.reference_tokens.end()); + return *this; + } + + /*! + @brief append an unescaped reference token at the end of this JSON pointer + + @param[in] token reference token to append + @return JSON pointer with @a token appended without escaping @a token + + @liveexample{The example shows the usage of `operator/=`.,json_pointer__operator_add} + + @complexity Amortized constant. + + @sa see @ref operator/=(const json_pointer&) to append a JSON pointer + @sa see @ref operator/=(std::size_t) to append an array index + @sa see @ref operator/(const json_pointer&, std::size_t) for a binary operator + + @since version 3.6.0 + */ + json_pointer& operator/=(std::string token) + { + push_back(std::move(token)); + return *this; + } + + /*! + @brief append an array index at the end of this JSON pointer + + @param[in] array_idx array index to append + @return JSON pointer with @a array_idx appended + + @liveexample{The example shows the usage of `operator/=`.,json_pointer__operator_add} + + @complexity Amortized constant. + + @sa see @ref operator/=(const json_pointer&) to append a JSON pointer + @sa see @ref operator/=(std::string) to append a reference token + @sa see @ref operator/(const json_pointer&, std::string) for a binary operator + + @since version 3.6.0 + */ + json_pointer& operator/=(std::size_t array_idx) + { + return *this /= std::to_string(array_idx); + } + + /*! + @brief create a new JSON pointer by appending the right JSON pointer at the end of the left JSON pointer + + @param[in] lhs JSON pointer + @param[in] rhs JSON pointer + @return a new JSON pointer with @a rhs appended to @a lhs + + @liveexample{The example shows the usage of `operator/`.,json_pointer__operator_add_binary} + + @complexity Linear in the length of @a lhs and @a rhs. + + @sa see @ref operator/=(const json_pointer&) to append a JSON pointer + + @since version 3.6.0 + */ + friend json_pointer operator/(const json_pointer& lhs, + const json_pointer& rhs) + { + return json_pointer(lhs) /= rhs; + } + + /*! + @brief create a new JSON pointer by appending the unescaped token at the end of the JSON pointer + + @param[in] ptr JSON pointer + @param[in] token reference token + @return a new JSON pointer with unescaped @a token appended to @a ptr + + @liveexample{The example shows the usage of `operator/`.,json_pointer__operator_add_binary} + + @complexity Linear in the length of @a ptr. + + @sa see @ref operator/=(std::string) to append a reference token + + @since version 3.6.0 + */ + friend json_pointer operator/(const json_pointer& ptr, std::string token) // NOLINT(performance-unnecessary-value-param) + { + return json_pointer(ptr) /= std::move(token); + } + + /*! + @brief create a new JSON pointer by appending the array-index-token at the end of the JSON pointer + + @param[in] ptr JSON pointer + @param[in] array_idx array index + @return a new JSON pointer with @a array_idx appended to @a ptr + + @liveexample{The example shows the usage of `operator/`.,json_pointer__operator_add_binary} + + @complexity Linear in the length of @a ptr. + + @sa see @ref operator/=(std::size_t) to append an array index + + @since version 3.6.0 + */ + friend json_pointer operator/(const json_pointer& ptr, std::size_t array_idx) + { + return json_pointer(ptr) /= array_idx; + } + + /*! + @brief returns the parent of this JSON pointer + + @return parent of this JSON pointer; in case this JSON pointer is the root, + the root itself is returned + + @complexity Linear in the length of the JSON pointer. + + @liveexample{The example shows the result of `parent_pointer` for different + JSON Pointers.,json_pointer__parent_pointer} + + @since version 3.6.0 + */ + json_pointer parent_pointer() const + { + if (empty()) + { + return *this; + } + + json_pointer res = *this; + res.pop_back(); + return res; + } + + /*! + @brief remove last reference token + + @pre not `empty()` + + @liveexample{The example shows the usage of `pop_back`.,json_pointer__pop_back} + + @complexity Constant. + + @throw out_of_range.405 if JSON pointer has no parent + + @since version 3.6.0 + */ + void pop_back() + { + if (JSON_HEDLEY_UNLIKELY(empty())) + { + JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType())); + } + + reference_tokens.pop_back(); + } + + /*! + @brief return last reference token + + @pre not `empty()` + @return last reference token + + @liveexample{The example shows the usage of `back`.,json_pointer__back} + + @complexity Constant. + + @throw out_of_range.405 if JSON pointer has no parent + + @since version 3.6.0 + */ + const std::string& back() const + { + if (JSON_HEDLEY_UNLIKELY(empty())) + { + JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType())); + } + + return reference_tokens.back(); + } + + /*! + @brief append an unescaped token at the end of the reference pointer + + @param[in] token token to add + + @complexity Amortized constant. + + @liveexample{The example shows the result of `push_back` for different + JSON Pointers.,json_pointer__push_back} + + @since version 3.6.0 + */ + void push_back(const std::string& token) + { + reference_tokens.push_back(token); + } + + /// @copydoc push_back(const std::string&) + void push_back(std::string&& token) + { + reference_tokens.push_back(std::move(token)); + } + + /*! + @brief return whether pointer points to the root document + + @return true iff the JSON pointer points to the root document + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + + @liveexample{The example shows the result of `empty` for different JSON + Pointers.,json_pointer__empty} + + @since version 3.6.0 + */ + bool empty() const noexcept + { + return reference_tokens.empty(); + } + + private: + /*! + @param[in] s reference token to be converted into an array index + + @return integer representation of @a s + + @throw parse_error.106 if an array index begins with '0' + @throw parse_error.109 if an array index begins not with a digit + @throw out_of_range.404 if string @a s could not be converted to an integer + @throw out_of_range.410 if an array index exceeds size_type + */ + static typename BasicJsonType::size_type array_index(const std::string& s) + { + using size_type = typename BasicJsonType::size_type; + + // error condition (cf. RFC 6901, Sect. 4) + if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && s[0] == '0')) + { + JSON_THROW(detail::parse_error::create(106, 0, "array index '" + s + "' must not begin with '0'", BasicJsonType())); + } + + // error condition (cf. RFC 6901, Sect. 4) + if (JSON_HEDLEY_UNLIKELY(s.size() > 1 && !(s[0] >= '1' && s[0] <= '9'))) + { + JSON_THROW(detail::parse_error::create(109, 0, "array index '" + s + "' is not a number", BasicJsonType())); + } + + std::size_t processed_chars = 0; + unsigned long long res = 0; // NOLINT(runtime/int) + JSON_TRY + { + res = std::stoull(s, &processed_chars); + } + JSON_CATCH(std::out_of_range&) + { + JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", BasicJsonType())); + } + + // check if the string was completely read + if (JSON_HEDLEY_UNLIKELY(processed_chars != s.size())) + { + JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + s + "'", BasicJsonType())); + } + + // only triggered on special platforms (like 32bit), see also + // https://github.com/nlohmann/json/pull/2203 + if (res >= static_cast((std::numeric_limits::max)())) // NOLINT(runtime/int) + { + JSON_THROW(detail::out_of_range::create(410, "array index " + s + " exceeds size_type", BasicJsonType())); // LCOV_EXCL_LINE + } + + return static_cast(res); + } + + JSON_PRIVATE_UNLESS_TESTED: + json_pointer top() const + { + if (JSON_HEDLEY_UNLIKELY(empty())) + { + JSON_THROW(detail::out_of_range::create(405, "JSON pointer has no parent", BasicJsonType())); + } + + json_pointer result = *this; + result.reference_tokens = {reference_tokens[0]}; + return result; + } + + private: + /*! + @brief create and return a reference to the pointed to value + + @complexity Linear in the number of reference tokens. + + @throw parse_error.109 if array index is not a number + @throw type_error.313 if value cannot be unflattened + */ + BasicJsonType& get_and_create(BasicJsonType& j) const + { + auto* result = &j; + + // in case no reference tokens exist, return a reference to the JSON value + // j which will be overwritten by a primitive value + for (const auto& reference_token : reference_tokens) + { + switch (result->type()) + { + case detail::value_t::null: + { + if (reference_token == "0") + { + // start a new array if reference token is 0 + result = &result->operator[](0); + } + else + { + // start a new object otherwise + result = &result->operator[](reference_token); + } + break; + } + + case detail::value_t::object: + { + // create an entry in the object + result = &result->operator[](reference_token); + break; + } + + case detail::value_t::array: + { + // create an entry in the array + result = &result->operator[](array_index(reference_token)); + break; + } + + /* + The following code is only reached if there exists a reference + token _and_ the current value is primitive. In this case, we have + an error situation, because primitive values may only occur as + single value; that is, with an empty list of reference tokens. + */ + case detail::value_t::string: + case detail::value_t::boolean: + case detail::value_t::number_integer: + case detail::value_t::number_unsigned: + case detail::value_t::number_float: + case detail::value_t::binary: + case detail::value_t::discarded: + default: + JSON_THROW(detail::type_error::create(313, "invalid value to unflatten", j)); + } + } + + return *result; + } + + /*! + @brief return a reference to the pointed to value + + @note This version does not throw if a value is not present, but tries to + create nested values instead. For instance, calling this function + with pointer `"/this/that"` on a null value is equivalent to calling + `operator[]("this").operator[]("that")` on that value, effectively + changing the null value to an object. + + @param[in] ptr a JSON value + + @return reference to the JSON value pointed to by the JSON pointer + + @complexity Linear in the length of the JSON pointer. + + @throw parse_error.106 if an array index begins with '0' + @throw parse_error.109 if an array index was not a number + @throw out_of_range.404 if the JSON pointer can not be resolved + */ + BasicJsonType& get_unchecked(BasicJsonType* ptr) const + { + for (const auto& reference_token : reference_tokens) + { + // convert null values to arrays or objects before continuing + if (ptr->is_null()) + { + // check if reference token is a number + const bool nums = + std::all_of(reference_token.begin(), reference_token.end(), + [](const unsigned char x) + { + return std::isdigit(x); + }); + + // change value to array for numbers or "-" or to object otherwise + *ptr = (nums || reference_token == "-") + ? detail::value_t::array + : detail::value_t::object; + } + + switch (ptr->type()) + { + case detail::value_t::object: + { + // use unchecked object access + ptr = &ptr->operator[](reference_token); + break; + } + + case detail::value_t::array: + { + if (reference_token == "-") + { + // explicitly treat "-" as index beyond the end + ptr = &ptr->operator[](ptr->m_value.array->size()); + } + else + { + // convert array index to number; unchecked access + ptr = &ptr->operator[](array_index(reference_token)); + } + break; + } + + case detail::value_t::null: + case detail::value_t::string: + case detail::value_t::boolean: + case detail::value_t::number_integer: + case detail::value_t::number_unsigned: + case detail::value_t::number_float: + case detail::value_t::binary: + case detail::value_t::discarded: + default: + JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr)); + } + } + + return *ptr; + } + + /*! + @throw parse_error.106 if an array index begins with '0' + @throw parse_error.109 if an array index was not a number + @throw out_of_range.402 if the array index '-' is used + @throw out_of_range.404 if the JSON pointer can not be resolved + */ + BasicJsonType& get_checked(BasicJsonType* ptr) const + { + for (const auto& reference_token : reference_tokens) + { + switch (ptr->type()) + { + case detail::value_t::object: + { + // note: at performs range check + ptr = &ptr->at(reference_token); + break; + } + + case detail::value_t::array: + { + if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) + { + // "-" always fails the range check + JSON_THROW(detail::out_of_range::create(402, + "array index '-' (" + std::to_string(ptr->m_value.array->size()) + + ") is out of range", *ptr)); + } + + // note: at performs range check + ptr = &ptr->at(array_index(reference_token)); + break; + } + + case detail::value_t::null: + case detail::value_t::string: + case detail::value_t::boolean: + case detail::value_t::number_integer: + case detail::value_t::number_unsigned: + case detail::value_t::number_float: + case detail::value_t::binary: + case detail::value_t::discarded: + default: + JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr)); + } + } + + return *ptr; + } + + /*! + @brief return a const reference to the pointed to value + + @param[in] ptr a JSON value + + @return const reference to the JSON value pointed to by the JSON + pointer + + @throw parse_error.106 if an array index begins with '0' + @throw parse_error.109 if an array index was not a number + @throw out_of_range.402 if the array index '-' is used + @throw out_of_range.404 if the JSON pointer can not be resolved + */ + const BasicJsonType& get_unchecked(const BasicJsonType* ptr) const + { + for (const auto& reference_token : reference_tokens) + { + switch (ptr->type()) + { + case detail::value_t::object: + { + // use unchecked object access + ptr = &ptr->operator[](reference_token); + break; + } + + case detail::value_t::array: + { + if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) + { + // "-" cannot be used for const access + JSON_THROW(detail::out_of_range::create(402, "array index '-' (" + std::to_string(ptr->m_value.array->size()) + ") is out of range", *ptr)); + } + + // use unchecked array access + ptr = &ptr->operator[](array_index(reference_token)); + break; + } + + case detail::value_t::null: + case detail::value_t::string: + case detail::value_t::boolean: + case detail::value_t::number_integer: + case detail::value_t::number_unsigned: + case detail::value_t::number_float: + case detail::value_t::binary: + case detail::value_t::discarded: + default: + JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr)); + } + } + + return *ptr; + } + + /*! + @throw parse_error.106 if an array index begins with '0' + @throw parse_error.109 if an array index was not a number + @throw out_of_range.402 if the array index '-' is used + @throw out_of_range.404 if the JSON pointer can not be resolved + */ + const BasicJsonType& get_checked(const BasicJsonType* ptr) const + { + for (const auto& reference_token : reference_tokens) + { + switch (ptr->type()) + { + case detail::value_t::object: + { + // note: at performs range check + ptr = &ptr->at(reference_token); + break; + } + + case detail::value_t::array: + { + if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) + { + // "-" always fails the range check + JSON_THROW(detail::out_of_range::create(402, + "array index '-' (" + std::to_string(ptr->m_value.array->size()) + + ") is out of range", *ptr)); + } + + // note: at performs range check + ptr = &ptr->at(array_index(reference_token)); + break; + } + + case detail::value_t::null: + case detail::value_t::string: + case detail::value_t::boolean: + case detail::value_t::number_integer: + case detail::value_t::number_unsigned: + case detail::value_t::number_float: + case detail::value_t::binary: + case detail::value_t::discarded: + default: + JSON_THROW(detail::out_of_range::create(404, "unresolved reference token '" + reference_token + "'", *ptr)); + } + } + + return *ptr; + } + + /*! + @throw parse_error.106 if an array index begins with '0' + @throw parse_error.109 if an array index was not a number + */ + bool contains(const BasicJsonType* ptr) const + { + for (const auto& reference_token : reference_tokens) + { + switch (ptr->type()) + { + case detail::value_t::object: + { + if (!ptr->contains(reference_token)) + { + // we did not find the key in the object + return false; + } + + ptr = &ptr->operator[](reference_token); + break; + } + + case detail::value_t::array: + { + if (JSON_HEDLEY_UNLIKELY(reference_token == "-")) + { + // "-" always fails the range check + return false; + } + if (JSON_HEDLEY_UNLIKELY(reference_token.size() == 1 && !("0" <= reference_token && reference_token <= "9"))) + { + // invalid char + return false; + } + if (JSON_HEDLEY_UNLIKELY(reference_token.size() > 1)) + { + if (JSON_HEDLEY_UNLIKELY(!('1' <= reference_token[0] && reference_token[0] <= '9'))) + { + // first char should be between '1' and '9' + return false; + } + for (std::size_t i = 1; i < reference_token.size(); i++) + { + if (JSON_HEDLEY_UNLIKELY(!('0' <= reference_token[i] && reference_token[i] <= '9'))) + { + // other char should be between '0' and '9' + return false; + } + } + } + + const auto idx = array_index(reference_token); + if (idx >= ptr->size()) + { + // index out of range + return false; + } + + ptr = &ptr->operator[](idx); + break; + } + + case detail::value_t::null: + case detail::value_t::string: + case detail::value_t::boolean: + case detail::value_t::number_integer: + case detail::value_t::number_unsigned: + case detail::value_t::number_float: + case detail::value_t::binary: + case detail::value_t::discarded: + default: + { + // we do not expect primitive values if there is still a + // reference token to process + return false; + } + } + } + + // no reference token left means we found a primitive value + return true; + } + + /*! + @brief split the string input to reference tokens + + @note This function is only called by the json_pointer constructor. + All exceptions below are documented there. + + @throw parse_error.107 if the pointer is not empty or begins with '/' + @throw parse_error.108 if character '~' is not followed by '0' or '1' + */ + static std::vector split(const std::string& reference_string) + { + std::vector result; + + // special case: empty reference string -> no reference tokens + if (reference_string.empty()) + { + return result; + } + + // check if nonempty reference string begins with slash + if (JSON_HEDLEY_UNLIKELY(reference_string[0] != '/')) + { + JSON_THROW(detail::parse_error::create(107, 1, "JSON pointer must be empty or begin with '/' - was: '" + reference_string + "'", BasicJsonType())); + } + + // extract the reference tokens: + // - slash: position of the last read slash (or end of string) + // - start: position after the previous slash + for ( + // search for the first slash after the first character + std::size_t slash = reference_string.find_first_of('/', 1), + // set the beginning of the first reference token + start = 1; + // we can stop if start == 0 (if slash == std::string::npos) + start != 0; + // set the beginning of the next reference token + // (will eventually be 0 if slash == std::string::npos) + start = (slash == std::string::npos) ? 0 : slash + 1, + // find next slash + slash = reference_string.find_first_of('/', start)) + { + // use the text between the beginning of the reference token + // (start) and the last slash (slash). + auto reference_token = reference_string.substr(start, slash - start); + + // check reference tokens are properly escaped + for (std::size_t pos = reference_token.find_first_of('~'); + pos != std::string::npos; + pos = reference_token.find_first_of('~', pos + 1)) + { + JSON_ASSERT(reference_token[pos] == '~'); + + // ~ must be followed by 0 or 1 + if (JSON_HEDLEY_UNLIKELY(pos == reference_token.size() - 1 || + (reference_token[pos + 1] != '0' && + reference_token[pos + 1] != '1'))) + { + JSON_THROW(detail::parse_error::create(108, 0, "escape character '~' must be followed with '0' or '1'", BasicJsonType())); + } + } + + // finally, store the reference token + detail::unescape(reference_token); + result.push_back(reference_token); + } + + return result; + } + + private: + /*! + @param[in] reference_string the reference string to the current value + @param[in] value the value to consider + @param[in,out] result the result object to insert values to + + @note Empty objects or arrays are flattened to `null`. + */ + static void flatten(const std::string& reference_string, + const BasicJsonType& value, + BasicJsonType& result) + { + switch (value.type()) + { + case detail::value_t::array: + { + if (value.m_value.array->empty()) + { + // flatten empty array as null + result[reference_string] = nullptr; + } + else + { + // iterate array and use index as reference string + for (std::size_t i = 0; i < value.m_value.array->size(); ++i) + { + flatten(reference_string + "/" + std::to_string(i), + value.m_value.array->operator[](i), result); + } + } + break; + } + + case detail::value_t::object: + { + if (value.m_value.object->empty()) + { + // flatten empty object as null + result[reference_string] = nullptr; + } + else + { + // iterate object and use keys as reference string + for (const auto& element : *value.m_value.object) + { + flatten(reference_string + "/" + detail::escape(element.first), element.second, result); + } + } + break; + } + + case detail::value_t::null: + case detail::value_t::string: + case detail::value_t::boolean: + case detail::value_t::number_integer: + case detail::value_t::number_unsigned: + case detail::value_t::number_float: + case detail::value_t::binary: + case detail::value_t::discarded: + default: + { + // add primitive value with its reference string + result[reference_string] = value; + break; + } + } + } + + /*! + @param[in] value flattened JSON + + @return unflattened JSON + + @throw parse_error.109 if array index is not a number + @throw type_error.314 if value is not an object + @throw type_error.315 if object values are not primitive + @throw type_error.313 if value cannot be unflattened + */ + static BasicJsonType + unflatten(const BasicJsonType& value) + { + if (JSON_HEDLEY_UNLIKELY(!value.is_object())) + { + JSON_THROW(detail::type_error::create(314, "only objects can be unflattened", value)); + } + + BasicJsonType result; + + // iterate the JSON object values + for (const auto& element : *value.m_value.object) + { + if (JSON_HEDLEY_UNLIKELY(!element.second.is_primitive())) + { + JSON_THROW(detail::type_error::create(315, "values in object must be primitive", element.second)); + } + + // assign value to reference pointed to by JSON pointer; Note that if + // the JSON pointer is "" (i.e., points to the whole value), function + // get_and_create returns a reference to result itself. An assignment + // will then create a primitive value. + json_pointer(element.first).get_and_create(result) = element.second; + } + + return result; + } + + /*! + @brief compares two JSON pointers for equality + + @param[in] lhs JSON pointer to compare + @param[in] rhs JSON pointer to compare + @return whether @a lhs is equal to @a rhs + + @complexity Linear in the length of the JSON pointer + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + */ + friend bool operator==(json_pointer const& lhs, + json_pointer const& rhs) noexcept + { + return lhs.reference_tokens == rhs.reference_tokens; + } + + /*! + @brief compares two JSON pointers for inequality + + @param[in] lhs JSON pointer to compare + @param[in] rhs JSON pointer to compare + @return whether @a lhs is not equal @a rhs + + @complexity Linear in the length of the JSON pointer + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + */ + friend bool operator!=(json_pointer const& lhs, + json_pointer const& rhs) noexcept + { + return !(lhs == rhs); + } + + /// the reference tokens + std::vector reference_tokens; +}; +} // namespace nlohmann + +// #include + + +#include +#include + +// #include + + +namespace nlohmann +{ +namespace detail +{ +template +class json_ref +{ + public: + using value_type = BasicJsonType; + + json_ref(value_type&& value) + : owned_value(std::move(value)) + {} + + json_ref(const value_type& value) + : value_ref(&value) + {} + + json_ref(std::initializer_list init) + : owned_value(init) + {} + + template < + class... Args, + enable_if_t::value, int> = 0 > + json_ref(Args && ... args) + : owned_value(std::forward(args)...) + {} + + // class should be movable only + json_ref(json_ref&&) noexcept = default; + json_ref(const json_ref&) = delete; + json_ref& operator=(const json_ref&) = delete; + json_ref& operator=(json_ref&&) = delete; + ~json_ref() = default; + + value_type moved_or_copied() const + { + if (value_ref == nullptr) + { + return std::move(owned_value); + } + return *value_ref; + } + + value_type const& operator*() const + { + return value_ref ? *value_ref : owned_value; + } + + value_type const* operator->() const + { + return &** this; + } + + private: + mutable value_type owned_value = nullptr; + value_type const* value_ref = nullptr; +}; +} // namespace detail +} // namespace nlohmann + +// #include + +// #include + +// #include + +// #include + +// #include + + +#include // reverse +#include // array +#include // isnan, isinf +#include // uint8_t, uint16_t, uint32_t, uint64_t +#include // memcpy +#include // numeric_limits +#include // string +#include // move + +// #include + +// #include + +// #include + + +#include // copy +#include // size_t +#include // back_inserter +#include // shared_ptr, make_shared +#include // basic_string +#include // vector + +#ifndef JSON_NO_IO + #include // streamsize + #include // basic_ostream +#endif // JSON_NO_IO + +// #include + + +namespace nlohmann +{ +namespace detail +{ +/// abstract output adapter interface +template struct output_adapter_protocol +{ + virtual void write_character(CharType c) = 0; + virtual void write_characters(const CharType* s, std::size_t length) = 0; + virtual ~output_adapter_protocol() = default; + + output_adapter_protocol() = default; + output_adapter_protocol(const output_adapter_protocol&) = default; + output_adapter_protocol(output_adapter_protocol&&) noexcept = default; + output_adapter_protocol& operator=(const output_adapter_protocol&) = default; + output_adapter_protocol& operator=(output_adapter_protocol&&) noexcept = default; +}; + +/// a type to simplify interfaces +template +using output_adapter_t = std::shared_ptr>; + +/// output adapter for byte vectors +template> +class output_vector_adapter : public output_adapter_protocol +{ + public: + explicit output_vector_adapter(std::vector& vec) noexcept + : v(vec) + {} + + void write_character(CharType c) override + { + v.push_back(c); + } + + JSON_HEDLEY_NON_NULL(2) + void write_characters(const CharType* s, std::size_t length) override + { + std::copy(s, s + length, std::back_inserter(v)); + } + + private: + std::vector& v; +}; + +#ifndef JSON_NO_IO +/// output adapter for output streams +template +class output_stream_adapter : public output_adapter_protocol +{ + public: + explicit output_stream_adapter(std::basic_ostream& s) noexcept + : stream(s) + {} + + void write_character(CharType c) override + { + stream.put(c); + } + + JSON_HEDLEY_NON_NULL(2) + void write_characters(const CharType* s, std::size_t length) override + { + stream.write(s, static_cast(length)); + } + + private: + std::basic_ostream& stream; +}; +#endif // JSON_NO_IO + +/// output adapter for basic_string +template> +class output_string_adapter : public output_adapter_protocol +{ + public: + explicit output_string_adapter(StringType& s) noexcept + : str(s) + {} + + void write_character(CharType c) override + { + str.push_back(c); + } + + JSON_HEDLEY_NON_NULL(2) + void write_characters(const CharType* s, std::size_t length) override + { + str.append(s, length); + } + + private: + StringType& str; +}; + +template> +class output_adapter +{ + public: + template> + output_adapter(std::vector& vec) + : oa(std::make_shared>(vec)) {} + +#ifndef JSON_NO_IO + output_adapter(std::basic_ostream& s) + : oa(std::make_shared>(s)) {} +#endif // JSON_NO_IO + + output_adapter(StringType& s) + : oa(std::make_shared>(s)) {} + + operator output_adapter_t() + { + return oa; + } + + private: + output_adapter_t oa = nullptr; +}; +} // namespace detail +} // namespace nlohmann + + +namespace nlohmann +{ +namespace detail +{ +/////////////////// +// binary writer // +/////////////////// + +/*! +@brief serialization to CBOR and MessagePack values +*/ +template +class binary_writer +{ + using string_t = typename BasicJsonType::string_t; + using binary_t = typename BasicJsonType::binary_t; + using number_float_t = typename BasicJsonType::number_float_t; + + public: + /*! + @brief create a binary writer + + @param[in] adapter output adapter to write to + */ + explicit binary_writer(output_adapter_t adapter) : oa(std::move(adapter)) + { + JSON_ASSERT(oa); + } + + /*! + @param[in] j JSON value to serialize + @pre j.type() == value_t::object + */ + void write_bson(const BasicJsonType& j) + { + switch (j.type()) + { + case value_t::object: + { + write_bson_object(*j.m_value.object); + break; + } + + case value_t::null: + case value_t::array: + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + { + JSON_THROW(type_error::create(317, "to serialize to BSON, top-level type must be object, but is " + std::string(j.type_name()), j)); + } + } + } + + /*! + @param[in] j JSON value to serialize + */ + void write_cbor(const BasicJsonType& j) + { + switch (j.type()) + { + case value_t::null: + { + oa->write_character(to_char_type(0xF6)); + break; + } + + case value_t::boolean: + { + oa->write_character(j.m_value.boolean + ? to_char_type(0xF5) + : to_char_type(0xF4)); + break; + } + + case value_t::number_integer: + { + if (j.m_value.number_integer >= 0) + { + // CBOR does not differentiate between positive signed + // integers and unsigned integers. Therefore, we used the + // code from the value_t::number_unsigned case here. + if (j.m_value.number_integer <= 0x17) + { + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x18)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x19)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x1A)); + write_number(static_cast(j.m_value.number_integer)); + } + else + { + oa->write_character(to_char_type(0x1B)); + write_number(static_cast(j.m_value.number_integer)); + } + } + else + { + // The conversions below encode the sign in the first + // byte, and the value is converted to a positive number. + const auto positive_number = -1 - j.m_value.number_integer; + if (j.m_value.number_integer >= -24) + { + write_number(static_cast(0x20 + positive_number)); + } + else if (positive_number <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x38)); + write_number(static_cast(positive_number)); + } + else if (positive_number <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x39)); + write_number(static_cast(positive_number)); + } + else if (positive_number <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x3A)); + write_number(static_cast(positive_number)); + } + else + { + oa->write_character(to_char_type(0x3B)); + write_number(static_cast(positive_number)); + } + } + break; + } + + case value_t::number_unsigned: + { + if (j.m_value.number_unsigned <= 0x17) + { + write_number(static_cast(j.m_value.number_unsigned)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x18)); + write_number(static_cast(j.m_value.number_unsigned)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x19)); + write_number(static_cast(j.m_value.number_unsigned)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x1A)); + write_number(static_cast(j.m_value.number_unsigned)); + } + else + { + oa->write_character(to_char_type(0x1B)); + write_number(static_cast(j.m_value.number_unsigned)); + } + break; + } + + case value_t::number_float: + { + if (std::isnan(j.m_value.number_float)) + { + // NaN is 0xf97e00 in CBOR + oa->write_character(to_char_type(0xF9)); + oa->write_character(to_char_type(0x7E)); + oa->write_character(to_char_type(0x00)); + } + else if (std::isinf(j.m_value.number_float)) + { + // Infinity is 0xf97c00, -Infinity is 0xf9fc00 + oa->write_character(to_char_type(0xf9)); + oa->write_character(j.m_value.number_float > 0 ? to_char_type(0x7C) : to_char_type(0xFC)); + oa->write_character(to_char_type(0x00)); + } + else + { + write_compact_float(j.m_value.number_float, detail::input_format_t::cbor); + } + break; + } + + case value_t::string: + { + // step 1: write control byte and the string length + const auto N = j.m_value.string->size(); + if (N <= 0x17) + { + write_number(static_cast(0x60 + N)); + } + else if (N <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x78)); + write_number(static_cast(N)); + } + else if (N <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x79)); + write_number(static_cast(N)); + } + else if (N <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x7A)); + write_number(static_cast(N)); + } + // LCOV_EXCL_START + else if (N <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x7B)); + write_number(static_cast(N)); + } + // LCOV_EXCL_STOP + + // step 2: write the string + oa->write_characters( + reinterpret_cast(j.m_value.string->c_str()), + j.m_value.string->size()); + break; + } + + case value_t::array: + { + // step 1: write control byte and the array size + const auto N = j.m_value.array->size(); + if (N <= 0x17) + { + write_number(static_cast(0x80 + N)); + } + else if (N <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x98)); + write_number(static_cast(N)); + } + else if (N <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x99)); + write_number(static_cast(N)); + } + else if (N <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x9A)); + write_number(static_cast(N)); + } + // LCOV_EXCL_START + else if (N <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x9B)); + write_number(static_cast(N)); + } + // LCOV_EXCL_STOP + + // step 2: write each element + for (const auto& el : *j.m_value.array) + { + write_cbor(el); + } + break; + } + + case value_t::binary: + { + if (j.m_value.binary->has_subtype()) + { + if (j.m_value.binary->subtype() <= (std::numeric_limits::max)()) + { + write_number(static_cast(0xd8)); + write_number(static_cast(j.m_value.binary->subtype())); + } + else if (j.m_value.binary->subtype() <= (std::numeric_limits::max)()) + { + write_number(static_cast(0xd9)); + write_number(static_cast(j.m_value.binary->subtype())); + } + else if (j.m_value.binary->subtype() <= (std::numeric_limits::max)()) + { + write_number(static_cast(0xda)); + write_number(static_cast(j.m_value.binary->subtype())); + } + else if (j.m_value.binary->subtype() <= (std::numeric_limits::max)()) + { + write_number(static_cast(0xdb)); + write_number(static_cast(j.m_value.binary->subtype())); + } + } + + // step 1: write control byte and the binary array size + const auto N = j.m_value.binary->size(); + if (N <= 0x17) + { + write_number(static_cast(0x40 + N)); + } + else if (N <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x58)); + write_number(static_cast(N)); + } + else if (N <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x59)); + write_number(static_cast(N)); + } + else if (N <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x5A)); + write_number(static_cast(N)); + } + // LCOV_EXCL_START + else if (N <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0x5B)); + write_number(static_cast(N)); + } + // LCOV_EXCL_STOP + + // step 2: write each element + oa->write_characters( + reinterpret_cast(j.m_value.binary->data()), + N); + + break; + } + + case value_t::object: + { + // step 1: write control byte and the object size + const auto N = j.m_value.object->size(); + if (N <= 0x17) + { + write_number(static_cast(0xA0 + N)); + } + else if (N <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0xB8)); + write_number(static_cast(N)); + } + else if (N <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0xB9)); + write_number(static_cast(N)); + } + else if (N <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0xBA)); + write_number(static_cast(N)); + } + // LCOV_EXCL_START + else if (N <= (std::numeric_limits::max)()) + { + oa->write_character(to_char_type(0xBB)); + write_number(static_cast(N)); + } + // LCOV_EXCL_STOP + + // step 2: write each element + for (const auto& el : *j.m_value.object) + { + write_cbor(el.first); + write_cbor(el.second); + } + break; + } + + case value_t::discarded: + default: + break; + } + } + + /*! + @param[in] j JSON value to serialize + */ + void write_msgpack(const BasicJsonType& j) + { + switch (j.type()) + { + case value_t::null: // nil + { + oa->write_character(to_char_type(0xC0)); + break; + } + + case value_t::boolean: // true and false + { + oa->write_character(j.m_value.boolean + ? to_char_type(0xC3) + : to_char_type(0xC2)); + break; + } + + case value_t::number_integer: + { + if (j.m_value.number_integer >= 0) + { + // MessagePack does not differentiate between positive + // signed integers and unsigned integers. Therefore, we used + // the code from the value_t::number_unsigned case here. + if (j.m_value.number_unsigned < 128) + { + // positive fixnum + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + // uint 8 + oa->write_character(to_char_type(0xCC)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + // uint 16 + oa->write_character(to_char_type(0xCD)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + // uint 32 + oa->write_character(to_char_type(0xCE)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + // uint 64 + oa->write_character(to_char_type(0xCF)); + write_number(static_cast(j.m_value.number_integer)); + } + } + else + { + if (j.m_value.number_integer >= -32) + { + // negative fixnum + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer >= (std::numeric_limits::min)() && + j.m_value.number_integer <= (std::numeric_limits::max)()) + { + // int 8 + oa->write_character(to_char_type(0xD0)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer >= (std::numeric_limits::min)() && + j.m_value.number_integer <= (std::numeric_limits::max)()) + { + // int 16 + oa->write_character(to_char_type(0xD1)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer >= (std::numeric_limits::min)() && + j.m_value.number_integer <= (std::numeric_limits::max)()) + { + // int 32 + oa->write_character(to_char_type(0xD2)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_integer >= (std::numeric_limits::min)() && + j.m_value.number_integer <= (std::numeric_limits::max)()) + { + // int 64 + oa->write_character(to_char_type(0xD3)); + write_number(static_cast(j.m_value.number_integer)); + } + } + break; + } + + case value_t::number_unsigned: + { + if (j.m_value.number_unsigned < 128) + { + // positive fixnum + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + // uint 8 + oa->write_character(to_char_type(0xCC)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + // uint 16 + oa->write_character(to_char_type(0xCD)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + // uint 32 + oa->write_character(to_char_type(0xCE)); + write_number(static_cast(j.m_value.number_integer)); + } + else if (j.m_value.number_unsigned <= (std::numeric_limits::max)()) + { + // uint 64 + oa->write_character(to_char_type(0xCF)); + write_number(static_cast(j.m_value.number_integer)); + } + break; + } + + case value_t::number_float: + { + write_compact_float(j.m_value.number_float, detail::input_format_t::msgpack); + break; + } + + case value_t::string: + { + // step 1: write control byte and the string length + const auto N = j.m_value.string->size(); + if (N <= 31) + { + // fixstr + write_number(static_cast(0xA0 | N)); + } + else if (N <= (std::numeric_limits::max)()) + { + // str 8 + oa->write_character(to_char_type(0xD9)); + write_number(static_cast(N)); + } + else if (N <= (std::numeric_limits::max)()) + { + // str 16 + oa->write_character(to_char_type(0xDA)); + write_number(static_cast(N)); + } + else if (N <= (std::numeric_limits::max)()) + { + // str 32 + oa->write_character(to_char_type(0xDB)); + write_number(static_cast(N)); + } + + // step 2: write the string + oa->write_characters( + reinterpret_cast(j.m_value.string->c_str()), + j.m_value.string->size()); + break; + } + + case value_t::array: + { + // step 1: write control byte and the array size + const auto N = j.m_value.array->size(); + if (N <= 15) + { + // fixarray + write_number(static_cast(0x90 | N)); + } + else if (N <= (std::numeric_limits::max)()) + { + // array 16 + oa->write_character(to_char_type(0xDC)); + write_number(static_cast(N)); + } + else if (N <= (std::numeric_limits::max)()) + { + // array 32 + oa->write_character(to_char_type(0xDD)); + write_number(static_cast(N)); + } + + // step 2: write each element + for (const auto& el : *j.m_value.array) + { + write_msgpack(el); + } + break; + } + + case value_t::binary: + { + // step 0: determine if the binary type has a set subtype to + // determine whether or not to use the ext or fixext types + const bool use_ext = j.m_value.binary->has_subtype(); + + // step 1: write control byte and the byte string length + const auto N = j.m_value.binary->size(); + if (N <= (std::numeric_limits::max)()) + { + std::uint8_t output_type{}; + bool fixed = true; + if (use_ext) + { + switch (N) + { + case 1: + output_type = 0xD4; // fixext 1 + break; + case 2: + output_type = 0xD5; // fixext 2 + break; + case 4: + output_type = 0xD6; // fixext 4 + break; + case 8: + output_type = 0xD7; // fixext 8 + break; + case 16: + output_type = 0xD8; // fixext 16 + break; + default: + output_type = 0xC7; // ext 8 + fixed = false; + break; + } + + } + else + { + output_type = 0xC4; // bin 8 + fixed = false; + } + + oa->write_character(to_char_type(output_type)); + if (!fixed) + { + write_number(static_cast(N)); + } + } + else if (N <= (std::numeric_limits::max)()) + { + std::uint8_t output_type = use_ext + ? 0xC8 // ext 16 + : 0xC5; // bin 16 + + oa->write_character(to_char_type(output_type)); + write_number(static_cast(N)); + } + else if (N <= (std::numeric_limits::max)()) + { + std::uint8_t output_type = use_ext + ? 0xC9 // ext 32 + : 0xC6; // bin 32 + + oa->write_character(to_char_type(output_type)); + write_number(static_cast(N)); + } + + // step 1.5: if this is an ext type, write the subtype + if (use_ext) + { + write_number(static_cast(j.m_value.binary->subtype())); + } + + // step 2: write the byte string + oa->write_characters( + reinterpret_cast(j.m_value.binary->data()), + N); + + break; + } + + case value_t::object: + { + // step 1: write control byte and the object size + const auto N = j.m_value.object->size(); + if (N <= 15) + { + // fixmap + write_number(static_cast(0x80 | (N & 0xF))); + } + else if (N <= (std::numeric_limits::max)()) + { + // map 16 + oa->write_character(to_char_type(0xDE)); + write_number(static_cast(N)); + } + else if (N <= (std::numeric_limits::max)()) + { + // map 32 + oa->write_character(to_char_type(0xDF)); + write_number(static_cast(N)); + } + + // step 2: write each element + for (const auto& el : *j.m_value.object) + { + write_msgpack(el.first); + write_msgpack(el.second); + } + break; + } + + case value_t::discarded: + default: + break; + } + } + + /*! + @param[in] j JSON value to serialize + @param[in] use_count whether to use '#' prefixes (optimized format) + @param[in] use_type whether to use '$' prefixes (optimized format) + @param[in] add_prefix whether prefixes need to be used for this value + */ + void write_ubjson(const BasicJsonType& j, const bool use_count, + const bool use_type, const bool add_prefix = true) + { + switch (j.type()) + { + case value_t::null: + { + if (add_prefix) + { + oa->write_character(to_char_type('Z')); + } + break; + } + + case value_t::boolean: + { + if (add_prefix) + { + oa->write_character(j.m_value.boolean + ? to_char_type('T') + : to_char_type('F')); + } + break; + } + + case value_t::number_integer: + { + write_number_with_ubjson_prefix(j.m_value.number_integer, add_prefix); + break; + } + + case value_t::number_unsigned: + { + write_number_with_ubjson_prefix(j.m_value.number_unsigned, add_prefix); + break; + } + + case value_t::number_float: + { + write_number_with_ubjson_prefix(j.m_value.number_float, add_prefix); + break; + } + + case value_t::string: + { + if (add_prefix) + { + oa->write_character(to_char_type('S')); + } + write_number_with_ubjson_prefix(j.m_value.string->size(), true); + oa->write_characters( + reinterpret_cast(j.m_value.string->c_str()), + j.m_value.string->size()); + break; + } + + case value_t::array: + { + if (add_prefix) + { + oa->write_character(to_char_type('[')); + } + + bool prefix_required = true; + if (use_type && !j.m_value.array->empty()) + { + JSON_ASSERT(use_count); + const CharType first_prefix = ubjson_prefix(j.front()); + const bool same_prefix = std::all_of(j.begin() + 1, j.end(), + [this, first_prefix](const BasicJsonType & v) + { + return ubjson_prefix(v) == first_prefix; + }); + + if (same_prefix) + { + prefix_required = false; + oa->write_character(to_char_type('$')); + oa->write_character(first_prefix); + } + } + + if (use_count) + { + oa->write_character(to_char_type('#')); + write_number_with_ubjson_prefix(j.m_value.array->size(), true); + } + + for (const auto& el : *j.m_value.array) + { + write_ubjson(el, use_count, use_type, prefix_required); + } + + if (!use_count) + { + oa->write_character(to_char_type(']')); + } + + break; + } + + case value_t::binary: + { + if (add_prefix) + { + oa->write_character(to_char_type('[')); + } + + if (use_type && !j.m_value.binary->empty()) + { + JSON_ASSERT(use_count); + oa->write_character(to_char_type('$')); + oa->write_character('U'); + } + + if (use_count) + { + oa->write_character(to_char_type('#')); + write_number_with_ubjson_prefix(j.m_value.binary->size(), true); + } + + if (use_type) + { + oa->write_characters( + reinterpret_cast(j.m_value.binary->data()), + j.m_value.binary->size()); + } + else + { + for (size_t i = 0; i < j.m_value.binary->size(); ++i) + { + oa->write_character(to_char_type('U')); + oa->write_character(j.m_value.binary->data()[i]); + } + } + + if (!use_count) + { + oa->write_character(to_char_type(']')); + } + + break; + } + + case value_t::object: + { + if (add_prefix) + { + oa->write_character(to_char_type('{')); + } + + bool prefix_required = true; + if (use_type && !j.m_value.object->empty()) + { + JSON_ASSERT(use_count); + const CharType first_prefix = ubjson_prefix(j.front()); + const bool same_prefix = std::all_of(j.begin(), j.end(), + [this, first_prefix](const BasicJsonType & v) + { + return ubjson_prefix(v) == first_prefix; + }); + + if (same_prefix) + { + prefix_required = false; + oa->write_character(to_char_type('$')); + oa->write_character(first_prefix); + } + } + + if (use_count) + { + oa->write_character(to_char_type('#')); + write_number_with_ubjson_prefix(j.m_value.object->size(), true); + } + + for (const auto& el : *j.m_value.object) + { + write_number_with_ubjson_prefix(el.first.size(), true); + oa->write_characters( + reinterpret_cast(el.first.c_str()), + el.first.size()); + write_ubjson(el.second, use_count, use_type, prefix_required); + } + + if (!use_count) + { + oa->write_character(to_char_type('}')); + } + + break; + } + + case value_t::discarded: + default: + break; + } + } + + private: + ////////// + // BSON // + ////////// + + /*! + @return The size of a BSON document entry header, including the id marker + and the entry name size (and its null-terminator). + */ + static std::size_t calc_bson_entry_header_size(const string_t& name, const BasicJsonType& j) + { + const auto it = name.find(static_cast(0)); + if (JSON_HEDLEY_UNLIKELY(it != BasicJsonType::string_t::npos)) + { + JSON_THROW(out_of_range::create(409, "BSON key cannot contain code point U+0000 (at byte " + std::to_string(it) + ")", j)); + static_cast(j); + } + + return /*id*/ 1ul + name.size() + /*zero-terminator*/1u; + } + + /*! + @brief Writes the given @a element_type and @a name to the output adapter + */ + void write_bson_entry_header(const string_t& name, + const std::uint8_t element_type) + { + oa->write_character(to_char_type(element_type)); // boolean + oa->write_characters( + reinterpret_cast(name.c_str()), + name.size() + 1u); + } + + /*! + @brief Writes a BSON element with key @a name and boolean value @a value + */ + void write_bson_boolean(const string_t& name, + const bool value) + { + write_bson_entry_header(name, 0x08); + oa->write_character(value ? to_char_type(0x01) : to_char_type(0x00)); + } + + /*! + @brief Writes a BSON element with key @a name and double value @a value + */ + void write_bson_double(const string_t& name, + const double value) + { + write_bson_entry_header(name, 0x01); + write_number(value); + } + + /*! + @return The size of the BSON-encoded string in @a value + */ + static std::size_t calc_bson_string_size(const string_t& value) + { + return sizeof(std::int32_t) + value.size() + 1ul; + } + + /*! + @brief Writes a BSON element with key @a name and string value @a value + */ + void write_bson_string(const string_t& name, + const string_t& value) + { + write_bson_entry_header(name, 0x02); + + write_number(static_cast(value.size() + 1ul)); + oa->write_characters( + reinterpret_cast(value.c_str()), + value.size() + 1); + } + + /*! + @brief Writes a BSON element with key @a name and null value + */ + void write_bson_null(const string_t& name) + { + write_bson_entry_header(name, 0x0A); + } + + /*! + @return The size of the BSON-encoded integer @a value + */ + static std::size_t calc_bson_integer_size(const std::int64_t value) + { + return (std::numeric_limits::min)() <= value && value <= (std::numeric_limits::max)() + ? sizeof(std::int32_t) + : sizeof(std::int64_t); + } + + /*! + @brief Writes a BSON element with key @a name and integer @a value + */ + void write_bson_integer(const string_t& name, + const std::int64_t value) + { + if ((std::numeric_limits::min)() <= value && value <= (std::numeric_limits::max)()) + { + write_bson_entry_header(name, 0x10); // int32 + write_number(static_cast(value)); + } + else + { + write_bson_entry_header(name, 0x12); // int64 + write_number(static_cast(value)); + } + } + + /*! + @return The size of the BSON-encoded unsigned integer in @a j + */ + static constexpr std::size_t calc_bson_unsigned_size(const std::uint64_t value) noexcept + { + return (value <= static_cast((std::numeric_limits::max)())) + ? sizeof(std::int32_t) + : sizeof(std::int64_t); + } + + /*! + @brief Writes a BSON element with key @a name and unsigned @a value + */ + void write_bson_unsigned(const string_t& name, + const BasicJsonType& j) + { + if (j.m_value.number_unsigned <= static_cast((std::numeric_limits::max)())) + { + write_bson_entry_header(name, 0x10 /* int32 */); + write_number(static_cast(j.m_value.number_unsigned)); + } + else if (j.m_value.number_unsigned <= static_cast((std::numeric_limits::max)())) + { + write_bson_entry_header(name, 0x12 /* int64 */); + write_number(static_cast(j.m_value.number_unsigned)); + } + else + { + JSON_THROW(out_of_range::create(407, "integer number " + std::to_string(j.m_value.number_unsigned) + " cannot be represented by BSON as it does not fit int64", j)); + } + } + + /*! + @brief Writes a BSON element with key @a name and object @a value + */ + void write_bson_object_entry(const string_t& name, + const typename BasicJsonType::object_t& value) + { + write_bson_entry_header(name, 0x03); // object + write_bson_object(value); + } + + /*! + @return The size of the BSON-encoded array @a value + */ + static std::size_t calc_bson_array_size(const typename BasicJsonType::array_t& value) + { + std::size_t array_index = 0ul; + + const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), std::size_t(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type & el) + { + return result + calc_bson_element_size(std::to_string(array_index++), el); + }); + + return sizeof(std::int32_t) + embedded_document_size + 1ul; + } + + /*! + @return The size of the BSON-encoded binary array @a value + */ + static std::size_t calc_bson_binary_size(const typename BasicJsonType::binary_t& value) + { + return sizeof(std::int32_t) + value.size() + 1ul; + } + + /*! + @brief Writes a BSON element with key @a name and array @a value + */ + void write_bson_array(const string_t& name, + const typename BasicJsonType::array_t& value) + { + write_bson_entry_header(name, 0x04); // array + write_number(static_cast(calc_bson_array_size(value))); + + std::size_t array_index = 0ul; + + for (const auto& el : value) + { + write_bson_element(std::to_string(array_index++), el); + } + + oa->write_character(to_char_type(0x00)); + } + + /*! + @brief Writes a BSON element with key @a name and binary value @a value + */ + void write_bson_binary(const string_t& name, + const binary_t& value) + { + write_bson_entry_header(name, 0x05); + + write_number(static_cast(value.size())); + write_number(value.has_subtype() ? static_cast(value.subtype()) : std::uint8_t(0x00)); + + oa->write_characters(reinterpret_cast(value.data()), value.size()); + } + + /*! + @brief Calculates the size necessary to serialize the JSON value @a j with its @a name + @return The calculated size for the BSON document entry for @a j with the given @a name. + */ + static std::size_t calc_bson_element_size(const string_t& name, + const BasicJsonType& j) + { + const auto header_size = calc_bson_entry_header_size(name, j); + switch (j.type()) + { + case value_t::object: + return header_size + calc_bson_object_size(*j.m_value.object); + + case value_t::array: + return header_size + calc_bson_array_size(*j.m_value.array); + + case value_t::binary: + return header_size + calc_bson_binary_size(*j.m_value.binary); + + case value_t::boolean: + return header_size + 1ul; + + case value_t::number_float: + return header_size + 8ul; + + case value_t::number_integer: + return header_size + calc_bson_integer_size(j.m_value.number_integer); + + case value_t::number_unsigned: + return header_size + calc_bson_unsigned_size(j.m_value.number_unsigned); + + case value_t::string: + return header_size + calc_bson_string_size(*j.m_value.string); + + case value_t::null: + return header_size + 0ul; + + // LCOV_EXCL_START + case value_t::discarded: + default: + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) + return 0ul; + // LCOV_EXCL_STOP + } + } + + /*! + @brief Serializes the JSON value @a j to BSON and associates it with the + key @a name. + @param name The name to associate with the JSON entity @a j within the + current BSON document + */ + void write_bson_element(const string_t& name, + const BasicJsonType& j) + { + switch (j.type()) + { + case value_t::object: + return write_bson_object_entry(name, *j.m_value.object); + + case value_t::array: + return write_bson_array(name, *j.m_value.array); + + case value_t::binary: + return write_bson_binary(name, *j.m_value.binary); + + case value_t::boolean: + return write_bson_boolean(name, j.m_value.boolean); + + case value_t::number_float: + return write_bson_double(name, j.m_value.number_float); + + case value_t::number_integer: + return write_bson_integer(name, j.m_value.number_integer); + + case value_t::number_unsigned: + return write_bson_unsigned(name, j); + + case value_t::string: + return write_bson_string(name, *j.m_value.string); + + case value_t::null: + return write_bson_null(name); + + // LCOV_EXCL_START + case value_t::discarded: + default: + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) + return; + // LCOV_EXCL_STOP + } + } + + /*! + @brief Calculates the size of the BSON serialization of the given + JSON-object @a j. + @param[in] value JSON value to serialize + @pre value.type() == value_t::object + */ + static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t& value) + { + std::size_t document_size = std::accumulate(value.begin(), value.end(), std::size_t(0), + [](size_t result, const typename BasicJsonType::object_t::value_type & el) + { + return result += calc_bson_element_size(el.first, el.second); + }); + + return sizeof(std::int32_t) + document_size + 1ul; + } + + /*! + @param[in] value JSON value to serialize + @pre value.type() == value_t::object + */ + void write_bson_object(const typename BasicJsonType::object_t& value) + { + write_number(static_cast(calc_bson_object_size(value))); + + for (const auto& el : value) + { + write_bson_element(el.first, el.second); + } + + oa->write_character(to_char_type(0x00)); + } + + ////////// + // CBOR // + ////////// + + static constexpr CharType get_cbor_float_prefix(float /*unused*/) + { + return to_char_type(0xFA); // Single-Precision Float + } + + static constexpr CharType get_cbor_float_prefix(double /*unused*/) + { + return to_char_type(0xFB); // Double-Precision Float + } + + ///////////// + // MsgPack // + ///////////// + + static constexpr CharType get_msgpack_float_prefix(float /*unused*/) + { + return to_char_type(0xCA); // float 32 + } + + static constexpr CharType get_msgpack_float_prefix(double /*unused*/) + { + return to_char_type(0xCB); // float 64 + } + + //////////// + // UBJSON // + //////////// + + // UBJSON: write number (floating point) + template::value, int>::type = 0> + void write_number_with_ubjson_prefix(const NumberType n, + const bool add_prefix) + { + if (add_prefix) + { + oa->write_character(get_ubjson_float_prefix(n)); + } + write_number(n); + } + + // UBJSON: write number (unsigned integer) + template::value, int>::type = 0> + void write_number_with_ubjson_prefix(const NumberType n, + const bool add_prefix) + { + if (n <= static_cast((std::numeric_limits::max)())) + { + if (add_prefix) + { + oa->write_character(to_char_type('i')); // int8 + } + write_number(static_cast(n)); + } + else if (n <= (std::numeric_limits::max)()) + { + if (add_prefix) + { + oa->write_character(to_char_type('U')); // uint8 + } + write_number(static_cast(n)); + } + else if (n <= static_cast((std::numeric_limits::max)())) + { + if (add_prefix) + { + oa->write_character(to_char_type('I')); // int16 + } + write_number(static_cast(n)); + } + else if (n <= static_cast((std::numeric_limits::max)())) + { + if (add_prefix) + { + oa->write_character(to_char_type('l')); // int32 + } + write_number(static_cast(n)); + } + else if (n <= static_cast((std::numeric_limits::max)())) + { + if (add_prefix) + { + oa->write_character(to_char_type('L')); // int64 + } + write_number(static_cast(n)); + } + else + { + if (add_prefix) + { + oa->write_character(to_char_type('H')); // high-precision number + } + + const auto number = BasicJsonType(n).dump(); + write_number_with_ubjson_prefix(number.size(), true); + for (std::size_t i = 0; i < number.size(); ++i) + { + oa->write_character(to_char_type(static_cast(number[i]))); + } + } + } + + // UBJSON: write number (signed integer) + template < typename NumberType, typename std::enable_if < + std::is_signed::value&& + !std::is_floating_point::value, int >::type = 0 > + void write_number_with_ubjson_prefix(const NumberType n, + const bool add_prefix) + { + if ((std::numeric_limits::min)() <= n && n <= (std::numeric_limits::max)()) + { + if (add_prefix) + { + oa->write_character(to_char_type('i')); // int8 + } + write_number(static_cast(n)); + } + else if (static_cast((std::numeric_limits::min)()) <= n && n <= static_cast((std::numeric_limits::max)())) + { + if (add_prefix) + { + oa->write_character(to_char_type('U')); // uint8 + } + write_number(static_cast(n)); + } + else if ((std::numeric_limits::min)() <= n && n <= (std::numeric_limits::max)()) + { + if (add_prefix) + { + oa->write_character(to_char_type('I')); // int16 + } + write_number(static_cast(n)); + } + else if ((std::numeric_limits::min)() <= n && n <= (std::numeric_limits::max)()) + { + if (add_prefix) + { + oa->write_character(to_char_type('l')); // int32 + } + write_number(static_cast(n)); + } + else if ((std::numeric_limits::min)() <= n && n <= (std::numeric_limits::max)()) + { + if (add_prefix) + { + oa->write_character(to_char_type('L')); // int64 + } + write_number(static_cast(n)); + } + // LCOV_EXCL_START + else + { + if (add_prefix) + { + oa->write_character(to_char_type('H')); // high-precision number + } + + const auto number = BasicJsonType(n).dump(); + write_number_with_ubjson_prefix(number.size(), true); + for (std::size_t i = 0; i < number.size(); ++i) + { + oa->write_character(to_char_type(static_cast(number[i]))); + } + } + // LCOV_EXCL_STOP + } + + /*! + @brief determine the type prefix of container values + */ + CharType ubjson_prefix(const BasicJsonType& j) const noexcept + { + switch (j.type()) + { + case value_t::null: + return 'Z'; + + case value_t::boolean: + return j.m_value.boolean ? 'T' : 'F'; + + case value_t::number_integer: + { + if ((std::numeric_limits::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits::max)()) + { + return 'i'; + } + if ((std::numeric_limits::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits::max)()) + { + return 'U'; + } + if ((std::numeric_limits::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits::max)()) + { + return 'I'; + } + if ((std::numeric_limits::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits::max)()) + { + return 'l'; + } + if ((std::numeric_limits::min)() <= j.m_value.number_integer && j.m_value.number_integer <= (std::numeric_limits::max)()) + { + return 'L'; + } + // anything else is treated as high-precision number + return 'H'; // LCOV_EXCL_LINE + } + + case value_t::number_unsigned: + { + if (j.m_value.number_unsigned <= static_cast((std::numeric_limits::max)())) + { + return 'i'; + } + if (j.m_value.number_unsigned <= static_cast((std::numeric_limits::max)())) + { + return 'U'; + } + if (j.m_value.number_unsigned <= static_cast((std::numeric_limits::max)())) + { + return 'I'; + } + if (j.m_value.number_unsigned <= static_cast((std::numeric_limits::max)())) + { + return 'l'; + } + if (j.m_value.number_unsigned <= static_cast((std::numeric_limits::max)())) + { + return 'L'; + } + // anything else is treated as high-precision number + return 'H'; // LCOV_EXCL_LINE + } + + case value_t::number_float: + return get_ubjson_float_prefix(j.m_value.number_float); + + case value_t::string: + return 'S'; + + case value_t::array: // fallthrough + case value_t::binary: + return '['; + + case value_t::object: + return '{'; + + case value_t::discarded: + default: // discarded values + return 'N'; + } + } + + static constexpr CharType get_ubjson_float_prefix(float /*unused*/) + { + return 'd'; // float 32 + } + + static constexpr CharType get_ubjson_float_prefix(double /*unused*/) + { + return 'D'; // float 64 + } + + /////////////////////// + // Utility functions // + /////////////////////// + + /* + @brief write a number to output input + @param[in] n number of type @a NumberType + @tparam NumberType the type of the number + @tparam OutputIsLittleEndian Set to true if output data is + required to be little endian + + @note This function needs to respect the system's endianess, because bytes + in CBOR, MessagePack, and UBJSON are stored in network order (big + endian) and therefore need reordering on little endian systems. + */ + template + void write_number(const NumberType n) + { + // step 1: write number to array of length NumberType + std::array vec{}; + std::memcpy(vec.data(), &n, sizeof(NumberType)); + + // step 2: write array to output (with possible reordering) + if (is_little_endian != OutputIsLittleEndian) + { + // reverse byte order prior to conversion if necessary + std::reverse(vec.begin(), vec.end()); + } + + oa->write_characters(vec.data(), sizeof(NumberType)); + } + + void write_compact_float(const number_float_t n, detail::input_format_t format) + { +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + if (static_cast(n) >= static_cast(std::numeric_limits::lowest()) && + static_cast(n) <= static_cast((std::numeric_limits::max)()) && + static_cast(static_cast(n)) == static_cast(n)) + { + oa->write_character(format == detail::input_format_t::cbor + ? get_cbor_float_prefix(static_cast(n)) + : get_msgpack_float_prefix(static_cast(n))); + write_number(static_cast(n)); + } + else + { + oa->write_character(format == detail::input_format_t::cbor + ? get_cbor_float_prefix(n) + : get_msgpack_float_prefix(n)); + write_number(n); + } +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + } + + public: + // The following to_char_type functions are implement the conversion + // between uint8_t and CharType. In case CharType is not unsigned, + // such a conversion is required to allow values greater than 128. + // See for a discussion. + template < typename C = CharType, + enable_if_t < std::is_signed::value && std::is_signed::value > * = nullptr > + static constexpr CharType to_char_type(std::uint8_t x) noexcept + { + return *reinterpret_cast(&x); + } + + template < typename C = CharType, + enable_if_t < std::is_signed::value && std::is_unsigned::value > * = nullptr > + static CharType to_char_type(std::uint8_t x) noexcept + { + static_assert(sizeof(std::uint8_t) == sizeof(CharType), "size of CharType must be equal to std::uint8_t"); + static_assert(std::is_trivial::value, "CharType must be trivial"); + CharType result; + std::memcpy(&result, &x, sizeof(x)); + return result; + } + + template::value>* = nullptr> + static constexpr CharType to_char_type(std::uint8_t x) noexcept + { + return x; + } + + template < typename InputCharType, typename C = CharType, + enable_if_t < + std::is_signed::value && + std::is_signed::value && + std::is_same::type>::value + > * = nullptr > + static constexpr CharType to_char_type(InputCharType x) noexcept + { + return x; + } + + private: + /// whether we can assume little endianess + const bool is_little_endian = little_endianess(); + + /// the output + output_adapter_t oa = nullptr; +}; +} // namespace detail +} // namespace nlohmann + +// #include + +// #include + + +#include // reverse, remove, fill, find, none_of +#include // array +#include // localeconv, lconv +#include // labs, isfinite, isnan, signbit +#include // size_t, ptrdiff_t +#include // uint8_t +#include // snprintf +#include // numeric_limits +#include // string, char_traits +#include // is_same +#include // move + +// #include + + +#include // array +#include // signbit, isfinite +#include // intN_t, uintN_t +#include // memcpy, memmove +#include // numeric_limits +#include // conditional + +// #include + + +namespace nlohmann +{ +namespace detail +{ + +/*! +@brief implements the Grisu2 algorithm for binary to decimal floating-point +conversion. + +This implementation is a slightly modified version of the reference +implementation which may be obtained from +http://florian.loitsch.com/publications (bench.tar.gz). + +The code is distributed under the MIT license, Copyright (c) 2009 Florian Loitsch. + +For a detailed description of the algorithm see: + +[1] Loitsch, "Printing Floating-Point Numbers Quickly and Accurately with + Integers", Proceedings of the ACM SIGPLAN 2010 Conference on Programming + Language Design and Implementation, PLDI 2010 +[2] Burger, Dybvig, "Printing Floating-Point Numbers Quickly and Accurately", + Proceedings of the ACM SIGPLAN 1996 Conference on Programming Language + Design and Implementation, PLDI 1996 +*/ +namespace dtoa_impl +{ + +template +Target reinterpret_bits(const Source source) +{ + static_assert(sizeof(Target) == sizeof(Source), "size mismatch"); + + Target target; + std::memcpy(&target, &source, sizeof(Source)); + return target; +} + +struct diyfp // f * 2^e +{ + static constexpr int kPrecision = 64; // = q + + std::uint64_t f = 0; + int e = 0; + + constexpr diyfp(std::uint64_t f_, int e_) noexcept : f(f_), e(e_) {} + + /*! + @brief returns x - y + @pre x.e == y.e and x.f >= y.f + */ + static diyfp sub(const diyfp& x, const diyfp& y) noexcept + { + JSON_ASSERT(x.e == y.e); + JSON_ASSERT(x.f >= y.f); + + return {x.f - y.f, x.e}; + } + + /*! + @brief returns x * y + @note The result is rounded. (Only the upper q bits are returned.) + */ + static diyfp mul(const diyfp& x, const diyfp& y) noexcept + { + static_assert(kPrecision == 64, "internal error"); + + // Computes: + // f = round((x.f * y.f) / 2^q) + // e = x.e + y.e + q + + // Emulate the 64-bit * 64-bit multiplication: + // + // p = u * v + // = (u_lo + 2^32 u_hi) (v_lo + 2^32 v_hi) + // = (u_lo v_lo ) + 2^32 ((u_lo v_hi ) + (u_hi v_lo )) + 2^64 (u_hi v_hi ) + // = (p0 ) + 2^32 ((p1 ) + (p2 )) + 2^64 (p3 ) + // = (p0_lo + 2^32 p0_hi) + 2^32 ((p1_lo + 2^32 p1_hi) + (p2_lo + 2^32 p2_hi)) + 2^64 (p3 ) + // = (p0_lo ) + 2^32 (p0_hi + p1_lo + p2_lo ) + 2^64 (p1_hi + p2_hi + p3) + // = (p0_lo ) + 2^32 (Q ) + 2^64 (H ) + // = (p0_lo ) + 2^32 (Q_lo + 2^32 Q_hi ) + 2^64 (H ) + // + // (Since Q might be larger than 2^32 - 1) + // + // = (p0_lo + 2^32 Q_lo) + 2^64 (Q_hi + H) + // + // (Q_hi + H does not overflow a 64-bit int) + // + // = p_lo + 2^64 p_hi + + const std::uint64_t u_lo = x.f & 0xFFFFFFFFu; + const std::uint64_t u_hi = x.f >> 32u; + const std::uint64_t v_lo = y.f & 0xFFFFFFFFu; + const std::uint64_t v_hi = y.f >> 32u; + + const std::uint64_t p0 = u_lo * v_lo; + const std::uint64_t p1 = u_lo * v_hi; + const std::uint64_t p2 = u_hi * v_lo; + const std::uint64_t p3 = u_hi * v_hi; + + const std::uint64_t p0_hi = p0 >> 32u; + const std::uint64_t p1_lo = p1 & 0xFFFFFFFFu; + const std::uint64_t p1_hi = p1 >> 32u; + const std::uint64_t p2_lo = p2 & 0xFFFFFFFFu; + const std::uint64_t p2_hi = p2 >> 32u; + + std::uint64_t Q = p0_hi + p1_lo + p2_lo; + + // The full product might now be computed as + // + // p_hi = p3 + p2_hi + p1_hi + (Q >> 32) + // p_lo = p0_lo + (Q << 32) + // + // But in this particular case here, the full p_lo is not required. + // Effectively we only need to add the highest bit in p_lo to p_hi (and + // Q_hi + 1 does not overflow). + + Q += std::uint64_t{1} << (64u - 32u - 1u); // round, ties up + + const std::uint64_t h = p3 + p2_hi + p1_hi + (Q >> 32u); + + return {h, x.e + y.e + 64}; + } + + /*! + @brief normalize x such that the significand is >= 2^(q-1) + @pre x.f != 0 + */ + static diyfp normalize(diyfp x) noexcept + { + JSON_ASSERT(x.f != 0); + + while ((x.f >> 63u) == 0) + { + x.f <<= 1u; + x.e--; + } + + return x; + } + + /*! + @brief normalize x such that the result has the exponent E + @pre e >= x.e and the upper e - x.e bits of x.f must be zero. + */ + static diyfp normalize_to(const diyfp& x, const int target_exponent) noexcept + { + const int delta = x.e - target_exponent; + + JSON_ASSERT(delta >= 0); + JSON_ASSERT(((x.f << delta) >> delta) == x.f); + + return {x.f << delta, target_exponent}; + } +}; + +struct boundaries +{ + diyfp w; + diyfp minus; + diyfp plus; +}; + +/*! +Compute the (normalized) diyfp representing the input number 'value' and its +boundaries. + +@pre value must be finite and positive +*/ +template +boundaries compute_boundaries(FloatType value) +{ + JSON_ASSERT(std::isfinite(value)); + JSON_ASSERT(value > 0); + + // Convert the IEEE representation into a diyfp. + // + // If v is denormal: + // value = 0.F * 2^(1 - bias) = ( F) * 2^(1 - bias - (p-1)) + // If v is normalized: + // value = 1.F * 2^(E - bias) = (2^(p-1) + F) * 2^(E - bias - (p-1)) + + static_assert(std::numeric_limits::is_iec559, + "internal error: dtoa_short requires an IEEE-754 floating-point implementation"); + + constexpr int kPrecision = std::numeric_limits::digits; // = p (includes the hidden bit) + constexpr int kBias = std::numeric_limits::max_exponent - 1 + (kPrecision - 1); + constexpr int kMinExp = 1 - kBias; + constexpr std::uint64_t kHiddenBit = std::uint64_t{1} << (kPrecision - 1); // = 2^(p-1) + + using bits_type = typename std::conditional::type; + + const auto bits = static_cast(reinterpret_bits(value)); + const std::uint64_t E = bits >> (kPrecision - 1); + const std::uint64_t F = bits & (kHiddenBit - 1); + + const bool is_denormal = E == 0; + const diyfp v = is_denormal + ? diyfp(F, kMinExp) + : diyfp(F + kHiddenBit, static_cast(E) - kBias); + + // Compute the boundaries m- and m+ of the floating-point value + // v = f * 2^e. + // + // Determine v- and v+, the floating-point predecessor and successor if v, + // respectively. + // + // v- = v - 2^e if f != 2^(p-1) or e == e_min (A) + // = v - 2^(e-1) if f == 2^(p-1) and e > e_min (B) + // + // v+ = v + 2^e + // + // Let m- = (v- + v) / 2 and m+ = (v + v+) / 2. All real numbers _strictly_ + // between m- and m+ round to v, regardless of how the input rounding + // algorithm breaks ties. + // + // ---+-------------+-------------+-------------+-------------+--- (A) + // v- m- v m+ v+ + // + // -----------------+------+------+-------------+-------------+--- (B) + // v- m- v m+ v+ + + const bool lower_boundary_is_closer = F == 0 && E > 1; + const diyfp m_plus = diyfp(2 * v.f + 1, v.e - 1); + const diyfp m_minus = lower_boundary_is_closer + ? diyfp(4 * v.f - 1, v.e - 2) // (B) + : diyfp(2 * v.f - 1, v.e - 1); // (A) + + // Determine the normalized w+ = m+. + const diyfp w_plus = diyfp::normalize(m_plus); + + // Determine w- = m- such that e_(w-) = e_(w+). + const diyfp w_minus = diyfp::normalize_to(m_minus, w_plus.e); + + return {diyfp::normalize(v), w_minus, w_plus}; +} + +// Given normalized diyfp w, Grisu needs to find a (normalized) cached +// power-of-ten c, such that the exponent of the product c * w = f * 2^e lies +// within a certain range [alpha, gamma] (Definition 3.2 from [1]) +// +// alpha <= e = e_c + e_w + q <= gamma +// +// or +// +// f_c * f_w * 2^alpha <= f_c 2^(e_c) * f_w 2^(e_w) * 2^q +// <= f_c * f_w * 2^gamma +// +// Since c and w are normalized, i.e. 2^(q-1) <= f < 2^q, this implies +// +// 2^(q-1) * 2^(q-1) * 2^alpha <= c * w * 2^q < 2^q * 2^q * 2^gamma +// +// or +// +// 2^(q - 2 + alpha) <= c * w < 2^(q + gamma) +// +// The choice of (alpha,gamma) determines the size of the table and the form of +// the digit generation procedure. Using (alpha,gamma)=(-60,-32) works out well +// in practice: +// +// The idea is to cut the number c * w = f * 2^e into two parts, which can be +// processed independently: An integral part p1, and a fractional part p2: +// +// f * 2^e = ( (f div 2^-e) * 2^-e + (f mod 2^-e) ) * 2^e +// = (f div 2^-e) + (f mod 2^-e) * 2^e +// = p1 + p2 * 2^e +// +// The conversion of p1 into decimal form requires a series of divisions and +// modulos by (a power of) 10. These operations are faster for 32-bit than for +// 64-bit integers, so p1 should ideally fit into a 32-bit integer. This can be +// achieved by choosing +// +// -e >= 32 or e <= -32 := gamma +// +// In order to convert the fractional part +// +// p2 * 2^e = p2 / 2^-e = d[-1] / 10^1 + d[-2] / 10^2 + ... +// +// into decimal form, the fraction is repeatedly multiplied by 10 and the digits +// d[-i] are extracted in order: +// +// (10 * p2) div 2^-e = d[-1] +// (10 * p2) mod 2^-e = d[-2] / 10^1 + ... +// +// The multiplication by 10 must not overflow. It is sufficient to choose +// +// 10 * p2 < 16 * p2 = 2^4 * p2 <= 2^64. +// +// Since p2 = f mod 2^-e < 2^-e, +// +// -e <= 60 or e >= -60 := alpha + +constexpr int kAlpha = -60; +constexpr int kGamma = -32; + +struct cached_power // c = f * 2^e ~= 10^k +{ + std::uint64_t f; + int e; + int k; +}; + +/*! +For a normalized diyfp w = f * 2^e, this function returns a (normalized) cached +power-of-ten c = f_c * 2^e_c, such that the exponent of the product w * c +satisfies (Definition 3.2 from [1]) + + alpha <= e_c + e + q <= gamma. +*/ +inline cached_power get_cached_power_for_binary_exponent(int e) +{ + // Now + // + // alpha <= e_c + e + q <= gamma (1) + // ==> f_c * 2^alpha <= c * 2^e * 2^q + // + // and since the c's are normalized, 2^(q-1) <= f_c, + // + // ==> 2^(q - 1 + alpha) <= c * 2^(e + q) + // ==> 2^(alpha - e - 1) <= c + // + // If c were an exact power of ten, i.e. c = 10^k, one may determine k as + // + // k = ceil( log_10( 2^(alpha - e - 1) ) ) + // = ceil( (alpha - e - 1) * log_10(2) ) + // + // From the paper: + // "In theory the result of the procedure could be wrong since c is rounded, + // and the computation itself is approximated [...]. In practice, however, + // this simple function is sufficient." + // + // For IEEE double precision floating-point numbers converted into + // normalized diyfp's w = f * 2^e, with q = 64, + // + // e >= -1022 (min IEEE exponent) + // -52 (p - 1) + // -52 (p - 1, possibly normalize denormal IEEE numbers) + // -11 (normalize the diyfp) + // = -1137 + // + // and + // + // e <= +1023 (max IEEE exponent) + // -52 (p - 1) + // -11 (normalize the diyfp) + // = 960 + // + // This binary exponent range [-1137,960] results in a decimal exponent + // range [-307,324]. One does not need to store a cached power for each + // k in this range. For each such k it suffices to find a cached power + // such that the exponent of the product lies in [alpha,gamma]. + // This implies that the difference of the decimal exponents of adjacent + // table entries must be less than or equal to + // + // floor( (gamma - alpha) * log_10(2) ) = 8. + // + // (A smaller distance gamma-alpha would require a larger table.) + + // NB: + // Actually this function returns c, such that -60 <= e_c + e + 64 <= -34. + + constexpr int kCachedPowersMinDecExp = -300; + constexpr int kCachedPowersDecStep = 8; + + static constexpr std::array kCachedPowers = + { + { + { 0xAB70FE17C79AC6CA, -1060, -300 }, + { 0xFF77B1FCBEBCDC4F, -1034, -292 }, + { 0xBE5691EF416BD60C, -1007, -284 }, + { 0x8DD01FAD907FFC3C, -980, -276 }, + { 0xD3515C2831559A83, -954, -268 }, + { 0x9D71AC8FADA6C9B5, -927, -260 }, + { 0xEA9C227723EE8BCB, -901, -252 }, + { 0xAECC49914078536D, -874, -244 }, + { 0x823C12795DB6CE57, -847, -236 }, + { 0xC21094364DFB5637, -821, -228 }, + { 0x9096EA6F3848984F, -794, -220 }, + { 0xD77485CB25823AC7, -768, -212 }, + { 0xA086CFCD97BF97F4, -741, -204 }, + { 0xEF340A98172AACE5, -715, -196 }, + { 0xB23867FB2A35B28E, -688, -188 }, + { 0x84C8D4DFD2C63F3B, -661, -180 }, + { 0xC5DD44271AD3CDBA, -635, -172 }, + { 0x936B9FCEBB25C996, -608, -164 }, + { 0xDBAC6C247D62A584, -582, -156 }, + { 0xA3AB66580D5FDAF6, -555, -148 }, + { 0xF3E2F893DEC3F126, -529, -140 }, + { 0xB5B5ADA8AAFF80B8, -502, -132 }, + { 0x87625F056C7C4A8B, -475, -124 }, + { 0xC9BCFF6034C13053, -449, -116 }, + { 0x964E858C91BA2655, -422, -108 }, + { 0xDFF9772470297EBD, -396, -100 }, + { 0xA6DFBD9FB8E5B88F, -369, -92 }, + { 0xF8A95FCF88747D94, -343, -84 }, + { 0xB94470938FA89BCF, -316, -76 }, + { 0x8A08F0F8BF0F156B, -289, -68 }, + { 0xCDB02555653131B6, -263, -60 }, + { 0x993FE2C6D07B7FAC, -236, -52 }, + { 0xE45C10C42A2B3B06, -210, -44 }, + { 0xAA242499697392D3, -183, -36 }, + { 0xFD87B5F28300CA0E, -157, -28 }, + { 0xBCE5086492111AEB, -130, -20 }, + { 0x8CBCCC096F5088CC, -103, -12 }, + { 0xD1B71758E219652C, -77, -4 }, + { 0x9C40000000000000, -50, 4 }, + { 0xE8D4A51000000000, -24, 12 }, + { 0xAD78EBC5AC620000, 3, 20 }, + { 0x813F3978F8940984, 30, 28 }, + { 0xC097CE7BC90715B3, 56, 36 }, + { 0x8F7E32CE7BEA5C70, 83, 44 }, + { 0xD5D238A4ABE98068, 109, 52 }, + { 0x9F4F2726179A2245, 136, 60 }, + { 0xED63A231D4C4FB27, 162, 68 }, + { 0xB0DE65388CC8ADA8, 189, 76 }, + { 0x83C7088E1AAB65DB, 216, 84 }, + { 0xC45D1DF942711D9A, 242, 92 }, + { 0x924D692CA61BE758, 269, 100 }, + { 0xDA01EE641A708DEA, 295, 108 }, + { 0xA26DA3999AEF774A, 322, 116 }, + { 0xF209787BB47D6B85, 348, 124 }, + { 0xB454E4A179DD1877, 375, 132 }, + { 0x865B86925B9BC5C2, 402, 140 }, + { 0xC83553C5C8965D3D, 428, 148 }, + { 0x952AB45CFA97A0B3, 455, 156 }, + { 0xDE469FBD99A05FE3, 481, 164 }, + { 0xA59BC234DB398C25, 508, 172 }, + { 0xF6C69A72A3989F5C, 534, 180 }, + { 0xB7DCBF5354E9BECE, 561, 188 }, + { 0x88FCF317F22241E2, 588, 196 }, + { 0xCC20CE9BD35C78A5, 614, 204 }, + { 0x98165AF37B2153DF, 641, 212 }, + { 0xE2A0B5DC971F303A, 667, 220 }, + { 0xA8D9D1535CE3B396, 694, 228 }, + { 0xFB9B7CD9A4A7443C, 720, 236 }, + { 0xBB764C4CA7A44410, 747, 244 }, + { 0x8BAB8EEFB6409C1A, 774, 252 }, + { 0xD01FEF10A657842C, 800, 260 }, + { 0x9B10A4E5E9913129, 827, 268 }, + { 0xE7109BFBA19C0C9D, 853, 276 }, + { 0xAC2820D9623BF429, 880, 284 }, + { 0x80444B5E7AA7CF85, 907, 292 }, + { 0xBF21E44003ACDD2D, 933, 300 }, + { 0x8E679C2F5E44FF8F, 960, 308 }, + { 0xD433179D9C8CB841, 986, 316 }, + { 0x9E19DB92B4E31BA9, 1013, 324 }, + } + }; + + // This computation gives exactly the same results for k as + // k = ceil((kAlpha - e - 1) * 0.30102999566398114) + // for |e| <= 1500, but doesn't require floating-point operations. + // NB: log_10(2) ~= 78913 / 2^18 + JSON_ASSERT(e >= -1500); + JSON_ASSERT(e <= 1500); + const int f = kAlpha - e - 1; + const int k = (f * 78913) / (1 << 18) + static_cast(f > 0); + + const int index = (-kCachedPowersMinDecExp + k + (kCachedPowersDecStep - 1)) / kCachedPowersDecStep; + JSON_ASSERT(index >= 0); + JSON_ASSERT(static_cast(index) < kCachedPowers.size()); + + const cached_power cached = kCachedPowers[static_cast(index)]; + JSON_ASSERT(kAlpha <= cached.e + e + 64); + JSON_ASSERT(kGamma >= cached.e + e + 64); + + return cached; +} + +/*! +For n != 0, returns k, such that pow10 := 10^(k-1) <= n < 10^k. +For n == 0, returns 1 and sets pow10 := 1. +*/ +inline int find_largest_pow10(const std::uint32_t n, std::uint32_t& pow10) +{ + // LCOV_EXCL_START + if (n >= 1000000000) + { + pow10 = 1000000000; + return 10; + } + // LCOV_EXCL_STOP + if (n >= 100000000) + { + pow10 = 100000000; + return 9; + } + if (n >= 10000000) + { + pow10 = 10000000; + return 8; + } + if (n >= 1000000) + { + pow10 = 1000000; + return 7; + } + if (n >= 100000) + { + pow10 = 100000; + return 6; + } + if (n >= 10000) + { + pow10 = 10000; + return 5; + } + if (n >= 1000) + { + pow10 = 1000; + return 4; + } + if (n >= 100) + { + pow10 = 100; + return 3; + } + if (n >= 10) + { + pow10 = 10; + return 2; + } + + pow10 = 1; + return 1; +} + +inline void grisu2_round(char* buf, int len, std::uint64_t dist, std::uint64_t delta, + std::uint64_t rest, std::uint64_t ten_k) +{ + JSON_ASSERT(len >= 1); + JSON_ASSERT(dist <= delta); + JSON_ASSERT(rest <= delta); + JSON_ASSERT(ten_k > 0); + + // <--------------------------- delta ----> + // <---- dist ---------> + // --------------[------------------+-------------------]-------------- + // M- w M+ + // + // ten_k + // <------> + // <---- rest ----> + // --------------[------------------+----+--------------]-------------- + // w V + // = buf * 10^k + // + // ten_k represents a unit-in-the-last-place in the decimal representation + // stored in buf. + // Decrement buf by ten_k while this takes buf closer to w. + + // The tests are written in this order to avoid overflow in unsigned + // integer arithmetic. + + while (rest < dist + && delta - rest >= ten_k + && (rest + ten_k < dist || dist - rest > rest + ten_k - dist)) + { + JSON_ASSERT(buf[len - 1] != '0'); + buf[len - 1]--; + rest += ten_k; + } +} + +/*! +Generates V = buffer * 10^decimal_exponent, such that M- <= V <= M+. +M- and M+ must be normalized and share the same exponent -60 <= e <= -32. +*/ +inline void grisu2_digit_gen(char* buffer, int& length, int& decimal_exponent, + diyfp M_minus, diyfp w, diyfp M_plus) +{ + static_assert(kAlpha >= -60, "internal error"); + static_assert(kGamma <= -32, "internal error"); + + // Generates the digits (and the exponent) of a decimal floating-point + // number V = buffer * 10^decimal_exponent in the range [M-, M+]. The diyfp's + // w, M- and M+ share the same exponent e, which satisfies alpha <= e <= gamma. + // + // <--------------------------- delta ----> + // <---- dist ---------> + // --------------[------------------+-------------------]-------------- + // M- w M+ + // + // Grisu2 generates the digits of M+ from left to right and stops as soon as + // V is in [M-,M+]. + + JSON_ASSERT(M_plus.e >= kAlpha); + JSON_ASSERT(M_plus.e <= kGamma); + + std::uint64_t delta = diyfp::sub(M_plus, M_minus).f; // (significand of (M+ - M-), implicit exponent is e) + std::uint64_t dist = diyfp::sub(M_plus, w ).f; // (significand of (M+ - w ), implicit exponent is e) + + // Split M+ = f * 2^e into two parts p1 and p2 (note: e < 0): + // + // M+ = f * 2^e + // = ((f div 2^-e) * 2^-e + (f mod 2^-e)) * 2^e + // = ((p1 ) * 2^-e + (p2 )) * 2^e + // = p1 + p2 * 2^e + + const diyfp one(std::uint64_t{1} << -M_plus.e, M_plus.e); + + auto p1 = static_cast(M_plus.f >> -one.e); // p1 = f div 2^-e (Since -e >= 32, p1 fits into a 32-bit int.) + std::uint64_t p2 = M_plus.f & (one.f - 1); // p2 = f mod 2^-e + + // 1) + // + // Generate the digits of the integral part p1 = d[n-1]...d[1]d[0] + + JSON_ASSERT(p1 > 0); + + std::uint32_t pow10{}; + const int k = find_largest_pow10(p1, pow10); + + // 10^(k-1) <= p1 < 10^k, pow10 = 10^(k-1) + // + // p1 = (p1 div 10^(k-1)) * 10^(k-1) + (p1 mod 10^(k-1)) + // = (d[k-1] ) * 10^(k-1) + (p1 mod 10^(k-1)) + // + // M+ = p1 + p2 * 2^e + // = d[k-1] * 10^(k-1) + (p1 mod 10^(k-1)) + p2 * 2^e + // = d[k-1] * 10^(k-1) + ((p1 mod 10^(k-1)) * 2^-e + p2) * 2^e + // = d[k-1] * 10^(k-1) + ( rest) * 2^e + // + // Now generate the digits d[n] of p1 from left to right (n = k-1,...,0) + // + // p1 = d[k-1]...d[n] * 10^n + d[n-1]...d[0] + // + // but stop as soon as + // + // rest * 2^e = (d[n-1]...d[0] * 2^-e + p2) * 2^e <= delta * 2^e + + int n = k; + while (n > 0) + { + // Invariants: + // M+ = buffer * 10^n + (p1 + p2 * 2^e) (buffer = 0 for n = k) + // pow10 = 10^(n-1) <= p1 < 10^n + // + const std::uint32_t d = p1 / pow10; // d = p1 div 10^(n-1) + const std::uint32_t r = p1 % pow10; // r = p1 mod 10^(n-1) + // + // M+ = buffer * 10^n + (d * 10^(n-1) + r) + p2 * 2^e + // = (buffer * 10 + d) * 10^(n-1) + (r + p2 * 2^e) + // + JSON_ASSERT(d <= 9); + buffer[length++] = static_cast('0' + d); // buffer := buffer * 10 + d + // + // M+ = buffer * 10^(n-1) + (r + p2 * 2^e) + // + p1 = r; + n--; + // + // M+ = buffer * 10^n + (p1 + p2 * 2^e) + // pow10 = 10^n + // + + // Now check if enough digits have been generated. + // Compute + // + // p1 + p2 * 2^e = (p1 * 2^-e + p2) * 2^e = rest * 2^e + // + // Note: + // Since rest and delta share the same exponent e, it suffices to + // compare the significands. + const std::uint64_t rest = (std::uint64_t{p1} << -one.e) + p2; + if (rest <= delta) + { + // V = buffer * 10^n, with M- <= V <= M+. + + decimal_exponent += n; + + // We may now just stop. But instead look if the buffer could be + // decremented to bring V closer to w. + // + // pow10 = 10^n is now 1 ulp in the decimal representation V. + // The rounding procedure works with diyfp's with an implicit + // exponent of e. + // + // 10^n = (10^n * 2^-e) * 2^e = ulp * 2^e + // + const std::uint64_t ten_n = std::uint64_t{pow10} << -one.e; + grisu2_round(buffer, length, dist, delta, rest, ten_n); + + return; + } + + pow10 /= 10; + // + // pow10 = 10^(n-1) <= p1 < 10^n + // Invariants restored. + } + + // 2) + // + // The digits of the integral part have been generated: + // + // M+ = d[k-1]...d[1]d[0] + p2 * 2^e + // = buffer + p2 * 2^e + // + // Now generate the digits of the fractional part p2 * 2^e. + // + // Note: + // No decimal point is generated: the exponent is adjusted instead. + // + // p2 actually represents the fraction + // + // p2 * 2^e + // = p2 / 2^-e + // = d[-1] / 10^1 + d[-2] / 10^2 + ... + // + // Now generate the digits d[-m] of p1 from left to right (m = 1,2,...) + // + // p2 * 2^e = d[-1]d[-2]...d[-m] * 10^-m + // + 10^-m * (d[-m-1] / 10^1 + d[-m-2] / 10^2 + ...) + // + // using + // + // 10^m * p2 = ((10^m * p2) div 2^-e) * 2^-e + ((10^m * p2) mod 2^-e) + // = ( d) * 2^-e + ( r) + // + // or + // 10^m * p2 * 2^e = d + r * 2^e + // + // i.e. + // + // M+ = buffer + p2 * 2^e + // = buffer + 10^-m * (d + r * 2^e) + // = (buffer * 10^m + d) * 10^-m + 10^-m * r * 2^e + // + // and stop as soon as 10^-m * r * 2^e <= delta * 2^e + + JSON_ASSERT(p2 > delta); + + int m = 0; + for (;;) + { + // Invariant: + // M+ = buffer * 10^-m + 10^-m * (d[-m-1] / 10 + d[-m-2] / 10^2 + ...) * 2^e + // = buffer * 10^-m + 10^-m * (p2 ) * 2^e + // = buffer * 10^-m + 10^-m * (1/10 * (10 * p2) ) * 2^e + // = buffer * 10^-m + 10^-m * (1/10 * ((10*p2 div 2^-e) * 2^-e + (10*p2 mod 2^-e)) * 2^e + // + JSON_ASSERT(p2 <= (std::numeric_limits::max)() / 10); + p2 *= 10; + const std::uint64_t d = p2 >> -one.e; // d = (10 * p2) div 2^-e + const std::uint64_t r = p2 & (one.f - 1); // r = (10 * p2) mod 2^-e + // + // M+ = buffer * 10^-m + 10^-m * (1/10 * (d * 2^-e + r) * 2^e + // = buffer * 10^-m + 10^-m * (1/10 * (d + r * 2^e)) + // = (buffer * 10 + d) * 10^(-m-1) + 10^(-m-1) * r * 2^e + // + JSON_ASSERT(d <= 9); + buffer[length++] = static_cast('0' + d); // buffer := buffer * 10 + d + // + // M+ = buffer * 10^(-m-1) + 10^(-m-1) * r * 2^e + // + p2 = r; + m++; + // + // M+ = buffer * 10^-m + 10^-m * p2 * 2^e + // Invariant restored. + + // Check if enough digits have been generated. + // + // 10^-m * p2 * 2^e <= delta * 2^e + // p2 * 2^e <= 10^m * delta * 2^e + // p2 <= 10^m * delta + delta *= 10; + dist *= 10; + if (p2 <= delta) + { + break; + } + } + + // V = buffer * 10^-m, with M- <= V <= M+. + + decimal_exponent -= m; + + // 1 ulp in the decimal representation is now 10^-m. + // Since delta and dist are now scaled by 10^m, we need to do the + // same with ulp in order to keep the units in sync. + // + // 10^m * 10^-m = 1 = 2^-e * 2^e = ten_m * 2^e + // + const std::uint64_t ten_m = one.f; + grisu2_round(buffer, length, dist, delta, p2, ten_m); + + // By construction this algorithm generates the shortest possible decimal + // number (Loitsch, Theorem 6.2) which rounds back to w. + // For an input number of precision p, at least + // + // N = 1 + ceil(p * log_10(2)) + // + // decimal digits are sufficient to identify all binary floating-point + // numbers (Matula, "In-and-Out conversions"). + // This implies that the algorithm does not produce more than N decimal + // digits. + // + // N = 17 for p = 53 (IEEE double precision) + // N = 9 for p = 24 (IEEE single precision) +} + +/*! +v = buf * 10^decimal_exponent +len is the length of the buffer (number of decimal digits) +The buffer must be large enough, i.e. >= max_digits10. +*/ +JSON_HEDLEY_NON_NULL(1) +inline void grisu2(char* buf, int& len, int& decimal_exponent, + diyfp m_minus, diyfp v, diyfp m_plus) +{ + JSON_ASSERT(m_plus.e == m_minus.e); + JSON_ASSERT(m_plus.e == v.e); + + // --------(-----------------------+-----------------------)-------- (A) + // m- v m+ + // + // --------------------(-----------+-----------------------)-------- (B) + // m- v m+ + // + // First scale v (and m- and m+) such that the exponent is in the range + // [alpha, gamma]. + + const cached_power cached = get_cached_power_for_binary_exponent(m_plus.e); + + const diyfp c_minus_k(cached.f, cached.e); // = c ~= 10^-k + + // The exponent of the products is = v.e + c_minus_k.e + q and is in the range [alpha,gamma] + const diyfp w = diyfp::mul(v, c_minus_k); + const diyfp w_minus = diyfp::mul(m_minus, c_minus_k); + const diyfp w_plus = diyfp::mul(m_plus, c_minus_k); + + // ----(---+---)---------------(---+---)---------------(---+---)---- + // w- w w+ + // = c*m- = c*v = c*m+ + // + // diyfp::mul rounds its result and c_minus_k is approximated too. w, w- and + // w+ are now off by a small amount. + // In fact: + // + // w - v * 10^k < 1 ulp + // + // To account for this inaccuracy, add resp. subtract 1 ulp. + // + // --------+---[---------------(---+---)---------------]---+-------- + // w- M- w M+ w+ + // + // Now any number in [M-, M+] (bounds included) will round to w when input, + // regardless of how the input rounding algorithm breaks ties. + // + // And digit_gen generates the shortest possible such number in [M-, M+]. + // Note that this does not mean that Grisu2 always generates the shortest + // possible number in the interval (m-, m+). + const diyfp M_minus(w_minus.f + 1, w_minus.e); + const diyfp M_plus (w_plus.f - 1, w_plus.e ); + + decimal_exponent = -cached.k; // = -(-k) = k + + grisu2_digit_gen(buf, len, decimal_exponent, M_minus, w, M_plus); +} + +/*! +v = buf * 10^decimal_exponent +len is the length of the buffer (number of decimal digits) +The buffer must be large enough, i.e. >= max_digits10. +*/ +template +JSON_HEDLEY_NON_NULL(1) +void grisu2(char* buf, int& len, int& decimal_exponent, FloatType value) +{ + static_assert(diyfp::kPrecision >= std::numeric_limits::digits + 3, + "internal error: not enough precision"); + + JSON_ASSERT(std::isfinite(value)); + JSON_ASSERT(value > 0); + + // If the neighbors (and boundaries) of 'value' are always computed for double-precision + // numbers, all float's can be recovered using strtod (and strtof). However, the resulting + // decimal representations are not exactly "short". + // + // The documentation for 'std::to_chars' (https://en.cppreference.com/w/cpp/utility/to_chars) + // says "value is converted to a string as if by std::sprintf in the default ("C") locale" + // and since sprintf promotes float's to double's, I think this is exactly what 'std::to_chars' + // does. + // On the other hand, the documentation for 'std::to_chars' requires that "parsing the + // representation using the corresponding std::from_chars function recovers value exactly". That + // indicates that single precision floating-point numbers should be recovered using + // 'std::strtof'. + // + // NB: If the neighbors are computed for single-precision numbers, there is a single float + // (7.0385307e-26f) which can't be recovered using strtod. The resulting double precision + // value is off by 1 ulp. +#if 0 + const boundaries w = compute_boundaries(static_cast(value)); +#else + const boundaries w = compute_boundaries(value); +#endif + + grisu2(buf, len, decimal_exponent, w.minus, w.w, w.plus); +} + +/*! +@brief appends a decimal representation of e to buf +@return a pointer to the element following the exponent. +@pre -1000 < e < 1000 +*/ +JSON_HEDLEY_NON_NULL(1) +JSON_HEDLEY_RETURNS_NON_NULL +inline char* append_exponent(char* buf, int e) +{ + JSON_ASSERT(e > -1000); + JSON_ASSERT(e < 1000); + + if (e < 0) + { + e = -e; + *buf++ = '-'; + } + else + { + *buf++ = '+'; + } + + auto k = static_cast(e); + if (k < 10) + { + // Always print at least two digits in the exponent. + // This is for compatibility with printf("%g"). + *buf++ = '0'; + *buf++ = static_cast('0' + k); + } + else if (k < 100) + { + *buf++ = static_cast('0' + k / 10); + k %= 10; + *buf++ = static_cast('0' + k); + } + else + { + *buf++ = static_cast('0' + k / 100); + k %= 100; + *buf++ = static_cast('0' + k / 10); + k %= 10; + *buf++ = static_cast('0' + k); + } + + return buf; +} + +/*! +@brief prettify v = buf * 10^decimal_exponent + +If v is in the range [10^min_exp, 10^max_exp) it will be printed in fixed-point +notation. Otherwise it will be printed in exponential notation. + +@pre min_exp < 0 +@pre max_exp > 0 +*/ +JSON_HEDLEY_NON_NULL(1) +JSON_HEDLEY_RETURNS_NON_NULL +inline char* format_buffer(char* buf, int len, int decimal_exponent, + int min_exp, int max_exp) +{ + JSON_ASSERT(min_exp < 0); + JSON_ASSERT(max_exp > 0); + + const int k = len; + const int n = len + decimal_exponent; + + // v = buf * 10^(n-k) + // k is the length of the buffer (number of decimal digits) + // n is the position of the decimal point relative to the start of the buffer. + + if (k <= n && n <= max_exp) + { + // digits[000] + // len <= max_exp + 2 + + std::memset(buf + k, '0', static_cast(n) - static_cast(k)); + // Make it look like a floating-point number (#362, #378) + buf[n + 0] = '.'; + buf[n + 1] = '0'; + return buf + (static_cast(n) + 2); + } + + if (0 < n && n <= max_exp) + { + // dig.its + // len <= max_digits10 + 1 + + JSON_ASSERT(k > n); + + std::memmove(buf + (static_cast(n) + 1), buf + n, static_cast(k) - static_cast(n)); + buf[n] = '.'; + return buf + (static_cast(k) + 1U); + } + + if (min_exp < n && n <= 0) + { + // 0.[000]digits + // len <= 2 + (-min_exp - 1) + max_digits10 + + std::memmove(buf + (2 + static_cast(-n)), buf, static_cast(k)); + buf[0] = '0'; + buf[1] = '.'; + std::memset(buf + 2, '0', static_cast(-n)); + return buf + (2U + static_cast(-n) + static_cast(k)); + } + + if (k == 1) + { + // dE+123 + // len <= 1 + 5 + + buf += 1; + } + else + { + // d.igitsE+123 + // len <= max_digits10 + 1 + 5 + + std::memmove(buf + 2, buf + 1, static_cast(k) - 1); + buf[1] = '.'; + buf += 1 + static_cast(k); + } + + *buf++ = 'e'; + return append_exponent(buf, n - 1); +} + +} // namespace dtoa_impl + +/*! +@brief generates a decimal representation of the floating-point number value in [first, last). + +The format of the resulting decimal representation is similar to printf's %g +format. Returns an iterator pointing past-the-end of the decimal representation. + +@note The input number must be finite, i.e. NaN's and Inf's are not supported. +@note The buffer must be large enough. +@note The result is NOT null-terminated. +*/ +template +JSON_HEDLEY_NON_NULL(1, 2) +JSON_HEDLEY_RETURNS_NON_NULL +char* to_chars(char* first, const char* last, FloatType value) +{ + static_cast(last); // maybe unused - fix warning + JSON_ASSERT(std::isfinite(value)); + + // Use signbit(value) instead of (value < 0) since signbit works for -0. + if (std::signbit(value)) + { + value = -value; + *first++ = '-'; + } + +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + if (value == 0) // +-0 + { + *first++ = '0'; + // Make it look like a floating-point number (#362, #378) + *first++ = '.'; + *first++ = '0'; + return first; + } +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + + JSON_ASSERT(last - first >= std::numeric_limits::max_digits10); + + // Compute v = buffer * 10^decimal_exponent. + // The decimal digits are stored in the buffer, which needs to be interpreted + // as an unsigned decimal integer. + // len is the length of the buffer, i.e. the number of decimal digits. + int len = 0; + int decimal_exponent = 0; + dtoa_impl::grisu2(first, len, decimal_exponent, value); + + JSON_ASSERT(len <= std::numeric_limits::max_digits10); + + // Format the buffer like printf("%.*g", prec, value) + constexpr int kMinExp = -4; + // Use digits10 here to increase compatibility with version 2. + constexpr int kMaxExp = std::numeric_limits::digits10; + + JSON_ASSERT(last - first >= kMaxExp + 2); + JSON_ASSERT(last - first >= 2 + (-kMinExp - 1) + std::numeric_limits::max_digits10); + JSON_ASSERT(last - first >= std::numeric_limits::max_digits10 + 6); + + return dtoa_impl::format_buffer(first, len, decimal_exponent, kMinExp, kMaxExp); +} + +} // namespace detail +} // namespace nlohmann + +// #include + +// #include + +// #include + +// #include + +// #include + +// #include + + +namespace nlohmann +{ +namespace detail +{ +/////////////////// +// serialization // +/////////////////// + +/// how to treat decoding errors +enum class error_handler_t +{ + strict, ///< throw a type_error exception in case of invalid UTF-8 + replace, ///< replace invalid UTF-8 sequences with U+FFFD + ignore ///< ignore invalid UTF-8 sequences +}; + +template +class serializer +{ + using string_t = typename BasicJsonType::string_t; + using number_float_t = typename BasicJsonType::number_float_t; + using number_integer_t = typename BasicJsonType::number_integer_t; + using number_unsigned_t = typename BasicJsonType::number_unsigned_t; + using binary_char_t = typename BasicJsonType::binary_t::value_type; + static constexpr std::uint8_t UTF8_ACCEPT = 0; + static constexpr std::uint8_t UTF8_REJECT = 1; + + public: + /*! + @param[in] s output stream to serialize to + @param[in] ichar indentation character to use + @param[in] error_handler_ how to react on decoding errors + */ + serializer(output_adapter_t s, const char ichar, + error_handler_t error_handler_ = error_handler_t::strict) + : o(std::move(s)) + , loc(std::localeconv()) + , thousands_sep(loc->thousands_sep == nullptr ? '\0' : std::char_traits::to_char_type(* (loc->thousands_sep))) + , decimal_point(loc->decimal_point == nullptr ? '\0' : std::char_traits::to_char_type(* (loc->decimal_point))) + , indent_char(ichar) + , indent_string(512, indent_char) + , error_handler(error_handler_) + {} + + // delete because of pointer members + serializer(const serializer&) = delete; + serializer& operator=(const serializer&) = delete; + serializer(serializer&&) = delete; + serializer& operator=(serializer&&) = delete; + ~serializer() = default; + + /*! + @brief internal implementation of the serialization function + + This function is called by the public member function dump and organizes + the serialization internally. The indentation level is propagated as + additional parameter. In case of arrays and objects, the function is + called recursively. + + - strings and object keys are escaped using `escape_string()` + - integer numbers are converted implicitly via `operator<<` + - floating-point numbers are converted to a string using `"%g"` format + - binary values are serialized as objects containing the subtype and the + byte array + + @param[in] val value to serialize + @param[in] pretty_print whether the output shall be pretty-printed + @param[in] ensure_ascii If @a ensure_ascii is true, all non-ASCII characters + in the output are escaped with `\uXXXX` sequences, and the result consists + of ASCII characters only. + @param[in] indent_step the indent level + @param[in] current_indent the current indent level (only used internally) + */ + void dump(const BasicJsonType& val, + const bool pretty_print, + const bool ensure_ascii, + const unsigned int indent_step, + const unsigned int current_indent = 0) + { + switch (val.m_type) + { + case value_t::object: + { + if (val.m_value.object->empty()) + { + o->write_characters("{}", 2); + return; + } + + if (pretty_print) + { + o->write_characters("{\n", 2); + + // variable to hold indentation for recursive calls + const auto new_indent = current_indent + indent_step; + if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) + { + indent_string.resize(indent_string.size() * 2, ' '); + } + + // first n-1 elements + auto i = val.m_value.object->cbegin(); + for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i) + { + o->write_characters(indent_string.c_str(), new_indent); + o->write_character('\"'); + dump_escaped(i->first, ensure_ascii); + o->write_characters("\": ", 3); + dump(i->second, true, ensure_ascii, indent_step, new_indent); + o->write_characters(",\n", 2); + } + + // last element + JSON_ASSERT(i != val.m_value.object->cend()); + JSON_ASSERT(std::next(i) == val.m_value.object->cend()); + o->write_characters(indent_string.c_str(), new_indent); + o->write_character('\"'); + dump_escaped(i->first, ensure_ascii); + o->write_characters("\": ", 3); + dump(i->second, true, ensure_ascii, indent_step, new_indent); + + o->write_character('\n'); + o->write_characters(indent_string.c_str(), current_indent); + o->write_character('}'); + } + else + { + o->write_character('{'); + + // first n-1 elements + auto i = val.m_value.object->cbegin(); + for (std::size_t cnt = 0; cnt < val.m_value.object->size() - 1; ++cnt, ++i) + { + o->write_character('\"'); + dump_escaped(i->first, ensure_ascii); + o->write_characters("\":", 2); + dump(i->second, false, ensure_ascii, indent_step, current_indent); + o->write_character(','); + } + + // last element + JSON_ASSERT(i != val.m_value.object->cend()); + JSON_ASSERT(std::next(i) == val.m_value.object->cend()); + o->write_character('\"'); + dump_escaped(i->first, ensure_ascii); + o->write_characters("\":", 2); + dump(i->second, false, ensure_ascii, indent_step, current_indent); + + o->write_character('}'); + } + + return; + } + + case value_t::array: + { + if (val.m_value.array->empty()) + { + o->write_characters("[]", 2); + return; + } + + if (pretty_print) + { + o->write_characters("[\n", 2); + + // variable to hold indentation for recursive calls + const auto new_indent = current_indent + indent_step; + if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) + { + indent_string.resize(indent_string.size() * 2, ' '); + } + + // first n-1 elements + for (auto i = val.m_value.array->cbegin(); + i != val.m_value.array->cend() - 1; ++i) + { + o->write_characters(indent_string.c_str(), new_indent); + dump(*i, true, ensure_ascii, indent_step, new_indent); + o->write_characters(",\n", 2); + } + + // last element + JSON_ASSERT(!val.m_value.array->empty()); + o->write_characters(indent_string.c_str(), new_indent); + dump(val.m_value.array->back(), true, ensure_ascii, indent_step, new_indent); + + o->write_character('\n'); + o->write_characters(indent_string.c_str(), current_indent); + o->write_character(']'); + } + else + { + o->write_character('['); + + // first n-1 elements + for (auto i = val.m_value.array->cbegin(); + i != val.m_value.array->cend() - 1; ++i) + { + dump(*i, false, ensure_ascii, indent_step, current_indent); + o->write_character(','); + } + + // last element + JSON_ASSERT(!val.m_value.array->empty()); + dump(val.m_value.array->back(), false, ensure_ascii, indent_step, current_indent); + + o->write_character(']'); + } + + return; + } + + case value_t::string: + { + o->write_character('\"'); + dump_escaped(*val.m_value.string, ensure_ascii); + o->write_character('\"'); + return; + } + + case value_t::binary: + { + if (pretty_print) + { + o->write_characters("{\n", 2); + + // variable to hold indentation for recursive calls + const auto new_indent = current_indent + indent_step; + if (JSON_HEDLEY_UNLIKELY(indent_string.size() < new_indent)) + { + indent_string.resize(indent_string.size() * 2, ' '); + } + + o->write_characters(indent_string.c_str(), new_indent); + + o->write_characters("\"bytes\": [", 10); + + if (!val.m_value.binary->empty()) + { + for (auto i = val.m_value.binary->cbegin(); + i != val.m_value.binary->cend() - 1; ++i) + { + dump_integer(*i); + o->write_characters(", ", 2); + } + dump_integer(val.m_value.binary->back()); + } + + o->write_characters("],\n", 3); + o->write_characters(indent_string.c_str(), new_indent); + + o->write_characters("\"subtype\": ", 11); + if (val.m_value.binary->has_subtype()) + { + dump_integer(val.m_value.binary->subtype()); + } + else + { + o->write_characters("null", 4); + } + o->write_character('\n'); + o->write_characters(indent_string.c_str(), current_indent); + o->write_character('}'); + } + else + { + o->write_characters("{\"bytes\":[", 10); + + if (!val.m_value.binary->empty()) + { + for (auto i = val.m_value.binary->cbegin(); + i != val.m_value.binary->cend() - 1; ++i) + { + dump_integer(*i); + o->write_character(','); + } + dump_integer(val.m_value.binary->back()); + } + + o->write_characters("],\"subtype\":", 12); + if (val.m_value.binary->has_subtype()) + { + dump_integer(val.m_value.binary->subtype()); + o->write_character('}'); + } + else + { + o->write_characters("null}", 5); + } + } + return; + } + + case value_t::boolean: + { + if (val.m_value.boolean) + { + o->write_characters("true", 4); + } + else + { + o->write_characters("false", 5); + } + return; + } + + case value_t::number_integer: + { + dump_integer(val.m_value.number_integer); + return; + } + + case value_t::number_unsigned: + { + dump_integer(val.m_value.number_unsigned); + return; + } + + case value_t::number_float: + { + dump_float(val.m_value.number_float); + return; + } + + case value_t::discarded: + { + o->write_characters("", 11); + return; + } + + case value_t::null: + { + o->write_characters("null", 4); + return; + } + + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + } + } + + JSON_PRIVATE_UNLESS_TESTED: + /*! + @brief dump escaped string + + Escape a string by replacing certain special characters by a sequence of an + escape character (backslash) and another character and other control + characters by a sequence of "\u" followed by a four-digit hex + representation. The escaped string is written to output stream @a o. + + @param[in] s the string to escape + @param[in] ensure_ascii whether to escape non-ASCII characters with + \uXXXX sequences + + @complexity Linear in the length of string @a s. + */ + void dump_escaped(const string_t& s, const bool ensure_ascii) + { + std::uint32_t codepoint{}; + std::uint8_t state = UTF8_ACCEPT; + std::size_t bytes = 0; // number of bytes written to string_buffer + + // number of bytes written at the point of the last valid byte + std::size_t bytes_after_last_accept = 0; + std::size_t undumped_chars = 0; + + for (std::size_t i = 0; i < s.size(); ++i) + { + const auto byte = static_cast(s[i]); + + switch (decode(state, codepoint, byte)) + { + case UTF8_ACCEPT: // decode found a new code point + { + switch (codepoint) + { + case 0x08: // backspace + { + string_buffer[bytes++] = '\\'; + string_buffer[bytes++] = 'b'; + break; + } + + case 0x09: // horizontal tab + { + string_buffer[bytes++] = '\\'; + string_buffer[bytes++] = 't'; + break; + } + + case 0x0A: // newline + { + string_buffer[bytes++] = '\\'; + string_buffer[bytes++] = 'n'; + break; + } + + case 0x0C: // formfeed + { + string_buffer[bytes++] = '\\'; + string_buffer[bytes++] = 'f'; + break; + } + + case 0x0D: // carriage return + { + string_buffer[bytes++] = '\\'; + string_buffer[bytes++] = 'r'; + break; + } + + case 0x22: // quotation mark + { + string_buffer[bytes++] = '\\'; + string_buffer[bytes++] = '\"'; + break; + } + + case 0x5C: // reverse solidus + { + string_buffer[bytes++] = '\\'; + string_buffer[bytes++] = '\\'; + break; + } + + default: + { + // escape control characters (0x00..0x1F) or, if + // ensure_ascii parameter is used, non-ASCII characters + if ((codepoint <= 0x1F) || (ensure_ascii && (codepoint >= 0x7F))) + { + if (codepoint <= 0xFFFF) + { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + (std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x", + static_cast(codepoint)); + bytes += 6; + } + else + { + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + (std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x", + static_cast(0xD7C0u + (codepoint >> 10u)), + static_cast(0xDC00u + (codepoint & 0x3FFu))); + bytes += 12; + } + } + else + { + // copy byte to buffer (all previous bytes + // been copied have in default case above) + string_buffer[bytes++] = s[i]; + } + break; + } + } + + // write buffer and reset index; there must be 13 bytes + // left, as this is the maximal number of bytes to be + // written ("\uxxxx\uxxxx\0") for one code point + if (string_buffer.size() - bytes < 13) + { + o->write_characters(string_buffer.data(), bytes); + bytes = 0; + } + + // remember the byte position of this accept + bytes_after_last_accept = bytes; + undumped_chars = 0; + break; + } + + case UTF8_REJECT: // decode found invalid UTF-8 byte + { + switch (error_handler) + { + case error_handler_t::strict: + { + std::string sn(9, '\0'); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + (std::snprintf)(&sn[0], sn.size(), "%.2X", byte); + JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn, BasicJsonType())); + } + + case error_handler_t::ignore: + case error_handler_t::replace: + { + // in case we saw this character the first time, we + // would like to read it again, because the byte + // may be OK for itself, but just not OK for the + // previous sequence + if (undumped_chars > 0) + { + --i; + } + + // reset length buffer to the last accepted index; + // thus removing/ignoring the invalid characters + bytes = bytes_after_last_accept; + + if (error_handler == error_handler_t::replace) + { + // add a replacement character + if (ensure_ascii) + { + string_buffer[bytes++] = '\\'; + string_buffer[bytes++] = 'u'; + string_buffer[bytes++] = 'f'; + string_buffer[bytes++] = 'f'; + string_buffer[bytes++] = 'f'; + string_buffer[bytes++] = 'd'; + } + else + { + string_buffer[bytes++] = detail::binary_writer::to_char_type('\xEF'); + string_buffer[bytes++] = detail::binary_writer::to_char_type('\xBF'); + string_buffer[bytes++] = detail::binary_writer::to_char_type('\xBD'); + } + + // write buffer and reset index; there must be 13 bytes + // left, as this is the maximal number of bytes to be + // written ("\uxxxx\uxxxx\0") for one code point + if (string_buffer.size() - bytes < 13) + { + o->write_characters(string_buffer.data(), bytes); + bytes = 0; + } + + bytes_after_last_accept = bytes; + } + + undumped_chars = 0; + + // continue processing the string + state = UTF8_ACCEPT; + break; + } + + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + } + break; + } + + default: // decode found yet incomplete multi-byte code point + { + if (!ensure_ascii) + { + // code point will not be escaped - copy byte to buffer + string_buffer[bytes++] = s[i]; + } + ++undumped_chars; + break; + } + } + } + + // we finished processing the string + if (JSON_HEDLEY_LIKELY(state == UTF8_ACCEPT)) + { + // write buffer + if (bytes > 0) + { + o->write_characters(string_buffer.data(), bytes); + } + } + else + { + // we finish reading, but do not accept: string was incomplete + switch (error_handler) + { + case error_handler_t::strict: + { + std::string sn(9, '\0'); + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + (std::snprintf)(&sn[0], sn.size(), "%.2X", static_cast(s.back())); + JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn, BasicJsonType())); + } + + case error_handler_t::ignore: + { + // write all accepted bytes + o->write_characters(string_buffer.data(), bytes_after_last_accept); + break; + } + + case error_handler_t::replace: + { + // write all accepted bytes + o->write_characters(string_buffer.data(), bytes_after_last_accept); + // add a replacement character + if (ensure_ascii) + { + o->write_characters("\\ufffd", 6); + } + else + { + o->write_characters("\xEF\xBF\xBD", 3); + } + break; + } + + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + } + } + } + + private: + /*! + @brief count digits + + Count the number of decimal (base 10) digits for an input unsigned integer. + + @param[in] x unsigned integer number to count its digits + @return number of decimal digits + */ + inline unsigned int count_digits(number_unsigned_t x) noexcept + { + unsigned int n_digits = 1; + for (;;) + { + if (x < 10) + { + return n_digits; + } + if (x < 100) + { + return n_digits + 1; + } + if (x < 1000) + { + return n_digits + 2; + } + if (x < 10000) + { + return n_digits + 3; + } + x = x / 10000u; + n_digits += 4; + } + } + + /*! + @brief dump an integer + + Dump a given integer to output stream @a o. Works internally with + @a number_buffer. + + @param[in] x integer number (signed or unsigned) to dump + @tparam NumberType either @a number_integer_t or @a number_unsigned_t + */ + template < typename NumberType, detail::enable_if_t < + std::is_integral::value || + std::is_same::value || + std::is_same::value || + std::is_same::value, + int > = 0 > + void dump_integer(NumberType x) + { + static constexpr std::array, 100> digits_to_99 + { + { + {{'0', '0'}}, {{'0', '1'}}, {{'0', '2'}}, {{'0', '3'}}, {{'0', '4'}}, {{'0', '5'}}, {{'0', '6'}}, {{'0', '7'}}, {{'0', '8'}}, {{'0', '9'}}, + {{'1', '0'}}, {{'1', '1'}}, {{'1', '2'}}, {{'1', '3'}}, {{'1', '4'}}, {{'1', '5'}}, {{'1', '6'}}, {{'1', '7'}}, {{'1', '8'}}, {{'1', '9'}}, + {{'2', '0'}}, {{'2', '1'}}, {{'2', '2'}}, {{'2', '3'}}, {{'2', '4'}}, {{'2', '5'}}, {{'2', '6'}}, {{'2', '7'}}, {{'2', '8'}}, {{'2', '9'}}, + {{'3', '0'}}, {{'3', '1'}}, {{'3', '2'}}, {{'3', '3'}}, {{'3', '4'}}, {{'3', '5'}}, {{'3', '6'}}, {{'3', '7'}}, {{'3', '8'}}, {{'3', '9'}}, + {{'4', '0'}}, {{'4', '1'}}, {{'4', '2'}}, {{'4', '3'}}, {{'4', '4'}}, {{'4', '5'}}, {{'4', '6'}}, {{'4', '7'}}, {{'4', '8'}}, {{'4', '9'}}, + {{'5', '0'}}, {{'5', '1'}}, {{'5', '2'}}, {{'5', '3'}}, {{'5', '4'}}, {{'5', '5'}}, {{'5', '6'}}, {{'5', '7'}}, {{'5', '8'}}, {{'5', '9'}}, + {{'6', '0'}}, {{'6', '1'}}, {{'6', '2'}}, {{'6', '3'}}, {{'6', '4'}}, {{'6', '5'}}, {{'6', '6'}}, {{'6', '7'}}, {{'6', '8'}}, {{'6', '9'}}, + {{'7', '0'}}, {{'7', '1'}}, {{'7', '2'}}, {{'7', '3'}}, {{'7', '4'}}, {{'7', '5'}}, {{'7', '6'}}, {{'7', '7'}}, {{'7', '8'}}, {{'7', '9'}}, + {{'8', '0'}}, {{'8', '1'}}, {{'8', '2'}}, {{'8', '3'}}, {{'8', '4'}}, {{'8', '5'}}, {{'8', '6'}}, {{'8', '7'}}, {{'8', '8'}}, {{'8', '9'}}, + {{'9', '0'}}, {{'9', '1'}}, {{'9', '2'}}, {{'9', '3'}}, {{'9', '4'}}, {{'9', '5'}}, {{'9', '6'}}, {{'9', '7'}}, {{'9', '8'}}, {{'9', '9'}}, + } + }; + + // special case for "0" + if (x == 0) + { + o->write_character('0'); + return; + } + + // use a pointer to fill the buffer + auto buffer_ptr = number_buffer.begin(); // NOLINT(llvm-qualified-auto,readability-qualified-auto,cppcoreguidelines-pro-type-vararg,hicpp-vararg) + + const bool is_negative = std::is_signed::value && !(x >= 0); // see issue #755 + number_unsigned_t abs_value; + + unsigned int n_chars{}; + + if (is_negative) + { + *buffer_ptr = '-'; + abs_value = remove_sign(static_cast(x)); + + // account one more byte for the minus sign + n_chars = 1 + count_digits(abs_value); + } + else + { + abs_value = static_cast(x); + n_chars = count_digits(abs_value); + } + + // spare 1 byte for '\0' + JSON_ASSERT(n_chars < number_buffer.size() - 1); + + // jump to the end to generate the string from backward + // so we later avoid reversing the result + buffer_ptr += n_chars; + + // Fast int2ascii implementation inspired by "Fastware" talk by Andrei Alexandrescu + // See: https://www.youtube.com/watch?v=o4-CwDo2zpg + while (abs_value >= 100) + { + const auto digits_index = static_cast((abs_value % 100)); + abs_value /= 100; + *(--buffer_ptr) = digits_to_99[digits_index][1]; + *(--buffer_ptr) = digits_to_99[digits_index][0]; + } + + if (abs_value >= 10) + { + const auto digits_index = static_cast(abs_value); + *(--buffer_ptr) = digits_to_99[digits_index][1]; + *(--buffer_ptr) = digits_to_99[digits_index][0]; + } + else + { + *(--buffer_ptr) = static_cast('0' + abs_value); + } + + o->write_characters(number_buffer.data(), n_chars); + } + + /*! + @brief dump a floating-point number + + Dump a given floating-point number to output stream @a o. Works internally + with @a number_buffer. + + @param[in] x floating-point number to dump + */ + void dump_float(number_float_t x) + { + // NaN / inf + if (!std::isfinite(x)) + { + o->write_characters("null", 4); + return; + } + + // If number_float_t is an IEEE-754 single or double precision number, + // use the Grisu2 algorithm to produce short numbers which are + // guaranteed to round-trip, using strtof and strtod, resp. + // + // NB: The test below works if == . + static constexpr bool is_ieee_single_or_double + = (std::numeric_limits::is_iec559 && std::numeric_limits::digits == 24 && std::numeric_limits::max_exponent == 128) || + (std::numeric_limits::is_iec559 && std::numeric_limits::digits == 53 && std::numeric_limits::max_exponent == 1024); + + dump_float(x, std::integral_constant()); + } + + void dump_float(number_float_t x, std::true_type /*is_ieee_single_or_double*/) + { + auto* begin = number_buffer.data(); + auto* end = ::nlohmann::detail::to_chars(begin, begin + number_buffer.size(), x); + + o->write_characters(begin, static_cast(end - begin)); + } + + void dump_float(number_float_t x, std::false_type /*is_ieee_single_or_double*/) + { + // get number of digits for a float -> text -> float round-trip + static constexpr auto d = std::numeric_limits::max_digits10; + + // the actual conversion + // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + std::ptrdiff_t len = (std::snprintf)(number_buffer.data(), number_buffer.size(), "%.*g", d, x); + + // negative value indicates an error + JSON_ASSERT(len > 0); + // check if buffer was large enough + JSON_ASSERT(static_cast(len) < number_buffer.size()); + + // erase thousands separator + if (thousands_sep != '\0') + { + // NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::remove returns an iterator, see https://github.com/nlohmann/json/issues/3081 + const auto end = std::remove(number_buffer.begin(), number_buffer.begin() + len, thousands_sep); + std::fill(end, number_buffer.end(), '\0'); + JSON_ASSERT((end - number_buffer.begin()) <= len); + len = (end - number_buffer.begin()); + } + + // convert decimal point to '.' + if (decimal_point != '\0' && decimal_point != '.') + { + // NOLINTNEXTLINE(readability-qualified-auto,llvm-qualified-auto): std::find returns an iterator, see https://github.com/nlohmann/json/issues/3081 + const auto dec_pos = std::find(number_buffer.begin(), number_buffer.end(), decimal_point); + if (dec_pos != number_buffer.end()) + { + *dec_pos = '.'; + } + } + + o->write_characters(number_buffer.data(), static_cast(len)); + + // determine if need to append ".0" + const bool value_is_int_like = + std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1, + [](char c) + { + return c == '.' || c == 'e'; + }); + + if (value_is_int_like) + { + o->write_characters(".0", 2); + } + } + + /*! + @brief check whether a string is UTF-8 encoded + + The function checks each byte of a string whether it is UTF-8 encoded. The + result of the check is stored in the @a state parameter. The function must + be called initially with state 0 (accept). State 1 means the string must + be rejected, because the current byte is not allowed. If the string is + completely processed, but the state is non-zero, the string ended + prematurely; that is, the last byte indicated more bytes should have + followed. + + @param[in,out] state the state of the decoding + @param[in,out] codep codepoint (valid only if resulting state is UTF8_ACCEPT) + @param[in] byte next byte to decode + @return new state + + @note The function has been edited: a std::array is used. + + @copyright Copyright (c) 2008-2009 Bjoern Hoehrmann + @sa http://bjoern.hoehrmann.de/utf-8/decoder/dfa/ + */ + static std::uint8_t decode(std::uint8_t& state, std::uint32_t& codep, const std::uint8_t byte) noexcept + { + static const std::array utf8d = + { + { + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00..1F + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 20..3F + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 40..5F + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 60..7F + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, 9, // 80..9F + 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, 7, // A0..BF + 8, 8, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, // C0..DF + 0xA, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x3, 0x4, 0x3, 0x3, // E0..EF + 0xB, 0x6, 0x6, 0x6, 0x5, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, 0x8, // F0..FF + 0x0, 0x1, 0x2, 0x3, 0x5, 0x8, 0x7, 0x1, 0x1, 0x1, 0x4, 0x6, 0x1, 0x1, 0x1, 0x1, // s0..s0 + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 1, // s1..s2 + 1, 2, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, // s3..s4 + 1, 2, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, // s5..s6 + 1, 3, 1, 1, 1, 1, 1, 3, 1, 3, 1, 1, 1, 1, 1, 1, 1, 3, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 // s7..s8 + } + }; + + JSON_ASSERT(byte < utf8d.size()); + const std::uint8_t type = utf8d[byte]; + + codep = (state != UTF8_ACCEPT) + ? (byte & 0x3fu) | (codep << 6u) + : (0xFFu >> type) & (byte); + + std::size_t index = 256u + static_cast(state) * 16u + static_cast(type); + JSON_ASSERT(index < 400); + state = utf8d[index]; + return state; + } + + /* + * Overload to make the compiler happy while it is instantiating + * dump_integer for number_unsigned_t. + * Must never be called. + */ + number_unsigned_t remove_sign(number_unsigned_t x) + { + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + return x; // LCOV_EXCL_LINE + } + + /* + * Helper function for dump_integer + * + * This function takes a negative signed integer and returns its absolute + * value as unsigned integer. The plus/minus shuffling is necessary as we can + * not directly remove the sign of an arbitrary signed integer as the + * absolute values of INT_MIN and INT_MAX are usually not the same. See + * #1708 for details. + */ + inline number_unsigned_t remove_sign(number_integer_t x) noexcept + { + JSON_ASSERT(x < 0 && x < (std::numeric_limits::max)()); // NOLINT(misc-redundant-expression) + return static_cast(-(x + 1)) + 1; + } + + private: + /// the output of the serializer + output_adapter_t o = nullptr; + + /// a (hopefully) large enough character buffer + std::array number_buffer{{}}; + + /// the locale + const std::lconv* loc = nullptr; + /// the locale's thousand separator character + const char thousands_sep = '\0'; + /// the locale's decimal point character + const char decimal_point = '\0'; + + /// string buffer + std::array string_buffer{{}}; + + /// the indentation character + const char indent_char; + /// the indentation string + string_t indent_string; + + /// error_handler how to react on decoding errors + const error_handler_t error_handler; +}; +} // namespace detail +} // namespace nlohmann + +// #include + +// #include + +// #include + + +#include // less +#include // initializer_list +#include // input_iterator_tag, iterator_traits +#include // allocator +#include // for out_of_range +#include // enable_if, is_convertible +#include // pair +#include // vector + +// #include + + +namespace nlohmann +{ + +/// ordered_map: a minimal map-like container that preserves insertion order +/// for use within nlohmann::basic_json +template , + class Allocator = std::allocator>> + struct ordered_map : std::vector, Allocator> +{ + using key_type = Key; + using mapped_type = T; + using Container = std::vector, Allocator>; + using typename Container::iterator; + using typename Container::const_iterator; + using typename Container::size_type; + using typename Container::value_type; + + // Explicit constructors instead of `using Container::Container` + // otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4) + ordered_map(const Allocator& alloc = Allocator()) : Container{alloc} {} + template + ordered_map(It first, It last, const Allocator& alloc = Allocator()) + : Container{first, last, alloc} {} + ordered_map(std::initializer_list init, const Allocator& alloc = Allocator() ) + : Container{init, alloc} {} + + std::pair emplace(const key_type& key, T&& t) + { + for (auto it = this->begin(); it != this->end(); ++it) + { + if (it->first == key) + { + return {it, false}; + } + } + Container::emplace_back(key, t); + return {--this->end(), true}; + } + + T& operator[](const Key& key) + { + return emplace(key, T{}).first->second; + } + + const T& operator[](const Key& key) const + { + return at(key); + } + + T& at(const Key& key) + { + for (auto it = this->begin(); it != this->end(); ++it) + { + if (it->first == key) + { + return it->second; + } + } + + JSON_THROW(std::out_of_range("key not found")); + } + + const T& at(const Key& key) const + { + for (auto it = this->begin(); it != this->end(); ++it) + { + if (it->first == key) + { + return it->second; + } + } + + JSON_THROW(std::out_of_range("key not found")); + } + + size_type erase(const Key& key) + { + for (auto it = this->begin(); it != this->end(); ++it) + { + if (it->first == key) + { + // Since we cannot move const Keys, re-construct them in place + for (auto next = it; ++next != this->end(); ++it) + { + it->~value_type(); // Destroy but keep allocation + new (&*it) value_type{std::move(*next)}; + } + Container::pop_back(); + return 1; + } + } + return 0; + } + + iterator erase(iterator pos) + { + auto it = pos; + + // Since we cannot move const Keys, re-construct them in place + for (auto next = it; ++next != this->end(); ++it) + { + it->~value_type(); // Destroy but keep allocation + new (&*it) value_type{std::move(*next)}; + } + Container::pop_back(); + return pos; + } + + size_type count(const Key& key) const + { + for (auto it = this->begin(); it != this->end(); ++it) + { + if (it->first == key) + { + return 1; + } + } + return 0; + } + + iterator find(const Key& key) + { + for (auto it = this->begin(); it != this->end(); ++it) + { + if (it->first == key) + { + return it; + } + } + return Container::end(); + } + + const_iterator find(const Key& key) const + { + for (auto it = this->begin(); it != this->end(); ++it) + { + if (it->first == key) + { + return it; + } + } + return Container::end(); + } + + std::pair insert( value_type&& value ) + { + return emplace(value.first, std::move(value.second)); + } + + std::pair insert( const value_type& value ) + { + for (auto it = this->begin(); it != this->end(); ++it) + { + if (it->first == value.first) + { + return {it, false}; + } + } + Container::push_back(value); + return {--this->end(), true}; + } + + template + using require_input_iter = typename std::enable_if::iterator_category, + std::input_iterator_tag>::value>::type; + + template> + void insert(InputIt first, InputIt last) + { + for (auto it = first; it != last; ++it) + { + insert(*it); + } + } +}; + +} // namespace nlohmann + + +#if defined(JSON_HAS_CPP_17) + #include +#endif + +/*! +@brief namespace for Niels Lohmann +@see https://github.com/nlohmann +@since version 1.0.0 +*/ +namespace nlohmann +{ + +/*! +@brief a class to store JSON values + +@tparam ObjectType type for JSON objects (`std::map` by default; will be used +in @ref object_t) +@tparam ArrayType type for JSON arrays (`std::vector` by default; will be used +in @ref array_t) +@tparam StringType type for JSON strings and object keys (`std::string` by +default; will be used in @ref string_t) +@tparam BooleanType type for JSON booleans (`bool` by default; will be used +in @ref boolean_t) +@tparam NumberIntegerType type for JSON integer numbers (`int64_t` by +default; will be used in @ref number_integer_t) +@tparam NumberUnsignedType type for JSON unsigned integer numbers (@c +`uint64_t` by default; will be used in @ref number_unsigned_t) +@tparam NumberFloatType type for JSON floating-point numbers (`double` by +default; will be used in @ref number_float_t) +@tparam BinaryType type for packed binary data for compatibility with binary +serialization formats (`std::vector` by default; will be used in +@ref binary_t) +@tparam AllocatorType type of the allocator to use (`std::allocator` by +default) +@tparam JSONSerializer the serializer to resolve internal calls to `to_json()` +and `from_json()` (@ref adl_serializer by default) + +@requirement The class satisfies the following concept requirements: +- Basic + - [DefaultConstructible](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible): + JSON values can be default constructed. The result will be a JSON null + value. + - [MoveConstructible](https://en.cppreference.com/w/cpp/named_req/MoveConstructible): + A JSON value can be constructed from an rvalue argument. + - [CopyConstructible](https://en.cppreference.com/w/cpp/named_req/CopyConstructible): + A JSON value can be copy-constructed from an lvalue expression. + - [MoveAssignable](https://en.cppreference.com/w/cpp/named_req/MoveAssignable): + A JSON value van be assigned from an rvalue argument. + - [CopyAssignable](https://en.cppreference.com/w/cpp/named_req/CopyAssignable): + A JSON value can be copy-assigned from an lvalue expression. + - [Destructible](https://en.cppreference.com/w/cpp/named_req/Destructible): + JSON values can be destructed. +- Layout + - [StandardLayoutType](https://en.cppreference.com/w/cpp/named_req/StandardLayoutType): + JSON values have + [standard layout](https://en.cppreference.com/w/cpp/language/data_members#Standard_layout): + All non-static data members are private and standard layout types, the + class has no virtual functions or (virtual) base classes. +- Library-wide + - [EqualityComparable](https://en.cppreference.com/w/cpp/named_req/EqualityComparable): + JSON values can be compared with `==`, see @ref + operator==(const_reference,const_reference). + - [LessThanComparable](https://en.cppreference.com/w/cpp/named_req/LessThanComparable): + JSON values can be compared with `<`, see @ref + operator<(const_reference,const_reference). + - [Swappable](https://en.cppreference.com/w/cpp/named_req/Swappable): + Any JSON lvalue or rvalue of can be swapped with any lvalue or rvalue of + other compatible types, using unqualified function call @ref swap(). + - [NullablePointer](https://en.cppreference.com/w/cpp/named_req/NullablePointer): + JSON values can be compared against `std::nullptr_t` objects which are used + to model the `null` value. +- Container + - [Container](https://en.cppreference.com/w/cpp/named_req/Container): + JSON values can be used like STL containers and provide iterator access. + - [ReversibleContainer](https://en.cppreference.com/w/cpp/named_req/ReversibleContainer); + JSON values can be used like STL containers and provide reverse iterator + access. + +@invariant The member variables @a m_value and @a m_type have the following +relationship: +- If `m_type == value_t::object`, then `m_value.object != nullptr`. +- If `m_type == value_t::array`, then `m_value.array != nullptr`. +- If `m_type == value_t::string`, then `m_value.string != nullptr`. +The invariants are checked by member function assert_invariant(). + +@internal +@note ObjectType trick from https://stackoverflow.com/a/9860911 +@endinternal + +@see [RFC 8259: The JavaScript Object Notation (JSON) Data Interchange +Format](https://tools.ietf.org/html/rfc8259) + +@since version 1.0.0 + +@nosubgrouping +*/ +NLOHMANN_BASIC_JSON_TPL_DECLARATION +class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) +{ + private: + template friend struct detail::external_constructor; + friend ::nlohmann::json_pointer; + + template + friend class ::nlohmann::detail::parser; + friend ::nlohmann::detail::serializer; + template + friend class ::nlohmann::detail::iter_impl; + template + friend class ::nlohmann::detail::binary_writer; + template + friend class ::nlohmann::detail::binary_reader; + template + friend class ::nlohmann::detail::json_sax_dom_parser; + template + friend class ::nlohmann::detail::json_sax_dom_callback_parser; + friend class ::nlohmann::detail::exception; + + /// workaround type for MSVC + using basic_json_t = NLOHMANN_BASIC_JSON_TPL; + + JSON_PRIVATE_UNLESS_TESTED: + // convenience aliases for types residing in namespace detail; + using lexer = ::nlohmann::detail::lexer_base; + + template + static ::nlohmann::detail::parser parser( + InputAdapterType adapter, + detail::parser_callback_tcb = nullptr, + const bool allow_exceptions = true, + const bool ignore_comments = false + ) + { + return ::nlohmann::detail::parser(std::move(adapter), + std::move(cb), allow_exceptions, ignore_comments); + } + + private: + using primitive_iterator_t = ::nlohmann::detail::primitive_iterator_t; + template + using internal_iterator = ::nlohmann::detail::internal_iterator; + template + using iter_impl = ::nlohmann::detail::iter_impl; + template + using iteration_proxy = ::nlohmann::detail::iteration_proxy; + template using json_reverse_iterator = ::nlohmann::detail::json_reverse_iterator; + + template + using output_adapter_t = ::nlohmann::detail::output_adapter_t; + + template + using binary_reader = ::nlohmann::detail::binary_reader; + template using binary_writer = ::nlohmann::detail::binary_writer; + + JSON_PRIVATE_UNLESS_TESTED: + using serializer = ::nlohmann::detail::serializer; + + public: + using value_t = detail::value_t; + /// JSON Pointer, see @ref nlohmann::json_pointer + using json_pointer = ::nlohmann::json_pointer; + template + using json_serializer = JSONSerializer; + /// how to treat decoding errors + using error_handler_t = detail::error_handler_t; + /// how to treat CBOR tags + using cbor_tag_handler_t = detail::cbor_tag_handler_t; + /// helper type for initializer lists of basic_json values + using initializer_list_t = std::initializer_list>; + + using input_format_t = detail::input_format_t; + /// SAX interface type, see @ref nlohmann::json_sax + using json_sax_t = json_sax; + + //////////////// + // exceptions // + //////////////// + + /// @name exceptions + /// Classes to implement user-defined exceptions. + /// @{ + + /// @copydoc detail::exception + using exception = detail::exception; + /// @copydoc detail::parse_error + using parse_error = detail::parse_error; + /// @copydoc detail::invalid_iterator + using invalid_iterator = detail::invalid_iterator; + /// @copydoc detail::type_error + using type_error = detail::type_error; + /// @copydoc detail::out_of_range + using out_of_range = detail::out_of_range; + /// @copydoc detail::other_error + using other_error = detail::other_error; + + /// @} + + + ///////////////////// + // container types // + ///////////////////// + + /// @name container types + /// The canonic container types to use @ref basic_json like any other STL + /// container. + /// @{ + + /// the type of elements in a basic_json container + using value_type = basic_json; + + /// the type of an element reference + using reference = value_type&; + /// the type of an element const reference + using const_reference = const value_type&; + + /// a type to represent differences between iterators + using difference_type = std::ptrdiff_t; + /// a type to represent container sizes + using size_type = std::size_t; + + /// the allocator type + using allocator_type = AllocatorType; + + /// the type of an element pointer + using pointer = typename std::allocator_traits::pointer; + /// the type of an element const pointer + using const_pointer = typename std::allocator_traits::const_pointer; + + /// an iterator for a basic_json container + using iterator = iter_impl; + /// a const iterator for a basic_json container + using const_iterator = iter_impl; + /// a reverse iterator for a basic_json container + using reverse_iterator = json_reverse_iterator; + /// a const reverse iterator for a basic_json container + using const_reverse_iterator = json_reverse_iterator; + + /// @} + + + /*! + @brief returns the allocator associated with the container + */ + static allocator_type get_allocator() + { + return allocator_type(); + } + + /*! + @brief returns version information on the library + + This function returns a JSON object with information about the library, + including the version number and information on the platform and compiler. + + @return JSON object holding version information + key | description + ----------- | --------------- + `compiler` | Information on the used compiler. It is an object with the following keys: `c++` (the used C++ standard), `family` (the compiler family; possible values are `clang`, `icc`, `gcc`, `ilecpp`, `msvc`, `pgcpp`, `sunpro`, and `unknown`), and `version` (the compiler version). + `copyright` | The copyright line for the library as string. + `name` | The name of the library as string. + `platform` | The used platform as string. Possible values are `win32`, `linux`, `apple`, `unix`, and `unknown`. + `url` | The URL of the project as string. + `version` | The version of the library. It is an object with the following keys: `major`, `minor`, and `patch` as defined by [Semantic Versioning](http://semver.org), and `string` (the version string). + + @liveexample{The following code shows an example output of the `meta()` + function.,meta} + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. + + @complexity Constant. + + @since 2.1.0 + */ + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json meta() + { + basic_json result; + + result["copyright"] = "(C) 2013-2021 Niels Lohmann"; + result["name"] = "JSON for Modern C++"; + result["url"] = "https://github.com/nlohmann/json"; + result["version"]["string"] = + std::to_string(NLOHMANN_JSON_VERSION_MAJOR) + "." + + std::to_string(NLOHMANN_JSON_VERSION_MINOR) + "." + + std::to_string(NLOHMANN_JSON_VERSION_PATCH); + result["version"]["major"] = NLOHMANN_JSON_VERSION_MAJOR; + result["version"]["minor"] = NLOHMANN_JSON_VERSION_MINOR; + result["version"]["patch"] = NLOHMANN_JSON_VERSION_PATCH; + +#ifdef _WIN32 + result["platform"] = "win32"; +#elif defined __linux__ + result["platform"] = "linux"; +#elif defined __APPLE__ + result["platform"] = "apple"; +#elif defined __unix__ + result["platform"] = "unix"; +#else + result["platform"] = "unknown"; +#endif + +#if defined(__ICC) || defined(__INTEL_COMPILER) + result["compiler"] = {{"family", "icc"}, {"version", __INTEL_COMPILER}}; +#elif defined(__clang__) + result["compiler"] = {{"family", "clang"}, {"version", __clang_version__}}; +#elif defined(__GNUC__) || defined(__GNUG__) + result["compiler"] = {{"family", "gcc"}, {"version", std::to_string(__GNUC__) + "." + std::to_string(__GNUC_MINOR__) + "." + std::to_string(__GNUC_PATCHLEVEL__)}}; +#elif defined(__HP_cc) || defined(__HP_aCC) + result["compiler"] = "hp" +#elif defined(__IBMCPP__) + result["compiler"] = {{"family", "ilecpp"}, {"version", __IBMCPP__}}; +#elif defined(_MSC_VER) + result["compiler"] = {{"family", "msvc"}, {"version", _MSC_VER}}; +#elif defined(__PGI) + result["compiler"] = {{"family", "pgcpp"}, {"version", __PGI}}; +#elif defined(__SUNPRO_CC) + result["compiler"] = {{"family", "sunpro"}, {"version", __SUNPRO_CC}}; +#else + result["compiler"] = {{"family", "unknown"}, {"version", "unknown"}}; +#endif + +#ifdef __cplusplus + result["compiler"]["c++"] = std::to_string(__cplusplus); +#else + result["compiler"]["c++"] = "unknown"; +#endif + return result; + } + + + /////////////////////////// + // JSON value data types // + /////////////////////////// + + /// @name JSON value data types + /// The data types to store a JSON value. These types are derived from + /// the template arguments passed to class @ref basic_json. + /// @{ + +#if defined(JSON_HAS_CPP_14) + // Use transparent comparator if possible, combined with perfect forwarding + // on find() and count() calls prevents unnecessary string construction. + using object_comparator_t = std::less<>; +#else + using object_comparator_t = std::less; +#endif + + /*! + @brief a type for an object + + [RFC 8259](https://tools.ietf.org/html/rfc8259) describes JSON objects as follows: + > An object is an unordered collection of zero or more name/value pairs, + > where a name is a string and a value is a string, number, boolean, null, + > object, or array. + + To store objects in C++, a type is defined by the template parameters + described below. + + @tparam ObjectType the container to store objects (e.g., `std::map` or + `std::unordered_map`) + @tparam StringType the type of the keys or names (e.g., `std::string`). + The comparison function `std::less` is used to order elements + inside the container. + @tparam AllocatorType the allocator to use for objects (e.g., + `std::allocator`) + + #### Default type + + With the default values for @a ObjectType (`std::map`), @a StringType + (`std::string`), and @a AllocatorType (`std::allocator`), the default + value for @a object_t is: + + @code {.cpp} + std::map< + std::string, // key_type + basic_json, // value_type + std::less, // key_compare + std::allocator> // allocator_type + > + @endcode + + #### Behavior + + The choice of @a object_t influences the behavior of the JSON class. With + the default type, objects have the following behavior: + + - When all names are unique, objects will be interoperable in the sense + that all software implementations receiving that object will agree on + the name-value mappings. + - When the names within an object are not unique, it is unspecified which + one of the values for a given key will be chosen. For instance, + `{"key": 2, "key": 1}` could be equal to either `{"key": 1}` or + `{"key": 2}`. + - Internally, name/value pairs are stored in lexicographical order of the + names. Objects will also be serialized (see @ref dump) in this order. + For instance, `{"b": 1, "a": 2}` and `{"a": 2, "b": 1}` will be stored + and serialized as `{"a": 2, "b": 1}`. + - When comparing objects, the order of the name/value pairs is irrelevant. + This makes objects interoperable in the sense that they will not be + affected by these differences. For instance, `{"b": 1, "a": 2}` and + `{"a": 2, "b": 1}` will be treated as equal. + + #### Limits + + [RFC 8259](https://tools.ietf.org/html/rfc8259) specifies: + > An implementation may set limits on the maximum depth of nesting. + + In this class, the object's limit of nesting is not explicitly constrained. + However, a maximum depth of nesting may be introduced by the compiler or + runtime environment. A theoretical limit can be queried by calling the + @ref max_size function of a JSON object. + + #### Storage + + Objects are stored as pointers in a @ref basic_json type. That is, for any + access to object values, a pointer of type `object_t*` must be + dereferenced. + + @sa see @ref array_t -- type for an array value + + @since version 1.0.0 + + @note The order name/value pairs are added to the object is *not* + preserved by the library. Therefore, iterating an object may return + name/value pairs in a different order than they were originally stored. In + fact, keys will be traversed in alphabetical order as `std::map` with + `std::less` is used by default. Please note this behavior conforms to [RFC + 8259](https://tools.ietf.org/html/rfc8259), because any order implements the + specified "unordered" nature of JSON objects. + */ + using object_t = ObjectType>>; + + /*! + @brief a type for an array + + [RFC 8259](https://tools.ietf.org/html/rfc8259) describes JSON arrays as follows: + > An array is an ordered sequence of zero or more values. + + To store objects in C++, a type is defined by the template parameters + explained below. + + @tparam ArrayType container type to store arrays (e.g., `std::vector` or + `std::list`) + @tparam AllocatorType allocator to use for arrays (e.g., `std::allocator`) + + #### Default type + + With the default values for @a ArrayType (`std::vector`) and @a + AllocatorType (`std::allocator`), the default value for @a array_t is: + + @code {.cpp} + std::vector< + basic_json, // value_type + std::allocator // allocator_type + > + @endcode + + #### Limits + + [RFC 8259](https://tools.ietf.org/html/rfc8259) specifies: + > An implementation may set limits on the maximum depth of nesting. + + In this class, the array's limit of nesting is not explicitly constrained. + However, a maximum depth of nesting may be introduced by the compiler or + runtime environment. A theoretical limit can be queried by calling the + @ref max_size function of a JSON array. + + #### Storage + + Arrays are stored as pointers in a @ref basic_json type. That is, for any + access to array values, a pointer of type `array_t*` must be dereferenced. + + @sa see @ref object_t -- type for an object value + + @since version 1.0.0 + */ + using array_t = ArrayType>; + + /*! + @brief a type for a string + + [RFC 8259](https://tools.ietf.org/html/rfc8259) describes JSON strings as follows: + > A string is a sequence of zero or more Unicode characters. + + To store objects in C++, a type is defined by the template parameter + described below. Unicode values are split by the JSON class into + byte-sized characters during deserialization. + + @tparam StringType the container to store strings (e.g., `std::string`). + Note this container is used for keys/names in objects, see @ref object_t. + + #### Default type + + With the default values for @a StringType (`std::string`), the default + value for @a string_t is: + + @code {.cpp} + std::string + @endcode + + #### Encoding + + Strings are stored in UTF-8 encoding. Therefore, functions like + `std::string::size()` or `std::string::length()` return the number of + bytes in the string rather than the number of characters or glyphs. + + #### String comparison + + [RFC 8259](https://tools.ietf.org/html/rfc8259) states: + > Software implementations are typically required to test names of object + > members for equality. Implementations that transform the textual + > representation into sequences of Unicode code units and then perform the + > comparison numerically, code unit by code unit, are interoperable in the + > sense that implementations will agree in all cases on equality or + > inequality of two strings. For example, implementations that compare + > strings with escaped characters unconverted may incorrectly find that + > `"a\\b"` and `"a\u005Cb"` are not equal. + + This implementation is interoperable as it does compare strings code unit + by code unit. + + #### Storage + + String values are stored as pointers in a @ref basic_json type. That is, + for any access to string values, a pointer of type `string_t*` must be + dereferenced. + + @since version 1.0.0 + */ + using string_t = StringType; + + /*! + @brief a type for a boolean + + [RFC 8259](https://tools.ietf.org/html/rfc8259) implicitly describes a boolean as a + type which differentiates the two literals `true` and `false`. + + To store objects in C++, a type is defined by the template parameter @a + BooleanType which chooses the type to use. + + #### Default type + + With the default values for @a BooleanType (`bool`), the default value for + @a boolean_t is: + + @code {.cpp} + bool + @endcode + + #### Storage + + Boolean values are stored directly inside a @ref basic_json type. + + @since version 1.0.0 + */ + using boolean_t = BooleanType; + + /*! + @brief a type for a number (integer) + + [RFC 8259](https://tools.ietf.org/html/rfc8259) describes numbers as follows: + > The representation of numbers is similar to that used in most + > programming languages. A number is represented in base 10 using decimal + > digits. It contains an integer component that may be prefixed with an + > optional minus sign, which may be followed by a fraction part and/or an + > exponent part. Leading zeros are not allowed. (...) Numeric values that + > cannot be represented in the grammar below (such as Infinity and NaN) + > are not permitted. + + This description includes both integer and floating-point numbers. + However, C++ allows more precise storage if it is known whether the number + is a signed integer, an unsigned integer or a floating-point number. + Therefore, three different types, @ref number_integer_t, @ref + number_unsigned_t and @ref number_float_t are used. + + To store integer numbers in C++, a type is defined by the template + parameter @a NumberIntegerType which chooses the type to use. + + #### Default type + + With the default values for @a NumberIntegerType (`int64_t`), the default + value for @a number_integer_t is: + + @code {.cpp} + int64_t + @endcode + + #### Default behavior + + - The restrictions about leading zeros is not enforced in C++. Instead, + leading zeros in integer literals lead to an interpretation as octal + number. Internally, the value will be stored as decimal number. For + instance, the C++ integer literal `010` will be serialized to `8`. + During deserialization, leading zeros yield an error. + - Not-a-number (NaN) values will be serialized to `null`. + + #### Limits + + [RFC 8259](https://tools.ietf.org/html/rfc8259) specifies: + > An implementation may set limits on the range and precision of numbers. + + When the default type is used, the maximal integer number that can be + stored is `9223372036854775807` (INT64_MAX) and the minimal integer number + that can be stored is `-9223372036854775808` (INT64_MIN). Integer numbers + that are out of range will yield over/underflow when used in a + constructor. During deserialization, too large or small integer numbers + will be automatically be stored as @ref number_unsigned_t or @ref + number_float_t. + + [RFC 8259](https://tools.ietf.org/html/rfc8259) further states: + > Note that when such software is used, numbers that are integers and are + > in the range \f$[-2^{53}+1, 2^{53}-1]\f$ are interoperable in the sense + > that implementations will agree exactly on their numeric values. + + As this range is a subrange of the exactly supported range [INT64_MIN, + INT64_MAX], this class's integer type is interoperable. + + #### Storage + + Integer number values are stored directly inside a @ref basic_json type. + + @sa see @ref number_float_t -- type for number values (floating-point) + + @sa see @ref number_unsigned_t -- type for number values (unsigned integer) + + @since version 1.0.0 + */ + using number_integer_t = NumberIntegerType; + + /*! + @brief a type for a number (unsigned) + + [RFC 8259](https://tools.ietf.org/html/rfc8259) describes numbers as follows: + > The representation of numbers is similar to that used in most + > programming languages. A number is represented in base 10 using decimal + > digits. It contains an integer component that may be prefixed with an + > optional minus sign, which may be followed by a fraction part and/or an + > exponent part. Leading zeros are not allowed. (...) Numeric values that + > cannot be represented in the grammar below (such as Infinity and NaN) + > are not permitted. + + This description includes both integer and floating-point numbers. + However, C++ allows more precise storage if it is known whether the number + is a signed integer, an unsigned integer or a floating-point number. + Therefore, three different types, @ref number_integer_t, @ref + number_unsigned_t and @ref number_float_t are used. + + To store unsigned integer numbers in C++, a type is defined by the + template parameter @a NumberUnsignedType which chooses the type to use. + + #### Default type + + With the default values for @a NumberUnsignedType (`uint64_t`), the + default value for @a number_unsigned_t is: + + @code {.cpp} + uint64_t + @endcode + + #### Default behavior + + - The restrictions about leading zeros is not enforced in C++. Instead, + leading zeros in integer literals lead to an interpretation as octal + number. Internally, the value will be stored as decimal number. For + instance, the C++ integer literal `010` will be serialized to `8`. + During deserialization, leading zeros yield an error. + - Not-a-number (NaN) values will be serialized to `null`. + + #### Limits + + [RFC 8259](https://tools.ietf.org/html/rfc8259) specifies: + > An implementation may set limits on the range and precision of numbers. + + When the default type is used, the maximal integer number that can be + stored is `18446744073709551615` (UINT64_MAX) and the minimal integer + number that can be stored is `0`. Integer numbers that are out of range + will yield over/underflow when used in a constructor. During + deserialization, too large or small integer numbers will be automatically + be stored as @ref number_integer_t or @ref number_float_t. + + [RFC 8259](https://tools.ietf.org/html/rfc8259) further states: + > Note that when such software is used, numbers that are integers and are + > in the range \f$[-2^{53}+1, 2^{53}-1]\f$ are interoperable in the sense + > that implementations will agree exactly on their numeric values. + + As this range is a subrange (when considered in conjunction with the + number_integer_t type) of the exactly supported range [0, UINT64_MAX], + this class's integer type is interoperable. + + #### Storage + + Integer number values are stored directly inside a @ref basic_json type. + + @sa see @ref number_float_t -- type for number values (floating-point) + @sa see @ref number_integer_t -- type for number values (integer) + + @since version 2.0.0 + */ + using number_unsigned_t = NumberUnsignedType; + + /*! + @brief a type for a number (floating-point) + + [RFC 8259](https://tools.ietf.org/html/rfc8259) describes numbers as follows: + > The representation of numbers is similar to that used in most + > programming languages. A number is represented in base 10 using decimal + > digits. It contains an integer component that may be prefixed with an + > optional minus sign, which may be followed by a fraction part and/or an + > exponent part. Leading zeros are not allowed. (...) Numeric values that + > cannot be represented in the grammar below (such as Infinity and NaN) + > are not permitted. + + This description includes both integer and floating-point numbers. + However, C++ allows more precise storage if it is known whether the number + is a signed integer, an unsigned integer or a floating-point number. + Therefore, three different types, @ref number_integer_t, @ref + number_unsigned_t and @ref number_float_t are used. + + To store floating-point numbers in C++, a type is defined by the template + parameter @a NumberFloatType which chooses the type to use. + + #### Default type + + With the default values for @a NumberFloatType (`double`), the default + value for @a number_float_t is: + + @code {.cpp} + double + @endcode + + #### Default behavior + + - The restrictions about leading zeros is not enforced in C++. Instead, + leading zeros in floating-point literals will be ignored. Internally, + the value will be stored as decimal number. For instance, the C++ + floating-point literal `01.2` will be serialized to `1.2`. During + deserialization, leading zeros yield an error. + - Not-a-number (NaN) values will be serialized to `null`. + + #### Limits + + [RFC 8259](https://tools.ietf.org/html/rfc8259) states: + > This specification allows implementations to set limits on the range and + > precision of numbers accepted. Since software that implements IEEE + > 754-2008 binary64 (double precision) numbers is generally available and + > widely used, good interoperability can be achieved by implementations + > that expect no more precision or range than these provide, in the sense + > that implementations will approximate JSON numbers within the expected + > precision. + + This implementation does exactly follow this approach, as it uses double + precision floating-point numbers. Note values smaller than + `-1.79769313486232e+308` and values greater than `1.79769313486232e+308` + will be stored as NaN internally and be serialized to `null`. + + #### Storage + + Floating-point number values are stored directly inside a @ref basic_json + type. + + @sa see @ref number_integer_t -- type for number values (integer) + + @sa see @ref number_unsigned_t -- type for number values (unsigned integer) + + @since version 1.0.0 + */ + using number_float_t = NumberFloatType; + + /*! + @brief a type for a packed binary type + + This type is a type designed to carry binary data that appears in various + serialized formats, such as CBOR's Major Type 2, MessagePack's bin, and + BSON's generic binary subtype. This type is NOT a part of standard JSON and + exists solely for compatibility with these binary types. As such, it is + simply defined as an ordered sequence of zero or more byte values. + + Additionally, as an implementation detail, the subtype of the binary data is + carried around as a `std::uint8_t`, which is compatible with both of the + binary data formats that use binary subtyping, (though the specific + numbering is incompatible with each other, and it is up to the user to + translate between them). + + [CBOR's RFC 7049](https://tools.ietf.org/html/rfc7049) describes this type + as: + > Major type 2: a byte string. The string's length in bytes is represented + > following the rules for positive integers (major type 0). + + [MessagePack's documentation on the bin type + family](https://github.com/msgpack/msgpack/blob/master/spec.md#bin-format-family) + describes this type as: + > Bin format family stores an byte array in 2, 3, or 5 bytes of extra bytes + > in addition to the size of the byte array. + + [BSON's specifications](http://bsonspec.org/spec.html) describe several + binary types; however, this type is intended to represent the generic binary + type which has the description: + > Generic binary subtype - This is the most commonly used binary subtype and + > should be the 'default' for drivers and tools. + + None of these impose any limitations on the internal representation other + than the basic unit of storage be some type of array whose parts are + decomposable into bytes. + + The default representation of this binary format is a + `std::vector`, which is a very common way to represent a byte + array in modern C++. + + #### Default type + + The default values for @a BinaryType is `std::vector` + + #### Storage + + Binary Arrays are stored as pointers in a @ref basic_json type. That is, + for any access to array values, a pointer of the type `binary_t*` must be + dereferenced. + + #### Notes on subtypes + + - CBOR + - Binary values are represented as byte strings. Subtypes are serialized + as tagged values. + - MessagePack + - If a subtype is given and the binary array contains exactly 1, 2, 4, 8, + or 16 elements, the fixext family (fixext1, fixext2, fixext4, fixext8) + is used. For other sizes, the ext family (ext8, ext16, ext32) is used. + The subtype is then added as singed 8-bit integer. + - If no subtype is given, the bin family (bin8, bin16, bin32) is used. + - BSON + - If a subtype is given, it is used and added as unsigned 8-bit integer. + - If no subtype is given, the generic binary subtype 0x00 is used. + + @sa see @ref binary -- create a binary array + + @since version 3.8.0 + */ + using binary_t = nlohmann::byte_container_with_subtype; + /// @} + + private: + + /// helper for exception-safe object creation + template + JSON_HEDLEY_RETURNS_NON_NULL + static T* create(Args&& ... args) + { + AllocatorType alloc; + using AllocatorTraits = std::allocator_traits>; + + auto deleter = [&](T * obj) + { + AllocatorTraits::deallocate(alloc, obj, 1); + }; + std::unique_ptr obj(AllocatorTraits::allocate(alloc, 1), deleter); + AllocatorTraits::construct(alloc, obj.get(), std::forward(args)...); + JSON_ASSERT(obj != nullptr); + return obj.release(); + } + + //////////////////////// + // JSON value storage // + //////////////////////// + + JSON_PRIVATE_UNLESS_TESTED: + /*! + @brief a JSON value + + The actual storage for a JSON value of the @ref basic_json class. This + union combines the different storage types for the JSON value types + defined in @ref value_t. + + JSON type | value_t type | used type + --------- | --------------- | ------------------------ + object | object | pointer to @ref object_t + array | array | pointer to @ref array_t + string | string | pointer to @ref string_t + boolean | boolean | @ref boolean_t + number | number_integer | @ref number_integer_t + number | number_unsigned | @ref number_unsigned_t + number | number_float | @ref number_float_t + binary | binary | pointer to @ref binary_t + null | null | *no value is stored* + + @note Variable-length types (objects, arrays, and strings) are stored as + pointers. The size of the union should not exceed 64 bits if the default + value types are used. + + @since version 1.0.0 + */ + union json_value + { + /// object (stored with pointer to save storage) + object_t* object; + /// array (stored with pointer to save storage) + array_t* array; + /// string (stored with pointer to save storage) + string_t* string; + /// binary (stored with pointer to save storage) + binary_t* binary; + /// boolean + boolean_t boolean; + /// number (integer) + number_integer_t number_integer; + /// number (unsigned integer) + number_unsigned_t number_unsigned; + /// number (floating-point) + number_float_t number_float; + + /// default constructor (for null values) + json_value() = default; + /// constructor for booleans + json_value(boolean_t v) noexcept : boolean(v) {} + /// constructor for numbers (integer) + json_value(number_integer_t v) noexcept : number_integer(v) {} + /// constructor for numbers (unsigned) + json_value(number_unsigned_t v) noexcept : number_unsigned(v) {} + /// constructor for numbers (floating-point) + json_value(number_float_t v) noexcept : number_float(v) {} + /// constructor for empty values of a given type + json_value(value_t t) + { + switch (t) + { + case value_t::object: + { + object = create(); + break; + } + + case value_t::array: + { + array = create(); + break; + } + + case value_t::string: + { + string = create(""); + break; + } + + case value_t::binary: + { + binary = create(); + break; + } + + case value_t::boolean: + { + boolean = boolean_t(false); + break; + } + + case value_t::number_integer: + { + number_integer = number_integer_t(0); + break; + } + + case value_t::number_unsigned: + { + number_unsigned = number_unsigned_t(0); + break; + } + + case value_t::number_float: + { + number_float = number_float_t(0.0); + break; + } + + case value_t::null: + { + object = nullptr; // silence warning, see #821 + break; + } + + case value_t::discarded: + default: + { + object = nullptr; // silence warning, see #821 + if (JSON_HEDLEY_UNLIKELY(t == value_t::null)) + { + JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.10.4", basic_json())); // LCOV_EXCL_LINE + } + break; + } + } + } + + /// constructor for strings + json_value(const string_t& value) + { + string = create(value); + } + + /// constructor for rvalue strings + json_value(string_t&& value) + { + string = create(std::move(value)); + } + + /// constructor for objects + json_value(const object_t& value) + { + object = create(value); + } + + /// constructor for rvalue objects + json_value(object_t&& value) + { + object = create(std::move(value)); + } + + /// constructor for arrays + json_value(const array_t& value) + { + array = create(value); + } + + /// constructor for rvalue arrays + json_value(array_t&& value) + { + array = create(std::move(value)); + } + + /// constructor for binary arrays + json_value(const typename binary_t::container_type& value) + { + binary = create(value); + } + + /// constructor for rvalue binary arrays + json_value(typename binary_t::container_type&& value) + { + binary = create(std::move(value)); + } + + /// constructor for binary arrays (internal type) + json_value(const binary_t& value) + { + binary = create(value); + } + + /// constructor for rvalue binary arrays (internal type) + json_value(binary_t&& value) + { + binary = create(std::move(value)); + } + + void destroy(value_t t) + { + if (t == value_t::array || t == value_t::object) + { + // flatten the current json_value to a heap-allocated stack + std::vector stack; + + // move the top-level items to stack + if (t == value_t::array) + { + stack.reserve(array->size()); + std::move(array->begin(), array->end(), std::back_inserter(stack)); + } + else + { + stack.reserve(object->size()); + for (auto&& it : *object) + { + stack.push_back(std::move(it.second)); + } + } + + while (!stack.empty()) + { + // move the last item to local variable to be processed + basic_json current_item(std::move(stack.back())); + stack.pop_back(); + + // if current_item is array/object, move + // its children to the stack to be processed later + if (current_item.is_array()) + { + std::move(current_item.m_value.array->begin(), current_item.m_value.array->end(), std::back_inserter(stack)); + + current_item.m_value.array->clear(); + } + else if (current_item.is_object()) + { + for (auto&& it : *current_item.m_value.object) + { + stack.push_back(std::move(it.second)); + } + + current_item.m_value.object->clear(); + } + + // it's now safe that current_item get destructed + // since it doesn't have any children + } + } + + switch (t) + { + case value_t::object: + { + AllocatorType alloc; + std::allocator_traits::destroy(alloc, object); + std::allocator_traits::deallocate(alloc, object, 1); + break; + } + + case value_t::array: + { + AllocatorType alloc; + std::allocator_traits::destroy(alloc, array); + std::allocator_traits::deallocate(alloc, array, 1); + break; + } + + case value_t::string: + { + AllocatorType alloc; + std::allocator_traits::destroy(alloc, string); + std::allocator_traits::deallocate(alloc, string, 1); + break; + } + + case value_t::binary: + { + AllocatorType alloc; + std::allocator_traits::destroy(alloc, binary); + std::allocator_traits::deallocate(alloc, binary, 1); + break; + } + + case value_t::null: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::discarded: + default: + { + break; + } + } + } + }; + + private: + /*! + @brief checks the class invariants + + This function asserts the class invariants. It needs to be called at the + end of every constructor to make sure that created objects respect the + invariant. Furthermore, it has to be called each time the type of a JSON + value is changed, because the invariant expresses a relationship between + @a m_type and @a m_value. + + Furthermore, the parent relation is checked for arrays and objects: If + @a check_parents true and the value is an array or object, then the + container's elements must have the current value as parent. + + @param[in] check_parents whether the parent relation should be checked. + The value is true by default and should only be set to false + during destruction of objects when the invariant does not + need to hold. + */ + void assert_invariant(bool check_parents = true) const noexcept + { + JSON_ASSERT(m_type != value_t::object || m_value.object != nullptr); + JSON_ASSERT(m_type != value_t::array || m_value.array != nullptr); + JSON_ASSERT(m_type != value_t::string || m_value.string != nullptr); + JSON_ASSERT(m_type != value_t::binary || m_value.binary != nullptr); + +#if JSON_DIAGNOSTICS + JSON_TRY + { + // cppcheck-suppress assertWithSideEffect + JSON_ASSERT(!check_parents || !is_structured() || std::all_of(begin(), end(), [this](const basic_json & j) + { + return j.m_parent == this; + })); + } + JSON_CATCH(...) {} // LCOV_EXCL_LINE +#endif + static_cast(check_parents); + } + + void set_parents() + { +#if JSON_DIAGNOSTICS + switch (m_type) + { + case value_t::array: + { + for (auto& element : *m_value.array) + { + element.m_parent = this; + } + break; + } + + case value_t::object: + { + for (auto& element : *m_value.object) + { + element.second.m_parent = this; + } + break; + } + + case value_t::null: + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + break; + } +#endif + } + + iterator set_parents(iterator it, typename iterator::difference_type count) + { +#if JSON_DIAGNOSTICS + for (typename iterator::difference_type i = 0; i < count; ++i) + { + (it + i)->m_parent = this; + } +#else + static_cast(count); +#endif + return it; + } + + reference set_parent(reference j, std::size_t old_capacity = std::size_t(-1)) + { +#if JSON_DIAGNOSTICS + if (old_capacity != std::size_t(-1)) + { + // see https://github.com/nlohmann/json/issues/2838 + JSON_ASSERT(type() == value_t::array); + if (JSON_HEDLEY_UNLIKELY(m_value.array->capacity() != old_capacity)) + { + // capacity has changed: update all parents + set_parents(); + return j; + } + } + + // ordered_json uses a vector internally, so pointers could have + // been invalidated; see https://github.com/nlohmann/json/issues/2962 +#ifdef JSON_HEDLEY_MSVC_VERSION +#pragma warning(push ) +#pragma warning(disable : 4127) // ignore warning to replace if with if constexpr +#endif + if (detail::is_ordered_map::value) + { + set_parents(); + return j; + } +#ifdef JSON_HEDLEY_MSVC_VERSION +#pragma warning( pop ) +#endif + + j.m_parent = this; +#else + static_cast(j); + static_cast(old_capacity); +#endif + return j; + } + + public: + ////////////////////////// + // JSON parser callback // + ////////////////////////// + + /*! + @brief parser event types + + The parser callback distinguishes the following events: + - `object_start`: the parser read `{` and started to process a JSON object + - `key`: the parser read a key of a value in an object + - `object_end`: the parser read `}` and finished processing a JSON object + - `array_start`: the parser read `[` and started to process a JSON array + - `array_end`: the parser read `]` and finished processing a JSON array + - `value`: the parser finished reading a JSON value + + @image html callback_events.png "Example when certain parse events are triggered" + + @sa see @ref parser_callback_t for more information and examples + */ + using parse_event_t = detail::parse_event_t; + + /*! + @brief per-element parser callback type + + With a parser callback function, the result of parsing a JSON text can be + influenced. When passed to @ref parse, it is called on certain events + (passed as @ref parse_event_t via parameter @a event) with a set recursion + depth @a depth and context JSON value @a parsed. The return value of the + callback function is a boolean indicating whether the element that emitted + the callback shall be kept or not. + + We distinguish six scenarios (determined by the event type) in which the + callback function can be called. The following table describes the values + of the parameters @a depth, @a event, and @a parsed. + + parameter @a event | description | parameter @a depth | parameter @a parsed + ------------------ | ----------- | ------------------ | ------------------- + parse_event_t::object_start | the parser read `{` and started to process a JSON object | depth of the parent of the JSON object | a JSON value with type discarded + parse_event_t::key | the parser read a key of a value in an object | depth of the currently parsed JSON object | a JSON string containing the key + parse_event_t::object_end | the parser read `}` and finished processing a JSON object | depth of the parent of the JSON object | the parsed JSON object + parse_event_t::array_start | the parser read `[` and started to process a JSON array | depth of the parent of the JSON array | a JSON value with type discarded + parse_event_t::array_end | the parser read `]` and finished processing a JSON array | depth of the parent of the JSON array | the parsed JSON array + parse_event_t::value | the parser finished reading a JSON value | depth of the value | the parsed JSON value + + @image html callback_events.png "Example when certain parse events are triggered" + + Discarding a value (i.e., returning `false`) has different effects + depending on the context in which function was called: + + - Discarded values in structured types are skipped. That is, the parser + will behave as if the discarded value was never read. + - In case a value outside a structured type is skipped, it is replaced + with `null`. This case happens if the top-level element is skipped. + + @param[in] depth the depth of the recursion during parsing + + @param[in] event an event of type parse_event_t indicating the context in + the callback function has been called + + @param[in,out] parsed the current intermediate parse result; note that + writing to this value has no effect for parse_event_t::key events + + @return Whether the JSON value which called the function during parsing + should be kept (`true`) or not (`false`). In the latter case, it is either + skipped completely or replaced by an empty discarded object. + + @sa see @ref parse for examples + + @since version 1.0.0 + */ + using parser_callback_t = detail::parser_callback_t; + + ////////////////// + // constructors // + ////////////////// + + /// @name constructors and destructors + /// Constructors of class @ref basic_json, copy/move constructor, copy + /// assignment, static functions creating objects, and the destructor. + /// @{ + + /*! + @brief create an empty value with a given type + + Create an empty JSON value with a given type. The value will be default + initialized with an empty value which depends on the type: + + Value type | initial value + ----------- | ------------- + null | `null` + boolean | `false` + string | `""` + number | `0` + object | `{}` + array | `[]` + binary | empty array + + @param[in] v the type of the value to create + + @complexity Constant. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. + + @liveexample{The following code shows the constructor for different @ref + value_t values,basic_json__value_t} + + @sa see @ref clear() -- restores the postcondition of this constructor + + @since version 1.0.0 + */ + basic_json(const value_t v) + : m_type(v), m_value(v) + { + assert_invariant(); + } + + /*! + @brief create a null object + + Create a `null` JSON value. It either takes a null pointer as parameter + (explicitly creating `null`) or no parameter (implicitly creating `null`). + The passed null pointer itself is not read -- it is only used to choose + the right constructor. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this constructor never throws + exceptions. + + @liveexample{The following code shows the constructor with and without a + null pointer parameter.,basic_json__nullptr_t} + + @since version 1.0.0 + */ + basic_json(std::nullptr_t = nullptr) noexcept + : basic_json(value_t::null) + { + assert_invariant(); + } + + /*! + @brief create a JSON value + + This is a "catch all" constructor for all compatible JSON types; that is, + types for which a `to_json()` method exists. The constructor forwards the + parameter @a val to that method (to `json_serializer::to_json` method + with `U = uncvref_t`, to be exact). + + Template type @a CompatibleType includes, but is not limited to, the + following types: + - **arrays**: @ref array_t and all kinds of compatible containers such as + `std::vector`, `std::deque`, `std::list`, `std::forward_list`, + `std::array`, `std::valarray`, `std::set`, `std::unordered_set`, + `std::multiset`, and `std::unordered_multiset` with a `value_type` from + which a @ref basic_json value can be constructed. + - **objects**: @ref object_t and all kinds of compatible associative + containers such as `std::map`, `std::unordered_map`, `std::multimap`, + and `std::unordered_multimap` with a `key_type` compatible to + @ref string_t and a `value_type` from which a @ref basic_json value can + be constructed. + - **strings**: @ref string_t, string literals, and all compatible string + containers can be used. + - **numbers**: @ref number_integer_t, @ref number_unsigned_t, + @ref number_float_t, and all convertible number types such as `int`, + `size_t`, `int64_t`, `float` or `double` can be used. + - **boolean**: @ref boolean_t / `bool` can be used. + - **binary**: @ref binary_t / `std::vector` may be used, + unfortunately because string literals cannot be distinguished from binary + character arrays by the C++ type system, all types compatible with `const + char*` will be directed to the string constructor instead. This is both + for backwards compatibility, and due to the fact that a binary type is not + a standard JSON type. + + See the examples below. + + @tparam CompatibleType a type such that: + - @a CompatibleType is not derived from `std::istream`, + - @a CompatibleType is not @ref basic_json (to avoid hijacking copy/move + constructors), + - @a CompatibleType is not a different @ref basic_json type (i.e. with different template arguments) + - @a CompatibleType is not a @ref basic_json nested type (e.g., + @ref json_pointer, @ref iterator, etc ...) + - `json_serializer` has a `to_json(basic_json_t&, CompatibleType&&)` method + + @tparam U = `uncvref_t` + + @param[in] val the value to be forwarded to the respective constructor + + @complexity Usually linear in the size of the passed @a val, also + depending on the implementation of the called `to_json()` + method. + + @exceptionsafety Depends on the called constructor. For types directly + supported by the library (i.e., all types for which no `to_json()` function + was provided), strong guarantee holds: if an exception is thrown, there are + no changes to any JSON value. + + @liveexample{The following code shows the constructor with several + compatible types.,basic_json__CompatibleType} + + @since version 2.1.0 + */ + template < typename CompatibleType, + typename U = detail::uncvref_t, + detail::enable_if_t < + !detail::is_basic_json::value && detail::is_compatible_type::value, int > = 0 > + basic_json(CompatibleType && val) noexcept(noexcept( // NOLINT(bugprone-forwarding-reference-overload,bugprone-exception-escape) + JSONSerializer::to_json(std::declval(), + std::forward(val)))) + { + JSONSerializer::to_json(*this, std::forward(val)); + set_parents(); + assert_invariant(); + } + + /*! + @brief create a JSON value from an existing one + + This is a constructor for existing @ref basic_json types. + It does not hijack copy/move constructors, since the parameter has different + template arguments than the current ones. + + The constructor tries to convert the internal @ref m_value of the parameter. + + @tparam BasicJsonType a type such that: + - @a BasicJsonType is a @ref basic_json type. + - @a BasicJsonType has different template arguments than @ref basic_json_t. + + @param[in] val the @ref basic_json value to be converted. + + @complexity Usually linear in the size of the passed @a val, also + depending on the implementation of the called `to_json()` + method. + + @exceptionsafety Depends on the called constructor. For types directly + supported by the library (i.e., all types for which no `to_json()` function + was provided), strong guarantee holds: if an exception is thrown, there are + no changes to any JSON value. + + @since version 3.2.0 + */ + template < typename BasicJsonType, + detail::enable_if_t < + detail::is_basic_json::value&& !std::is_same::value, int > = 0 > + basic_json(const BasicJsonType& val) + { + using other_boolean_t = typename BasicJsonType::boolean_t; + using other_number_float_t = typename BasicJsonType::number_float_t; + using other_number_integer_t = typename BasicJsonType::number_integer_t; + using other_number_unsigned_t = typename BasicJsonType::number_unsigned_t; + using other_string_t = typename BasicJsonType::string_t; + using other_object_t = typename BasicJsonType::object_t; + using other_array_t = typename BasicJsonType::array_t; + using other_binary_t = typename BasicJsonType::binary_t; + + switch (val.type()) + { + case value_t::boolean: + JSONSerializer::to_json(*this, val.template get()); + break; + case value_t::number_float: + JSONSerializer::to_json(*this, val.template get()); + break; + case value_t::number_integer: + JSONSerializer::to_json(*this, val.template get()); + break; + case value_t::number_unsigned: + JSONSerializer::to_json(*this, val.template get()); + break; + case value_t::string: + JSONSerializer::to_json(*this, val.template get_ref()); + break; + case value_t::object: + JSONSerializer::to_json(*this, val.template get_ref()); + break; + case value_t::array: + JSONSerializer::to_json(*this, val.template get_ref()); + break; + case value_t::binary: + JSONSerializer::to_json(*this, val.template get_ref()); + break; + case value_t::null: + *this = nullptr; + break; + case value_t::discarded: + m_type = value_t::discarded; + break; + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + } + set_parents(); + assert_invariant(); + } + + /*! + @brief create a container (array or object) from an initializer list + + Creates a JSON value of type array or object from the passed initializer + list @a init. In case @a type_deduction is `true` (default), the type of + the JSON value to be created is deducted from the initializer list @a init + according to the following rules: + + 1. If the list is empty, an empty JSON object value `{}` is created. + 2. If the list consists of pairs whose first element is a string, a JSON + object value is created where the first elements of the pairs are + treated as keys and the second elements are as values. + 3. In all other cases, an array is created. + + The rules aim to create the best fit between a C++ initializer list and + JSON values. The rationale is as follows: + + 1. The empty initializer list is written as `{}` which is exactly an empty + JSON object. + 2. C++ has no way of describing mapped types other than to list a list of + pairs. As JSON requires that keys must be of type string, rule 2 is the + weakest constraint one can pose on initializer lists to interpret them + as an object. + 3. In all other cases, the initializer list could not be interpreted as + JSON object type, so interpreting it as JSON array type is safe. + + With the rules described above, the following JSON values cannot be + expressed by an initializer list: + + - the empty array (`[]`): use @ref array(initializer_list_t) + with an empty initializer list in this case + - arrays whose elements satisfy rule 2: use @ref + array(initializer_list_t) with the same initializer list + in this case + + @note When used without parentheses around an empty initializer list, @ref + basic_json() is called instead of this function, yielding the JSON null + value. + + @param[in] init initializer list with JSON values + + @param[in] type_deduction internal parameter; when set to `true`, the type + of the JSON value is deducted from the initializer list @a init; when set + to `false`, the type provided via @a manual_type is forced. This mode is + used by the functions @ref array(initializer_list_t) and + @ref object(initializer_list_t). + + @param[in] manual_type internal parameter; when @a type_deduction is set + to `false`, the created JSON value will use the provided type (only @ref + value_t::array and @ref value_t::object are valid); when @a type_deduction + is set to `true`, this parameter has no effect + + @throw type_error.301 if @a type_deduction is `false`, @a manual_type is + `value_t::object`, but @a init contains an element which is not a pair + whose first element is a string. In this case, the constructor could not + create an object. If @a type_deduction would have be `true`, an array + would have been created. See @ref object(initializer_list_t) + for an example. + + @complexity Linear in the size of the initializer list @a init. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. + + @liveexample{The example below shows how JSON values are created from + initializer lists.,basic_json__list_init_t} + + @sa see @ref array(initializer_list_t) -- create a JSON array + value from an initializer list + @sa see @ref object(initializer_list_t) -- create a JSON object + value from an initializer list + + @since version 1.0.0 + */ + basic_json(initializer_list_t init, + bool type_deduction = true, + value_t manual_type = value_t::array) + { + // check if each element is an array with two elements whose first + // element is a string + bool is_an_object = std::all_of(init.begin(), init.end(), + [](const detail::json_ref& element_ref) + { + return element_ref->is_array() && element_ref->size() == 2 && (*element_ref)[0].is_string(); + }); + + // adjust type if type deduction is not wanted + if (!type_deduction) + { + // if array is wanted, do not create an object though possible + if (manual_type == value_t::array) + { + is_an_object = false; + } + + // if object is wanted but impossible, throw an exception + if (JSON_HEDLEY_UNLIKELY(manual_type == value_t::object && !is_an_object)) + { + JSON_THROW(type_error::create(301, "cannot create object from initializer list", basic_json())); + } + } + + if (is_an_object) + { + // the initializer list is a list of pairs -> create object + m_type = value_t::object; + m_value = value_t::object; + + for (auto& element_ref : init) + { + auto element = element_ref.moved_or_copied(); + m_value.object->emplace( + std::move(*((*element.m_value.array)[0].m_value.string)), + std::move((*element.m_value.array)[1])); + } + } + else + { + // the initializer list describes an array -> create array + m_type = value_t::array; + m_value.array = create(init.begin(), init.end()); + } + + set_parents(); + assert_invariant(); + } + + /*! + @brief explicitly create a binary array (without subtype) + + Creates a JSON binary array value from a given binary container. Binary + values are part of various binary formats, such as CBOR, MessagePack, and + BSON. This constructor is used to create a value for serialization to those + formats. + + @note Note, this function exists because of the difficulty in correctly + specifying the correct template overload in the standard value ctor, as both + JSON arrays and JSON binary arrays are backed with some form of a + `std::vector`. Because JSON binary arrays are a non-standard extension it + was decided that it would be best to prevent automatic initialization of a + binary array type, for backwards compatibility and so it does not happen on + accident. + + @param[in] init container containing bytes to use as binary type + + @return JSON binary array value + + @complexity Linear in the size of @a init. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. + + @since version 3.8.0 + */ + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json binary(const typename binary_t::container_type& init) + { + auto res = basic_json(); + res.m_type = value_t::binary; + res.m_value = init; + return res; + } + + /*! + @brief explicitly create a binary array (with subtype) + + Creates a JSON binary array value from a given binary container. Binary + values are part of various binary formats, such as CBOR, MessagePack, and + BSON. This constructor is used to create a value for serialization to those + formats. + + @note Note, this function exists because of the difficulty in correctly + specifying the correct template overload in the standard value ctor, as both + JSON arrays and JSON binary arrays are backed with some form of a + `std::vector`. Because JSON binary arrays are a non-standard extension it + was decided that it would be best to prevent automatic initialization of a + binary array type, for backwards compatibility and so it does not happen on + accident. + + @param[in] init container containing bytes to use as binary type + @param[in] subtype subtype to use in MessagePack and BSON + + @return JSON binary array value + + @complexity Linear in the size of @a init. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. + + @since version 3.8.0 + */ + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json binary(const typename binary_t::container_type& init, typename binary_t::subtype_type subtype) + { + auto res = basic_json(); + res.m_type = value_t::binary; + res.m_value = binary_t(init, subtype); + return res; + } + + /// @copydoc binary(const typename binary_t::container_type&) + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json binary(typename binary_t::container_type&& init) + { + auto res = basic_json(); + res.m_type = value_t::binary; + res.m_value = std::move(init); + return res; + } + + /// @copydoc binary(const typename binary_t::container_type&, typename binary_t::subtype_type) + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json binary(typename binary_t::container_type&& init, typename binary_t::subtype_type subtype) + { + auto res = basic_json(); + res.m_type = value_t::binary; + res.m_value = binary_t(std::move(init), subtype); + return res; + } + + /*! + @brief explicitly create an array from an initializer list + + Creates a JSON array value from a given initializer list. That is, given a + list of values `a, b, c`, creates the JSON value `[a, b, c]`. If the + initializer list is empty, the empty array `[]` is created. + + @note This function is only needed to express two edge cases that cannot + be realized with the initializer list constructor (@ref + basic_json(initializer_list_t, bool, value_t)). These cases + are: + 1. creating an array whose elements are all pairs whose first element is a + string -- in this case, the initializer list constructor would create an + object, taking the first elements as keys + 2. creating an empty array -- passing the empty initializer list to the + initializer list constructor yields an empty object + + @param[in] init initializer list with JSON values to create an array from + (optional) + + @return JSON array value + + @complexity Linear in the size of @a init. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. + + @liveexample{The following code shows an example for the `array` + function.,array} + + @sa see @ref basic_json(initializer_list_t, bool, value_t) -- + create a JSON value from an initializer list + @sa see @ref object(initializer_list_t) -- create a JSON object + value from an initializer list + + @since version 1.0.0 + */ + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json array(initializer_list_t init = {}) + { + return basic_json(init, false, value_t::array); + } + + /*! + @brief explicitly create an object from an initializer list + + Creates a JSON object value from a given initializer list. The initializer + lists elements must be pairs, and their first elements must be strings. If + the initializer list is empty, the empty object `{}` is created. + + @note This function is only added for symmetry reasons. In contrast to the + related function @ref array(initializer_list_t), there are + no cases which can only be expressed by this function. That is, any + initializer list @a init can also be passed to the initializer list + constructor @ref basic_json(initializer_list_t, bool, value_t). + + @param[in] init initializer list to create an object from (optional) + + @return JSON object value + + @throw type_error.301 if @a init is not a list of pairs whose first + elements are strings. In this case, no object can be created. When such a + value is passed to @ref basic_json(initializer_list_t, bool, value_t), + an array would have been created from the passed initializer list @a init. + See example below. + + @complexity Linear in the size of @a init. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. + + @liveexample{The following code shows an example for the `object` + function.,object} + + @sa see @ref basic_json(initializer_list_t, bool, value_t) -- + create a JSON value from an initializer list + @sa see @ref array(initializer_list_t) -- create a JSON array + value from an initializer list + + @since version 1.0.0 + */ + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json object(initializer_list_t init = {}) + { + return basic_json(init, false, value_t::object); + } + + /*! + @brief construct an array with count copies of given value + + Constructs a JSON array value by creating @a cnt copies of a passed value. + In case @a cnt is `0`, an empty array is created. + + @param[in] cnt the number of JSON copies of @a val to create + @param[in] val the JSON value to copy + + @post `std::distance(begin(),end()) == cnt` holds. + + @complexity Linear in @a cnt. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. + + @liveexample{The following code shows examples for the @ref + basic_json(size_type\, const basic_json&) + constructor.,basic_json__size_type_basic_json} + + @since version 1.0.0 + */ + basic_json(size_type cnt, const basic_json& val) + : m_type(value_t::array) + { + m_value.array = create(cnt, val); + set_parents(); + assert_invariant(); + } + + /*! + @brief construct a JSON container given an iterator range + + Constructs the JSON value with the contents of the range `[first, last)`. + The semantics depends on the different types a JSON value can have: + - In case of a null type, invalid_iterator.206 is thrown. + - In case of other primitive types (number, boolean, or string), @a first + must be `begin()` and @a last must be `end()`. In this case, the value is + copied. Otherwise, invalid_iterator.204 is thrown. + - In case of structured types (array, object), the constructor behaves as + similar versions for `std::vector` or `std::map`; that is, a JSON array + or object is constructed from the values in the range. + + @tparam InputIT an input iterator type (@ref iterator or @ref + const_iterator) + + @param[in] first begin of the range to copy from (included) + @param[in] last end of the range to copy from (excluded) + + @pre Iterators @a first and @a last must be initialized. **This + precondition is enforced with an assertion (see warning).** If + assertions are switched off, a violation of this precondition yields + undefined behavior. + + @pre Range `[first, last)` is valid. Usually, this precondition cannot be + checked efficiently. Only certain edge cases are detected; see the + description of the exceptions below. A violation of this precondition + yields undefined behavior. + + @warning A precondition is enforced with a runtime assertion that will + result in calling `std::abort` if this precondition is not met. + Assertions can be disabled by defining `NDEBUG` at compile time. + See https://en.cppreference.com/w/cpp/error/assert for more + information. + + @throw invalid_iterator.201 if iterators @a first and @a last are not + compatible (i.e., do not belong to the same JSON value). In this case, + the range `[first, last)` is undefined. + @throw invalid_iterator.204 if iterators @a first and @a last belong to a + primitive type (number, boolean, or string), but @a first does not point + to the first element any more. In this case, the range `[first, last)` is + undefined. See example code below. + @throw invalid_iterator.206 if iterators @a first and @a last belong to a + null value. In this case, the range `[first, last)` is undefined. + + @complexity Linear in distance between @a first and @a last. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. + + @liveexample{The example below shows several ways to create JSON values by + specifying a subrange with iterators.,basic_json__InputIt_InputIt} + + @since version 1.0.0 + */ + template < class InputIT, typename std::enable_if < + std::is_same::value || + std::is_same::value, int >::type = 0 > + basic_json(InputIT first, InputIT last) + { + JSON_ASSERT(first.m_object != nullptr); + JSON_ASSERT(last.m_object != nullptr); + + // make sure iterator fits the current value + if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) + { + JSON_THROW(invalid_iterator::create(201, "iterators are not compatible", basic_json())); + } + + // copy type from first iterator + m_type = first.m_object->m_type; + + // check if iterator range is complete for primitive values + switch (m_type) + { + case value_t::boolean: + case value_t::number_float: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::string: + { + if (JSON_HEDLEY_UNLIKELY(!first.m_it.primitive_iterator.is_begin() + || !last.m_it.primitive_iterator.is_end())) + { + JSON_THROW(invalid_iterator::create(204, "iterators out of range", *first.m_object)); + } + break; + } + + case value_t::null: + case value_t::object: + case value_t::array: + case value_t::binary: + case value_t::discarded: + default: + break; + } + + switch (m_type) + { + case value_t::number_integer: + { + m_value.number_integer = first.m_object->m_value.number_integer; + break; + } + + case value_t::number_unsigned: + { + m_value.number_unsigned = first.m_object->m_value.number_unsigned; + break; + } + + case value_t::number_float: + { + m_value.number_float = first.m_object->m_value.number_float; + break; + } + + case value_t::boolean: + { + m_value.boolean = first.m_object->m_value.boolean; + break; + } + + case value_t::string: + { + m_value = *first.m_object->m_value.string; + break; + } + + case value_t::object: + { + m_value.object = create(first.m_it.object_iterator, + last.m_it.object_iterator); + break; + } + + case value_t::array: + { + m_value.array = create(first.m_it.array_iterator, + last.m_it.array_iterator); + break; + } + + case value_t::binary: + { + m_value = *first.m_object->m_value.binary; + break; + } + + case value_t::null: + case value_t::discarded: + default: + JSON_THROW(invalid_iterator::create(206, "cannot construct with iterators from " + std::string(first.m_object->type_name()), *first.m_object)); + } + + set_parents(); + assert_invariant(); + } + + + /////////////////////////////////////// + // other constructors and destructor // + /////////////////////////////////////// + + template, + std::is_same>::value, int> = 0 > + basic_json(const JsonRef& ref) : basic_json(ref.moved_or_copied()) {} + + /*! + @brief copy constructor + + Creates a copy of a given JSON value. + + @param[in] other the JSON value to copy + + @post `*this == other` + + @complexity Linear in the size of @a other. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes to any JSON value. + + @requirement This function helps `basic_json` satisfying the + [Container](https://en.cppreference.com/w/cpp/named_req/Container) + requirements: + - The complexity is linear. + - As postcondition, it holds: `other == basic_json(other)`. + + @liveexample{The following code shows an example for the copy + constructor.,basic_json__basic_json} + + @since version 1.0.0 + */ + basic_json(const basic_json& other) + : m_type(other.m_type) + { + // check of passed value is valid + other.assert_invariant(); + + switch (m_type) + { + case value_t::object: + { + m_value = *other.m_value.object; + break; + } + + case value_t::array: + { + m_value = *other.m_value.array; + break; + } + + case value_t::string: + { + m_value = *other.m_value.string; + break; + } + + case value_t::boolean: + { + m_value = other.m_value.boolean; + break; + } + + case value_t::number_integer: + { + m_value = other.m_value.number_integer; + break; + } + + case value_t::number_unsigned: + { + m_value = other.m_value.number_unsigned; + break; + } + + case value_t::number_float: + { + m_value = other.m_value.number_float; + break; + } + + case value_t::binary: + { + m_value = *other.m_value.binary; + break; + } + + case value_t::null: + case value_t::discarded: + default: + break; + } + + set_parents(); + assert_invariant(); + } + + /*! + @brief move constructor + + Move constructor. Constructs a JSON value with the contents of the given + value @a other using move semantics. It "steals" the resources from @a + other and leaves it as JSON null value. + + @param[in,out] other value to move to this object + + @post `*this` has the same value as @a other before the call. + @post @a other is a JSON null value. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this constructor never throws + exceptions. + + @requirement This function helps `basic_json` satisfying the + [MoveConstructible](https://en.cppreference.com/w/cpp/named_req/MoveConstructible) + requirements. + + @liveexample{The code below shows the move constructor explicitly called + via std::move.,basic_json__moveconstructor} + + @since version 1.0.0 + */ + basic_json(basic_json&& other) noexcept + : m_type(std::move(other.m_type)), + m_value(std::move(other.m_value)) + { + // check that passed value is valid + other.assert_invariant(false); + + // invalidate payload + other.m_type = value_t::null; + other.m_value = {}; + + set_parents(); + assert_invariant(); + } + + /*! + @brief copy assignment + + Copy assignment operator. Copies a JSON value via the "copy and swap" + strategy: It is expressed in terms of the copy constructor, destructor, + and the `swap()` member function. + + @param[in] other value to copy from + + @complexity Linear. + + @requirement This function helps `basic_json` satisfying the + [Container](https://en.cppreference.com/w/cpp/named_req/Container) + requirements: + - The complexity is linear. + + @liveexample{The code below shows and example for the copy assignment. It + creates a copy of value `a` which is then swapped with `b`. Finally\, the + copy of `a` (which is the null value after the swap) is + destroyed.,basic_json__copyassignment} + + @since version 1.0.0 + */ + basic_json& operator=(basic_json other) noexcept ( + std::is_nothrow_move_constructible::value&& + std::is_nothrow_move_assignable::value&& + std::is_nothrow_move_constructible::value&& + std::is_nothrow_move_assignable::value + ) + { + // check that passed value is valid + other.assert_invariant(); + + using std::swap; + swap(m_type, other.m_type); + swap(m_value, other.m_value); + + set_parents(); + assert_invariant(); + return *this; + } + + /*! + @brief destructor + + Destroys the JSON value and frees all allocated memory. + + @complexity Linear. + + @requirement This function helps `basic_json` satisfying the + [Container](https://en.cppreference.com/w/cpp/named_req/Container) + requirements: + - The complexity is linear. + - All stored elements are destroyed and all memory is freed. + + @since version 1.0.0 + */ + ~basic_json() noexcept + { + assert_invariant(false); + m_value.destroy(m_type); + } + + /// @} + + public: + /////////////////////// + // object inspection // + /////////////////////// + + /// @name object inspection + /// Functions to inspect the type of a JSON value. + /// @{ + + /*! + @brief serialization + + Serialization function for JSON values. The function tries to mimic + Python's `json.dumps()` function, and currently supports its @a indent + and @a ensure_ascii parameters. + + @param[in] indent If indent is nonnegative, then array elements and object + members will be pretty-printed with that indent level. An indent level of + `0` will only insert newlines. `-1` (the default) selects the most compact + representation. + @param[in] indent_char The character to use for indentation if @a indent is + greater than `0`. The default is ` ` (space). + @param[in] ensure_ascii If @a ensure_ascii is true, all non-ASCII characters + in the output are escaped with `\uXXXX` sequences, and the result consists + of ASCII characters only. + @param[in] error_handler how to react on decoding errors; there are three + possible values: `strict` (throws and exception in case a decoding error + occurs; default), `replace` (replace invalid UTF-8 sequences with U+FFFD), + and `ignore` (ignore invalid UTF-8 sequences during serialization; all + bytes are copied to the output unchanged). + + @return string containing the serialization of the JSON value + + @throw type_error.316 if a string stored inside the JSON value is not + UTF-8 encoded and @a error_handler is set to strict + + @note Binary values are serialized as object containing two keys: + - "bytes": an array of bytes as integers + - "subtype": the subtype as integer or "null" if the binary has no subtype + + @complexity Linear. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes in the JSON value. + + @liveexample{The following example shows the effect of different @a indent\, + @a indent_char\, and @a ensure_ascii parameters to the result of the + serialization.,dump} + + @see https://docs.python.org/2/library/json.html#json.dump + + @since version 1.0.0; indentation character @a indent_char, option + @a ensure_ascii and exceptions added in version 3.0.0; error + handlers added in version 3.4.0; serialization of binary values added + in version 3.8.0. + */ + string_t dump(const int indent = -1, + const char indent_char = ' ', + const bool ensure_ascii = false, + const error_handler_t error_handler = error_handler_t::strict) const + { + string_t result; + serializer s(detail::output_adapter(result), indent_char, error_handler); + + if (indent >= 0) + { + s.dump(*this, true, ensure_ascii, static_cast(indent)); + } + else + { + s.dump(*this, false, ensure_ascii, 0); + } + + return result; + } + + /*! + @brief return the type of the JSON value (explicit) + + Return the type of the JSON value as a value from the @ref value_t + enumeration. + + @return the type of the JSON value + Value type | return value + ------------------------- | ------------------------- + null | value_t::null + boolean | value_t::boolean + string | value_t::string + number (integer) | value_t::number_integer + number (unsigned integer) | value_t::number_unsigned + number (floating-point) | value_t::number_float + object | value_t::object + array | value_t::array + binary | value_t::binary + discarded | value_t::discarded + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `type()` for all JSON + types.,type} + + @sa see @ref operator value_t() -- return the type of the JSON value (implicit) + @sa see @ref type_name() -- return the type as string + + @since version 1.0.0 + */ + constexpr value_t type() const noexcept + { + return m_type; + } + + /*! + @brief return whether type is primitive + + This function returns true if and only if the JSON type is primitive + (string, number, boolean, or null). + + @return `true` if type is primitive (string, number, boolean, or null), + `false` otherwise. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_primitive()` for all JSON + types.,is_primitive} + + @sa see @ref is_structured() -- returns whether JSON value is structured + @sa see @ref is_null() -- returns whether JSON value is `null` + @sa see @ref is_string() -- returns whether JSON value is a string + @sa see @ref is_boolean() -- returns whether JSON value is a boolean + @sa see @ref is_number() -- returns whether JSON value is a number + @sa see @ref is_binary() -- returns whether JSON value is a binary array + + @since version 1.0.0 + */ + constexpr bool is_primitive() const noexcept + { + return is_null() || is_string() || is_boolean() || is_number() || is_binary(); + } + + /*! + @brief return whether type is structured + + This function returns true if and only if the JSON type is structured + (array or object). + + @return `true` if type is structured (array or object), `false` otherwise. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_structured()` for all JSON + types.,is_structured} + + @sa see @ref is_primitive() -- returns whether value is primitive + @sa see @ref is_array() -- returns whether value is an array + @sa see @ref is_object() -- returns whether value is an object + + @since version 1.0.0 + */ + constexpr bool is_structured() const noexcept + { + return is_array() || is_object(); + } + + /*! + @brief return whether value is null + + This function returns true if and only if the JSON value is null. + + @return `true` if type is null, `false` otherwise. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_null()` for all JSON + types.,is_null} + + @since version 1.0.0 + */ + constexpr bool is_null() const noexcept + { + return m_type == value_t::null; + } + + /*! + @brief return whether value is a boolean + + This function returns true if and only if the JSON value is a boolean. + + @return `true` if type is boolean, `false` otherwise. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_boolean()` for all JSON + types.,is_boolean} + + @since version 1.0.0 + */ + constexpr bool is_boolean() const noexcept + { + return m_type == value_t::boolean; + } + + /*! + @brief return whether value is a number + + This function returns true if and only if the JSON value is a number. This + includes both integer (signed and unsigned) and floating-point values. + + @return `true` if type is number (regardless whether integer, unsigned + integer or floating-type), `false` otherwise. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_number()` for all JSON + types.,is_number} + + @sa see @ref is_number_integer() -- check if value is an integer or unsigned + integer number + @sa see @ref is_number_unsigned() -- check if value is an unsigned integer + number + @sa see @ref is_number_float() -- check if value is a floating-point number + + @since version 1.0.0 + */ + constexpr bool is_number() const noexcept + { + return is_number_integer() || is_number_float(); + } + + /*! + @brief return whether value is an integer number + + This function returns true if and only if the JSON value is a signed or + unsigned integer number. This excludes floating-point values. + + @return `true` if type is an integer or unsigned integer number, `false` + otherwise. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_number_integer()` for all + JSON types.,is_number_integer} + + @sa see @ref is_number() -- check if value is a number + @sa see @ref is_number_unsigned() -- check if value is an unsigned integer + number + @sa see @ref is_number_float() -- check if value is a floating-point number + + @since version 1.0.0 + */ + constexpr bool is_number_integer() const noexcept + { + return m_type == value_t::number_integer || m_type == value_t::number_unsigned; + } + + /*! + @brief return whether value is an unsigned integer number + + This function returns true if and only if the JSON value is an unsigned + integer number. This excludes floating-point and signed integer values. + + @return `true` if type is an unsigned integer number, `false` otherwise. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_number_unsigned()` for all + JSON types.,is_number_unsigned} + + @sa see @ref is_number() -- check if value is a number + @sa see @ref is_number_integer() -- check if value is an integer or unsigned + integer number + @sa see @ref is_number_float() -- check if value is a floating-point number + + @since version 2.0.0 + */ + constexpr bool is_number_unsigned() const noexcept + { + return m_type == value_t::number_unsigned; + } + + /*! + @brief return whether value is a floating-point number + + This function returns true if and only if the JSON value is a + floating-point number. This excludes signed and unsigned integer values. + + @return `true` if type is a floating-point number, `false` otherwise. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_number_float()` for all + JSON types.,is_number_float} + + @sa see @ref is_number() -- check if value is number + @sa see @ref is_number_integer() -- check if value is an integer number + @sa see @ref is_number_unsigned() -- check if value is an unsigned integer + number + + @since version 1.0.0 + */ + constexpr bool is_number_float() const noexcept + { + return m_type == value_t::number_float; + } + + /*! + @brief return whether value is an object + + This function returns true if and only if the JSON value is an object. + + @return `true` if type is object, `false` otherwise. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_object()` for all JSON + types.,is_object} + + @since version 1.0.0 + */ + constexpr bool is_object() const noexcept + { + return m_type == value_t::object; + } + + /*! + @brief return whether value is an array + + This function returns true if and only if the JSON value is an array. + + @return `true` if type is array, `false` otherwise. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_array()` for all JSON + types.,is_array} + + @since version 1.0.0 + */ + constexpr bool is_array() const noexcept + { + return m_type == value_t::array; + } + + /*! + @brief return whether value is a string + + This function returns true if and only if the JSON value is a string. + + @return `true` if type is string, `false` otherwise. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_string()` for all JSON + types.,is_string} + + @since version 1.0.0 + */ + constexpr bool is_string() const noexcept + { + return m_type == value_t::string; + } + + /*! + @brief return whether value is a binary array + + This function returns true if and only if the JSON value is a binary array. + + @return `true` if type is binary array, `false` otherwise. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_binary()` for all JSON + types.,is_binary} + + @since version 3.8.0 + */ + constexpr bool is_binary() const noexcept + { + return m_type == value_t::binary; + } + + /*! + @brief return whether value is discarded + + This function returns true if and only if the JSON value was discarded + during parsing with a callback function (see @ref parser_callback_t). + + @note This function will always be `false` for JSON values after parsing. + That is, discarded values can only occur during parsing, but will be + removed when inside a structured value or replaced by null in other cases. + + @return `true` if type is discarded, `false` otherwise. + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies `is_discarded()` for all JSON + types.,is_discarded} + + @since version 1.0.0 + */ + constexpr bool is_discarded() const noexcept + { + return m_type == value_t::discarded; + } + + /*! + @brief return the type of the JSON value (implicit) + + Implicitly return the type of the JSON value as a value from the @ref + value_t enumeration. + + @return the type of the JSON value + + @complexity Constant. + + @exceptionsafety No-throw guarantee: this member function never throws + exceptions. + + @liveexample{The following code exemplifies the @ref value_t operator for + all JSON types.,operator__value_t} + + @sa see @ref type() -- return the type of the JSON value (explicit) + @sa see @ref type_name() -- return the type as string + + @since version 1.0.0 + */ + constexpr operator value_t() const noexcept + { + return m_type; + } + + /// @} + + private: + ////////////////// + // value access // + ////////////////// + + /// get a boolean (explicit) + boolean_t get_impl(boolean_t* /*unused*/) const + { + if (JSON_HEDLEY_LIKELY(is_boolean())) + { + return m_value.boolean; + } + + JSON_THROW(type_error::create(302, "type must be boolean, but is " + std::string(type_name()), *this)); + } + + /// get a pointer to the value (object) + object_t* get_impl_ptr(object_t* /*unused*/) noexcept + { + return is_object() ? m_value.object : nullptr; + } + + /// get a pointer to the value (object) + constexpr const object_t* get_impl_ptr(const object_t* /*unused*/) const noexcept + { + return is_object() ? m_value.object : nullptr; + } + + /// get a pointer to the value (array) + array_t* get_impl_ptr(array_t* /*unused*/) noexcept + { + return is_array() ? m_value.array : nullptr; + } + + /// get a pointer to the value (array) + constexpr const array_t* get_impl_ptr(const array_t* /*unused*/) const noexcept + { + return is_array() ? m_value.array : nullptr; + } + + /// get a pointer to the value (string) + string_t* get_impl_ptr(string_t* /*unused*/) noexcept + { + return is_string() ? m_value.string : nullptr; + } + + /// get a pointer to the value (string) + constexpr const string_t* get_impl_ptr(const string_t* /*unused*/) const noexcept + { + return is_string() ? m_value.string : nullptr; + } + + /// get a pointer to the value (boolean) + boolean_t* get_impl_ptr(boolean_t* /*unused*/) noexcept + { + return is_boolean() ? &m_value.boolean : nullptr; + } + + /// get a pointer to the value (boolean) + constexpr const boolean_t* get_impl_ptr(const boolean_t* /*unused*/) const noexcept + { + return is_boolean() ? &m_value.boolean : nullptr; + } + + /// get a pointer to the value (integer number) + number_integer_t* get_impl_ptr(number_integer_t* /*unused*/) noexcept + { + return is_number_integer() ? &m_value.number_integer : nullptr; + } + + /// get a pointer to the value (integer number) + constexpr const number_integer_t* get_impl_ptr(const number_integer_t* /*unused*/) const noexcept + { + return is_number_integer() ? &m_value.number_integer : nullptr; + } + + /// get a pointer to the value (unsigned number) + number_unsigned_t* get_impl_ptr(number_unsigned_t* /*unused*/) noexcept + { + return is_number_unsigned() ? &m_value.number_unsigned : nullptr; + } + + /// get a pointer to the value (unsigned number) + constexpr const number_unsigned_t* get_impl_ptr(const number_unsigned_t* /*unused*/) const noexcept + { + return is_number_unsigned() ? &m_value.number_unsigned : nullptr; + } + + /// get a pointer to the value (floating-point number) + number_float_t* get_impl_ptr(number_float_t* /*unused*/) noexcept + { + return is_number_float() ? &m_value.number_float : nullptr; + } + + /// get a pointer to the value (floating-point number) + constexpr const number_float_t* get_impl_ptr(const number_float_t* /*unused*/) const noexcept + { + return is_number_float() ? &m_value.number_float : nullptr; + } + + /// get a pointer to the value (binary) + binary_t* get_impl_ptr(binary_t* /*unused*/) noexcept + { + return is_binary() ? m_value.binary : nullptr; + } + + /// get a pointer to the value (binary) + constexpr const binary_t* get_impl_ptr(const binary_t* /*unused*/) const noexcept + { + return is_binary() ? m_value.binary : nullptr; + } + + /*! + @brief helper function to implement get_ref() + + This function helps to implement get_ref() without code duplication for + const and non-const overloads + + @tparam ThisType will be deduced as `basic_json` or `const basic_json` + + @throw type_error.303 if ReferenceType does not match underlying value + type of the current JSON + */ + template + static ReferenceType get_ref_impl(ThisType& obj) + { + // delegate the call to get_ptr<>() + auto* ptr = obj.template get_ptr::type>(); + + if (JSON_HEDLEY_LIKELY(ptr != nullptr)) + { + return *ptr; + } + + JSON_THROW(type_error::create(303, "incompatible ReferenceType for get_ref, actual type is " + std::string(obj.type_name()), obj)); + } + + public: + /// @name value access + /// Direct access to the stored value of a JSON value. + /// @{ + + /*! + @brief get a pointer value (implicit) + + Implicit pointer access to the internally stored JSON value. No copies are + made. + + @warning Writing data to the pointee of the result yields an undefined + state. + + @tparam PointerType pointer type; must be a pointer to @ref array_t, @ref + object_t, @ref string_t, @ref boolean_t, @ref number_integer_t, + @ref number_unsigned_t, or @ref number_float_t. Enforced by a static + assertion. + + @return pointer to the internally stored JSON value if the requested + pointer type @a PointerType fits to the JSON value; `nullptr` otherwise + + @complexity Constant. + + @liveexample{The example below shows how pointers to internal values of a + JSON value can be requested. Note that no type conversions are made and a + `nullptr` is returned if the value and the requested pointer type does not + match.,get_ptr} + + @since version 1.0.0 + */ + template::value, int>::type = 0> + auto get_ptr() noexcept -> decltype(std::declval().get_impl_ptr(std::declval())) + { + // delegate the call to get_impl_ptr<>() + return get_impl_ptr(static_cast(nullptr)); + } + + /*! + @brief get a pointer value (implicit) + @copydoc get_ptr() + */ + template < typename PointerType, typename std::enable_if < + std::is_pointer::value&& + std::is_const::type>::value, int >::type = 0 > + constexpr auto get_ptr() const noexcept -> decltype(std::declval().get_impl_ptr(std::declval())) + { + // delegate the call to get_impl_ptr<>() const + return get_impl_ptr(static_cast(nullptr)); + } + + private: + /*! + @brief get a value (explicit) + + Explicit type conversion between the JSON value and a compatible value + which is [CopyConstructible](https://en.cppreference.com/w/cpp/named_req/CopyConstructible) + and [DefaultConstructible](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible). + The value is converted by calling the @ref json_serializer + `from_json()` method. + + The function is equivalent to executing + @code {.cpp} + ValueType ret; + JSONSerializer::from_json(*this, ret); + return ret; + @endcode + + This overloads is chosen if: + - @a ValueType is not @ref basic_json, + - @ref json_serializer has a `from_json()` method of the form + `void from_json(const basic_json&, ValueType&)`, and + - @ref json_serializer does not have a `from_json()` method of + the form `ValueType from_json(const basic_json&)` + + @tparam ValueType the returned value type + + @return copy of the JSON value, converted to @a ValueType + + @throw what @ref json_serializer `from_json()` method throws + + @liveexample{The example below shows several conversions from JSON values + to other types. There a few things to note: (1) Floating-point numbers can + be converted to integers\, (2) A JSON array can be converted to a standard + `std::vector`\, (3) A JSON object can be converted to C++ + associative containers such as `std::unordered_map`.,get__ValueType_const} + + @since version 2.1.0 + */ + template < typename ValueType, + detail::enable_if_t < + detail::is_default_constructible::value&& + detail::has_from_json::value, + int > = 0 > + ValueType get_impl(detail::priority_tag<0> /*unused*/) const noexcept(noexcept( + JSONSerializer::from_json(std::declval(), std::declval()))) + { + auto ret = ValueType(); + JSONSerializer::from_json(*this, ret); + return ret; + } + + /*! + @brief get a value (explicit); special case + + Explicit type conversion between the JSON value and a compatible value + which is **not** [CopyConstructible](https://en.cppreference.com/w/cpp/named_req/CopyConstructible) + and **not** [DefaultConstructible](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible). + The value is converted by calling the @ref json_serializer + `from_json()` method. + + The function is equivalent to executing + @code {.cpp} + return JSONSerializer::from_json(*this); + @endcode + + This overloads is chosen if: + - @a ValueType is not @ref basic_json and + - @ref json_serializer has a `from_json()` method of the form + `ValueType from_json(const basic_json&)` + + @note If @ref json_serializer has both overloads of + `from_json()`, this one is chosen. + + @tparam ValueType the returned value type + + @return copy of the JSON value, converted to @a ValueType + + @throw what @ref json_serializer `from_json()` method throws + + @since version 2.1.0 + */ + template < typename ValueType, + detail::enable_if_t < + detail::has_non_default_from_json::value, + int > = 0 > + ValueType get_impl(detail::priority_tag<1> /*unused*/) const noexcept(noexcept( + JSONSerializer::from_json(std::declval()))) + { + return JSONSerializer::from_json(*this); + } + + /*! + @brief get special-case overload + + This overloads converts the current @ref basic_json in a different + @ref basic_json type + + @tparam BasicJsonType == @ref basic_json + + @return a copy of *this, converted into @a BasicJsonType + + @complexity Depending on the implementation of the called `from_json()` + method. + + @since version 3.2.0 + */ + template < typename BasicJsonType, + detail::enable_if_t < + detail::is_basic_json::value, + int > = 0 > + BasicJsonType get_impl(detail::priority_tag<2> /*unused*/) const + { + return *this; + } + + /*! + @brief get special-case overload + + This overloads avoids a lot of template boilerplate, it can be seen as the + identity method + + @tparam BasicJsonType == @ref basic_json + + @return a copy of *this + + @complexity Constant. + + @since version 2.1.0 + */ + template::value, + int> = 0> + basic_json get_impl(detail::priority_tag<3> /*unused*/) const + { + return *this; + } + + /*! + @brief get a pointer value (explicit) + @copydoc get() + */ + template::value, + int> = 0> + constexpr auto get_impl(detail::priority_tag<4> /*unused*/) const noexcept + -> decltype(std::declval().template get_ptr()) + { + // delegate the call to get_ptr + return get_ptr(); + } + + public: + /*! + @brief get a (pointer) value (explicit) + + Performs explicit type conversion between the JSON value and a compatible value if required. + + - If the requested type is a pointer to the internally stored JSON value that pointer is returned. + No copies are made. + + - If the requested type is the current @ref basic_json, or a different @ref basic_json convertible + from the current @ref basic_json. + + - Otherwise the value is converted by calling the @ref json_serializer `from_json()` + method. + + @tparam ValueTypeCV the provided value type + @tparam ValueType the returned value type + + @return copy of the JSON value, converted to @tparam ValueType if necessary + + @throw what @ref json_serializer `from_json()` method throws if conversion is required + + @since version 2.1.0 + */ + template < typename ValueTypeCV, typename ValueType = detail::uncvref_t> +#if defined(JSON_HAS_CPP_14) + constexpr +#endif + auto get() const noexcept( + noexcept(std::declval().template get_impl(detail::priority_tag<4> {}))) + -> decltype(std::declval().template get_impl(detail::priority_tag<4> {})) + { + // we cannot static_assert on ValueTypeCV being non-const, because + // there is support for get(), which is why we + // still need the uncvref + static_assert(!std::is_reference::value, + "get() cannot be used with reference types, you might want to use get_ref()"); + return get_impl(detail::priority_tag<4> {}); + } + + /*! + @brief get a pointer value (explicit) + + Explicit pointer access to the internally stored JSON value. No copies are + made. + + @warning The pointer becomes invalid if the underlying JSON object + changes. + + @tparam PointerType pointer type; must be a pointer to @ref array_t, @ref + object_t, @ref string_t, @ref boolean_t, @ref number_integer_t, + @ref number_unsigned_t, or @ref number_float_t. + + @return pointer to the internally stored JSON value if the requested + pointer type @a PointerType fits to the JSON value; `nullptr` otherwise + + @complexity Constant. + + @liveexample{The example below shows how pointers to internal values of a + JSON value can be requested. Note that no type conversions are made and a + `nullptr` is returned if the value and the requested pointer type does not + match.,get__PointerType} + + @sa see @ref get_ptr() for explicit pointer-member access + + @since version 1.0.0 + */ + template::value, int>::type = 0> + auto get() noexcept -> decltype(std::declval().template get_ptr()) + { + // delegate the call to get_ptr + return get_ptr(); + } + + /*! + @brief get a value (explicit) + + Explicit type conversion between the JSON value and a compatible value. + The value is filled into the input parameter by calling the @ref json_serializer + `from_json()` method. + + The function is equivalent to executing + @code {.cpp} + ValueType v; + JSONSerializer::from_json(*this, v); + @endcode + + This overloads is chosen if: + - @a ValueType is not @ref basic_json, + - @ref json_serializer has a `from_json()` method of the form + `void from_json(const basic_json&, ValueType&)`, and + + @tparam ValueType the input parameter type. + + @return the input parameter, allowing chaining calls. + + @throw what @ref json_serializer `from_json()` method throws + + @liveexample{The example below shows several conversions from JSON values + to other types. There a few things to note: (1) Floating-point numbers can + be converted to integers\, (2) A JSON array can be converted to a standard + `std::vector`\, (3) A JSON object can be converted to C++ + associative containers such as `std::unordered_map`.,get_to} + + @since version 3.3.0 + */ + template < typename ValueType, + detail::enable_if_t < + !detail::is_basic_json::value&& + detail::has_from_json::value, + int > = 0 > + ValueType & get_to(ValueType& v) const noexcept(noexcept( + JSONSerializer::from_json(std::declval(), v))) + { + JSONSerializer::from_json(*this, v); + return v; + } + + // specialization to allow to call get_to with a basic_json value + // see https://github.com/nlohmann/json/issues/2175 + template::value, + int> = 0> + ValueType & get_to(ValueType& v) const + { + v = *this; + return v; + } + + template < + typename T, std::size_t N, + typename Array = T (&)[N], // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + detail::enable_if_t < + detail::has_from_json::value, int > = 0 > + Array get_to(T (&v)[N]) const // NOLINT(cppcoreguidelines-avoid-c-arrays,hicpp-avoid-c-arrays,modernize-avoid-c-arrays) + noexcept(noexcept(JSONSerializer::from_json( + std::declval(), v))) + { + JSONSerializer::from_json(*this, v); + return v; + } + + /*! + @brief get a reference value (implicit) + + Implicit reference access to the internally stored JSON value. No copies + are made. + + @warning Writing data to the referee of the result yields an undefined + state. + + @tparam ReferenceType reference type; must be a reference to @ref array_t, + @ref object_t, @ref string_t, @ref boolean_t, @ref number_integer_t, or + @ref number_float_t. Enforced by static assertion. + + @return reference to the internally stored JSON value if the requested + reference type @a ReferenceType fits to the JSON value; throws + type_error.303 otherwise + + @throw type_error.303 in case passed type @a ReferenceType is incompatible + with the stored JSON value; see example below + + @complexity Constant. + + @liveexample{The example shows several calls to `get_ref()`.,get_ref} + + @since version 1.1.0 + */ + template::value, int>::type = 0> + ReferenceType get_ref() + { + // delegate call to get_ref_impl + return get_ref_impl(*this); + } + + /*! + @brief get a reference value (implicit) + @copydoc get_ref() + */ + template < typename ReferenceType, typename std::enable_if < + std::is_reference::value&& + std::is_const::type>::value, int >::type = 0 > + ReferenceType get_ref() const + { + // delegate call to get_ref_impl + return get_ref_impl(*this); + } + + /*! + @brief get a value (implicit) + + Implicit type conversion between the JSON value and a compatible value. + The call is realized by calling @ref get() const. + + @tparam ValueType non-pointer type compatible to the JSON value, for + instance `int` for JSON integer numbers, `bool` for JSON booleans, or + `std::vector` types for JSON arrays. The character type of @ref string_t + as well as an initializer list of this type is excluded to avoid + ambiguities as these types implicitly convert to `std::string`. + + @return copy of the JSON value, converted to type @a ValueType + + @throw type_error.302 in case passed type @a ValueType is incompatible + to the JSON value type (e.g., the JSON value is of type boolean, but a + string is requested); see example below + + @complexity Linear in the size of the JSON value. + + @liveexample{The example below shows several conversions from JSON values + to other types. There a few things to note: (1) Floating-point numbers can + be converted to integers\, (2) A JSON array can be converted to a standard + `std::vector`\, (3) A JSON object can be converted to C++ + associative containers such as `std::unordered_map`.,operator__ValueType} + + @since version 1.0.0 + */ + template < typename ValueType, typename std::enable_if < + detail::conjunction < + detail::negation>, + detail::negation>>, + detail::negation>, + detail::negation>, + detail::negation>>, + +#if defined(JSON_HAS_CPP_17) && (defined(__GNUC__) || (defined(_MSC_VER) && _MSC_VER >= 1910 && _MSC_VER <= 1914)) + detail::negation>, +#endif + detail::is_detected_lazy + >::value, int >::type = 0 > + JSON_EXPLICIT operator ValueType() const + { + // delegate the call to get<>() const + return get(); + } + + /*! + @return reference to the binary value + + @throw type_error.302 if the value is not binary + + @sa see @ref is_binary() to check if the value is binary + + @since version 3.8.0 + */ + binary_t& get_binary() + { + if (!is_binary()) + { + JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(type_name()), *this)); + } + + return *get_ptr(); + } + + /// @copydoc get_binary() + const binary_t& get_binary() const + { + if (!is_binary()) + { + JSON_THROW(type_error::create(302, "type must be binary, but is " + std::string(type_name()), *this)); + } + + return *get_ptr(); + } + + /// @} + + + //////////////////// + // element access // + //////////////////// + + /// @name element access + /// Access to the JSON value. + /// @{ + + /*! + @brief access specified array element with bounds checking + + Returns a reference to the element at specified location @a idx, with + bounds checking. + + @param[in] idx index of the element to access + + @return reference to the element at index @a idx + + @throw type_error.304 if the JSON value is not an array; in this case, + calling `at` with an index makes no sense. See example below. + @throw out_of_range.401 if the index @a idx is out of range of the array; + that is, `idx >= size()`. See example below. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes in the JSON value. + + @complexity Constant. + + @since version 1.0.0 + + @liveexample{The example below shows how array elements can be read and + written using `at()`. It also demonstrates the different exceptions that + can be thrown.,at__size_type} + */ + reference at(size_type idx) + { + // at only works for arrays + if (JSON_HEDLEY_LIKELY(is_array())) + { + JSON_TRY + { + return set_parent(m_value.array->at(idx)); + } + JSON_CATCH (std::out_of_range&) + { + // create better exception explanation + JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this)); + } + } + else + { + JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this)); + } + } + + /*! + @brief access specified array element with bounds checking + + Returns a const reference to the element at specified location @a idx, + with bounds checking. + + @param[in] idx index of the element to access + + @return const reference to the element at index @a idx + + @throw type_error.304 if the JSON value is not an array; in this case, + calling `at` with an index makes no sense. See example below. + @throw out_of_range.401 if the index @a idx is out of range of the array; + that is, `idx >= size()`. See example below. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes in the JSON value. + + @complexity Constant. + + @since version 1.0.0 + + @liveexample{The example below shows how array elements can be read using + `at()`. It also demonstrates the different exceptions that can be thrown., + at__size_type_const} + */ + const_reference at(size_type idx) const + { + // at only works for arrays + if (JSON_HEDLEY_LIKELY(is_array())) + { + JSON_TRY + { + return m_value.array->at(idx); + } + JSON_CATCH (std::out_of_range&) + { + // create better exception explanation + JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this)); + } + } + else + { + JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this)); + } + } + + /*! + @brief access specified object element with bounds checking + + Returns a reference to the element at with specified key @a key, with + bounds checking. + + @param[in] key key of the element to access + + @return reference to the element at key @a key + + @throw type_error.304 if the JSON value is not an object; in this case, + calling `at` with a key makes no sense. See example below. + @throw out_of_range.403 if the key @a key is is not stored in the object; + that is, `find(key) == end()`. See example below. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes in the JSON value. + + @complexity Logarithmic in the size of the container. + + @sa see @ref operator[](const typename object_t::key_type&) for unchecked + access by reference + @sa see @ref value() for access by value with a default value + + @since version 1.0.0 + + @liveexample{The example below shows how object elements can be read and + written using `at()`. It also demonstrates the different exceptions that + can be thrown.,at__object_t_key_type} + */ + reference at(const typename object_t::key_type& key) + { + // at only works for objects + if (JSON_HEDLEY_LIKELY(is_object())) + { + JSON_TRY + { + return set_parent(m_value.object->at(key)); + } + JSON_CATCH (std::out_of_range&) + { + // create better exception explanation + JSON_THROW(out_of_range::create(403, "key '" + key + "' not found", *this)); + } + } + else + { + JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this)); + } + } + + /*! + @brief access specified object element with bounds checking + + Returns a const reference to the element at with specified key @a key, + with bounds checking. + + @param[in] key key of the element to access + + @return const reference to the element at key @a key + + @throw type_error.304 if the JSON value is not an object; in this case, + calling `at` with a key makes no sense. See example below. + @throw out_of_range.403 if the key @a key is is not stored in the object; + that is, `find(key) == end()`. See example below. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes in the JSON value. + + @complexity Logarithmic in the size of the container. + + @sa see @ref operator[](const typename object_t::key_type&) for unchecked + access by reference + @sa see @ref value() for access by value with a default value + + @since version 1.0.0 + + @liveexample{The example below shows how object elements can be read using + `at()`. It also demonstrates the different exceptions that can be thrown., + at__object_t_key_type_const} + */ + const_reference at(const typename object_t::key_type& key) const + { + // at only works for objects + if (JSON_HEDLEY_LIKELY(is_object())) + { + JSON_TRY + { + return m_value.object->at(key); + } + JSON_CATCH (std::out_of_range&) + { + // create better exception explanation + JSON_THROW(out_of_range::create(403, "key '" + key + "' not found", *this)); + } + } + else + { + JSON_THROW(type_error::create(304, "cannot use at() with " + std::string(type_name()), *this)); + } + } + + /*! + @brief access specified array element + + Returns a reference to the element at specified location @a idx. + + @note If @a idx is beyond the range of the array (i.e., `idx >= size()`), + then the array is silently filled up with `null` values to make `idx` a + valid reference to the last stored element. + + @param[in] idx index of the element to access + + @return reference to the element at index @a idx + + @throw type_error.305 if the JSON value is not an array or null; in that + cases, using the [] operator with an index makes no sense. + + @complexity Constant if @a idx is in the range of the array. Otherwise + linear in `idx - size()`. + + @liveexample{The example below shows how array elements can be read and + written using `[]` operator. Note the addition of `null` + values.,operatorarray__size_type} + + @since version 1.0.0 + */ + reference operator[](size_type idx) + { + // implicitly convert null value to an empty array + if (is_null()) + { + m_type = value_t::array; + m_value.array = create(); + assert_invariant(); + } + + // operator[] only works for arrays + if (JSON_HEDLEY_LIKELY(is_array())) + { + // fill up array with null values if given idx is outside range + if (idx >= m_value.array->size()) + { +#if JSON_DIAGNOSTICS + // remember array size & capacity before resizing + const auto old_size = m_value.array->size(); + const auto old_capacity = m_value.array->capacity(); +#endif + m_value.array->resize(idx + 1); + +#if JSON_DIAGNOSTICS + if (JSON_HEDLEY_UNLIKELY(m_value.array->capacity() != old_capacity)) + { + // capacity has changed: update all parents + set_parents(); + } + else + { + // set parent for values added above + set_parents(begin() + static_cast(old_size), static_cast(idx + 1 - old_size)); + } +#endif + assert_invariant(); + } + + return m_value.array->operator[](idx); + } + + JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name()), *this)); + } + + /*! + @brief access specified array element + + Returns a const reference to the element at specified location @a idx. + + @param[in] idx index of the element to access + + @return const reference to the element at index @a idx + + @throw type_error.305 if the JSON value is not an array; in that case, + using the [] operator with an index makes no sense. + + @complexity Constant. + + @liveexample{The example below shows how array elements can be read using + the `[]` operator.,operatorarray__size_type_const} + + @since version 1.0.0 + */ + const_reference operator[](size_type idx) const + { + // const operator[] only works for arrays + if (JSON_HEDLEY_LIKELY(is_array())) + { + return m_value.array->operator[](idx); + } + + JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name()), *this)); + } + + /*! + @brief access specified object element + + Returns a reference to the element at with specified key @a key. + + @note If @a key is not found in the object, then it is silently added to + the object and filled with a `null` value to make `key` a valid reference. + In case the value was `null` before, it is converted to an object. + + @param[in] key key of the element to access + + @return reference to the element at key @a key + + @throw type_error.305 if the JSON value is not an object or null; in that + cases, using the [] operator with a key makes no sense. + + @complexity Logarithmic in the size of the container. + + @liveexample{The example below shows how object elements can be read and + written using the `[]` operator.,operatorarray__key_type} + + @sa see @ref at(const typename object_t::key_type&) for access by reference + with range checking + @sa see @ref value() for access by value with a default value + + @since version 1.0.0 + */ + reference operator[](const typename object_t::key_type& key) + { + // implicitly convert null value to an empty object + if (is_null()) + { + m_type = value_t::object; + m_value.object = create(); + assert_invariant(); + } + + // operator[] only works for objects + if (JSON_HEDLEY_LIKELY(is_object())) + { + return set_parent(m_value.object->operator[](key)); + } + + JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this)); + } + + /*! + @brief read-only access specified object element + + Returns a const reference to the element at with specified key @a key. No + bounds checking is performed. + + @warning If the element with key @a key does not exist, the behavior is + undefined. + + @param[in] key key of the element to access + + @return const reference to the element at key @a key + + @pre The element with key @a key must exist. **This precondition is + enforced with an assertion.** + + @throw type_error.305 if the JSON value is not an object; in that case, + using the [] operator with a key makes no sense. + + @complexity Logarithmic in the size of the container. + + @liveexample{The example below shows how object elements can be read using + the `[]` operator.,operatorarray__key_type_const} + + @sa see @ref at(const typename object_t::key_type&) for access by reference + with range checking + @sa see @ref value() for access by value with a default value + + @since version 1.0.0 + */ + const_reference operator[](const typename object_t::key_type& key) const + { + // const operator[] only works for objects + if (JSON_HEDLEY_LIKELY(is_object())) + { + JSON_ASSERT(m_value.object->find(key) != m_value.object->end()); + return m_value.object->find(key)->second; + } + + JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this)); + } + + /*! + @brief access specified object element + + Returns a reference to the element at with specified key @a key. + + @note If @a key is not found in the object, then it is silently added to + the object and filled with a `null` value to make `key` a valid reference. + In case the value was `null` before, it is converted to an object. + + @param[in] key key of the element to access + + @return reference to the element at key @a key + + @throw type_error.305 if the JSON value is not an object or null; in that + cases, using the [] operator with a key makes no sense. + + @complexity Logarithmic in the size of the container. + + @liveexample{The example below shows how object elements can be read and + written using the `[]` operator.,operatorarray__key_type} + + @sa see @ref at(const typename object_t::key_type&) for access by reference + with range checking + @sa see @ref value() for access by value with a default value + + @since version 1.1.0 + */ + template + JSON_HEDLEY_NON_NULL(2) + reference operator[](T* key) + { + // implicitly convert null to object + if (is_null()) + { + m_type = value_t::object; + m_value = value_t::object; + assert_invariant(); + } + + // at only works for objects + if (JSON_HEDLEY_LIKELY(is_object())) + { + return set_parent(m_value.object->operator[](key)); + } + + JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this)); + } + + /*! + @brief read-only access specified object element + + Returns a const reference to the element at with specified key @a key. No + bounds checking is performed. + + @warning If the element with key @a key does not exist, the behavior is + undefined. + + @param[in] key key of the element to access + + @return const reference to the element at key @a key + + @pre The element with key @a key must exist. **This precondition is + enforced with an assertion.** + + @throw type_error.305 if the JSON value is not an object; in that case, + using the [] operator with a key makes no sense. + + @complexity Logarithmic in the size of the container. + + @liveexample{The example below shows how object elements can be read using + the `[]` operator.,operatorarray__key_type_const} + + @sa see @ref at(const typename object_t::key_type&) for access by reference + with range checking + @sa see @ref value() for access by value with a default value + + @since version 1.1.0 + */ + template + JSON_HEDLEY_NON_NULL(2) + const_reference operator[](T* key) const + { + // at only works for objects + if (JSON_HEDLEY_LIKELY(is_object())) + { + JSON_ASSERT(m_value.object->find(key) != m_value.object->end()); + return m_value.object->find(key)->second; + } + + JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this)); + } + + /*! + @brief access specified object element with default value + + Returns either a copy of an object's element at the specified key @a key + or a given default value if no element with key @a key exists. + + The function is basically equivalent to executing + @code {.cpp} + try { + return at(key); + } catch(out_of_range) { + return default_value; + } + @endcode + + @note Unlike @ref at(const typename object_t::key_type&), this function + does not throw if the given key @a key was not found. + + @note Unlike @ref operator[](const typename object_t::key_type& key), this + function does not implicitly add an element to the position defined by @a + key. This function is furthermore also applicable to const objects. + + @param[in] key key of the element to access + @param[in] default_value the value to return if @a key is not found + + @tparam ValueType type compatible to JSON values, for instance `int` for + JSON integer numbers, `bool` for JSON booleans, or `std::vector` types for + JSON arrays. Note the type of the expected value at @a key and the default + value @a default_value must be compatible. + + @return copy of the element at key @a key or @a default_value if @a key + is not found + + @throw type_error.302 if @a default_value does not match the type of the + value at @a key + @throw type_error.306 if the JSON value is not an object; in that case, + using `value()` with a key makes no sense. + + @complexity Logarithmic in the size of the container. + + @liveexample{The example below shows how object elements can be queried + with a default value.,basic_json__value} + + @sa see @ref at(const typename object_t::key_type&) for access by reference + with range checking + @sa see @ref operator[](const typename object_t::key_type&) for unchecked + access by reference + + @since version 1.0.0 + */ + // using std::is_convertible in a std::enable_if will fail when using explicit conversions + template < class ValueType, typename std::enable_if < + detail::is_getable::value + && !std::is_same::value, int >::type = 0 > + ValueType value(const typename object_t::key_type& key, const ValueType& default_value) const + { + // at only works for objects + if (JSON_HEDLEY_LIKELY(is_object())) + { + // if key is found, return value and given default value otherwise + const auto it = find(key); + if (it != end()) + { + return it->template get(); + } + + return default_value; + } + + JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), *this)); + } + + /*! + @brief overload for a default value of type const char* + @copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const + */ + string_t value(const typename object_t::key_type& key, const char* default_value) const + { + return value(key, string_t(default_value)); + } + + /*! + @brief access specified object element via JSON Pointer with default value + + Returns either a copy of an object's element at the specified key @a key + or a given default value if no element with key @a key exists. + + The function is basically equivalent to executing + @code {.cpp} + try { + return at(ptr); + } catch(out_of_range) { + return default_value; + } + @endcode + + @note Unlike @ref at(const json_pointer&), this function does not throw + if the given key @a key was not found. + + @param[in] ptr a JSON pointer to the element to access + @param[in] default_value the value to return if @a ptr found no value + + @tparam ValueType type compatible to JSON values, for instance `int` for + JSON integer numbers, `bool` for JSON booleans, or `std::vector` types for + JSON arrays. Note the type of the expected value at @a key and the default + value @a default_value must be compatible. + + @return copy of the element at key @a key or @a default_value if @a key + is not found + + @throw type_error.302 if @a default_value does not match the type of the + value at @a ptr + @throw type_error.306 if the JSON value is not an object; in that case, + using `value()` with a key makes no sense. + + @complexity Logarithmic in the size of the container. + + @liveexample{The example below shows how object elements can be queried + with a default value.,basic_json__value_ptr} + + @sa see @ref operator[](const json_pointer&) for unchecked access by reference + + @since version 2.0.2 + */ + template::value, int>::type = 0> + ValueType value(const json_pointer& ptr, const ValueType& default_value) const + { + // at only works for objects + if (JSON_HEDLEY_LIKELY(is_object())) + { + // if pointer resolves a value, return it or use default value + JSON_TRY + { + return ptr.get_checked(this).template get(); + } + JSON_INTERNAL_CATCH (out_of_range&) + { + return default_value; + } + } + + JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), *this)); + } + + /*! + @brief overload for a default value of type const char* + @copydoc basic_json::value(const json_pointer&, ValueType) const + */ + JSON_HEDLEY_NON_NULL(3) + string_t value(const json_pointer& ptr, const char* default_value) const + { + return value(ptr, string_t(default_value)); + } + + /*! + @brief access the first element + + Returns a reference to the first element in the container. For a JSON + container `c`, the expression `c.front()` is equivalent to `*c.begin()`. + + @return In case of a structured type (array or object), a reference to the + first element is returned. In case of number, string, boolean, or binary + values, a reference to the value is returned. + + @complexity Constant. + + @pre The JSON value must not be `null` (would throw `std::out_of_range`) + or an empty array or object (undefined behavior, **guarded by + assertions**). + @post The JSON value remains unchanged. + + @throw invalid_iterator.214 when called on `null` value + + @liveexample{The following code shows an example for `front()`.,front} + + @sa see @ref back() -- access the last element + + @since version 1.0.0 + */ + reference front() + { + return *begin(); + } + + /*! + @copydoc basic_json::front() + */ + const_reference front() const + { + return *cbegin(); + } + + /*! + @brief access the last element + + Returns a reference to the last element in the container. For a JSON + container `c`, the expression `c.back()` is equivalent to + @code {.cpp} + auto tmp = c.end(); + --tmp; + return *tmp; + @endcode + + @return In case of a structured type (array or object), a reference to the + last element is returned. In case of number, string, boolean, or binary + values, a reference to the value is returned. + + @complexity Constant. + + @pre The JSON value must not be `null` (would throw `std::out_of_range`) + or an empty array or object (undefined behavior, **guarded by + assertions**). + @post The JSON value remains unchanged. + + @throw invalid_iterator.214 when called on a `null` value. See example + below. + + @liveexample{The following code shows an example for `back()`.,back} + + @sa see @ref front() -- access the first element + + @since version 1.0.0 + */ + reference back() + { + auto tmp = end(); + --tmp; + return *tmp; + } + + /*! + @copydoc basic_json::back() + */ + const_reference back() const + { + auto tmp = cend(); + --tmp; + return *tmp; + } + + /*! + @brief remove element given an iterator + + Removes the element specified by iterator @a pos. The iterator @a pos must + be valid and dereferenceable. Thus the `end()` iterator (which is valid, + but is not dereferenceable) cannot be used as a value for @a pos. + + If called on a primitive type other than `null`, the resulting JSON value + will be `null`. + + @param[in] pos iterator to the element to remove + @return Iterator following the last removed element. If the iterator @a + pos refers to the last element, the `end()` iterator is returned. + + @tparam IteratorType an @ref iterator or @ref const_iterator + + @post Invalidates iterators and references at or after the point of the + erase, including the `end()` iterator. + + @throw type_error.307 if called on a `null` value; example: `"cannot use + erase() with null"` + @throw invalid_iterator.202 if called on an iterator which does not belong + to the current JSON value; example: `"iterator does not fit current + value"` + @throw invalid_iterator.205 if called on a primitive type with invalid + iterator (i.e., any iterator which is not `begin()`); example: `"iterator + out of range"` + + @complexity The complexity depends on the type: + - objects: amortized constant + - arrays: linear in distance between @a pos and the end of the container + - strings and binary: linear in the length of the member + - other types: constant + + @liveexample{The example shows the result of `erase()` for different JSON + types.,erase__IteratorType} + + @sa see @ref erase(IteratorType, IteratorType) -- removes the elements in + the given range + @sa see @ref erase(const typename object_t::key_type&) -- removes the element + from an object at the given key + @sa see @ref erase(const size_type) -- removes the element from an array at + the given index + + @since version 1.0.0 + */ + template < class IteratorType, typename std::enable_if < + std::is_same::value || + std::is_same::value, int >::type + = 0 > + IteratorType erase(IteratorType pos) + { + // make sure iterator fits the current value + if (JSON_HEDLEY_UNLIKELY(this != pos.m_object)) + { + JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this)); + } + + IteratorType result = end(); + + switch (m_type) + { + case value_t::boolean: + case value_t::number_float: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::string: + case value_t::binary: + { + if (JSON_HEDLEY_UNLIKELY(!pos.m_it.primitive_iterator.is_begin())) + { + JSON_THROW(invalid_iterator::create(205, "iterator out of range", *this)); + } + + if (is_string()) + { + AllocatorType alloc; + std::allocator_traits::destroy(alloc, m_value.string); + std::allocator_traits::deallocate(alloc, m_value.string, 1); + m_value.string = nullptr; + } + else if (is_binary()) + { + AllocatorType alloc; + std::allocator_traits::destroy(alloc, m_value.binary); + std::allocator_traits::deallocate(alloc, m_value.binary, 1); + m_value.binary = nullptr; + } + + m_type = value_t::null; + assert_invariant(); + break; + } + + case value_t::object: + { + result.m_it.object_iterator = m_value.object->erase(pos.m_it.object_iterator); + break; + } + + case value_t::array: + { + result.m_it.array_iterator = m_value.array->erase(pos.m_it.array_iterator); + break; + } + + case value_t::null: + case value_t::discarded: + default: + JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this)); + } + + return result; + } + + /*! + @brief remove elements given an iterator range + + Removes the element specified by the range `[first; last)`. The iterator + @a first does not need to be dereferenceable if `first == last`: erasing + an empty range is a no-op. + + If called on a primitive type other than `null`, the resulting JSON value + will be `null`. + + @param[in] first iterator to the beginning of the range to remove + @param[in] last iterator past the end of the range to remove + @return Iterator following the last removed element. If the iterator @a + second refers to the last element, the `end()` iterator is returned. + + @tparam IteratorType an @ref iterator or @ref const_iterator + + @post Invalidates iterators and references at or after the point of the + erase, including the `end()` iterator. + + @throw type_error.307 if called on a `null` value; example: `"cannot use + erase() with null"` + @throw invalid_iterator.203 if called on iterators which does not belong + to the current JSON value; example: `"iterators do not fit current value"` + @throw invalid_iterator.204 if called on a primitive type with invalid + iterators (i.e., if `first != begin()` and `last != end()`); example: + `"iterators out of range"` + + @complexity The complexity depends on the type: + - objects: `log(size()) + std::distance(first, last)` + - arrays: linear in the distance between @a first and @a last, plus linear + in the distance between @a last and end of the container + - strings and binary: linear in the length of the member + - other types: constant + + @liveexample{The example shows the result of `erase()` for different JSON + types.,erase__IteratorType_IteratorType} + + @sa see @ref erase(IteratorType) -- removes the element at a given position + @sa see @ref erase(const typename object_t::key_type&) -- removes the element + from an object at the given key + @sa see @ref erase(const size_type) -- removes the element from an array at + the given index + + @since version 1.0.0 + */ + template < class IteratorType, typename std::enable_if < + std::is_same::value || + std::is_same::value, int >::type + = 0 > + IteratorType erase(IteratorType first, IteratorType last) + { + // make sure iterator fits the current value + if (JSON_HEDLEY_UNLIKELY(this != first.m_object || this != last.m_object)) + { + JSON_THROW(invalid_iterator::create(203, "iterators do not fit current value", *this)); + } + + IteratorType result = end(); + + switch (m_type) + { + case value_t::boolean: + case value_t::number_float: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::string: + case value_t::binary: + { + if (JSON_HEDLEY_LIKELY(!first.m_it.primitive_iterator.is_begin() + || !last.m_it.primitive_iterator.is_end())) + { + JSON_THROW(invalid_iterator::create(204, "iterators out of range", *this)); + } + + if (is_string()) + { + AllocatorType alloc; + std::allocator_traits::destroy(alloc, m_value.string); + std::allocator_traits::deallocate(alloc, m_value.string, 1); + m_value.string = nullptr; + } + else if (is_binary()) + { + AllocatorType alloc; + std::allocator_traits::destroy(alloc, m_value.binary); + std::allocator_traits::deallocate(alloc, m_value.binary, 1); + m_value.binary = nullptr; + } + + m_type = value_t::null; + assert_invariant(); + break; + } + + case value_t::object: + { + result.m_it.object_iterator = m_value.object->erase(first.m_it.object_iterator, + last.m_it.object_iterator); + break; + } + + case value_t::array: + { + result.m_it.array_iterator = m_value.array->erase(first.m_it.array_iterator, + last.m_it.array_iterator); + break; + } + + case value_t::null: + case value_t::discarded: + default: + JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this)); + } + + return result; + } + + /*! + @brief remove element from a JSON object given a key + + Removes elements from a JSON object with the key value @a key. + + @param[in] key value of the elements to remove + + @return Number of elements removed. If @a ObjectType is the default + `std::map` type, the return value will always be `0` (@a key was not + found) or `1` (@a key was found). + + @post References and iterators to the erased elements are invalidated. + Other references and iterators are not affected. + + @throw type_error.307 when called on a type other than JSON object; + example: `"cannot use erase() with null"` + + @complexity `log(size()) + count(key)` + + @liveexample{The example shows the effect of `erase()`.,erase__key_type} + + @sa see @ref erase(IteratorType) -- removes the element at a given position + @sa see @ref erase(IteratorType, IteratorType) -- removes the elements in + the given range + @sa see @ref erase(const size_type) -- removes the element from an array at + the given index + + @since version 1.0.0 + */ + size_type erase(const typename object_t::key_type& key) + { + // this erase only works for objects + if (JSON_HEDLEY_LIKELY(is_object())) + { + return m_value.object->erase(key); + } + + JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this)); + } + + /*! + @brief remove element from a JSON array given an index + + Removes element from a JSON array at the index @a idx. + + @param[in] idx index of the element to remove + + @throw type_error.307 when called on a type other than JSON object; + example: `"cannot use erase() with null"` + @throw out_of_range.401 when `idx >= size()`; example: `"array index 17 + is out of range"` + + @complexity Linear in distance between @a idx and the end of the container. + + @liveexample{The example shows the effect of `erase()`.,erase__size_type} + + @sa see @ref erase(IteratorType) -- removes the element at a given position + @sa see @ref erase(IteratorType, IteratorType) -- removes the elements in + the given range + @sa see @ref erase(const typename object_t::key_type&) -- removes the element + from an object at the given key + + @since version 1.0.0 + */ + void erase(const size_type idx) + { + // this erase only works for arrays + if (JSON_HEDLEY_LIKELY(is_array())) + { + if (JSON_HEDLEY_UNLIKELY(idx >= size())) + { + JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", *this)); + } + + m_value.array->erase(m_value.array->begin() + static_cast(idx)); + } + else + { + JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this)); + } + } + + /// @} + + + //////////// + // lookup // + //////////// + + /// @name lookup + /// @{ + + /*! + @brief find an element in a JSON object + + Finds an element in a JSON object with key equivalent to @a key. If the + element is not found or the JSON value is not an object, end() is + returned. + + @note This method always returns @ref end() when executed on a JSON type + that is not an object. + + @param[in] key key value of the element to search for. + + @return Iterator to an element with key equivalent to @a key. If no such + element is found or the JSON value is not an object, past-the-end (see + @ref end()) iterator is returned. + + @complexity Logarithmic in the size of the JSON object. + + @liveexample{The example shows how `find()` is used.,find__key_type} + + @sa see @ref contains(KeyT&&) const -- checks whether a key exists + + @since version 1.0.0 + */ + template + iterator find(KeyT&& key) + { + auto result = end(); + + if (is_object()) + { + result.m_it.object_iterator = m_value.object->find(std::forward(key)); + } + + return result; + } + + /*! + @brief find an element in a JSON object + @copydoc find(KeyT&&) + */ + template + const_iterator find(KeyT&& key) const + { + auto result = cend(); + + if (is_object()) + { + result.m_it.object_iterator = m_value.object->find(std::forward(key)); + } + + return result; + } + + /*! + @brief returns the number of occurrences of a key in a JSON object + + Returns the number of elements with key @a key. If ObjectType is the + default `std::map` type, the return value will always be `0` (@a key was + not found) or `1` (@a key was found). + + @note This method always returns `0` when executed on a JSON type that is + not an object. + + @param[in] key key value of the element to count + + @return Number of elements with key @a key. If the JSON value is not an + object, the return value will be `0`. + + @complexity Logarithmic in the size of the JSON object. + + @liveexample{The example shows how `count()` is used.,count} + + @since version 1.0.0 + */ + template + size_type count(KeyT&& key) const + { + // return 0 for all nonobject types + return is_object() ? m_value.object->count(std::forward(key)) : 0; + } + + /*! + @brief check the existence of an element in a JSON object + + Check whether an element exists in a JSON object with key equivalent to + @a key. If the element is not found or the JSON value is not an object, + false is returned. + + @note This method always returns false when executed on a JSON type + that is not an object. + + @param[in] key key value to check its existence. + + @return true if an element with specified @a key exists. If no such + element with such key is found or the JSON value is not an object, + false is returned. + + @complexity Logarithmic in the size of the JSON object. + + @liveexample{The following code shows an example for `contains()`.,contains} + + @sa see @ref find(KeyT&&) -- returns an iterator to an object element + @sa see @ref contains(const json_pointer&) const -- checks the existence for a JSON pointer + + @since version 3.6.0 + */ + template < typename KeyT, typename std::enable_if < + !std::is_same::type, json_pointer>::value, int >::type = 0 > + bool contains(KeyT && key) const + { + return is_object() && m_value.object->find(std::forward(key)) != m_value.object->end(); + } + + /*! + @brief check the existence of an element in a JSON object given a JSON pointer + + Check whether the given JSON pointer @a ptr can be resolved in the current + JSON value. + + @note This method can be executed on any JSON value type. + + @param[in] ptr JSON pointer to check its existence. + + @return true if the JSON pointer can be resolved to a stored value, false + otherwise. + + @post If `j.contains(ptr)` returns true, it is safe to call `j[ptr]`. + + @throw parse_error.106 if an array index begins with '0' + @throw parse_error.109 if an array index was not a number + + @complexity Logarithmic in the size of the JSON object. + + @liveexample{The following code shows an example for `contains()`.,contains_json_pointer} + + @sa see @ref contains(KeyT &&) const -- checks the existence of a key + + @since version 3.7.0 + */ + bool contains(const json_pointer& ptr) const + { + return ptr.contains(this); + } + + /// @} + + + /////////////// + // iterators // + /////////////// + + /// @name iterators + /// @{ + + /*! + @brief returns an iterator to the first element + + Returns an iterator to the first element. + + @image html range-begin-end.svg "Illustration from cppreference.com" + + @return iterator to the first element + + @complexity Constant. + + @requirement This function helps `basic_json` satisfying the + [Container](https://en.cppreference.com/w/cpp/named_req/Container) + requirements: + - The complexity is constant. + + @liveexample{The following code shows an example for `begin()`.,begin} + + @sa see @ref cbegin() -- returns a const iterator to the beginning + @sa see @ref end() -- returns an iterator to the end + @sa see @ref cend() -- returns a const iterator to the end + + @since version 1.0.0 + */ + iterator begin() noexcept + { + iterator result(this); + result.set_begin(); + return result; + } + + /*! + @copydoc basic_json::cbegin() + */ + const_iterator begin() const noexcept + { + return cbegin(); + } + + /*! + @brief returns a const iterator to the first element + + Returns a const iterator to the first element. + + @image html range-begin-end.svg "Illustration from cppreference.com" + + @return const iterator to the first element + + @complexity Constant. + + @requirement This function helps `basic_json` satisfying the + [Container](https://en.cppreference.com/w/cpp/named_req/Container) + requirements: + - The complexity is constant. + - Has the semantics of `const_cast(*this).begin()`. + + @liveexample{The following code shows an example for `cbegin()`.,cbegin} + + @sa see @ref begin() -- returns an iterator to the beginning + @sa see @ref end() -- returns an iterator to the end + @sa see @ref cend() -- returns a const iterator to the end + + @since version 1.0.0 + */ + const_iterator cbegin() const noexcept + { + const_iterator result(this); + result.set_begin(); + return result; + } + + /*! + @brief returns an iterator to one past the last element + + Returns an iterator to one past the last element. + + @image html range-begin-end.svg "Illustration from cppreference.com" + + @return iterator one past the last element + + @complexity Constant. + + @requirement This function helps `basic_json` satisfying the + [Container](https://en.cppreference.com/w/cpp/named_req/Container) + requirements: + - The complexity is constant. + + @liveexample{The following code shows an example for `end()`.,end} + + @sa see @ref cend() -- returns a const iterator to the end + @sa see @ref begin() -- returns an iterator to the beginning + @sa see @ref cbegin() -- returns a const iterator to the beginning + + @since version 1.0.0 + */ + iterator end() noexcept + { + iterator result(this); + result.set_end(); + return result; + } + + /*! + @copydoc basic_json::cend() + */ + const_iterator end() const noexcept + { + return cend(); + } + + /*! + @brief returns a const iterator to one past the last element + + Returns a const iterator to one past the last element. + + @image html range-begin-end.svg "Illustration from cppreference.com" + + @return const iterator one past the last element + + @complexity Constant. + + @requirement This function helps `basic_json` satisfying the + [Container](https://en.cppreference.com/w/cpp/named_req/Container) + requirements: + - The complexity is constant. + - Has the semantics of `const_cast(*this).end()`. + + @liveexample{The following code shows an example for `cend()`.,cend} + + @sa see @ref end() -- returns an iterator to the end + @sa see @ref begin() -- returns an iterator to the beginning + @sa see @ref cbegin() -- returns a const iterator to the beginning + + @since version 1.0.0 + */ + const_iterator cend() const noexcept + { + const_iterator result(this); + result.set_end(); + return result; + } + + /*! + @brief returns an iterator to the reverse-beginning + + Returns an iterator to the reverse-beginning; that is, the last element. + + @image html range-rbegin-rend.svg "Illustration from cppreference.com" + + @complexity Constant. + + @requirement This function helps `basic_json` satisfying the + [ReversibleContainer](https://en.cppreference.com/w/cpp/named_req/ReversibleContainer) + requirements: + - The complexity is constant. + - Has the semantics of `reverse_iterator(end())`. + + @liveexample{The following code shows an example for `rbegin()`.,rbegin} + + @sa see @ref crbegin() -- returns a const reverse iterator to the beginning + @sa see @ref rend() -- returns a reverse iterator to the end + @sa see @ref crend() -- returns a const reverse iterator to the end + + @since version 1.0.0 + */ + reverse_iterator rbegin() noexcept + { + return reverse_iterator(end()); + } + + /*! + @copydoc basic_json::crbegin() + */ + const_reverse_iterator rbegin() const noexcept + { + return crbegin(); + } + + /*! + @brief returns an iterator to the reverse-end + + Returns an iterator to the reverse-end; that is, one before the first + element. + + @image html range-rbegin-rend.svg "Illustration from cppreference.com" + + @complexity Constant. + + @requirement This function helps `basic_json` satisfying the + [ReversibleContainer](https://en.cppreference.com/w/cpp/named_req/ReversibleContainer) + requirements: + - The complexity is constant. + - Has the semantics of `reverse_iterator(begin())`. + + @liveexample{The following code shows an example for `rend()`.,rend} + + @sa see @ref crend() -- returns a const reverse iterator to the end + @sa see @ref rbegin() -- returns a reverse iterator to the beginning + @sa see @ref crbegin() -- returns a const reverse iterator to the beginning + + @since version 1.0.0 + */ + reverse_iterator rend() noexcept + { + return reverse_iterator(begin()); + } + + /*! + @copydoc basic_json::crend() + */ + const_reverse_iterator rend() const noexcept + { + return crend(); + } + + /*! + @brief returns a const reverse iterator to the last element + + Returns a const iterator to the reverse-beginning; that is, the last + element. + + @image html range-rbegin-rend.svg "Illustration from cppreference.com" + + @complexity Constant. + + @requirement This function helps `basic_json` satisfying the + [ReversibleContainer](https://en.cppreference.com/w/cpp/named_req/ReversibleContainer) + requirements: + - The complexity is constant. + - Has the semantics of `const_cast(*this).rbegin()`. + + @liveexample{The following code shows an example for `crbegin()`.,crbegin} + + @sa see @ref rbegin() -- returns a reverse iterator to the beginning + @sa see @ref rend() -- returns a reverse iterator to the end + @sa see @ref crend() -- returns a const reverse iterator to the end + + @since version 1.0.0 + */ + const_reverse_iterator crbegin() const noexcept + { + return const_reverse_iterator(cend()); + } + + /*! + @brief returns a const reverse iterator to one before the first + + Returns a const reverse iterator to the reverse-end; that is, one before + the first element. + + @image html range-rbegin-rend.svg "Illustration from cppreference.com" + + @complexity Constant. + + @requirement This function helps `basic_json` satisfying the + [ReversibleContainer](https://en.cppreference.com/w/cpp/named_req/ReversibleContainer) + requirements: + - The complexity is constant. + - Has the semantics of `const_cast(*this).rend()`. + + @liveexample{The following code shows an example for `crend()`.,crend} + + @sa see @ref rend() -- returns a reverse iterator to the end + @sa see @ref rbegin() -- returns a reverse iterator to the beginning + @sa see @ref crbegin() -- returns a const reverse iterator to the beginning + + @since version 1.0.0 + */ + const_reverse_iterator crend() const noexcept + { + return const_reverse_iterator(cbegin()); + } + + public: + /*! + @brief wrapper to access iterator member functions in range-based for + + This function allows to access @ref iterator::key() and @ref + iterator::value() during range-based for loops. In these loops, a + reference to the JSON values is returned, so there is no access to the + underlying iterator. + + For loop without iterator_wrapper: + + @code{cpp} + for (auto it = j_object.begin(); it != j_object.end(); ++it) + { + std::cout << "key: " << it.key() << ", value:" << it.value() << '\n'; + } + @endcode + + Range-based for loop without iterator proxy: + + @code{cpp} + for (auto it : j_object) + { + // "it" is of type json::reference and has no key() member + std::cout << "value: " << it << '\n'; + } + @endcode + + Range-based for loop with iterator proxy: + + @code{cpp} + for (auto it : json::iterator_wrapper(j_object)) + { + std::cout << "key: " << it.key() << ", value:" << it.value() << '\n'; + } + @endcode + + @note When iterating over an array, `key()` will return the index of the + element as string (see example). + + @param[in] ref reference to a JSON value + @return iteration proxy object wrapping @a ref with an interface to use in + range-based for loops + + @liveexample{The following code shows how the wrapper is used,iterator_wrapper} + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes in the JSON value. + + @complexity Constant. + + @note The name of this function is not yet final and may change in the + future. + + @deprecated This stream operator is deprecated and will be removed in + future 4.0.0 of the library. Please use @ref items() instead; + that is, replace `json::iterator_wrapper(j)` with `j.items()`. + */ + JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items()) + static iteration_proxy iterator_wrapper(reference ref) noexcept + { + return ref.items(); + } + + /*! + @copydoc iterator_wrapper(reference) + */ + JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items()) + static iteration_proxy iterator_wrapper(const_reference ref) noexcept + { + return ref.items(); + } + + /*! + @brief helper to access iterator member functions in range-based for + + This function allows to access @ref iterator::key() and @ref + iterator::value() during range-based for loops. In these loops, a + reference to the JSON values is returned, so there is no access to the + underlying iterator. + + For loop without `items()` function: + + @code{cpp} + for (auto it = j_object.begin(); it != j_object.end(); ++it) + { + std::cout << "key: " << it.key() << ", value:" << it.value() << '\n'; + } + @endcode + + Range-based for loop without `items()` function: + + @code{cpp} + for (auto it : j_object) + { + // "it" is of type json::reference and has no key() member + std::cout << "value: " << it << '\n'; + } + @endcode + + Range-based for loop with `items()` function: + + @code{cpp} + for (auto& el : j_object.items()) + { + std::cout << "key: " << el.key() << ", value:" << el.value() << '\n'; + } + @endcode + + The `items()` function also allows to use + [structured bindings](https://en.cppreference.com/w/cpp/language/structured_binding) + (C++17): + + @code{cpp} + for (auto& [key, val] : j_object.items()) + { + std::cout << "key: " << key << ", value:" << val << '\n'; + } + @endcode + + @note When iterating over an array, `key()` will return the index of the + element as string (see example). For primitive types (e.g., numbers), + `key()` returns an empty string. + + @warning Using `items()` on temporary objects is dangerous. Make sure the + object's lifetime exeeds the iteration. See + for more + information. + + @return iteration proxy object wrapping @a ref with an interface to use in + range-based for loops + + @liveexample{The following code shows how the function is used.,items} + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes in the JSON value. + + @complexity Constant. + + @since version 3.1.0, structured bindings support since 3.5.0. + */ + iteration_proxy items() noexcept + { + return iteration_proxy(*this); + } + + /*! + @copydoc items() + */ + iteration_proxy items() const noexcept + { + return iteration_proxy(*this); + } + + /// @} + + + ////////////// + // capacity // + ////////////// + + /// @name capacity + /// @{ + + /*! + @brief checks whether the container is empty. + + Checks if a JSON value has no elements (i.e. whether its @ref size is `0`). + + @return The return value depends on the different types and is + defined as follows: + Value type | return value + ----------- | ------------- + null | `true` + boolean | `false` + string | `false` + number | `false` + binary | `false` + object | result of function `object_t::empty()` + array | result of function `array_t::empty()` + + @liveexample{The following code uses `empty()` to check if a JSON + object contains any elements.,empty} + + @complexity Constant, as long as @ref array_t and @ref object_t satisfy + the Container concept; that is, their `empty()` functions have constant + complexity. + + @iterators No changes. + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + + @note This function does not return whether a string stored as JSON value + is empty - it returns whether the JSON container itself is empty which is + false in the case of a string. + + @requirement This function helps `basic_json` satisfying the + [Container](https://en.cppreference.com/w/cpp/named_req/Container) + requirements: + - The complexity is constant. + - Has the semantics of `begin() == end()`. + + @sa see @ref size() -- returns the number of elements + + @since version 1.0.0 + */ + bool empty() const noexcept + { + switch (m_type) + { + case value_t::null: + { + // null values are empty + return true; + } + + case value_t::array: + { + // delegate call to array_t::empty() + return m_value.array->empty(); + } + + case value_t::object: + { + // delegate call to object_t::empty() + return m_value.object->empty(); + } + + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + { + // all other types are nonempty + return false; + } + } + } + + /*! + @brief returns the number of elements + + Returns the number of elements in a JSON value. + + @return The return value depends on the different types and is + defined as follows: + Value type | return value + ----------- | ------------- + null | `0` + boolean | `1` + string | `1` + number | `1` + binary | `1` + object | result of function object_t::size() + array | result of function array_t::size() + + @liveexample{The following code calls `size()` on the different value + types.,size} + + @complexity Constant, as long as @ref array_t and @ref object_t satisfy + the Container concept; that is, their size() functions have constant + complexity. + + @iterators No changes. + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + + @note This function does not return the length of a string stored as JSON + value - it returns the number of elements in the JSON value which is 1 in + the case of a string. + + @requirement This function helps `basic_json` satisfying the + [Container](https://en.cppreference.com/w/cpp/named_req/Container) + requirements: + - The complexity is constant. + - Has the semantics of `std::distance(begin(), end())`. + + @sa see @ref empty() -- checks whether the container is empty + @sa see @ref max_size() -- returns the maximal number of elements + + @since version 1.0.0 + */ + size_type size() const noexcept + { + switch (m_type) + { + case value_t::null: + { + // null values are empty + return 0; + } + + case value_t::array: + { + // delegate call to array_t::size() + return m_value.array->size(); + } + + case value_t::object: + { + // delegate call to object_t::size() + return m_value.object->size(); + } + + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + { + // all other types have size 1 + return 1; + } + } + } + + /*! + @brief returns the maximum possible number of elements + + Returns the maximum number of elements a JSON value is able to hold due to + system or library implementation limitations, i.e. `std::distance(begin(), + end())` for the JSON value. + + @return The return value depends on the different types and is + defined as follows: + Value type | return value + ----------- | ------------- + null | `0` (same as `size()`) + boolean | `1` (same as `size()`) + string | `1` (same as `size()`) + number | `1` (same as `size()`) + binary | `1` (same as `size()`) + object | result of function `object_t::max_size()` + array | result of function `array_t::max_size()` + + @liveexample{The following code calls `max_size()` on the different value + types. Note the output is implementation specific.,max_size} + + @complexity Constant, as long as @ref array_t and @ref object_t satisfy + the Container concept; that is, their `max_size()` functions have constant + complexity. + + @iterators No changes. + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + + @requirement This function helps `basic_json` satisfying the + [Container](https://en.cppreference.com/w/cpp/named_req/Container) + requirements: + - The complexity is constant. + - Has the semantics of returning `b.size()` where `b` is the largest + possible JSON value. + + @sa see @ref size() -- returns the number of elements + + @since version 1.0.0 + */ + size_type max_size() const noexcept + { + switch (m_type) + { + case value_t::array: + { + // delegate call to array_t::max_size() + return m_value.array->max_size(); + } + + case value_t::object: + { + // delegate call to object_t::max_size() + return m_value.object->max_size(); + } + + case value_t::null: + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + { + // all other types have max_size() == size() + return size(); + } + } + } + + /// @} + + + /////////////// + // modifiers // + /////////////// + + /// @name modifiers + /// @{ + + /*! + @brief clears the contents + + Clears the content of a JSON value and resets it to the default value as + if @ref basic_json(value_t) would have been called with the current value + type from @ref type(): + + Value type | initial value + ----------- | ------------- + null | `null` + boolean | `false` + string | `""` + number | `0` + binary | An empty byte vector + object | `{}` + array | `[]` + + @post Has the same effect as calling + @code {.cpp} + *this = basic_json(type()); + @endcode + + @liveexample{The example below shows the effect of `clear()` to different + JSON types.,clear} + + @complexity Linear in the size of the JSON value. + + @iterators All iterators, pointers and references related to this container + are invalidated. + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + + @sa see @ref basic_json(value_t) -- constructor that creates an object with the + same value than calling `clear()` + + @since version 1.0.0 + */ + void clear() noexcept + { + switch (m_type) + { + case value_t::number_integer: + { + m_value.number_integer = 0; + break; + } + + case value_t::number_unsigned: + { + m_value.number_unsigned = 0; + break; + } + + case value_t::number_float: + { + m_value.number_float = 0.0; + break; + } + + case value_t::boolean: + { + m_value.boolean = false; + break; + } + + case value_t::string: + { + m_value.string->clear(); + break; + } + + case value_t::binary: + { + m_value.binary->clear(); + break; + } + + case value_t::array: + { + m_value.array->clear(); + break; + } + + case value_t::object: + { + m_value.object->clear(); + break; + } + + case value_t::null: + case value_t::discarded: + default: + break; + } + } + + /*! + @brief add an object to an array + + Appends the given element @a val to the end of the JSON value. If the + function is called on a JSON null value, an empty array is created before + appending @a val. + + @param[in] val the value to add to the JSON array + + @throw type_error.308 when called on a type other than JSON array or + null; example: `"cannot use push_back() with number"` + + @complexity Amortized constant. + + @liveexample{The example shows how `push_back()` and `+=` can be used to + add elements to a JSON array. Note how the `null` value was silently + converted to a JSON array.,push_back} + + @since version 1.0.0 + */ + void push_back(basic_json&& val) + { + // push_back only works for null objects or arrays + if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array()))) + { + JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this)); + } + + // transform null object into an array + if (is_null()) + { + m_type = value_t::array; + m_value = value_t::array; + assert_invariant(); + } + + // add element to array (move semantics) + const auto old_capacity = m_value.array->capacity(); + m_value.array->push_back(std::move(val)); + set_parent(m_value.array->back(), old_capacity); + // if val is moved from, basic_json move constructor marks it null so we do not call the destructor + } + + /*! + @brief add an object to an array + @copydoc push_back(basic_json&&) + */ + reference operator+=(basic_json&& val) + { + push_back(std::move(val)); + return *this; + } + + /*! + @brief add an object to an array + @copydoc push_back(basic_json&&) + */ + void push_back(const basic_json& val) + { + // push_back only works for null objects or arrays + if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array()))) + { + JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this)); + } + + // transform null object into an array + if (is_null()) + { + m_type = value_t::array; + m_value = value_t::array; + assert_invariant(); + } + + // add element to array + const auto old_capacity = m_value.array->capacity(); + m_value.array->push_back(val); + set_parent(m_value.array->back(), old_capacity); + } + + /*! + @brief add an object to an array + @copydoc push_back(basic_json&&) + */ + reference operator+=(const basic_json& val) + { + push_back(val); + return *this; + } + + /*! + @brief add an object to an object + + Inserts the given element @a val to the JSON object. If the function is + called on a JSON null value, an empty object is created before inserting + @a val. + + @param[in] val the value to add to the JSON object + + @throw type_error.308 when called on a type other than JSON object or + null; example: `"cannot use push_back() with number"` + + @complexity Logarithmic in the size of the container, O(log(`size()`)). + + @liveexample{The example shows how `push_back()` and `+=` can be used to + add elements to a JSON object. Note how the `null` value was silently + converted to a JSON object.,push_back__object_t__value} + + @since version 1.0.0 + */ + void push_back(const typename object_t::value_type& val) + { + // push_back only works for null objects or objects + if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object()))) + { + JSON_THROW(type_error::create(308, "cannot use push_back() with " + std::string(type_name()), *this)); + } + + // transform null object into an object + if (is_null()) + { + m_type = value_t::object; + m_value = value_t::object; + assert_invariant(); + } + + // add element to object + auto res = m_value.object->insert(val); + set_parent(res.first->second); + } + + /*! + @brief add an object to an object + @copydoc push_back(const typename object_t::value_type&) + */ + reference operator+=(const typename object_t::value_type& val) + { + push_back(val); + return *this; + } + + /*! + @brief add an object to an object + + This function allows to use `push_back` with an initializer list. In case + + 1. the current value is an object, + 2. the initializer list @a init contains only two elements, and + 3. the first element of @a init is a string, + + @a init is converted into an object element and added using + @ref push_back(const typename object_t::value_type&). Otherwise, @a init + is converted to a JSON value and added using @ref push_back(basic_json&&). + + @param[in] init an initializer list + + @complexity Linear in the size of the initializer list @a init. + + @note This function is required to resolve an ambiguous overload error, + because pairs like `{"key", "value"}` can be both interpreted as + `object_t::value_type` or `std::initializer_list`, see + https://github.com/nlohmann/json/issues/235 for more information. + + @liveexample{The example shows how initializer lists are treated as + objects when possible.,push_back__initializer_list} + */ + void push_back(initializer_list_t init) + { + if (is_object() && init.size() == 2 && (*init.begin())->is_string()) + { + basic_json&& key = init.begin()->moved_or_copied(); + push_back(typename object_t::value_type( + std::move(key.get_ref()), (init.begin() + 1)->moved_or_copied())); + } + else + { + push_back(basic_json(init)); + } + } + + /*! + @brief add an object to an object + @copydoc push_back(initializer_list_t) + */ + reference operator+=(initializer_list_t init) + { + push_back(init); + return *this; + } + + /*! + @brief add an object to an array + + Creates a JSON value from the passed parameters @a args to the end of the + JSON value. If the function is called on a JSON null value, an empty array + is created before appending the value created from @a args. + + @param[in] args arguments to forward to a constructor of @ref basic_json + @tparam Args compatible types to create a @ref basic_json object + + @return reference to the inserted element + + @throw type_error.311 when called on a type other than JSON array or + null; example: `"cannot use emplace_back() with number"` + + @complexity Amortized constant. + + @liveexample{The example shows how `push_back()` can be used to add + elements to a JSON array. Note how the `null` value was silently converted + to a JSON array.,emplace_back} + + @since version 2.0.8, returns reference since 3.7.0 + */ + template + reference emplace_back(Args&& ... args) + { + // emplace_back only works for null objects or arrays + if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_array()))) + { + JSON_THROW(type_error::create(311, "cannot use emplace_back() with " + std::string(type_name()), *this)); + } + + // transform null object into an array + if (is_null()) + { + m_type = value_t::array; + m_value = value_t::array; + assert_invariant(); + } + + // add element to array (perfect forwarding) + const auto old_capacity = m_value.array->capacity(); + m_value.array->emplace_back(std::forward(args)...); + return set_parent(m_value.array->back(), old_capacity); + } + + /*! + @brief add an object to an object if key does not exist + + Inserts a new element into a JSON object constructed in-place with the + given @a args if there is no element with the key in the container. If the + function is called on a JSON null value, an empty object is created before + appending the value created from @a args. + + @param[in] args arguments to forward to a constructor of @ref basic_json + @tparam Args compatible types to create a @ref basic_json object + + @return a pair consisting of an iterator to the inserted element, or the + already-existing element if no insertion happened, and a bool + denoting whether the insertion took place. + + @throw type_error.311 when called on a type other than JSON object or + null; example: `"cannot use emplace() with number"` + + @complexity Logarithmic in the size of the container, O(log(`size()`)). + + @liveexample{The example shows how `emplace()` can be used to add elements + to a JSON object. Note how the `null` value was silently converted to a + JSON object. Further note how no value is added if there was already one + value stored with the same key.,emplace} + + @since version 2.0.8 + */ + template + std::pair emplace(Args&& ... args) + { + // emplace only works for null objects or arrays + if (JSON_HEDLEY_UNLIKELY(!(is_null() || is_object()))) + { + JSON_THROW(type_error::create(311, "cannot use emplace() with " + std::string(type_name()), *this)); + } + + // transform null object into an object + if (is_null()) + { + m_type = value_t::object; + m_value = value_t::object; + assert_invariant(); + } + + // add element to array (perfect forwarding) + auto res = m_value.object->emplace(std::forward(args)...); + set_parent(res.first->second); + + // create result iterator and set iterator to the result of emplace + auto it = begin(); + it.m_it.object_iterator = res.first; + + // return pair of iterator and boolean + return {it, res.second}; + } + + /// Helper for insertion of an iterator + /// @note: This uses std::distance to support GCC 4.8, + /// see https://github.com/nlohmann/json/pull/1257 + template + iterator insert_iterator(const_iterator pos, Args&& ... args) + { + iterator result(this); + JSON_ASSERT(m_value.array != nullptr); + + auto insert_pos = std::distance(m_value.array->begin(), pos.m_it.array_iterator); + m_value.array->insert(pos.m_it.array_iterator, std::forward(args)...); + result.m_it.array_iterator = m_value.array->begin() + insert_pos; + + // This could have been written as: + // result.m_it.array_iterator = m_value.array->insert(pos.m_it.array_iterator, cnt, val); + // but the return value of insert is missing in GCC 4.8, so it is written this way instead. + + set_parents(); + return result; + } + + /*! + @brief inserts element + + Inserts element @a val before iterator @a pos. + + @param[in] pos iterator before which the content will be inserted; may be + the end() iterator + @param[in] val element to insert + @return iterator pointing to the inserted @a val. + + @throw type_error.309 if called on JSON values other than arrays; + example: `"cannot use insert() with string"` + @throw invalid_iterator.202 if @a pos is not an iterator of *this; + example: `"iterator does not fit current value"` + + @complexity Constant plus linear in the distance between @a pos and end of + the container. + + @liveexample{The example shows how `insert()` is used.,insert} + + @since version 1.0.0 + */ + iterator insert(const_iterator pos, const basic_json& val) + { + // insert only works for arrays + if (JSON_HEDLEY_LIKELY(is_array())) + { + // check if iterator pos fits to this JSON value + if (JSON_HEDLEY_UNLIKELY(pos.m_object != this)) + { + JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this)); + } + + // insert to array and return iterator + return insert_iterator(pos, val); + } + + JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this)); + } + + /*! + @brief inserts element + @copydoc insert(const_iterator, const basic_json&) + */ + iterator insert(const_iterator pos, basic_json&& val) + { + return insert(pos, val); + } + + /*! + @brief inserts elements + + Inserts @a cnt copies of @a val before iterator @a pos. + + @param[in] pos iterator before which the content will be inserted; may be + the end() iterator + @param[in] cnt number of copies of @a val to insert + @param[in] val element to insert + @return iterator pointing to the first element inserted, or @a pos if + `cnt==0` + + @throw type_error.309 if called on JSON values other than arrays; example: + `"cannot use insert() with string"` + @throw invalid_iterator.202 if @a pos is not an iterator of *this; + example: `"iterator does not fit current value"` + + @complexity Linear in @a cnt plus linear in the distance between @a pos + and end of the container. + + @liveexample{The example shows how `insert()` is used.,insert__count} + + @since version 1.0.0 + */ + iterator insert(const_iterator pos, size_type cnt, const basic_json& val) + { + // insert only works for arrays + if (JSON_HEDLEY_LIKELY(is_array())) + { + // check if iterator pos fits to this JSON value + if (JSON_HEDLEY_UNLIKELY(pos.m_object != this)) + { + JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this)); + } + + // insert to array and return iterator + return insert_iterator(pos, cnt, val); + } + + JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this)); + } + + /*! + @brief inserts elements + + Inserts elements from range `[first, last)` before iterator @a pos. + + @param[in] pos iterator before which the content will be inserted; may be + the end() iterator + @param[in] first begin of the range of elements to insert + @param[in] last end of the range of elements to insert + + @throw type_error.309 if called on JSON values other than arrays; example: + `"cannot use insert() with string"` + @throw invalid_iterator.202 if @a pos is not an iterator of *this; + example: `"iterator does not fit current value"` + @throw invalid_iterator.210 if @a first and @a last do not belong to the + same JSON value; example: `"iterators do not fit"` + @throw invalid_iterator.211 if @a first or @a last are iterators into + container for which insert is called; example: `"passed iterators may not + belong to container"` + + @return iterator pointing to the first element inserted, or @a pos if + `first==last` + + @complexity Linear in `std::distance(first, last)` plus linear in the + distance between @a pos and end of the container. + + @liveexample{The example shows how `insert()` is used.,insert__range} + + @since version 1.0.0 + */ + iterator insert(const_iterator pos, const_iterator first, const_iterator last) + { + // insert only works for arrays + if (JSON_HEDLEY_UNLIKELY(!is_array())) + { + JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this)); + } + + // check if iterator pos fits to this JSON value + if (JSON_HEDLEY_UNLIKELY(pos.m_object != this)) + { + JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this)); + } + + // check if range iterators belong to the same JSON object + if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) + { + JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this)); + } + + if (JSON_HEDLEY_UNLIKELY(first.m_object == this)) + { + JSON_THROW(invalid_iterator::create(211, "passed iterators may not belong to container", *this)); + } + + // insert to array and return iterator + return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator); + } + + /*! + @brief inserts elements + + Inserts elements from initializer list @a ilist before iterator @a pos. + + @param[in] pos iterator before which the content will be inserted; may be + the end() iterator + @param[in] ilist initializer list to insert the values from + + @throw type_error.309 if called on JSON values other than arrays; example: + `"cannot use insert() with string"` + @throw invalid_iterator.202 if @a pos is not an iterator of *this; + example: `"iterator does not fit current value"` + + @return iterator pointing to the first element inserted, or @a pos if + `ilist` is empty + + @complexity Linear in `ilist.size()` plus linear in the distance between + @a pos and end of the container. + + @liveexample{The example shows how `insert()` is used.,insert__ilist} + + @since version 1.0.0 + */ + iterator insert(const_iterator pos, initializer_list_t ilist) + { + // insert only works for arrays + if (JSON_HEDLEY_UNLIKELY(!is_array())) + { + JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this)); + } + + // check if iterator pos fits to this JSON value + if (JSON_HEDLEY_UNLIKELY(pos.m_object != this)) + { + JSON_THROW(invalid_iterator::create(202, "iterator does not fit current value", *this)); + } + + // insert to array and return iterator + return insert_iterator(pos, ilist.begin(), ilist.end()); + } + + /*! + @brief inserts elements + + Inserts elements from range `[first, last)`. + + @param[in] first begin of the range of elements to insert + @param[in] last end of the range of elements to insert + + @throw type_error.309 if called on JSON values other than objects; example: + `"cannot use insert() with string"` + @throw invalid_iterator.202 if iterator @a first or @a last does does not + point to an object; example: `"iterators first and last must point to + objects"` + @throw invalid_iterator.210 if @a first and @a last do not belong to the + same JSON value; example: `"iterators do not fit"` + + @complexity Logarithmic: `O(N*log(size() + N))`, where `N` is the number + of elements to insert. + + @liveexample{The example shows how `insert()` is used.,insert__range_object} + + @since version 3.0.0 + */ + void insert(const_iterator first, const_iterator last) + { + // insert only works for objects + if (JSON_HEDLEY_UNLIKELY(!is_object())) + { + JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this)); + } + + // check if range iterators belong to the same JSON object + if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) + { + JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this)); + } + + // passed iterators must belong to objects + if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object())) + { + JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", *this)); + } + + m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator); + } + + /*! + @brief updates a JSON object from another object, overwriting existing keys + + Inserts all values from JSON object @a j and overwrites existing keys. + + @param[in] j JSON object to read values from + + @throw type_error.312 if called on JSON values other than objects; example: + `"cannot use update() with string"` + + @complexity O(N*log(size() + N)), where N is the number of elements to + insert. + + @liveexample{The example shows how `update()` is used.,update} + + @sa https://docs.python.org/3.6/library/stdtypes.html#dict.update + + @since version 3.0.0 + */ + void update(const_reference j) + { + // implicitly convert null value to an empty object + if (is_null()) + { + m_type = value_t::object; + m_value.object = create(); + assert_invariant(); + } + + if (JSON_HEDLEY_UNLIKELY(!is_object())) + { + JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), *this)); + } + if (JSON_HEDLEY_UNLIKELY(!j.is_object())) + { + JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name()), *this)); + } + + for (auto it = j.cbegin(); it != j.cend(); ++it) + { + m_value.object->operator[](it.key()) = it.value(); +#if JSON_DIAGNOSTICS + m_value.object->operator[](it.key()).m_parent = this; +#endif + } + } + + /*! + @brief updates a JSON object from another object, overwriting existing keys + + Inserts all values from from range `[first, last)` and overwrites existing + keys. + + @param[in] first begin of the range of elements to insert + @param[in] last end of the range of elements to insert + + @throw type_error.312 if called on JSON values other than objects; example: + `"cannot use update() with string"` + @throw invalid_iterator.202 if iterator @a first or @a last does does not + point to an object; example: `"iterators first and last must point to + objects"` + @throw invalid_iterator.210 if @a first and @a last do not belong to the + same JSON value; example: `"iterators do not fit"` + + @complexity O(N*log(size() + N)), where N is the number of elements to + insert. + + @liveexample{The example shows how `update()` is used__range.,update} + + @sa https://docs.python.org/3.6/library/stdtypes.html#dict.update + + @since version 3.0.0 + */ + void update(const_iterator first, const_iterator last) + { + // implicitly convert null value to an empty object + if (is_null()) + { + m_type = value_t::object; + m_value.object = create(); + assert_invariant(); + } + + if (JSON_HEDLEY_UNLIKELY(!is_object())) + { + JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), *this)); + } + + // check if range iterators belong to the same JSON object + if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) + { + JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this)); + } + + // passed iterators must belong to objects + if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object() + || !last.m_object->is_object())) + { + JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", *this)); + } + + for (auto it = first; it != last; ++it) + { + m_value.object->operator[](it.key()) = it.value(); +#if JSON_DIAGNOSTICS + m_value.object->operator[](it.key()).m_parent = this; +#endif + } + } + + /*! + @brief exchanges the values + + Exchanges the contents of the JSON value with those of @a other. Does not + invoke any move, copy, or swap operations on individual elements. All + iterators and references remain valid. The past-the-end iterator is + invalidated. + + @param[in,out] other JSON value to exchange the contents with + + @complexity Constant. + + @liveexample{The example below shows how JSON values can be swapped with + `swap()`.,swap__reference} + + @since version 1.0.0 + */ + void swap(reference other) noexcept ( + std::is_nothrow_move_constructible::value&& + std::is_nothrow_move_assignable::value&& + std::is_nothrow_move_constructible::value&& + std::is_nothrow_move_assignable::value + ) + { + std::swap(m_type, other.m_type); + std::swap(m_value, other.m_value); + + set_parents(); + other.set_parents(); + assert_invariant(); + } + + /*! + @brief exchanges the values + + Exchanges the contents of the JSON value from @a left with those of @a right. Does not + invoke any move, copy, or swap operations on individual elements. All + iterators and references remain valid. The past-the-end iterator is + invalidated. implemented as a friend function callable via ADL. + + @param[in,out] left JSON value to exchange the contents with + @param[in,out] right JSON value to exchange the contents with + + @complexity Constant. + + @liveexample{The example below shows how JSON values can be swapped with + `swap()`.,swap__reference} + + @since version 1.0.0 + */ + friend void swap(reference left, reference right) noexcept ( + std::is_nothrow_move_constructible::value&& + std::is_nothrow_move_assignable::value&& + std::is_nothrow_move_constructible::value&& + std::is_nothrow_move_assignable::value + ) + { + left.swap(right); + } + + /*! + @brief exchanges the values + + Exchanges the contents of a JSON array with those of @a other. Does not + invoke any move, copy, or swap operations on individual elements. All + iterators and references remain valid. The past-the-end iterator is + invalidated. + + @param[in,out] other array to exchange the contents with + + @throw type_error.310 when JSON value is not an array; example: `"cannot + use swap() with string"` + + @complexity Constant. + + @liveexample{The example below shows how arrays can be swapped with + `swap()`.,swap__array_t} + + @since version 1.0.0 + */ + void swap(array_t& other) // NOLINT(bugprone-exception-escape) + { + // swap only works for arrays + if (JSON_HEDLEY_LIKELY(is_array())) + { + std::swap(*(m_value.array), other); + } + else + { + JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this)); + } + } + + /*! + @brief exchanges the values + + Exchanges the contents of a JSON object with those of @a other. Does not + invoke any move, copy, or swap operations on individual elements. All + iterators and references remain valid. The past-the-end iterator is + invalidated. + + @param[in,out] other object to exchange the contents with + + @throw type_error.310 when JSON value is not an object; example: + `"cannot use swap() with string"` + + @complexity Constant. + + @liveexample{The example below shows how objects can be swapped with + `swap()`.,swap__object_t} + + @since version 1.0.0 + */ + void swap(object_t& other) // NOLINT(bugprone-exception-escape) + { + // swap only works for objects + if (JSON_HEDLEY_LIKELY(is_object())) + { + std::swap(*(m_value.object), other); + } + else + { + JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this)); + } + } + + /*! + @brief exchanges the values + + Exchanges the contents of a JSON string with those of @a other. Does not + invoke any move, copy, or swap operations on individual elements. All + iterators and references remain valid. The past-the-end iterator is + invalidated. + + @param[in,out] other string to exchange the contents with + + @throw type_error.310 when JSON value is not a string; example: `"cannot + use swap() with boolean"` + + @complexity Constant. + + @liveexample{The example below shows how strings can be swapped with + `swap()`.,swap__string_t} + + @since version 1.0.0 + */ + void swap(string_t& other) // NOLINT(bugprone-exception-escape) + { + // swap only works for strings + if (JSON_HEDLEY_LIKELY(is_string())) + { + std::swap(*(m_value.string), other); + } + else + { + JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this)); + } + } + + /*! + @brief exchanges the values + + Exchanges the contents of a JSON string with those of @a other. Does not + invoke any move, copy, or swap operations on individual elements. All + iterators and references remain valid. The past-the-end iterator is + invalidated. + + @param[in,out] other binary to exchange the contents with + + @throw type_error.310 when JSON value is not a string; example: `"cannot + use swap() with boolean"` + + @complexity Constant. + + @liveexample{The example below shows how strings can be swapped with + `swap()`.,swap__binary_t} + + @since version 3.8.0 + */ + void swap(binary_t& other) // NOLINT(bugprone-exception-escape) + { + // swap only works for strings + if (JSON_HEDLEY_LIKELY(is_binary())) + { + std::swap(*(m_value.binary), other); + } + else + { + JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this)); + } + } + + /// @copydoc swap(binary_t&) + void swap(typename binary_t::container_type& other) // NOLINT(bugprone-exception-escape) + { + // swap only works for strings + if (JSON_HEDLEY_LIKELY(is_binary())) + { + std::swap(*(m_value.binary), other); + } + else + { + JSON_THROW(type_error::create(310, "cannot use swap() with " + std::string(type_name()), *this)); + } + } + + /// @} + + public: + ////////////////////////////////////////// + // lexicographical comparison operators // + ////////////////////////////////////////// + + /// @name lexicographical comparison operators + /// @{ + + /*! + @brief comparison: equal + + Compares two JSON values for equality according to the following rules: + - Two JSON values are equal if (1) they are from the same type and (2) + their stored values are the same according to their respective + `operator==`. + - Integer and floating-point numbers are automatically converted before + comparison. Note that two NaN values are always treated as unequal. + - Two JSON null values are equal. + + @note Floating-point inside JSON values numbers are compared with + `json::number_float_t::operator==` which is `double::operator==` by + default. To compare floating-point while respecting an epsilon, an alternative + [comparison function](https://github.com/mariokonrad/marnav/blob/master/include/marnav/math/floatingpoint.hpp#L34-#L39) + could be used, for instance + @code {.cpp} + template::value, T>::type> + inline bool is_same(T a, T b, T epsilon = std::numeric_limits::epsilon()) noexcept + { + return std::abs(a - b) <= epsilon; + } + @endcode + Or you can self-defined operator equal function like this: + @code {.cpp} + bool my_equal(const_reference lhs, const_reference rhs) { + const auto lhs_type lhs.type(); + const auto rhs_type rhs.type(); + if (lhs_type == rhs_type) { + switch(lhs_type) + // self_defined case + case value_t::number_float: + return std::abs(lhs - rhs) <= std::numeric_limits::epsilon(); + // other cases remain the same with the original + ... + } + ... + } + @endcode + + @note NaN values never compare equal to themselves or to other NaN values. + + @param[in] lhs first JSON value to consider + @param[in] rhs second JSON value to consider + @return whether the values @a lhs and @a rhs are equal + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + + @complexity Linear. + + @liveexample{The example demonstrates comparing several JSON + types.,operator__equal} + + @since version 1.0.0 + */ + friend bool operator==(const_reference lhs, const_reference rhs) noexcept + { +#ifdef __GNUC__ +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wfloat-equal" +#endif + const auto lhs_type = lhs.type(); + const auto rhs_type = rhs.type(); + + if (lhs_type == rhs_type) + { + switch (lhs_type) + { + case value_t::array: + return *lhs.m_value.array == *rhs.m_value.array; + + case value_t::object: + return *lhs.m_value.object == *rhs.m_value.object; + + case value_t::null: + return true; + + case value_t::string: + return *lhs.m_value.string == *rhs.m_value.string; + + case value_t::boolean: + return lhs.m_value.boolean == rhs.m_value.boolean; + + case value_t::number_integer: + return lhs.m_value.number_integer == rhs.m_value.number_integer; + + case value_t::number_unsigned: + return lhs.m_value.number_unsigned == rhs.m_value.number_unsigned; + + case value_t::number_float: + return lhs.m_value.number_float == rhs.m_value.number_float; + + case value_t::binary: + return *lhs.m_value.binary == *rhs.m_value.binary; + + case value_t::discarded: + default: + return false; + } + } + else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) + { + return static_cast(lhs.m_value.number_integer) == rhs.m_value.number_float; + } + else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) + { + return lhs.m_value.number_float == static_cast(rhs.m_value.number_integer); + } + else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) + { + return static_cast(lhs.m_value.number_unsigned) == rhs.m_value.number_float; + } + else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) + { + return lhs.m_value.number_float == static_cast(rhs.m_value.number_unsigned); + } + else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) + { + return static_cast(lhs.m_value.number_unsigned) == rhs.m_value.number_integer; + } + else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) + { + return lhs.m_value.number_integer == static_cast(rhs.m_value.number_unsigned); + } + + return false; +#ifdef __GNUC__ +#pragma GCC diagnostic pop +#endif + } + + /*! + @brief comparison: equal + @copydoc operator==(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator==(const_reference lhs, ScalarType rhs) noexcept + { + return lhs == basic_json(rhs); + } + + /*! + @brief comparison: equal + @copydoc operator==(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator==(ScalarType lhs, const_reference rhs) noexcept + { + return basic_json(lhs) == rhs; + } + + /*! + @brief comparison: not equal + + Compares two JSON values for inequality by calculating `not (lhs == rhs)`. + + @param[in] lhs first JSON value to consider + @param[in] rhs second JSON value to consider + @return whether the values @a lhs and @a rhs are not equal + + @complexity Linear. + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + + @liveexample{The example demonstrates comparing several JSON + types.,operator__notequal} + + @since version 1.0.0 + */ + friend bool operator!=(const_reference lhs, const_reference rhs) noexcept + { + return !(lhs == rhs); + } + + /*! + @brief comparison: not equal + @copydoc operator!=(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator!=(const_reference lhs, ScalarType rhs) noexcept + { + return lhs != basic_json(rhs); + } + + /*! + @brief comparison: not equal + @copydoc operator!=(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator!=(ScalarType lhs, const_reference rhs) noexcept + { + return basic_json(lhs) != rhs; + } + + /*! + @brief comparison: less than + + Compares whether one JSON value @a lhs is less than another JSON value @a + rhs according to the following rules: + - If @a lhs and @a rhs have the same type, the values are compared using + the default `<` operator. + - Integer and floating-point numbers are automatically converted before + comparison + - In case @a lhs and @a rhs have different types, the values are ignored + and the order of the types is considered, see + @ref operator<(const value_t, const value_t). + + @param[in] lhs first JSON value to consider + @param[in] rhs second JSON value to consider + @return whether @a lhs is less than @a rhs + + @complexity Linear. + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + + @liveexample{The example demonstrates comparing several JSON + types.,operator__less} + + @since version 1.0.0 + */ + friend bool operator<(const_reference lhs, const_reference rhs) noexcept + { + const auto lhs_type = lhs.type(); + const auto rhs_type = rhs.type(); + + if (lhs_type == rhs_type) + { + switch (lhs_type) + { + case value_t::array: + // note parentheses are necessary, see + // https://github.com/nlohmann/json/issues/1530 + return (*lhs.m_value.array) < (*rhs.m_value.array); + + case value_t::object: + return (*lhs.m_value.object) < (*rhs.m_value.object); + + case value_t::null: + return false; + + case value_t::string: + return (*lhs.m_value.string) < (*rhs.m_value.string); + + case value_t::boolean: + return (lhs.m_value.boolean) < (rhs.m_value.boolean); + + case value_t::number_integer: + return (lhs.m_value.number_integer) < (rhs.m_value.number_integer); + + case value_t::number_unsigned: + return (lhs.m_value.number_unsigned) < (rhs.m_value.number_unsigned); + + case value_t::number_float: + return (lhs.m_value.number_float) < (rhs.m_value.number_float); + + case value_t::binary: + return (*lhs.m_value.binary) < (*rhs.m_value.binary); + + case value_t::discarded: + default: + return false; + } + } + else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_float) + { + return static_cast(lhs.m_value.number_integer) < rhs.m_value.number_float; + } + else if (lhs_type == value_t::number_float && rhs_type == value_t::number_integer) + { + return lhs.m_value.number_float < static_cast(rhs.m_value.number_integer); + } + else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_float) + { + return static_cast(lhs.m_value.number_unsigned) < rhs.m_value.number_float; + } + else if (lhs_type == value_t::number_float && rhs_type == value_t::number_unsigned) + { + return lhs.m_value.number_float < static_cast(rhs.m_value.number_unsigned); + } + else if (lhs_type == value_t::number_integer && rhs_type == value_t::number_unsigned) + { + return lhs.m_value.number_integer < static_cast(rhs.m_value.number_unsigned); + } + else if (lhs_type == value_t::number_unsigned && rhs_type == value_t::number_integer) + { + return static_cast(lhs.m_value.number_unsigned) < rhs.m_value.number_integer; + } + + // We only reach this line if we cannot compare values. In that case, + // we compare types. Note we have to call the operator explicitly, + // because MSVC has problems otherwise. + return operator<(lhs_type, rhs_type); + } + + /*! + @brief comparison: less than + @copydoc operator<(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator<(const_reference lhs, ScalarType rhs) noexcept + { + return lhs < basic_json(rhs); + } + + /*! + @brief comparison: less than + @copydoc operator<(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator<(ScalarType lhs, const_reference rhs) noexcept + { + return basic_json(lhs) < rhs; + } + + /*! + @brief comparison: less than or equal + + Compares whether one JSON value @a lhs is less than or equal to another + JSON value by calculating `not (rhs < lhs)`. + + @param[in] lhs first JSON value to consider + @param[in] rhs second JSON value to consider + @return whether @a lhs is less than or equal to @a rhs + + @complexity Linear. + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + + @liveexample{The example demonstrates comparing several JSON + types.,operator__greater} + + @since version 1.0.0 + */ + friend bool operator<=(const_reference lhs, const_reference rhs) noexcept + { + return !(rhs < lhs); + } + + /*! + @brief comparison: less than or equal + @copydoc operator<=(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator<=(const_reference lhs, ScalarType rhs) noexcept + { + return lhs <= basic_json(rhs); + } + + /*! + @brief comparison: less than or equal + @copydoc operator<=(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator<=(ScalarType lhs, const_reference rhs) noexcept + { + return basic_json(lhs) <= rhs; + } + + /*! + @brief comparison: greater than + + Compares whether one JSON value @a lhs is greater than another + JSON value by calculating `not (lhs <= rhs)`. + + @param[in] lhs first JSON value to consider + @param[in] rhs second JSON value to consider + @return whether @a lhs is greater than to @a rhs + + @complexity Linear. + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + + @liveexample{The example demonstrates comparing several JSON + types.,operator__lessequal} + + @since version 1.0.0 + */ + friend bool operator>(const_reference lhs, const_reference rhs) noexcept + { + return !(lhs <= rhs); + } + + /*! + @brief comparison: greater than + @copydoc operator>(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator>(const_reference lhs, ScalarType rhs) noexcept + { + return lhs > basic_json(rhs); + } + + /*! + @brief comparison: greater than + @copydoc operator>(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator>(ScalarType lhs, const_reference rhs) noexcept + { + return basic_json(lhs) > rhs; + } + + /*! + @brief comparison: greater than or equal + + Compares whether one JSON value @a lhs is greater than or equal to another + JSON value by calculating `not (lhs < rhs)`. + + @param[in] lhs first JSON value to consider + @param[in] rhs second JSON value to consider + @return whether @a lhs is greater than or equal to @a rhs + + @complexity Linear. + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + + @liveexample{The example demonstrates comparing several JSON + types.,operator__greaterequal} + + @since version 1.0.0 + */ + friend bool operator>=(const_reference lhs, const_reference rhs) noexcept + { + return !(lhs < rhs); + } + + /*! + @brief comparison: greater than or equal + @copydoc operator>=(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator>=(const_reference lhs, ScalarType rhs) noexcept + { + return lhs >= basic_json(rhs); + } + + /*! + @brief comparison: greater than or equal + @copydoc operator>=(const_reference, const_reference) + */ + template::value, int>::type = 0> + friend bool operator>=(ScalarType lhs, const_reference rhs) noexcept + { + return basic_json(lhs) >= rhs; + } + + /// @} + + /////////////////// + // serialization // + /////////////////// + + /// @name serialization + /// @{ +#ifndef JSON_NO_IO + /*! + @brief serialize to stream + + Serialize the given JSON value @a j to the output stream @a o. The JSON + value will be serialized using the @ref dump member function. + + - The indentation of the output can be controlled with the member variable + `width` of the output stream @a o. For instance, using the manipulator + `std::setw(4)` on @a o sets the indentation level to `4` and the + serialization result is the same as calling `dump(4)`. + + - The indentation character can be controlled with the member variable + `fill` of the output stream @a o. For instance, the manipulator + `std::setfill('\\t')` sets indentation to use a tab character rather than + the default space character. + + @param[in,out] o stream to serialize to + @param[in] j JSON value to serialize + + @return the stream @a o + + @throw type_error.316 if a string stored inside the JSON value is not + UTF-8 encoded + + @complexity Linear. + + @liveexample{The example below shows the serialization with different + parameters to `width` to adjust the indentation level.,operator_serialize} + + @since version 1.0.0; indentation character added in version 3.0.0 + */ + friend std::ostream& operator<<(std::ostream& o, const basic_json& j) + { + // read width member and use it as indentation parameter if nonzero + const bool pretty_print = o.width() > 0; + const auto indentation = pretty_print ? o.width() : 0; + + // reset width to 0 for subsequent calls to this stream + o.width(0); + + // do the actual serialization + serializer s(detail::output_adapter(o), o.fill()); + s.dump(j, pretty_print, false, static_cast(indentation)); + return o; + } + + /*! + @brief serialize to stream + @deprecated This stream operator is deprecated and will be removed in + future 4.0.0 of the library. Please use + @ref operator<<(std::ostream&, const basic_json&) + instead; that is, replace calls like `j >> o;` with `o << j;`. + @since version 1.0.0; deprecated since version 3.0.0 + */ + JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator<<(std::ostream&, const basic_json&)) + friend std::ostream& operator>>(const basic_json& j, std::ostream& o) + { + return o << j; + } +#endif // JSON_NO_IO + /// @} + + + ///////////////////// + // deserialization // + ///////////////////// + + /// @name deserialization + /// @{ + + /*! + @brief deserialize from a compatible input + + @tparam InputType A compatible input, for instance + - an std::istream object + - a FILE pointer + - a C-style array of characters + - a pointer to a null-terminated string of single byte characters + - an object obj for which begin(obj) and end(obj) produces a valid pair of + iterators. + + @param[in] i input to read from + @param[in] cb a parser callback function of type @ref parser_callback_t + which is used to control the deserialization by filtering unwanted values + (optional) + @param[in] allow_exceptions whether to throw exceptions in case of a + parse error (optional, true by default) + @param[in] ignore_comments whether comments should be ignored and treated + like whitespace (true) or yield a parse error (true); (optional, false by + default) + + @return deserialized JSON value; in case of a parse error and + @a allow_exceptions set to `false`, the return value will be + value_t::discarded. + + @throw parse_error.101 if a parse error occurs; example: `""unexpected end + of input; expected string literal""` + @throw parse_error.102 if to_unicode fails or surrogate error + @throw parse_error.103 if to_unicode fails + + @complexity Linear in the length of the input. The parser is a predictive + LL(1) parser. The complexity can be higher if the parser callback function + @a cb or reading from the input @a i has a super-linear complexity. + + @note A UTF-8 byte order mark is silently ignored. + + @liveexample{The example below demonstrates the `parse()` function reading + from an array.,parse__array__parser_callback_t} + + @liveexample{The example below demonstrates the `parse()` function with + and without callback function.,parse__string__parser_callback_t} + + @liveexample{The example below demonstrates the `parse()` function with + and without callback function.,parse__istream__parser_callback_t} + + @liveexample{The example below demonstrates the `parse()` function reading + from a contiguous container.,parse__contiguouscontainer__parser_callback_t} + + @since version 2.0.3 (contiguous containers); version 3.9.0 allowed to + ignore comments. + */ + template + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json parse(InputType&& i, + const parser_callback_t cb = nullptr, + const bool allow_exceptions = true, + const bool ignore_comments = false) + { + basic_json result; + parser(detail::input_adapter(std::forward(i)), cb, allow_exceptions, ignore_comments).parse(true, result); + return result; + } + + /*! + @brief deserialize from a pair of character iterators + + The value_type of the iterator must be a integral type with size of 1, 2 or + 4 bytes, which will be interpreted respectively as UTF-8, UTF-16 and UTF-32. + + @param[in] first iterator to start of character range + @param[in] last iterator to end of character range + @param[in] cb a parser callback function of type @ref parser_callback_t + which is used to control the deserialization by filtering unwanted values + (optional) + @param[in] allow_exceptions whether to throw exceptions in case of a + parse error (optional, true by default) + @param[in] ignore_comments whether comments should be ignored and treated + like whitespace (true) or yield a parse error (true); (optional, false by + default) + + @return deserialized JSON value; in case of a parse error and + @a allow_exceptions set to `false`, the return value will be + value_t::discarded. + + @throw parse_error.101 if a parse error occurs; example: `""unexpected end + of input; expected string literal""` + @throw parse_error.102 if to_unicode fails or surrogate error + @throw parse_error.103 if to_unicode fails + */ + template + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json parse(IteratorType first, + IteratorType last, + const parser_callback_t cb = nullptr, + const bool allow_exceptions = true, + const bool ignore_comments = false) + { + basic_json result; + parser(detail::input_adapter(std::move(first), std::move(last)), cb, allow_exceptions, ignore_comments).parse(true, result); + return result; + } + + JSON_HEDLEY_WARN_UNUSED_RESULT + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, parse(ptr, ptr + len)) + static basic_json parse(detail::span_input_adapter&& i, + const parser_callback_t cb = nullptr, + const bool allow_exceptions = true, + const bool ignore_comments = false) + { + basic_json result; + parser(i.get(), cb, allow_exceptions, ignore_comments).parse(true, result); + return result; + } + + /*! + @brief check if the input is valid JSON + + Unlike the @ref parse(InputType&&, const parser_callback_t,const bool) + function, this function neither throws an exception in case of invalid JSON + input (i.e., a parse error) nor creates diagnostic information. + + @tparam InputType A compatible input, for instance + - an std::istream object + - a FILE pointer + - a C-style array of characters + - a pointer to a null-terminated string of single byte characters + - an object obj for which begin(obj) and end(obj) produces a valid pair of + iterators. + + @param[in] i input to read from + @param[in] ignore_comments whether comments should be ignored and treated + like whitespace (true) or yield a parse error (true); (optional, false by + default) + + @return Whether the input read from @a i is valid JSON. + + @complexity Linear in the length of the input. The parser is a predictive + LL(1) parser. + + @note A UTF-8 byte order mark is silently ignored. + + @liveexample{The example below demonstrates the `accept()` function reading + from a string.,accept__string} + */ + template + static bool accept(InputType&& i, + const bool ignore_comments = false) + { + return parser(detail::input_adapter(std::forward(i)), nullptr, false, ignore_comments).accept(true); + } + + template + static bool accept(IteratorType first, IteratorType last, + const bool ignore_comments = false) + { + return parser(detail::input_adapter(std::move(first), std::move(last)), nullptr, false, ignore_comments).accept(true); + } + + JSON_HEDLEY_WARN_UNUSED_RESULT + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, accept(ptr, ptr + len)) + static bool accept(detail::span_input_adapter&& i, + const bool ignore_comments = false) + { + return parser(i.get(), nullptr, false, ignore_comments).accept(true); + } + + /*! + @brief generate SAX events + + The SAX event lister must follow the interface of @ref json_sax. + + This function reads from a compatible input. Examples are: + - an std::istream object + - a FILE pointer + - a C-style array of characters + - a pointer to a null-terminated string of single byte characters + - an object obj for which begin(obj) and end(obj) produces a valid pair of + iterators. + + @param[in] i input to read from + @param[in,out] sax SAX event listener + @param[in] format the format to parse (JSON, CBOR, MessagePack, or UBJSON) + @param[in] strict whether the input has to be consumed completely + @param[in] ignore_comments whether comments should be ignored and treated + like whitespace (true) or yield a parse error (true); (optional, false by + default); only applies to the JSON file format. + + @return return value of the last processed SAX event + + @throw parse_error.101 if a parse error occurs; example: `""unexpected end + of input; expected string literal""` + @throw parse_error.102 if to_unicode fails or surrogate error + @throw parse_error.103 if to_unicode fails + + @complexity Linear in the length of the input. The parser is a predictive + LL(1) parser. The complexity can be higher if the SAX consumer @a sax has + a super-linear complexity. + + @note A UTF-8 byte order mark is silently ignored. + + @liveexample{The example below demonstrates the `sax_parse()` function + reading from string and processing the events with a user-defined SAX + event consumer.,sax_parse} + + @since version 3.2.0 + */ + template + JSON_HEDLEY_NON_NULL(2) + static bool sax_parse(InputType&& i, SAX* sax, + input_format_t format = input_format_t::json, + const bool strict = true, + const bool ignore_comments = false) + { + auto ia = detail::input_adapter(std::forward(i)); + return format == input_format_t::json + ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) + : detail::binary_reader(std::move(ia)).sax_parse(format, sax, strict); + } + + template + JSON_HEDLEY_NON_NULL(3) + static bool sax_parse(IteratorType first, IteratorType last, SAX* sax, + input_format_t format = input_format_t::json, + const bool strict = true, + const bool ignore_comments = false) + { + auto ia = detail::input_adapter(std::move(first), std::move(last)); + return format == input_format_t::json + ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) + : detail::binary_reader(std::move(ia)).sax_parse(format, sax, strict); + } + + template + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, sax_parse(ptr, ptr + len, ...)) + JSON_HEDLEY_NON_NULL(2) + static bool sax_parse(detail::span_input_adapter&& i, SAX* sax, + input_format_t format = input_format_t::json, + const bool strict = true, + const bool ignore_comments = false) + { + auto ia = i.get(); + return format == input_format_t::json + // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) + ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) + // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) + : detail::binary_reader(std::move(ia)).sax_parse(format, sax, strict); + } +#ifndef JSON_NO_IO + /*! + @brief deserialize from stream + @deprecated This stream operator is deprecated and will be removed in + version 4.0.0 of the library. Please use + @ref operator>>(std::istream&, basic_json&) + instead; that is, replace calls like `j << i;` with `i >> j;`. + @since version 1.0.0; deprecated since version 3.0.0 + */ + JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator>>(std::istream&, basic_json&)) + friend std::istream& operator<<(basic_json& j, std::istream& i) + { + return operator>>(i, j); + } + + /*! + @brief deserialize from stream + + Deserializes an input stream to a JSON value. + + @param[in,out] i input stream to read a serialized JSON value from + @param[in,out] j JSON value to write the deserialized input to + + @throw parse_error.101 in case of an unexpected token + @throw parse_error.102 if to_unicode fails or surrogate error + @throw parse_error.103 if to_unicode fails + + @complexity Linear in the length of the input. The parser is a predictive + LL(1) parser. + + @note A UTF-8 byte order mark is silently ignored. + + @liveexample{The example below shows how a JSON value is constructed by + reading a serialization from a stream.,operator_deserialize} + + @sa parse(std::istream&, const parser_callback_t) for a variant with a + parser callback function to filter values while parsing + + @since version 1.0.0 + */ + friend std::istream& operator>>(std::istream& i, basic_json& j) + { + parser(detail::input_adapter(i)).parse(false, j); + return i; + } +#endif // JSON_NO_IO + /// @} + + /////////////////////////// + // convenience functions // + /////////////////////////// + + /*! + @brief return the type as string + + Returns the type name as string to be used in error messages - usually to + indicate that a function was called on a wrong JSON type. + + @return a string representation of a the @a m_type member: + Value type | return value + ----------- | ------------- + null | `"null"` + boolean | `"boolean"` + string | `"string"` + number | `"number"` (for all number types) + object | `"object"` + array | `"array"` + binary | `"binary"` + discarded | `"discarded"` + + @exceptionsafety No-throw guarantee: this function never throws exceptions. + + @complexity Constant. + + @liveexample{The following code exemplifies `type_name()` for all JSON + types.,type_name} + + @sa see @ref type() -- return the type of the JSON value + @sa see @ref operator value_t() -- return the type of the JSON value (implicit) + + @since version 1.0.0, public since 2.1.0, `const char*` and `noexcept` + since 3.0.0 + */ + JSON_HEDLEY_RETURNS_NON_NULL + const char* type_name() const noexcept + { + { + switch (m_type) + { + case value_t::null: + return "null"; + case value_t::object: + return "object"; + case value_t::array: + return "array"; + case value_t::string: + return "string"; + case value_t::boolean: + return "boolean"; + case value_t::binary: + return "binary"; + case value_t::discarded: + return "discarded"; + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + default: + return "number"; + } + } + } + + + JSON_PRIVATE_UNLESS_TESTED: + ////////////////////// + // member variables // + ////////////////////// + + /// the type of the current element + value_t m_type = value_t::null; + + /// the value of the current element + json_value m_value = {}; + +#if JSON_DIAGNOSTICS + /// a pointer to a parent value (for debugging purposes) + basic_json* m_parent = nullptr; +#endif + + ////////////////////////////////////////// + // binary serialization/deserialization // + ////////////////////////////////////////// + + /// @name binary serialization/deserialization support + /// @{ + + public: + /*! + @brief create a CBOR serialization of a given JSON value + + Serializes a given JSON value @a j to a byte vector using the CBOR (Concise + Binary Object Representation) serialization format. CBOR is a binary + serialization format which aims to be more compact than JSON itself, yet + more efficient to parse. + + The library uses the following mapping from JSON values types to + CBOR types according to the CBOR specification (RFC 7049): + + JSON value type | value/range | CBOR type | first byte + --------------- | ------------------------------------------ | ---------------------------------- | --------------- + null | `null` | Null | 0xF6 + boolean | `true` | True | 0xF5 + boolean | `false` | False | 0xF4 + number_integer | -9223372036854775808..-2147483649 | Negative integer (8 bytes follow) | 0x3B + number_integer | -2147483648..-32769 | Negative integer (4 bytes follow) | 0x3A + number_integer | -32768..-129 | Negative integer (2 bytes follow) | 0x39 + number_integer | -128..-25 | Negative integer (1 byte follow) | 0x38 + number_integer | -24..-1 | Negative integer | 0x20..0x37 + number_integer | 0..23 | Integer | 0x00..0x17 + number_integer | 24..255 | Unsigned integer (1 byte follow) | 0x18 + number_integer | 256..65535 | Unsigned integer (2 bytes follow) | 0x19 + number_integer | 65536..4294967295 | Unsigned integer (4 bytes follow) | 0x1A + number_integer | 4294967296..18446744073709551615 | Unsigned integer (8 bytes follow) | 0x1B + number_unsigned | 0..23 | Integer | 0x00..0x17 + number_unsigned | 24..255 | Unsigned integer (1 byte follow) | 0x18 + number_unsigned | 256..65535 | Unsigned integer (2 bytes follow) | 0x19 + number_unsigned | 65536..4294967295 | Unsigned integer (4 bytes follow) | 0x1A + number_unsigned | 4294967296..18446744073709551615 | Unsigned integer (8 bytes follow) | 0x1B + number_float | *any value representable by a float* | Single-Precision Float | 0xFA + number_float | *any value NOT representable by a float* | Double-Precision Float | 0xFB + string | *length*: 0..23 | UTF-8 string | 0x60..0x77 + string | *length*: 23..255 | UTF-8 string (1 byte follow) | 0x78 + string | *length*: 256..65535 | UTF-8 string (2 bytes follow) | 0x79 + string | *length*: 65536..4294967295 | UTF-8 string (4 bytes follow) | 0x7A + string | *length*: 4294967296..18446744073709551615 | UTF-8 string (8 bytes follow) | 0x7B + array | *size*: 0..23 | array | 0x80..0x97 + array | *size*: 23..255 | array (1 byte follow) | 0x98 + array | *size*: 256..65535 | array (2 bytes follow) | 0x99 + array | *size*: 65536..4294967295 | array (4 bytes follow) | 0x9A + array | *size*: 4294967296..18446744073709551615 | array (8 bytes follow) | 0x9B + object | *size*: 0..23 | map | 0xA0..0xB7 + object | *size*: 23..255 | map (1 byte follow) | 0xB8 + object | *size*: 256..65535 | map (2 bytes follow) | 0xB9 + object | *size*: 65536..4294967295 | map (4 bytes follow) | 0xBA + object | *size*: 4294967296..18446744073709551615 | map (8 bytes follow) | 0xBB + binary | *size*: 0..23 | byte string | 0x40..0x57 + binary | *size*: 23..255 | byte string (1 byte follow) | 0x58 + binary | *size*: 256..65535 | byte string (2 bytes follow) | 0x59 + binary | *size*: 65536..4294967295 | byte string (4 bytes follow) | 0x5A + binary | *size*: 4294967296..18446744073709551615 | byte string (8 bytes follow) | 0x5B + + Binary values with subtype are mapped to tagged values (0xD8..0xDB) + depending on the subtype, followed by a byte string, see "binary" cells + in the table above. + + @note The mapping is **complete** in the sense that any JSON value type + can be converted to a CBOR value. + + @note If NaN or Infinity are stored inside a JSON number, they are + serialized properly. This behavior differs from the @ref dump() + function which serializes NaN or Infinity to `null`. + + @note The following CBOR types are not used in the conversion: + - UTF-8 strings terminated by "break" (0x7F) + - arrays terminated by "break" (0x9F) + - maps terminated by "break" (0xBF) + - byte strings terminated by "break" (0x5F) + - date/time (0xC0..0xC1) + - bignum (0xC2..0xC3) + - decimal fraction (0xC4) + - bigfloat (0xC5) + - expected conversions (0xD5..0xD7) + - simple values (0xE0..0xF3, 0xF8) + - undefined (0xF7) + - half-precision floats (0xF9) + - break (0xFF) + + @param[in] j JSON value to serialize + @return CBOR serialization as byte vector + + @complexity Linear in the size of the JSON value @a j. + + @liveexample{The example shows the serialization of a JSON value to a byte + vector in CBOR format.,to_cbor} + + @sa http://cbor.io + @sa see @ref from_cbor(InputType&&, const bool, const bool, const cbor_tag_handler_t) for the + analogous deserialization + @sa see @ref to_msgpack(const basic_json&) for the related MessagePack format + @sa see @ref to_ubjson(const basic_json&, const bool, const bool) for the + related UBJSON format + + @since version 2.0.9; compact representation of floating-point numbers + since version 3.8.0 + */ + static std::vector to_cbor(const basic_json& j) + { + std::vector result; + to_cbor(j, result); + return result; + } + + static void to_cbor(const basic_json& j, detail::output_adapter o) + { + binary_writer(o).write_cbor(j); + } + + static void to_cbor(const basic_json& j, detail::output_adapter o) + { + binary_writer(o).write_cbor(j); + } + + /*! + @brief create a MessagePack serialization of a given JSON value + + Serializes a given JSON value @a j to a byte vector using the MessagePack + serialization format. MessagePack is a binary serialization format which + aims to be more compact than JSON itself, yet more efficient to parse. + + The library uses the following mapping from JSON values types to + MessagePack types according to the MessagePack specification: + + JSON value type | value/range | MessagePack type | first byte + --------------- | --------------------------------- | ---------------- | ---------- + null | `null` | nil | 0xC0 + boolean | `true` | true | 0xC3 + boolean | `false` | false | 0xC2 + number_integer | -9223372036854775808..-2147483649 | int64 | 0xD3 + number_integer | -2147483648..-32769 | int32 | 0xD2 + number_integer | -32768..-129 | int16 | 0xD1 + number_integer | -128..-33 | int8 | 0xD0 + number_integer | -32..-1 | negative fixint | 0xE0..0xFF + number_integer | 0..127 | positive fixint | 0x00..0x7F + number_integer | 128..255 | uint 8 | 0xCC + number_integer | 256..65535 | uint 16 | 0xCD + number_integer | 65536..4294967295 | uint 32 | 0xCE + number_integer | 4294967296..18446744073709551615 | uint 64 | 0xCF + number_unsigned | 0..127 | positive fixint | 0x00..0x7F + number_unsigned | 128..255 | uint 8 | 0xCC + number_unsigned | 256..65535 | uint 16 | 0xCD + number_unsigned | 65536..4294967295 | uint 32 | 0xCE + number_unsigned | 4294967296..18446744073709551615 | uint 64 | 0xCF + number_float | *any value representable by a float* | float 32 | 0xCA + number_float | *any value NOT representable by a float* | float 64 | 0xCB + string | *length*: 0..31 | fixstr | 0xA0..0xBF + string | *length*: 32..255 | str 8 | 0xD9 + string | *length*: 256..65535 | str 16 | 0xDA + string | *length*: 65536..4294967295 | str 32 | 0xDB + array | *size*: 0..15 | fixarray | 0x90..0x9F + array | *size*: 16..65535 | array 16 | 0xDC + array | *size*: 65536..4294967295 | array 32 | 0xDD + object | *size*: 0..15 | fix map | 0x80..0x8F + object | *size*: 16..65535 | map 16 | 0xDE + object | *size*: 65536..4294967295 | map 32 | 0xDF + binary | *size*: 0..255 | bin 8 | 0xC4 + binary | *size*: 256..65535 | bin 16 | 0xC5 + binary | *size*: 65536..4294967295 | bin 32 | 0xC6 + + @note The mapping is **complete** in the sense that any JSON value type + can be converted to a MessagePack value. + + @note The following values can **not** be converted to a MessagePack value: + - strings with more than 4294967295 bytes + - byte strings with more than 4294967295 bytes + - arrays with more than 4294967295 elements + - objects with more than 4294967295 elements + + @note Any MessagePack output created @ref to_msgpack can be successfully + parsed by @ref from_msgpack. + + @note If NaN or Infinity are stored inside a JSON number, they are + serialized properly. This behavior differs from the @ref dump() + function which serializes NaN or Infinity to `null`. + + @param[in] j JSON value to serialize + @return MessagePack serialization as byte vector + + @complexity Linear in the size of the JSON value @a j. + + @liveexample{The example shows the serialization of a JSON value to a byte + vector in MessagePack format.,to_msgpack} + + @sa http://msgpack.org + @sa see @ref from_msgpack for the analogous deserialization + @sa see @ref to_cbor(const basic_json& for the related CBOR format + @sa see @ref to_ubjson(const basic_json&, const bool, const bool) for the + related UBJSON format + + @since version 2.0.9 + */ + static std::vector to_msgpack(const basic_json& j) + { + std::vector result; + to_msgpack(j, result); + return result; + } + + static void to_msgpack(const basic_json& j, detail::output_adapter o) + { + binary_writer(o).write_msgpack(j); + } + + static void to_msgpack(const basic_json& j, detail::output_adapter o) + { + binary_writer(o).write_msgpack(j); + } + + /*! + @brief create a UBJSON serialization of a given JSON value + + Serializes a given JSON value @a j to a byte vector using the UBJSON + (Universal Binary JSON) serialization format. UBJSON aims to be more compact + than JSON itself, yet more efficient to parse. + + The library uses the following mapping from JSON values types to + UBJSON types according to the UBJSON specification: + + JSON value type | value/range | UBJSON type | marker + --------------- | --------------------------------- | ----------- | ------ + null | `null` | null | `Z` + boolean | `true` | true | `T` + boolean | `false` | false | `F` + number_integer | -9223372036854775808..-2147483649 | int64 | `L` + number_integer | -2147483648..-32769 | int32 | `l` + number_integer | -32768..-129 | int16 | `I` + number_integer | -128..127 | int8 | `i` + number_integer | 128..255 | uint8 | `U` + number_integer | 256..32767 | int16 | `I` + number_integer | 32768..2147483647 | int32 | `l` + number_integer | 2147483648..9223372036854775807 | int64 | `L` + number_unsigned | 0..127 | int8 | `i` + number_unsigned | 128..255 | uint8 | `U` + number_unsigned | 256..32767 | int16 | `I` + number_unsigned | 32768..2147483647 | int32 | `l` + number_unsigned | 2147483648..9223372036854775807 | int64 | `L` + number_unsigned | 2147483649..18446744073709551615 | high-precision | `H` + number_float | *any value* | float64 | `D` + string | *with shortest length indicator* | string | `S` + array | *see notes on optimized format* | array | `[` + object | *see notes on optimized format* | map | `{` + + @note The mapping is **complete** in the sense that any JSON value type + can be converted to a UBJSON value. + + @note The following values can **not** be converted to a UBJSON value: + - strings with more than 9223372036854775807 bytes (theoretical) + + @note The following markers are not used in the conversion: + - `Z`: no-op values are not created. + - `C`: single-byte strings are serialized with `S` markers. + + @note Any UBJSON output created @ref to_ubjson can be successfully parsed + by @ref from_ubjson. + + @note If NaN or Infinity are stored inside a JSON number, they are + serialized properly. This behavior differs from the @ref dump() + function which serializes NaN or Infinity to `null`. + + @note The optimized formats for containers are supported: Parameter + @a use_size adds size information to the beginning of a container and + removes the closing marker. Parameter @a use_type further checks + whether all elements of a container have the same type and adds the + type marker to the beginning of the container. The @a use_type + parameter must only be used together with @a use_size = true. Note + that @a use_size = true alone may result in larger representations - + the benefit of this parameter is that the receiving side is + immediately informed on the number of elements of the container. + + @note If the JSON data contains the binary type, the value stored is a list + of integers, as suggested by the UBJSON documentation. In particular, + this means that serialization and the deserialization of a JSON + containing binary values into UBJSON and back will result in a + different JSON object. + + @param[in] j JSON value to serialize + @param[in] use_size whether to add size annotations to container types + @param[in] use_type whether to add type annotations to container types + (must be combined with @a use_size = true) + @return UBJSON serialization as byte vector + + @complexity Linear in the size of the JSON value @a j. + + @liveexample{The example shows the serialization of a JSON value to a byte + vector in UBJSON format.,to_ubjson} + + @sa http://ubjson.org + @sa see @ref from_ubjson(InputType&&, const bool, const bool) for the + analogous deserialization + @sa see @ref to_cbor(const basic_json& for the related CBOR format + @sa see @ref to_msgpack(const basic_json&) for the related MessagePack format + + @since version 3.1.0 + */ + static std::vector to_ubjson(const basic_json& j, + const bool use_size = false, + const bool use_type = false) + { + std::vector result; + to_ubjson(j, result, use_size, use_type); + return result; + } + + static void to_ubjson(const basic_json& j, detail::output_adapter o, + const bool use_size = false, const bool use_type = false) + { + binary_writer(o).write_ubjson(j, use_size, use_type); + } + + static void to_ubjson(const basic_json& j, detail::output_adapter o, + const bool use_size = false, const bool use_type = false) + { + binary_writer(o).write_ubjson(j, use_size, use_type); + } + + + /*! + @brief Serializes the given JSON object `j` to BSON and returns a vector + containing the corresponding BSON-representation. + + BSON (Binary JSON) is a binary format in which zero or more ordered key/value pairs are + stored as a single entity (a so-called document). + + The library uses the following mapping from JSON values types to BSON types: + + JSON value type | value/range | BSON type | marker + --------------- | --------------------------------- | ----------- | ------ + null | `null` | null | 0x0A + boolean | `true`, `false` | boolean | 0x08 + number_integer | -9223372036854775808..-2147483649 | int64 | 0x12 + number_integer | -2147483648..2147483647 | int32 | 0x10 + number_integer | 2147483648..9223372036854775807 | int64 | 0x12 + number_unsigned | 0..2147483647 | int32 | 0x10 + number_unsigned | 2147483648..9223372036854775807 | int64 | 0x12 + number_unsigned | 9223372036854775808..18446744073709551615| -- | -- + number_float | *any value* | double | 0x01 + string | *any value* | string | 0x02 + array | *any value* | document | 0x04 + object | *any value* | document | 0x03 + binary | *any value* | binary | 0x05 + + @warning The mapping is **incomplete**, since only JSON-objects (and things + contained therein) can be serialized to BSON. + Also, integers larger than 9223372036854775807 cannot be serialized to BSON, + and the keys may not contain U+0000, since they are serialized a + zero-terminated c-strings. + + @throw out_of_range.407 if `j.is_number_unsigned() && j.get() > 9223372036854775807` + @throw out_of_range.409 if a key in `j` contains a NULL (U+0000) + @throw type_error.317 if `!j.is_object()` + + @pre The input `j` is required to be an object: `j.is_object() == true`. + + @note Any BSON output created via @ref to_bson can be successfully parsed + by @ref from_bson. + + @param[in] j JSON value to serialize + @return BSON serialization as byte vector + + @complexity Linear in the size of the JSON value @a j. + + @liveexample{The example shows the serialization of a JSON value to a byte + vector in BSON format.,to_bson} + + @sa http://bsonspec.org/spec.html + @sa see @ref from_bson(detail::input_adapter&&, const bool strict) for the + analogous deserialization + @sa see @ref to_ubjson(const basic_json&, const bool, const bool) for the + related UBJSON format + @sa see @ref to_cbor(const basic_json&) for the related CBOR format + @sa see @ref to_msgpack(const basic_json&) for the related MessagePack format + */ + static std::vector to_bson(const basic_json& j) + { + std::vector result; + to_bson(j, result); + return result; + } + + /*! + @brief Serializes the given JSON object `j` to BSON and forwards the + corresponding BSON-representation to the given output_adapter `o`. + @param j The JSON object to convert to BSON. + @param o The output adapter that receives the binary BSON representation. + @pre The input `j` shall be an object: `j.is_object() == true` + @sa see @ref to_bson(const basic_json&) + */ + static void to_bson(const basic_json& j, detail::output_adapter o) + { + binary_writer(o).write_bson(j); + } + + /*! + @copydoc to_bson(const basic_json&, detail::output_adapter) + */ + static void to_bson(const basic_json& j, detail::output_adapter o) + { + binary_writer(o).write_bson(j); + } + + + /*! + @brief create a JSON value from an input in CBOR format + + Deserializes a given input @a i to a JSON value using the CBOR (Concise + Binary Object Representation) serialization format. + + The library maps CBOR types to JSON value types as follows: + + CBOR type | JSON value type | first byte + ---------------------- | --------------- | ---------- + Integer | number_unsigned | 0x00..0x17 + Unsigned integer | number_unsigned | 0x18 + Unsigned integer | number_unsigned | 0x19 + Unsigned integer | number_unsigned | 0x1A + Unsigned integer | number_unsigned | 0x1B + Negative integer | number_integer | 0x20..0x37 + Negative integer | number_integer | 0x38 + Negative integer | number_integer | 0x39 + Negative integer | number_integer | 0x3A + Negative integer | number_integer | 0x3B + Byte string | binary | 0x40..0x57 + Byte string | binary | 0x58 + Byte string | binary | 0x59 + Byte string | binary | 0x5A + Byte string | binary | 0x5B + UTF-8 string | string | 0x60..0x77 + UTF-8 string | string | 0x78 + UTF-8 string | string | 0x79 + UTF-8 string | string | 0x7A + UTF-8 string | string | 0x7B + UTF-8 string | string | 0x7F + array | array | 0x80..0x97 + array | array | 0x98 + array | array | 0x99 + array | array | 0x9A + array | array | 0x9B + array | array | 0x9F + map | object | 0xA0..0xB7 + map | object | 0xB8 + map | object | 0xB9 + map | object | 0xBA + map | object | 0xBB + map | object | 0xBF + False | `false` | 0xF4 + True | `true` | 0xF5 + Null | `null` | 0xF6 + Half-Precision Float | number_float | 0xF9 + Single-Precision Float | number_float | 0xFA + Double-Precision Float | number_float | 0xFB + + @warning The mapping is **incomplete** in the sense that not all CBOR + types can be converted to a JSON value. The following CBOR types + are not supported and will yield parse errors (parse_error.112): + - date/time (0xC0..0xC1) + - bignum (0xC2..0xC3) + - decimal fraction (0xC4) + - bigfloat (0xC5) + - expected conversions (0xD5..0xD7) + - simple values (0xE0..0xF3, 0xF8) + - undefined (0xF7) + + @warning CBOR allows map keys of any type, whereas JSON only allows + strings as keys in object values. Therefore, CBOR maps with keys + other than UTF-8 strings are rejected (parse_error.113). + + @note Any CBOR output created @ref to_cbor can be successfully parsed by + @ref from_cbor. + + @param[in] i an input in CBOR format convertible to an input adapter + @param[in] strict whether to expect the input to be consumed until EOF + (true by default) + @param[in] allow_exceptions whether to throw exceptions in case of a + parse error (optional, true by default) + @param[in] tag_handler how to treat CBOR tags (optional, error by default) + + @return deserialized JSON value; in case of a parse error and + @a allow_exceptions set to `false`, the return value will be + value_t::discarded. + + @throw parse_error.110 if the given input ends prematurely or the end of + file was not reached when @a strict was set to true + @throw parse_error.112 if unsupported features from CBOR were + used in the given input @a v or if the input is not valid CBOR + @throw parse_error.113 if a string was expected as map key, but not found + + @complexity Linear in the size of the input @a i. + + @liveexample{The example shows the deserialization of a byte vector in CBOR + format to a JSON value.,from_cbor} + + @sa http://cbor.io + @sa see @ref to_cbor(const basic_json&) for the analogous serialization + @sa see @ref from_msgpack(InputType&&, const bool, const bool) for the + related MessagePack format + @sa see @ref from_ubjson(InputType&&, const bool, const bool) for the + related UBJSON format + + @since version 2.0.9; parameter @a start_index since 2.1.1; changed to + consume input adapters, removed start_index parameter, and added + @a strict parameter since 3.0.0; added @a allow_exceptions parameter + since 3.2.0; added @a tag_handler parameter since 3.9.0. + */ + template + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json from_cbor(InputType&& i, + const bool strict = true, + const bool allow_exceptions = true, + const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) + { + basic_json result; + detail::json_sax_dom_parser sdp(result, allow_exceptions); + auto ia = detail::input_adapter(std::forward(i)); + const bool res = binary_reader(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); + return res ? result : basic_json(value_t::discarded); + } + + /*! + @copydoc from_cbor(InputType&&, const bool, const bool, const cbor_tag_handler_t) + */ + template + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json from_cbor(IteratorType first, IteratorType last, + const bool strict = true, + const bool allow_exceptions = true, + const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) + { + basic_json result; + detail::json_sax_dom_parser sdp(result, allow_exceptions); + auto ia = detail::input_adapter(std::move(first), std::move(last)); + const bool res = binary_reader(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); + return res ? result : basic_json(value_t::discarded); + } + + template + JSON_HEDLEY_WARN_UNUSED_RESULT + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len)) + static basic_json from_cbor(const T* ptr, std::size_t len, + const bool strict = true, + const bool allow_exceptions = true, + const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) + { + return from_cbor(ptr, ptr + len, strict, allow_exceptions, tag_handler); + } + + + JSON_HEDLEY_WARN_UNUSED_RESULT + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_cbor(ptr, ptr + len)) + static basic_json from_cbor(detail::span_input_adapter&& i, + const bool strict = true, + const bool allow_exceptions = true, + const cbor_tag_handler_t tag_handler = cbor_tag_handler_t::error) + { + basic_json result; + detail::json_sax_dom_parser sdp(result, allow_exceptions); + auto ia = i.get(); + // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) + const bool res = binary_reader(std::move(ia)).sax_parse(input_format_t::cbor, &sdp, strict, tag_handler); + return res ? result : basic_json(value_t::discarded); + } + + /*! + @brief create a JSON value from an input in MessagePack format + + Deserializes a given input @a i to a JSON value using the MessagePack + serialization format. + + The library maps MessagePack types to JSON value types as follows: + + MessagePack type | JSON value type | first byte + ---------------- | --------------- | ---------- + positive fixint | number_unsigned | 0x00..0x7F + fixmap | object | 0x80..0x8F + fixarray | array | 0x90..0x9F + fixstr | string | 0xA0..0xBF + nil | `null` | 0xC0 + false | `false` | 0xC2 + true | `true` | 0xC3 + float 32 | number_float | 0xCA + float 64 | number_float | 0xCB + uint 8 | number_unsigned | 0xCC + uint 16 | number_unsigned | 0xCD + uint 32 | number_unsigned | 0xCE + uint 64 | number_unsigned | 0xCF + int 8 | number_integer | 0xD0 + int 16 | number_integer | 0xD1 + int 32 | number_integer | 0xD2 + int 64 | number_integer | 0xD3 + str 8 | string | 0xD9 + str 16 | string | 0xDA + str 32 | string | 0xDB + array 16 | array | 0xDC + array 32 | array | 0xDD + map 16 | object | 0xDE + map 32 | object | 0xDF + bin 8 | binary | 0xC4 + bin 16 | binary | 0xC5 + bin 32 | binary | 0xC6 + ext 8 | binary | 0xC7 + ext 16 | binary | 0xC8 + ext 32 | binary | 0xC9 + fixext 1 | binary | 0xD4 + fixext 2 | binary | 0xD5 + fixext 4 | binary | 0xD6 + fixext 8 | binary | 0xD7 + fixext 16 | binary | 0xD8 + negative fixint | number_integer | 0xE0-0xFF + + @note Any MessagePack output created @ref to_msgpack can be successfully + parsed by @ref from_msgpack. + + @param[in] i an input in MessagePack format convertible to an input + adapter + @param[in] strict whether to expect the input to be consumed until EOF + (true by default) + @param[in] allow_exceptions whether to throw exceptions in case of a + parse error (optional, true by default) + + @return deserialized JSON value; in case of a parse error and + @a allow_exceptions set to `false`, the return value will be + value_t::discarded. + + @throw parse_error.110 if the given input ends prematurely or the end of + file was not reached when @a strict was set to true + @throw parse_error.112 if unsupported features from MessagePack were + used in the given input @a i or if the input is not valid MessagePack + @throw parse_error.113 if a string was expected as map key, but not found + + @complexity Linear in the size of the input @a i. + + @liveexample{The example shows the deserialization of a byte vector in + MessagePack format to a JSON value.,from_msgpack} + + @sa http://msgpack.org + @sa see @ref to_msgpack(const basic_json&) for the analogous serialization + @sa see @ref from_cbor(InputType&&, const bool, const bool, const cbor_tag_handler_t) for the + related CBOR format + @sa see @ref from_ubjson(InputType&&, const bool, const bool) for + the related UBJSON format + @sa see @ref from_bson(InputType&&, const bool, const bool) for + the related BSON format + + @since version 2.0.9; parameter @a start_index since 2.1.1; changed to + consume input adapters, removed start_index parameter, and added + @a strict parameter since 3.0.0; added @a allow_exceptions parameter + since 3.2.0 + */ + template + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json from_msgpack(InputType&& i, + const bool strict = true, + const bool allow_exceptions = true) + { + basic_json result; + detail::json_sax_dom_parser sdp(result, allow_exceptions); + auto ia = detail::input_adapter(std::forward(i)); + const bool res = binary_reader(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict); + return res ? result : basic_json(value_t::discarded); + } + + /*! + @copydoc from_msgpack(InputType&&, const bool, const bool) + */ + template + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json from_msgpack(IteratorType first, IteratorType last, + const bool strict = true, + const bool allow_exceptions = true) + { + basic_json result; + detail::json_sax_dom_parser sdp(result, allow_exceptions); + auto ia = detail::input_adapter(std::move(first), std::move(last)); + const bool res = binary_reader(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict); + return res ? result : basic_json(value_t::discarded); + } + + + template + JSON_HEDLEY_WARN_UNUSED_RESULT + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len)) + static basic_json from_msgpack(const T* ptr, std::size_t len, + const bool strict = true, + const bool allow_exceptions = true) + { + return from_msgpack(ptr, ptr + len, strict, allow_exceptions); + } + + JSON_HEDLEY_WARN_UNUSED_RESULT + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len)) + static basic_json from_msgpack(detail::span_input_adapter&& i, + const bool strict = true, + const bool allow_exceptions = true) + { + basic_json result; + detail::json_sax_dom_parser sdp(result, allow_exceptions); + auto ia = i.get(); + // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) + const bool res = binary_reader(std::move(ia)).sax_parse(input_format_t::msgpack, &sdp, strict); + return res ? result : basic_json(value_t::discarded); + } + + + /*! + @brief create a JSON value from an input in UBJSON format + + Deserializes a given input @a i to a JSON value using the UBJSON (Universal + Binary JSON) serialization format. + + The library maps UBJSON types to JSON value types as follows: + + UBJSON type | JSON value type | marker + ----------- | --------------------------------------- | ------ + no-op | *no value, next value is read* | `N` + null | `null` | `Z` + false | `false` | `F` + true | `true` | `T` + float32 | number_float | `d` + float64 | number_float | `D` + uint8 | number_unsigned | `U` + int8 | number_integer | `i` + int16 | number_integer | `I` + int32 | number_integer | `l` + int64 | number_integer | `L` + high-precision number | number_integer, number_unsigned, or number_float - depends on number string | 'H' + string | string | `S` + char | string | `C` + array | array (optimized values are supported) | `[` + object | object (optimized values are supported) | `{` + + @note The mapping is **complete** in the sense that any UBJSON value can + be converted to a JSON value. + + @param[in] i an input in UBJSON format convertible to an input adapter + @param[in] strict whether to expect the input to be consumed until EOF + (true by default) + @param[in] allow_exceptions whether to throw exceptions in case of a + parse error (optional, true by default) + + @return deserialized JSON value; in case of a parse error and + @a allow_exceptions set to `false`, the return value will be + value_t::discarded. + + @throw parse_error.110 if the given input ends prematurely or the end of + file was not reached when @a strict was set to true + @throw parse_error.112 if a parse error occurs + @throw parse_error.113 if a string could not be parsed successfully + + @complexity Linear in the size of the input @a i. + + @liveexample{The example shows the deserialization of a byte vector in + UBJSON format to a JSON value.,from_ubjson} + + @sa http://ubjson.org + @sa see @ref to_ubjson(const basic_json&, const bool, const bool) for the + analogous serialization + @sa see @ref from_cbor(InputType&&, const bool, const bool, const cbor_tag_handler_t) for the + related CBOR format + @sa see @ref from_msgpack(InputType&&, const bool, const bool) for + the related MessagePack format + @sa see @ref from_bson(InputType&&, const bool, const bool) for + the related BSON format + + @since version 3.1.0; added @a allow_exceptions parameter since 3.2.0 + */ + template + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json from_ubjson(InputType&& i, + const bool strict = true, + const bool allow_exceptions = true) + { + basic_json result; + detail::json_sax_dom_parser sdp(result, allow_exceptions); + auto ia = detail::input_adapter(std::forward(i)); + const bool res = binary_reader(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict); + return res ? result : basic_json(value_t::discarded); + } + + /*! + @copydoc from_ubjson(InputType&&, const bool, const bool) + */ + template + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json from_ubjson(IteratorType first, IteratorType last, + const bool strict = true, + const bool allow_exceptions = true) + { + basic_json result; + detail::json_sax_dom_parser sdp(result, allow_exceptions); + auto ia = detail::input_adapter(std::move(first), std::move(last)); + const bool res = binary_reader(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict); + return res ? result : basic_json(value_t::discarded); + } + + template + JSON_HEDLEY_WARN_UNUSED_RESULT + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len)) + static basic_json from_ubjson(const T* ptr, std::size_t len, + const bool strict = true, + const bool allow_exceptions = true) + { + return from_ubjson(ptr, ptr + len, strict, allow_exceptions); + } + + JSON_HEDLEY_WARN_UNUSED_RESULT + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_ubjson(ptr, ptr + len)) + static basic_json from_ubjson(detail::span_input_adapter&& i, + const bool strict = true, + const bool allow_exceptions = true) + { + basic_json result; + detail::json_sax_dom_parser sdp(result, allow_exceptions); + auto ia = i.get(); + // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) + const bool res = binary_reader(std::move(ia)).sax_parse(input_format_t::ubjson, &sdp, strict); + return res ? result : basic_json(value_t::discarded); + } + + + /*! + @brief Create a JSON value from an input in BSON format + + Deserializes a given input @a i to a JSON value using the BSON (Binary JSON) + serialization format. + + The library maps BSON record types to JSON value types as follows: + + BSON type | BSON marker byte | JSON value type + --------------- | ---------------- | --------------------------- + double | 0x01 | number_float + string | 0x02 | string + document | 0x03 | object + array | 0x04 | array + binary | 0x05 | binary + undefined | 0x06 | still unsupported + ObjectId | 0x07 | still unsupported + boolean | 0x08 | boolean + UTC Date-Time | 0x09 | still unsupported + null | 0x0A | null + Regular Expr. | 0x0B | still unsupported + DB Pointer | 0x0C | still unsupported + JavaScript Code | 0x0D | still unsupported + Symbol | 0x0E | still unsupported + JavaScript Code | 0x0F | still unsupported + int32 | 0x10 | number_integer + Timestamp | 0x11 | still unsupported + 128-bit decimal float | 0x13 | still unsupported + Max Key | 0x7F | still unsupported + Min Key | 0xFF | still unsupported + + @warning The mapping is **incomplete**. The unsupported mappings + are indicated in the table above. + + @param[in] i an input in BSON format convertible to an input adapter + @param[in] strict whether to expect the input to be consumed until EOF + (true by default) + @param[in] allow_exceptions whether to throw exceptions in case of a + parse error (optional, true by default) + + @return deserialized JSON value; in case of a parse error and + @a allow_exceptions set to `false`, the return value will be + value_t::discarded. + + @throw parse_error.114 if an unsupported BSON record type is encountered + + @complexity Linear in the size of the input @a i. + + @liveexample{The example shows the deserialization of a byte vector in + BSON format to a JSON value.,from_bson} + + @sa http://bsonspec.org/spec.html + @sa see @ref to_bson(const basic_json&) for the analogous serialization + @sa see @ref from_cbor(InputType&&, const bool, const bool, const cbor_tag_handler_t) for the + related CBOR format + @sa see @ref from_msgpack(InputType&&, const bool, const bool) for + the related MessagePack format + @sa see @ref from_ubjson(InputType&&, const bool, const bool) for the + related UBJSON format + */ + template + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json from_bson(InputType&& i, + const bool strict = true, + const bool allow_exceptions = true) + { + basic_json result; + detail::json_sax_dom_parser sdp(result, allow_exceptions); + auto ia = detail::input_adapter(std::forward(i)); + const bool res = binary_reader(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict); + return res ? result : basic_json(value_t::discarded); + } + + /*! + @copydoc from_bson(InputType&&, const bool, const bool) + */ + template + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json from_bson(IteratorType first, IteratorType last, + const bool strict = true, + const bool allow_exceptions = true) + { + basic_json result; + detail::json_sax_dom_parser sdp(result, allow_exceptions); + auto ia = detail::input_adapter(std::move(first), std::move(last)); + const bool res = binary_reader(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict); + return res ? result : basic_json(value_t::discarded); + } + + template + JSON_HEDLEY_WARN_UNUSED_RESULT + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len)) + static basic_json from_bson(const T* ptr, std::size_t len, + const bool strict = true, + const bool allow_exceptions = true) + { + return from_bson(ptr, ptr + len, strict, allow_exceptions); + } + + JSON_HEDLEY_WARN_UNUSED_RESULT + JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_bson(ptr, ptr + len)) + static basic_json from_bson(detail::span_input_adapter&& i, + const bool strict = true, + const bool allow_exceptions = true) + { + basic_json result; + detail::json_sax_dom_parser sdp(result, allow_exceptions); + auto ia = i.get(); + // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) + const bool res = binary_reader(std::move(ia)).sax_parse(input_format_t::bson, &sdp, strict); + return res ? result : basic_json(value_t::discarded); + } + /// @} + + ////////////////////////// + // JSON Pointer support // + ////////////////////////// + + /// @name JSON Pointer functions + /// @{ + + /*! + @brief access specified element via JSON Pointer + + Uses a JSON pointer to retrieve a reference to the respective JSON value. + No bound checking is performed. Similar to @ref operator[](const typename + object_t::key_type&), `null` values are created in arrays and objects if + necessary. + + In particular: + - If the JSON pointer points to an object key that does not exist, it + is created an filled with a `null` value before a reference to it + is returned. + - If the JSON pointer points to an array index that does not exist, it + is created an filled with a `null` value before a reference to it + is returned. All indices between the current maximum and the given + index are also filled with `null`. + - The special value `-` is treated as a synonym for the index past the + end. + + @param[in] ptr a JSON pointer + + @return reference to the element pointed to by @a ptr + + @complexity Constant. + + @throw parse_error.106 if an array index begins with '0' + @throw parse_error.109 if an array index was not a number + @throw out_of_range.404 if the JSON pointer can not be resolved + + @liveexample{The behavior is shown in the example.,operatorjson_pointer} + + @since version 2.0.0 + */ + reference operator[](const json_pointer& ptr) + { + return ptr.get_unchecked(this); + } + + /*! + @brief access specified element via JSON Pointer + + Uses a JSON pointer to retrieve a reference to the respective JSON value. + No bound checking is performed. The function does not change the JSON + value; no `null` values are created. In particular, the special value + `-` yields an exception. + + @param[in] ptr JSON pointer to the desired element + + @return const reference to the element pointed to by @a ptr + + @complexity Constant. + + @throw parse_error.106 if an array index begins with '0' + @throw parse_error.109 if an array index was not a number + @throw out_of_range.402 if the array index '-' is used + @throw out_of_range.404 if the JSON pointer can not be resolved + + @liveexample{The behavior is shown in the example.,operatorjson_pointer_const} + + @since version 2.0.0 + */ + const_reference operator[](const json_pointer& ptr) const + { + return ptr.get_unchecked(this); + } + + /*! + @brief access specified element via JSON Pointer + + Returns a reference to the element at with specified JSON pointer @a ptr, + with bounds checking. + + @param[in] ptr JSON pointer to the desired element + + @return reference to the element pointed to by @a ptr + + @throw parse_error.106 if an array index in the passed JSON pointer @a ptr + begins with '0'. See example below. + + @throw parse_error.109 if an array index in the passed JSON pointer @a ptr + is not a number. See example below. + + @throw out_of_range.401 if an array index in the passed JSON pointer @a ptr + is out of range. See example below. + + @throw out_of_range.402 if the array index '-' is used in the passed JSON + pointer @a ptr. As `at` provides checked access (and no elements are + implicitly inserted), the index '-' is always invalid. See example below. + + @throw out_of_range.403 if the JSON pointer describes a key of an object + which cannot be found. See example below. + + @throw out_of_range.404 if the JSON pointer @a ptr can not be resolved. + See example below. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes in the JSON value. + + @complexity Constant. + + @since version 2.0.0 + + @liveexample{The behavior is shown in the example.,at_json_pointer} + */ + reference at(const json_pointer& ptr) + { + return ptr.get_checked(this); + } + + /*! + @brief access specified element via JSON Pointer + + Returns a const reference to the element at with specified JSON pointer @a + ptr, with bounds checking. + + @param[in] ptr JSON pointer to the desired element + + @return reference to the element pointed to by @a ptr + + @throw parse_error.106 if an array index in the passed JSON pointer @a ptr + begins with '0'. See example below. + + @throw parse_error.109 if an array index in the passed JSON pointer @a ptr + is not a number. See example below. + + @throw out_of_range.401 if an array index in the passed JSON pointer @a ptr + is out of range. See example below. + + @throw out_of_range.402 if the array index '-' is used in the passed JSON + pointer @a ptr. As `at` provides checked access (and no elements are + implicitly inserted), the index '-' is always invalid. See example below. + + @throw out_of_range.403 if the JSON pointer describes a key of an object + which cannot be found. See example below. + + @throw out_of_range.404 if the JSON pointer @a ptr can not be resolved. + See example below. + + @exceptionsafety Strong guarantee: if an exception is thrown, there are no + changes in the JSON value. + + @complexity Constant. + + @since version 2.0.0 + + @liveexample{The behavior is shown in the example.,at_json_pointer_const} + */ + const_reference at(const json_pointer& ptr) const + { + return ptr.get_checked(this); + } + + /*! + @brief return flattened JSON value + + The function creates a JSON object whose keys are JSON pointers (see [RFC + 6901](https://tools.ietf.org/html/rfc6901)) and whose values are all + primitive. The original JSON value can be restored using the @ref + unflatten() function. + + @return an object that maps JSON pointers to primitive values + + @note Empty objects and arrays are flattened to `null` and will not be + reconstructed correctly by the @ref unflatten() function. + + @complexity Linear in the size the JSON value. + + @liveexample{The following code shows how a JSON object is flattened to an + object whose keys consist of JSON pointers.,flatten} + + @sa see @ref unflatten() for the reverse function + + @since version 2.0.0 + */ + basic_json flatten() const + { + basic_json result(value_t::object); + json_pointer::flatten("", *this, result); + return result; + } + + /*! + @brief unflatten a previously flattened JSON value + + The function restores the arbitrary nesting of a JSON value that has been + flattened before using the @ref flatten() function. The JSON value must + meet certain constraints: + 1. The value must be an object. + 2. The keys must be JSON pointers (see + [RFC 6901](https://tools.ietf.org/html/rfc6901)) + 3. The mapped values must be primitive JSON types. + + @return the original JSON from a flattened version + + @note Empty objects and arrays are flattened by @ref flatten() to `null` + values and can not unflattened to their original type. Apart from + this example, for a JSON value `j`, the following is always true: + `j == j.flatten().unflatten()`. + + @complexity Linear in the size the JSON value. + + @throw type_error.314 if value is not an object + @throw type_error.315 if object values are not primitive + + @liveexample{The following code shows how a flattened JSON object is + unflattened into the original nested JSON object.,unflatten} + + @sa see @ref flatten() for the reverse function + + @since version 2.0.0 + */ + basic_json unflatten() const + { + return json_pointer::unflatten(*this); + } + + /// @} + + ////////////////////////// + // JSON Patch functions // + ////////////////////////// + + /// @name JSON Patch functions + /// @{ + + /*! + @brief applies a JSON patch + + [JSON Patch](http://jsonpatch.com) defines a JSON document structure for + expressing a sequence of operations to apply to a JSON) document. With + this function, a JSON Patch is applied to the current JSON value by + executing all operations from the patch. + + @param[in] json_patch JSON patch document + @return patched document + + @note The application of a patch is atomic: Either all operations succeed + and the patched document is returned or an exception is thrown. In + any case, the original value is not changed: the patch is applied + to a copy of the value. + + @throw parse_error.104 if the JSON patch does not consist of an array of + objects + + @throw parse_error.105 if the JSON patch is malformed (e.g., mandatory + attributes are missing); example: `"operation add must have member path"` + + @throw out_of_range.401 if an array index is out of range. + + @throw out_of_range.403 if a JSON pointer inside the patch could not be + resolved successfully in the current JSON value; example: `"key baz not + found"` + + @throw out_of_range.405 if JSON pointer has no parent ("add", "remove", + "move") + + @throw other_error.501 if "test" operation was unsuccessful + + @complexity Linear in the size of the JSON value and the length of the + JSON patch. As usually only a fraction of the JSON value is affected by + the patch, the complexity can usually be neglected. + + @liveexample{The following code shows how a JSON patch is applied to a + value.,patch} + + @sa see @ref diff -- create a JSON patch by comparing two JSON values + + @sa [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902) + @sa [RFC 6901 (JSON Pointer)](https://tools.ietf.org/html/rfc6901) + + @since version 2.0.0 + */ + basic_json patch(const basic_json& json_patch) const + { + // make a working copy to apply the patch to + basic_json result = *this; + + // the valid JSON Patch operations + enum class patch_operations {add, remove, replace, move, copy, test, invalid}; + + const auto get_op = [](const std::string & op) + { + if (op == "add") + { + return patch_operations::add; + } + if (op == "remove") + { + return patch_operations::remove; + } + if (op == "replace") + { + return patch_operations::replace; + } + if (op == "move") + { + return patch_operations::move; + } + if (op == "copy") + { + return patch_operations::copy; + } + if (op == "test") + { + return patch_operations::test; + } + + return patch_operations::invalid; + }; + + // wrapper for "add" operation; add value at ptr + const auto operation_add = [&result](json_pointer & ptr, basic_json val) + { + // adding to the root of the target document means replacing it + if (ptr.empty()) + { + result = val; + return; + } + + // make sure the top element of the pointer exists + json_pointer top_pointer = ptr.top(); + if (top_pointer != ptr) + { + result.at(top_pointer); + } + + // get reference to parent of JSON pointer ptr + const auto last_path = ptr.back(); + ptr.pop_back(); + basic_json& parent = result[ptr]; + + switch (parent.m_type) + { + case value_t::null: + case value_t::object: + { + // use operator[] to add value + parent[last_path] = val; + break; + } + + case value_t::array: + { + if (last_path == "-") + { + // special case: append to back + parent.push_back(val); + } + else + { + const auto idx = json_pointer::array_index(last_path); + if (JSON_HEDLEY_UNLIKELY(idx > parent.size())) + { + // avoid undefined behavior + JSON_THROW(out_of_range::create(401, "array index " + std::to_string(idx) + " is out of range", parent)); + } + + // default case: insert add offset + parent.insert(parent.begin() + static_cast(idx), val); + } + break; + } + + // if there exists a parent it cannot be primitive + case value_t::string: // LCOV_EXCL_LINE + case value_t::boolean: // LCOV_EXCL_LINE + case value_t::number_integer: // LCOV_EXCL_LINE + case value_t::number_unsigned: // LCOV_EXCL_LINE + case value_t::number_float: // LCOV_EXCL_LINE + case value_t::binary: // LCOV_EXCL_LINE + case value_t::discarded: // LCOV_EXCL_LINE + default: // LCOV_EXCL_LINE + JSON_ASSERT(false); // NOLINT(cert-dcl03-c,hicpp-static-assert,misc-static-assert) LCOV_EXCL_LINE + } + }; + + // wrapper for "remove" operation; remove value at ptr + const auto operation_remove = [this, &result](json_pointer & ptr) + { + // get reference to parent of JSON pointer ptr + const auto last_path = ptr.back(); + ptr.pop_back(); + basic_json& parent = result.at(ptr); + + // remove child + if (parent.is_object()) + { + // perform range check + auto it = parent.find(last_path); + if (JSON_HEDLEY_LIKELY(it != parent.end())) + { + parent.erase(it); + } + else + { + JSON_THROW(out_of_range::create(403, "key '" + last_path + "' not found", *this)); + } + } + else if (parent.is_array()) + { + // note erase performs range check + parent.erase(json_pointer::array_index(last_path)); + } + }; + + // type check: top level value must be an array + if (JSON_HEDLEY_UNLIKELY(!json_patch.is_array())) + { + JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects", json_patch)); + } + + // iterate and apply the operations + for (const auto& val : json_patch) + { + // wrapper to get a value for an operation + const auto get_value = [&val](const std::string & op, + const std::string & member, + bool string_type) -> basic_json & + { + // find value + auto it = val.m_value.object->find(member); + + // context-sensitive error message + const auto error_msg = (op == "op") ? "operation" : "operation '" + op + "'"; + + // check if desired value is present + if (JSON_HEDLEY_UNLIKELY(it == val.m_value.object->end())) + { + // NOLINTNEXTLINE(performance-inefficient-string-concatenation) + JSON_THROW(parse_error::create(105, 0, error_msg + " must have member '" + member + "'", val)); + } + + // check if result is of type string + if (JSON_HEDLEY_UNLIKELY(string_type && !it->second.is_string())) + { + // NOLINTNEXTLINE(performance-inefficient-string-concatenation) + JSON_THROW(parse_error::create(105, 0, error_msg + " must have string member '" + member + "'", val)); + } + + // no error: return value + return it->second; + }; + + // type check: every element of the array must be an object + if (JSON_HEDLEY_UNLIKELY(!val.is_object())) + { + JSON_THROW(parse_error::create(104, 0, "JSON patch must be an array of objects", val)); + } + + // collect mandatory members + const auto op = get_value("op", "op", true).template get(); + const auto path = get_value(op, "path", true).template get(); + json_pointer ptr(path); + + switch (get_op(op)) + { + case patch_operations::add: + { + operation_add(ptr, get_value("add", "value", false)); + break; + } + + case patch_operations::remove: + { + operation_remove(ptr); + break; + } + + case patch_operations::replace: + { + // the "path" location must exist - use at() + result.at(ptr) = get_value("replace", "value", false); + break; + } + + case patch_operations::move: + { + const auto from_path = get_value("move", "from", true).template get(); + json_pointer from_ptr(from_path); + + // the "from" location must exist - use at() + basic_json v = result.at(from_ptr); + + // The move operation is functionally identical to a + // "remove" operation on the "from" location, followed + // immediately by an "add" operation at the target + // location with the value that was just removed. + operation_remove(from_ptr); + operation_add(ptr, v); + break; + } + + case patch_operations::copy: + { + const auto from_path = get_value("copy", "from", true).template get(); + const json_pointer from_ptr(from_path); + + // the "from" location must exist - use at() + basic_json v = result.at(from_ptr); + + // The copy is functionally identical to an "add" + // operation at the target location using the value + // specified in the "from" member. + operation_add(ptr, v); + break; + } + + case patch_operations::test: + { + bool success = false; + JSON_TRY + { + // check if "value" matches the one at "path" + // the "path" location must exist - use at() + success = (result.at(ptr) == get_value("test", "value", false)); + } + JSON_INTERNAL_CATCH (out_of_range&) + { + // ignore out of range errors: success remains false + } + + // throw an exception if test fails + if (JSON_HEDLEY_UNLIKELY(!success)) + { + JSON_THROW(other_error::create(501, "unsuccessful: " + val.dump(), val)); + } + + break; + } + + case patch_operations::invalid: + default: + { + // op must be "add", "remove", "replace", "move", "copy", or + // "test" + JSON_THROW(parse_error::create(105, 0, "operation value '" + op + "' is invalid", val)); + } + } + } + + return result; + } + + /*! + @brief creates a diff as a JSON patch + + Creates a [JSON Patch](http://jsonpatch.com) so that value @a source can + be changed into the value @a target by calling @ref patch function. + + @invariant For two JSON values @a source and @a target, the following code + yields always `true`: + @code {.cpp} + source.patch(diff(source, target)) == target; + @endcode + + @note Currently, only `remove`, `add`, and `replace` operations are + generated. + + @param[in] source JSON value to compare from + @param[in] target JSON value to compare against + @param[in] path helper value to create JSON pointers + + @return a JSON patch to convert the @a source to @a target + + @complexity Linear in the lengths of @a source and @a target. + + @liveexample{The following code shows how a JSON patch is created as a + diff for two JSON values.,diff} + + @sa see @ref patch -- apply a JSON patch + @sa see @ref merge_patch -- apply a JSON Merge Patch + + @sa [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902) + + @since version 2.0.0 + */ + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json diff(const basic_json& source, const basic_json& target, + const std::string& path = "") + { + // the patch + basic_json result(value_t::array); + + // if the values are the same, return empty patch + if (source == target) + { + return result; + } + + if (source.type() != target.type()) + { + // different types: replace value + result.push_back( + { + {"op", "replace"}, {"path", path}, {"value", target} + }); + return result; + } + + switch (source.type()) + { + case value_t::array: + { + // first pass: traverse common elements + std::size_t i = 0; + while (i < source.size() && i < target.size()) + { + // recursive call to compare array values at index i + auto temp_diff = diff(source[i], target[i], path + "/" + std::to_string(i)); + result.insert(result.end(), temp_diff.begin(), temp_diff.end()); + ++i; + } + + // i now reached the end of at least one array + // in a second pass, traverse the remaining elements + + // remove my remaining elements + const auto end_index = static_cast(result.size()); + while (i < source.size()) + { + // add operations in reverse order to avoid invalid + // indices + result.insert(result.begin() + end_index, object( + { + {"op", "remove"}, + {"path", path + "/" + std::to_string(i)} + })); + ++i; + } + + // add other remaining elements + while (i < target.size()) + { + result.push_back( + { + {"op", "add"}, + {"path", path + "/-"}, + {"value", target[i]} + }); + ++i; + } + + break; + } + + case value_t::object: + { + // first pass: traverse this object's elements + for (auto it = source.cbegin(); it != source.cend(); ++it) + { + // escape the key name to be used in a JSON patch + const auto path_key = path + "/" + detail::escape(it.key()); + + if (target.find(it.key()) != target.end()) + { + // recursive call to compare object values at key it + auto temp_diff = diff(it.value(), target[it.key()], path_key); + result.insert(result.end(), temp_diff.begin(), temp_diff.end()); + } + else + { + // found a key that is not in o -> remove it + result.push_back(object( + { + {"op", "remove"}, {"path", path_key} + })); + } + } + + // second pass: traverse other object's elements + for (auto it = target.cbegin(); it != target.cend(); ++it) + { + if (source.find(it.key()) == source.end()) + { + // found a key that is not in this -> add it + const auto path_key = path + "/" + detail::escape(it.key()); + result.push_back( + { + {"op", "add"}, {"path", path_key}, + {"value", it.value()} + }); + } + } + + break; + } + + case value_t::null: + case value_t::string: + case value_t::boolean: + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + case value_t::binary: + case value_t::discarded: + default: + { + // both primitive type: replace value + result.push_back( + { + {"op", "replace"}, {"path", path}, {"value", target} + }); + break; + } + } + + return result; + } + + /// @} + + //////////////////////////////// + // JSON Merge Patch functions // + //////////////////////////////// + + /// @name JSON Merge Patch functions + /// @{ + + /*! + @brief applies a JSON Merge Patch + + The merge patch format is primarily intended for use with the HTTP PATCH + method as a means of describing a set of modifications to a target + resource's content. This function applies a merge patch to the current + JSON value. + + The function implements the following algorithm from Section 2 of + [RFC 7396 (JSON Merge Patch)](https://tools.ietf.org/html/rfc7396): + + ``` + define MergePatch(Target, Patch): + if Patch is an Object: + if Target is not an Object: + Target = {} // Ignore the contents and set it to an empty Object + for each Name/Value pair in Patch: + if Value is null: + if Name exists in Target: + remove the Name/Value pair from Target + else: + Target[Name] = MergePatch(Target[Name], Value) + return Target + else: + return Patch + ``` + + Thereby, `Target` is the current object; that is, the patch is applied to + the current value. + + @param[in] apply_patch the patch to apply + + @complexity Linear in the lengths of @a patch. + + @liveexample{The following code shows how a JSON Merge Patch is applied to + a JSON document.,merge_patch} + + @sa see @ref patch -- apply a JSON patch + @sa [RFC 7396 (JSON Merge Patch)](https://tools.ietf.org/html/rfc7396) + + @since version 3.0.0 + */ + void merge_patch(const basic_json& apply_patch) + { + if (apply_patch.is_object()) + { + if (!is_object()) + { + *this = object(); + } + for (auto it = apply_patch.begin(); it != apply_patch.end(); ++it) + { + if (it.value().is_null()) + { + erase(it.key()); + } + else + { + operator[](it.key()).merge_patch(it.value()); + } + } + } + else + { + *this = apply_patch; + } + } + + /// @} +}; + +/*! +@brief user-defined to_string function for JSON values + +This function implements a user-defined to_string for JSON objects. + +@param[in] j a JSON object +@return a std::string object +*/ + +NLOHMANN_BASIC_JSON_TPL_DECLARATION +std::string to_string(const NLOHMANN_BASIC_JSON_TPL& j) +{ + return j.dump(); +} +} // namespace nlohmann + +/////////////////////// +// nonmember support // +/////////////////////// + +// specialization of std::swap, and std::hash +namespace std +{ + +/// hash value for JSON objects +template<> +struct hash +{ + /*! + @brief return a hash value for a JSON object + + @since version 1.0.0 + */ + std::size_t operator()(const nlohmann::json& j) const + { + return nlohmann::detail::hash(j); + } +}; + +/// specialization for std::less +/// @note: do not remove the space after '<', +/// see https://github.com/nlohmann/json/pull/679 +template<> +struct less<::nlohmann::detail::value_t> +{ + /*! + @brief compare two value_t enum values + @since version 3.0.0 + */ + bool operator()(nlohmann::detail::value_t lhs, + nlohmann::detail::value_t rhs) const noexcept + { + return nlohmann::detail::operator<(lhs, rhs); + } +}; + +// C++20 prohibit function specialization in the std namespace. +#ifndef JSON_HAS_CPP_20 + +/*! +@brief exchanges the values of two JSON objects + +@since version 1.0.0 +*/ +template<> +inline void swap(nlohmann::json& j1, nlohmann::json& j2) noexcept( // NOLINT(readability-inconsistent-declaration-parameter-name) + is_nothrow_move_constructible::value&& // NOLINT(misc-redundant-expression) + is_nothrow_move_assignable::value + ) +{ + j1.swap(j2); +} + +#endif + +} // namespace std + +/*! +@brief user-defined string literal for JSON values + +This operator implements a user-defined string literal for JSON objects. It +can be used by adding `"_json"` to a string literal and returns a JSON object +if no parse error occurred. + +@param[in] s a string representation of a JSON object +@param[in] n the length of string @a s +@return a JSON object + +@since version 1.0.0 +*/ +JSON_HEDLEY_NON_NULL(1) +inline nlohmann::json operator "" _json(const char* s, std::size_t n) +{ + return nlohmann::json::parse(s, s + n); +} + +/*! +@brief user-defined string literal for JSON pointer + +This operator implements a user-defined string literal for JSON Pointers. It +can be used by adding `"_json_pointer"` to a string literal and returns a JSON pointer +object if no parse error occurred. + +@param[in] s a string representation of a JSON Pointer +@param[in] n the length of string @a s +@return a JSON pointer object + +@since version 2.0.0 +*/ +JSON_HEDLEY_NON_NULL(1) +inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n) +{ + return nlohmann::json::json_pointer(std::string(s, n)); +} + +// #include + + +// restore clang diagnostic settings +#if defined(__clang__) + #pragma clang diagnostic pop +#endif + +// clean up +#undef JSON_ASSERT +#undef JSON_INTERNAL_CATCH +#undef JSON_CATCH +#undef JSON_THROW +#undef JSON_TRY +#undef JSON_PRIVATE_UNLESS_TESTED +#undef JSON_HAS_CPP_11 +#undef JSON_HAS_CPP_14 +#undef JSON_HAS_CPP_17 +#undef JSON_HAS_CPP_20 +#undef NLOHMANN_BASIC_JSON_TPL_DECLARATION +#undef NLOHMANN_BASIC_JSON_TPL +#undef JSON_EXPLICIT +#undef NLOHMANN_CAN_CALL_STD_FUNC_IMPL + +// #include + + +#undef JSON_HEDLEY_ALWAYS_INLINE +#undef JSON_HEDLEY_ARM_VERSION +#undef JSON_HEDLEY_ARM_VERSION_CHECK +#undef JSON_HEDLEY_ARRAY_PARAM +#undef JSON_HEDLEY_ASSUME +#undef JSON_HEDLEY_BEGIN_C_DECLS +#undef JSON_HEDLEY_CLANG_HAS_ATTRIBUTE +#undef JSON_HEDLEY_CLANG_HAS_BUILTIN +#undef JSON_HEDLEY_CLANG_HAS_CPP_ATTRIBUTE +#undef JSON_HEDLEY_CLANG_HAS_DECLSPEC_DECLSPEC_ATTRIBUTE +#undef JSON_HEDLEY_CLANG_HAS_EXTENSION +#undef JSON_HEDLEY_CLANG_HAS_FEATURE +#undef JSON_HEDLEY_CLANG_HAS_WARNING +#undef JSON_HEDLEY_COMPCERT_VERSION +#undef JSON_HEDLEY_COMPCERT_VERSION_CHECK +#undef JSON_HEDLEY_CONCAT +#undef JSON_HEDLEY_CONCAT3 +#undef JSON_HEDLEY_CONCAT3_EX +#undef JSON_HEDLEY_CONCAT_EX +#undef JSON_HEDLEY_CONST +#undef JSON_HEDLEY_CONSTEXPR +#undef JSON_HEDLEY_CONST_CAST +#undef JSON_HEDLEY_CPP_CAST +#undef JSON_HEDLEY_CRAY_VERSION +#undef JSON_HEDLEY_CRAY_VERSION_CHECK +#undef JSON_HEDLEY_C_DECL +#undef JSON_HEDLEY_DEPRECATED +#undef JSON_HEDLEY_DEPRECATED_FOR +#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CAST_QUAL +#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_CPP98_COMPAT_WRAP_ +#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_DEPRECATED +#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_CPP_ATTRIBUTES +#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNKNOWN_PRAGMAS +#undef JSON_HEDLEY_DIAGNOSTIC_DISABLE_UNUSED_FUNCTION +#undef JSON_HEDLEY_DIAGNOSTIC_POP +#undef JSON_HEDLEY_DIAGNOSTIC_PUSH +#undef JSON_HEDLEY_DMC_VERSION +#undef JSON_HEDLEY_DMC_VERSION_CHECK +#undef JSON_HEDLEY_EMPTY_BASES +#undef JSON_HEDLEY_EMSCRIPTEN_VERSION +#undef JSON_HEDLEY_EMSCRIPTEN_VERSION_CHECK +#undef JSON_HEDLEY_END_C_DECLS +#undef JSON_HEDLEY_FLAGS +#undef JSON_HEDLEY_FLAGS_CAST +#undef JSON_HEDLEY_GCC_HAS_ATTRIBUTE +#undef JSON_HEDLEY_GCC_HAS_BUILTIN +#undef JSON_HEDLEY_GCC_HAS_CPP_ATTRIBUTE +#undef JSON_HEDLEY_GCC_HAS_DECLSPEC_ATTRIBUTE +#undef JSON_HEDLEY_GCC_HAS_EXTENSION +#undef JSON_HEDLEY_GCC_HAS_FEATURE +#undef JSON_HEDLEY_GCC_HAS_WARNING +#undef JSON_HEDLEY_GCC_NOT_CLANG_VERSION_CHECK +#undef JSON_HEDLEY_GCC_VERSION +#undef JSON_HEDLEY_GCC_VERSION_CHECK +#undef JSON_HEDLEY_GNUC_HAS_ATTRIBUTE +#undef JSON_HEDLEY_GNUC_HAS_BUILTIN +#undef JSON_HEDLEY_GNUC_HAS_CPP_ATTRIBUTE +#undef JSON_HEDLEY_GNUC_HAS_DECLSPEC_ATTRIBUTE +#undef JSON_HEDLEY_GNUC_HAS_EXTENSION +#undef JSON_HEDLEY_GNUC_HAS_FEATURE +#undef JSON_HEDLEY_GNUC_HAS_WARNING +#undef JSON_HEDLEY_GNUC_VERSION +#undef JSON_HEDLEY_GNUC_VERSION_CHECK +#undef JSON_HEDLEY_HAS_ATTRIBUTE +#undef JSON_HEDLEY_HAS_BUILTIN +#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE +#undef JSON_HEDLEY_HAS_CPP_ATTRIBUTE_NS +#undef JSON_HEDLEY_HAS_DECLSPEC_ATTRIBUTE +#undef JSON_HEDLEY_HAS_EXTENSION +#undef JSON_HEDLEY_HAS_FEATURE +#undef JSON_HEDLEY_HAS_WARNING +#undef JSON_HEDLEY_IAR_VERSION +#undef JSON_HEDLEY_IAR_VERSION_CHECK +#undef JSON_HEDLEY_IBM_VERSION +#undef JSON_HEDLEY_IBM_VERSION_CHECK +#undef JSON_HEDLEY_IMPORT +#undef JSON_HEDLEY_INLINE +#undef JSON_HEDLEY_INTEL_CL_VERSION +#undef JSON_HEDLEY_INTEL_CL_VERSION_CHECK +#undef JSON_HEDLEY_INTEL_VERSION +#undef JSON_HEDLEY_INTEL_VERSION_CHECK +#undef JSON_HEDLEY_IS_CONSTANT +#undef JSON_HEDLEY_IS_CONSTEXPR_ +#undef JSON_HEDLEY_LIKELY +#undef JSON_HEDLEY_MALLOC +#undef JSON_HEDLEY_MCST_LCC_VERSION +#undef JSON_HEDLEY_MCST_LCC_VERSION_CHECK +#undef JSON_HEDLEY_MESSAGE +#undef JSON_HEDLEY_MSVC_VERSION +#undef JSON_HEDLEY_MSVC_VERSION_CHECK +#undef JSON_HEDLEY_NEVER_INLINE +#undef JSON_HEDLEY_NON_NULL +#undef JSON_HEDLEY_NO_ESCAPE +#undef JSON_HEDLEY_NO_RETURN +#undef JSON_HEDLEY_NO_THROW +#undef JSON_HEDLEY_NULL +#undef JSON_HEDLEY_PELLES_VERSION +#undef JSON_HEDLEY_PELLES_VERSION_CHECK +#undef JSON_HEDLEY_PGI_VERSION +#undef JSON_HEDLEY_PGI_VERSION_CHECK +#undef JSON_HEDLEY_PREDICT +#undef JSON_HEDLEY_PRINTF_FORMAT +#undef JSON_HEDLEY_PRIVATE +#undef JSON_HEDLEY_PUBLIC +#undef JSON_HEDLEY_PURE +#undef JSON_HEDLEY_REINTERPRET_CAST +#undef JSON_HEDLEY_REQUIRE +#undef JSON_HEDLEY_REQUIRE_CONSTEXPR +#undef JSON_HEDLEY_REQUIRE_MSG +#undef JSON_HEDLEY_RESTRICT +#undef JSON_HEDLEY_RETURNS_NON_NULL +#undef JSON_HEDLEY_SENTINEL +#undef JSON_HEDLEY_STATIC_ASSERT +#undef JSON_HEDLEY_STATIC_CAST +#undef JSON_HEDLEY_STRINGIFY +#undef JSON_HEDLEY_STRINGIFY_EX +#undef JSON_HEDLEY_SUNPRO_VERSION +#undef JSON_HEDLEY_SUNPRO_VERSION_CHECK +#undef JSON_HEDLEY_TINYC_VERSION +#undef JSON_HEDLEY_TINYC_VERSION_CHECK +#undef JSON_HEDLEY_TI_ARMCL_VERSION +#undef JSON_HEDLEY_TI_ARMCL_VERSION_CHECK +#undef JSON_HEDLEY_TI_CL2000_VERSION +#undef JSON_HEDLEY_TI_CL2000_VERSION_CHECK +#undef JSON_HEDLEY_TI_CL430_VERSION +#undef JSON_HEDLEY_TI_CL430_VERSION_CHECK +#undef JSON_HEDLEY_TI_CL6X_VERSION +#undef JSON_HEDLEY_TI_CL6X_VERSION_CHECK +#undef JSON_HEDLEY_TI_CL7X_VERSION +#undef JSON_HEDLEY_TI_CL7X_VERSION_CHECK +#undef JSON_HEDLEY_TI_CLPRU_VERSION +#undef JSON_HEDLEY_TI_CLPRU_VERSION_CHECK +#undef JSON_HEDLEY_TI_VERSION +#undef JSON_HEDLEY_TI_VERSION_CHECK +#undef JSON_HEDLEY_UNAVAILABLE +#undef JSON_HEDLEY_UNLIKELY +#undef JSON_HEDLEY_UNPREDICTABLE +#undef JSON_HEDLEY_UNREACHABLE +#undef JSON_HEDLEY_UNREACHABLE_RETURN +#undef JSON_HEDLEY_VERSION +#undef JSON_HEDLEY_VERSION_DECODE_MAJOR +#undef JSON_HEDLEY_VERSION_DECODE_MINOR +#undef JSON_HEDLEY_VERSION_DECODE_REVISION +#undef JSON_HEDLEY_VERSION_ENCODE +#undef JSON_HEDLEY_WARNING +#undef JSON_HEDLEY_WARN_UNUSED_RESULT +#undef JSON_HEDLEY_WARN_UNUSED_RESULT_MSG +#undef JSON_HEDLEY_FALL_THROUGH + + + +#endif // INCLUDE_NLOHMANN_JSON_HPP_ diff --git a/templates/b_to_s_gamma.cpp.in b/templates/b_to_s_gamma.cpp.in index 42755af5a9..b90e83180d 100644 --- a/templates/b_to_s_gamma.cpp.in +++ b/templates/b_to_s_gamma.cpp.in @@ -25,18 +25,18 @@ #include #include -#include +#include +#include #include "@ModelName@_b_to_s_gamma.hpp" #include "@ModelName@_mass_eigenstates.hpp" - #include "cxx_qft/@ModelName@_qft.hpp" #include "@ModelName@_FFV_form_factors.hpp" #include "lowe.h" #include "wrappers.hpp" +#include "json.hpp" -#include #define MODELPARAMETER(p) context.model.get_##p() @@ -56,30 +56,18 @@ void write_wilsoncoeffs(const std::complex& C7NP_bs, const std::complex< const std::complex& C8NP_bs, const std::complex& C8pNP_bs, const double& matching_scale) { - std::ofstream wc_json; - wc_json.open ("WC_@ModelName@.json"); - wc_json << "{\n\"eft\": \"WET\",\n"; - wc_json << "\t\"basis\": \"flavio\",\n"; - wc_json << "\t\"scale\": \"" << matching_scale << "\",\n"; - wc_json << "\t\"values\": {\n"; - wc_json << "\t\t\"C7_bs\": {\n"; - wc_json << "\t\t\t\"Re\": " << Re(C7NP_bs) << ",\n"; - wc_json << "\t\t\t\"Im\": " << Im(C7NP_bs) << "\n"; - wc_json << "\t\t},\n"; - wc_json << "\t\t\"C7p_bs\": {\n"; - wc_json << "\t\t\t\"Re\": " << Re(C7pNP_bs) << ",\n"; - wc_json << "\t\t\t\"Im\": " << Im(C7pNP_bs) << "\n"; - wc_json << "\t\t},\n"; - wc_json << "\t\t\"C8_bs\": {\n"; - wc_json << "\t\t\t\"Re\": " << Re(C8NP_bs) << ",\n"; - wc_json << "\t\t\t\"Im\": " << Im(C8NP_bs) << "\n"; - wc_json << "\t\t},\n"; - wc_json << "\t\t\"C8p_bs\": {\n"; - wc_json << "\t\t\t\"Re\": " << Re(C8pNP_bs) << ",\n"; - wc_json << "\t\t\t\"Im\": " << Im(C8pNP_bs) << "\n"; - wc_json << "\t\t}\n"; - wc_json << "\t}\n"; - wc_json << "}"; + nlohmann::json j; + j["eft"] = "WET"; + j["basis"] = "flavio"; + j["scale"] = matching_scale; + j["values"] = { + {"C7_bs", {{"Re", Re(C7NP_bs)}, {"Im", Im(C7NP_bs)}}}, + {"C7p_bs", {{"Re", Re(C7pNP_bs)}, {"Im", Im(C7pNP_bs)}}}, + {"C8_bs", {{"Re", Re(C8NP_bs)}, {"Im", Im(C8NP_bs)}}}, + {"C8p_bs", {{"Re", Re(C8pNP_bs)}, {"Im", Im(C8pNP_bs)}}} + }; + std::ofstream wc_json("WC_@ModelName@.json"); + wc_json << std::setw(4) << j << std::endl; wc_json.close(); } From 065cfb0740229b560ea3802e3880993943381dcf Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 2 Dec 2021 13:45:19 +0100 Subject: [PATCH 096/477] added file forgotten in previous commit --- nlohmann/module.mk | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 nlohmann/module.mk diff --git a/nlohmann/module.mk b/nlohmann/module.mk new file mode 100644 index 0000000000..5d8562d93a --- /dev/null +++ b/nlohmann/module.mk @@ -0,0 +1,31 @@ +DIR := nlohmann +MODNAME := nlohmann + +NLOHMANN_HDR := \ + $(DIR)/json.hpp + +NLOHMANN_MK := \ + $(DIR)/module.mk + +NLOHMANN_INSTALL_DIR := $(INSTALL_DIR)/$(DIR) + +.PHONY: all-$(MODNAME) clean-$(MODNAME) distclean-$(MODNAME) + +all-$(MODNAME): + @true + +ifneq ($(INSTALL_DIR),) +install-src:: + $(Q)install -d $(NLOHMANN_INSTALL_DIR) + $(Q)install -m u=rw,g=r,o=r $(NLOHMANN_HDR) $(NLOHMANN_INSTALL_DIR) + $(Q)install -m u=rw,g=r,o=r $(NLOHMANN_MK) $(NLOHMANN_INSTALL_DIR) +endif + +clean-$(MODNAME): + @true + +distclean-$(MODNAME): clean-$(MODNAME) + +clean:: clean-$(MODNAME) + +distclean:: distclean-$(MODNAME) From 15b227c67e0a18037fd955173fe3af517689f6c0 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Mon, 6 Dec 2021 08:19:06 +0100 Subject: [PATCH 097/477] faster implementation (~20%) of Iabc function --- src/threshold_loop_functions.cpp | 150 +++++++++++++++---------------- 1 file changed, 75 insertions(+), 75 deletions(-) diff --git a/src/threshold_loop_functions.cpp b/src/threshold_loop_functions.cpp index ca5fa82a7a..c449b61926 100644 --- a/src/threshold_loop_functions.cpp +++ b/src/threshold_loop_functions.cpp @@ -22,6 +22,7 @@ #include "logger.hpp" #include "numerics.h" +#include #include #include @@ -92,6 +93,13 @@ namespace { return x * std::log(x); } + void sort(double& x, double& y, double& z) noexcept + { + if (x > y) { std::swap(x, y); } + if (y > z) { std::swap(y, z); } + if (x > y) { std::swap(x, y); } + } + } // anonymous namespace double F1(double x) noexcept @@ -1830,107 +1838,99 @@ double D2F7(double x) noexcept namespace { -/// I2abc(a,a,a), squared arguments, a != 0 -double I2aaa(double a, double b, double c) noexcept { - const double ba = b - a; - const double ca = c - a; - const double a2 = sqr(a); - const double a3 = a2*a; +/// Ixy(0,y), squared arguments, y != 0 +double I0y(double y) noexcept { + if (is_close(y, 1, 10*std::numeric_limits::epsilon())) { + const double d = y - 1; + return 1 + d*(-0.5 + d/3); + } - return 0.5/a + (-ba - ca)/(6.0*a2) + (sqr(ba) + ba*ca + sqr(ca))/(12.0*a3); + return std::log(y)/(y - 1); } -/// I2abc(a,a,c), squared arguments, a != c -double I2aac(double a, double b, double c) noexcept { - const double ba = b - a; - const double ac = a - c; - const double a2 = sqr(a); - const double a3 = a2*a; - const double c2 = sqr(c); - const double c3 = c2*c; - const double ac2 = sqr(ac); - const double ac3 = ac2*ac; - const double ac4 = ac2*ac2; - const double lac = std::log(a/c); +/// I(x,y), squared arguments, x == 1, y != 0 +double I1y(double x, double y) noexcept { + const double dy = y - 1; + const double dy2 = sqr(dy); + const double dx = (x - 1)/dy2; + const double y2 = sqr(y); + const double yly = y*std::log(y); - return (ac - c*lac)/ac2 - + ba*(-a2 + c2 + 2*a*c*lac)/(2.0*a*ac3) - + sqr(ba)*((2*a3 + 3*a2*c - 6*a*c2 + c3 - 6*a2*c*lac)/(6.*a2*ac4)); + return (1 - y + yly)/dy2 + + dx*(0.5 - y2/2 + yly)/dy + + sqr(dx)*(1./3 + y/2 + yly + y2*(y/6 - 1)); } -/// I2abc(a,a,0), squared arguments, a != 0 -double I2aa0(double a, double b) noexcept { - const double a2 = sqr(a); - const double a3 = a2*a; - const double ba = b - a; - const double ba2 = sqr(ba); - - return 1.0/a - ba/(2.0*a2) + ba2/(3.0*a3); -} +/// I(x,y), squared arguments, x == y, x != 0, y != 0 +double Ixx(double x, double y) noexcept { + const double eps_eq = 0.001; -/// I2abc(0,b,c), squared arguments, b != c -double I20bc(double b, double c) noexcept { - return std::log(b/c)/(b - c); -} + if (is_close(y, 1, eps_eq)) { + const double dx = x - 1; + const double dy = y - 1; + const double dy2 = sqr(dy); -} // anonymous namespace + return 0.5 + dx*(-1./6 + dy/12 - dy2/20) + + sqr(dx)*(1./12 - dy/20 + dy2/30) + - dy/6 + dy2/12; + } -double Iabc(double a, double b, double c) noexcept { - const double eps = 10.0*std::numeric_limits::epsilon(); + const double y2 = sqr(y); + const double dy = y - 1; + const double dy2 = sqr(dy); + const double dxy = (x - y)/dy2; + const double ly = std::log(y); - if ((is_zero(a, eps) && is_zero(b, eps) && is_zero(c, eps)) || - (is_zero(a, eps) && is_zero(b, eps)) || - (is_zero(a, eps) && is_zero(c, eps)) || - (is_zero(b, eps) && is_zero(c, eps))) { - return 0.0; - } + return (dy - ly)/dy2 + + dxy*(0.5 - y2/2 + y*ly)/(dy*y) + + sqr(dxy)*(1./6 - y + y2*(0.5 + y/3 - ly))/y2; +} - const double a2 = sqr(a); - const double b2 = sqr(b); - const double c2 = sqr(c); +/// I(x,y), x < y, x and y are squared arguments +double Ixy(double x, double y) noexcept { const double eps_eq = 0.001; - if (is_close(a2, b2, eps_eq) && is_close(a2, c2, eps_eq)) { - return I2aaa(a2, b2, c2); + if (is_zero(y, 10*std::numeric_limits::epsilon())) { + return 0; } - if (is_close(a2, b2, eps_eq)) { - if (is_zero(c, eps)) { - return I2aa0(a2, b2); - } - return I2aac(a2, b2, c2); + if (is_zero(x, 10*std::numeric_limits::epsilon())) { + return I0y(y); } - if (is_close(b2, c2, eps_eq)) { - if (is_zero(a, eps)) { - return I2aa0(b2, c2); - } - return I2aac(b2, c2, a2); + if (is_close(x/y, 1, eps_eq)) { + return Ixx(x, y); } - if (is_close(a2, c2, eps_eq)) { - if (is_zero(b, eps)) { - return I2aa0(a2, c2); - } - return I2aac(a2, c2, b2); + if (is_close(x, 1, eps_eq)) { + return I1y(x, y); } - if (is_zero(a, eps)) { - return I20bc(b2, c2); + if (is_close(y, 1, eps_eq)) { + return I1y(y, x); } - if (is_zero(b, eps)) { - return I20bc(c2, a2); - } + const double lx = std::log(x); + const double ly = std::log(y); + + return (x*(y - 1)*lx - y*(x - 1)*ly)/((x - 1)*(x - y)*(y - 1)); +} - if (is_zero(c, eps)) { - return I20bc(a2, b2); +/// I(x,y,z), x, y and z are squared arguments +double Ixyz(double x, double y, double z) noexcept { + sort(x, y, z); + + if (is_zero(z, 10*std::numeric_limits::epsilon())) { + return 0; } - return (+ a2 * b2 * std::log(a2/b2) - + b2 * c2 * std::log(b2/c2) - + c2 * a2 * std::log(c2/a2)) - / ((a2 - b2) * (b2 - c2) * (a2 - c2)); + return Ixy(x/z, y/z)/z; +} + +} // anonymous namespace + +double Iabc(double a, double b, double c) noexcept { + return Ixyz(sqr(a), sqr(b), sqr(c)); } /// Delta function from hep-ph/0907.47682v1 From 8d229c8e87489291fc7c23a1cd14a065711f51a9 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Mon, 6 Dec 2021 08:23:50 +0100 Subject: [PATCH 098/477] faster implementation of power functions --- src/threshold_loop_functions.cpp | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/src/threshold_loop_functions.cpp b/src/threshold_loop_functions.cpp index c449b61926..19c2ba0ebe 100644 --- a/src/threshold_loop_functions.cpp +++ b/src/threshold_loop_functions.cpp @@ -30,14 +30,15 @@ namespace flexiblesusy { namespace threshold_loop_functions { namespace { - template T sqr(T x) noexcept { return x*x; } - template T cube(T x) noexcept { return x*x*x; } - template T quad(T x) noexcept { return x*x*x*x; } - template T pow5(T x) noexcept { return x*x*x*x*x; } - template T pow6(T x) noexcept { return x*x*x*x*x*x; } - template T pow7(T x) noexcept { return x*x*x*x*x*x*x; } - template T pow8(T x) noexcept { return x*x*x*x*x*x*x*x; } - template T pow9(T x) noexcept { return x*x*x*x*x*x*x*x*x; } + template constexpr T sqr(T x) noexcept { return x*x; } + template constexpr T cube(T x) noexcept { return x*x*x; } + template constexpr T quad(T x) noexcept { return sqr(sqr(x)); } + template constexpr T pow5(T x) noexcept { return x*quad(x); } + template constexpr T pow6(T x) noexcept { return sqr(cube(x)); } + template constexpr T pow7(T x) noexcept { return x*pow6(x); } + template constexpr T pow8(T x) noexcept { return sqr(quad(x)); } + template constexpr T pow9(T x) noexcept { return x*pow8(x); } + template bool is_zero(T a, T prec) noexcept From d34721c05d1dba975a61826f1cb076a8fd78306d Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Fri, 17 Dec 2021 00:25:26 +0100 Subject: [PATCH 099/477] updated CI to Wolfram Engine v13.0.0 --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9732347cfd..c5d92c4022 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -125,7 +125,7 @@ jobs: runs-on: ubuntu-latest container: - image: navir/opensuseleap-for-flexiblesusy:0.10.0 + image: navir/opensuseleap-for-flexiblesusy:0.11.0 strategy: matrix: From fd8d59dda8fc90182fdfb2255189326341dd8f57 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Mon, 3 Jan 2022 18:24:58 +0100 Subject: [PATCH 100/477] fixed wrong calculation of Ah->AZ --- CHANGES.rst | 3 ++- src/decays/H_SM_decays/decay_AH_to_AZ.inc | 2 +- test/test_MSSM_FlexibleDecay.cpp | 4 +--- test/test_THDMII_FlexibleDecay.cpp | 4 +--- 4 files changed, 5 insertions(+), 8 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 0abd8c6948..91ede8faf2 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -33,6 +33,8 @@ Fixed bugs * [commit 26f5262ad3a8936ae6297305d2ee92a71b17da09]: Branching ratio of L'->LGamma was breaking printing of observables via the mathlink interface. +* [commit ]: Fixed wrong calculation of $A \to Z \gamma$. + FlexibleSUSY 2.6.1 [July, 08 2021] ================================== @@ -53,7 +55,6 @@ Fixed bugs * [commit a0bbda569]: Correcting check for required Mathematica version 11.0, needed by FlexibleDecay. - FlexibleSUSY 2.6.0 [June, 10 2021] ================================== diff --git a/src/decays/H_SM_decays/decay_AH_to_AZ.inc b/src/decays/H_SM_decays/decay_AH_to_AZ.inc index 3192e67a27..522e84afc3 100644 --- a/src/decays/H_SM_decays/decay_AH_to_AZ.inc +++ b/src/decays/H_SM_decays/decay_AH_to_AZ.inc @@ -5,7 +5,7 @@ double CLASSNAME::get_partial_width( const typename field_indices::type& out1_idx, const typename field_indices::type& out2_idx) const { - const auto amp = calculate_amplitude(context, in_idx, out1_idx, out2_idx); + const auto amp = calculate_amplitude(context, in_idx, out1_idx, out2_idx); const double mH = context.physical_mass(in_idx); const double mZ = qedqcd.displayPoleMZ(); const double ps = 1./(8.*Pi) * std::sqrt(KallenLambda(1., 0., Sqr(mZ/mH))); diff --git a/test/test_MSSM_FlexibleDecay.cpp b/test/test_MSSM_FlexibleDecay.cpp index 92b2c22a2e..1e8ef706a3 100644 --- a/test/test_MSSM_FlexibleDecay.cpp +++ b/test/test_MSSM_FlexibleDecay.cpp @@ -712,8 +712,6 @@ Block MSOFT Q= 8.61574711E+02 BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00043378057279629952, 4e-13); // Ah -> gamma gamma BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VPVP(&m, 1), 4.1843910938310874e-06, 4e-12); - // Ah -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VPVZ(&m, 1), 8.9472411012847983e-06, 2e-11); // ----------------------------------------------------- // decays without higher-order SM corrections @@ -743,7 +741,7 @@ Block MSOFT Q= 8.61574711E+02 // Ah -> gamma gamma BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VPVP(&m, 1), 4.0630566804965507e-06, 4e-12); // Ah -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VPVZ(&m, 1), 8.6877987532066177e-06, 2e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VPVZ(&m, 1), 9.3179924792926659e-06, 2e-11); // h -> gamma Z BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVZ(&m, 0), 2.2198080013381038e-06, 2e-10); diff --git a/test/test_THDMII_FlexibleDecay.cpp b/test/test_THDMII_FlexibleDecay.cpp index e1d18d3146..de688b46ac 100644 --- a/test/test_THDMII_FlexibleDecay.cpp +++ b/test/test_THDMII_FlexibleDecay.cpp @@ -297,8 +297,6 @@ Block UERMIX BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00078773836543896236, 3e-14); // Ah -> gamma gamma BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VPVP(&m, 1), 3.5731537311554876e-06, 3e-12); - // Ah -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VPVZ(&m, 1), 7.400139551262125e-06, 8e-12); // Ah -> b bbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFdFd(&m, 0, 2, 2), @@ -339,5 +337,5 @@ Block UERMIX // Ah -> gamma gamma BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VPVP(&m, 1), 2.5449279002187577e-06, 3e-12); // Ah -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VPVZ(&m, 1), 5.2706440938462322e-06, 8e-12); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VPVZ(&m, 1), 5.4527502373283228e-07, 8e-12); } From 92b7b651e9d7397028a454dd70aae6af8b6fff6a Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Mon, 31 Jan 2022 11:30:34 +0100 Subject: [PATCH 101/477] don't repeat the same expression in different files --- src/decays/H_SM_decays/decay_AH_to_dqdq.inc | 2 +- src/decays/H_SM_decays/decay_AH_to_uquq.inc | 2 +- src/decays/H_SM_decays/decay_H_to_dqdq.inc | 2 +- src/decays/H_SM_decays/decay_H_to_uquq.inc | 2 +- src/decays/decay_functions.hpp | 2 ++ 5 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/decays/H_SM_decays/decay_AH_to_dqdq.inc b/src/decays/H_SM_decays/decay_AH_to_dqdq.inc index 037ff63c0d..e028d96c3e 100644 --- a/src/decays/H_SM_decays/decay_AH_to_dqdq.inc +++ b/src/decays/H_SM_decays/decay_AH_to_dqdq.inc @@ -101,7 +101,7 @@ double CLASSNAME::get_partial_width::type, dq>( if (static_cast(flexibledecay_settings.get(FlexibleDecay_settings::include_higher_order_corrections)) > 1) { deltaqq_QCDxQED_DR = - (691/24. - 6*zeta3 - Sqr(Pi))*Sqr(dq::electric_charge)*alpha_red*alpha_s_red; + deltaqq_QCDxQED*Sqr(dq::electric_charge)*alpha_red*alpha_s_red; if (!is_zero(gbHoVEV_P)) { const double mtpole = qedqcd.displayPoleMt(); const double lt = std::log(Sqr(mAOS/mtpole)); diff --git a/src/decays/H_SM_decays/decay_AH_to_uquq.inc b/src/decays/H_SM_decays/decay_AH_to_uquq.inc index 6307c12b39..2ad7d00a7f 100644 --- a/src/decays/H_SM_decays/decay_AH_to_uquq.inc +++ b/src/decays/H_SM_decays/decay_AH_to_uquq.inc @@ -96,7 +96,7 @@ double CLASSNAME::get_partial_width::type, uq>( double deltaPhi2_P = 0.; if (static_cast(flexibledecay_settings.get(FlexibleDecay_settings::include_higher_order_corrections)) > 1) { deltaqq_QCDxQED_DR = - (691/24. - 6*zeta3 - Sqr(Pi))*Sqr(dq::electric_charge)*alpha_red*alpha_s_red; + deltaqq_QCDxQED*Sqr(dq::electric_charge)*alpha_red*alpha_s_red; if ((indexOut1.at(0) < 2 || indexOut2.at(0) < 2)) { const double mtpole = qedqcd.displayPoleMt(); const double lt = std::log(Sqr(mAHOS/mtpole)); diff --git a/src/decays/H_SM_decays/decay_H_to_dqdq.inc b/src/decays/H_SM_decays/decay_H_to_dqdq.inc index 570599e239..f34ca16f24 100644 --- a/src/decays/H_SM_decays/decay_H_to_dqdq.inc +++ b/src/decays/H_SM_decays/decay_H_to_dqdq.inc @@ -110,7 +110,7 @@ double CLASSNAME::get_partial_width::type,dq>( if (static_cast(flexibledecay_settings.get(FlexibleDecay_settings::include_higher_order_corrections)) > 1) { deltaqq_QCDxQED_DR = - (691/24. - 6*zeta3 - Sqr(Pi))*Sqr(dq::electric_charge)*alpha_red*alpha_s_red; + deltaqq_QCDxQED*Sqr(dq::electric_charge)*alpha_red*alpha_s_red; const double mtpole = qedqcd.displayPoleMt(); const double lt = std::log(Sqr(mHOS/mtpole)); diff --git a/src/decays/H_SM_decays/decay_H_to_uquq.inc b/src/decays/H_SM_decays/decay_H_to_uquq.inc index 93cae5db60..5e79fd4b92 100644 --- a/src/decays/H_SM_decays/decay_H_to_uquq.inc +++ b/src/decays/H_SM_decays/decay_H_to_uquq.inc @@ -122,7 +122,7 @@ double CLASSNAME::get_partial_width::type, uq>( double deltaqq_QCDxQED_DR = 0.; if (static_cast(flexibledecay_settings.get(FlexibleDecay_settings::include_higher_order_corrections)) > 1) { deltaqq_QCDxQED_DR = - (691/24. - 6*zeta3 - Sqr(Pi))*Sqr(dq::electric_charge)*alpha_red*alpha_s_red; + deltaqq_QCDxQED*Sqr(dq::electric_charge)*alpha_red*alpha_s_red; if ((indexOut1.at(0) < 2 || indexOut2.at(0) < 2)) { const double mtpole = qedqcd.displayPoleMt(); const double lt = std::log(Sqr(mHOS/mtpole)); diff --git a/src/decays/decay_functions.hpp b/src/decays/decay_functions.hpp index 76e58c2ce8..c8fe1d7082 100644 --- a/src/decays/decay_functions.hpp +++ b/src/decays/decay_functions.hpp @@ -22,6 +22,7 @@ #include #include "src/lowe.h" #include "flexibledecay_settings.hpp" +#include "src/wrappers.hpp" namespace flexiblesusy { @@ -59,6 +60,7 @@ unsigned int number_of_active_flavours(softsusy::QedQcd const&, double m) noexce double sm_up_quark_masses(softsusy::QedQcd const&, int); double sm_down_quark_masses(softsusy::QedQcd const&, int); +static constexpr double deltaqq_QCDxQED = 691/24. - 6*zeta3 - Sqr(Pi); } // namespace flexiblesusy #endif From f52ad3449dbce92cbfbc60aa92317ee0f3dd823b Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 9 Feb 2022 05:19:21 +0100 Subject: [PATCH 102/477] reduced precision of failing FlexibleDecay MRSSM tests --- test/test_MRSSM2_FlexibleDecay.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_MRSSM2_FlexibleDecay.cpp b/test/test_MRSSM2_FlexibleDecay.cpp index 867d915983..b5db916cb0 100644 --- a/test/test_MRSSM2_FlexibleDecay.cpp +++ b/test/test_MRSSM2_FlexibleDecay.cpp @@ -743,10 +743,10 @@ Block FlexibleSUSYLowEnergy Q= 1.00000000E+03 // h -> b bbar BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFdFd(&m, 0, 2, 2), - 0.0015852320624501718, 4e-14); + 0.0015852320624501718, 2e-13); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFuFu(&m, 0, 1, 1), - 8.2876032145842477e-05, 3e-14); + 8.2876032145842477e-05, 1e-13); // h -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFeFe(&m, 0, 2, 2), 0.00026660324954596258, 5e-12); From b82d0d212384ee79b880769b72ed713a1406c350 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Tue, 15 Feb 2022 20:41:23 +0100 Subject: [PATCH 103/477] SSV amp squared with mV=0 should give 0 --- src/decays/decay_amplitudes.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/decays/decay_amplitudes.cpp b/src/decays/decay_amplitudes.cpp index c2694f6d1d..30fb55f120 100644 --- a/src/decays/decay_amplitudes.cpp +++ b/src/decays/decay_amplitudes.cpp @@ -36,8 +36,10 @@ double Decay_amplitude_SSS::square() const double Decay_amplitude_SSV::square() const { if (m_vector <= massless_vector_threshold) { - // eq. B36 of http://etheses.dur.ac.uk/2301 has incorrect oposite sign - return 2. * AbsSqr(form_factor) * (Sqr(m_decay) + Sqr(m_scalar)); + // eq. B36 of http://etheses.dur.ac.uk/2301 is incorrect + // if the amplitude fullfils the Ward indentity & the vector is physical (i.e. transversal) + // then the amplitude is identically 0 + return 0.; } const double m_in_sq = Sqr(m_decay); From 0ab73b467f49ce8deb8b3ef23e03e819a361e05e Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Tue, 15 Feb 2022 20:42:56 +0100 Subject: [PATCH 104/477] added WARNING as promised in FlexibleDecay referee report --- src/decays/decay_functions.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/decays/decay_functions.cpp b/src/decays/decay_functions.cpp index 20daaf0c4b..8e9ffaafd0 100644 --- a/src/decays/decay_functions.cpp +++ b/src/decays/decay_functions.cpp @@ -204,7 +204,8 @@ std::complex delta_hAA_2loopQCD_for_quark_loop(double mH, double mq, dou std::complex delta_AhAA_2loopQCD_for_quark_loop(double mAh, double mq, double mu) noexcept { const double tau = Sqr(mAh/(2.*mq)); // know threshold singularity at mAh = 2*mq - if (is_zero(1 - tau, 1e-6)) { + if (is_zero(1 - tau, 1e-2)) { + WARNING("2-loop QCD corrections to A→γγ are disable in the threshold region: τ = " << std::to_string(tau)); return 0.; } const std::complex z = is_zero(tau) ? 1. : (std::sqrt(std::complex(1. - 1./tau))-1.)/(std::sqrt(std::complex(1.-1./tau))+1.); From 69a544c1e753a8dbce3fd3b0ad7cc90945822694 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sat, 19 Feb 2022 14:06:00 +0100 Subject: [PATCH 105/477] updated changelog before the next release --- CHANGES.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 91ede8faf2..973ab84ee5 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,4 +1,4 @@ -FlexibleSUSY 2.?.? [?, ? 202?] +FlexibleSUSY 2.6.2 [February, ? 2022] ================================== New features @@ -25,15 +25,15 @@ Changes ------- * [commit ae1eae8e4d373eec531d6e5774977da2f12e88c8]: Mathematica-style indexing (starting from 1) of - leptons in L'->LGamma via the mathlink interface. + leptons in `$L' \to L \gamma$` via the mathlink interface. Fixed bugs ---------- -* [commit 26f5262ad3a8936ae6297305d2ee92a71b17da09]: Branching ratio of L'->LGamma was breaking printing of +* [commit 26f5262ad3a8936ae6297305d2ee92a71b17da09]: Branching ratio of `$L' \to L \gamma$` was breaking printing of observables via the mathlink interface. -* [commit ]: Fixed wrong calculation of $A \to Z \gamma$. +* [commit fd8d59dda8fc90182fdfb2255189326341dd8f57]: Fixed wrong calculation of `$A \to Z \gamma$`. FlexibleSUSY 2.6.1 [July, 08 2021] ================================== From 7c1d692485d72b1b9ef65ea4d2fdab2c652f0c50 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 10 Mar 2022 21:34:28 +0100 Subject: [PATCH 106/477] updated CI to Wolfram Engine v13.0.1 --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index c5d92c4022..9aa0f7cdb8 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -125,7 +125,7 @@ jobs: runs-on: ubuntu-latest container: - image: navir/opensuseleap-for-flexiblesusy:0.11.0 + image: navir/opensuseleap-for-flexiblesusy:0.11.3 strategy: matrix: From 9a3fb6c0679accbc489ac67cdbf1f94f92f57fcb Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sat, 12 Mar 2022 14:22:40 +0100 Subject: [PATCH 107/477] make sure that no one calls decay for a goldstone (#411) --- meta/FlexibleSUSY.m | 2 ++ src/decays/H_SM_decays/decay_AH_to_AA.inc | 4 ++++ src/decays/H_SM_decays/decay_AH_to_AZ.inc | 4 ++++ src/decays/H_SM_decays/decay_AH_to_GG.inc | 4 ++++ src/decays/H_SM_decays/decay_AH_to_dqdq.inc | 4 ++++ src/decays/H_SM_decays/decay_AH_to_leplep.inc | 3 +++ src/decays/H_SM_decays/decay_AH_to_uquq.inc | 4 ++++ templates/info.hpp.in | 2 ++ test/test_MRSSM2_FlexibleDecay.cpp | 8 ++++---- test/test_MSSMCPV_FlexibleDecay.cpp | 4 ++-- test/test_MSSM_FlexibleDecay.cpp | 4 ++-- test/test_THDMII_FlexibleDecay.cpp | 8 ++++---- 12 files changed, 39 insertions(+), 12 deletions(-) diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index 2bf42be39e..6e5451fc79 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -3065,6 +3065,8 @@ corresponding tadpole is real or imaginary (only in models with CP "@setParticleMultipletNameAndIndexFromPDG@" -> IndentText[setParticleMultipletNameAndIndexFromPDG], "@isCPViolatingHiggsSector@" -> CreateCBoolValue @ SA`CPViolationHiggsSector, "@useDecaysData@" -> useDecaysData, + "@numberOfNeutralGoldstones@" -> IndentText["static constexpr int number_of_neutral_goldstones = " <> ToString[TreeMasses`GetDimensionStartSkippingGoldstones[TreeMasses`GetPseudoscalarHiggsBoson[]]-1] <> ";"], + "@numberOfChargedGoldstones@" -> IndentText["static constexpr int number_of_charged_goldstones = " <> ToString[TreeMasses`GetDimensionStartSkippingGoldstones[TreeMasses`GetChargedHiggsBoson[]]-1] <> ";"], Sequence @@ GeneralReplacementRules[] } ]; ]; diff --git a/src/decays/H_SM_decays/decay_AH_to_AA.inc b/src/decays/H_SM_decays/decay_AH_to_AA.inc index 84775c754b..aca73d5064 100644 --- a/src/decays/H_SM_decays/decay_AH_to_AA.inc +++ b/src/decays/H_SM_decays/decay_AH_to_AA.inc @@ -5,6 +5,10 @@ double CLASSNAME::get_partial_width( const typename field_indices::type& out1_idx, const typename field_indices::type& out2_idx) const { + if (in_idx.at(0) < info::number_of_neutral_goldstones) { + throw OutOfBoundsError("Error in " + create_process_string(in_idx, out1_idx, out2_idx) + " decay. Decaying particle is a Goldstone."); + } + const auto amp = calculate_amplitude(context, in_idx, out1_idx, out2_idx); const double mH = context.physical_mass(in_idx); constexpr double ps {1./(8.*Pi)}; diff --git a/src/decays/H_SM_decays/decay_AH_to_AZ.inc b/src/decays/H_SM_decays/decay_AH_to_AZ.inc index 522e84afc3..056e131f8a 100644 --- a/src/decays/H_SM_decays/decay_AH_to_AZ.inc +++ b/src/decays/H_SM_decays/decay_AH_to_AZ.inc @@ -5,6 +5,10 @@ double CLASSNAME::get_partial_width( const typename field_indices::type& out1_idx, const typename field_indices::type& out2_idx) const { + if (in_idx.at(0) < info::number_of_neutral_goldstones) { + throw OutOfBoundsError("Error in " + create_process_string(in_idx, out1_idx, out2_idx) + " decay. Decaying particle is a Goldstone."); + } + const auto amp = calculate_amplitude(context, in_idx, out1_idx, out2_idx); const double mH = context.physical_mass(in_idx); const double mZ = qedqcd.displayPoleMZ(); diff --git a/src/decays/H_SM_decays/decay_AH_to_GG.inc b/src/decays/H_SM_decays/decay_AH_to_GG.inc index 3667624fbf..3178f2c2f3 100644 --- a/src/decays/H_SM_decays/decay_AH_to_GG.inc +++ b/src/decays/H_SM_decays/decay_AH_to_GG.inc @@ -5,6 +5,10 @@ double CLASSNAME::get_partial_width( const typename field_indices::type& out1_idx, const typename field_indices::type& out2_idx) const { + if (in_idx.at(0) < info::number_of_neutral_goldstones) { + throw OutOfBoundsError("Error in " + create_process_string(in_idx, out1_idx, out2_idx) + " decay. Decaying particle is a Goldstone."); + } + const auto amp = calculate_amplitude(context, in_idx, out1_idx, out2_idx); const double mAh = context.physical_mass(in_idx); constexpr double ps {1./(8.*Pi)}; diff --git a/src/decays/H_SM_decays/decay_AH_to_dqdq.inc b/src/decays/H_SM_decays/decay_AH_to_dqdq.inc index e028d96c3e..ec0164f3a3 100644 --- a/src/decays/H_SM_decays/decay_AH_to_dqdq.inc +++ b/src/decays/H_SM_decays/decay_AH_to_dqdq.inc @@ -9,6 +9,10 @@ double CLASSNAME::get_partial_width::type, dq>( typename field_indices::type const& indexOut2 ) const { + if (indexIn.at(0) < info::number_of_neutral_goldstones) { + throw OutOfBoundsError("Error in " + create_process_string::type, dq>(indexIn, indexOut1, indexOut2) + " decay. Decaying particle is a Goldstone."); + } + // get HBBbar vertex // we don't use amplitude_squared here because we need both this vertex // both with running and pole masses diff --git a/src/decays/H_SM_decays/decay_AH_to_leplep.inc b/src/decays/H_SM_decays/decay_AH_to_leplep.inc index 34e9b458fc..8dcd01414b 100644 --- a/src/decays/H_SM_decays/decay_AH_to_leplep.inc +++ b/src/decays/H_SM_decays/decay_AH_to_leplep.inc @@ -7,6 +7,9 @@ double CLASSNAME::get_partial_width::type, lep>( typename field_indices::type>::type const& indexOut1, typename field_indices::type const& indexOut2) const { + if (indexIn.at(0) < info::number_of_neutral_goldstones) { + throw OutOfBoundsError("Error in " + create_process_string::type, lep>(indexIn, indexOut1, indexOut2) + " decay. Decaying particle is a Goldstone."); + } const double mAHOS = context.physical_mass(indexIn); const double mL1OS = context.physical_mass::type>(indexOut1); diff --git a/src/decays/H_SM_decays/decay_AH_to_uquq.inc b/src/decays/H_SM_decays/decay_AH_to_uquq.inc index 2ad7d00a7f..2198b79068 100644 --- a/src/decays/H_SM_decays/decay_AH_to_uquq.inc +++ b/src/decays/H_SM_decays/decay_AH_to_uquq.inc @@ -8,6 +8,10 @@ double CLASSNAME::get_partial_width::type, uq>( typename field_indices::type const& indexOut2 ) const { + if (indexIn.at(0) < info::number_of_neutral_goldstones) { + throw OutOfBoundsError("Error in " + create_process_string::type, uq>(indexIn, indexOut1, indexOut2) + " decay. Decaying particle is a Goldstone."); + } + // get AHBBbar vertex // we don't use amplitude_squared here because we need both this vertex // both with running and pole masses diff --git a/templates/info.hpp.in b/templates/info.hpp.in index cb685286b0..57e0a7f025 100644 --- a/templates/info.hpp.in +++ b/templates/info.hpp.in @@ -38,6 +38,8 @@ namespace @ModelName@_info { @inputParameterEnum@ @extraParameterEnum@ @gaugeCouplingNormalizationDecls@ +@numberOfNeutralGoldstones@ +@numberOfChargedGoldstones@ extern const std::array particle_multiplicities; extern const std::array particle_names; diff --git a/test/test_MRSSM2_FlexibleDecay.cpp b/test/test_MRSSM2_FlexibleDecay.cpp index b5db916cb0..2dc36f3a56 100644 --- a/test/test_MRSSM2_FlexibleDecay.cpp +++ b/test/test_MRSSM2_FlexibleDecay.cpp @@ -730,10 +730,10 @@ Block FlexibleSUSYLowEnergy Q= 1.00000000E+03 BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00029502623532270532, 8e-14); - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFdFd(&m, 0, 2, 2), - 0.0018327846210855049, 5e-12); - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFuFu(&m, 0, 1, 1), - 9.139211136105259e-05, 2e-13); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFdFd(&m, 1, 2, 2), + 27.558400433360585, 5e-12); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFuFu(&m, 1, 1, 1), + 6.5403200582277049e-07, 2e-13); // ----------------------------------------------------- // decays without higher-order SM corrections diff --git a/test/test_MSSMCPV_FlexibleDecay.cpp b/test/test_MSSMCPV_FlexibleDecay.cpp index 3e9bbe38aa..f85de4d541 100644 --- a/test/test_MSSMCPV_FlexibleDecay.cpp +++ b/test/test_MSSMCPV_FlexibleDecay.cpp @@ -788,7 +788,7 @@ Block ImMSOFT Q= 2.00000000E+03 // without 2L QCD for squark // BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 0), 6.3284545616000571e-06, 4e-11); // with 2L QCD for squark - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 1), 5.3089300093115946e-06, 5e-10); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 1), 5.3089300093115946e-06, 7e-10); // h -> gamma Z BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 1), 5.1994372474535712e-07, 7e-11); @@ -808,7 +808,7 @@ Block ImMSOFT Q= 2.00000000E+03 BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFeFe(&m, 1, 2, 2), 0.00022454719336516455, 3e-13); // h -> gamma gamma - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVP(&m, 1), 5.2382389517397406e-06, 5e-10); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVP(&m, 1), 5.2382389517397406e-06, 7e-10); // h -> gluon gluon BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VGVG(&m, 1), 6.1972398675528688e-05, 2e-10); diff --git a/test/test_MSSM_FlexibleDecay.cpp b/test/test_MSSM_FlexibleDecay.cpp index 1e8ef706a3..733930fd9b 100644 --- a/test/test_MSSM_FlexibleDecay.cpp +++ b/test/test_MSSM_FlexibleDecay.cpp @@ -697,8 +697,8 @@ Block MSOFT Q= 8.61574711E+02 BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFeFe(&m, 1, 2, 2), 0.14370134308297239, 4e-13); // Ah -> c cbar - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFuFu(&m, 0, 1, 1), - 9.3015080450372116e-05, 3e-13); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFuFu(&m, 1, 1, 1), + 6.1486061511096085e-06, 3e-13); // Ah -> W+ W- BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_conjVWmVWm(&m, 1), 3.9267959281226782e-05, 2e-12); diff --git a/test/test_THDMII_FlexibleDecay.cpp b/test/test_THDMII_FlexibleDecay.cpp index de688b46ac..2c0f820930 100644 --- a/test/test_THDMII_FlexibleDecay.cpp +++ b/test/test_THDMII_FlexibleDecay.cpp @@ -299,11 +299,11 @@ Block UERMIX BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VPVP(&m, 1), 3.5731537311554876e-06, 3e-12); // Ah -> b bbar - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFdFd(&m, 0, 2, 2), - 0.0018671335954316421, 2e-15); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFdFd(&m, 1, 2, 2), + 1.0248504778252014, 2e-15); // Ah -> c cbar - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFuFu(&m, 0, 1, 1), - 9.3482696650389066e-05, 2e-16); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFuFu(&m, 1, 1, 1), + 5.1682891794454512e-06, 2e-16); // ----------------------------------------------------- // decays without higher-order SM corrections From bf545b9f47149c47aa56eb95de45392ff966debc Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Mon, 14 Mar 2022 09:03:15 +0100 Subject: [PATCH 108/477] make more constants constexpr and use std:: prefix --- src/ew_input.hpp | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src/ew_input.hpp b/src/ew_input.hpp index 91c1b3f96d..314f33ba5b 100644 --- a/src/ew_input.hpp +++ b/src/ew_input.hpp @@ -33,13 +33,13 @@ namespace flexiblesusy { namespace Electroweak_constants { namespace { constexpr double vev = 246.22; - const double root2 = sqrt(2.0); + constexpr double root2 = 1.4142135623730950; constexpr double mtoprun = 165; constexpr double mbrun = 2.9; constexpr double mtau = 1.77699; - const double yt = mtoprun * root2 / vev; - const double yb = mbrun * root2 / vev; - const double ytau = mtau * root2 / vev; + constexpr double yt = mtoprun * root2 / vev; + constexpr double yb = mbrun * root2 / vev; + constexpr double ytau = mtau * root2 / vev; constexpr double MZ = 91.1876; constexpr double Error_MZ = 0.0021; ///< uncertainty on MZ from PDG constexpr double MW = 80.385; @@ -59,27 +59,27 @@ namespace Electroweak_constants { constexpr double PMBOTTOM = 4.9; ///< default pole mass from PDG constexpr double aem = 1.0 / 127.916; // at MZ constexpr double sinThetaW2 = 0.23122; - const double sinThetaW = sqrt(sinThetaW2); + const double sinThetaW = std::sqrt(sinThetaW2); constexpr double cosThetaW2 = 1 - sinThetaW2; - const double cosThetaW = sqrt(cosThetaW2); + const double cosThetaW = std::sqrt(cosThetaW2); constexpr double alpha1 = 5.0 * aem / (3.0 * (1.0 - sinThetaW2)); constexpr double alpha2 = aem / sinThetaW2; constexpr double alpha3 = 0.1184; // at MZ from PDG - const double e = sqrt(4.0 * Pi * aem); - const double g1 = sqrt(4.0 * Pi * alpha1); - const double g2 = sqrt(4.0 * Pi * alpha2); - const double g3 = sqrt(4.0 * Pi * alpha3); + const double e = std::sqrt(4.0 * Pi * aem); + const double g1 = std::sqrt(4.0 * Pi * alpha1); + const double g2 = std::sqrt(4.0 * Pi * alpha2); + const double g3 = std::sqrt(4.0 * Pi * alpha3); constexpr double gYSM = 3.57232027E-01; ///< gY MS-bar in the SM at Q = MZ - const double g1SM = sqrt(5./3.) * gYSM; ///< g1 MS-bar in the SM at Q = MZ + const double g1SM = std::sqrt(5./3.) * gYSM; ///< g1 MS-bar in the SM at Q = MZ constexpr double g2SM = 6.51103848E-01; ///< g2 MS-bar in the SM at Q = MZ constexpr double g3SM = 1.21087245E+00; ///< g3 MS-bar in the SM at Q = MZ constexpr double CKM_THETA12 = 0.229206; ///< From Vus/Vud in global CKM fit, PDG constexpr double CKM_THETA13 = 0.003960; ///< From Vub in global CKM fit, PDG constexpr double CKM_THETA23 = 0.042223; ///< From Vcb/Vtb in global CKM fit, PDG constexpr double CKM_DELTA = 0.; - const double PMNS_THETA12 = 0.5 * asin(sqrt(0.846)); - const double PMNS_THETA13 = 0.5 * asin(sqrt(0.093)); - const double PMNS_THETA23 = 0.5 * asin(sqrt(0.999)); + const double PMNS_THETA12 = 0.5 * std::asin(std::sqrt(0.846)); + const double PMNS_THETA13 = 0.5 * std::asin(std::sqrt(0.093)); + const double PMNS_THETA23 = 0.5 * std::asin(std::sqrt(0.999)); constexpr double PMNS_DELTA = 0.; constexpr double PMNS_ALPHA1 = 0.; constexpr double PMNS_ALPHA2 = 0.; From 78ea1189646444aee30ba2bb4b6f78cfbff4f069 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 17 Mar 2022 10:26:25 +0100 Subject: [PATCH 109/477] changed parameter point in MRSSM2 FlexibleDecay tests (some?) sgluon decays vanish in the limit where left and right handed squark masses are equal. Previous test point results for sgluon partial widths were therefore very sensitive to exact numerical values of squark masses. --- test/test_MRSSM2_FlexibleDecay.cpp | 60 +++++++++++++++--------------- 1 file changed, 30 insertions(+), 30 deletions(-) diff --git a/test/test_MRSSM2_FlexibleDecay.cpp b/test/test_MRSSM2_FlexibleDecay.cpp index 2dc36f3a56..91888136de 100644 --- a/test/test_MRSSM2_FlexibleDecay.cpp +++ b/test/test_MRSSM2_FlexibleDecay.cpp @@ -106,11 +106,11 @@ Block HMIXIN 201 4.00000000E+02 # MuDInput 202 4.00000000E+02 # MuUInput Block MSD2IN - 1 1 6.25000000E+06 # md2Input(1,1) + 1 1 1.00000000E+06 # md2Input(1,1) 1 2 0.00000000E+00 # md2Input(1,2) 1 3 0.00000000E+00 # md2Input(1,3) 2 1 0.00000000E+00 # md2Input(2,1) - 2 2 6.25000000E+06 # md2Input(2,2) + 2 2 1.00000000E+06 # md2Input(2,2) 2 3 0.00000000E+00 # md2Input(2,3) 3 1 0.00000000E+00 # md2Input(3,1) 3 2 0.00000000E+00 # md2Input(3,2) @@ -134,33 +134,33 @@ Block MSE2IN 3 2 0.00000000E+00 # me2Input(3,2) 3 3 1.00000000E+06 # me2Input(3,3) Block MSL2IN - 1 1 1.00000000E+06 # ml2Input(1,1) + 1 1 4.00000000E+06 # ml2Input(1,1) 1 2 0.00000000E+00 # ml2Input(1,2) 1 3 0.00000000E+00 # ml2Input(1,3) 2 1 0.00000000E+00 # ml2Input(2,1) - 2 2 1.00000000E+06 # ml2Input(2,2) + 2 2 4.00000000E+06 # ml2Input(2,2) 2 3 0.00000000E+00 # ml2Input(2,3) 3 1 0.00000000E+00 # ml2Input(3,1) 3 2 0.00000000E+00 # ml2Input(3,2) - 3 3 1.00000000E+06 # ml2Input(3,3) + 3 3 4.00000000E+06 # ml2Input(3,3) Block MSQ2IN - 1 1 6.25000000E+06 # mq2Input(1,1) + 1 1 4.00000000E+06 # mq2Input(1,1) 1 2 0.00000000E+00 # mq2Input(1,2) 1 3 0.00000000E+00 # mq2Input(1,3) 2 1 0.00000000E+00 # mq2Input(2,1) - 2 2 6.25000000E+06 # mq2Input(2,2) + 2 2 4.00000000E+06 # mq2Input(2,2) 2 3 0.00000000E+00 # mq2Input(2,3) 3 1 0.00000000E+00 # mq2Input(3,1) 3 2 0.00000000E+00 # mq2Input(3,2) - 3 3 1.00000000E+06 # mq2Input(3,3) + 3 3 4.00000000E+06 # mq2Input(3,3) Block NMSSMRUNIN 10 4.00000000E+06 # mS2Input Block MSU2IN - 1 1 6.25000000E+06 # mu2Input(1,1) + 1 1 1.00000000E+06 # mu2Input(1,1) 1 2 0.00000000E+00 # mu2Input(1,2) 1 3 0.00000000E+00 # mu2Input(1,3) 2 1 0.00000000E+00 # mu2Input(2,1) - 2 2 6.25000000E+06 # mu2Input(2,2) + 2 2 1.00000000E+06 # mu2Input(2,2) 2 3 0.00000000E+00 # mu2Input(2,3) 3 1 0.00000000E+00 # mu2Input(3,1) 3 2 0.00000000E+00 # mu2Input(3,2) @@ -695,45 +695,45 @@ Block FlexibleSUSYLowEnergy Q= 1.00000000E+03 // h -> b bbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFdFd(&m, 0, 2, 2), - 0.0025273625096655988, 5e-12); + 0.0025634108347145032, 5e-12); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFuFu(&m, 0, 1, 1), - 0.00012115281603656197, 2e-13); + 0.00012285838147242436, 2e-13); // QED corrections // BOOST_CHECK_CLOSE_FRACTION(decays.partial_width_hh_to_barFdFd(&m, 0, 2, 2), // 2.6059181498481999E-003, 5e-15); // h -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFeFe(&m, 0, 2, 2), - 0.00026946060398832237, 5e-12); + 0.00027545151828801864, 5e-12); // h -> W+ W- // BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_conjVWmVWm(&m, 0), // 0.00066154345019159267, 5e-11); BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_conjVWmVWm(&m, 0), - 0.00073836837044127768, 1e-3); + 0.00094083425095728521, 1e-3); // h -> Z Z // BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VZVZ(&m, 0), // 7.5383132433569488e-05, 9e-12); BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VZVZ(&m, 0), - 9.638232014475222e-05, 1e-3); + 0.00012722814312214181, 1e-3); // ------------ loop-induces decays ------------ // h -> gluon gluon - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VGVG(&m, 0), 0.00038305055803087727, 7e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VGVG(&m, 0), 0.00040230167812046075, 7e-11); // h -> gamma gamma // without 2-loop QCD corrections to squark loop // BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 0), 8.3519576334971031e-06, 4e-11); // with 2-loop QCD corrections to squark loop - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 0), 1.0316485590151162e-05, 4e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 0), 1.1323516448739387e-05, 4e-11); // h -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 0), 6.391735378735319e-06, 5e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 0), 7.8803489809960472e-06, 5e-11); - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00029502623532270532, 8e-14); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00029585461520717076, 2e-13); BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFdFd(&m, 1, 2, 2), - 27.558400433360585, 5e-12); + 27.422426060823373, 5e-12); BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFuFu(&m, 1, 1, 1), - 6.5403200582277049e-07, 2e-13); + 6.535918222486397e-07, 2e-13); // ----------------------------------------------------- // decays without higher-order SM corrections @@ -743,29 +743,29 @@ Block FlexibleSUSYLowEnergy Q= 1.00000000E+03 // h -> b bbar BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFdFd(&m, 0, 2, 2), - 0.0015852320624501718, 2e-13); + 0.0016025829212124214, 2e-13); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFuFu(&m, 0, 1, 1), - 8.2876032145842477e-05, 1e-13); + 8.4238942917635169e-05, 2e-13); // h -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFeFe(&m, 0, 2, 2), - 0.00026660324954596258, 5e-12); + 0.00027252978259241349, 5e-12); // ------------ loop-induces decays ------------ // h -> gamma gamma - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVP(&m, 0), 1.0133389963488187e-05, 4e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVP(&m, 0), 1.1149675854277999e-05, 4e-11); // h -> gluon gluon - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VGVG(&m, 0), 0.00012423136936565911, 7e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VGVG(&m, 0), 0.00013277226722491827, 7e-11); // h -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVZ(&m, 0), 6.391735378735319e-06, 5e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVZ(&m, 0), 7.8803489809960472e-06, 5e-11); // scalar sgluon - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_phiO_to_VGVG(&m), 7.5701751945543629e-09, 3e-11); - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_phiO_to_barFuFu(&m, 2, 2), 2.2040853636396876e-05, 2e-12); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_phiO_to_VGVG(&m), 0.057227805663593985, 3e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_phiO_to_barFuFu(&m, 2, 2), 2.3214926991726654e-05, 2e-12); // pseudoscalar sgluon BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_sigmaO_to_VGVG(&m), 0, 1e-16); - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_sigmaO_to_barFuFu(&m, 2, 2), 2.1375623871457065e-11, 8e-12); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_sigmaO_to_barFuFu(&m, 2, 2), 2.2644027655336339e-05, 8e-12); } From 9289e3a9187f1164ca151ce3cc92ef596b1309f3 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 17 Mar 2022 15:00:56 +0100 Subject: [PATCH 110/477] reduced precision of MRSSM2 FlexibleDecay tests --- test/test_MRSSM2_FlexibleDecay.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_MRSSM2_FlexibleDecay.cpp b/test/test_MRSSM2_FlexibleDecay.cpp index 91888136de..8516d6d185 100644 --- a/test/test_MRSSM2_FlexibleDecay.cpp +++ b/test/test_MRSSM2_FlexibleDecay.cpp @@ -726,7 +726,7 @@ Block FlexibleSUSYLowEnergy Q= 1.00000000E+03 // with 2-loop QCD corrections to squark loop BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 0), 1.1323516448739387e-05, 4e-11); // h -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 0), 7.8803489809960472e-06, 5e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 0), 7.8803489809960472e-06, 7e-11); BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00029585461520717076, 2e-13); @@ -759,7 +759,7 @@ Block FlexibleSUSYLowEnergy Q= 1.00000000E+03 // h -> gluon gluon BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VGVG(&m, 0), 0.00013277226722491827, 7e-11); // h -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVZ(&m, 0), 7.8803489809960472e-06, 5e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVZ(&m, 0), 7.8803489809960472e-06, 7e-11); // scalar sgluon BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_phiO_to_VGVG(&m), 0.057227805663593985, 3e-11); From 2307a0e4b97411bdb3cc9dec5058bcf469c813ae Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Fri, 18 Mar 2022 21:22:51 +0100 Subject: [PATCH 111/477] make FlexibleDecay tests read the entire SLHA output (#413) The tests in the THDMII, MSSM, MSSMCPV and MRSSM2, even though they contained an entire SLHA outputs as strings, only used the input values and internally recalculated the spectra again. This made them fragile and dependent on any changes to how spectra are computed. --- test/test_MRSSM2_FlexibleDecay.cpp | 714 ++++++++++++++-------------- test/test_MSSMCPV_FlexibleDecay.cpp | 393 ++++++++------- test/test_MSSM_FlexibleDecay.cpp | 531 +++++++++++---------- test/test_THDMII_FlexibleDecay.cpp | 49 +- 4 files changed, 871 insertions(+), 816 deletions(-) diff --git a/test/test_MRSSM2_FlexibleDecay.cpp b/test/test_MRSSM2_FlexibleDecay.cpp index 8516d6d185..619a7289cf 100644 --- a/test/test_MRSSM2_FlexibleDecay.cpp +++ b/test/test_MRSSM2_FlexibleDecay.cpp @@ -12,18 +12,15 @@ using namespace flexiblesusy; -/* BMP3 of arXiv:1410.4791 - considered in Adam Buchner's thesis */ - BOOST_AUTO_TEST_CASE( test_MRSSM2_FlexibleDecay ) { char const * const slha_input = R"( Block SPINFO 1 FlexibleSUSY - 2 2.4.1 + 2 2.6.1 5 MRSSM2 - 9 4.13.0 + 9 4.14.5 Block MODSEL # Select model 6 1 # flavour violation # 12 1000 # DRbar parameter output scale (GeV) @@ -43,7 +40,7 @@ Block FlexibleSUSY 12 0 # force output 13 1 # Top pole mass QCD corrections (0 = 1L, 1 = 2L, 2 = 3L) 14 1.000000000e-11 # beta-function zero threshold - 15 0 # calculate observables (a_muon, ...) + 15 1 # calculate observables (a_muon, ...) 16 0 # force positive majorana masses 17 0 # pole mass renormalization scale (0 = SUSY scale) 18 0 # pole mass renormalization scale in the EFT (0 = min(SUSY scale, Mt)) @@ -93,6 +90,12 @@ Block VCKMIN # CKM matrix input (Wolfenstein parameters) # 4 0.000000000e+00 # delta # 5 0.000000000e+00 # alpha_1 # 6 0.000000000e+00 # alpha_2 +Block FlexibleDecay + 0 1 # calculate decays (0 = no, 1 = yes) + 1 1e-5 # minimum BR to print + 2 4 # include higher order corrections in decays (0 = LO, 1 = NLO, 2 = NNLO, 3 = N^3LO, 4 = N^4LO ) + 3 1 # use Thomson alpha(0) instead of alpha(m) in decays to γγ and γZ + 4 2 # off-shell decays into VV pair Block MINPAR 3 4.00000000E+01 # TanBeta Block EXTPAR @@ -166,253 +169,253 @@ Block MSU2IN 3 2 0.00000000E+00 # mu2Input(3,2) 3 3 1.00000000E+06 # mu2Input(3,3) Block gauge Q= 1.00000000E+03 - 1 3.62120030E-01 # g1 * 0.7745966692414834 - 2 6.43012598E-01 # g2 - 3 1.05807099E+00 # g3 + 1 3.62350606E-01 # g1 * 0.7745966692414834 + 2 6.42118963E-01 # g2 + 3 1.06215840E+00 # g3 Block Yu Q= 1.00000000E+03 - 1 1 7.33065972E-06 # Yu(1,1) + 1 1 7.32341299E-06 # Yu(1,1) 1 2 0.00000000E+00 # Yu(1,2) 1 3 0.00000000E+00 # Yu(1,3) 2 1 0.00000000E+00 # Yu(2,1) - 2 2 3.33720117E-03 # Yu(2,2) + 2 2 3.33390202E-03 # Yu(2,2) 2 3 0.00000000E+00 # Yu(2,3) 3 1 0.00000000E+00 # Yu(3,1) 3 2 0.00000000E+00 # Yu(3,2) - 3 3 8.89862945E-01 # Yu(3,3) + 3 3 8.83286581E-01 # Yu(3,3) Block Yd Q= 1.00000000E+03 - 1 1 5.69356767E-04 # Yd(1,1) + 1 1 5.69014312E-04 # Yd(1,1) 1 2 0.00000000E+00 # Yd(1,2) 1 3 0.00000000E+00 # Yd(1,3) 2 1 0.00000000E+00 # Yd(2,1) - 2 2 1.24662505E-02 # Yd(2,2) + 2 2 1.24587493E-02 # Yd(2,2) 2 3 0.00000000E+00 # Yd(2,3) 3 1 0.00000000E+00 # Yd(3,1) 3 2 0.00000000E+00 # Yd(3,2) - 3 3 5.63512800E-01 # Yd(3,3) + 3 3 5.61642799E-01 # Yd(3,3) Block Ye Q= 1.00000000E+03 - 1 1 1.15181876E-04 # Ye(1,1) + 1 1 1.15519032E-04 # Ye(1,1) 1 2 0.00000000E+00 # Ye(1,2) 1 3 0.00000000E+00 # Ye(1,3) 2 1 0.00000000E+00 # Ye(2,1) - 2 2 2.38159700E-02 # Ye(2,2) + 2 2 2.38856226E-02 # Ye(2,2) 2 3 0.00000000E+00 # Ye(2,3) 3 1 0.00000000E+00 # Ye(3,1) 3 2 0.00000000E+00 # Ye(3,2) - 3 3 4.00639040E-01 # Ye(3,3) + 3 3 4.01531161E-01 # Ye(3,3) Block HMIX Q= 1.00000000E+03 1 0.00000000E+00 # Mu - 101 3.99999831E+04 # BMu - 102 6.17997917E+00 # vd - 103 2.41067730E+02 # vu - 310 -3.44417030E-01 # vT - 201 4.00000047E+02 # MuD - 202 3.99999778E+02 # MuU + 101 3.99999974E+04 # BMu + 102 6.17979538E+00 # vd + 103 2.41154149E+02 # vu + 310 -3.57900109E-01 # vT + 201 4.00000090E+02 # MuD + 202 3.99999878E+02 # MuU 203 0.00000000E+00 # BMuD 204 0.00000000E+00 # BMuU - 301 1.50000018E-01 # LamSD - 302 -1.49999917E-01 # LamSU - 303 -1.00000010E+00 # LamTD - 304 -1.14999934E+00 # LamTU + 301 1.50000034E-01 # LamSD + 302 -1.49999954E-01 # LamSU + 303 -1.00000021E+00 # LamTD + 304 -1.14999963E+00 # LamTU Block MSQ2 Q= 1.00000000E+03 - 1 1 6.25000008E+06 # mq2(1,1) - 1 2 6.46548635E-04 # mq2(1,2) - 1 3 -1.59044113E-02 # mq2(1,3) - 2 1 6.46548635E-04 # mq2(2,1) - 2 2 6.25000007E+06 # mq2(2,2) - 2 3 8.85814761E-02 # mq2(2,3) - 3 1 -1.59044113E-02 # mq2(3,1) - 3 2 8.85814761E-02 # mq2(3,2) - 3 3 9.99999938E+05 # mq2(3,3) + 1 1 4.00000005E+06 # mq2(1,1) + 1 2 2.16076037E-04 # mq2(1,2) + 1 3 -5.26363540E-03 # mq2(1,3) + 2 1 2.16076037E-04 # mq2(2,1) + 2 2 4.00000005E+06 # mq2(2,2) + 2 3 2.92912673E-02 # mq2(2,3) + 3 1 -5.26363540E-03 # mq2(3,1) + 3 2 2.92912673E-02 # mq2(3,2) + 3 3 4.00000021E+06 # mq2(3,3) Block MSE2 Q= 1.00000000E+03 - 1 1 9.99999996E+05 # me2(1,1) + 1 1 9.99999999E+05 # me2(1,1) 1 2 0.00000000E+00 # me2(1,2) 1 3 0.00000000E+00 # me2(1,3) 2 1 0.00000000E+00 # me2(2,1) - 2 2 9.99999995E+05 # me2(2,2) + 2 2 9.99999998E+05 # me2(2,2) 2 3 0.00000000E+00 # me2(2,3) 3 1 0.00000000E+00 # me2(3,1) 3 2 0.00000000E+00 # me2(3,2) - 3 3 9.99999790E+05 # me2(3,3) + 3 3 9.99999888E+05 # me2(3,3) Block MSL2 Q= 1.00000000E+03 - 1 1 1.00000001E+06 # ml2(1,1) + 1 1 4.00000001E+06 # ml2(1,1) 1 2 0.00000000E+00 # ml2(1,2) 1 3 0.00000000E+00 # ml2(1,3) 2 1 0.00000000E+00 # ml2(2,1) - 2 2 1.00000001E+06 # ml2(2,2) + 2 2 4.00000001E+06 # ml2(2,2) 2 3 0.00000000E+00 # ml2(2,3) 3 1 0.00000000E+00 # ml2(3,1) 3 2 0.00000000E+00 # ml2(3,2) - 3 3 9.99999903E+05 # ml2(3,3) + 3 3 3.99999995E+06 # ml2(3,3) Block MSU2 Q= 1.00000000E+03 - 1 1 6.25000008E+06 # mu2(1,1) - 1 2 5.96176233E-12 # mu2(1,2) - 1 3 6.08888029E-08 # mu2(1,3) - 2 1 5.96176927E-12 # mu2(2,1) - 2 2 6.25000008E+06 # mu2(2,2) - 2 3 5.38336802E-04 # mu2(2,3) - 3 1 6.08888029E-08 # mu2(3,1) - 3 2 5.38336802E-04 # mu2(3,2) - 3 3 9.99999268E+05 # mu2(3,3) + 1 1 1.00000004E+06 # mu2(1,1) + 1 2 8.13498574E-14 # mu2(1,2) + 1 3 6.90953136E-10 # mu2(1,3) + 2 1 8.13481227E-14 # mu2(2,1) + 2 2 1.00000004E+06 # mu2(2,2) + 2 3 6.11378928E-06 # mu2(2,3) + 3 1 6.90953133E-10 # mu2(3,1) + 3 2 6.11378928E-06 # mu2(3,2) + 3 3 9.99998614E+05 # mu2(3,3) Block MSD2 Q= 1.00000000E+03 - 1 1 6.25000007E+06 # md2(1,1) - 1 2 -7.86388732E-11 # md2(1,2) - 1 3 -2.11796663E-05 # md2(1,3) - 2 1 -7.86388732E-11 # md2(2,1) - 2 2 6.25000007E+06 # md2(2,2) - 2 3 2.58275994E-03 # md2(2,3) - 3 1 -2.11796663E-05 # md2(3,1) - 3 2 2.58275994E-03 # md2(3,2) - 3 3 1.00000059E+06 # md2(3,3) + 1 1 1.00000004E+06 # md2(1,1) + 1 2 4.71937489E-11 # md2(1,2) + 1 3 -4.08043448E-07 # md2(1,3) + 2 1 4.71937489E-11 # md2(2,1) + 2 2 1.00000004E+06 # md2(2,2) + 2 3 4.97361335E-05 # md2(2,3) + 3 1 -4.08043448E-07 # md2(3,1) + 3 2 4.97361335E-05 # md2(3,2) + 3 3 1.00000177E+06 # md2(3,3) Block MSOFT Q= 1.00000000E+03 - 21 1.30202577E+06 # mHd2 - 22 -2.95541171E+05 # mHu2 - 110 8.99999992E+06 # mT2 - 111 1.00000017E+06 # moc2 - 300 2.50000001E+02 # MDBS - 301 5.00000000E+02 # MDWBT + 21 1.28465220E+06 # mHd2 + 22 -3.33824153E+05 # mHu2 + 110 8.99999999E+06 # mT2 + 111 1.00000010E+06 # moc2 + 300 2.50000000E+02 # MDBS + 301 5.00000001E+02 # MDWBT 302 9.99999929E+02 # MDGoc - 50 4.90000039E+05 # mRd2 - 51 9.99999833E+05 # mRu2 + 50 4.90000092E+05 # mRd2 + 51 9.99999885E+05 # mRu2 Block NMSSMRUN Q= 1.00000000E+03 10 4.00000000E+06 # mS2 - 5 -6.31078301E-02 # vS + 5 -6.58611175E-02 # vS Block MASS - 24 8.04935130E+01 # VWm - 404 8.91170992E+02 # SRdp - 403 1.17375227E+03 # SRum - 1000021 1.16847311E+03 # Glu - 3000022 1.15761125E+03 # sigmaO - 3000021 2.32557770E+03 # phiO - 2000024 4.23953307E+02 # Cha2(1) - 2000037 5.64621108E+02 # Cha2(2) - 1000024 4.08278270E+02 # Cha1(1) - 1000037 5.25549522E+02 # Cha1(2) - 401 8.95570270E+02 # Rh(1) - 402 1.16211833E+03 # Rh(2) - 1000012 9.99942682E+02 # Sv(1) - 1000014 1.00175553E+03 # Sv(2) - 1000016 1.00176197E+03 # Sv(3) - 1000022 2.51353830E+02 # Chi(1) - 1000023 4.08048927E+02 # Chi(2) - 1000025 4.20363857E+02 # Chi(3) - 1000035 5.45509248E+02 # Chi(4) - 37 1.23200002E+03 # Hpm(2) - 47 3.01680652E+03 # Hpm(3) - 57 3.17924784E+03 # Hpm(4) - 25 1.24775982E+02 # hh(1) - 35 1.22898763E+03 # hh(2) - 45 2.06068208E+03 # hh(3) - 55 3.17898558E+03 # hh(4) - 36 1.22897644E+03 # Ah(2) - 46 1.99954600E+03 # Ah(3) - 56 3.01660750E+03 # Ah(4) - 1000001 1.05165217E+03 # Sd(1) - 1000003 1.05404121E+03 # Sd(2) - 1000005 2.53612871E+03 # Sd(3) - 2000001 2.53613011E+03 # Sd(4) - 2000003 2.54251640E+03 # Sd(5) - 2000005 2.54252062E+03 # Sd(6) - 1000011 9.98655341E+02 # Se(1) - 1000013 1.00224777E+03 # Se(2) - 1000015 1.00226050E+03 # Se(3) - 2000011 1.00349567E+03 # Se(4) - 2000013 1.00531846E+03 # Se(5) - 2000015 1.00532492E+03 # Se(6) - 1000002 1.05710992E+03 # Su(1) - 1000004 1.06420319E+03 # Su(2) - 1000006 2.53648695E+03 # Su(3) - 2000002 2.53648715E+03 # Su(4) - 2000004 2.54139480E+03 # Su(5) - 2000006 2.54139875E+03 # Su(6) + 24 8.03946575E+01 # VWm + 404 8.91726546E+02 # SRdp + 403 1.17471104E+03 # SRum + 1000021 1.15530397E+03 # Glu + 3000022 1.15881785E+03 # sigmaO + 3000021 2.29249134E+03 # phiO + 2000024 4.25299413E+02 # Cha2(1) + 2000037 5.66773575E+02 # Cha2(2) + 1000024 4.09265442E+02 # Cha1(1) + 1000037 5.27489928E+02 # Cha1(2) + 401 8.95815263E+02 # Rh(1) + 402 1.16262647E+03 # Rh(2) + 1000012 2.00175391E+03 # Sv(1) + 1000014 2.00297474E+03 # Sv(2) + 1000016 2.00297908E+03 # Sv(3) + 1000022 2.50941894E+02 # Chi(1) + 1000023 4.09056207E+02 # Chi(2) + 1000025 4.22075658E+02 # Chi(3) + 1000035 5.47585018E+02 # Chi(4) + 37 1.23229115E+03 # Hpm(2) + 47 3.01676952E+03 # Hpm(3) + 57 3.17984669E+03 # Hpm(4) + 25 1.27060566E+02 # hh(1) + 35 1.22926626E+03 # hh(2) + 45 2.06032688E+03 # hh(3) + 55 3.17958470E+03 # hh(4) + 36 1.22925494E+03 # Ah(2) + 46 1.99954615E+03 # Ah(3) + 56 3.01657098E+03 # Ah(4) + 1000001 1.05730617E+03 # Sd(1) + 1000003 1.05919387E+03 # Sd(2) + 1000005 1.05919484E+03 # Sd(3) + 2000001 2.03399075E+03 # Sd(4) + 2000003 2.04190092E+03 # Sd(5) + 2000005 2.04190519E+03 # Sd(6) + 1000011 1.00136991E+03 # Se(1) + 1000013 1.00226372E+03 # Se(2) + 1000015 1.00226689E+03 # Se(3) + 2000011 2.00369715E+03 # Se(4) + 2000013 2.00492394E+03 # Se(5) + 2000015 2.00492830E+03 # Se(6) + 1000002 1.05839522E+03 # Su(1) + 1000004 1.05839538E+03 # Su(2) + 1000006 1.07014623E+03 # Su(3) + 2000002 2.03841573E+03 # Su(4) + 2000004 2.04048569E+03 # Su(5) + 2000006 2.04048811E+03 # Su(6) 21 0.00000000E+00 # VG 12 0.00000000E+00 # Fv(1) 14 0.00000000E+00 # Fv(2) 16 0.00000000E+00 # Fv(3) - 11 5.29033878E-04 # Fe(1) - 13 1.07278707E-01 # Fe(2) - 15 1.78529243E+00 # Fe(3) - 1 4.43123064E-03 # Fd(1) - 3 8.77332488E-02 # Fd(2) - 5 3.45634038E+00 # Fd(3) - 2 2.29355408E-03 # Fu(1) - 4 8.47491831E-01 # Fu(2) - 6 1.77434227E+02 # Fu(3) + 11 5.29111495E-04 # Fe(1) + 13 1.07287537E-01 # Fe(2) + 15 1.78530042E+00 # Fe(3) + 1 4.42593001E-03 # Fd(1) + 3 8.75538751E-02 # Fd(2) + 5 3.45866793E+00 # Fd(3) + 2 2.29131381E-03 # Fu(1) + 4 8.45162005E-01 # Fu(2) + 6 1.77307012E+02 # Fu(3) 22 0.00000000E+00 # VP - 23 9.11601029E+01 # VZ + 23 9.11536697E+01 # VZ Block U1MIX - 1 1 2.75021091E-03 # Re(UM1(1,1)) - 1 2 9.99996218E-01 # Re(UM1(1,2)) - 2 1 9.99996218E-01 # Re(UM1(2,1)) - 2 2 -2.75021091E-03 # Re(UM1(2,2)) + 1 1 2.74744790E-03 # Re(UM1(1,1)) + 1 2 9.99996226E-01 # Re(UM1(1,2)) + 2 1 9.99996226E-01 # Re(UM1(2,1)) + 2 2 -2.74744790E-03 # Re(UM1(2,2)) Block U2MIX - 1 1 4.64965885E-01 # Re(UM2(1,1)) - 1 2 -8.85328598E-01 # Re(UM2(1,2)) - 2 1 8.85328598E-01 # Re(UM2(2,1)) - 2 2 4.64965885E-01 # Re(UM2(2,2)) + 1 1 4.68016439E-01 # Re(UM2(1,1)) + 1 2 -8.83719759E-01 # Re(UM2(1,2)) + 2 1 8.83719759E-01 # Re(UM2(2,1)) + 2 2 4.68016439E-01 # Re(UM2(2,2)) Block V1MIX - 1 1 1.08747242E-02 # Re(UP1(1,1)) - 1 2 9.99940868E-01 # Re(UP1(1,2)) - 2 1 9.99940868E-01 # Re(UP1(2,1)) - 2 2 -1.08747242E-02 # Re(UP1(2,2)) + 1 1 1.09030525E-02 # Re(UP1(1,1)) + 1 2 9.99940560E-01 # Re(UP1(1,2)) + 2 1 9.99940560E-01 # Re(UP1(2,1)) + 2 2 -1.09030525E-02 # Re(UP1(2,2)) Block V2MIX - 1 1 1.66010343E-01 # Re(UP2(1,1)) - 1 2 9.86124011E-01 # Re(UP2(1,2)) - 2 1 9.86124011E-01 # Re(UP2(2,1)) - 2 2 -1.66010343E-01 # Re(UP2(2,2)) + 1 1 1.71904445E-01 # Re(UP2(1,1)) + 1 2 9.85113629E-01 # Re(UP2(1,2)) + 2 1 9.85113629E-01 # Re(UP2(2,1)) + 2 2 -1.71904445E-01 # Re(UP2(2,2)) Block PSEUDOSCALARMIX - 1 1 -2.50525910E-02 # ZA(1,1) - 1 2 9.99686126E-01 # ZA(1,2) - 1 3 -6.90965974E-05 # ZA(1,3) - 1 4 1.11592680E-04 # ZA(1,4) - 2 1 9.99686135E-01 # ZA(2,1) - 2 2 2.50525911E-02 # ZA(2,2) - 2 3 -1.04941819E-06 # ZA(2,3) - 2 4 1.12201699E-06 # ZA(2,4) - 3 1 6.80730364E-07 # ZA(3,1) - 3 2 -6.90192312E-05 # ZA(3,2) + 1 1 -2.50514967E-02 # ZA(1,1) + 1 2 9.99686153E-01 # ZA(1,2) + 1 3 -6.92103957E-05 # ZA(1,3) + 1 4 1.11524894E-04 # ZA(1,4) + 2 1 9.99686162E-01 # ZA(2,1) + 2 2 2.50514967E-02 # ZA(2,2) + 2 3 -1.05059746E-06 # ZA(2,3) + 2 4 1.12046293E-06 # ZA(2,4) + 3 1 6.82326059E-07 # ZA(3,1) + 3 2 -6.91330221E-05 # ZA(3,2) 3 3 -9.99999728E-01 # ZA(3,3) - 3 4 -7.34427429E-04 # ZA(3,4) - 4 1 1.67452135E-06 # ZA(4,1) - 4 2 -1.11636483E-04 # ZA(4,2) - 4 3 -7.34419720E-04 # ZA(4,3) + 3 4 -7.34890714E-04 # ZA(3,4) + 4 1 1.67425612E-06 # ZA(4,1) + 4 2 -1.11568798E-04 # ZA(4,2) + 4 3 -7.34882997E-04 # ZA(4,3) 4 4 9.99999724E-01 # ZA(4,4) Block DSQMIX - 1 1 0.00000000E+00 # ZD(1,1) - 1 2 0.00000000E+00 # ZD(1,2) - 1 3 0.00000000E+00 # ZD(1,3) - 1 4 1.75745044E-07 # ZD(1,4) - 1 5 -2.14231084E-05 # ZD(1,5) - 1 6 1.00000000E+00 # ZD(1,6) - 2 1 1.06097390E-04 # ZD(2,1) - 2 2 -5.90875452E-04 # ZD(2,2) - 2 3 9.99999820E-01 # ZD(2,3) - 2 4 0.00000000E+00 # ZD(2,4) - 2 5 0.00000000E+00 # ZD(2,5) - 2 6 0.00000000E+00 # ZD(2,6) - 3 1 -1.97712110E-01 # ZD(3,1) - 3 2 9.80259946E-01 # ZD(3,2) - 3 3 6.00188385E-04 # ZD(3,3) - 3 4 0.00000000E+00 # ZD(3,4) - 3 5 0.00000000E+00 # ZD(3,5) - 3 6 0.00000000E+00 # ZD(3,6) - 4 1 -9.80260124E-01 # ZD(4,1) - 4 2 -1.97712138E-01 # ZD(4,2) - 4 3 -1.28202108E-05 # ZD(4,3) - 4 4 -0.00000000E+00 # ZD(4,4) - 4 5 -0.00000000E+00 # ZD(4,5) - 4 6 -0.00000000E+00 # ZD(4,6) - 5 1 -0.00000000E+00 # ZD(5,1) - 5 2 -0.00000000E+00 # ZD(5,2) - 5 3 -0.00000000E+00 # ZD(5,3) - 5 4 -1.00000000E+00 # ZD(5,4) - 5 5 -5.78329000E-07 # ZD(5,5) - 5 6 1.75732655E-07 # ZD(5,6) - 6 1 0.00000000E+00 # ZD(6,1) - 6 2 0.00000000E+00 # ZD(6,2) - 6 3 0.00000000E+00 # ZD(6,3) - 6 4 5.78325235E-07 # ZD(6,4) - 6 5 -1.00000000E+00 # ZD(6,5) - 6 6 -2.14231085E-05 # ZD(6,6) + 1 1 -0.00000000E+00 # ZD(1,1) + 1 2 -0.00000000E+00 # ZD(1,2) + 1 3 -0.00000000E+00 # ZD(1,3) + 1 4 1.48140447E-07 # ZD(1,4) + 1 5 -1.80584972E-05 # ZD(1,5) + 1 6 -1.00000000E+00 # ZD(1,6) + 2 1 0.00000000E+00 # ZD(2,1) + 2 2 0.00000000E+00 # ZD(2,2) + 2 3 0.00000000E+00 # ZD(2,3) + 2 4 -2.77307016E-07 # ZD(2,4) + 2 5 -1.00000000E+00 # ZD(2,5) + 2 6 1.80584971E-05 # ZD(2,6) + 3 1 0.00000000E+00 # ZD(3,1) + 3 2 0.00000000E+00 # ZD(3,2) + 3 3 0.00000000E+00 # ZD(3,3) + 3 4 1.00000000E+00 # ZD(3,4) + 3 5 -2.77304341E-07 # ZD(3,5) + 3 6 1.48145455E-07 # ZD(3,6) + 4 1 4.88721699E-03 # ZD(4,1) + 4 2 -2.72006501E-02 # ZD(4,2) + 4 3 9.99618047E-01 # ZD(4,3) + 4 4 0.00000000E+00 # ZD(4,4) + 4 5 0.00000000E+00 # ZD(4,5) + 4 6 0.00000000E+00 # ZD(4,6) + 5 1 -1.25596414E-01 # ZD(5,1) + 5 2 9.91697447E-01 # ZD(5,2) + 5 3 2.75991738E-02 # ZD(5,3) + 5 4 0.00000000E+00 # ZD(5,4) + 5 5 0.00000000E+00 # ZD(5,5) + 5 6 0.00000000E+00 # ZD(5,6) + 6 1 -9.92069381E-01 # ZD(6,1) + 6 2 -1.25683326E-01 # ZD(6,2) + 6 3 1.43033649E-03 # ZD(6,3) + 6 4 -0.00000000E+00 # ZD(6,4) + 6 5 -0.00000000E+00 # ZD(6,5) + 6 6 -0.00000000E+00 # ZD(6,6) Block SELMIX 1 1 0.00000000E+00 # ZE(1,1) 1 2 0.00000000E+00 # ZE(1,2) @@ -451,115 +454,115 @@ Block SELMIX 6 5 0.00000000E+00 # ZE(6,5) 6 6 0.00000000E+00 # ZE(6,6) Block SCALARMIX - 1 1 -2.60150592E-02 # ZH(1,1) - 1 2 -9.99657406E-01 # ZH(1,2) - 1 3 1.56979855E-04 # ZH(1,3) - 1 4 2.87442402E-03 # ZH(1,4) - 2 1 9.99661549E-01 # ZH(2,1) - 2 2 -2.60147782E-02 # ZH(2,2) - 2 3 1.66647476E-05 # ZH(2,3) - 2 4 1.34305770E-04 # ZH(2,4) - 3 1 1.26120035E-05 # ZH(3,1) - 3 2 -1.59136493E-04 # ZH(3,2) - 3 3 -9.99999797E-01 # ZH(3,3) - 3 4 -6.17184141E-04 # ZH(3,4) - 4 1 5.94744765E-05 # ZH(4,1) - 4 2 -2.87684744E-03 # ZH(4,2) - 4 3 6.17640155E-04 # ZH(4,3) - 4 4 -9.99995669E-01 # ZH(4,4) + 1 1 -2.60123622E-02 # ZH(1,1) + 1 2 -9.99657149E-01 # ZH(1,2) + 1 3 1.78509883E-04 # ZH(1,3) + 1 4 2.98483135E-03 # ZH(1,4) + 2 1 9.99661619E-01 # ZH(2,1) + 2 2 -2.60120618E-02 # ZH(2,2) + 2 3 1.67182039E-05 # ZH(2,3) + 2 4 1.38556929E-04 # ZH(2,4) + 3 1 1.21066976E-05 # ZH(3,1) + 3 2 -1.80729770E-04 # ZH(3,2) + 3 3 -9.99999793E-01 # ZH(3,3) + 3 4 -6.17467555E-04 # ZH(3,4) + 4 1 6.08603375E-05 # ZH(4,1) + 4 2 -2.98731446E-03 # ZH(4,2) + 4 3 6.18005442E-04 # ZH(4,3) + 4 4 -9.99995345E-01 # ZH(4,4) Block RHMIX - 1 1 -9.99999638E-01 # ZHR(1,1) - 1 2 8.50495379E-04 # ZHR(1,2) - 2 1 -8.50495379E-04 # ZHR(2,1) - 2 2 -9.99999638E-01 # ZHR(2,2) + 1 1 -9.99999639E-01 # ZHR(1,1) + 1 2 8.49807450E-04 # ZHR(1,2) + 2 1 -8.49807450E-04 # ZHR(2,1) + 2 2 -9.99999639E-01 # ZHR(2,2) Block N1MIX - 1 1 9.93910506E-01 # Re(ZN1(1,1)) - 1 2 3.53299104E-02 # Re(ZN1(1,2)) - 1 3 -2.67585189E-03 # Re(ZN1(1,3)) - 1 4 -1.04338600E-01 # Re(ZN1(1,4)) - 2 1 -8.11104643E-04 # Re(ZN1(2,1)) - 2 2 7.75211685E-04 # Re(ZN1(2,2)) - 2 3 -9.99834143E-01 # Re(ZN1(2,3)) - 2 4 1.81776526E-02 # Re(ZN1(2,4)) - 3 1 1.10102244E-01 # Re(ZN1(3,1)) - 3 2 -3.55647997E-01 # Re(ZN1(3,2)) - 3 3 1.65059610E-02 # Re(ZN1(3,3)) - 3 4 9.27965275E-01 # Re(ZN1(3,4)) - 4 1 4.32945548E-03 # Re(ZN1(4,1)) - 4 2 9.33951658E-01 # Re(ZN1(4,2)) - 4 3 7.21657556E-03 # Re(ZN1(4,3)) - 4 4 3.57300263E-01 # Re(ZN1(4,4)) + 1 1 9.93812659E-01 # Re(ZN1(1,1)) + 1 2 3.54137057E-02 # Re(ZN1(1,2)) + 1 3 -2.66214317E-03 # Re(ZN1(1,3)) + 1 4 -1.05238683E-01 # Re(ZN1(1,4)) + 2 1 -9.37734293E-04 # Re(ZN1(2,1)) + 2 2 1.22447426E-03 # Re(ZN1(2,2)) + 2 3 -9.99856852E-01 # Re(ZN1(2,3)) + 2 4 1.68492517E-02 # Re(ZN1(2,4)) + 3 1 1.10956357E-01 # Re(ZN1(3,1)) + 3 2 -3.58545649E-01 # Re(ZN1(3,2)) + 3 3 1.50744962E-02 # Re(ZN1(3,3)) + 3 4 9.26772067E-01 # Re(ZN1(3,4)) + 4 1 4.91990158E-03 # Re(ZN1(4,1)) + 4 2 9.32839422E-01 # Re(ZN1(4,2)) + 4 3 7.20753241E-03 # Re(ZN1(4,3)) + 4 4 3.60186699E-01 # Re(ZN1(4,4)) Block N2MIX - 1 1 9.99846857E-01 # Re(ZN2(1,1)) - 1 2 1.59398355E-02 # Re(ZN2(1,2)) - 1 3 1.94223332E-04 # Re(ZN2(1,3)) - 1 4 -7.22129694E-03 # Re(ZN2(1,4)) - 2 1 -5.47010467E-05 # Re(ZN2(2,1)) - 2 2 -5.30320738E-04 # Re(ZN2(2,2)) - 2 3 9.99835186E-01 # Re(ZN2(2,3)) - 2 4 1.81470763E-02 # Re(ZN2(2,4)) - 3 1 9.33126946E-03 # Re(ZN2(3,1)) - 3 2 -1.36389336E-01 # Re(ZN2(3,2)) - 3 3 -1.80485104E-02 # Re(ZN2(3,3)) - 3 4 9.90446933E-01 # Re(ZN2(3,4)) - 4 1 -1.48049865E-02 # Re(ZN2(4,1)) - 4 2 9.90526925E-01 # Re(ZN2(4,2)) - 4 3 -1.95298770E-03 # Re(ZN2(4,3)) - 4 4 1.36504245E-01 # Re(ZN2(4,4)) + 1 1 9.99845443E-01 # Re(ZN2(1,1)) + 1 2 1.58613853E-02 # Re(ZN2(1,2)) + 1 3 1.82055639E-04 # Re(ZN2(1,3)) + 1 4 -7.58118239E-03 # Re(ZN2(1,4)) + 2 1 -4.87682769E-05 # Re(ZN2(2,1)) + 2 2 -3.97310844E-04 # Re(ZN2(2,2)) + 2 3 9.99859667E-01 # Re(ZN2(2,3)) + 2 4 1.67477109E-02 # Re(ZN2(2,4)) + 3 1 9.74898766E-03 # Re(ZN2(3,1)) + 3 2 -1.41269095E-01 # Re(ZN2(3,2)) + 3 3 -1.66345939E-02 # Re(ZN2(3,3)) + 3 4 9.89783456E-01 # Re(ZN2(3,4)) + 4 1 -1.46303068E-02 # Re(ZN2(4,1)) + 4 2 9.89844079E-01 # Re(ZN2(4,2)) + 4 3 -1.97565115E-03 # Re(ZN2(4,3)) + 4 4 1.41388647E-01 # Re(ZN2(4,4)) Block CHARGEMIX - 1 1 2.51132077E-02 # ZP(1,1) - 1 2 -9.99681236E-01 # ZP(1,2) - 1 3 -1.91329206E-03 # ZP(1,3) - 1 4 -1.75875021E-03 # ZP(1,4) - 2 1 -9.99684612E-01 # ZP(2,1) - 2 2 -2.51129839E-02 # ZP(2,2) - 2 3 -8.47447660E-05 # ZP(2,3) - 2 4 -8.32594559E-05 # ZP(2,4) - 3 1 9.76024908E-07 # ZP(3,1) - 3 2 -1.44110284E-04 # ZP(3,2) - 3 3 7.16525947E-01 # ZP(3,3) - 3 4 -6.97560425E-01 # ZP(3,4) - 4 1 5.35704486E-05 # ZP(4,1) - 4 2 2.59699135E-03 # ZP(4,2) - 4 3 -6.97557811E-01 # ZP(4,3) - 4 4 -7.16523798E-01 # ZP(4,4) + 1 1 2.51125867E-02 # ZP(1,1) + 1 2 -9.99680917E-01 # ZP(1,2) + 1 3 -2.00213201E-03 # ZP(1,3) + 1 4 -1.84765551E-03 # ZP(1,4) + 2 1 -9.99684628E-01 # ZP(2,1) + 2 2 -2.51123438E-02 # ZP(2,2) + 2 3 -8.80116470E-05 # ZP(2,3) + 2 4 -8.65276923E-05 # ZP(2,4) + 3 1 9.56888105E-07 # ZP(3,1) + 3 2 -1.45712048E-04 # ZP(3,2) + 3 3 7.16516053E-01 # ZP(3,3) + 3 4 -6.97570588E-01 # ZP(3,4) + 4 1 5.50352333E-05 # ZP(4,1) + 4 2 2.72274398E-03 # ZP(4,2) + 4 3 -6.97567724E-01 # ZP(4,3) + 4 4 -7.16513680E-01 # ZP(4,4) Block USQMIX 1 1 0.00000000E+00 # ZU(1,1) 1 2 0.00000000E+00 # ZU(1,2) 1 3 0.00000000E+00 # ZU(1,3) - 1 4 3.91334119E-10 # ZU(1,4) - 1 5 3.46105492E-06 # ZU(1,5) - 1 6 1.00000000E+00 # ZU(1,6) - 2 1 6.88673900E-05 # ZU(2,1) - 2 2 -3.83703467E-04 # ZU(2,2) - 2 3 9.99999924E-01 # ZU(2,3) - 2 4 0.00000000E+00 # ZU(2,4) - 2 5 0.00000000E+00 # ZU(2,5) - 2 6 0.00000000E+00 # ZU(2,6) - 3 1 9.87267869E-01 # ZU(3,1) - 3 2 1.59066508E-01 # ZU(3,2) - 3 3 -6.95619121E-06 # ZU(3,3) - 3 4 -0.00000000E+00 # ZU(3,4) - 3 5 -0.00000000E+00 # ZU(3,5) - 3 6 -0.00000000E+00 # ZU(3,6) - 4 1 1.59066493E-01 # ZU(4,1) - 4 2 -9.87267795E-01 # ZU(4,2) - 4 3 -3.89772599E-04 # ZU(4,3) + 1 4 1.00000000E+00 # ZU(1,4) + 1 5 -4.41889299E-09 # ZU(1,5) + 1 6 -1.79858505E-10 # ZU(1,6) + 2 1 0.00000000E+00 # ZU(2,1) + 2 2 0.00000000E+00 # ZU(2,2) + 2 3 0.00000000E+00 # ZU(2,3) + 2 4 -4.41889270E-09 # ZU(2,4) + 2 5 -1.00000000E+00 # ZU(2,5) + 2 6 1.59127507E-06 # ZU(2,6) + 3 1 0.00000000E+00 # ZU(3,1) + 3 2 0.00000000E+00 # ZU(3,2) + 3 3 0.00000000E+00 # ZU(3,3) + 3 4 -1.79865536E-10 # ZU(3,4) + 3 5 -1.59127507E-06 # ZU(3,5) + 3 6 -1.00000000E+00 # ZU(3,6) + 4 1 -1.56974454E-01 # ZU(4,1) + 4 2 9.82832740E-01 # ZU(4,2) + 4 3 9.69475387E-02 # ZU(4,3) 4 4 0.00000000E+00 # ZU(4,4) 4 5 0.00000000E+00 # ZU(4,5) 4 6 0.00000000E+00 # ZU(4,6) - 5 1 0.00000000E+00 # ZU(5,1) - 5 2 0.00000000E+00 # ZU(5,2) - 5 3 0.00000000E+00 # ZU(5,3) - 5 4 -1.00000000E+00 # ZU(5,4) - 5 5 -1.95514893E-07 # ZU(5,5) - 5 6 3.92010806E-10 # ZU(5,6) - 6 1 0.00000000E+00 # ZU(6,1) - 6 2 0.00000000E+00 # ZU(6,2) - 6 3 0.00000000E+00 # ZU(6,3) - 6 4 1.95514895E-07 # ZU(6,4) - 6 5 -1.00000000E+00 # ZU(6,5) - 6 6 3.46105492E-06 # ZU(6,6) + 5 1 -9.87453546E-01 # ZU(5,1) + 5 2 -1.57898504E-01 # ZU(5,2) + 5 3 1.88595291E-03 # ZU(5,3) + 5 4 0.00000000E+00 # ZU(5,4) + 5 5 0.00000000E+00 # ZU(5,5) + 5 6 0.00000000E+00 # ZU(5,6) + 6 1 1.71614476E-02 # ZU(6,1) + 6 2 -9.54351444E-02 # ZU(6,2) + 6 3 9.95287706E-01 # ZU(6,3) + 6 4 0.00000000E+00 # ZU(6,4) + 6 5 0.00000000E+00 # ZU(6,5) + 6 6 0.00000000E+00 # ZU(6,6) Block SNUMIX 1 1 0.00000000E+00 # ZV(1,1) 1 2 0.00000000E+00 # ZV(1,2) @@ -591,55 +594,55 @@ Block UERMIX 3 2 0.00000000E+00 # Re(ZER(3,2)) 3 3 1.00000000E+00 # Re(ZER(3,3)) Block UDLMIX - 1 1 9.99999987E-01 # Re(ZDL(1,1)) - 1 2 6.30436594E-06 # Re(ZDL(1,2)) - 1 3 -1.59439405E-04 # Re(ZDL(1,3)) - 2 1 -6.16274368E-06 # Re(ZDL(2,1)) - 2 2 9.99999605E-01 # Re(ZDL(2,2)) - 2 3 8.88236153E-04 # Re(ZDL(2,3)) - 3 1 1.59444941E-04 # Re(ZDL(3,1)) - 3 2 -8.88235159E-04 # Re(ZDL(3,2)) - 3 3 9.99999593E-01 # Re(ZDL(3,3)) + 1 1 9.99999988E-01 # Re(ZDL(1,1)) + 1 2 6.22824967E-06 # Re(ZDL(1,2)) + 1 3 -1.57234209E-04 # Re(ZDL(1,3)) + 2 1 -6.09051785E-06 # Re(ZDL(2,1)) + 2 2 9.99999616E-01 # Re(ZDL(2,2)) + 2 3 8.75951247E-04 # Re(ZDL(2,3)) + 3 1 1.57239604E-04 # Re(ZDL(3,1)) + 3 2 -8.75950279E-04 # Re(ZDL(3,2)) + 3 3 9.99999604E-01 # Re(ZDL(3,3)) Block UDRMIX 1 1 1.00000000E+00 # Re(ZDR(1,1)) - 1 2 5.82600624E-07 # Re(ZDR(1,2)) - 1 3 -3.46055997E-07 # Re(ZDR(1,3)) - 2 1 -5.82586462E-07 # Re(ZDR(2,1)) + 1 2 5.75816956E-07 # Re(ZDR(1,2)) + 1 3 -3.41712787E-07 # Re(ZDR(1,3)) + 2 1 -5.75803149E-07 # Re(ZDR(2,1)) 2 2 9.99999999E-01 # Re(ZDR(2,2)) - 2 3 4.09220373E-05 # Re(ZDR(2,3)) - 3 1 3.46079838E-07 # Re(ZDR(3,1)) - 3 2 -4.09220371E-05 # Re(ZDR(3,2)) + 2 3 4.04034945E-05 # Re(ZDR(2,3)) + 3 1 3.41736052E-07 # Re(ZDR(3,1)) + 3 2 -4.04034943E-05 # Re(ZDR(3,2)) 3 3 9.99999999E-01 # Re(ZDR(3,3)) Block UULMIX - 1 1 9.73845815E-01 # Re(ZUL(1,1)) - 1 2 2.27200171E-01 # Re(ZUL(1,2)) - 1 3 2.10036017E-03 # Re(ZUL(1,3)) - 2 1 -2.27094969E-01 # Re(ZUL(2,1)) - 2 2 9.73017747E-01 # Re(ZUL(2,2)) - 2 3 4.07963018E-02 # Re(ZUL(2,3)) - 3 1 7.22523903E-03 # Re(ZUL(3,1)) - 3 2 -4.02062890E-02 # Re(ZUL(3,2)) - 3 3 9.99165277E-01 # Re(ZUL(3,3)) + 1 1 9.73845795E-01 # Re(ZUL(1,1)) + 1 2 2.27200301E-01 # Re(ZUL(1,2)) + 1 3 2.09546246E-03 # Re(ZUL(1,3)) + 2 1 -2.27095589E-01 # Re(ZUL(2,1)) + 2 2 9.73021583E-01 # Re(ZUL(2,2)) + 2 3 4.07012648E-02 # Re(ZUL(2,3)) + 3 1 7.20840943E-03 # Re(ZUL(3,1)) + 3 2 -4.01126259E-02 # Re(ZUL(3,2)) + 3 3 9.99169163E-01 # Re(ZUL(3,3)) Block UURMIX 1 1 1.00000000E+00 # Re(ZUR(1,1)) - 1 2 -1.11482059E-08 # Re(ZUR(1,2)) - 1 3 -1.26334348E-09 # Re(ZUR(1,3)) - 2 1 1.11481937E-08 # Re(ZUR(2,1)) + 1 2 -1.14917713E-08 # Re(ZUR(1,2)) + 1 3 -1.42990213E-09 # Re(ZUR(1,3)) + 2 1 1.14917555E-08 # Re(ZUR(2,1)) 2 2 1.00000000E+00 # Re(ZUR(2,2)) - 2 3 -9.71199909E-06 # Re(ZUR(2,3)) - 3 1 1.26345175E-09 # Re(ZUR(3,1)) - 3 2 9.71199909E-06 # Re(ZUR(3,2)) + 2 3 -1.10574958E-05 # Re(ZUR(2,3)) + 3 1 1.43002920E-09 # Re(ZUR(3,1)) + 3 2 1.10574958E-05 # Re(ZUR(3,2)) 3 3 1.00000000E+00 # Re(ZUR(3,3)) Block VCKM Q= 1.00000000E+03 - 1 1 9.73846600E-01 # Re(CKM)(1,1) - 1 2 2.27196452E-01 # Re(CKM)(1,2) - 1 3 2.13826417E-03 # Re(CKM)(1,3) - 2 1 -2.27087415E-01 # Re(CKM)(2,1) - 2 2 9.72988337E-01 # Re(CKM)(2,2) - 2 3 4.15331325E-02 # Re(CKM)(2,3) - 3 1 7.35567425E-03 # Re(CKM)(3,1) - 3 2 -4.09324727E-02 # Re(CKM)(3,2) - 3 3 9.99134839E-01 # Re(CKM)(3,3) + 1 1 9.73846592E-01 # Re(CKM)(1,1) + 1 2 2.27196483E-01 # Re(CKM)(1,2) + 1 3 2.13864228E-03 # Re(CKM)(1,3) + 2 1 -2.27087408E-01 # Re(CKM)(2,1) + 2 2 9.72988026E-01 # Re(CKM)(2,2) + 2 3 4.15404624E-02 # Re(CKM)(2,3) + 3 1 7.35697364E-03 # Re(CKM)(3,1) + 3 2 -4.09396965E-02 # Re(CKM)(3,2) + 3 3 9.99134534E-01 # Re(CKM)(3,3) Block IMVCKM Q= 1.00000000E+03 1 1 0.00000000E+00 # Im(CKM)(1,1) 1 2 0.00000000E+00 # Im(CKM)(1,2) @@ -650,12 +653,6 @@ Block IMVCKM Q= 1.00000000E+03 3 1 0.00000000E+00 # Im(CKM)(3,1) 3 2 0.00000000E+00 # Im(CKM)(3,2) 3 3 0.00000000E+00 # Im(CKM)(3,3) -Block FlexibleSUSYLowEnergy Q= 1.00000000E+03 - 21 0.00000000E+00 # Delta(g-2)_muon/2 FlexibleSUSY - 23 0.00000000E+00 # electric dipole moment of Fe(0) [1/GeV] - 24 0.00000000E+00 # electric dipole moment of Fe(1) [1/GeV] - 25 0.00000000E+00 # electric dipole moment of Fe(2) [1/GeV] - 26 0.00000000E+00 # BR(Fe1 -> Fe0 VP) )"; std::stringstream istr(slha_input); @@ -680,11 +677,10 @@ Block FlexibleSUSYLowEnergy Q= 1.00000000E+03 BOOST_TEST(false); } - MRSSM2_spectrum_generator spectrum_generator; - spectrum_generator.set_settings(settings); - spectrum_generator.run(qedqcd, input); - - MRSSM2_slha m = std::get<0>(spectrum_generator.get_models_slha()); + MRSSM2_slha m(input); + slha_io.fill(m); + m.calculate_DRbar_masses(); + m.reorder_DRbar_masses(); // ----------------------------------------------------- // decays with higher-order SM corrections @@ -695,16 +691,16 @@ Block FlexibleSUSYLowEnergy Q= 1.00000000E+03 // h -> b bbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFdFd(&m, 0, 2, 2), - 0.0025634108347145032, 5e-12); + 0.0025634108458618405, 5e-12); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFuFu(&m, 0, 1, 1), - 0.00012285838147242436, 2e-13); + 0.00012285838200009531, 2e-13); // QED corrections // BOOST_CHECK_CLOSE_FRACTION(decays.partial_width_hh_to_barFdFd(&m, 0, 2, 2), // 2.6059181498481999E-003, 5e-15); // h -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFeFe(&m, 0, 2, 2), - 0.00027545151828801864, 5e-12); + 0.0002754515192858279, 5e-12); // h -> W+ W- // BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_conjVWmVWm(&m, 0), // 0.00066154345019159267, 5e-11); @@ -719,21 +715,21 @@ Block FlexibleSUSYLowEnergy Q= 1.00000000E+03 // ------------ loop-induces decays ------------ // h -> gluon gluon - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VGVG(&m, 0), 0.00040230167812046075, 7e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VGVG(&m, 0), 0.00040230168141814043, 7e-11); // h -> gamma gamma // without 2-loop QCD corrections to squark loop // BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 0), 8.3519576334971031e-06, 4e-11); // with 2-loop QCD corrections to squark loop - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 0), 1.1323516448739387e-05, 4e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 0), 1.1323516625659973e-05, 4e-11); // h -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 0), 7.8803489809960472e-06, 7e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 0), 7.8803492070093454e-06, 5e-11); - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00029585461520717076, 2e-13); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00029585462066712443, 2e-13); BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFdFd(&m, 1, 2, 2), - 27.422426060823373, 5e-12); + 27.422426128468313, 5e-12); BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFuFu(&m, 1, 1, 1), - 6.535918222486397e-07, 2e-13); + 6.5359182777429661e-07, 2e-13); // ----------------------------------------------------- // decays without higher-order SM corrections @@ -743,29 +739,29 @@ Block FlexibleSUSYLowEnergy Q= 1.00000000E+03 // h -> b bbar BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFdFd(&m, 0, 2, 2), - 0.0016025829212124214, 2e-13); + 0.0016025829292552107, 2e-13); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFuFu(&m, 0, 1, 1), - 8.4238942917635169e-05, 2e-13); + 8.4238943320917841e-05, 2e-13); // h -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFeFe(&m, 0, 2, 2), - 0.00027252978259241349, 5e-12); + 0.00027252978357707359, 5e-12); // ------------ loop-induces decays ------------ // h -> gamma gamma - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVP(&m, 0), 1.1149675854277999e-05, 4e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVP(&m, 0), 1.1149676028035005e-05, 4e-11); // h -> gluon gluon - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VGVG(&m, 0), 0.00013277226722491827, 7e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VGVG(&m, 0), 0.00013277227074162971, 8e-11); // h -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVZ(&m, 0), 7.8803489809960472e-06, 7e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVZ(&m, 0), 7.8803492070093454e-06, 5e-11); // scalar sgluon - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_phiO_to_VGVG(&m), 0.057227805663593985, 3e-11); - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_phiO_to_barFuFu(&m, 2, 2), 2.3214926991726654e-05, 2e-12); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_phiO_to_VGVG(&m), 0.057227807158571162, 3e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_phiO_to_barFuFu(&m, 2, 2), 2.3251564031550308e-05, 2e-12); // pseudoscalar sgluon BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_sigmaO_to_VGVG(&m), 0, 1e-16); - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_sigmaO_to_barFuFu(&m, 2, 2), 2.2644027655336339e-05, 8e-12); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_sigmaO_to_barFuFu(&m, 2, 2), 2.2644028086115904e-05, 8e-12); } diff --git a/test/test_MSSMCPV_FlexibleDecay.cpp b/test/test_MSSMCPV_FlexibleDecay.cpp index f85de4d541..62e7af4516 100644 --- a/test/test_MSSMCPV_FlexibleDecay.cpp +++ b/test/test_MSSMCPV_FlexibleDecay.cpp @@ -17,9 +17,9 @@ BOOST_AUTO_TEST_CASE( test_MSSMCPV_FlexibleDecay ) char const * const slha_input = R"( Block SPINFO 1 FlexibleSUSY - 2 2.6.0 + 2 2.6.1 5 MSSMCPV - 9 4.14.3 + 9 4.14.5 Block MODSEL # Select model # 12 1000 # DRbar parameter output scale (GeV) Block FlexibleSUSY @@ -201,7 +201,7 @@ Block gauge Q= 2.00000000E+03 2 6.36432161E-01 # g2 3 1.02558883E+00 # g3 Block Yu Q= 2.00000000E+03 - 1 1 7.22296753E-06 # Yu(1,1) + 1 1 7.22296754E-06 # Yu(1,1) 1 2 0.00000000E+00 # Yu(1,2) 1 3 0.00000000E+00 # Yu(1,3) 2 1 0.00000000E+00 # Yu(2,1) @@ -261,7 +261,7 @@ Block IMYe Q= 2.00000000E+03 3 2 0.00000000E+00 # Im(Ye(3,2)) 3 3 0.00000000E+00 # Im(Ye(3,3)) Block Te Q= 2.00000000E+03 - 1 1 1.44626927E-01 # Re(TYe(1,1)) + 1 1 1.44626926E-01 # Re(TYe(1,1)) 1 2 0.00000000E+00 # Re(TYe(1,2)) 1 3 0.00000000E+00 # Re(TYe(1,3)) 2 1 0.00000000E+00 # Re(TYe(2,1)) @@ -271,15 +271,15 @@ Block Te Q= 2.00000000E+03 3 2 0.00000000E+00 # Re(TYe(3,2)) 3 3 5.02943166E+02 # Re(TYe(3,3)) Block IMTe Q= 2.00000000E+03 - 1 1 -1.28160489E-10 # Im(TYe(1,1)) + 1 1 -1.28097413E-10 # Im(TYe(1,1)) 1 2 0.00000000E+00 # Im(TYe(1,2)) 1 3 0.00000000E+00 # Im(TYe(1,3)) 2 1 0.00000000E+00 # Im(TYe(2,1)) - 2 2 -2.64973639E-08 # Im(TYe(2,2)) + 2 2 -2.64843217E-08 # Im(TYe(2,2)) 2 3 0.00000000E+00 # Im(TYe(2,3)) 3 1 0.00000000E+00 # Im(TYe(3,1)) 3 2 0.00000000E+00 # Im(TYe(3,2)) - 3 3 -4.35626607E-07 # Im(TYe(3,3)) + 3 3 -4.35407343E-07 # Im(TYe(3,3)) Block Td Q= 2.00000000E+03 1 1 6.87048270E-01 # Re(TYd(1,1)) 1 2 0.00000000E+00 # Re(TYd(1,2)) @@ -289,17 +289,17 @@ Block Td Q= 2.00000000E+03 2 3 0.00000000E+00 # Re(TYd(2,3)) 3 1 0.00000000E+00 # Re(TYd(3,1)) 3 2 0.00000000E+00 # Re(TYd(3,2)) - 3 3 6.78846562E+02 # Re(TYd(3,3)) + 3 3 6.78846561E+02 # Re(TYd(3,3)) Block IMTd Q= 2.00000000E+03 - 1 1 8.17085641E-09 # Im(TYd(1,1)) + 1 1 8.17236531E-09 # Im(TYd(1,1)) 1 2 0.00000000E+00 # Im(TYd(1,2)) 1 3 0.00000000E+00 # Im(TYd(1,3)) 2 1 0.00000000E+00 # Im(TYd(2,1)) - 2 2 1.78898783E-07 # Im(TYd(2,2)) + 2 2 1.78931820E-07 # Im(TYd(2,2)) 2 3 0.00000000E+00 # Im(TYd(2,3)) 3 1 0.00000000E+00 # Im(TYd(3,1)) 3 2 0.00000000E+00 # Im(TYd(3,2)) - 3 3 1.78391086E-05 # Im(TYd(3,3)) + 3 3 1.78404600E-05 # Im(TYd(3,3)) Block Tu Q= 2.00000000E+03 1 1 2.88919526E-03 # Re(TYu(1,1)) 1 2 0.00000000E+00 # Re(TYu(1,2)) @@ -311,15 +311,15 @@ Block Tu Q= 2.00000000E+03 3 2 0.00000000E+00 # Re(TYu(3,2)) 3 3 3.41688289E+02 # Re(TYu(3,3)) Block IMTu Q= 2.00000000E+03 - 1 1 8.45729492E-10 # Im(TYu(1,1)) + 1 1 8.45875713E-10 # Im(TYu(1,1)) 1 2 0.00000000E+00 # Im(TYu(1,2)) 1 3 0.00000000E+00 # Im(TYu(1,3)) 2 1 0.00000000E+00 # Im(TYu(2,1)) - 2 2 3.86744318E-07 # Im(TYu(2,2)) + 2 2 3.86811184E-07 # Im(TYu(2,2)) 2 3 0.00000000E+00 # Im(TYu(2,3)) 3 1 0.00000000E+00 # Im(TYu(3,1)) 3 2 0.00000000E+00 # Im(TYu(3,2)) - 3 3 1.82838625E-06 # Im(TYu(3,3)) + 3 3 1.84365506E-06 # Im(TYu(3,3)) Block MSQ2 Q= 2.00000000E+03 1 1 3.99999902E+06 # Re(mq2(1,1)) 1 2 0.00000000E+00 # Re(mq2(1,2)) @@ -391,7 +391,7 @@ Block MSU2 Q= 2.00000000E+03 3 2 0.00000000E+00 # Re(mu2(3,2)) 3 3 3.99999822E+06 # Re(mu2(3,3)) Block IMMSU2 Q= 2.00000000E+03 - 1 1 0.00000000E+00 # Im(mu2(1,1)) + 1 1 -7.27595761E-12 # Im(mu2(1,1)) 1 2 0.00000000E+00 # Im(mu2(1,2)) 1 3 0.00000000E+00 # Im(mu2(1,3)) 2 1 0.00000000E+00 # Im(mu2(2,1)) @@ -399,7 +399,7 @@ Block IMMSU2 Q= 2.00000000E+03 2 3 0.00000000E+00 # Im(mu2(2,3)) 3 1 0.00000000E+00 # Im(mu2(3,1)) 3 2 0.00000000E+00 # Im(mu2(3,2)) - 3 3 0.00000000E+00 # Im(mu2(3,3)) + 3 3 7.27595761E-12 # Im(mu2(3,3)) Block MSD2 Q= 2.00000000E+03 1 1 3.99999901E+06 # Re(md2(1,1)) 1 2 0.00000000E+00 # Re(md2(1,2)) @@ -458,121 +458,136 @@ Block MASS 2000002 2.08366996E+03 # Su(4) 2000004 2.08444844E+03 # Su(5) 2000006 2.09071039E+03 # Su(6) + 21 0.00000000E+00 # VG + 12 0.00000000E+00 # Fv(1) + 14 0.00000000E+00 # Fv(2) + 16 0.00000000E+00 # Fv(3) + 11 5.30033519E-04 # Fe(1) + 13 1.07458698E-01 # Fe(2) + 15 1.78826361E+00 # Fe(3) + 1 4.25777269E-03 # Fd(1) + 3 8.44043803E-02 # Fd(2) + 5 3.35408940E+00 # Fd(3) + 2 2.21823311E-03 # Fu(1) + 4 8.26552842E-01 # Fu(2) + 6 1.74023906E+02 # Fu(3) + 22 0.00000000E+00 # VP + 23 9.10363042E+01 # VZ Block UMIX 1 1 -6.74308528E-01 # Re(UM(1,1)) - 1 2 7.37548381E-01 # Re(UM(1,2)) + 1 2 7.37548380E-01 # Re(UM(1,2)) 2 1 7.38430942E-01 # Re(UM(2,1)) 2 2 6.73554514E-01 # Re(UM(2,2)) Block VMIX 1 1 -6.89511561E-01 # Re(UP(1,1)) 1 2 7.23719240E-01 # Re(UP(1,2)) - 2 1 7.23107866E-01 # Re(UP(2,1)) + 2 1 7.23107865E-01 # Re(UP(2,1)) 2 2 6.90094531E-01 # Re(UP(2,2)) Block DSQMIX 1 1 0.00000000E+00 # Re(ZD(1,1)) - 1 2 -1.02049981E-16 # Re(ZD(1,2)) - 1 3 -1.64836623E-03 # Re(ZD(1,3)) - 1 4 -1.50618287E-33 # Re(ZD(1,4)) - 1 5 -3.96738074E-15 # Re(ZD(1,5)) - 1 6 -8.16343871E-01 # Re(ZD(1,6)) + 1 2 4.05876750E-16 # Re(ZD(1,2)) + 1 3 2.25193872E-02 # Re(ZD(1,3)) + 1 4 4.52983839E-32 # Re(ZD(1,4)) + 1 5 1.60605380E-14 # Re(ZD(1,5)) + 1 6 -5.79521697E-01 # Re(ZD(1,6)) 2 1 0.00000000E+00 # Re(ZD(2,1)) - 2 2 3.97181164E-04 # Re(ZD(2,2)) - 2 3 5.67887989E-15 # Re(ZD(2,3)) - 2 4 -4.74338409E-20 # Re(ZD(2,4)) - 2 5 1.54110923E-01 # Re(ZD(2,5)) - 2 6 -6.20537550E-15 # Re(ZD(2,6)) - 3 1 -1.97836577E-05 # Re(ZD(3,1)) + 2 2 4.29985522E-04 # Re(ZD(2,2)) + 2 3 9.80325892E-17 # Re(ZD(2,3)) + 2 4 4.94933664E-20 # Re(ZD(2,4)) + 2 5 -3.67898261E-01 # Re(ZD(2,5)) + 2 6 1.32024654E-15 # Re(ZD(2,6)) + 3 1 1.97836576E-05 # Re(ZD(3,1)) 3 2 0.00000000E+00 # Re(ZD(3,2)) - 3 3 -3.54618571E-35 # Re(ZD(3,3)) - 3 4 2.52921286E-01 # Re(ZD(3,4)) - 3 5 5.14079088E-20 # Re(ZD(3,5)) - 3 6 -1.37363525E-33 # Re(ZD(3,6)) - 4 1 0.00000000E+00 # Re(ZD(4,1)) - 4 2 5.90085390E-14 # Re(ZD(4,2)) - 4 3 -9.58023202E-01 # Re(ZD(4,3)) - 4 4 -3.51971449E-32 # Re(ZD(4,4)) - 4 5 -2.20215547E-14 # Re(ZD(4,5)) - 4 6 -5.64034393E-03 # Re(ZD(4,6)) + 3 3 -2.44243972E-34 # Re(ZD(3,3)) + 3 4 -2.52921273E-01 # Re(ZD(3,4)) + 3 5 1.85262697E-20 # Re(ZD(3,5)) + 3 6 -1.26186452E-34 # Re(ZD(3,6)) + 4 1 -0.00000000E+00 # Re(ZD(4,1)) + 4 2 5.94241871E-15 # Re(ZD(4,2)) + 4 3 -2.60399345E-01 # Re(ZD(4,3)) + 4 4 6.88934165E-31 # Re(ZD(4,4)) + 4 5 -1.09481417E-15 # Re(ZD(4,5)) + 4 6 -2.17123218E-02 # Re(ZD(4,6)) 5 1 0.00000000E+00 # Re(ZD(5,1)) - 5 2 9.18747130E-01 # Re(ZD(5,2)) - 5 3 6.14772771E-14 # Re(ZD(5,3)) - 5 4 1.99493487E-23 # Re(ZD(5,4)) - 5 5 -6.48147500E-05 # Re(ZD(5,5)) - 5 6 2.72965740E-16 # Re(ZD(5,6)) + 5 2 9.92682840E-01 # Re(ZD(5,2)) + 5 3 1.54570710E-15 # Re(ZD(5,3)) + 5 4 1.11022291E-16 # Re(ZD(5,4)) + 5 5 1.59356966E-04 # Re(ZD(5,5)) + 5 6 3.64350311E-16 # Re(ZD(5,6)) 6 1 1.00000000E+00 # Re(ZD(6,1)) 6 2 0.00000000E+00 # Re(ZD(6,2)) - 6 3 -7.01565243E-40 # Re(ZD(6,3)) - 6 4 5.00370814E-06 # Re(ZD(6,4)) - 6 5 1.01703647E-24 # Re(ZD(6,5)) - 6 6 -2.71755296E-38 # Re(ZD(6,6)) + 6 3 4.83203912E-39 # Re(ZD(6,3)) + 6 4 5.00370787E-06 # Re(ZD(6,4)) + 6 5 -3.66517376E-25 # Re(ZD(6,5)) + 6 6 2.49642955E-39 # Re(ZD(6,6)) Block SELMIX - 1 1 -0.00000000E+00 # Re(ZE(1,1)) - 1 2 3.13284975E-16 # Re(ZE(1,2)) - 1 3 -3.39214507E-02 # Re(ZE(1,3)) - 1 4 1.03896833E-31 # Re(ZE(1,4)) - 1 5 -4.13604096E-15 # Re(ZE(1,5)) - 1 6 5.14601937E-01 # Re(ZE(1,6)) + 1 1 0.00000000E+00 # Re(ZE(1,1)) + 1 2 -1.91618813E-16 # Re(ZE(1,2)) + 1 3 2.53949812E-02 # Re(ZE(1,3)) + 1 4 7.99510941E-29 # Re(ZE(1,4)) + 1 5 3.96104865E-15 # Re(ZE(1,5)) + 1 6 -9.57207848E-01 # Re(ZE(1,6)) 2 1 0.00000000E+00 # Re(ZE(2,1)) - 2 2 2.03843013E-03 # Re(ZE(2,2)) - 2 3 2.44285156E-15 # Re(ZE(2,3)) - 2 4 6.81532055E-19 # Re(ZE(2,4)) - 2 5 -5.88927093E-01 # Re(ZE(2,5)) - 2 6 8.72426912E-15 # Re(ZE(2,6)) - 3 1 9.88700435E-06 # Re(ZE(3,1)) - 3 2 0.00000000E+00 # Re(ZE(3,2)) - 3 3 -3.23176259E-34 # Re(ZE(3,3)) - 3 4 -5.26454855E-01 # Re(ZE(3,4)) - 3 5 -1.58979968E-22 # Re(ZE(3,5)) - 3 6 -1.79844093E-36 # Re(ZE(3,6)) - 4 1 -0.00000000E+00 # Re(ZE(4,1)) - 4 2 9.11266516E-13 # Re(ZE(4,2)) - 4 3 -9.99325981E-01 # Re(ZE(4,3)) - 4 4 3.04350187E-28 # Re(ZE(4,4)) - 4 5 3.55937106E-15 # Re(ZE(4,5)) - 4 6 -1.82567993E-02 # Re(ZE(4,6)) + 2 2 -1.99734605E-03 # Re(ZE(2,2)) + 2 3 9.88180987E-15 # Re(ZE(2,3)) + 2 4 -3.85177746E-18 # Re(ZE(2,4)) + 2 5 3.33349838E-01 # Re(ZE(2,5)) + 2 6 2.79952017E-14 # Re(ZE(2,6)) + 3 1 -9.88700429E-06 # Re(ZE(3,1)) + 3 2 -1.55431223E-15 # Re(ZE(3,2)) + 3 3 -1.83840514E-28 # Re(ZE(3,3)) + 3 4 5.26454847E-01 # Re(ZE(3,4)) + 3 5 2.34083863E-17 # Re(ZE(3,5)) + 3 6 1.38970100E-28 # Re(ZE(3,6)) + 4 1 0.00000000E+00 # Re(ZE(4,1)) + 4 2 -4.43153669E-13 # Re(ZE(4,2)) + 4 3 5.01349084E-01 # Re(ZE(4,3)) + 4 4 3.94626733E-30 # Re(ZE(4,4)) + 4 5 -8.03083558E-15 # Re(ZE(4,5)) + 4 6 3.39104666E-02 # Re(ZE(4,6)) 5 1 0.00000000E+00 # Re(ZE(5,1)) - 5 2 9.97163661E-01 # Re(ZE(5,2)) - 5 3 9.13460204E-13 # Re(ZE(5,3)) - 5 4 3.33066210E-16 # Re(ZE(5,4)) - 5 5 1.20390140E-03 # Re(ZE(5,5)) - 5 6 1.65052435E-14 # Re(ZE(5,6)) + 5 2 -9.86503896E-01 # Re(ZE(5,2)) + 5 3 -2.28203261E-13 # Re(ZE(5,3)) + 5 4 -3.88571854E-16 # Re(ZE(5,4)) + 5 5 -7.77112837E-04 # Re(ZE(5,5)) + 5 6 -1.50698730E-14 # Re(ZE(5,6)) 6 1 1.00000000E+00 # Re(ZE(6,1)) - 6 2 0.00000000E+00 # Re(ZE(6,2)) - 6 3 3.19524507E-39 # Re(ZE(6,3)) - 6 4 5.20506144E-06 # Re(ZE(6,4)) - 6 5 1.57183563E-27 # Re(ZE(6,5)) - 6 6 1.77811933E-41 # Re(ZE(6,6)) + 6 2 -1.53674917E-20 # Re(ZE(6,2)) + 6 3 -1.81763195E-33 # Re(ZE(6,3)) + 6 4 5.20506133E-06 # Re(ZE(6,4)) + 6 5 2.31438815E-22 # Re(ZE(6,5)) + 6 6 1.37399797E-33 # Re(ZE(6,6)) Block SCALARMIX 1 1 6.58317063E-07 # ZH(1,1) - 1 2 5.75447562E-07 # ZH(1,2) + 1 2 5.75447560E-07 # ZH(1,2) 1 3 -2.04921897E-01 # ZH(1,3) 1 4 9.78778328E-01 # ZH(1,4) 2 1 -2.05941537E-01 # ZH(2,1) 2 2 -9.78564297E-01 # ZH(2,2) 2 3 2.56774341E-06 # ZH(2,3) 2 4 1.25143159E-06 # ZH(2,4) - 3 1 -3.20729293E-03 # ZH(3,1) + 3 1 -3.20729294E-03 # ZH(3,1) 3 2 6.72153232E-04 # ZH(3,2) 3 3 -9.78773073E-01 # ZH(3,3) 3 4 -2.04920795E-01 # ZH(3,4) 4 1 -9.78559041E-01 # ZH(4,1) 4 2 2.05940440E-01 # ZH(4,2) 4 3 3.20731619E-03 # ZH(4,3) - 4 4 6.72036756E-04 # ZH(4,4) + 4 4 6.72036757E-04 # ZH(4,4) Block NMIX 1 1 -1.17411817E-02 # Re(ZN(1,1)) 1 2 1.27757982E-02 # Re(ZN(1,2)) 1 3 -3.33170047E-02 # Re(ZN(1,3)) - 1 4 -8.21772589E-03 # Re(ZN(1,4)) - 2 1 2.09697462E-02 # Re(ZN(2,1)) + 1 4 -8.21772588E-03 # Re(ZN(1,4)) + 2 1 2.09697461E-02 # Re(ZN(2,1)) 2 2 1.20739572E-02 # Re(ZN(2,2)) 2 3 -1.23544567E-02 # Re(ZN(2,3)) - 2 4 -7.22039804E-03 # Re(ZN(2,4)) - 3 1 6.01397605E-03 # Re(ZN(3,1)) + 2 4 -7.22039797E-03 # Re(ZN(2,4)) + 3 1 6.01397606E-03 # Re(ZN(3,1)) 3 2 -1.08795375E-02 # Re(ZN(3,2)) 3 3 -7.05302993E-01 # Re(ZN(3,3)) 3 4 -7.07073094E-01 # Re(ZN(3,4)) - 4 1 6.95368868E-03 # Re(ZN(4,1)) + 4 1 6.95368867E-03 # Re(ZN(4,1)) 4 2 -1.50631891E-02 # Re(ZN(4,2)) 4 3 -3.14432341E-02 # Re(ZN(4,3)) 4 4 -8.63878097E-03 # Re(ZN(4,4)) @@ -582,69 +597,116 @@ Block CHARGEMIX 2 1 9.80167642E-01 # Re(ZP(2,1)) 2 2 1.98169999E-01 # Re(ZP(2,2)) Block USQMIX - 1 1 -0.00000000E+00 # Re(ZU(1,1)) - 1 2 2.02870323E-03 # Re(ZU(1,2)) - 1 3 -7.95342182E-14 # Re(ZU(1,3)) - 1 4 2.42381861E-19 # Re(ZU(1,4)) - 1 5 9.88815806E-01 # Re(ZU(1,5)) - 1 6 -1.66170608E-13 # Re(ZU(1,6)) - 2 1 -4.43695922E-06 # Re(ZU(2,1)) + 1 1 0.00000000E+00 # Re(ZU(1,1)) + 1 2 1.99245866E-03 # Re(ZU(1,2)) + 1 3 3.32241102E-14 # Re(ZU(1,3)) + 1 4 -4.50484651E-19 # Re(ZU(1,4)) + 1 5 9.98603891E-01 # Re(ZU(1,5)) + 1 6 5.93054460E-14 # Re(ZU(1,6)) + 2 1 4.43695921E-06 # Re(ZU(2,1)) 2 2 0.00000000E+00 # Re(ZU(2,2)) - 2 3 2.31285481E-33 # Re(ZU(2,3)) - 2 4 -9.90641516E-01 # Re(ZU(2,4)) - 2 5 6.03639393E-19 # Re(ZU(2,5)) - 2 6 1.37788954E-31 # Re(ZU(2,6)) + 2 3 -1.39141046E-33 # Re(ZU(2,3)) + 2 4 9.90641516E-01 # Re(ZU(2,4)) + 2 5 -1.69357107E-23 # Re(ZU(2,5)) + 2 6 -3.47197908E-33 # Re(ZU(2,6)) 3 1 0.00000000E+00 # Re(ZU(3,1)) - 3 2 -1.11984484E-15 # Re(ZU(3,2)) - 3 3 2.21063653E-01 # Re(ZU(3,3)) - 3 4 4.66267870E-31 # Re(ZU(3,4)) - 3 5 1.38948153E-13 # Re(ZU(3,5)) - 3 6 6.81758753E-01 # Re(ZU(3,6)) + 3 2 4.35986043E-15 # Re(ZU(3,2)) + 3 3 -3.60472795E-01 # Re(ZU(3,3)) + 3 4 -9.85964623E-31 # Re(ZU(3,4)) + 3 5 7.65773006E-14 # Re(ZU(3,5)) + 3 6 -9.14458679E-01 # Re(ZU(3,6)) 4 1 1.00000000E+00 # Re(ZU(4,1)) 4 2 0.00000000E+00 # Re(ZU(4,2)) - 4 3 1.02620424E-38 # Re(ZU(4,3)) - 4 4 -4.39543601E-06 # Re(ZU(4,4)) - 4 5 2.67832337E-24 # Re(ZU(4,5)) - 4 6 6.11363969E-37 # Re(ZU(4,6)) + 4 3 6.17363147E-39 # Re(ZU(4,3)) + 4 4 -4.39543600E-06 # Re(ZU(4,4)) + 4 5 7.51430575E-29 # Re(ZU(4,5)) + 4 6 1.54050296E-38 # Re(ZU(4,6)) 5 1 0.00000000E+00 # Re(ZU(5,1)) - 5 2 9.99923977E-01 # Re(ZU(5,2)) - 5 3 -5.10272788E-15 # Re(ZU(5,3)) - 5 4 2.22044570E-16 # Re(ZU(5,4)) - 5 5 -2.00636162E-03 # Re(ZU(5,5)) - 5 6 3.49098316E-15 # Re(ZU(5,6)) + 5 2 9.82052145E-01 # Re(ZU(5,2)) + 5 3 -1.66400697E-14 # Re(ZU(5,3)) + 5 4 -2.22044148E-16 # Re(ZU(5,4)) + 5 5 -2.02604005E-03 # Re(ZU(5,5)) + 5 6 1.09391609E-14 # Re(ZU(5,6)) 6 1 0.00000000E+00 # Re(ZU(6,1)) - 6 2 -7.24045556E-15 # Re(ZU(6,2)) - 6 3 -7.61359167E-01 # Re(ZU(6,3)) - 6 4 -1.53685523E-30 # Re(ZU(6,4)) - 6 5 -1.30781855E-14 # Re(ZU(6,5)) - 6 6 3.23925874E-01 # Re(ZU(6,6)) + 6 2 -1.91544388E-14 # Re(ZU(6,2)) + 6 3 -9.32648116E-01 # Re(ZU(6,3)) + 6 4 4.32828091E-30 # Re(ZU(6,4)) + 6 5 5.44694874E-15 # Re(ZU(6,5)) + 6 6 3.56501913E-01 # Re(ZU(6,6)) Block SNUMIX 1 1 0.00000000E+00 # Re(ZV(1,1)) - 1 2 4.93507117E-16 # Re(ZV(1,2)) - 1 3 -8.13200476E-01 # Re(ZV(1,3)) + 1 2 3.92143553E-16 # Re(ZV(1,2)) + 1 3 -3.20556426E-01 # Re(ZV(1,3)) 2 1 0.00000000E+00 # Re(ZV(2,1)) - 2 2 -3.25932406E-01 # Re(ZV(2,2)) - 2 3 -6.47877747E-16 # Re(ZV(2,3)) + 2 2 -9.74685428E-01 # Re(ZV(2,2)) + 2 3 -3.94618972E-16 # Re(ZV(2,3)) 3 1 1.00000000E+00 # Re(ZV(3,1)) 3 2 0.00000000E+00 # Re(ZV(3,2)) 3 3 0.00000000E+00 # Re(ZV(3,3)) +Block UELMIX + 1 1 9.99999532E-01 # Re(ZEL(1,1)) + 1 2 0.00000000E+00 # Re(ZEL(1,2)) + 1 3 0.00000000E+00 # Re(ZEL(1,3)) + 2 1 0.00000000E+00 # Re(ZEL(2,1)) + 2 2 9.99999511E-01 # Re(ZEL(2,2)) + 2 3 0.00000000E+00 # Re(ZEL(2,3)) + 3 1 0.00000000E+00 # Re(ZEL(3,1)) + 3 2 0.00000000E+00 # Re(ZEL(3,2)) + 3 3 9.99999501E-01 # Re(ZEL(3,3)) +Block UERMIX + 1 1 1.00000000E+00 # Re(ZER(1,1)) + 1 2 0.00000000E+00 # Re(ZER(1,2)) + 1 3 0.00000000E+00 # Re(ZER(1,3)) + 2 1 0.00000000E+00 # Re(ZER(2,1)) + 2 2 1.00000000E+00 # Re(ZER(2,2)) + 2 3 0.00000000E+00 # Re(ZER(2,3)) + 3 1 0.00000000E+00 # Re(ZER(3,1)) + 3 2 0.00000000E+00 # Re(ZER(3,2)) + 3 3 1.00000000E+00 # Re(ZER(3,3)) +Block UDLMIX + 1 1 9.99999628E-01 # Re(ZDL(1,1)) + 1 2 0.00000000E+00 # Re(ZDL(1,2)) + 1 3 0.00000000E+00 # Re(ZDL(1,3)) + 2 1 0.00000000E+00 # Re(ZDL(2,1)) + 2 2 -4.55435498E-02 # Re(ZDL(2,2)) + 2 3 -2.17623843E-17 # Re(ZDL(2,3)) + 3 1 0.00000000E+00 # Re(ZDL(3,1)) + 3 2 1.58539148E-19 # Re(ZDL(3,2)) + 3 3 9.99999284E-01 # Re(ZDL(3,3)) +Block UDRMIX + 1 1 1.00000000E+00 # Re(ZDR(1,1)) + 1 2 0.00000000E+00 # Re(ZDR(1,2)) + 1 3 0.00000000E+00 # Re(ZDR(1,3)) + 2 1 0.00000000E+00 # Re(ZDR(2,1)) + 2 2 -4.65090294E-02 # Re(ZDR(2,2)) + 2 3 -9.50114445E-16 # Re(ZDR(2,3)) + 3 1 0.00000000E+00 # Re(ZDR(3,1)) + 3 2 -4.41889006E-17 # Re(ZDR(3,2)) + 3 3 1.00000000E+00 # Re(ZDR(3,3)) +Block UULMIX + 1 1 9.99999999E-01 # Re(ZUL(1,1)) + 1 2 0.00000000E+00 # Re(ZUL(1,2)) + 1 3 0.00000000E+00 # Re(ZUL(1,3)) + 2 1 0.00000000E+00 # Re(ZUL(2,1)) + 2 2 9.99999999E-01 # Re(ZUL(2,2)) + 2 3 0.00000000E+00 # Re(ZUL(2,3)) + 3 1 0.00000000E+00 # Re(ZUL(3,1)) + 3 2 0.00000000E+00 # Re(ZUL(3,2)) + 3 3 9.99999999E-01 # Re(ZUL(3,3)) +Block UURMIX + 1 1 1.00000000E+00 # Re(ZUR(1,1)) + 1 2 0.00000000E+00 # Re(ZUR(1,2)) + 1 3 0.00000000E+00 # Re(ZUR(1,3)) + 2 1 0.00000000E+00 # Re(ZUR(2,1)) + 2 2 1.00000000E+00 # Re(ZUR(2,2)) + 2 3 0.00000000E+00 # Re(ZUR(2,3)) + 3 1 0.00000000E+00 # Re(ZUR(3,1)) + 3 2 0.00000000E+00 # Re(ZUR(3,2)) + 3 3 1.00000000E+00 # Re(ZUR(3,3)) Block FlexibleSUSYOutput 0 0.00000000E+00 # HighScale 1 2.00000000E+03 # SUSYScale 2 9.11876000E+01 # LowScale -Block FlexibleSUSYLowEnergy Q= 2.00000000E+03 - 21 0.00000000E+00 # Delta(g-2)_muon/2 FlexibleSUSY - 23 0.00000000E+00 # electric dipole moment of Fe(0) [1/GeV] - 24 0.00000000E+00 # electric dipole moment of Fe(1) [1/GeV] - 25 0.00000000E+00 # electric dipole moment of Fe(2) [1/GeV] - 26 0.00000000E+00 # BR(Fe1 -> Fe0 VP) -Block EFFHIGGSCOUPLINGS - 25 22 22 0.00000000E+00 # Abs(effective H-Photon-Photon coupling) - 35 22 22 0.00000000E+00 # Abs(effective H-Photon-Photon coupling) - 36 22 22 0.00000000E+00 # Abs(effective H-Photon-Photon coupling) - 25 21 21 0.00000000E+00 # Abs(effective H-Gluon-Gluon coupling) - 35 21 21 0.00000000E+00 # Abs(effective H-Gluon-Gluon coupling) - 36 21 21 0.00000000E+00 # Abs(effective H-Gluon-Gluon coupling) Block ALPHA -1.36337055E+00 # ArcSin(Pole(ZH(2,2))) Block HMIX Q= 2.00000000E+03 @@ -652,7 +714,7 @@ Block HMIX Q= 2.00000000E+03 2 4.77520537E+00 # vu/vd 3 2.44022303E+02 # Sqrt(Sqr(vd) + Sqr(vu)) 101 8.02468438E+05 # Re(BMu) - 102 5.00169780E+01 # vd + 102 5.00169779E+01 # vd 103 2.38841341E+02 # vu Block ImHMIX Q= 2.00000000E+03 1 9.99999897E+01 # Im(Mu) @@ -662,25 +724,25 @@ Block Au Q= 2.00000000E+03 2 2 4.00001141E+02 # Re(TYu(2,2)/Yu(2,2)) 3 3 4.00000303E+02 # Re(TYu(3,3)/Yu(3,3)) Block Ad Q= 2.00000000E+03 - 1 1 9.99997100E+03 # Re(TYd(1,1)/Yd(1,1)) - 2 2 9.99997100E+03 # Re(TYd(2,2)/Yd(2,2)) - 3 3 9.99992475E+03 # Re(TYd(3,3)/Yd(3,3)) + 1 1 9.99997099E+03 # Re(TYd(1,1)/Yd(1,1)) + 2 2 9.99997099E+03 # Re(TYd(2,2)/Yd(2,2)) + 3 3 9.99992474E+03 # Re(TYd(3,3)/Yd(3,3)) Block Ae Q= 2.00000000E+03 1 1 1.00000160E+04 # Re(TYe(1,1)/Ye(1,1)) 2 2 1.00000160E+04 # Re(TYe(2,2)/Ye(2,2)) 3 3 1.00000157E+04 # Re(TYe(3,3)/Ye(3,3)) Block ImAu Q= 2.00000000E+03 - 1 1 1.17088923E-04 # Im(TYu(1,1)/Yu(1,1)) - 2 2 1.17088875E-04 # Im(TYu(2,2)/Yu(2,2)) - 3 3 2.14041592E-06 # Im(TYu(3,3)/Yu(3,3)) + 1 1 1.17109167E-04 # Im(TYu(1,1)/Yu(1,1)) + 2 2 1.17109119E-04 # Im(TYu(2,2)/Yu(2,2)) + 3 3 2.15829048E-06 # Im(TYu(3,3)/Yu(3,3)) Block ImAd Q= 2.00000000E+03 - 1 1 1.18926618E-04 # Im(TYd(1,1)/Yd(1,1)) - 2 2 1.18926593E-04 # Im(TYd(2,2)/Yd(2,2)) - 3 3 2.62783601E-04 # Im(TYd(3,3)/Yd(3,3)) + 1 1 1.18948580E-04 # Im(TYd(1,1)/Yd(1,1)) + 2 2 1.18948555E-04 # Im(TYd(2,2)/Yd(2,2)) + 3 3 2.62803507E-04 # Im(TYd(3,3)/Yd(3,3)) Block ImAe Q= 2.00000000E+03 - 1 1 -8.86146846E-06 # Im(TYe(1,1)/Ye(1,1)) - 2 2 -8.86074664E-06 # Im(TYe(2,2)/Ye(2,2)) - 3 3 -8.66156099E-06 # Im(TYe(3,3)/Ye(3,3)) + 1 1 -8.85710713E-06 # Im(TYe(1,1)/Ye(1,1)) + 2 2 -8.85638533E-06 # Im(TYe(2,2)/Ye(2,2)) + 3 3 -8.65720136E-06 # Im(TYe(3,3)/Ye(3,3)) Block MSOFT Q= 2.00000000E+03 1 2.00000004E+03 # Re(MassB) 2 2.00000002E+03 # Re(MassWB) @@ -745,11 +807,10 @@ Block ImMSOFT Q= 2.00000000E+03 BOOST_TEST(false); } - MSSMCPV_spectrum_generator spectrum_generator; - spectrum_generator.set_settings(settings); - spectrum_generator.run(qedqcd, input); - - MSSMCPV_slha m = std::get<0>(spectrum_generator.get_models_slha()); + MSSMCPV_slha m(input); + slha_io.fill(m); + m.calculate_DRbar_masses(); + m.reorder_DRbar_masses(); // ----------------------------------------------------- // decays with higher-order SM corrections @@ -762,13 +823,13 @@ Block ImMSOFT Q= 2.00000000E+03 // h -> b bbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFdFd(&m, 1, 2, 2), - 0.0021707230194274911, 6e-13); + 0.0021707237775801919, 6e-13); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFuFu(&m, 1, 1, 1), - 0.00010604105533198515, 2e-13); + 0.00010604105374890464, 2e-13); // h -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFeFe(&m, 1, 2, 2), - 0.00022695651732646037, 3e-13); + 0.00022695659608435093, 3e-13); // h -> W+ W- // BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_conjVWmVWm(&m, 1), // 4.271655828335071e-05, 2e-12); @@ -783,14 +844,14 @@ Block ImMSOFT Q= 2.00000000E+03 // ------------ loop-induces decays ------------ // h -> gluon gluon - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VGVG(&m, 1), 0.0002318886239533966, 2e-10); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VGVG(&m, 1), 0.00023188864634816065, 2e-10); // h -> gamma gamma // without 2L QCD for squark // BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 0), 6.3284545616000571e-06, 4e-11); // with 2L QCD for squark - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 1), 5.3089300093115946e-06, 7e-10); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 1), 5.3089524775640594e-06, 7e-10); // h -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 1), 5.1994372474535712e-07, 7e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 1), 5.1994529676800549e-07, 7e-11); // ----------------------------------------------------- // decays without higher-order SM corrections @@ -800,19 +861,19 @@ Block ImMSOFT Q= 2.00000000E+03 // h -> b bbar BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFdFd(&m, 1, 2, 2), - 0.0012302546723090763, 2e-13); + 0.0012302551007035709, 2e-13); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFuFu(&m, 1, 1, 1), - 6.5889191543027687e-05, 2e-13); + 6.5889190180543533e-05, 2e-13); // h -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFeFe(&m, 1, 2, 2), - 0.00022454719336516455, 3e-13); + 0.0002245472712886441, 3e-13); // h -> gamma gamma - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVP(&m, 1), 5.2382389517397406e-06, 7e-10); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVP(&m, 1), 5.2382612693789171e-06, 7e-10); // h -> gluon gluon - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VGVG(&m, 1), 6.1972398675528688e-05, 2e-10); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VGVG(&m, 1), 6.1972425811286929e-05, 2e-10); // h -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVZ(&m, 1), 5.1994372474535712e-07, 7e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVZ(&m, 1), 5.1994529676800549e-07, 7e-11); } diff --git a/test/test_MSSM_FlexibleDecay.cpp b/test/test_MSSM_FlexibleDecay.cpp index 733930fd9b..66303cc3c2 100644 --- a/test/test_MSSM_FlexibleDecay.cpp +++ b/test/test_MSSM_FlexibleDecay.cpp @@ -17,9 +17,9 @@ BOOST_AUTO_TEST_CASE( test_MSSM_FlexibleDecay ) char const * const slha_input = R"( Block SPINFO 1 FlexibleSUSY - 2 2.4.1 + 2 2.6.1 5 MSSM - 9 4.14.3 + 9 4.14.5 Block MODSEL # Select model 6 0 # flavour violation # 12 1000 # DRbar parameter output scale (GeV) @@ -177,239 +177,239 @@ Block MSU2IN 3 1 0.00000000E+00 # mu2Input(3,1) 3 2 0.00000000E+00 # mu2Input(3,2) 3 3 1.56250000E+04 # mu2Input(3,3) -Block gauge Q= 8.61574711E+02 - 1 3.59999781E-01 # g1 * 0.7745966692414834 - 2 6.56898251E-01 # g2 - 3 1.06298750E+00 # g3 -Block Yu Q= 8.61574711E+02 - 1 1 7.44114581E-06 # Yu(1,1) +Block gauge Q= 8.64566212E+02 + 1 3.62397260E-01 # g1 * 0.7745966692414834 + 2 6.43021599E-01 # g2 + 3 1.06289850E+00 # g3 +Block Yu Q= 8.64566212E+02 + 1 1 7.32865780E-06 # Yu(1,1) 1 2 0.00000000E+00 # Yu(1,2) 1 3 0.00000000E+00 # Yu(1,3) 2 1 0.00000000E+00 # Yu(2,1) - 2 2 3.40276871E-03 # Yu(2,2) + 2 2 3.35132890E-03 # Yu(2,2) 2 3 0.00000000E+00 # Yu(2,3) 3 1 0.00000000E+00 # Yu(3,1) 3 2 0.00000000E+00 # Yu(3,2) - 3 3 8.75768601E-01 # Yu(3,3) -Block Yd Q= 8.61574711E+02 - 1 1 1.43200353E-04 # Yd(1,1) + 3 3 8.61499146E-01 # Yu(3,3) +Block Yd Q= 8.64566212E+02 + 1 1 1.41176492E-04 # Yd(1,1) 1 2 0.00000000E+00 # Yd(1,2) 1 3 0.00000000E+00 # Yd(1,3) 2 1 0.00000000E+00 # Yd(2,1) - 2 2 3.13533605E-03 # Yd(2,2) + 2 2 3.09102407E-03 # Yd(2,2) 2 3 0.00000000E+00 # Yd(2,3) 3 1 0.00000000E+00 # Yd(3,1) 3 2 0.00000000E+00 # Yd(3,2) - 3 3 1.35247807E-01 # Yd(3,3) -Block Ye Q= 8.61574711E+02 - 1 1 2.94098526E-05 # Ye(1,1) + 3 3 1.33305769E-01 # Yd(3,3) +Block Ye Q= 8.64566212E+02 + 1 1 2.89548332E-05 # Ye(1,1) 1 2 0.00000000E+00 # Ye(1,2) 1 3 0.00000000E+00 # Ye(1,3) 2 1 0.00000000E+00 # Ye(2,1) - 2 2 6.08102487E-03 # Ye(2,2) + 2 2 5.98694134E-03 # Ye(2,2) 2 3 0.00000000E+00 # Ye(2,3) 3 1 0.00000000E+00 # Ye(3,1) 3 2 0.00000000E+00 # Ye(3,2) - 3 3 1.02276019E-01 # Ye(3,3) -Block Te Q= 8.61574711E+02 - 1 1 -9.05425923E-03 # TYe(1,1) + 3 3 1.00693901E-01 # Ye(3,3) +Block Te Q= 8.64566212E+02 + 1 1 -8.66772958E-03 # TYe(1,1) 1 2 0.00000000E+00 # TYe(1,2) 1 3 0.00000000E+00 # TYe(1,3) 2 1 0.00000000E+00 # TYe(2,1) - 2 2 -1.87209650E+00 # TYe(2,2) + 2 2 -1.79217692E+00 # TYe(2,2) 2 3 0.00000000E+00 # TYe(2,3) 3 1 0.00000000E+00 # TYe(3,1) 3 2 0.00000000E+00 # TYe(3,2) - 3 3 -3.13103118E+01 # TYe(3,3) -Block Td Q= 8.61574711E+02 - 1 1 -1.99663480E-01 # TYd(1,1) + 3 3 -2.99779990E+01 # TYe(3,3) +Block Td Q= 8.64566212E+02 + 1 1 -1.95555678E-01 # TYd(1,1) 1 2 0.00000000E+00 # TYd(1,2) 1 3 0.00000000E+00 # TYd(1,3) 2 1 0.00000000E+00 # TYd(2,1) - 2 2 -4.37156706E+00 # TYd(2,2) + 2 2 -4.28162839E+00 # TYd(2,2) 2 3 0.00000000E+00 # TYd(2,3) 3 1 0.00000000E+00 # TYd(3,1) 3 2 0.00000000E+00 # TYd(3,2) - 3 3 -1.75898126E+02 # TYd(3,3) -Block Tu Q= 8.61574711E+02 - 1 1 -8.41105668E-03 # TYu(1,1) + 3 3 -1.72594209E+02 # TYd(3,3) +Block Tu Q= 8.64566212E+02 + 1 1 -8.29130231E-03 # TYu(1,1) 1 2 0.00000000E+00 # TYu(1,2) 1 3 0.00000000E+00 # TYu(1,3) 2 1 0.00000000E+00 # TYu(2,1) - 2 2 -3.84628253E+00 # TYu(2,2) + 2 2 -3.79152071E+00 # TYu(2,2) 2 3 0.00000000E+00 # TYu(2,3) 3 1 0.00000000E+00 # TYu(3,1) 3 2 0.00000000E+00 # TYu(3,2) - 3 3 -7.55562692E+02 # TYu(3,3) -Block MSQ2 Q= 8.61574711E+02 - 1 1 1.01698410E+06 # mq2(1,1) + 3 3 -7.52334904E+02 # TYu(3,3) +Block MSQ2 Q= 8.64566212E+02 + 1 1 1.01404039E+06 # mq2(1,1) 1 2 0.00000000E+00 # mq2(1,2) 1 3 0.00000000E+00 # mq2(1,3) 2 1 0.00000000E+00 # mq2(2,1) - 2 2 1.01697877E+06 # mq2(2,2) + 2 2 1.01403524E+06 # mq2(2,2) 2 3 0.00000000E+00 # mq2(2,3) 3 1 0.00000000E+00 # mq2(3,1) 3 2 0.00000000E+00 # mq2(3,2) - 3 3 8.60663456E+05 # mq2(3,3) -Block MSE2 Q= 8.61574711E+02 - 1 1 4.92190886E+04 # me2(1,1) + 3 3 8.61830295E+05 # mq2(3,3) +Block MSE2 Q= 8.64566212E+02 + 1 1 4.93996314E+04 # me2(1,1) 1 2 0.00000000E+00 # me2(1,2) 1 3 0.00000000E+00 # me2(1,3) 2 1 0.00000000E+00 # me2(2,1) - 2 2 4.92136724E+04 # me2(2,2) + 2 2 4.93944907E+04 # me2(2,2) 2 3 0.00000000E+00 # me2(2,3) 3 1 0.00000000E+00 # me2(3,1) 3 2 0.00000000E+00 # me2(3,2) - 3 3 4.76891146E+04 # me2(3,3) -Block MSL2 Q= 8.61574711E+02 - 1 1 1.28303328E+05 # ml2(1,1) + 3 3 4.79473518E+04 # me2(3,3) +Block MSL2 Q= 8.64566212E+02 + 1 1 1.24998047E+05 # ml2(1,1) 1 2 0.00000000E+00 # ml2(1,2) 1 3 0.00000000E+00 # ml2(1,3) 2 1 0.00000000E+00 # ml2(2,1) - 2 2 1.28300676E+05 # ml2(2,2) + 2 2 1.24995528E+05 # ml2(2,2) 2 3 0.00000000E+00 # ml2(2,3) 3 1 0.00000000E+00 # ml2(3,1) 3 2 0.00000000E+00 # ml2(3,2) - 3 3 1.27554323E+05 # ml2(3,3) -Block MSU2 Q= 8.61574711E+02 - 1 1 9.37379062E+05 # mu2(1,1) + 3 3 1.24286462E+05 # ml2(3,3) +Block MSU2 Q= 8.64566212E+02 + 1 1 9.37329592E+05 # mu2(1,1) 1 2 0.00000000E+00 # mu2(1,2) 1 3 0.00000000E+00 # mu2(1,3) 2 1 0.00000000E+00 # mu2(2,1) - 2 2 9.37373619E+05 # mu2(2,2) + 2 2 9.37324316E+05 # mu2(2,2) 2 3 0.00000000E+00 # mu2(2,3) 3 1 0.00000000E+00 # mu2(3,1) 3 2 0.00000000E+00 # mu2(3,2) - 3 3 6.27037222E+05 # mu2(3,3) -Block MSD2 Q= 8.61574711E+02 - 1 1 9.28209501E+05 # md2(1,1) + 3 3 6.35411190E+05 # mu2(3,3) +Block MSD2 Q= 8.64566212E+02 + 1 1 9.28110603E+05 # md2(1,1) 1 2 0.00000000E+00 # md2(1,2) 1 3 0.00000000E+00 # md2(1,3) 2 1 0.00000000E+00 # md2(2,1) - 2 2 9.28204149E+05 # md2(2,2) + 2 2 9.28105434E+05 # md2(2,2) 2 3 0.00000000E+00 # md2(2,3) 3 1 0.00000000E+00 # md2(3,1) 3 2 0.00000000E+00 # md2(3,2) - 3 3 9.18700843E+05 # md2(3,3) -Block Phases Q= 8.61574711E+02 + 3 3 9.18917534E+05 # md2(3,3) +Block Phases Q= 8.64566212E+02 1 1.00000000E+00 # Re(PhaseGlu) -Block IMPhases Q= 8.61574711E+02 +Block IMPhases Q= 8.64566212E+02 1 0.00000000E+00 # Im(PhaseGlu) Block MASS - 1000021 1.14482639E+03 # Glu - 24 8.22179853E+01 # VWm - 1000024 3.80849556E+02 # Cha(1) - 1000037 6.51784974E+02 # Cha(2) - 25 1.15461248E+02 # hh(1) - 35 7.22610281E+02 # hh(2) - 37 7.27129000E+02 # Hpm(2) - 36 7.22328661E+02 # Ah(2) - 1000012 3.55652239E+02 # Sv(1) - 1000014 3.56861268E+02 # Sv(2) - 1000016 3.56865558E+02 # Sv(3) - 1000022 2.07672439E+02 # Chi(1) - 1000023 3.80829020E+02 # Chi(2) - 1000025 -6.38064535E+02 # Chi(3) - 1000035 6.51307635E+02 # Chi(4) - 1000001 9.54750500E+02 # Sd(1) - 1000003 9.94898036E+02 # Sd(2) - 1000005 9.98047186E+02 # Sd(3) - 2000001 9.98051060E+02 # Sd(4) - 2000003 1.04512659E+03 # Sd(5) - 2000005 1.04512853E+03 # Sd(6) - 1000011 2.22269063E+02 # Se(1) - 1000013 2.29495276E+02 # Se(2) - 1000015 2.29520911E+02 # Se(3) - 2000011 3.65774038E+02 # Se(4) - 2000013 3.65777881E+02 # Se(5) - 2000015 3.66795565E+02 # Se(6) - 1000002 7.90438045E+02 # Su(1) - 1000004 9.98575595E+02 # Su(2) - 1000006 1.00154427E+03 # Su(3) - 2000002 1.00233322E+03 # Su(4) - 2000004 1.04221767E+03 # Su(5) - 2000006 1.04221811E+03 # Su(6) + 1000021 1.14507765E+03 # Glu + 24 8.03633615E+01 # VWm + 1000024 3.84946652E+02 # Cha(1) + 1000037 6.43567570E+02 # Cha(2) + 25 1.14844829E+02 # hh(1) + 35 7.12647702E+02 # hh(2) + 37 7.17159962E+02 # Hpm(2) + 36 7.12376885E+02 # Ah(2) + 1000012 3.50946348E+02 # Sv(1) + 1000014 3.52110103E+02 # Sv(2) + 1000016 3.52114232E+02 # Sv(3) + 1000022 2.03765032E+02 # Chi(1) + 1000023 3.84941967E+02 # Chi(2) + 1000025 -6.29278072E+02 # Chi(3) + 1000035 6.43254469E+02 # Chi(4) + 1000001 9.55616899E+02 # Sd(1) + 1000003 9.95172642E+02 # Sd(2) + 1000005 9.98169155E+02 # Sd(3) + 2000001 9.98172941E+02 # Sd(4) + 2000003 1.04379200E+03 # Sd(5) + 2000005 1.04379385E+03 # Sd(6) + 1000011 2.22944690E+02 # Se(1) + 1000013 2.30022228E+02 # Se(2) + 1000015 2.30047372E+02 # Se(3) + 2000011 3.61034664E+02 # Se(4) + 2000013 3.61038910E+02 # Se(5) + 2000015 3.62164628E+02 # Se(6) + 1000002 7.94247721E+02 # Su(1) + 1000004 1.00025984E+03 # Su(2) + 1000006 1.00165304E+03 # Su(3) + 2000002 1.00272702E+03 # Su(4) + 2000004 1.04091773E+03 # Su(5) + 2000006 1.04091837E+03 # Su(6) 21 0.00000000E+00 # VG 12 0.00000000E+00 # Fv(1) 14 0.00000000E+00 # Fv(2) 16 0.00000000E+00 # Fv(3) - 11 5.30386450E-04 # Fe(1) - 13 1.07519240E-01 # Fe(2) - 15 1.78907515E+00 # Fe(3) - 1 4.61547151E-03 # Fd(1) - 3 9.12933235E-02 # Fd(2) - 5 3.39876655E+00 # Fd(3) - 2 2.32347760E-03 # Fu(1) - 4 8.54837592E-01 # Fu(2) - 6 1.73817518E+02 # Fu(3) + 11 5.30293274E-04 # Fe(1) + 13 1.07502302E-01 # Fe(2) + 15 1.78881716E+00 # Fe(3) + 1 4.61593304E-03 # Fd(1) + 3 9.13029979E-02 # Fd(2) + 5 3.39894600E+00 # Fd(3) + 2 2.32430773E-03 # Fu(1) + 4 8.55208202E-01 # Fu(2) + 6 1.73822611E+02 # Fu(3) 22 0.00000000E+00 # VP - 23 9.11338975E+01 # VZ + 23 9.11298854E+01 # VZ Block UMIX - 1 1 9.60383246E-01 # Re(UM(1,1)) - 1 2 -2.78682654E-01 # Re(UM(1,2)) - 2 1 2.78682654E-01 # Re(UM(2,1)) - 2 2 9.60383246E-01 # Re(UM(2,2)) + 1 1 9.57429771E-01 # Re(UM(1,1)) + 1 2 -2.88666301E-01 # Re(UM(1,2)) + 2 1 2.88666301E-01 # Re(UM(2,1)) + 2 2 9.57429771E-01 # Re(UM(2,2)) Block VMIX - 1 1 9.82927175E-01 # Re(UP(1,1)) - 1 2 -1.83995021E-01 # Re(UP(1,2)) - 2 1 1.83995021E-01 # Re(UP(2,1)) - 2 2 9.82927175E-01 # Re(UP(2,2)) + 1 1 9.80920736E-01 # Re(UP(1,1)) + 1 2 -1.94408100E-01 # Re(UP(1,2)) + 2 1 1.94408100E-01 # Re(UP(2,1)) + 2 2 9.80920736E-01 # Re(UP(2,2)) Block PSEUDOSCALARMIX - 1 1 -9.90160581E-02 # ZA(1,1) - 1 2 9.95085836E-01 # ZA(1,2) - 2 1 9.95085836E-01 # ZA(2,1) - 2 2 9.90160581E-02 # ZA(2,2) + 1 1 -9.89804863E-02 # ZA(1,1) + 1 2 9.95089375E-01 # ZA(1,2) + 2 1 9.95089375E-01 # ZA(2,1) + 2 2 9.89804863E-02 # ZA(2,2) Block DSQMIX - 1 1 -0.00000000E+00 # ZD(1,1) - 1 2 -0.00000000E+00 # ZD(1,2) - 1 3 -9.74286165E-01 # ZD(1,3) - 1 4 -0.00000000E+00 # ZD(1,4) - 1 5 -0.00000000E+00 # ZD(1,5) - 1 6 -2.25314157E-01 # ZD(1,6) + 1 1 0.00000000E+00 # ZD(1,1) + 1 2 -7.29213802E-16 # ZD(1,2) + 1 3 9.74106342E-01 # ZD(1,3) + 1 4 0.00000000E+00 # ZD(1,4) + 1 5 -7.61221493E-16 # ZD(1,5) + 1 6 2.26090322E-01 # ZD(1,6) 2 1 0.00000000E+00 # ZD(2,1) - 2 2 0.00000000E+00 # ZD(2,2) - 2 3 2.25314157E-01 # ZD(2,3) + 2 2 3.07818909E-16 # ZD(2,2) + 2 3 -2.26090322E-01 # ZD(2,3) 2 4 0.00000000E+00 # ZD(2,4) - 2 5 0.00000000E+00 # ZD(2,5) - 2 6 -9.74286165E-01 # ZD(2,6) - 3 1 -0.00000000E+00 # ZD(3,1) - 3 2 -4.48067024E-03 # ZD(3,2) - 3 3 -0.00000000E+00 # ZD(3,3) - 3 4 -0.00000000E+00 # ZD(3,4) - 3 5 -9.99989962E-01 # ZD(3,5) - 3 6 -0.00000000E+00 # ZD(3,6) - 4 1 2.04652197E-04 # ZD(4,1) + 2 5 2.40876201E-15 # ZD(2,5) + 2 6 9.74106342E-01 # ZD(2,6) + 3 1 0.00000000E+00 # ZD(3,1) + 3 2 -4.57005211E-03 # ZD(3,2) + 3 3 -1.26686878E-15 # ZD(3,3) + 3 4 0.00000000E+00 # ZD(3,4) + 3 5 -9.99989557E-01 # ZD(3,5) + 3 6 2.16934167E-15 # ZD(3,6) + 4 1 2.08734887E-04 # ZD(4,1) 4 2 0.00000000E+00 # ZD(4,2) 4 3 0.00000000E+00 # ZD(4,3) - 4 4 9.99999979E-01 # ZD(4,4) + 4 4 9.99999978E-01 # ZD(4,4) 4 5 0.00000000E+00 # ZD(4,5) 4 6 0.00000000E+00 # ZD(4,6) 5 1 0.00000000E+00 # ZD(5,1) - 5 2 -9.99989962E-01 # ZD(5,2) - 5 3 0.00000000E+00 # ZD(5,3) + 5 2 9.99989557E-01 # ZD(5,2) + 5 3 7.74145093E-16 # ZD(5,3) 5 4 0.00000000E+00 # ZD(5,4) - 5 5 4.48067024E-03 # ZD(5,5) - 5 6 0.00000000E+00 # ZD(5,6) - 6 1 9.99999979E-01 # ZD(6,1) + 5 5 -4.57005211E-03 # ZD(5,5) + 5 6 -1.25067470E-16 # ZD(5,6) + 6 1 9.99999978E-01 # ZD(6,1) 6 2 0.00000000E+00 # ZD(6,2) 6 3 0.00000000E+00 # ZD(6,3) - 6 4 -2.04652197E-04 # ZD(6,4) + 6 4 -2.08734887E-04 # ZD(6,4) 6 5 0.00000000E+00 # ZD(6,5) 6 6 0.00000000E+00 # ZD(6,6) Block SELMIX 1 1 0.00000000E+00 # ZE(1,1) - 1 2 2.71107806E-17 # ZE(1,2) - 1 3 1.37829507E-01 # ZE(1,3) + 1 2 0.00000000E+00 # ZE(1,2) + 1 3 1.42036469E-01 # ZE(1,3) 1 4 0.00000000E+00 # ZE(1,4) - 1 5 3.31164198E-16 # ZE(1,5) - 1 6 9.90455969E-01 # ZE(1,6) + 1 5 0.00000000E+00 # ZE(1,5) + 1 6 9.89861425E-01 # ZE(1,6) 2 1 0.00000000E+00 # ZE(2,1) - 2 2 -8.52595046E-03 # ZE(2,2) - 2 3 3.05760718E-17 # ZE(2,3) + 2 2 8.80185979E-03 # ZE(2,2) + 2 3 0.00000000E+00 # ZE(2,3) 2 4 0.00000000E+00 # ZE(2,4) - 2 5 -9.99963653E-01 # ZE(2,5) - 2 6 3.38375884E-16 # ZE(2,6) - 3 1 4.12403764E-05 # ZE(3,1) + 2 5 9.99961263E-01 # ZE(2,5) + 2 6 0.00000000E+00 # ZE(2,6) + 3 1 4.25752572E-05 # ZE(3,1) 3 2 0.00000000E+00 # ZE(3,2) 3 3 0.00000000E+00 # ZE(3,3) 3 4 9.99999999E-01 # ZE(3,4) @@ -418,62 +418,62 @@ Block SELMIX 4 1 9.99999999E-01 # ZE(4,1) 4 2 0.00000000E+00 # ZE(4,2) 4 3 0.00000000E+00 # ZE(4,3) - 4 4 -4.12403764E-05 # ZE(4,4) + 4 4 -4.25752572E-05 # ZE(4,4) 4 5 0.00000000E+00 # ZE(4,5) 4 6 0.00000000E+00 # ZE(4,6) 5 1 0.00000000E+00 # ZE(5,1) - 5 2 9.99963653E-01 # ZE(5,2) - 5 3 1.87938838E-14 # ZE(5,3) + 5 2 9.99961263E-01 # ZE(5,2) + 5 3 0.00000000E+00 # ZE(5,3) 5 4 0.00000000E+00 # ZE(5,4) - 5 5 -8.52595046E-03 # ZE(5,5) - 5 6 -2.63976402E-15 # ZE(5,6) + 5 5 -8.80185979E-03 # ZE(5,5) + 5 6 0.00000000E+00 # ZE(5,6) 6 1 0.00000000E+00 # ZE(6,1) - 6 2 -1.89778014E-14 # ZE(6,2) - 6 3 9.90455969E-01 # ZE(6,3) + 6 2 0.00000000E+00 # ZE(6,2) + 6 3 9.89861425E-01 # ZE(6,3) 6 4 0.00000000E+00 # ZE(6,4) - 6 5 1.43100164E-16 # ZE(6,5) - 6 6 -1.37829507E-01 # ZE(6,6) + 6 5 0.00000000E+00 # ZE(6,5) + 6 6 -1.42036469E-01 # ZE(6,6) Block SCALARMIX - 1 1 1.06626992E-01 # ZH(1,1) - 1 2 9.94299092E-01 # ZH(1,2) - 2 1 9.94299092E-01 # ZH(2,1) - 2 2 -1.06626992E-01 # ZH(2,2) + 1 1 1.06631109E-01 # ZH(1,1) + 1 2 9.94298651E-01 # ZH(1,2) + 2 1 9.94298651E-01 # ZH(2,1) + 2 2 -1.06631109E-01 # ZH(2,2) Block NMIX - 1 1 -9.95937884E-01 # Re(ZN(1,1)) - 1 2 1.82403903E-02 # Re(ZN(1,2)) - 1 3 -8.13208590E-02 # Re(ZN(1,3)) - 1 4 3.40871879E-02 # Re(ZN(1,4)) - 2 1 3.80941901E-02 # Re(ZN(2,1)) - 2 2 9.71669835E-01 # Re(ZN(2,2)) - 2 3 -1.94844064E-01 # Re(ZN(2,3)) - 2 4 1.28227750E-01 # Re(ZN(2,4)) - 3 1 3.23009163E-02 # Re(ZN(3,1)) - 3 2 -4.88516996E-02 # Re(ZN(3,2)) - 3 3 -7.03454555E-01 # Re(ZN(3,3)) - 3 4 -7.08323268E-01 # Re(ZN(3,4)) - 4 1 7.49213842E-02 # Re(ZN(4,1)) - 4 2 -2.30517965E-01 # Re(ZN(4,2)) - 4 3 -6.78656318E-01 # Re(ZN(4,3)) - 4 4 6.93306466E-01 # Re(ZN(4,4)) + 1 1 -9.95692479E-01 # Re(ZN(1,1)) + 1 2 1.78138151E-02 # Re(ZN(1,2)) + 1 3 -8.39671875E-02 # Re(ZN(1,3)) + 1 4 3.50523347E-02 # Re(ZN(1,4)) + 2 1 3.91216656E-02 # Re(ZN(2,1)) + 2 2 9.69238435E-01 # Re(ZN(2,2)) + 2 3 -2.01735414E-01 # Re(ZN(2,3)) + 2 4 1.35459125E-01 # Re(ZN(2,4)) + 3 1 3.35071390E-02 # Re(ZN(3,1)) + 3 2 -4.87542661E-02 # Re(ZN(3,2)) + 3 3 -7.03377609E-01 # Re(ZN(3,3)) + 3 4 -7.08350360E-01 # Re(ZN(3,4)) + 4 1 7.70925008E-02 # Re(ZN(4,1)) + 4 2 -2.40587917E-01 # Re(ZN(4,2)) + 4 3 -6.76396535E-01 # Re(ZN(4,3)) + 4 4 6.91853978E-01 # Re(ZN(4,4)) Block CHARGEMIX - 1 1 -9.96359870E-02 # ZP(1,1) - 1 2 9.95023955E-01 # ZP(1,2) - 2 1 9.95023955E-01 # ZP(2,1) - 2 2 9.96359870E-02 # ZP(2,2) + 1 1 -9.95719443E-02 # ZP(1,1) + 1 2 9.95030365E-01 # ZP(1,2) + 2 1 9.95030365E-01 # ZP(2,1) + 2 2 9.95719443E-02 # ZP(2,2) Block USQMIX 1 1 0.00000000E+00 # ZU(1,1) 1 2 0.00000000E+00 # ZU(1,2) - 1 3 4.19318558E-01 # ZU(1,3) + 1 3 4.27858606E-01 # ZU(1,3) 1 4 0.00000000E+00 # ZU(1,4) 1 5 0.00000000E+00 # ZU(1,5) - 1 6 9.07839164E-01 # ZU(1,6) - 2 1 -0.00000000E+00 # ZU(2,1) - 2 2 -8.95797956E-03 # ZU(2,2) - 2 3 -0.00000000E+00 # ZU(2,3) - 2 4 -0.00000000E+00 # ZU(2,4) - 2 5 -9.99959876E-01 # ZU(2,5) - 2 6 -0.00000000E+00 # ZU(2,6) - 3 1 1.95917144E-05 # ZU(3,1) + 1 6 9.03845680E-01 # ZU(1,6) + 2 1 0.00000000E+00 # ZU(2,1) + 2 2 -9.27975914E-03 # ZU(2,2) + 2 3 0.00000000E+00 # ZU(2,3) + 2 4 0.00000000E+00 # ZU(2,4) + 2 5 -9.99956942E-01 # ZU(2,5) + 2 6 0.00000000E+00 # ZU(2,6) + 3 1 2.02956466E-05 # ZU(3,1) 3 2 0.00000000E+00 # ZU(3,2) 3 3 0.00000000E+00 # ZU(3,3) 3 4 1.00000000E+00 # ZU(3,4) @@ -481,21 +481,21 @@ Block USQMIX 3 6 0.00000000E+00 # ZU(3,6) 4 1 0.00000000E+00 # ZU(4,1) 4 2 0.00000000E+00 # ZU(4,2) - 4 3 9.07839164E-01 # ZU(4,3) + 4 3 9.03845680E-01 # ZU(4,3) 4 4 0.00000000E+00 # ZU(4,4) 4 5 0.00000000E+00 # ZU(4,5) - 4 6 -4.19318558E-01 # ZU(4,6) + 4 6 -4.27858606E-01 # ZU(4,6) 5 1 1.00000000E+00 # ZU(5,1) 5 2 0.00000000E+00 # ZU(5,2) 5 3 0.00000000E+00 # ZU(5,3) - 5 4 -1.95917144E-05 # ZU(5,4) + 5 4 -2.02956466E-05 # ZU(5,4) 5 5 0.00000000E+00 # ZU(5,5) 5 6 0.00000000E+00 # ZU(5,6) 6 1 0.00000000E+00 # ZU(6,1) - 6 2 -9.99959876E-01 # ZU(6,2) + 6 2 -9.99956942E-01 # ZU(6,2) 6 3 0.00000000E+00 # ZU(6,3) 6 4 0.00000000E+00 # ZU(6,4) - 6 5 8.95797956E-03 # ZU(6,5) + 6 5 9.27975914E-03 # ZU(6,5) 6 6 0.00000000E+00 # ZU(6,6) Block SNUMIX 1 1 0.00000000E+00 # ZV(1,1) @@ -569,51 +569,51 @@ Block UURMIX 3 3 1.00000000E+00 # Re(ZUR(3,3)) Block FlexibleSUSYOutput 0 1.94220000E+16 # HighScale - 1 8.61574711E+02 # SUSYScale + 1 8.64566212E+02 # SUSYScale 2 9.11876000E+01 # LowScale Block ALPHA - -1.06830078E-01 # ArcSin(Pole(ZH(2,2))) -Block HMIX Q= 8.61574711E+02 - 1 6.32596004E+02 # Mu - 2 9.66521530E+00 # vu/vd - 3 2.40393898E+02 # Sqrt(Sqr(vd) + Sqr(vu)) - 4 5.41191164E+05 # Sqr(MAh(2)) - 101 5.54006492E+04 # BMu - 102 2.47400032E+01 # vd - 103 2.39117457E+02 # vu -Block Au Q= 8.61574711E+02 - 1 1 -1.13034429E+03 # TYu(1,1)/Yu(1,1) - 2 2 -1.13033910E+03 # TYu(2,2)/Yu(2,2) - 3 3 -8.62742386E+02 # TYu(3,3)/Yu(3,3) -Block Ad Q= 8.61574711E+02 - 1 1 -1.39429461E+03 # TYd(1,1)/Yd(1,1) - 2 2 -1.39428979E+03 # TYd(2,2)/Yd(2,2) - 3 3 -1.30056176E+03 # TYd(3,3)/Yd(3,3) -Block Ae Q= 8.61574711E+02 - 1 1 -3.07864828E+02 # TYe(1,1)/Ye(1,1) - 2 2 -3.07858714E+02 # TYe(2,2)/Ye(2,2) - 3 3 -3.06135419E+02 # TYe(3,3)/Ye(3,3) -Block MSOFT Q= 8.61574711E+02 - 1 2.12674076E+02 # MassB - 2 3.82588792E+02 # MassWB - 3 1.11445312E+03 # MassG - 21 1.12097875E+05 # mHd2 - 22 -3.87890853E+05 # mHu2 - 31 3.58194540E+02 # SignedAbsSqrt(ml2(1,1)) - 32 3.58190838E+02 # SignedAbsSqrt(ml2(2,2)) - 33 3.57147481E+02 # SignedAbsSqrt(ml2(3,3)) - 34 2.21853755E+02 # SignedAbsSqrt(me2(1,1)) - 35 2.21841548E+02 # SignedAbsSqrt(me2(2,2)) - 36 2.18378375E+02 # SignedAbsSqrt(me2(3,3)) - 41 1.00845629E+03 # SignedAbsSqrt(mq2(1,1)) - 42 1.00845366E+03 # SignedAbsSqrt(mq2(2,2)) - 43 9.27719492E+02 # SignedAbsSqrt(mq2(3,3)) - 44 9.68183382E+02 # SignedAbsSqrt(mu2(1,1)) - 45 9.68180571E+02 # SignedAbsSqrt(mu2(2,2)) - 46 7.91856819E+02 # SignedAbsSqrt(mu2(3,3)) - 47 9.63436298E+02 # SignedAbsSqrt(md2(1,1)) - 48 9.63433521E+02 # SignedAbsSqrt(md2(2,2)) - 49 9.58488833E+02 # SignedAbsSqrt(md2(3,3)) + -1.06834219E-01 # ArcSin(Pole(ZH(2,2))) +Block HMIX Q= 8.64566212E+02 + 1 6.23808476E+02 # Mu + 2 9.67481745E+00 # vu/vd + 3 2.44130978E+02 # Sqrt(Sqr(vd) + Sqr(vu)) + 4 5.26379373E+05 # Sqr(MAh(2)) + 101 5.38320475E+04 # BMu + 102 2.50999305E+01 # vd + 103 2.42837245E+02 # vu +Block Au Q= 8.64566212E+02 + 1 1 -1.13135345E+03 # TYu(1,1)/Yu(1,1) + 2 2 -1.13134844E+03 # TYu(2,2)/Yu(2,2) + 3 3 -8.73285723E+02 # TYu(3,3)/Yu(3,3) +Block Ad Q= 8.64566212E+02 + 1 1 -1.38518584E+03 # TYd(1,1)/Yd(1,1) + 2 2 -1.38518119E+03 # TYd(2,2)/Yd(2,2) + 3 3 -1.29472423E+03 # TYd(3,3)/Yd(3,3) +Block Ae Q= 8.64566212E+02 + 1 1 -2.99353463E+02 # TYe(1,1)/Ye(1,1) + 2 2 -2.99347667E+02 # TYe(2,2)/Ye(2,2) + 3 3 -2.97714149E+02 # TYe(3,3)/Ye(3,3) +Block MSOFT Q= 8.64566212E+02 + 1 2.08850011E+02 # MassB + 2 3.87896014E+02 # MassWB + 3 1.11451862E+03 # MassG + 21 1.09331762E+05 # mHd2 + 22 -3.77162157E+05 # mHu2 + 31 3.53550629E+02 # SignedAbsSqrt(ml2(1,1)) + 32 3.53547066E+02 # SignedAbsSqrt(ml2(2,2)) + 33 3.52542851E+02 # SignedAbsSqrt(ml2(3,3)) + 34 2.22260279E+02 # SignedAbsSqrt(me2(1,1)) + 35 2.22248714E+02 # SignedAbsSqrt(me2(2,2)) + 36 2.18968838E+02 # SignedAbsSqrt(me2(3,3)) + 41 1.00699572E+03 # SignedAbsSqrt(mq2(1,1)) + 42 1.00699317E+03 # SignedAbsSqrt(mq2(2,2)) + 43 9.28348154E+02 # SignedAbsSqrt(mq2(3,3)) + 44 9.68157834E+02 # SignedAbsSqrt(mu2(1,1)) + 45 9.68155109E+02 # SignedAbsSqrt(mu2(2,2)) + 46 7.97126835E+02 # SignedAbsSqrt(mu2(3,3)) + 47 9.63384971E+02 # SignedAbsSqrt(md2(1,1)) + 48 9.63382289E+02 # SignedAbsSqrt(md2(2,2)) + 49 9.58601864E+02 # SignedAbsSqrt(md2(3,3)) )"; std::stringstream istr(slha_input); @@ -638,11 +638,10 @@ Block MSOFT Q= 8.61574711E+02 BOOST_TEST(false); } - MSSM_spectrum_generator spectrum_generator; - spectrum_generator.set_settings(settings); - spectrum_generator.run(qedqcd, input); - - MSSM_slha m = std::get<0>(spectrum_generator.get_models_slha()); + MSSM_slha m(input); + slha_io.fill(m); + m.calculate_DRbar_masses(); + m.reorder_DRbar_masses(); // ----------------------------------------------------- // decays with higher-order SM corrections @@ -655,63 +654,63 @@ Block MSOFT Q= 8.61574711E+02 // h -> b bbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFdFd(&m, 0, 2, 2), - 0.0024454872227556591, 7e-13); + 0.0024454872837716721, 7e-13); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFuFu(&m, 0, 1, 1), - 0.00011318500076009065, 3e-13); + 0.00011318500362355447, 3e-13); // h -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFeFe(&m, 0, 2, 2), - 0.00026234512352358479, 3e-13); + 0.00026234514953420564, 3e-13); // h -> W+ W- // BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_conjVWmVWm(&m, 0), // 0.0001976368796373175, 2e-12); BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_conjVWmVWm(&m, 0), - 0.00023570868278330426, 1e-3); + 0.00023570018177709328, 1e-3); // h -> Z Z // BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VZVZ(&m, 0), // 1.4826613977728886e-05, 3e-12); BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VZVZ(&m, 0), - 2.4985674072908062e-05, 1e-3); + 2.4998529690114355e-05, 1e-3); // ------------ loop-induces decays ------------ // h -> gluon gluon - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VGVG(&m, 0), 0.00029107801549747592, 2e-10); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VGVG(&m, 0), 0.00029107803462142189, 2e-10); // h -> gamma gamma // without 2L QCD for squark // BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 0), 6.3284545616000571e-06, 4e-11); // with 2L QCD for squark - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 0), 7.271047934944202e-06, 4e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 0), 7.2710487609165856e-06, 4e-11); // h -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 0), 2.2198080013381038e-06, 2e-10); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 0), 2.2198087946884208e-06, 2e-10); // pseudoscalar Higgs - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00043378057279629952, 4e-13); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00043378061307989104, 4e-13); // ------------ tree-level decays ------------ // Ah -> b bbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFdFd(&m, 1, 2, 2), - 0.88658108806852576, 4e-13); + 0.88658115467704091, 4e-13); // Ah -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFeFe(&m, 1, 2, 2), - 0.14370134308297239, 4e-13); + 0.14370135383550148, 4e-13); // Ah -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFuFu(&m, 1, 1, 1), - 6.1486061511096085e-06, 3e-13); + 6.1486066780391835e-06, 3e-13); // Ah -> W+ W- BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_conjVWmVWm(&m, 1), - 3.9267959281226782e-05, 2e-12); + 3.926795985114403e-05, 2e-12); // Ah -> Z Z BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VZVZ(&m, 1), - 1.0275363917478054e-05, 2e-12); + 1.0275363930925979e-05, 2e-12); // ------------ loop-induces decays ------------ // Ah -> gluon gluon - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00043378057279629952, 4e-13); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00043378061307989104, 4e-13); // Ah -> gamma gamma - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VPVP(&m, 1), 4.1843910938310874e-06, 4e-12); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VPVP(&m, 1), 4.1843914309546067e-06, 4e-12); // ----------------------------------------------------- // decays without higher-order SM corrections @@ -721,47 +720,47 @@ Block MSOFT Q= 8.61574711E+02 // h -> b bbar BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFdFd(&m, 0, 2, 2), - 0.0013683067977931381, 3e-13); + 0.0013683069345404055, 3e-13); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFuFu(&m, 0, 1, 1), - 7.6128484411953055e-05, 3e-13); + 7.6128491585600595e-05, 3e-13); // h -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFeFe(&m, 0, 2, 2), - 0.0002595600030762401, 3e-13); + 0.00025956002881119691, 3e-13); // h -> gamma gamma - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVP(&m, 0), 7.1507053618014637e-06, 5e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVP(&m, 0), 7.1507061728988442e-06, 5e-11); // h -> gluon gluon - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VGVG(&m, 0), 9.381223898157936e-05, 2e-10); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VGVG(&m, 0), 9.3812245440699979e-05, 2e-10); // h -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVZ(&m, 0), 2.2198080013381038e-06, 2e-10); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVZ(&m, 0), 2.2198087946884208e-06, 2e-10); // Ah -> gluon gluon - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00043378057279629952, 4e-13); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00043378061307989104, 4e-13); // Ah -> gamma gamma - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VPVP(&m, 1), 4.0630566804965507e-06, 4e-12); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VPVP(&m, 1), 4.0630569784682124e-06, 4e-12); // Ah -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VPVZ(&m, 1), 9.3179924792926659e-06, 2e-11); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VPVZ(&m, 1), 9.3179926421364644e-06, 2e-11); // h -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVZ(&m, 0), 2.2198080013381038e-06, 2e-10); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVZ(&m, 0), 2.2198087946884208e-06, 2e-10); // Sd5 -> Chi d BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Sd_to_ChiFd(&m, 5, 0, 0), - 0.16874114269702825, 9e-14); + 0.16874114148504477, 9e-14); // Su5 -> Cha d BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Su_to_barChaFd(&m, 4, 0, 0), - 6.1539819601771386, 8e-14); + 6.1539820064913817, 8e-14); // Sv -> Chi Fv BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Sv_to_FvChi(&m, 2, 0, 0), - 0.21565996349804162, 7e-15); + 0.21565996414399113, 7e-15); // Se -> Chi Fv BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Se_to_ChiFe(&m, 2, 0, 0), - 0.055308965207257907, 2e-13); + 0.055308969643458182, 2e-13); // hh(2) -> hh(1) hh(1) BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_hhhh(&m, 1, 0, 0), - 0.0055271603985390999, 5e-13); + 0.0055271603394791615, 5e-13); } diff --git a/test/test_THDMII_FlexibleDecay.cpp b/test/test_THDMII_FlexibleDecay.cpp index 2c0f820930..166182b7eb 100644 --- a/test/test_THDMII_FlexibleDecay.cpp +++ b/test/test_THDMII_FlexibleDecay.cpp @@ -255,11 +255,10 @@ Block UERMIX BOOST_TEST(false); } - THDMII_spectrum_generator spectrum_generator; - spectrum_generator.set_settings(settings); - spectrum_generator.run(qedqcd, input); - - THDMII_slha m = std::get<0>(spectrum_generator.get_models_slha()); + THDMII_slha m(input); + slha_io.fill(m); + m.calculate_DRbar_masses(); + m.reorder_DRbar_masses(); // ----------------------------------------------------- // decays with higher-order SM corrections @@ -270,16 +269,16 @@ Block UERMIX // h -> b bbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFdFd(&m, 0, 2, 2), - 0.00074272223389794053, 2e-13); + 0.00074272222469849497, 2e-13); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFuFu(&m, 0, 1, 1), - 0.00011992760375249642, 6e-15); + 0.0001199276031491833, 6e-15); // h -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFeFe(&m, 0, 2, 2), - 7.9645091090513334e-05, 1e-15); + 7.9645089645449552e-05, 1e-15); // h -> W+ W- BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_conjVWmVWm(&m, 0), - 0.00081324389707053922, 1e-4); + 0.0008129948152050411, 1e-4); // h -> Z Z BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VZVZ(&m, 0), 0.00010469488286769175, 1e-4); @@ -287,23 +286,23 @@ Block UERMIX // ------------ loop-induces decays ------------ // h -> gluon gluon - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VGVG(&m, 0), 0.00035337029100761187, 4e-13); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VGVG(&m, 0), 0.00035337028803345954, 4e-13); // h -> gamma gamma - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 0), 8.8199464537241665e-06, 3e-12); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVP(&m, 0), 8.8199463433627699e-06, 5e-12); // h -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 0), 5.9831753703986111e-06, 8e-12); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_VPVZ(&m, 0), 5.9831752385412133e-06, 8e-12); // Ah -> gluon gluon - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00078773836543896236, 3e-14); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00078773837698980077, 3e-14); // Ah -> gamma gamma - BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VPVP(&m, 1), 3.5731537311554876e-06, 3e-12); + BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_VPVP(&m, 1), 3.5731537651293608e-06, 3e-12); // Ah -> b bbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFdFd(&m, 1, 2, 2), - 1.0248504778252014, 2e-15); + 1.0248504807742072, 2e-15); // Ah -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFuFu(&m, 1, 1, 1), - 5.1682891794454512e-06, 2e-16); + 5.1682891827667072e-06, 2e-16); // ----------------------------------------------------- // decays without higher-order SM corrections @@ -315,27 +314,27 @@ Block UERMIX // h -> b bbar BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFdFd(&m, 0, 2, 2), - 0.00062168170474045936, 2e-15); + 0.0006216817003100219, 2e-15); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFuFu(&m, 0, 1, 1), - 0.00010014749564849829, 1e-16); + 0.00010014749542769435, 1e-16); // h -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_barFeFe(&m, 0, 2, 2), - 7.8811709644693243e-05, 1e-15); + 7.8811708216169657e-05, 1e-15); // ------------ loop-induces decays ------------ // h -> gluon gluon - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VGVG(&m, 0), 0.00020488527576778421, 4e-13); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VGVG(&m, 0), 0.00020488527557422341, 4e-13); // h -> gamma gamma - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVP(&m, 0), 8.6596828747315178e-06, 3e-12); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVP(&m, 0), 8.6596827650370546e-06, 5e-12); // h -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVZ(&m, 0), 5.9580043778320952e-06, 8e-12); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_hh_to_VPVZ(&m, 0), 5.9580042463527976e-06, 8e-12); // Ah -> gluon gluon - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00078773836543896236, 4e-13); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VGVG(&m, 1), 0.00078773837698980077, 4e-13); // Ah -> gamma gamma - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VPVP(&m, 1), 2.5449279002187577e-06, 3e-12); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VPVP(&m, 1), 2.5449279204866726e-06, 3e-12); // Ah -> gamma Z - BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VPVZ(&m, 1), 5.4527502373283228e-07, 8e-12); + BOOST_CHECK_CLOSE_FRACTION(decays_without_HO.partial_width_Ah_to_VPVZ(&m, 1), 5.4527502926727843e-07, 8e-12); } From 0e0b2aeb29fb5424c48386ae413cbb402510a838 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sat, 19 Mar 2022 08:01:13 +0100 Subject: [PATCH 112/477] updated CI to GM2Calc 2.1.0 --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 9aa0f7cdb8..b026f2233f 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -125,7 +125,7 @@ jobs: runs-on: ubuntu-latest container: - image: navir/opensuseleap-for-flexiblesusy:0.11.3 + image: navir/opensuseleap-for-flexiblesusy:0.11.4 strategy: matrix: From 95097ee4507ad83f8a4b0971ff920fe3475e3273 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Fri, 25 Mar 2022 19:31:53 +0100 Subject: [PATCH 113/477] hand balance models on CI (#417) --- .github/workflows/tests.yml | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b026f2233f..61ff480bb0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -134,7 +134,8 @@ jobs: env: FORMCALC_VERSION: '9.9' - MODELS: 'MSSM CMSSM CMSSMNoFV CMSSMCKM MSSMCPV MSSMNoFV NUHMSSMNoFVHimalaya ScalarLeptoquarks LRLR E6SSM SM THDMII MRSSM2 MRSSM2CKM' + MODELS1: 'MSSM THDMII ScalarLeptoquarks MSSMCPV CMSSM E6SSM CMSSMNoFV CMSSMCKM MSSMNoFV NUHMSSMNoFVHimalaya' + MODELS2: 'MRSSM2 LRLR SM MRSSM2CKM' steps: @@ -166,7 +167,10 @@ jobs: env: PART: ${{ matrix.PART }} run: | - models=$(ruby -e "MODELS=ARGV.drop(1); puts MODELS.each_slice(MODELS.length/2).to_a[ARGV[0].to_i-1].join(' ')" -- $PART $MODELS) + case "$PART" in + "1") models=${MODELS1} ;; + "2") models=${MODELS2} ;; + esac for m in $models; do ./createmodel --name=$m; done - name: "Set FS dependency directory" @@ -184,7 +188,11 @@ jobs: CXXCOMPILER: ${{ matrix.CXXCOMPILER }} PART: ${{ matrix.PART }} run: | - models=$(ruby -e "MODELS=ARGV.drop(1); puts MODELS.each_slice(MODELS.length/2).to_a[ARGV[0].to_i-1].join(',')" -- $PART $MODELS) + case "$PART" in + "1") models=${MODELS1} ;; + "2") models=${MODELS2} ;; + esac + models=$(ruby -e "puts ARGV.join(',')" -- $models) ./configure \ --with-cxx=$CXXCOMPILER \ --with-models=$models \ From 72186266b270d677c014847b27631a5100c2a48d Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 30 Mar 2022 21:20:04 +0200 Subject: [PATCH 114/477] updated FormCalc to 9.10 on CI --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 61ff480bb0..0faf69f929 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -133,7 +133,7 @@ jobs: PART: [1, 2] env: - FORMCALC_VERSION: '9.9' + FORMCALC_VERSION: '9.10' MODELS1: 'MSSM THDMII ScalarLeptoquarks MSSMCPV CMSSM E6SSM CMSSMNoFV CMSSMCKM MSSMNoFV NUHMSSMNoFVHimalaya' MODELS2: 'MRSSM2 LRLR SM MRSSM2CKM' From 88ae1b813212ea842e54195b392e9094a35dad43 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 31 Mar 2022 11:38:50 +0200 Subject: [PATCH 115/477] updated version of github actions on CI --- .github/workflows/tests.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 0faf69f929..11211a7194 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -49,7 +49,7 @@ jobs: brew install gsl - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Install conan run: | @@ -141,7 +141,7 @@ jobs: # action checks-out our repository directly under $GITHUB_WORKSPACE - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Activate Wolfram Engine env: @@ -276,7 +276,7 @@ jobs: done - name: (Optional) Save logs in case of an error - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 if: failure() with: name: ${{matrix.CXXCOMPILER}}-${{matrix.LOOPLIBRARY}}_test-logs From b0ff44a9c0bab50e3793dc797b65cc5277a315e3 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Mon, 4 Apr 2022 10:51:58 +0200 Subject: [PATCH 116/477] small performance improvement of Phi(x,y,z) function ported from GM2Calc 2.1.0 --- src/threshold_loop_functions.cpp | 63 +++++++++++++++++++------------- 1 file changed, 37 insertions(+), 26 deletions(-) diff --git a/src/threshold_loop_functions.cpp b/src/threshold_loop_functions.cpp index 19c2ba0ebe..64b693e963 100644 --- a/src/threshold_loop_functions.cpp +++ b/src/threshold_loop_functions.cpp @@ -1956,28 +1956,33 @@ namespace { return 2.343907238689459; } - const double Pi = 3.141592653589793; + const double pi23 = 3.2898681336964529; // Pi^2/3 const auto lambda = std::sqrt(lambda_2(u,v)); if (is_equal(u, v, eps)) { - return (-(sqr(std::log(u))) - + 2*sqr(std::log((1 - lambda)/2.)) - - 4*dilog((1 - lambda)/2.) - + sqr(Pi)/3.)/lambda; + return (- sqr(std::log(u)) + + 2*sqr(std::log(0.5*(1 - lambda))) + - 4*dilog(0.5*(1 - lambda)) + + pi23)/lambda; } - return (-(std::log(u)*std::log(v)) - + 2*std::log((1 - lambda + u - v)/2.)*std::log((1 - lambda - u + v)/2.) - - 2*dilog((1 - lambda + u - v)/2.) - - 2*dilog((1 - lambda - u + v)/2.) - + sqr(Pi)/3.)/lambda; + return (- std::log(u)*std::log(v) + + 2*std::log(0.5*(1 - lambda + u - v))*std::log(0.5*(1 - lambda - u + v)) + - 2*dilog(0.5*(1 - lambda + u - v)) + - 2*dilog(0.5*(1 - lambda - u + v)) + + pi23)/lambda; + } + + /// clausen_2(2*acos(x)) + double cl2acos(double x) noexcept + { + return clausen_2(2*std::acos(x)); } /// lambda^2(u,v) < 0, u = 1 - double phi_neg_1v(double v, double lambda) noexcept + double phi_neg_1v(double v) noexcept { - return 2*(+ clausen_2(2*std::acos((2 - v)/2)) - + 2*clausen_2(2*std::acos(0.5*std::sqrt(v))))/lambda; + return 2*(cl2acos(1 - 0.5*v) + 2*cl2acos(0.5*std::sqrt(v))); } /// lambda^2(u,v) < 0; note: phi_neg(u,v) = phi_neg(v,u) @@ -1986,27 +1991,30 @@ namespace { const double eps = 1.0e-7; if (is_equal(u, 1.0, eps) && is_equal(v, 1.0, eps)) { + // -I/9 (Pi^2 - 36 PolyLog[2, (1 - I Sqrt[3])/2])/Sqrt[3] return 2.343907238689459; } const auto lambda = std::sqrt(-lambda_2(u,v)); + if (is_equal(u, v, eps)) { + return 4*clausen_2(2*std::asin(std::sqrt(0.25/u)))/lambda; + } + if (is_equal(u, 1.0, eps)) { - return phi_neg_1v(v, lambda); + return phi_neg_1v(v)/lambda; } if (is_equal(v, 1.0, eps)) { - return phi_neg_1v(u, lambda); + return phi_neg_1v(u)/lambda; } - if (is_equal(u, v, eps)) { - return 2*(2*clausen_2(2*std::acos(1/(2.*std::sqrt(u)))) - + clausen_2(2*std::acos((-1 + 2*u)/(2.*std::abs(u)))))/lambda; - } + const auto sqrtu = std::sqrt(u); + const auto sqrtv = std::sqrt(v); - return 2*(+ clausen_2(2*std::acos((1 + u - v)/(2.*std::sqrt(u)))) - + clausen_2(2*std::acos((1 - u + v)/(2.*std::sqrt(v)))) - + clausen_2(2*std::acos((-1 + u + v)/(2.*std::sqrt(u*v)))))/lambda; + return 2*(+ cl2acos(0.5*(1 + u - v)/sqrtu) + + cl2acos(0.5*(1 - u + v)/sqrtv) + + cl2acos(0.5*(-1 + u + v)/(sqrtu*sqrtv)))/lambda; } /** @@ -2019,7 +2027,7 @@ namespace { { const auto lambda = lambda_2(u,v); - if (is_zero(lambda, std::numeric_limits::epsilon())) { + if (is_zero(lambda, 1e-11)) { // phi_uv is always multiplied by lambda. So, in order to // avoid nans if lambda == 0, we simply return 0 return 0.0; @@ -2029,11 +2037,14 @@ namespace { if (u <= 1 && v <= 1) { return phi_pos(u,v); } - if (u >= 1 && v/u <= 1) { - return phi_pos(1./u,v/u)/u; + const auto oou = 1/u; + const auto vou = v/u; + if (u >= 1 && vou <= 1) { + return phi_pos(oou,vou)*oou; } // v >= 1 && u/v <= 1 - return phi_pos(1./v,u/v)/v; + const auto oov = 1/v; + return phi_pos(oov,1/vou)*oov; } return phi_neg(u,v); From d16a9b68f12fcd6e7c9728c594b21b5a60a79910 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Wed, 6 Apr 2022 06:05:29 +0200 Subject: [PATCH 117/477] use the user-provided precision in the root finder and minimizer (#419) Fixes #418 --- meta/Constraint.m | 41 ++++++++++++++++++++++++++++++----------- src/problems.cpp | 44 ++++++++++++++++++++++++++++++++++++++++++++ src/problems.hpp | 8 ++++++++ 3 files changed, 82 insertions(+), 11 deletions(-) diff --git a/meta/Constraint.m b/meta/Constraint.m index 7e06db4537..ce4ab39650 100644 --- a/meta/Constraint.m +++ b/meta/Constraint.m @@ -150,12 +150,22 @@ functionWrapper = CreateMinimizationFunctionWrapper[functionName,dim,parameters, Parameters`DecreaseIndexLiterals[function], modelPrefix]; - callMinimizer = functionWrapper <> "\n" <> startPoint <> - "Minimizer<" <> dimStr <> - "> minimizer(" <> functionName <> ", 100, 1.0e-2);\n" <> - "const int status = minimizer.minimize(start_point);\n" <> - "VERBOSE_MSG(\"\\tminimizer status: \" << gsl_strerror(status));\n"; - "\n{" <> TextFormatting`IndentText[callMinimizer] <> "}\n" + callMinimizer = functionWrapper <> " +const char* par_str = \"" <> ToString[CConversion`ToValidCSymbol /@ parameters] <> "\"; +MODEL->get_problems().unflag_no_minimum(par_str); + +" <> startPoint <> +"Minimizer<" <> dimStr <> "> minimizer(" <> functionName <> ", 100, " <> modelPrefix <> "get_precision()); + +const int status = minimizer.minimize(start_point); + +VERBOSE_MSG(\"\\tminimizer status: \" << gsl_strerror(status)); + +if (status != GSL_SUCCESS) { + MODEL->get_problems().flag_no_minimum(par_str, status); +} +"; + "\n{\n" <> TextFormatting`IndentText[callMinimizer] <> "}\n\n" ]; CreateRootFinderFunctionWrapper[functionName_String, dim_Integer, parameters_List, function_List, modelPrefix_String] := @@ -181,11 +191,20 @@ functionWrapper = CreateRootFinderFunctionWrapper[functionName,dim,parameters, Parameters`DecreaseIndexLiterals[function], modelPrefix]; - callRootFinder = functionWrapper <> "\n" <> startPoint <> - "Root_finder<" <> dimStr <> - "> root_finder(" <> functionName <> ", 100, 1.0e-2);\n" <> - "const int status = root_finder.find_root(start_point);\n" <> - "VERBOSE_MSG(\"\\troot finder status: \" << gsl_strerror(status));\n"; + callRootFinder = functionWrapper <> " +const char* par_str = \"" <> ToString[CConversion`ToValidCSymbol /@ parameters] <> "\"; +MODEL->get_problems().unflag_no_root(par_str); + +" <> startPoint <> +"Root_finder<" <> dimStr <> "> root_finder(" <> functionName <> ", 100, " <> modelPrefix <> "get_precision()); +const int status = root_finder.find_root(start_point); + +VERBOSE_MSG(\"\\troot finder status: \" << gsl_strerror(status)); + +if (status != GSL_SUCCESS) { + MODEL->get_problems().flag_no_root(par_str, status); +} +"; "\n{\n" <> TextFormatting`IndentText[callRootFinder] <> "}\n\n" ]; diff --git a/src/problems.cpp b/src/problems.cpp index 11de88c2e9..1a46c294e0 100644 --- a/src/problems.cpp +++ b/src/problems.cpp @@ -69,6 +69,8 @@ void Problems::clear() std::fill(pole_tachyons.begin(), pole_tachyons.end(), 0); std::fill(failed_pole_mass_convergence.begin(), failed_pole_mass_convergence.end(), 0); non_pert_pars.clear(); + failed_minimum.clear(); + failed_root.clear(); exception_msg = ""; failed_ewsb = false; failed_ewsb_tree_level = false; @@ -86,6 +88,8 @@ void Problems::add(const Problems& other) vector_or(pole_tachyons, other.pole_tachyons); vector_or(failed_pole_mass_convergence, other.failed_pole_mass_convergence); map_or(non_pert_pars, other.non_pert_pars); + map_or(failed_minimum, other.failed_minimum); + map_or(failed_root, other.failed_root); if (exception_msg.empty() && !other.exception_msg.empty()) exception_msg = other.exception_msg; @@ -109,6 +113,8 @@ unsigned Problems::number_of_problems() const if (failed_ewsb_tree_level) count++; if (non_perturbative || have_non_perturbative_parameter()) count++; if (failed_sinThetaW_convergence) count++; + if (no_minimum()) count++; + if (no_root()) count++; if (have_thrown()) count++; if (have_failed_pole_mass_convergence()) count++; return count; @@ -183,6 +189,14 @@ std::vector Problems::get_problem_strings() const strings.emplace_back(str); } + for (const auto& m: failed_minimum) { + strings.emplace_back(std::string("no minimum for parameters ") + m.first); + } + + for (const auto& m: failed_root) { + strings.emplace_back(std::string("no root for parameters ") + m.first); + } + strings.shrink_to_fit(); return strings; @@ -311,6 +325,16 @@ void Problems::flag_no_sinThetaW_convergence() failed_sinThetaW_convergence = true; } +void Problems::flag_no_minimum(const std::string& msg, int status) +{ + failed_minimum[msg] = status; +} + +void Problems::flag_no_root(const std::string& msg, int status) +{ + failed_root[msg] = status; +} + void Problems::unflag_bad_mass(int particle) { bad_masses.at(particle) = false; @@ -377,6 +401,16 @@ void Problems::unflag_no_sinThetaW_convergence() failed_sinThetaW_convergence = false; } +void Problems::unflag_no_minimum(const std::string& msg) +{ + failed_minimum.erase(msg); +} + +void Problems::unflag_no_root(const std::string& msg) +{ + failed_root.erase(msg); +} + bool Problems::is_bad_mass(int particle) const { return bad_masses.at(particle); @@ -452,6 +486,16 @@ bool Problems::no_sinThetaW_convergence() const return failed_sinThetaW_convergence; } +bool Problems::no_minimum() const +{ + return !failed_minimum.empty(); +} + +bool Problems::no_root() const +{ + return !failed_root.empty(); +} + std::vector Problems::get_bad_masses() const { return bad_masses; diff --git a/src/problems.hpp b/src/problems.hpp index 8888c9d55b..5347fc9a3a 100644 --- a/src/problems.hpp +++ b/src/problems.hpp @@ -46,6 +46,8 @@ class Problems { void flag_no_pole_mass_convergence(int particle); void flag_non_perturbative_parameter(int parameter, double value, double scale, double threshold = 0.); void flag_no_sinThetaW_convergence(); + void flag_no_minimum(const std::string& msg, int status); + void flag_no_root(const std::string& msg, int status); void unflag_bad_mass(int particle); void unflag_all_bad_masses(); @@ -60,6 +62,8 @@ class Problems { void unflag_non_perturbative_parameter(int parameter); void unflag_all_non_perturbative_parameters(); void unflag_no_sinThetaW_convergence(); + void unflag_no_minimum(const std::string& msg); + void unflag_no_root(const std::string& msg); bool is_bad_mass(int particle) const; bool is_running_tachyon(int particle) const; @@ -75,6 +79,8 @@ class Problems { bool no_ewsb_tree_level() const; bool no_perturbative() const; bool no_sinThetaW_convergence() const; + bool no_minimum() const; + bool no_root() const; void add(const Problems&); ///< add problems from other class void clear(); ///< clear all problems @@ -115,6 +121,8 @@ class Problems { std::vector pole_tachyons; ///< tachyonic particles (pole mass) std::vector failed_pole_mass_convergence; ///< no convergence during pole mass calculation std::map non_pert_pars; ///< non-perturbative parmeters + std::map failed_minimum; ///< no minimum found (message, status code) + std::map failed_root; ///< no root found (message, status code) std::string exception_msg; ///< exception message bool failed_ewsb{false}; ///< no EWSB bool failed_ewsb_tree_level{false}; ///< no tree-level EWSB From 15e2863aecd8c7834f6510debae9b379e573c277 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Thu, 7 Apr 2022 17:20:33 +0200 Subject: [PATCH 118/477] more precise error message from ConvertColourStructureToColorMathConvention --- meta/CXXDiagrams.m | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/meta/CXXDiagrams.m b/meta/CXXDiagrams.m index 871771ff5f..d907b757e9 100644 --- a/meta/CXXDiagrams.m +++ b/meta/CXXDiagrams.m @@ -536,7 +536,9 @@ Utils`AssertWithMessage[colourRep1 == colourRep2, "CXXDiagrams`ConvertColourStructureToColorMathConvention[]: " <> "Two colour indices in Kronecker delta that come from fields " <> - "of incompatible representations."]; + "of incompatible representations: Field1 = " <> + ToString[{colouredField1, colourRep1}] <> ", Field2 = " <> + ToString[{colouredField2, colourRep2}]]; (* FIXME: Are these orderings correct? *) Switch[{colourRep1}, From 102ae79f0f526642a8b1a29757189246a7bc8b39 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Fri, 8 Apr 2022 14:55:12 +0200 Subject: [PATCH 119/477] Bugfix: temporarily enforce calculation of pole masses in intermediate iteration steps --- meta/Constraint.m | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/meta/Constraint.m b/meta/Constraint.m index ce4ab39650..8ba6595e5e 100644 --- a/meta/Constraint.m +++ b/meta/Constraint.m @@ -129,6 +129,8 @@ type = CConversion`CreateCType[CConversion`MatrixType[CConversion`realScalarCType, dim, 1]]; stype = CConversion`CreateCType[CConversion`ScalarType[CConversion`realScalarCType]]; "auto " <> functionName <> " = [&](const "<> type <> "& x) { +" <> TextFormatting`IndentText[CreateTemporaryForceOutputRAII[modelPrefix]] <> " + " <> TextFormatting`IndentText[SetModelParametersFromVector[modelPrefix,"x",parameters]] <> " " <> modelPrefix <> "calculate_DRbar_masses(); " <> TextFormatting`IndentText[Parameters`CreateLocalConstRefs[function]] <> " @@ -168,10 +170,18 @@ "\n{\n" <> TextFormatting`IndentText[callMinimizer] <> "}\n\n" ]; +CreateTemporaryForceOutputRAII[modelPrefix_String] := "\ +// temporarily enforce calculation of pole masses +const bool force_output = " <> modelPrefix <> "do_force_output(); +const auto tmp_force_output = make_raii_guard([&] { " <> modelPrefix <> "do_force_output(force_output); }); +" <> modelPrefix <> "do_force_output(true);"; + CreateRootFinderFunctionWrapper[functionName_String, dim_Integer, parameters_List, function_List, modelPrefix_String] := Module[{type}, type = CConversion`CreateCType[CConversion`MatrixType[CConversion`realScalarCType, dim, 1]]; "auto " <> functionName <> " = [&](const "<> type <> "& x) { +" <> TextFormatting`IndentText[CreateTemporaryForceOutputRAII[modelPrefix]] <> " + " <> TextFormatting`IndentText[SetModelParametersFromVector[modelPrefix,"x",parameters]] <> " " <> modelPrefix <> "calculate_DRbar_masses(); " <> TextFormatting`IndentText[Parameters`CreateLocalConstRefs[function]] <> " From 768c092dff4feeb3f7230c1a1ffc992fc0f459da Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Fri, 8 Apr 2022 11:50:27 +0200 Subject: [PATCH 120/477] identify colour deltas in models with 3 and -3 fields Handle colour deltas in models where there are fundamental (i.e. unconjugated) fields in 3 and -3 representations. --- meta/CXXDiagrams.m | 83 +++++++++++++++++++++++++++++++++------------- 1 file changed, 60 insertions(+), 23 deletions(-) diff --git a/meta/CXXDiagrams.m b/meta/CXXDiagrams.m index d907b757e9..e884fd3e43 100644 --- a/meta/CXXDiagrams.m +++ b/meta/CXXDiagrams.m @@ -517,7 +517,7 @@ ConvertColourStructureToColorMathConvention[indexedFields_List, KroneckerDeltaColourVertex[cIndex1_, cIndex2_]] := - Module[{colouredField1, colouredField2, colourRep1, colourRep2}, + Module[{colouredField1, colouredField2, colourRep1, colourRep2, errorMessage}, (* If the result has a color Delta, we need to find out if it's adj. or fundamental because they are represented by different symbols in ColorMath. Also, in ColorMath the order of indices matters. As stated in ColorMath tutorial notebook: @@ -533,28 +533,65 @@ colourRep1 = SARAH`getColorRep[colouredField1]; colourRep2 = SARAH`getColorRep[colouredField2]; - Utils`AssertWithMessage[colourRep1 == colourRep2, - "CXXDiagrams`ConvertColourStructureToColorMathConvention[]: " <> - "Two colour indices in Kronecker delta that come from fields " <> - "of incompatible representations: Field1 = " <> - ToString[{colouredField1, colourRep1}] <> ", Field2 = " <> - ToString[{colouredField2, colourRep2}]]; - - (* FIXME: Are these orderings correct? *) - Switch[{colourRep1}, - {SARAH`T}, If[RemoveLorentzConjugation[colouredField1] === colouredField1, - ColorMath`CMdelta[cIndex2, cIndex1], - ColorMath`CMdelta[cIndex1, cIndex2] - ], - {O}, ColorMath`CMDelta[cIndex2, cIndex1], - _, - Print["CXXDiagrams`ConvertColourStructureToColorMathConvention[]: " <> - "Two colour indices in Kronecker delta that come from fields " <> - "or representations we cannot handle: " <> - ToString[{colourRep1, colourRep2}]]; - Quit[1]; - ] - ]; + errorMessage = "CXXDiagrams`ConvertColourStructureToColorMathConvention[]: " <> + "Two colour indices in Kronecker delta that come from fields " <> + "of incompatible representations: Field1 = " <> + ToString[{colouredField1, colourRep1}] <> ", Field2 = " <> + ToString[{colouredField2, colourRep2}]; + + (* FIXME: Are these orderings correct? *) + Switch[{colourRep1, colourRep2}, + {SARAH`T, SARAH`T}, + (* 2 is conjugated, 1 is not *) + If[RemoveLorentzConjugation[colouredField1] === colouredField1 && RemoveLorentzConjugation[colouredField2] =!= colouredField2, + ColorMath`CMdelta[cIndex2, cIndex1], + (* 1 is conjugated, 2 is not *) + If[RemoveLorentzConjugation[colouredField2] === colouredField2 && RemoveLorentzConjugation[colouredField1] =!= colouredField1, + ColorMath`CMdelta[cIndex1, cIndex2], + Utils`AssertWithMessage[False, errorMessage] + ] + ], + {-SARAH`T, -SARAH`T}, + (* 2 is conjugated, 1 is not *) + If[RemoveLorentzConjugation[colouredField1] === colouredField1 && RemoveLorentzConjugation[colouredField2] =!= colouredField2, + ColorMath`CMdelta[cIndex1, cIndex2], + (* 1 is conjugated, 2 is not *) + If[RemoveLorentzConjugation[colouredField2] === colouredField2 && RemoveLorentzConjugation[colouredField1] =!= colouredField1, + ColorMath`CMdelta[cIndex2, cIndex1], + Utils`AssertWithMessage[False, errorMessage] + ] + ], + {SARAH`T, -SARAH`T}, + (* none is conjugated *) + If[RemoveLorentzConjugation[colouredField1] === colouredField1 && RemoveLorentzConjugation[colouredField2] === colouredField2, + ColorMath`CMdelta[cIndex2, cIndex1], + (* both are conjugated *) + If[RemoveLorentzConjugation[colouredField1] =!= colouredField1 && RemoveLorentzConjugation[colouredField2] =!= colouredField2, + ColorMath`CMdelta[cIndex1, cIndex2], + (* error if only one is conjugated *) + Utils`AssertWithMessage[False, errorMessage] + ] + ], + {-SARAH`T, SARAH`T}, + (* none is conjugated *) + If[RemoveLorentzConjugation[colouredField1] === colouredField1 && RemoveLorentzConjugation[colouredField2] === colouredField2, + ColorMath`CMdelta[cIndex1, cIndex2], + (* both are conjugated *) + If[RemoveLorentzConjugation[colouredField1] =!= colouredField1 && RemoveLorentzConjugation[colouredField2] =!= colouredField2, + ColorMath`CMdelta[cIndex2, cIndex1], + (* error if only one is conjugated *) + Utils`AssertWithMessage[False, errorMessage] + ] + ], + {O, O}, ColorMath`CMDelta[cIndex2, cIndex1], + _, + Print["CXXDiagrams`ConvertColourStructureToColorMathConvention[]: " <> + "Two colour indices in Kronecker delta that come from fields " <> + "or representations we cannot handle: " <> + ToString[{colourRep1, colourRep2}]]; + Quit[1]; + ] +]; ConvertColourStructureToColorMathConvention[fields_List, AdjointlyColouredVertex[cIndex1_, cIndex2_, cIndex3_] GellMannVertex[cIndex3_, cIndex4_, cIndex5_]] := From 1d35c2662129e2abb80e682d0dbebb58493adf26 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Mon, 11 Apr 2022 19:11:07 +0200 Subject: [PATCH 121/477] auto update used github actions --- .github/dependabot.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000000..23c1e85e95 --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,11 @@ +# Set update schedule for GitHub Actions + +version: 2 +updates: + + - package-ecosystem: "github-actions" + directory: "/" + schedule: + # Check for updates to GitHub Actions every weekday + interval: "daily" + From 6205ce4dbc66183ca77ddd1cfa3dd8dfeb33270e Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Tue, 12 Apr 2022 20:36:24 +0200 Subject: [PATCH 122/477] CI updated to clang12 and boost 1.75.0 --- .github/workflows/package-models.yml | 8 ++++---- .github/workflows/tests.yml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/package-models.yml b/.github/workflows/package-models.yml index bb576cf1b1..0aa24a0e88 100644 --- a/.github/workflows/package-models.yml +++ b/.github/workflows/package-models.yml @@ -11,7 +11,7 @@ env: jobs: package-models: name: Create model packages - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest container: image: navir/opensuseleap-for-flexiblesusy @@ -76,7 +76,7 @@ jobs: upload-models: name: Upload packages to git needs: package-models - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout @@ -110,7 +110,7 @@ jobs: upload-slha-outputs: name: Upload SLHA to git needs: package-models - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout @@ -144,7 +144,7 @@ jobs: upload-release: name: Upload to release needs: package-models - runs-on: ubuntu-20.04 + runs-on: ubuntu-latest steps: - name: Checkout code diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 11211a7194..6f749afd46 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -125,7 +125,7 @@ jobs: runs-on: ubuntu-latest container: - image: navir/opensuseleap-for-flexiblesusy:0.11.4 + image: navir/opensuseleap-for-flexiblesusy:0.11.5 strategy: matrix: From cb9049c006f80e4328b90901b8f976b6be75ea75 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 13 Apr 2022 11:17:55 +0200 Subject: [PATCH 123/477] removed unused variable --- test/test_MRSSM2_l_to_lgamma.cpp | 3 --- 1 file changed, 3 deletions(-) diff --git a/test/test_MRSSM2_l_to_lgamma.cpp b/test/test_MRSSM2_l_to_lgamma.cpp index d867e2cfa4..45b12c292f 100644 --- a/test/test_MRSSM2_l_to_lgamma.cpp +++ b/test/test_MRSSM2_l_to_lgamma.cpp @@ -63,9 +63,6 @@ BOOST_AUTO_TEST_CASE( test_l_to_lgamma ) MRSSM2_slha m = setup_MRSSM2(input, qedqcd); - using MRSSM2_cxx_diagrams::fields::Fe; - auto width = MRSSM2_l_to_lgamma::lepton_total_decay_width(std::array {1}, std::array {0}, m, qedqcd); - Physical_input physical_inputs; auto brMuEGamma = MRSSM2_l_to_lgamma::calculate_Fe_to_Fe_VP(1, 0, m, qedqcd, physical_inputs); From c5546914422039ffa9a95bdcb44556a1734d7514 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 14 Apr 2022 11:44:26 +0200 Subject: [PATCH 124/477] updated CI to gcc11 --- .github/workflows/package-models.yml | 2 +- .github/workflows/tests.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/package-models.yml b/.github/workflows/package-models.yml index 0aa24a0e88..7bf0919e05 100644 --- a/.github/workflows/package-models.yml +++ b/.github/workflows/package-models.yml @@ -13,7 +13,7 @@ jobs: name: Create model packages runs-on: ubuntu-latest container: - image: navir/opensuseleap-for-flexiblesusy + image: navir/opensuseleap-for-flexiblesusy:latest strategy: matrix: diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 6f749afd46..b6ad5207e0 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -125,7 +125,7 @@ jobs: runs-on: ubuntu-latest container: - image: navir/opensuseleap-for-flexiblesusy:0.11.5 + image: navir/opensuseleap-for-flexiblesusy:0.12.0 strategy: matrix: From 30f8812079ec5821f751396b3555d64069827516 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Fri, 15 Apr 2022 00:20:24 +0200 Subject: [PATCH 125/477] continue tests even if some element of build matrix fails --- .github/workflows/tests.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b6ad5207e0..a868f98e5e 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -128,6 +128,7 @@ jobs: image: navir/opensuseleap-for-flexiblesusy:0.12.0 strategy: + fail-fast: false matrix: CXXCOMPILER: [g++, clang++] PART: [1, 2] From 1cf72db7cafbfcf6dad3217c5af39d1042c2e3d2 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sat, 16 Apr 2022 17:58:18 +0200 Subject: [PATCH 126/477] updated JSON library --- README.rst | 3 + nlohmann/json.hpp | 6338 ++++++--------------------------------------- 2 files changed, 841 insertions(+), 5500 deletions(-) diff --git a/README.rst b/README.rst index ee0bae0426..2c046eeabd 100644 --- a/README.rst +++ b/README.rst @@ -968,6 +968,8 @@ are listed: * ``models/`` This is the output directory where the generated C++ code for the spectrum generators will be stored. +* ``nlohmann/`` contains the nlohmann_ JSON library + * ``Output/`` contains SARAHs model-specific output files * ``sarah/`` contains SARAH model files shipped with FlexibleSUSY @@ -1013,6 +1015,7 @@ References .. _COLLIER: https://collier.hepforge.org .. _Himalaya: https://github.com/Himalaya-Library/Himalaya .. _TSIL: https://www.niu.edu/spmartin/tsil +.. _nlohmann: https://github.com/nlohmann/json .. _`FlexibleSUSY model file`: doc/model_file.rst .. _`FlexibleEFTHiggs`: doc/FlexibleEFTHiggs.rst diff --git a/nlohmann/json.hpp b/nlohmann/json.hpp index 87475ab31e..cb27e05811 100644 --- a/nlohmann/json.hpp +++ b/nlohmann/json.hpp @@ -1,12 +1,12 @@ /* __ _____ _____ _____ __| | __| | | | JSON for Modern C++ -| | |__ | | | | | | version 3.10.4 +| | |__ | | | | | | version 3.10.5 |_____|_____|_____|_|___| https://github.com/nlohmann/json Licensed under the MIT License . SPDX-License-Identifier: MIT -Copyright (c) 2013-2019 Niels Lohmann . +Copyright (c) 2013-2022 Niels Lohmann . Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal @@ -27,12 +27,21 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +/****************************************************************************\ + * Note on documentation: The source files contain links to the online * + * documentation of the public API at https://json.nlohmann.me. This URL * + * contains the most recent documentation and should also be applicable to * + * previous versions; documentation for deprecated functions is not * + * removed, but marked deprecated. See "Generate documentation" section in * + * file doc/README.md. * +\****************************************************************************/ + #ifndef INCLUDE_NLOHMANN_JSON_HPP_ #define INCLUDE_NLOHMANN_JSON_HPP_ #define NLOHMANN_JSON_VERSION_MAJOR 3 #define NLOHMANN_JSON_VERSION_MINOR 10 -#define NLOHMANN_JSON_VERSION_PATCH 4 +#define NLOHMANN_JSON_VERSION_PATCH 5 #include // all_of, find, for_each #include // nullptr_t, ptrdiff_t, size_t @@ -2325,6 +2334,66 @@ using is_detected_convertible = #define JSON_HAS_CPP_11 #endif +#if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM) + #ifdef JSON_HAS_CPP_17 + #if defined(__cpp_lib_filesystem) + #define JSON_HAS_FILESYSTEM 1 + #elif defined(__cpp_lib_experimental_filesystem) + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 + #elif !defined(__has_include) + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 + #elif __has_include() + #define JSON_HAS_FILESYSTEM 1 + #elif __has_include() + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 1 + #endif + + // std::filesystem does not work on MinGW GCC 8: https://sourceforge.net/p/mingw-w64/bugs/737/ + #if defined(__MINGW32__) && defined(__GNUC__) && __GNUC__ == 8 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + + // no filesystem support before GCC 8: https://en.cppreference.com/w/cpp/compiler_support + #if defined(__GNUC__) && !defined(__clang__) && __GNUC__ < 8 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + + // no filesystem support before Clang 7: https://en.cppreference.com/w/cpp/compiler_support + #if defined(__clang_major__) && __clang_major__ < 7 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + + // no filesystem support before MSVC 19.14: https://en.cppreference.com/w/cpp/compiler_support + #if defined(_MSC_VER) && _MSC_VER < 1940 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + + // no filesystem support before iOS 13 + #if defined(__IPHONE_OS_VERSION_MIN_REQUIRED) && __IPHONE_OS_VERSION_MIN_REQUIRED < 130000 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + + // no filesystem support before macOS Catalina + #if defined(__MAC_OS_X_VERSION_MIN_REQUIRED) && __MAC_OS_X_VERSION_MIN_REQUIRED < 101500 + #undef JSON_HAS_FILESYSTEM + #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #endif + #endif +#endif + +#ifndef JSON_HAS_EXPERIMENTAL_FILESYSTEM + #define JSON_HAS_EXPERIMENTAL_FILESYSTEM 0 +#endif + +#ifndef JSON_HAS_FILESYSTEM + #define JSON_HAS_FILESYSTEM 0 +#endif + // disable documentation warnings on clang #if defined(__clang__) #pragma clang diagnostic push @@ -2332,7 +2401,7 @@ using is_detected_convertible = #pragma clang diagnostic ignored "-Wdocumentation-unknown-command" #endif -// allow to disable exceptions +// allow disabling exceptions #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(JSON_NOEXCEPTION) #define JSON_THROW(exception) throw exception #define JSON_TRY try @@ -2366,7 +2435,7 @@ using is_detected_convertible = #define JSON_INTERNAL_CATCH JSON_INTERNAL_CATCH_USER #endif -// allow to override assert +// allow overriding assert #if !defined(JSON_ASSERT) #include // assert #define JSON_ASSERT(x) assert(x) @@ -2734,34 +2803,8 @@ namespace detail // exceptions // //////////////// -/*! -@brief general exception of the @ref basic_json class - -This class is an extension of `std::exception` objects with a member @a id for -exception ids. It is used as the base class for all exceptions thrown by the -@ref basic_json class. This class can hence be used as "wildcard" to catch -exceptions. - -Subclasses: -- @ref parse_error for exceptions indicating a parse error -- @ref invalid_iterator for exceptions indicating errors with iterators -- @ref type_error for exceptions indicating executing a member function with - a wrong type -- @ref out_of_range for exceptions indicating access out of the defined range -- @ref other_error for exceptions indicating other library errors - -@internal -@note To have nothrow-copy-constructible exceptions, we internally use - `std::runtime_error` which can cope with arbitrary-length error messages. - Intermediate strings are built with static functions and then passed to - the actual constructor. -@endinternal - -@liveexample{The following code shows how arbitrary library exceptions can be -caught.,exception} - -@since version 3.0.0 -*/ +/// @brief general exception of the @ref basic_json class +/// @sa https://json.nlohmann.me/api/basic_json/exception/ class exception : public std::exception { public: @@ -2776,7 +2819,7 @@ class exception : public std::exception protected: JSON_HEDLEY_NON_NULL(3) - exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} + exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} // NOLINT(bugprone-throw-keyword-missing) static std::string name(const std::string& ename, int id_) { @@ -2852,51 +2895,8 @@ class exception : public std::exception std::runtime_error m; }; -/*! -@brief exception indicating a parse error - -This exception is thrown by the library when a parse error occurs. Parse errors -can occur during the deserialization of JSON text, CBOR, MessagePack, as well -as when using JSON Patch. - -Member @a byte holds the byte index of the last read character in the input -file. - -Exceptions have ids 1xx. - -name / id | example message | description ------------------------------- | --------------- | ------------------------- -json.exception.parse_error.101 | parse error at 2: unexpected end of input; expected string literal | This error indicates a syntax error while deserializing a JSON text. The error message describes that an unexpected token (character) was encountered, and the member @a byte indicates the error position. -json.exception.parse_error.102 | parse error at 14: missing or wrong low surrogate | JSON uses the `\uxxxx` format to describe Unicode characters. Code points above above 0xFFFF are split into two `\uxxxx` entries ("surrogate pairs"). This error indicates that the surrogate pair is incomplete or contains an invalid code point. -json.exception.parse_error.103 | parse error: code points above 0x10FFFF are invalid | Unicode supports code points up to 0x10FFFF. Code points above 0x10FFFF are invalid. -json.exception.parse_error.104 | parse error: JSON patch must be an array of objects | [RFC 6902](https://tools.ietf.org/html/rfc6902) requires a JSON Patch document to be a JSON document that represents an array of objects. -json.exception.parse_error.105 | parse error: operation must have string member 'op' | An operation of a JSON Patch document must contain exactly one "op" member, whose value indicates the operation to perform. Its value must be one of "add", "remove", "replace", "move", "copy", or "test"; other values are errors. -json.exception.parse_error.106 | parse error: array index '01' must not begin with '0' | An array index in a JSON Pointer ([RFC 6901](https://tools.ietf.org/html/rfc6901)) may be `0` or any number without a leading `0`. -json.exception.parse_error.107 | parse error: JSON pointer must be empty or begin with '/' - was: 'foo' | A JSON Pointer must be a Unicode string containing a sequence of zero or more reference tokens, each prefixed by a `/` character. -json.exception.parse_error.108 | parse error: escape character '~' must be followed with '0' or '1' | In a JSON Pointer, only `~0` and `~1` are valid escape sequences. -json.exception.parse_error.109 | parse error: array index 'one' is not a number | A JSON Pointer array index must be a number. -json.exception.parse_error.110 | parse error at 1: cannot read 2 bytes from vector | When parsing CBOR or MessagePack, the byte vector ends before the complete value has been read. -json.exception.parse_error.112 | parse error at 1: error reading CBOR; last byte: 0xF8 | Not all types of CBOR or MessagePack are supported. This exception occurs if an unsupported byte was read. -json.exception.parse_error.113 | parse error at 2: expected a CBOR string; last byte: 0x98 | While parsing a map key, a value that is not a string has been read. -json.exception.parse_error.114 | parse error: Unsupported BSON record type 0x0F | The parsing of the corresponding BSON record type is not implemented (yet). -json.exception.parse_error.115 | parse error at byte 5: syntax error while parsing UBJSON high-precision number: invalid number text: 1A | A UBJSON high-precision number could not be parsed. - -@note For an input with n bytes, 1 is the index of the first character and n+1 - is the index of the terminating null byte or the end of file. This also - holds true when reading a byte vector (CBOR or MessagePack). - -@liveexample{The following code shows how a `parse_error` exception can be -caught.,parse_error} - -@sa - @ref exception for the base class of the library exceptions -@sa - @ref invalid_iterator for exceptions indicating errors with iterators -@sa - @ref type_error for exceptions indicating executing a member function with - a wrong type -@sa - @ref out_of_range for exceptions indicating access out of the defined range -@sa - @ref other_error for exceptions indicating other library errors - -@since version 3.0.0 -*/ +/// @brief exception indicating a parse error +/// @sa https://json.nlohmann.me/api/basic_json/parse_error/ class parse_error : public exception { public: @@ -2914,7 +2914,7 @@ class parse_error : public exception { std::string w = exception::name("parse_error", id_) + "parse error" + position_string(pos) + ": " + exception::diagnostics(context) + what_arg; - return parse_error(id_, pos.chars_read_total, w.c_str()); + return {id_, pos.chars_read_total, w.c_str()}; } template @@ -2923,7 +2923,7 @@ class parse_error : public exception std::string w = exception::name("parse_error", id_) + "parse error" + (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") + ": " + exception::diagnostics(context) + what_arg; - return parse_error(id_, byte_, w.c_str()); + return {id_, byte_, w.c_str()}; } /*! @@ -2948,43 +2948,8 @@ class parse_error : public exception } }; -/*! -@brief exception indicating errors with iterators - -This exception is thrown if iterators passed to a library function do not match -the expected semantics. - -Exceptions have ids 2xx. - -name / id | example message | description ------------------------------------ | --------------- | ------------------------- -json.exception.invalid_iterator.201 | iterators are not compatible | The iterators passed to constructor @ref basic_json(InputIT first, InputIT last) are not compatible, meaning they do not belong to the same container. Therefore, the range (@a first, @a last) is invalid. -json.exception.invalid_iterator.202 | iterator does not fit current value | In an erase or insert function, the passed iterator @a pos does not belong to the JSON value for which the function was called. It hence does not define a valid position for the deletion/insertion. -json.exception.invalid_iterator.203 | iterators do not fit current value | Either iterator passed to function @ref erase(IteratorType first, IteratorType last) does not belong to the JSON value from which values shall be erased. It hence does not define a valid range to delete values from. -json.exception.invalid_iterator.204 | iterators out of range | When an iterator range for a primitive type (number, boolean, or string) is passed to a constructor or an erase function, this range has to be exactly (@ref begin(), @ref end()), because this is the only way the single stored value is expressed. All other ranges are invalid. -json.exception.invalid_iterator.205 | iterator out of range | When an iterator for a primitive type (number, boolean, or string) is passed to an erase function, the iterator has to be the @ref begin() iterator, because it is the only way to address the stored value. All other iterators are invalid. -json.exception.invalid_iterator.206 | cannot construct with iterators from null | The iterators passed to constructor @ref basic_json(InputIT first, InputIT last) belong to a JSON null value and hence to not define a valid range. -json.exception.invalid_iterator.207 | cannot use key() for non-object iterators | The key() member function can only be used on iterators belonging to a JSON object, because other types do not have a concept of a key. -json.exception.invalid_iterator.208 | cannot use operator[] for object iterators | The operator[] to specify a concrete offset cannot be used on iterators belonging to a JSON object, because JSON objects are unordered. -json.exception.invalid_iterator.209 | cannot use offsets with object iterators | The offset operators (+, -, +=, -=) cannot be used on iterators belonging to a JSON object, because JSON objects are unordered. -json.exception.invalid_iterator.210 | iterators do not fit | The iterator range passed to the insert function are not compatible, meaning they do not belong to the same container. Therefore, the range (@a first, @a last) is invalid. -json.exception.invalid_iterator.211 | passed iterators may not belong to container | The iterator range passed to the insert function must not be a subrange of the container to insert to. -json.exception.invalid_iterator.212 | cannot compare iterators of different containers | When two iterators are compared, they must belong to the same container. -json.exception.invalid_iterator.213 | cannot compare order of object iterators | The order of object iterators cannot be compared, because JSON objects are unordered. -json.exception.invalid_iterator.214 | cannot get value | Cannot get value for iterator: Either the iterator belongs to a null value or it is an iterator to a primitive type (number, boolean, or string), but the iterator is different to @ref begin(). - -@liveexample{The following code shows how an `invalid_iterator` exception can be -caught.,invalid_iterator} - -@sa - @ref exception for the base class of the library exceptions -@sa - @ref parse_error for exceptions indicating a parse error -@sa - @ref type_error for exceptions indicating executing a member function with - a wrong type -@sa - @ref out_of_range for exceptions indicating access out of the defined range -@sa - @ref other_error for exceptions indicating other library errors - -@since version 3.0.0 -*/ +/// @brief exception indicating errors with iterators +/// @sa https://json.nlohmann.me/api/basic_json/invalid_iterator/ class invalid_iterator : public exception { public: @@ -2992,7 +2957,7 @@ class invalid_iterator : public exception static invalid_iterator create(int id_, const std::string& what_arg, const BasicJsonType& context) { std::string w = exception::name("invalid_iterator", id_) + exception::diagnostics(context) + what_arg; - return invalid_iterator(id_, w.c_str()); + return {id_, w.c_str()}; } private: @@ -3001,45 +2966,8 @@ class invalid_iterator : public exception : exception(id_, what_arg) {} }; -/*! -@brief exception indicating executing a member function with a wrong type - -This exception is thrown in case of a type error; that is, a library function is -executed on a JSON value whose type does not match the expected semantics. - -Exceptions have ids 3xx. - -name / id | example message | description ------------------------------ | --------------- | ------------------------- -json.exception.type_error.301 | cannot create object from initializer list | To create an object from an initializer list, the initializer list must consist only of a list of pairs whose first element is a string. When this constraint is violated, an array is created instead. -json.exception.type_error.302 | type must be object, but is array | During implicit or explicit value conversion, the JSON type must be compatible to the target type. For instance, a JSON string can only be converted into string types, but not into numbers or boolean types. -json.exception.type_error.303 | incompatible ReferenceType for get_ref, actual type is object | To retrieve a reference to a value stored in a @ref basic_json object with @ref get_ref, the type of the reference must match the value type. For instance, for a JSON array, the @a ReferenceType must be @ref array_t &. -json.exception.type_error.304 | cannot use at() with string | The @ref at() member functions can only be executed for certain JSON types. -json.exception.type_error.305 | cannot use operator[] with string | The @ref operator[] member functions can only be executed for certain JSON types. -json.exception.type_error.306 | cannot use value() with string | The @ref value() member functions can only be executed for certain JSON types. -json.exception.type_error.307 | cannot use erase() with string | The @ref erase() member functions can only be executed for certain JSON types. -json.exception.type_error.308 | cannot use push_back() with string | The @ref push_back() and @ref operator+= member functions can only be executed for certain JSON types. -json.exception.type_error.309 | cannot use insert() with | The @ref insert() member functions can only be executed for certain JSON types. -json.exception.type_error.310 | cannot use swap() with number | The @ref swap() member functions can only be executed for certain JSON types. -json.exception.type_error.311 | cannot use emplace_back() with string | The @ref emplace_back() member function can only be executed for certain JSON types. -json.exception.type_error.312 | cannot use update() with string | The @ref update() member functions can only be executed for certain JSON types. -json.exception.type_error.313 | invalid value to unflatten | The @ref unflatten function converts an object whose keys are JSON Pointers back into an arbitrary nested JSON value. The JSON Pointers must not overlap, because then the resulting value would not be well defined. -json.exception.type_error.314 | only objects can be unflattened | The @ref unflatten function only works for an object whose keys are JSON Pointers. -json.exception.type_error.315 | values in object must be primitive | The @ref unflatten function only works for an object whose keys are JSON Pointers and whose values are primitive. -json.exception.type_error.316 | invalid UTF-8 byte at index 10: 0x7E | The @ref dump function only works with UTF-8 encoded strings; that is, if you assign a `std::string` to a JSON value, make sure it is UTF-8 encoded. | -json.exception.type_error.317 | JSON value cannot be serialized to requested format | The dynamic type of the object cannot be represented in the requested serialization format (e.g. a raw `true` or `null` JSON object cannot be serialized to BSON) | - -@liveexample{The following code shows how a `type_error` exception can be -caught.,type_error} - -@sa - @ref exception for the base class of the library exceptions -@sa - @ref parse_error for exceptions indicating a parse error -@sa - @ref invalid_iterator for exceptions indicating errors with iterators -@sa - @ref out_of_range for exceptions indicating access out of the defined range -@sa - @ref other_error for exceptions indicating other library errors - -@since version 3.0.0 -*/ +/// @brief exception indicating executing a member function with a wrong type +/// @sa https://json.nlohmann.me/api/basic_json/type_error/ class type_error : public exception { public: @@ -3047,7 +2975,7 @@ class type_error : public exception static type_error create(int id_, const std::string& what_arg, const BasicJsonType& context) { std::string w = exception::name("type_error", id_) + exception::diagnostics(context) + what_arg; - return type_error(id_, w.c_str()); + return {id_, w.c_str()}; } private: @@ -3055,39 +2983,8 @@ class type_error : public exception type_error(int id_, const char* what_arg) : exception(id_, what_arg) {} }; -/*! -@brief exception indicating access out of the defined range - -This exception is thrown in case a library function is called on an input -parameter that exceeds the expected range, for instance in case of array -indices or nonexisting object keys. - -Exceptions have ids 4xx. - -name / id | example message | description -------------------------------- | --------------- | ------------------------- -json.exception.out_of_range.401 | array index 3 is out of range | The provided array index @a i is larger than @a size-1. -json.exception.out_of_range.402 | array index '-' (3) is out of range | The special array index `-` in a JSON Pointer never describes a valid element of the array, but the index past the end. That is, it can only be used to add elements at this position, but not to read it. -json.exception.out_of_range.403 | key 'foo' not found | The provided key was not found in the JSON object. -json.exception.out_of_range.404 | unresolved reference token 'foo' | A reference token in a JSON Pointer could not be resolved. -json.exception.out_of_range.405 | JSON pointer has no parent | The JSON Patch operations 'remove' and 'add' can not be applied to the root element of the JSON value. -json.exception.out_of_range.406 | number overflow parsing '10E1000' | A parsed number could not be stored as without changing it to NaN or INF. -json.exception.out_of_range.407 | number overflow serializing '9223372036854775808' | UBJSON and BSON only support integer numbers up to 9223372036854775807. (until version 3.8.0) | -json.exception.out_of_range.408 | excessive array size: 8658170730974374167 | The size (following `#`) of an UBJSON array or object exceeds the maximal capacity. | -json.exception.out_of_range.409 | BSON key cannot contain code point U+0000 (at byte 2) | Key identifiers to be serialized to BSON cannot contain code point U+0000, since the key is stored as zero-terminated c-string | - -@liveexample{The following code shows how an `out_of_range` exception can be -caught.,out_of_range} - -@sa - @ref exception for the base class of the library exceptions -@sa - @ref parse_error for exceptions indicating a parse error -@sa - @ref invalid_iterator for exceptions indicating errors with iterators -@sa - @ref type_error for exceptions indicating executing a member function with - a wrong type -@sa - @ref other_error for exceptions indicating other library errors - -@since version 3.0.0 -*/ +/// @brief exception indicating access out of the defined range +/// @sa https://json.nlohmann.me/api/basic_json/out_of_range/ class out_of_range : public exception { public: @@ -3095,7 +2992,7 @@ class out_of_range : public exception static out_of_range create(int id_, const std::string& what_arg, const BasicJsonType& context) { std::string w = exception::name("out_of_range", id_) + exception::diagnostics(context) + what_arg; - return out_of_range(id_, w.c_str()); + return {id_, w.c_str()}; } private: @@ -3103,30 +3000,8 @@ class out_of_range : public exception out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {} }; -/*! -@brief exception indicating other library errors - -This exception is thrown in case of errors that cannot be classified with the -other exception types. - -Exceptions have ids 5xx. - -name / id | example message | description ------------------------------- | --------------- | ------------------------- -json.exception.other_error.501 | unsuccessful: {"op":"test","path":"/baz", "value":"bar"} | A JSON Patch operation 'test' failed. The unsuccessful operation is also printed. - -@sa - @ref exception for the base class of the library exceptions -@sa - @ref parse_error for exceptions indicating a parse error -@sa - @ref invalid_iterator for exceptions indicating errors with iterators -@sa - @ref type_error for exceptions indicating executing a member function with - a wrong type -@sa - @ref out_of_range for exceptions indicating access out of the defined range - -@liveexample{The following code shows how an `other_error` exception can be -caught.,other_error} - -@since version 3.0.0 -*/ +/// @brief exception indicating other library errors +/// @sa https://json.nlohmann.me/api/basic_json/other_error/ class other_error : public exception { public: @@ -3134,13 +3009,14 @@ class other_error : public exception static other_error create(int id_, const std::string& what_arg, const BasicJsonType& context) { std::string w = exception::name("other_error", id_) + exception::diagnostics(context) + what_arg; - return other_error(id_, w.c_str()); + return {id_, w.c_str()}; } private: JSON_HEDLEY_NON_NULL(3) other_error(int id_, const char* what_arg) : exception(id_, what_arg) {} }; + } // namespace detail } // namespace nlohmann @@ -3298,7 +3174,7 @@ struct static_const }; template -constexpr T static_const::value; +constexpr T static_const::value; // NOLINT(readability-redundant-declaration) } // namespace detail } // namespace nlohmann @@ -3434,6 +3310,8 @@ for serialization. template struct adl_serializer; +/// a class to store JSON values +/// @sa https://json.nlohmann.me/api/basic_json/ template class ObjectType = std::map, template class ArrayType = std::vector, @@ -3447,40 +3325,24 @@ template class ObjectType = class BinaryType = std::vector> class basic_json; -/*! -@brief JSON Pointer - -A JSON pointer defines a string syntax for identifying a specific value -within a JSON document. It can be used with functions `at` and -`operator[]`. Furthermore, JSON pointers are the base for JSON patches. - -@sa [RFC 6901](https://tools.ietf.org/html/rfc6901) - -@since version 2.0.0 -*/ +/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document +/// @sa https://json.nlohmann.me/api/json_pointer/ template class json_pointer; /*! -@brief default JSON class - -This type is the default specialization of the @ref basic_json class which -uses the standard template types. - -@since version 1.0.0 +@brief default specialization +@sa https://json.nlohmann.me/api/json/ */ using json = basic_json<>; +/// @brief a minimal map-like container that preserves insertion order +/// @sa https://json.nlohmann.me/api/ordered_map/ template struct ordered_map; -/*! -@brief ordered JSON class - -This type preserves the insertion order of object keys. - -@since version 3.9.0 -*/ +/// @brief specialization that maintains the insertion order of object keys +/// @sa https://json.nlohmann.me/api/ordered_json/ using ordered_json = basic_json; } // namespace nlohmann @@ -3950,8 +3812,18 @@ T conditional_static_cast(U value) // #include -#ifdef JSON_HAS_CPP_17 - #include +#if JSON_HAS_EXPERIMENTAL_FILESYSTEM +#include +namespace nlohmann::detail +{ +namespace std_fs = std::experimental::filesystem; +} // namespace nlohmann::detail +#elif JSON_HAS_FILESYSTEM +#include +namespace nlohmann::detail +{ +namespace std_fs = std::filesystem; +} // namespace nlohmann::detail #endif namespace nlohmann @@ -4379,9 +4251,9 @@ void from_json(const BasicJsonType& j, std::unordered_map -void from_json(const BasicJsonType& j, std::filesystem::path& p) +void from_json(const BasicJsonType& j, std_fs::path& p) { if (JSON_HEDLEY_UNLIKELY(!j.is_string())) { @@ -4626,8 +4498,18 @@ class tuple_element> // #include -#ifdef JSON_HAS_CPP_17 - #include +#if JSON_HAS_EXPERIMENTAL_FILESYSTEM +#include +namespace nlohmann::detail +{ +namespace std_fs = std::experimental::filesystem; +} // namespace nlohmann::detail +#elif JSON_HAS_FILESYSTEM +#include +namespace nlohmann::detail +{ +namespace std_fs = std::filesystem; +} // namespace nlohmann::detail #endif namespace nlohmann @@ -5002,9 +4884,9 @@ void to_json(BasicJsonType& j, const T& t) to_json_tuple_impl(j, t, make_index_sequence::value> {}); } -#ifdef JSON_HAS_CPP_17 +#if JSON_HAS_FILESYSTEM || JSON_HAS_EXPERIMENTAL_FILESYSTEM template -void to_json(BasicJsonType& j, const std::filesystem::path& p) +void to_json(BasicJsonType& j, const std_fs::path& p) { j = p.string(); } @@ -5038,20 +4920,12 @@ constexpr const auto& to_json = detail::static_const::value; namespace nlohmann { +/// @sa https://json.nlohmann.me/api/adl_serializer/ template struct adl_serializer { - /*! - @brief convert a JSON value to any value type - - This function is usually called by the `get()` function of the - @ref basic_json class (either explicit or via conversion operators). - - @note This function is chosen for default-constructible value types. - - @param[in] j JSON value to read from - @param[in,out] val value to write to - */ + /// @brief convert a JSON value to any value type + /// @sa https://json.nlohmann.me/api/adl_serializer/from_json/ template static auto from_json(BasicJsonType && j, TargetType& val) noexcept( noexcept(::nlohmann::from_json(std::forward(j), val))) @@ -5060,18 +4934,8 @@ struct adl_serializer ::nlohmann::from_json(std::forward(j), val); } - /*! - @brief convert a JSON value to any value type - - This function is usually called by the `get()` function of the - @ref basic_json class (either explicit or via conversion operators). - - @note This function is chosen for value types which are not default-constructible. - - @param[in] j JSON value to read from - - @return copy of the JSON value, converted to @a ValueType - */ + /// @brief convert a JSON value to any value type + /// @sa https://json.nlohmann.me/api/adl_serializer/from_json/ template static auto from_json(BasicJsonType && j) noexcept( noexcept(::nlohmann::from_json(std::forward(j), detail::identity_tag {}))) @@ -5080,15 +4944,8 @@ struct adl_serializer return ::nlohmann::from_json(std::forward(j), detail::identity_tag {}); } - /*! - @brief convert any value type to a JSON value - - This function is usually called by the constructors of the @ref basic_json - class. - - @param[in,out] j JSON value to write to - @param[in] val value to read from - */ + /// @brief convert any value type to a JSON value + /// @sa https://json.nlohmann.me/api/adl_serializer/to_json/ template static auto to_json(BasicJsonType& j, TargetType && val) noexcept( noexcept(::nlohmann::to_json(j, std::forward(val)))) @@ -5109,46 +4966,38 @@ struct adl_serializer namespace nlohmann { -/*! -@brief an internal type for a backed binary type - -This type extends the template parameter @a BinaryType provided to `basic_json` -with a subtype used by BSON and MessagePack. This type exists so that the user -does not have to specify a type themselves with a specific naming scheme in -order to override the binary type. - -@tparam BinaryType container to store bytes (`std::vector` by - default) - -@since version 3.8.0; changed type of subtypes to std::uint64_t in 3.10.0. -*/ +/// @brief an internal type for a backed binary type +/// @sa https://json.nlohmann.me/api/byte_container_with_subtype/ template class byte_container_with_subtype : public BinaryType { public: - /// the type of the underlying container using container_type = BinaryType; - /// the type of the subtype using subtype_type = std::uint64_t; + /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ byte_container_with_subtype() noexcept(noexcept(container_type())) : container_type() {} + /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ byte_container_with_subtype(const container_type& b) noexcept(noexcept(container_type(b))) : container_type(b) {} + /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ byte_container_with_subtype(container_type&& b) noexcept(noexcept(container_type(std::move(b)))) : container_type(std::move(b)) {} + /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ byte_container_with_subtype(const container_type& b, subtype_type subtype_) noexcept(noexcept(container_type(b))) : container_type(b) , m_subtype(subtype_) , m_has_subtype(true) {} + /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/byte_container_with_subtype/ byte_container_with_subtype(container_type&& b, subtype_type subtype_) noexcept(noexcept(container_type(std::move(b)))) : container_type(std::move(b)) , m_subtype(subtype_) @@ -5166,97 +5015,30 @@ class byte_container_with_subtype : public BinaryType return !(rhs == *this); } - /*! - @brief sets the binary subtype - - Sets the binary subtype of the value, also flags a binary JSON value as - having a subtype, which has implications for serialization. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @sa see @ref subtype() -- return the binary subtype - @sa see @ref clear_subtype() -- clears the binary subtype - @sa see @ref has_subtype() -- returns whether or not the binary value has a - subtype - - @since version 3.8.0 - */ + /// @brief sets the binary subtype + /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/set_subtype/ void set_subtype(subtype_type subtype_) noexcept { m_subtype = subtype_; m_has_subtype = true; } - /*! - @brief return the binary subtype - - Returns the numerical subtype of the value if it has a subtype. If it does - not have a subtype, this function will return subtype_type(-1) as a sentinel - value. - - @return the numerical subtype of the binary value - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @sa see @ref set_subtype() -- sets the binary subtype - @sa see @ref clear_subtype() -- clears the binary subtype - @sa see @ref has_subtype() -- returns whether or not the binary value has a - subtype - - @since version 3.8.0; fixed return value to properly return - subtype_type(-1) as documented in version 3.10.0 - */ + /// @brief return the binary subtype + /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/subtype/ constexpr subtype_type subtype() const noexcept { - return m_has_subtype ? m_subtype : subtype_type(-1); + return m_has_subtype ? m_subtype : static_cast(-1); } - /*! - @brief return whether the value has a subtype - - @return whether the value has a subtype - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @sa see @ref subtype() -- return the binary subtype - @sa see @ref set_subtype() -- sets the binary subtype - @sa see @ref clear_subtype() -- clears the binary subtype - - @since version 3.8.0 - */ + /// @brief return whether the value has a subtype + /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/has_subtype/ constexpr bool has_subtype() const noexcept { return m_has_subtype; } - /*! - @brief clears the binary subtype - - Clears the binary subtype and flags the value as not having a subtype, which - has implications for serialization; for instance MessagePack will prefer the - bin family over the ext family. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @sa see @ref subtype() -- return the binary subtype - @sa see @ref set_subtype() -- sets the binary subtype - @sa see @ref has_subtype() -- returns whether or not the binary value has a - subtype - - @since version 3.8.0 - */ + /// @brief clears the binary subtype + /// @sa https://json.nlohmann.me/api/byte_container_with_subtype/clear_subtype/ void clear_subtype() noexcept { m_subtype = 0; @@ -5529,7 +5311,7 @@ class input_stream_adapter // std::istream/std::streambuf use std::char_traits::to_int_type, to // ensure that std::char_traits::eof() and the character 0xFF do not - // end up as the same value, eg. 0xFFFFFFFF. + // end up as the same value, e.g. 0xFFFFFFFF. std::char_traits::int_type get_character() { auto res = sb->sbumpc(); @@ -5875,7 +5657,7 @@ auto input_adapter(T (&array)[N]) -> decltype(input_adapter(array, array + N)) / } // This class only handles inputs of input_buffer_adapter type. -// It's required so that expressions like {ptr, len} can be implicitely casted +// It's required so that expressions like {ptr, len} can be implicitly cast // to the correct adapter. class span_input_adapter { @@ -5968,7 +5750,7 @@ struct json_sax virtual bool number_unsigned(number_unsigned_t val) = 0; /*! - @brief an floating-point number was read + @brief a floating-point number was read @param[in] val floating-point value @param[in] s raw token value @return whether parsing should proceed @@ -5976,18 +5758,18 @@ struct json_sax virtual bool number_float(number_float_t val, const string_t& s) = 0; /*! - @brief a string was read + @brief a string value was read @param[in] val string value @return whether parsing should proceed - @note It is safe to move the passed string. + @note It is safe to move the passed string value. */ virtual bool string(string_t& val) = 0; /*! - @brief a binary string was read + @brief a binary value was read @param[in] val binary value @return whether parsing should proceed - @note It is safe to move the passed binary. + @note It is safe to move the passed binary value. */ virtual bool binary(binary_t& val) = 0; @@ -6134,7 +5916,7 @@ class json_sax_dom_parser { ref_stack.push_back(handle_value(BasicJsonType::value_t::object)); - if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) + if (JSON_HEDLEY_UNLIKELY(len != static_cast(-1) && len > ref_stack.back()->max_size())) { JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), *ref_stack.back())); } @@ -6160,7 +5942,7 @@ class json_sax_dom_parser { ref_stack.push_back(handle_value(BasicJsonType::value_t::array)); - if (JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) + if (JSON_HEDLEY_UNLIKELY(len != static_cast(-1) && len > ref_stack.back()->max_size())) { JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), *ref_stack.back())); } @@ -6315,7 +6097,7 @@ class json_sax_dom_callback_parser ref_stack.push_back(val.second); // check object limit - if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) + if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != static_cast(-1) && len > ref_stack.back()->max_size())) { JSON_THROW(out_of_range::create(408, "excessive object size: " + std::to_string(len), *ref_stack.back())); } @@ -6385,7 +6167,7 @@ class json_sax_dom_callback_parser ref_stack.push_back(val.second); // check array limit - if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != std::size_t(-1) && len > ref_stack.back()->max_size())) + if (ref_stack.back() && JSON_HEDLEY_UNLIKELY(len != static_cast(-1) && len > ref_stack.back()->max_size())) { JSON_THROW(out_of_range::create(408, "excessive array size: " + std::to_string(len), *ref_stack.back())); } @@ -6588,7 +6370,7 @@ class json_sax_acceptor return true; } - bool start_object(std::size_t /*unused*/ = std::size_t(-1)) + bool start_object(std::size_t /*unused*/ = static_cast(-1)) { return true; } @@ -6603,7 +6385,7 @@ class json_sax_acceptor return true; } - bool start_array(std::size_t /*unused*/ = std::size_t(-1)) + bool start_array(std::size_t /*unused*/ = static_cast(-1)) { return true; } @@ -6971,7 +6753,7 @@ class lexer : public lexer_base // low surrogate occupies the least significant 15 bits + static_cast(codepoint2) // there is still the 0xD800, 0xDC00 and 0x10000 noise - // in the result so we have to subtract with: + // in the result, so we have to subtract with: // (0xD800 << 10) + DC00 - 0x10000 = 0x35FDC00 - 0x35FDC00u); } @@ -8075,7 +7857,7 @@ class lexer : public lexer_base { // escape control characters std::array cs{{}}; - (std::snprintf)(cs.data(), cs.size(), "", static_cast(c)); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + static_cast((std::snprintf)(cs.data(), cs.size(), "", static_cast(c))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) result += cs.data(); } else @@ -8169,17 +7951,17 @@ class lexer : public lexer_base // literals case 't': { - std::array true_literal = {{char_type('t'), char_type('r'), char_type('u'), char_type('e')}}; + std::array true_literal = {{static_cast('t'), static_cast('r'), static_cast('u'), static_cast('e')}}; return scan_literal(true_literal.data(), true_literal.size(), token_type::literal_true); } case 'f': { - std::array false_literal = {{char_type('f'), char_type('a'), char_type('l'), char_type('s'), char_type('e')}}; + std::array false_literal = {{static_cast('f'), static_cast('a'), static_cast('l'), static_cast('s'), static_cast('e')}}; return scan_literal(false_literal.data(), false_literal.size(), token_type::literal_false); } case 'n': { - std::array null_literal = {{char_type('n'), char_type('u'), char_type('l'), char_type('l')}}; + std::array null_literal = {{static_cast('n'), static_cast('u'), static_cast('l'), static_cast('l')}}; return scan_literal(null_literal.data(), null_literal.size(), token_type::literal_null); } @@ -8430,7 +8212,7 @@ enum class cbor_tag_handler_t @note from https://stackoverflow.com/a/1001328/266378 */ -static inline bool little_endianess(int num = 1) noexcept +static inline bool little_endianness(int num = 1) noexcept { return *reinterpret_cast(&num) == 1; } @@ -8549,7 +8331,7 @@ class binary_reader std::int32_t document_size{}; get_number(input_format_t::bson, document_size); - if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1)))) + if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast(-1)))) { return false; } @@ -8706,7 +8488,7 @@ class binary_reader default: // anything else not supported (yet) { std::array cr{{}}; - (std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast(element_type)); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + static_cast((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast(element_type))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) return sax->parse_error(element_type_parse_position, std::string(cr.data()), parse_error::create(114, element_type_parse_position, "Unsupported BSON record type 0x" + std::string(cr.data()), BasicJsonType())); } } @@ -8767,7 +8549,7 @@ class binary_reader std::int32_t document_size{}; get_number(input_format_t::bson, document_size); - if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1)))) + if (JSON_HEDLEY_UNLIKELY(!sax->start_array(static_cast(-1)))) { return false; } @@ -9026,7 +8808,7 @@ class binary_reader } case 0x9F: // array (indefinite length) - return get_cbor_array(std::size_t(-1), tag_handler); + return get_cbor_array(static_cast(-1), tag_handler); // map (0x00..0x17 pairs of data items follow) case 0xA0: @@ -9080,7 +8862,7 @@ class binary_reader } case 0xBF: // map (indefinite length) - return get_cbor_object(std::size_t(-1), tag_handler); + return get_cbor_object(static_cast(-1), tag_handler); case 0xC6: // tagged item case 0xC7: @@ -9464,7 +9246,7 @@ class binary_reader } /*! - @param[in] len the length of the array or std::size_t(-1) for an + @param[in] len the length of the array or static_cast(-1) for an array of indefinite size @param[in] tag_handler how CBOR tags should be treated @return whether array creation completed @@ -9477,7 +9259,7 @@ class binary_reader return false; } - if (len != std::size_t(-1)) + if (len != static_cast(-1)) { for (std::size_t i = 0; i < len; ++i) { @@ -9502,7 +9284,7 @@ class binary_reader } /*! - @param[in] len the length of the object or std::size_t(-1) for an + @param[in] len the length of the object or static_cast(-1) for an object of indefinite size @param[in] tag_handler how CBOR tags should be treated @return whether object creation completed @@ -9518,7 +9300,7 @@ class binary_reader if (len != 0) { string_t key; - if (len != std::size_t(-1)) + if (len != static_cast(-1)) { for (std::size_t i = 0; i < len; ++i) { @@ -10528,7 +10310,7 @@ class binary_reader } else { - if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1)))) + if (JSON_HEDLEY_UNLIKELY(!sax->start_array(static_cast(-1)))) { return false; } @@ -10598,7 +10380,7 @@ class binary_reader } else { - if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1)))) + if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast(-1)))) { return false; } @@ -10729,7 +10511,7 @@ class binary_reader @return whether conversion completed - @note This function needs to respect the system's endianess, because + @note This function needs to respect the system's endianness, because bytes in CBOR, MessagePack, and UBJSON are stored in network order (big endian) and therefore need reordering on little endian systems. */ @@ -10850,7 +10632,7 @@ class binary_reader std::string get_token_string() const { std::array cr{{}}; - (std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast(current)); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) + static_cast((std::snprintf)(cr.data(), cr.size(), "%.2hhX", static_cast(current))); // NOLINT(cppcoreguidelines-pro-type-vararg,hicpp-vararg) return std::string{cr.data()}; } @@ -10902,8 +10684,8 @@ class binary_reader /// the number of characters read std::size_t chars_read = 0; - /// whether we can assume little endianess - const bool is_little_endian = little_endianess(); + /// whether we can assume little endianness + const bool is_little_endian = little_endianness(); /// the SAX parser json_sax_t* sax = nullptr; @@ -11111,7 +10893,7 @@ class parser { case token_type::begin_object: { - if (JSON_HEDLEY_UNLIKELY(!sax->start_object(std::size_t(-1)))) + if (JSON_HEDLEY_UNLIKELY(!sax->start_object(static_cast(-1)))) { return false; } @@ -11156,7 +10938,7 @@ class parser case token_type::begin_array: { - if (JSON_HEDLEY_UNLIKELY(!sax->start_array(std::size_t(-1)))) + if (JSON_HEDLEY_UNLIKELY(!sax->start_array(static_cast(-1)))) { return false; } @@ -11621,7 +11403,7 @@ This class implements a both iterators (iterator and const_iterator) for the iterators in version 3.0.0 (see https://github.com/nlohmann/json/issues/593) */ template -class iter_impl +class iter_impl // NOLINT(cppcoreguidelines-special-member-functions,hicpp-special-member-functions) { /// the iterator with BasicJsonType of different const-ness using other_iter_impl = iter_impl::value, typename std::remove_const::type, const BasicJsonType>::type>; @@ -12470,6 +12252,9 @@ class json_reverse_iterator : public std::reverse_iterator namespace nlohmann { + +/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document +/// @sa https://json.nlohmann.me/api/json_pointer/ template class json_pointer { @@ -12478,45 +12263,14 @@ class json_pointer friend class basic_json; public: - /*! - @brief create JSON pointer - - Create a JSON pointer according to the syntax described in - [Section 3 of RFC6901](https://tools.ietf.org/html/rfc6901#section-3). - - @param[in] s string representing the JSON pointer; if omitted, the empty - string is assumed which references the whole JSON value - - @throw parse_error.107 if the given JSON pointer @a s is nonempty and does - not begin with a slash (`/`); see example below - - @throw parse_error.108 if a tilde (`~`) in the given JSON pointer @a s is - not followed by `0` (representing `~`) or `1` (representing `/`); see - example below - - @liveexample{The example shows the construction several valid JSON pointers - as well as the exceptional behavior.,json_pointer} - - @since version 2.0.0 - */ + /// @brief create JSON pointer + /// @sa https://json.nlohmann.me/api/json_pointer/json_pointer/ explicit json_pointer(const std::string& s = "") : reference_tokens(split(s)) {} - /*! - @brief return a string representation of the JSON pointer - - @invariant For each JSON pointer `ptr`, it holds: - @code {.cpp} - ptr == json_pointer(ptr.to_string()); - @endcode - - @return a string representation of the JSON pointer - - @liveexample{The example shows the result of `to_string`.,json_pointer__to_string} - - @since version 2.0.0 - */ + /// @brief return a string representation of the JSON pointer + /// @sa https://json.nlohmann.me/api/json_pointer/to_string/ std::string to_string() const { return std::accumulate(reference_tokens.begin(), reference_tokens.end(), @@ -12527,28 +12281,15 @@ class json_pointer }); } - /// @copydoc to_string() + /// @brief return a string representation of the JSON pointer + /// @sa https://json.nlohmann.me/api/json_pointer/operator_string/ operator std::string() const { return to_string(); } - /*! - @brief append another JSON pointer at the end of this JSON pointer - - @param[in] ptr JSON pointer to append - @return JSON pointer with @a ptr appended - - @liveexample{The example shows the usage of `operator/=`.,json_pointer__operator_add} - - @complexity Linear in the length of @a ptr. - - @sa see @ref operator/=(std::string) to append a reference token - @sa see @ref operator/=(std::size_t) to append an array index - @sa see @ref operator/(const json_pointer&, const json_pointer&) for a binary operator - - @since version 3.6.0 - */ + /// @brief append another JSON pointer at the end of this JSON pointer + /// @sa https://json.nlohmann.me/api/json_pointer/operator_slasheq/ json_pointer& operator/=(const json_pointer& ptr) { reference_tokens.insert(reference_tokens.end(), @@ -12557,123 +12298,45 @@ class json_pointer return *this; } - /*! - @brief append an unescaped reference token at the end of this JSON pointer - - @param[in] token reference token to append - @return JSON pointer with @a token appended without escaping @a token - - @liveexample{The example shows the usage of `operator/=`.,json_pointer__operator_add} - - @complexity Amortized constant. - - @sa see @ref operator/=(const json_pointer&) to append a JSON pointer - @sa see @ref operator/=(std::size_t) to append an array index - @sa see @ref operator/(const json_pointer&, std::size_t) for a binary operator - - @since version 3.6.0 - */ + /// @brief append an unescaped reference token at the end of this JSON pointer + /// @sa https://json.nlohmann.me/api/json_pointer/operator_slasheq/ json_pointer& operator/=(std::string token) { push_back(std::move(token)); return *this; } - /*! - @brief append an array index at the end of this JSON pointer - - @param[in] array_idx array index to append - @return JSON pointer with @a array_idx appended - - @liveexample{The example shows the usage of `operator/=`.,json_pointer__operator_add} - - @complexity Amortized constant. - - @sa see @ref operator/=(const json_pointer&) to append a JSON pointer - @sa see @ref operator/=(std::string) to append a reference token - @sa see @ref operator/(const json_pointer&, std::string) for a binary operator - - @since version 3.6.0 - */ + /// @brief append an array index at the end of this JSON pointer + /// @sa https://json.nlohmann.me/api/json_pointer/operator_slasheq/ json_pointer& operator/=(std::size_t array_idx) { return *this /= std::to_string(array_idx); } - /*! - @brief create a new JSON pointer by appending the right JSON pointer at the end of the left JSON pointer - - @param[in] lhs JSON pointer - @param[in] rhs JSON pointer - @return a new JSON pointer with @a rhs appended to @a lhs - - @liveexample{The example shows the usage of `operator/`.,json_pointer__operator_add_binary} - - @complexity Linear in the length of @a lhs and @a rhs. - - @sa see @ref operator/=(const json_pointer&) to append a JSON pointer - - @since version 3.6.0 - */ + /// @brief create a new JSON pointer by appending the right JSON pointer at the end of the left JSON pointer + /// @sa https://json.nlohmann.me/api/json_pointer/operator_slash/ friend json_pointer operator/(const json_pointer& lhs, const json_pointer& rhs) { return json_pointer(lhs) /= rhs; } - /*! - @brief create a new JSON pointer by appending the unescaped token at the end of the JSON pointer - - @param[in] ptr JSON pointer - @param[in] token reference token - @return a new JSON pointer with unescaped @a token appended to @a ptr - - @liveexample{The example shows the usage of `operator/`.,json_pointer__operator_add_binary} - - @complexity Linear in the length of @a ptr. - - @sa see @ref operator/=(std::string) to append a reference token - - @since version 3.6.0 - */ - friend json_pointer operator/(const json_pointer& ptr, std::string token) // NOLINT(performance-unnecessary-value-param) + /// @brief create a new JSON pointer by appending the unescaped token at the end of the JSON pointer + /// @sa https://json.nlohmann.me/api/json_pointer/operator_slash/ + friend json_pointer operator/(const json_pointer& lhs, std::string token) // NOLINT(performance-unnecessary-value-param) { - return json_pointer(ptr) /= std::move(token); + return json_pointer(lhs) /= std::move(token); } - /*! - @brief create a new JSON pointer by appending the array-index-token at the end of the JSON pointer - - @param[in] ptr JSON pointer - @param[in] array_idx array index - @return a new JSON pointer with @a array_idx appended to @a ptr - - @liveexample{The example shows the usage of `operator/`.,json_pointer__operator_add_binary} - - @complexity Linear in the length of @a ptr. - - @sa see @ref operator/=(std::size_t) to append an array index - - @since version 3.6.0 - */ - friend json_pointer operator/(const json_pointer& ptr, std::size_t array_idx) + /// @brief create a new JSON pointer by appending the array-index-token at the end of the JSON pointer + /// @sa https://json.nlohmann.me/api/json_pointer/operator_slash/ + friend json_pointer operator/(const json_pointer& lhs, std::size_t array_idx) { - return json_pointer(ptr) /= array_idx; + return json_pointer(lhs) /= array_idx; } - /*! - @brief returns the parent of this JSON pointer - - @return parent of this JSON pointer; in case this JSON pointer is the root, - the root itself is returned - - @complexity Linear in the length of the JSON pointer. - - @liveexample{The example shows the result of `parent_pointer` for different - JSON Pointers.,json_pointer__parent_pointer} - - @since version 3.6.0 - */ + /// @brief returns the parent of this JSON pointer + /// @sa https://json.nlohmann.me/api/json_pointer/parent_pointer/ json_pointer parent_pointer() const { if (empty()) @@ -12686,19 +12349,8 @@ class json_pointer return res; } - /*! - @brief remove last reference token - - @pre not `empty()` - - @liveexample{The example shows the usage of `pop_back`.,json_pointer__pop_back} - - @complexity Constant. - - @throw out_of_range.405 if JSON pointer has no parent - - @since version 3.6.0 - */ + /// @brief remove last reference token + /// @sa https://json.nlohmann.me/api/json_pointer/pop_back/ void pop_back() { if (JSON_HEDLEY_UNLIKELY(empty())) @@ -12709,20 +12361,8 @@ class json_pointer reference_tokens.pop_back(); } - /*! - @brief return last reference token - - @pre not `empty()` - @return last reference token - - @liveexample{The example shows the usage of `back`.,json_pointer__back} - - @complexity Constant. - - @throw out_of_range.405 if JSON pointer has no parent - - @since version 3.6.0 - */ + /// @brief return last reference token + /// @sa https://json.nlohmann.me/api/json_pointer/back/ const std::string& back() const { if (JSON_HEDLEY_UNLIKELY(empty())) @@ -12733,43 +12373,22 @@ class json_pointer return reference_tokens.back(); } - /*! - @brief append an unescaped token at the end of the reference pointer - - @param[in] token token to add - - @complexity Amortized constant. - - @liveexample{The example shows the result of `push_back` for different - JSON Pointers.,json_pointer__push_back} - - @since version 3.6.0 - */ + /// @brief append an unescaped token at the end of the reference pointer + /// @sa https://json.nlohmann.me/api/json_pointer/push_back/ void push_back(const std::string& token) { reference_tokens.push_back(token); } - /// @copydoc push_back(const std::string&) + /// @brief append an unescaped token at the end of the reference pointer + /// @sa https://json.nlohmann.me/api/json_pointer/push_back/ void push_back(std::string&& token) { reference_tokens.push_back(std::move(token)); } - /*! - @brief return whether pointer points to the root document - - @return true iff the JSON pointer points to the root document - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this function never throws exceptions. - - @liveexample{The example shows the result of `empty` for different JSON - Pointers.,json_pointer__empty} - - @since version 3.6.0 - */ + /// @brief return whether pointer points to the root document + /// @sa https://json.nlohmann.me/api/json_pointer/empty/ bool empty() const noexcept { return reference_tokens.empty(); @@ -14750,7 +14369,7 @@ class binary_writer { std::size_t array_index = 0ul; - const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), std::size_t(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type & el) + const std::size_t embedded_document_size = std::accumulate(std::begin(value), std::end(value), static_cast(0), [&array_index](std::size_t result, const typename BasicJsonType::array_t::value_type & el) { return result + calc_bson_element_size(std::to_string(array_index++), el); }); @@ -14794,7 +14413,7 @@ class binary_writer write_bson_entry_header(name, 0x05); write_number(static_cast(value.size())); - write_number(value.has_subtype() ? static_cast(value.subtype()) : std::uint8_t(0x00)); + write_number(value.has_subtype() ? static_cast(value.subtype()) : static_cast(0x00)); oa->write_characters(reinterpret_cast(value.data()), value.size()); } @@ -14900,7 +14519,7 @@ class binary_writer */ static std::size_t calc_bson_object_size(const typename BasicJsonType::object_t& value) { - std::size_t document_size = std::accumulate(value.begin(), value.end(), std::size_t(0), + std::size_t document_size = std::accumulate(value.begin(), value.end(), static_cast(0), [](size_t result, const typename BasicJsonType::object_t::value_type & el) { return result += calc_bson_element_size(el.first, el.second); @@ -15202,7 +14821,7 @@ class binary_writer @tparam OutputIsLittleEndian Set to true if output data is required to be little endian - @note This function needs to respect the system's endianess, because bytes + @note This function needs to respect the system's endianness, because bytes in CBOR, MessagePack, and UBJSON are stored in network order (big endian) and therefore need reordering on little endian systems. */ @@ -15292,8 +14911,8 @@ class binary_writer } private: - /// whether we can assume little endianess - const bool is_little_endian = little_endianess(); + /// whether we can assume little endianness + const bool is_little_endian = little_endianness(); /// the output output_adapter_t oa = nullptr; @@ -15315,6 +14934,8 @@ class binary_writer #include // snprintf #include // numeric_limits #include // string, char_traits +#include // setfill, setw +#include // stringstream #include // is_same #include // move @@ -16213,7 +15834,7 @@ void grisu2(char* buf, int& len, int& decimal_exponent, FloatType value) // // The documentation for 'std::to_chars' (https://en.cppreference.com/w/cpp/utility/to_chars) // says "value is converted to a string as if by std::sprintf in the default ("C") locale" - // and since sprintf promotes float's to double's, I think this is exactly what 'std::to_chars' + // and since sprintf promotes floats to doubles, I think this is exactly what 'std::to_chars' // does. // On the other hand, the documentation for 'std::to_chars' requires that "parsing the // representation using the corresponding std::from_chars function recovers value exactly". That @@ -16879,16 +16500,16 @@ class serializer if (codepoint <= 0xFFFF) { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) - (std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x", - static_cast(codepoint)); + static_cast((std::snprintf)(string_buffer.data() + bytes, 7, "\\u%04x", + static_cast(codepoint))); bytes += 6; } else { // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) - (std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x", - static_cast(0xD7C0u + (codepoint >> 10u)), - static_cast(0xDC00u + (codepoint & 0x3FFu))); + static_cast((std::snprintf)(string_buffer.data() + bytes, 13, "\\u%04x\\u%04x", + static_cast(0xD7C0u + (codepoint >> 10u)), + static_cast(0xDC00u + (codepoint & 0x3FFu)))); bytes += 12; } } @@ -16923,10 +16544,9 @@ class serializer { case error_handler_t::strict: { - std::string sn(9, '\0'); - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) - (std::snprintf)(&sn[0], sn.size(), "%.2X", byte); - JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + sn, BasicJsonType())); + std::stringstream ss; + ss << std::uppercase << std::setfill('0') << std::setw(2) << std::hex << (byte | 0); + JSON_THROW(type_error::create(316, "invalid UTF-8 byte at index " + std::to_string(i) + ": 0x" + ss.str(), BasicJsonType())); } case error_handler_t::ignore: @@ -17018,10 +16638,9 @@ class serializer { case error_handler_t::strict: { - std::string sn(9, '\0'); - // NOLINTNEXTLINE(cppcoreguidelines-pro-type-vararg,hicpp-vararg) - (std::snprintf)(&sn[0], sn.size(), "%.2X", static_cast(s.back())); - JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + sn, BasicJsonType())); + std::stringstream ss; + ss << std::uppercase << std::setfill('0') << std::setw(2) << std::hex << (static_cast(s.back()) | 0); + JSON_THROW(type_error::create(316, "incomplete UTF-8 string; last byte: 0x" + ss.str(), BasicJsonType())); } case error_handler_t::ignore: @@ -17088,6 +16707,19 @@ class serializer } } + // templates to avoid warnings about useless casts + template ::value, int> = 0> + bool is_negative_number(NumberType x) + { + return x < 0; + } + + template < typename NumberType, enable_if_t ::value, int > = 0 > + bool is_negative_number(NumberType /*unused*/) + { + return false; + } + /*! @brief dump an integer @@ -17131,12 +16763,11 @@ class serializer // use a pointer to fill the buffer auto buffer_ptr = number_buffer.begin(); // NOLINT(llvm-qualified-auto,readability-qualified-auto,cppcoreguidelines-pro-type-vararg,hicpp-vararg) - const bool is_negative = std::is_signed::value && !(x >= 0); // see issue #755 number_unsigned_t abs_value; unsigned int n_chars{}; - if (is_negative) + if (is_negative_number(x)) { *buffer_ptr = '-'; abs_value = remove_sign(static_cast(x)); @@ -17153,7 +16784,7 @@ class serializer // spare 1 byte for '\0' JSON_ASSERT(n_chars < number_buffer.size() - 1); - // jump to the end to generate the string from backward + // jump to the end to generate the string from backward, // so we later avoid reversing the result buffer_ptr += n_chars; @@ -17255,7 +16886,7 @@ class serializer o->write_characters(number_buffer.data(), static_cast(len)); - // determine if need to append ".0" + // determine if we need to append ".0" const bool value_is_int_like = std::none_of(number_buffer.begin(), number_buffer.begin() + len + 1, [](char c) @@ -17410,10 +17041,10 @@ template , using key_type = Key; using mapped_type = T; using Container = std::vector, Allocator>; - using typename Container::iterator; - using typename Container::const_iterator; - using typename Container::size_type; - using typename Container::value_type; + using iterator = typename Container::iterator; + using const_iterator = typename Container::const_iterator; + using size_type = typename Container::size_type; + using value_type = typename Container::value_type; // Explicit constructors instead of `using Container::Container` // otherwise older compilers choke on it (GCC <= 5.5, xcode <= 9.4) @@ -17494,16 +17125,55 @@ template , iterator erase(iterator pos) { - auto it = pos; + return erase(pos, std::next(pos)); + } + + iterator erase(iterator first, iterator last) + { + const auto elements_affected = std::distance(first, last); + const auto offset = std::distance(Container::begin(), first); + + // This is the start situation. We need to delete elements_affected + // elements (3 in this example: e, f, g), and need to return an + // iterator past the last deleted element (h in this example). + // Note that offset is the distance from the start of the vector + // to first. We will need this later. - // Since we cannot move const Keys, re-construct them in place - for (auto next = it; ++next != this->end(); ++it) + // [ a, b, c, d, e, f, g, h, i, j ] + // ^ ^ + // first last + + // Since we cannot move const Keys, we re-construct them in place. + // We start at first and re-construct (viz. copy) the elements from + // the back of the vector. Example for first iteration: + + // ,--------. + // v | destroy e and re-construct with h + // [ a, b, c, d, e, f, g, h, i, j ] + // ^ ^ + // it it + elements_affected + + for (auto it = first; std::next(it, elements_affected) != Container::end(); ++it) { - it->~value_type(); // Destroy but keep allocation - new (&*it) value_type{std::move(*next)}; + it->~value_type(); // destroy but keep allocation + new (&*it) value_type{std::move(*std::next(it, elements_affected))}; // "move" next element to it } - Container::pop_back(); - return pos; + + // [ a, b, c, d, h, i, j, h, i, j ] + // ^ ^ + // first last + + // remove the unneeded elements at the end of the vector + Container::resize(this->size() - static_cast(elements_affected)); + + // [ a, b, c, d, h, i, j ] + // ^ ^ + // first last + + // first is now pointing past the last deleted element, but we cannot + // use this iterator, because it may have been invalidated by the + // resize call. Instead, we can return begin() + offset. + return Container::begin() + offset; } size_type count(const Key& key) const @@ -17592,69 +17262,7 @@ namespace nlohmann /*! @brief a class to store JSON values -@tparam ObjectType type for JSON objects (`std::map` by default; will be used -in @ref object_t) -@tparam ArrayType type for JSON arrays (`std::vector` by default; will be used -in @ref array_t) -@tparam StringType type for JSON strings and object keys (`std::string` by -default; will be used in @ref string_t) -@tparam BooleanType type for JSON booleans (`bool` by default; will be used -in @ref boolean_t) -@tparam NumberIntegerType type for JSON integer numbers (`int64_t` by -default; will be used in @ref number_integer_t) -@tparam NumberUnsignedType type for JSON unsigned integer numbers (@c -`uint64_t` by default; will be used in @ref number_unsigned_t) -@tparam NumberFloatType type for JSON floating-point numbers (`double` by -default; will be used in @ref number_float_t) -@tparam BinaryType type for packed binary data for compatibility with binary -serialization formats (`std::vector` by default; will be used in -@ref binary_t) -@tparam AllocatorType type of the allocator to use (`std::allocator` by -default) -@tparam JSONSerializer the serializer to resolve internal calls to `to_json()` -and `from_json()` (@ref adl_serializer by default) - -@requirement The class satisfies the following concept requirements: -- Basic - - [DefaultConstructible](https://en.cppreference.com/w/cpp/named_req/DefaultConstructible): - JSON values can be default constructed. The result will be a JSON null - value. - - [MoveConstructible](https://en.cppreference.com/w/cpp/named_req/MoveConstructible): - A JSON value can be constructed from an rvalue argument. - - [CopyConstructible](https://en.cppreference.com/w/cpp/named_req/CopyConstructible): - A JSON value can be copy-constructed from an lvalue expression. - - [MoveAssignable](https://en.cppreference.com/w/cpp/named_req/MoveAssignable): - A JSON value van be assigned from an rvalue argument. - - [CopyAssignable](https://en.cppreference.com/w/cpp/named_req/CopyAssignable): - A JSON value can be copy-assigned from an lvalue expression. - - [Destructible](https://en.cppreference.com/w/cpp/named_req/Destructible): - JSON values can be destructed. -- Layout - - [StandardLayoutType](https://en.cppreference.com/w/cpp/named_req/StandardLayoutType): - JSON values have - [standard layout](https://en.cppreference.com/w/cpp/language/data_members#Standard_layout): - All non-static data members are private and standard layout types, the - class has no virtual functions or (virtual) base classes. -- Library-wide - - [EqualityComparable](https://en.cppreference.com/w/cpp/named_req/EqualityComparable): - JSON values can be compared with `==`, see @ref - operator==(const_reference,const_reference). - - [LessThanComparable](https://en.cppreference.com/w/cpp/named_req/LessThanComparable): - JSON values can be compared with `<`, see @ref - operator<(const_reference,const_reference). - - [Swappable](https://en.cppreference.com/w/cpp/named_req/Swappable): - Any JSON lvalue or rvalue of can be swapped with any lvalue or rvalue of - other compatible types, using unqualified function call @ref swap(). - - [NullablePointer](https://en.cppreference.com/w/cpp/named_req/NullablePointer): - JSON values can be compared against `std::nullptr_t` objects which are used - to model the `null` value. -- Container - - [Container](https://en.cppreference.com/w/cpp/named_req/Container): - JSON values can be used like STL containers and provide iterator access. - - [ReversibleContainer](https://en.cppreference.com/w/cpp/named_req/ReversibleContainer); - JSON values can be used like STL containers and provide reverse iterator - access. - +@internal @invariant The member variables @a m_value and @a m_type have the following relationship: - If `m_type == value_t::object`, then `m_value.object != nullptr`. @@ -17662,13 +17270,9 @@ and `from_json()` (@ref adl_serializer by default) - If `m_type == value_t::string`, then `m_value.string != nullptr`. The invariants are checked by member function assert_invariant(). -@internal @note ObjectType trick from https://stackoverflow.com/a/9860911 @endinternal -@see [RFC 8259: The JavaScript Object Notation (JSON) Data Interchange -Format](https://tools.ietf.org/html/rfc8259) - @since version 1.0.0 @nosubgrouping @@ -17759,17 +17363,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// Classes to implement user-defined exceptions. /// @{ - /// @copydoc detail::exception using exception = detail::exception; - /// @copydoc detail::parse_error using parse_error = detail::parse_error; - /// @copydoc detail::invalid_iterator using invalid_iterator = detail::invalid_iterator; - /// @copydoc detail::type_error using type_error = detail::type_error; - /// @copydoc detail::out_of_range using out_of_range = detail::out_of_range; - /// @copydoc detail::other_error using other_error = detail::other_error; /// @} @@ -17817,46 +17415,21 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @} - /*! - @brief returns the allocator associated with the container - */ + /// @brief returns the allocator associated with the container + /// @sa https://json.nlohmann.me/api/basic_json/get_allocator/ static allocator_type get_allocator() { return allocator_type(); } - /*! - @brief returns version information on the library - - This function returns a JSON object with information about the library, - including the version number and information on the platform and compiler. - - @return JSON object holding version information - key | description - ----------- | --------------- - `compiler` | Information on the used compiler. It is an object with the following keys: `c++` (the used C++ standard), `family` (the compiler family; possible values are `clang`, `icc`, `gcc`, `ilecpp`, `msvc`, `pgcpp`, `sunpro`, and `unknown`), and `version` (the compiler version). - `copyright` | The copyright line for the library as string. - `name` | The name of the library as string. - `platform` | The used platform as string. Possible values are `win32`, `linux`, `apple`, `unix`, and `unknown`. - `url` | The URL of the project as string. - `version` | The version of the library. It is an object with the following keys: `major`, `minor`, and `patch` as defined by [Semantic Versioning](http://semver.org), and `string` (the version string). - - @liveexample{The following code shows an example output of the `meta()` - function.,meta} - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes to any JSON value. - - @complexity Constant. - - @since 2.1.0 - */ + /// @brief returns version information on the library + /// @sa https://json.nlohmann.me/api/basic_json/meta/ JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json meta() { basic_json result; - result["copyright"] = "(C) 2013-2021 Niels Lohmann"; + result["copyright"] = "(C) 2013-2022 Niels Lohmann"; result["name"] = "JSON for Modern C++"; result["url"] = "https://github.com/nlohmann/json"; result["version"]["string"] = @@ -17917,6 +17490,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// the template arguments passed to class @ref basic_json. /// @{ + /// @brief object key comparator type + /// @sa https://json.nlohmann.me/api/basic_json/object_comparator_t/ #if defined(JSON_HAS_CPP_14) // Use transparent comparator if possible, combined with perfect forwarding // on find() and count() calls prevents unnecessary string construction. @@ -17925,501 +17500,42 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec using object_comparator_t = std::less; #endif - /*! - @brief a type for an object - - [RFC 8259](https://tools.ietf.org/html/rfc8259) describes JSON objects as follows: - > An object is an unordered collection of zero or more name/value pairs, - > where a name is a string and a value is a string, number, boolean, null, - > object, or array. - - To store objects in C++, a type is defined by the template parameters - described below. - - @tparam ObjectType the container to store objects (e.g., `std::map` or - `std::unordered_map`) - @tparam StringType the type of the keys or names (e.g., `std::string`). - The comparison function `std::less` is used to order elements - inside the container. - @tparam AllocatorType the allocator to use for objects (e.g., - `std::allocator`) - - #### Default type - - With the default values for @a ObjectType (`std::map`), @a StringType - (`std::string`), and @a AllocatorType (`std::allocator`), the default - value for @a object_t is: - - @code {.cpp} - std::map< - std::string, // key_type - basic_json, // value_type - std::less, // key_compare - std::allocator> // allocator_type - > - @endcode - - #### Behavior - - The choice of @a object_t influences the behavior of the JSON class. With - the default type, objects have the following behavior: - - - When all names are unique, objects will be interoperable in the sense - that all software implementations receiving that object will agree on - the name-value mappings. - - When the names within an object are not unique, it is unspecified which - one of the values for a given key will be chosen. For instance, - `{"key": 2, "key": 1}` could be equal to either `{"key": 1}` or - `{"key": 2}`. - - Internally, name/value pairs are stored in lexicographical order of the - names. Objects will also be serialized (see @ref dump) in this order. - For instance, `{"b": 1, "a": 2}` and `{"a": 2, "b": 1}` will be stored - and serialized as `{"a": 2, "b": 1}`. - - When comparing objects, the order of the name/value pairs is irrelevant. - This makes objects interoperable in the sense that they will not be - affected by these differences. For instance, `{"b": 1, "a": 2}` and - `{"a": 2, "b": 1}` will be treated as equal. - - #### Limits - - [RFC 8259](https://tools.ietf.org/html/rfc8259) specifies: - > An implementation may set limits on the maximum depth of nesting. - - In this class, the object's limit of nesting is not explicitly constrained. - However, a maximum depth of nesting may be introduced by the compiler or - runtime environment. A theoretical limit can be queried by calling the - @ref max_size function of a JSON object. - - #### Storage - - Objects are stored as pointers in a @ref basic_json type. That is, for any - access to object values, a pointer of type `object_t*` must be - dereferenced. - - @sa see @ref array_t -- type for an array value - - @since version 1.0.0 - - @note The order name/value pairs are added to the object is *not* - preserved by the library. Therefore, iterating an object may return - name/value pairs in a different order than they were originally stored. In - fact, keys will be traversed in alphabetical order as `std::map` with - `std::less` is used by default. Please note this behavior conforms to [RFC - 8259](https://tools.ietf.org/html/rfc8259), because any order implements the - specified "unordered" nature of JSON objects. - */ + /// @brief a type for an object + /// @sa https://json.nlohmann.me/api/basic_json/object_t/ using object_t = ObjectType>>; - /*! - @brief a type for an array - - [RFC 8259](https://tools.ietf.org/html/rfc8259) describes JSON arrays as follows: - > An array is an ordered sequence of zero or more values. - - To store objects in C++, a type is defined by the template parameters - explained below. - - @tparam ArrayType container type to store arrays (e.g., `std::vector` or - `std::list`) - @tparam AllocatorType allocator to use for arrays (e.g., `std::allocator`) - - #### Default type - - With the default values for @a ArrayType (`std::vector`) and @a - AllocatorType (`std::allocator`), the default value for @a array_t is: - - @code {.cpp} - std::vector< - basic_json, // value_type - std::allocator // allocator_type - > - @endcode - - #### Limits - - [RFC 8259](https://tools.ietf.org/html/rfc8259) specifies: - > An implementation may set limits on the maximum depth of nesting. - - In this class, the array's limit of nesting is not explicitly constrained. - However, a maximum depth of nesting may be introduced by the compiler or - runtime environment. A theoretical limit can be queried by calling the - @ref max_size function of a JSON array. - - #### Storage - - Arrays are stored as pointers in a @ref basic_json type. That is, for any - access to array values, a pointer of type `array_t*` must be dereferenced. - - @sa see @ref object_t -- type for an object value - - @since version 1.0.0 - */ + /// @brief a type for an array + /// @sa https://json.nlohmann.me/api/basic_json/array_t/ using array_t = ArrayType>; - /*! - @brief a type for a string - - [RFC 8259](https://tools.ietf.org/html/rfc8259) describes JSON strings as follows: - > A string is a sequence of zero or more Unicode characters. - - To store objects in C++, a type is defined by the template parameter - described below. Unicode values are split by the JSON class into - byte-sized characters during deserialization. - - @tparam StringType the container to store strings (e.g., `std::string`). - Note this container is used for keys/names in objects, see @ref object_t. - - #### Default type - - With the default values for @a StringType (`std::string`), the default - value for @a string_t is: - - @code {.cpp} - std::string - @endcode - - #### Encoding - - Strings are stored in UTF-8 encoding. Therefore, functions like - `std::string::size()` or `std::string::length()` return the number of - bytes in the string rather than the number of characters or glyphs. - - #### String comparison - - [RFC 8259](https://tools.ietf.org/html/rfc8259) states: - > Software implementations are typically required to test names of object - > members for equality. Implementations that transform the textual - > representation into sequences of Unicode code units and then perform the - > comparison numerically, code unit by code unit, are interoperable in the - > sense that implementations will agree in all cases on equality or - > inequality of two strings. For example, implementations that compare - > strings with escaped characters unconverted may incorrectly find that - > `"a\\b"` and `"a\u005Cb"` are not equal. - - This implementation is interoperable as it does compare strings code unit - by code unit. - - #### Storage - - String values are stored as pointers in a @ref basic_json type. That is, - for any access to string values, a pointer of type `string_t*` must be - dereferenced. - - @since version 1.0.0 - */ + /// @brief a type for a string + /// @sa https://json.nlohmann.me/api/basic_json/string_t/ using string_t = StringType; - /*! - @brief a type for a boolean - - [RFC 8259](https://tools.ietf.org/html/rfc8259) implicitly describes a boolean as a - type which differentiates the two literals `true` and `false`. - - To store objects in C++, a type is defined by the template parameter @a - BooleanType which chooses the type to use. - - #### Default type - - With the default values for @a BooleanType (`bool`), the default value for - @a boolean_t is: - - @code {.cpp} - bool - @endcode - - #### Storage - - Boolean values are stored directly inside a @ref basic_json type. - - @since version 1.0.0 - */ + /// @brief a type for a boolean + /// @sa https://json.nlohmann.me/api/basic_json/boolean_t/ using boolean_t = BooleanType; - /*! - @brief a type for a number (integer) - - [RFC 8259](https://tools.ietf.org/html/rfc8259) describes numbers as follows: - > The representation of numbers is similar to that used in most - > programming languages. A number is represented in base 10 using decimal - > digits. It contains an integer component that may be prefixed with an - > optional minus sign, which may be followed by a fraction part and/or an - > exponent part. Leading zeros are not allowed. (...) Numeric values that - > cannot be represented in the grammar below (such as Infinity and NaN) - > are not permitted. - - This description includes both integer and floating-point numbers. - However, C++ allows more precise storage if it is known whether the number - is a signed integer, an unsigned integer or a floating-point number. - Therefore, three different types, @ref number_integer_t, @ref - number_unsigned_t and @ref number_float_t are used. - - To store integer numbers in C++, a type is defined by the template - parameter @a NumberIntegerType which chooses the type to use. - - #### Default type - - With the default values for @a NumberIntegerType (`int64_t`), the default - value for @a number_integer_t is: - - @code {.cpp} - int64_t - @endcode - - #### Default behavior - - - The restrictions about leading zeros is not enforced in C++. Instead, - leading zeros in integer literals lead to an interpretation as octal - number. Internally, the value will be stored as decimal number. For - instance, the C++ integer literal `010` will be serialized to `8`. - During deserialization, leading zeros yield an error. - - Not-a-number (NaN) values will be serialized to `null`. - - #### Limits - - [RFC 8259](https://tools.ietf.org/html/rfc8259) specifies: - > An implementation may set limits on the range and precision of numbers. - - When the default type is used, the maximal integer number that can be - stored is `9223372036854775807` (INT64_MAX) and the minimal integer number - that can be stored is `-9223372036854775808` (INT64_MIN). Integer numbers - that are out of range will yield over/underflow when used in a - constructor. During deserialization, too large or small integer numbers - will be automatically be stored as @ref number_unsigned_t or @ref - number_float_t. - - [RFC 8259](https://tools.ietf.org/html/rfc8259) further states: - > Note that when such software is used, numbers that are integers and are - > in the range \f$[-2^{53}+1, 2^{53}-1]\f$ are interoperable in the sense - > that implementations will agree exactly on their numeric values. - - As this range is a subrange of the exactly supported range [INT64_MIN, - INT64_MAX], this class's integer type is interoperable. - - #### Storage - - Integer number values are stored directly inside a @ref basic_json type. - - @sa see @ref number_float_t -- type for number values (floating-point) - - @sa see @ref number_unsigned_t -- type for number values (unsigned integer) - - @since version 1.0.0 - */ + /// @brief a type for a number (integer) + /// @sa https://json.nlohmann.me/api/basic_json/number_integer_t/ using number_integer_t = NumberIntegerType; - /*! - @brief a type for a number (unsigned) - - [RFC 8259](https://tools.ietf.org/html/rfc8259) describes numbers as follows: - > The representation of numbers is similar to that used in most - > programming languages. A number is represented in base 10 using decimal - > digits. It contains an integer component that may be prefixed with an - > optional minus sign, which may be followed by a fraction part and/or an - > exponent part. Leading zeros are not allowed. (...) Numeric values that - > cannot be represented in the grammar below (such as Infinity and NaN) - > are not permitted. - - This description includes both integer and floating-point numbers. - However, C++ allows more precise storage if it is known whether the number - is a signed integer, an unsigned integer or a floating-point number. - Therefore, three different types, @ref number_integer_t, @ref - number_unsigned_t and @ref number_float_t are used. - - To store unsigned integer numbers in C++, a type is defined by the - template parameter @a NumberUnsignedType which chooses the type to use. - - #### Default type - - With the default values for @a NumberUnsignedType (`uint64_t`), the - default value for @a number_unsigned_t is: - - @code {.cpp} - uint64_t - @endcode - - #### Default behavior - - - The restrictions about leading zeros is not enforced in C++. Instead, - leading zeros in integer literals lead to an interpretation as octal - number. Internally, the value will be stored as decimal number. For - instance, the C++ integer literal `010` will be serialized to `8`. - During deserialization, leading zeros yield an error. - - Not-a-number (NaN) values will be serialized to `null`. - - #### Limits - - [RFC 8259](https://tools.ietf.org/html/rfc8259) specifies: - > An implementation may set limits on the range and precision of numbers. - - When the default type is used, the maximal integer number that can be - stored is `18446744073709551615` (UINT64_MAX) and the minimal integer - number that can be stored is `0`. Integer numbers that are out of range - will yield over/underflow when used in a constructor. During - deserialization, too large or small integer numbers will be automatically - be stored as @ref number_integer_t or @ref number_float_t. - - [RFC 8259](https://tools.ietf.org/html/rfc8259) further states: - > Note that when such software is used, numbers that are integers and are - > in the range \f$[-2^{53}+1, 2^{53}-1]\f$ are interoperable in the sense - > that implementations will agree exactly on their numeric values. - - As this range is a subrange (when considered in conjunction with the - number_integer_t type) of the exactly supported range [0, UINT64_MAX], - this class's integer type is interoperable. - - #### Storage - - Integer number values are stored directly inside a @ref basic_json type. - - @sa see @ref number_float_t -- type for number values (floating-point) - @sa see @ref number_integer_t -- type for number values (integer) - - @since version 2.0.0 - */ + /// @brief a type for a number (unsigned) + /// @sa https://json.nlohmann.me/api/basic_json/number_unsigned_t/ using number_unsigned_t = NumberUnsignedType; - /*! - @brief a type for a number (floating-point) - - [RFC 8259](https://tools.ietf.org/html/rfc8259) describes numbers as follows: - > The representation of numbers is similar to that used in most - > programming languages. A number is represented in base 10 using decimal - > digits. It contains an integer component that may be prefixed with an - > optional minus sign, which may be followed by a fraction part and/or an - > exponent part. Leading zeros are not allowed. (...) Numeric values that - > cannot be represented in the grammar below (such as Infinity and NaN) - > are not permitted. - - This description includes both integer and floating-point numbers. - However, C++ allows more precise storage if it is known whether the number - is a signed integer, an unsigned integer or a floating-point number. - Therefore, three different types, @ref number_integer_t, @ref - number_unsigned_t and @ref number_float_t are used. - - To store floating-point numbers in C++, a type is defined by the template - parameter @a NumberFloatType which chooses the type to use. - - #### Default type - - With the default values for @a NumberFloatType (`double`), the default - value for @a number_float_t is: - - @code {.cpp} - double - @endcode - - #### Default behavior - - - The restrictions about leading zeros is not enforced in C++. Instead, - leading zeros in floating-point literals will be ignored. Internally, - the value will be stored as decimal number. For instance, the C++ - floating-point literal `01.2` will be serialized to `1.2`. During - deserialization, leading zeros yield an error. - - Not-a-number (NaN) values will be serialized to `null`. - - #### Limits - - [RFC 8259](https://tools.ietf.org/html/rfc8259) states: - > This specification allows implementations to set limits on the range and - > precision of numbers accepted. Since software that implements IEEE - > 754-2008 binary64 (double precision) numbers is generally available and - > widely used, good interoperability can be achieved by implementations - > that expect no more precision or range than these provide, in the sense - > that implementations will approximate JSON numbers within the expected - > precision. - - This implementation does exactly follow this approach, as it uses double - precision floating-point numbers. Note values smaller than - `-1.79769313486232e+308` and values greater than `1.79769313486232e+308` - will be stored as NaN internally and be serialized to `null`. - - #### Storage - - Floating-point number values are stored directly inside a @ref basic_json - type. - - @sa see @ref number_integer_t -- type for number values (integer) - - @sa see @ref number_unsigned_t -- type for number values (unsigned integer) - - @since version 1.0.0 - */ + /// @brief a type for a number (floating-point) + /// @sa https://json.nlohmann.me/api/basic_json/number_float_t/ using number_float_t = NumberFloatType; - /*! - @brief a type for a packed binary type - - This type is a type designed to carry binary data that appears in various - serialized formats, such as CBOR's Major Type 2, MessagePack's bin, and - BSON's generic binary subtype. This type is NOT a part of standard JSON and - exists solely for compatibility with these binary types. As such, it is - simply defined as an ordered sequence of zero or more byte values. - - Additionally, as an implementation detail, the subtype of the binary data is - carried around as a `std::uint8_t`, which is compatible with both of the - binary data formats that use binary subtyping, (though the specific - numbering is incompatible with each other, and it is up to the user to - translate between them). - - [CBOR's RFC 7049](https://tools.ietf.org/html/rfc7049) describes this type - as: - > Major type 2: a byte string. The string's length in bytes is represented - > following the rules for positive integers (major type 0). - - [MessagePack's documentation on the bin type - family](https://github.com/msgpack/msgpack/blob/master/spec.md#bin-format-family) - describes this type as: - > Bin format family stores an byte array in 2, 3, or 5 bytes of extra bytes - > in addition to the size of the byte array. - - [BSON's specifications](http://bsonspec.org/spec.html) describe several - binary types; however, this type is intended to represent the generic binary - type which has the description: - > Generic binary subtype - This is the most commonly used binary subtype and - > should be the 'default' for drivers and tools. - - None of these impose any limitations on the internal representation other - than the basic unit of storage be some type of array whose parts are - decomposable into bytes. - - The default representation of this binary format is a - `std::vector`, which is a very common way to represent a byte - array in modern C++. - - #### Default type - - The default values for @a BinaryType is `std::vector` - - #### Storage - - Binary Arrays are stored as pointers in a @ref basic_json type. That is, - for any access to array values, a pointer of the type `binary_t*` must be - dereferenced. - - #### Notes on subtypes - - - CBOR - - Binary values are represented as byte strings. Subtypes are serialized - as tagged values. - - MessagePack - - If a subtype is given and the binary array contains exactly 1, 2, 4, 8, - or 16 elements, the fixext family (fixext1, fixext2, fixext4, fixext8) - is used. For other sizes, the ext family (ext8, ext16, ext32) is used. - The subtype is then added as singed 8-bit integer. - - If no subtype is given, the bin family (bin8, bin16, bin32) is used. - - BSON - - If a subtype is given, it is used and added as unsigned 8-bit integer. - - If no subtype is given, the generic binary subtype 0x00 is used. - - @sa see @ref binary -- create a binary array - - @since version 3.8.0 - */ + /// @brief a type for a packed binary type + /// @sa https://json.nlohmann.me/api/basic_json/binary_t/ using binary_t = nlohmann::byte_container_with_subtype; + /// @} private: @@ -18532,25 +17648,25 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec case value_t::boolean: { - boolean = boolean_t(false); + boolean = static_cast(false); break; } case value_t::number_integer: { - number_integer = number_integer_t(0); + number_integer = static_cast(0); break; } case value_t::number_unsigned: { - number_unsigned = number_unsigned_t(0); + number_unsigned = static_cast(0); break; } case value_t::number_float: { - number_float = number_float_t(0.0); + number_float = static_cast(0.0); break; } @@ -18566,7 +17682,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec object = nullptr; // silence warning, see #821 if (JSON_HEDLEY_UNLIKELY(t == value_t::null)) { - JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.10.4", basic_json())); // LCOV_EXCL_LINE + JSON_THROW(other_error::create(500, "961c151d2e87f2686a955a9be24d316f1362bf21 3.10.5", basic_json())); // LCOV_EXCL_LINE } break; } @@ -18574,64 +17690,34 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } /// constructor for strings - json_value(const string_t& value) - { - string = create(value); - } + json_value(const string_t& value) : string(create(value)) {} /// constructor for rvalue strings - json_value(string_t&& value) - { - string = create(std::move(value)); - } + json_value(string_t&& value) : string(create(std::move(value))) {} /// constructor for objects - json_value(const object_t& value) - { - object = create(value); - } + json_value(const object_t& value) : object(create(value)) {} /// constructor for rvalue objects - json_value(object_t&& value) - { - object = create(std::move(value)); - } + json_value(object_t&& value) : object(create(std::move(value))) {} /// constructor for arrays - json_value(const array_t& value) - { - array = create(value); - } + json_value(const array_t& value) : array(create(value)) {} /// constructor for rvalue arrays - json_value(array_t&& value) - { - array = create(std::move(value)); - } + json_value(array_t&& value) : array(create(std::move(value))) {} /// constructor for binary arrays - json_value(const typename binary_t::container_type& value) - { - binary = create(value); - } + json_value(const typename binary_t::container_type& value) : binary(create(value)) {} /// constructor for rvalue binary arrays - json_value(typename binary_t::container_type&& value) - { - binary = create(std::move(value)); - } + json_value(typename binary_t::container_type&& value) : binary(create(std::move(value))) {} /// constructor for binary arrays (internal type) - json_value(const binary_t& value) - { - binary = create(value); - } + json_value(const binary_t& value) : binary(create(value)) {} /// constructor for rvalue binary arrays (internal type) - json_value(binary_t&& value) - { - binary = create(std::move(value)); - } + json_value(binary_t&& value) : binary(create(std::move(value))) {} void destroy(value_t t) { @@ -18809,23 +17895,23 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec #endif } - iterator set_parents(iterator it, typename iterator::difference_type count) + iterator set_parents(iterator it, typename iterator::difference_type count_set_parents) { #if JSON_DIAGNOSTICS - for (typename iterator::difference_type i = 0; i < count; ++i) + for (typename iterator::difference_type i = 0; i < count_set_parents; ++i) { (it + i)->m_parent = this; } #else - static_cast(count); + static_cast(count_set_parents); #endif return it; } - reference set_parent(reference j, std::size_t old_capacity = std::size_t(-1)) + reference set_parent(reference j, std::size_t old_capacity = static_cast(-1)) { #if JSON_DIAGNOSTICS - if (old_capacity != std::size_t(-1)) + if (old_capacity != static_cast(-1)) { // see https://github.com/nlohmann/json/issues/2838 JSON_ASSERT(type() == value_t::array); @@ -18865,72 +17951,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // JSON parser callback // ////////////////////////// - /*! - @brief parser event types - - The parser callback distinguishes the following events: - - `object_start`: the parser read `{` and started to process a JSON object - - `key`: the parser read a key of a value in an object - - `object_end`: the parser read `}` and finished processing a JSON object - - `array_start`: the parser read `[` and started to process a JSON array - - `array_end`: the parser read `]` and finished processing a JSON array - - `value`: the parser finished reading a JSON value - - @image html callback_events.png "Example when certain parse events are triggered" - - @sa see @ref parser_callback_t for more information and examples - */ + /// @brief parser event types + /// @sa https://json.nlohmann.me/api/basic_json/parse_event_t/ using parse_event_t = detail::parse_event_t; - /*! - @brief per-element parser callback type - - With a parser callback function, the result of parsing a JSON text can be - influenced. When passed to @ref parse, it is called on certain events - (passed as @ref parse_event_t via parameter @a event) with a set recursion - depth @a depth and context JSON value @a parsed. The return value of the - callback function is a boolean indicating whether the element that emitted - the callback shall be kept or not. - - We distinguish six scenarios (determined by the event type) in which the - callback function can be called. The following table describes the values - of the parameters @a depth, @a event, and @a parsed. - - parameter @a event | description | parameter @a depth | parameter @a parsed - ------------------ | ----------- | ------------------ | ------------------- - parse_event_t::object_start | the parser read `{` and started to process a JSON object | depth of the parent of the JSON object | a JSON value with type discarded - parse_event_t::key | the parser read a key of a value in an object | depth of the currently parsed JSON object | a JSON string containing the key - parse_event_t::object_end | the parser read `}` and finished processing a JSON object | depth of the parent of the JSON object | the parsed JSON object - parse_event_t::array_start | the parser read `[` and started to process a JSON array | depth of the parent of the JSON array | a JSON value with type discarded - parse_event_t::array_end | the parser read `]` and finished processing a JSON array | depth of the parent of the JSON array | the parsed JSON array - parse_event_t::value | the parser finished reading a JSON value | depth of the value | the parsed JSON value - - @image html callback_events.png "Example when certain parse events are triggered" - - Discarding a value (i.e., returning `false`) has different effects - depending on the context in which function was called: - - - Discarded values in structured types are skipped. That is, the parser - will behave as if the discarded value was never read. - - In case a value outside a structured type is skipped, it is replaced - with `null`. This case happens if the top-level element is skipped. - - @param[in] depth the depth of the recursion during parsing - - @param[in] event an event of type parse_event_t indicating the context in - the callback function has been called - - @param[in,out] parsed the current intermediate parse result; note that - writing to this value has no effect for parse_event_t::key events - - @return Whether the JSON value which called the function during parsing - should be kept (`true`) or not (`false`). In the latter case, it is either - skipped completely or replaced by an empty discarded object. - - @sa see @ref parse for examples - - @since version 1.0.0 - */ + /// @brief per-element parser callback type + /// @sa https://json.nlohmann.me/api/basic_json/parser_callback_t/ using parser_callback_t = detail::parser_callback_t; ////////////////// @@ -18942,128 +17968,24 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// assignment, static functions creating objects, and the destructor. /// @{ - /*! - @brief create an empty value with a given type - - Create an empty JSON value with a given type. The value will be default - initialized with an empty value which depends on the type: - - Value type | initial value - ----------- | ------------- - null | `null` - boolean | `false` - string | `""` - number | `0` - object | `{}` - array | `[]` - binary | empty array - - @param[in] v the type of the value to create - - @complexity Constant. - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes to any JSON value. - - @liveexample{The following code shows the constructor for different @ref - value_t values,basic_json__value_t} - - @sa see @ref clear() -- restores the postcondition of this constructor - - @since version 1.0.0 - */ + /// @brief create an empty value with a given type + /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(const value_t v) : m_type(v), m_value(v) { assert_invariant(); } - /*! - @brief create a null object - - Create a `null` JSON value. It either takes a null pointer as parameter - (explicitly creating `null`) or no parameter (implicitly creating `null`). - The passed null pointer itself is not read -- it is only used to choose - the right constructor. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this constructor never throws - exceptions. - - @liveexample{The following code shows the constructor with and without a - null pointer parameter.,basic_json__nullptr_t} - - @since version 1.0.0 - */ + /// @brief create a null object + /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(std::nullptr_t = nullptr) noexcept : basic_json(value_t::null) { assert_invariant(); } - /*! - @brief create a JSON value - - This is a "catch all" constructor for all compatible JSON types; that is, - types for which a `to_json()` method exists. The constructor forwards the - parameter @a val to that method (to `json_serializer::to_json` method - with `U = uncvref_t`, to be exact). - - Template type @a CompatibleType includes, but is not limited to, the - following types: - - **arrays**: @ref array_t and all kinds of compatible containers such as - `std::vector`, `std::deque`, `std::list`, `std::forward_list`, - `std::array`, `std::valarray`, `std::set`, `std::unordered_set`, - `std::multiset`, and `std::unordered_multiset` with a `value_type` from - which a @ref basic_json value can be constructed. - - **objects**: @ref object_t and all kinds of compatible associative - containers such as `std::map`, `std::unordered_map`, `std::multimap`, - and `std::unordered_multimap` with a `key_type` compatible to - @ref string_t and a `value_type` from which a @ref basic_json value can - be constructed. - - **strings**: @ref string_t, string literals, and all compatible string - containers can be used. - - **numbers**: @ref number_integer_t, @ref number_unsigned_t, - @ref number_float_t, and all convertible number types such as `int`, - `size_t`, `int64_t`, `float` or `double` can be used. - - **boolean**: @ref boolean_t / `bool` can be used. - - **binary**: @ref binary_t / `std::vector` may be used, - unfortunately because string literals cannot be distinguished from binary - character arrays by the C++ type system, all types compatible with `const - char*` will be directed to the string constructor instead. This is both - for backwards compatibility, and due to the fact that a binary type is not - a standard JSON type. - - See the examples below. - - @tparam CompatibleType a type such that: - - @a CompatibleType is not derived from `std::istream`, - - @a CompatibleType is not @ref basic_json (to avoid hijacking copy/move - constructors), - - @a CompatibleType is not a different @ref basic_json type (i.e. with different template arguments) - - @a CompatibleType is not a @ref basic_json nested type (e.g., - @ref json_pointer, @ref iterator, etc ...) - - `json_serializer` has a `to_json(basic_json_t&, CompatibleType&&)` method - - @tparam U = `uncvref_t` - - @param[in] val the value to be forwarded to the respective constructor - - @complexity Usually linear in the size of the passed @a val, also - depending on the implementation of the called `to_json()` - method. - - @exceptionsafety Depends on the called constructor. For types directly - supported by the library (i.e., all types for which no `to_json()` function - was provided), strong guarantee holds: if an exception is thrown, there are - no changes to any JSON value. - - @liveexample{The following code shows the constructor with several - compatible types.,basic_json__CompatibleType} - - @since version 2.1.0 - */ + /// @brief create a JSON value from compatible types + /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ template < typename CompatibleType, typename U = detail::uncvref_t, detail::enable_if_t < @@ -19077,32 +17999,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - /*! - @brief create a JSON value from an existing one - - This is a constructor for existing @ref basic_json types. - It does not hijack copy/move constructors, since the parameter has different - template arguments than the current ones. - - The constructor tries to convert the internal @ref m_value of the parameter. - - @tparam BasicJsonType a type such that: - - @a BasicJsonType is a @ref basic_json type. - - @a BasicJsonType has different template arguments than @ref basic_json_t. - - @param[in] val the @ref basic_json value to be converted. - - @complexity Usually linear in the size of the passed @a val, also - depending on the implementation of the called `to_json()` - method. - - @exceptionsafety Depends on the called constructor. For types directly - supported by the library (i.e., all types for which no `to_json()` function - was provided), strong guarantee holds: if an exception is thrown, there are - no changes to any JSON value. - - @since version 3.2.0 - */ + /// @brief create a JSON value from an existing one + /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ template < typename BasicJsonType, detail::enable_if_t < detail::is_basic_json::value&& !std::is_same::value, int > = 0 > @@ -19156,80 +18054,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - /*! - @brief create a container (array or object) from an initializer list - - Creates a JSON value of type array or object from the passed initializer - list @a init. In case @a type_deduction is `true` (default), the type of - the JSON value to be created is deducted from the initializer list @a init - according to the following rules: - - 1. If the list is empty, an empty JSON object value `{}` is created. - 2. If the list consists of pairs whose first element is a string, a JSON - object value is created where the first elements of the pairs are - treated as keys and the second elements are as values. - 3. In all other cases, an array is created. - - The rules aim to create the best fit between a C++ initializer list and - JSON values. The rationale is as follows: - - 1. The empty initializer list is written as `{}` which is exactly an empty - JSON object. - 2. C++ has no way of describing mapped types other than to list a list of - pairs. As JSON requires that keys must be of type string, rule 2 is the - weakest constraint one can pose on initializer lists to interpret them - as an object. - 3. In all other cases, the initializer list could not be interpreted as - JSON object type, so interpreting it as JSON array type is safe. - - With the rules described above, the following JSON values cannot be - expressed by an initializer list: - - - the empty array (`[]`): use @ref array(initializer_list_t) - with an empty initializer list in this case - - arrays whose elements satisfy rule 2: use @ref - array(initializer_list_t) with the same initializer list - in this case - - @note When used without parentheses around an empty initializer list, @ref - basic_json() is called instead of this function, yielding the JSON null - value. - - @param[in] init initializer list with JSON values - - @param[in] type_deduction internal parameter; when set to `true`, the type - of the JSON value is deducted from the initializer list @a init; when set - to `false`, the type provided via @a manual_type is forced. This mode is - used by the functions @ref array(initializer_list_t) and - @ref object(initializer_list_t). - - @param[in] manual_type internal parameter; when @a type_deduction is set - to `false`, the created JSON value will use the provided type (only @ref - value_t::array and @ref value_t::object are valid); when @a type_deduction - is set to `true`, this parameter has no effect - - @throw type_error.301 if @a type_deduction is `false`, @a manual_type is - `value_t::object`, but @a init contains an element which is not a pair - whose first element is a string. In this case, the constructor could not - create an object. If @a type_deduction would have be `true`, an array - would have been created. See @ref object(initializer_list_t) - for an example. - - @complexity Linear in the size of the initializer list @a init. - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes to any JSON value. - - @liveexample{The example below shows how JSON values are created from - initializer lists.,basic_json__list_init_t} - - @sa see @ref array(initializer_list_t) -- create a JSON array - value from an initializer list - @sa see @ref object(initializer_list_t) -- create a JSON object - value from an initializer list - - @since version 1.0.0 - */ + /// @brief create a container (array or object) from an initializer list + /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(initializer_list_t init, bool type_deduction = true, value_t manual_type = value_t::array) @@ -19283,33 +18109,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - /*! - @brief explicitly create a binary array (without subtype) - - Creates a JSON binary array value from a given binary container. Binary - values are part of various binary formats, such as CBOR, MessagePack, and - BSON. This constructor is used to create a value for serialization to those - formats. - - @note Note, this function exists because of the difficulty in correctly - specifying the correct template overload in the standard value ctor, as both - JSON arrays and JSON binary arrays are backed with some form of a - `std::vector`. Because JSON binary arrays are a non-standard extension it - was decided that it would be best to prevent automatic initialization of a - binary array type, for backwards compatibility and so it does not happen on - accident. - - @param[in] init container containing bytes to use as binary type - - @return JSON binary array value - - @complexity Linear in the size of @a init. - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes to any JSON value. - - @since version 3.8.0 - */ + /// @brief explicitly create a binary array (without subtype) + /// @sa https://json.nlohmann.me/api/basic_json/binary/ JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json binary(const typename binary_t::container_type& init) { @@ -19319,34 +18120,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return res; } - /*! - @brief explicitly create a binary array (with subtype) - - Creates a JSON binary array value from a given binary container. Binary - values are part of various binary formats, such as CBOR, MessagePack, and - BSON. This constructor is used to create a value for serialization to those - formats. - - @note Note, this function exists because of the difficulty in correctly - specifying the correct template overload in the standard value ctor, as both - JSON arrays and JSON binary arrays are backed with some form of a - `std::vector`. Because JSON binary arrays are a non-standard extension it - was decided that it would be best to prevent automatic initialization of a - binary array type, for backwards compatibility and so it does not happen on - accident. - - @param[in] init container containing bytes to use as binary type - @param[in] subtype subtype to use in MessagePack and BSON - - @return JSON binary array value - - @complexity Linear in the size of @a init. - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes to any JSON value. - - @since version 3.8.0 - */ + /// @brief explicitly create a binary array (with subtype) + /// @sa https://json.nlohmann.me/api/basic_json/binary/ JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json binary(const typename binary_t::container_type& init, typename binary_t::subtype_type subtype) { @@ -19356,7 +18131,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return res; } - /// @copydoc binary(const typename binary_t::container_type&) + /// @brief explicitly create a binary array + /// @sa https://json.nlohmann.me/api/basic_json/binary/ JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json binary(typename binary_t::container_type&& init) { @@ -19366,7 +18142,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return res; } - /// @copydoc binary(const typename binary_t::container_type&, typename binary_t::subtype_type) + /// @brief explicitly create a binary array (with subtype) + /// @sa https://json.nlohmann.me/api/basic_json/binary/ JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json binary(typename binary_t::container_type&& init, typename binary_t::subtype_type subtype) { @@ -19376,115 +18153,24 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return res; } - /*! - @brief explicitly create an array from an initializer list - - Creates a JSON array value from a given initializer list. That is, given a - list of values `a, b, c`, creates the JSON value `[a, b, c]`. If the - initializer list is empty, the empty array `[]` is created. - - @note This function is only needed to express two edge cases that cannot - be realized with the initializer list constructor (@ref - basic_json(initializer_list_t, bool, value_t)). These cases - are: - 1. creating an array whose elements are all pairs whose first element is a - string -- in this case, the initializer list constructor would create an - object, taking the first elements as keys - 2. creating an empty array -- passing the empty initializer list to the - initializer list constructor yields an empty object - - @param[in] init initializer list with JSON values to create an array from - (optional) - - @return JSON array value - - @complexity Linear in the size of @a init. - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes to any JSON value. - - @liveexample{The following code shows an example for the `array` - function.,array} - - @sa see @ref basic_json(initializer_list_t, bool, value_t) -- - create a JSON value from an initializer list - @sa see @ref object(initializer_list_t) -- create a JSON object - value from an initializer list - - @since version 1.0.0 - */ + /// @brief explicitly create an array from an initializer list + /// @sa https://json.nlohmann.me/api/basic_json/array/ JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json array(initializer_list_t init = {}) { return basic_json(init, false, value_t::array); } - /*! - @brief explicitly create an object from an initializer list - - Creates a JSON object value from a given initializer list. The initializer - lists elements must be pairs, and their first elements must be strings. If - the initializer list is empty, the empty object `{}` is created. + /// @brief explicitly create an object from an initializer list + /// @sa https://json.nlohmann.me/api/basic_json/object/ + JSON_HEDLEY_WARN_UNUSED_RESULT + static basic_json object(initializer_list_t init = {}) + { + return basic_json(init, false, value_t::object); + } - @note This function is only added for symmetry reasons. In contrast to the - related function @ref array(initializer_list_t), there are - no cases which can only be expressed by this function. That is, any - initializer list @a init can also be passed to the initializer list - constructor @ref basic_json(initializer_list_t, bool, value_t). - - @param[in] init initializer list to create an object from (optional) - - @return JSON object value - - @throw type_error.301 if @a init is not a list of pairs whose first - elements are strings. In this case, no object can be created. When such a - value is passed to @ref basic_json(initializer_list_t, bool, value_t), - an array would have been created from the passed initializer list @a init. - See example below. - - @complexity Linear in the size of @a init. - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes to any JSON value. - - @liveexample{The following code shows an example for the `object` - function.,object} - - @sa see @ref basic_json(initializer_list_t, bool, value_t) -- - create a JSON value from an initializer list - @sa see @ref array(initializer_list_t) -- create a JSON array - value from an initializer list - - @since version 1.0.0 - */ - JSON_HEDLEY_WARN_UNUSED_RESULT - static basic_json object(initializer_list_t init = {}) - { - return basic_json(init, false, value_t::object); - } - - /*! - @brief construct an array with count copies of given value - - Constructs a JSON array value by creating @a cnt copies of a passed value. - In case @a cnt is `0`, an empty array is created. - - @param[in] cnt the number of JSON copies of @a val to create - @param[in] val the JSON value to copy - - @post `std::distance(begin(),end()) == cnt` holds. - - @complexity Linear in @a cnt. - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes to any JSON value. - - @liveexample{The following code shows examples for the @ref - basic_json(size_type\, const basic_json&) - constructor.,basic_json__size_type_basic_json} - - @since version 1.0.0 - */ + /// @brief construct an array with count copies of given value + /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(size_type cnt, const basic_json& val) : m_type(value_t::array) { @@ -19493,61 +18179,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - /*! - @brief construct a JSON container given an iterator range - - Constructs the JSON value with the contents of the range `[first, last)`. - The semantics depends on the different types a JSON value can have: - - In case of a null type, invalid_iterator.206 is thrown. - - In case of other primitive types (number, boolean, or string), @a first - must be `begin()` and @a last must be `end()`. In this case, the value is - copied. Otherwise, invalid_iterator.204 is thrown. - - In case of structured types (array, object), the constructor behaves as - similar versions for `std::vector` or `std::map`; that is, a JSON array - or object is constructed from the values in the range. - - @tparam InputIT an input iterator type (@ref iterator or @ref - const_iterator) - - @param[in] first begin of the range to copy from (included) - @param[in] last end of the range to copy from (excluded) - - @pre Iterators @a first and @a last must be initialized. **This - precondition is enforced with an assertion (see warning).** If - assertions are switched off, a violation of this precondition yields - undefined behavior. - - @pre Range `[first, last)` is valid. Usually, this precondition cannot be - checked efficiently. Only certain edge cases are detected; see the - description of the exceptions below. A violation of this precondition - yields undefined behavior. - - @warning A precondition is enforced with a runtime assertion that will - result in calling `std::abort` if this precondition is not met. - Assertions can be disabled by defining `NDEBUG` at compile time. - See https://en.cppreference.com/w/cpp/error/assert for more - information. - - @throw invalid_iterator.201 if iterators @a first and @a last are not - compatible (i.e., do not belong to the same JSON value). In this case, - the range `[first, last)` is undefined. - @throw invalid_iterator.204 if iterators @a first and @a last belong to a - primitive type (number, boolean, or string), but @a first does not point - to the first element any more. In this case, the range `[first, last)` is - undefined. See example code below. - @throw invalid_iterator.206 if iterators @a first and @a last belong to a - null value. In this case, the range `[first, last)` is undefined. - - @complexity Linear in distance between @a first and @a last. - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes to any JSON value. - - @liveexample{The example below shows several ways to create JSON values by - specifying a subrange with iterators.,basic_json__InputIt_InputIt} - - @since version 1.0.0 - */ + /// @brief construct a JSON container given an iterator range + /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ template < class InputIT, typename std::enable_if < std::is_same::value || std::is_same::value, int >::type = 0 > @@ -19663,31 +18296,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec std::is_same>::value, int> = 0 > basic_json(const JsonRef& ref) : basic_json(ref.moved_or_copied()) {} - /*! - @brief copy constructor - - Creates a copy of a given JSON value. - - @param[in] other the JSON value to copy - - @post `*this == other` - - @complexity Linear in the size of @a other. - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes to any JSON value. - - @requirement This function helps `basic_json` satisfying the - [Container](https://en.cppreference.com/w/cpp/named_req/Container) - requirements: - - The complexity is linear. - - As postcondition, it holds: `other == basic_json(other)`. - - @liveexample{The following code shows an example for the copy - constructor.,basic_json__basic_json} - - @since version 1.0.0 - */ + /// @brief copy constructor + /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(const basic_json& other) : m_type(other.m_type) { @@ -19754,32 +18364,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - /*! - @brief move constructor - - Move constructor. Constructs a JSON value with the contents of the given - value @a other using move semantics. It "steals" the resources from @a - other and leaves it as JSON null value. - - @param[in,out] other value to move to this object - - @post `*this` has the same value as @a other before the call. - @post @a other is a JSON null value. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this constructor never throws - exceptions. - - @requirement This function helps `basic_json` satisfying the - [MoveConstructible](https://en.cppreference.com/w/cpp/named_req/MoveConstructible) - requirements. - - @liveexample{The code below shows the move constructor explicitly called - via std::move.,basic_json__moveconstructor} - - @since version 1.0.0 - */ + /// @brief move constructor + /// @sa https://json.nlohmann.me/api/basic_json/basic_json/ basic_json(basic_json&& other) noexcept : m_type(std::move(other.m_type)), m_value(std::move(other.m_value)) @@ -19795,29 +18381,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - /*! - @brief copy assignment - - Copy assignment operator. Copies a JSON value via the "copy and swap" - strategy: It is expressed in terms of the copy constructor, destructor, - and the `swap()` member function. - - @param[in] other value to copy from - - @complexity Linear. - - @requirement This function helps `basic_json` satisfying the - [Container](https://en.cppreference.com/w/cpp/named_req/Container) - requirements: - - The complexity is linear. - - @liveexample{The code below shows and example for the copy assignment. It - creates a copy of value `a` which is then swapped with `b`. Finally\, the - copy of `a` (which is the null value after the swap) is - destroyed.,basic_json__copyassignment} - - @since version 1.0.0 - */ + /// @brief copy assignment + /// @sa https://json.nlohmann.me/api/basic_json/operator=/ basic_json& operator=(basic_json other) noexcept ( std::is_nothrow_move_constructible::value&& std::is_nothrow_move_assignable::value&& @@ -19837,21 +18402,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return *this; } - /*! - @brief destructor - - Destroys the JSON value and frees all allocated memory. - - @complexity Linear. - - @requirement This function helps `basic_json` satisfying the - [Container](https://en.cppreference.com/w/cpp/named_req/Container) - requirements: - - The complexity is linear. - - All stored elements are destroyed and all memory is freed. - - @since version 1.0.0 - */ + /// @brief destructor + /// @sa https://json.nlohmann.me/api/basic_json/~basic_json/ ~basic_json() noexcept { assert_invariant(false); @@ -19869,53 +18421,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// Functions to inspect the type of a JSON value. /// @{ - /*! - @brief serialization - - Serialization function for JSON values. The function tries to mimic - Python's `json.dumps()` function, and currently supports its @a indent - and @a ensure_ascii parameters. - - @param[in] indent If indent is nonnegative, then array elements and object - members will be pretty-printed with that indent level. An indent level of - `0` will only insert newlines. `-1` (the default) selects the most compact - representation. - @param[in] indent_char The character to use for indentation if @a indent is - greater than `0`. The default is ` ` (space). - @param[in] ensure_ascii If @a ensure_ascii is true, all non-ASCII characters - in the output are escaped with `\uXXXX` sequences, and the result consists - of ASCII characters only. - @param[in] error_handler how to react on decoding errors; there are three - possible values: `strict` (throws and exception in case a decoding error - occurs; default), `replace` (replace invalid UTF-8 sequences with U+FFFD), - and `ignore` (ignore invalid UTF-8 sequences during serialization; all - bytes are copied to the output unchanged). - - @return string containing the serialization of the JSON value - - @throw type_error.316 if a string stored inside the JSON value is not - UTF-8 encoded and @a error_handler is set to strict - - @note Binary values are serialized as object containing two keys: - - "bytes": an array of bytes as integers - - "subtype": the subtype as integer or "null" if the binary has no subtype - - @complexity Linear. - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes in the JSON value. - - @liveexample{The following example shows the effect of different @a indent\, - @a indent_char\, and @a ensure_ascii parameters to the result of the - serialization.,dump} - - @see https://docs.python.org/2/library/json.html#json.dump - - @since version 1.0.0; indentation character @a indent_char, option - @a ensure_ascii and exceptions added in version 3.0.0; error - handlers added in version 3.4.0; serialization of binary values added - in version 3.8.0. - */ + /// @brief serialization + /// @sa https://json.nlohmann.me/api/basic_json/dump/ string_t dump(const int indent = -1, const char indent_char = ' ', const bool ensure_ascii = false, @@ -19936,397 +18443,106 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } - /*! - @brief return the type of the JSON value (explicit) - - Return the type of the JSON value as a value from the @ref value_t - enumeration. - - @return the type of the JSON value - Value type | return value - ------------------------- | ------------------------- - null | value_t::null - boolean | value_t::boolean - string | value_t::string - number (integer) | value_t::number_integer - number (unsigned integer) | value_t::number_unsigned - number (floating-point) | value_t::number_float - object | value_t::object - array | value_t::array - binary | value_t::binary - discarded | value_t::discarded - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `type()` for all JSON - types.,type} - - @sa see @ref operator value_t() -- return the type of the JSON value (implicit) - @sa see @ref type_name() -- return the type as string - - @since version 1.0.0 - */ + /// @brief return the type of the JSON value (explicit) + /// @sa https://json.nlohmann.me/api/basic_json/type/ constexpr value_t type() const noexcept { return m_type; } - /*! - @brief return whether type is primitive - - This function returns true if and only if the JSON type is primitive - (string, number, boolean, or null). - - @return `true` if type is primitive (string, number, boolean, or null), - `false` otherwise. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `is_primitive()` for all JSON - types.,is_primitive} - - @sa see @ref is_structured() -- returns whether JSON value is structured - @sa see @ref is_null() -- returns whether JSON value is `null` - @sa see @ref is_string() -- returns whether JSON value is a string - @sa see @ref is_boolean() -- returns whether JSON value is a boolean - @sa see @ref is_number() -- returns whether JSON value is a number - @sa see @ref is_binary() -- returns whether JSON value is a binary array - - @since version 1.0.0 - */ + /// @brief return whether type is primitive + /// @sa https://json.nlohmann.me/api/basic_json/is_primitive/ constexpr bool is_primitive() const noexcept { return is_null() || is_string() || is_boolean() || is_number() || is_binary(); } - /*! - @brief return whether type is structured - - This function returns true if and only if the JSON type is structured - (array or object). - - @return `true` if type is structured (array or object), `false` otherwise. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `is_structured()` for all JSON - types.,is_structured} - - @sa see @ref is_primitive() -- returns whether value is primitive - @sa see @ref is_array() -- returns whether value is an array - @sa see @ref is_object() -- returns whether value is an object - - @since version 1.0.0 - */ + /// @brief return whether type is structured + /// @sa https://json.nlohmann.me/api/basic_json/is_structured/ constexpr bool is_structured() const noexcept { return is_array() || is_object(); } - /*! - @brief return whether value is null - - This function returns true if and only if the JSON value is null. - - @return `true` if type is null, `false` otherwise. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `is_null()` for all JSON - types.,is_null} - - @since version 1.0.0 - */ + /// @brief return whether value is null + /// @sa https://json.nlohmann.me/api/basic_json/is_null/ constexpr bool is_null() const noexcept { return m_type == value_t::null; } - /*! - @brief return whether value is a boolean - - This function returns true if and only if the JSON value is a boolean. - - @return `true` if type is boolean, `false` otherwise. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `is_boolean()` for all JSON - types.,is_boolean} - - @since version 1.0.0 - */ + /// @brief return whether value is a boolean + /// @sa https://json.nlohmann.me/api/basic_json/is_boolean/ constexpr bool is_boolean() const noexcept { return m_type == value_t::boolean; } - /*! - @brief return whether value is a number - - This function returns true if and only if the JSON value is a number. This - includes both integer (signed and unsigned) and floating-point values. - - @return `true` if type is number (regardless whether integer, unsigned - integer or floating-type), `false` otherwise. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `is_number()` for all JSON - types.,is_number} - - @sa see @ref is_number_integer() -- check if value is an integer or unsigned - integer number - @sa see @ref is_number_unsigned() -- check if value is an unsigned integer - number - @sa see @ref is_number_float() -- check if value is a floating-point number - - @since version 1.0.0 - */ + /// @brief return whether value is a number + /// @sa https://json.nlohmann.me/api/basic_json/is_number/ constexpr bool is_number() const noexcept { return is_number_integer() || is_number_float(); } - /*! - @brief return whether value is an integer number - - This function returns true if and only if the JSON value is a signed or - unsigned integer number. This excludes floating-point values. - - @return `true` if type is an integer or unsigned integer number, `false` - otherwise. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `is_number_integer()` for all - JSON types.,is_number_integer} - - @sa see @ref is_number() -- check if value is a number - @sa see @ref is_number_unsigned() -- check if value is an unsigned integer - number - @sa see @ref is_number_float() -- check if value is a floating-point number - - @since version 1.0.0 - */ + /// @brief return whether value is an integer number + /// @sa https://json.nlohmann.me/api/basic_json/is_number_integer/ constexpr bool is_number_integer() const noexcept { return m_type == value_t::number_integer || m_type == value_t::number_unsigned; } - /*! - @brief return whether value is an unsigned integer number - - This function returns true if and only if the JSON value is an unsigned - integer number. This excludes floating-point and signed integer values. - - @return `true` if type is an unsigned integer number, `false` otherwise. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `is_number_unsigned()` for all - JSON types.,is_number_unsigned} - - @sa see @ref is_number() -- check if value is a number - @sa see @ref is_number_integer() -- check if value is an integer or unsigned - integer number - @sa see @ref is_number_float() -- check if value is a floating-point number - - @since version 2.0.0 - */ + /// @brief return whether value is an unsigned integer number + /// @sa https://json.nlohmann.me/api/basic_json/is_number_unsigned/ constexpr bool is_number_unsigned() const noexcept { return m_type == value_t::number_unsigned; } - /*! - @brief return whether value is a floating-point number - - This function returns true if and only if the JSON value is a - floating-point number. This excludes signed and unsigned integer values. - - @return `true` if type is a floating-point number, `false` otherwise. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `is_number_float()` for all - JSON types.,is_number_float} - - @sa see @ref is_number() -- check if value is number - @sa see @ref is_number_integer() -- check if value is an integer number - @sa see @ref is_number_unsigned() -- check if value is an unsigned integer - number - - @since version 1.0.0 - */ + /// @brief return whether value is a floating-point number + /// @sa https://json.nlohmann.me/api/basic_json/is_number_float/ constexpr bool is_number_float() const noexcept { return m_type == value_t::number_float; } - /*! - @brief return whether value is an object - - This function returns true if and only if the JSON value is an object. - - @return `true` if type is object, `false` otherwise. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `is_object()` for all JSON - types.,is_object} - - @since version 1.0.0 - */ + /// @brief return whether value is an object + /// @sa https://json.nlohmann.me/api/basic_json/is_object/ constexpr bool is_object() const noexcept { return m_type == value_t::object; } - /*! - @brief return whether value is an array - - This function returns true if and only if the JSON value is an array. - - @return `true` if type is array, `false` otherwise. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `is_array()` for all JSON - types.,is_array} - - @since version 1.0.0 - */ + /// @brief return whether value is an array + /// @sa https://json.nlohmann.me/api/basic_json/is_array/ constexpr bool is_array() const noexcept { return m_type == value_t::array; } - /*! - @brief return whether value is a string - - This function returns true if and only if the JSON value is a string. - - @return `true` if type is string, `false` otherwise. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `is_string()` for all JSON - types.,is_string} - - @since version 1.0.0 - */ + /// @brief return whether value is a string + /// @sa https://json.nlohmann.me/api/basic_json/is_string/ constexpr bool is_string() const noexcept { return m_type == value_t::string; } - /*! - @brief return whether value is a binary array - - This function returns true if and only if the JSON value is a binary array. - - @return `true` if type is binary array, `false` otherwise. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `is_binary()` for all JSON - types.,is_binary} - - @since version 3.8.0 - */ + /// @brief return whether value is a binary array + /// @sa https://json.nlohmann.me/api/basic_json/is_binary/ constexpr bool is_binary() const noexcept { return m_type == value_t::binary; } - /*! - @brief return whether value is discarded - - This function returns true if and only if the JSON value was discarded - during parsing with a callback function (see @ref parser_callback_t). - - @note This function will always be `false` for JSON values after parsing. - That is, discarded values can only occur during parsing, but will be - removed when inside a structured value or replaced by null in other cases. - - @return `true` if type is discarded, `false` otherwise. - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies `is_discarded()` for all JSON - types.,is_discarded} - - @since version 1.0.0 - */ + /// @brief return whether value is discarded + /// @sa https://json.nlohmann.me/api/basic_json/is_discarded/ constexpr bool is_discarded() const noexcept { return m_type == value_t::discarded; } - /*! - @brief return the type of the JSON value (implicit) - - Implicitly return the type of the JSON value as a value from the @ref - value_t enumeration. - - @return the type of the JSON value - - @complexity Constant. - - @exceptionsafety No-throw guarantee: this member function never throws - exceptions. - - @liveexample{The following code exemplifies the @ref value_t operator for - all JSON types.,operator__value_t} - - @sa see @ref type() -- return the type of the JSON value (explicit) - @sa see @ref type_name() -- return the type as string - - @since version 1.0.0 - */ + /// @brief return the type of the JSON value (implicit) + /// @sa https://json.nlohmann.me/api/basic_json/operator_value_t/ constexpr operator value_t() const noexcept { return m_type; @@ -20476,32 +18692,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// Direct access to the stored value of a JSON value. /// @{ - /*! - @brief get a pointer value (implicit) - - Implicit pointer access to the internally stored JSON value. No copies are - made. - - @warning Writing data to the pointee of the result yields an undefined - state. - - @tparam PointerType pointer type; must be a pointer to @ref array_t, @ref - object_t, @ref string_t, @ref boolean_t, @ref number_integer_t, - @ref number_unsigned_t, or @ref number_float_t. Enforced by a static - assertion. - - @return pointer to the internally stored JSON value if the requested - pointer type @a PointerType fits to the JSON value; `nullptr` otherwise - - @complexity Constant. - - @liveexample{The example below shows how pointers to internal values of a - JSON value can be requested. Note that no type conversions are made and a - `nullptr` is returned if the value and the requested pointer type does not - match.,get_ptr} - - @since version 1.0.0 - */ + /// @brief get a pointer value (implicit) + /// @sa https://json.nlohmann.me/api/basic_json/get_ptr/ template::value, int>::type = 0> auto get_ptr() noexcept -> decltype(std::declval().get_impl_ptr(std::declval())) @@ -20510,10 +18702,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return get_impl_ptr(static_cast(nullptr)); } - /*! - @brief get a pointer value (implicit) - @copydoc get_ptr() - */ + /// @brief get a pointer value (implicit) + /// @sa https://json.nlohmann.me/api/basic_json/get_ptr/ template < typename PointerType, typename std::enable_if < std::is_pointer::value&& std::is_const::type>::value, int >::type = 0 > @@ -20752,39 +18942,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return get_ptr(); } - /*! - @brief get a value (explicit) - - Explicit type conversion between the JSON value and a compatible value. - The value is filled into the input parameter by calling the @ref json_serializer - `from_json()` method. - - The function is equivalent to executing - @code {.cpp} - ValueType v; - JSONSerializer::from_json(*this, v); - @endcode - - This overloads is chosen if: - - @a ValueType is not @ref basic_json, - - @ref json_serializer has a `from_json()` method of the form - `void from_json(const basic_json&, ValueType&)`, and - - @tparam ValueType the input parameter type. - - @return the input parameter, allowing chaining calls. - - @throw what @ref json_serializer `from_json()` method throws - - @liveexample{The example below shows several conversions from JSON values - to other types. There a few things to note: (1) Floating-point numbers can - be converted to integers\, (2) A JSON array can be converted to a standard - `std::vector`\, (3) A JSON object can be converted to C++ - associative containers such as `std::unordered_map`.,get_to} - - @since version 3.3.0 - */ + /// @brief get a value (explicit) + /// @sa https://json.nlohmann.me/api/basic_json/get_to/ template < typename ValueType, detail::enable_if_t < !detail::is_basic_json::value&& @@ -20797,7 +18956,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return v; } - // specialization to allow to call get_to with a basic_json value + // specialization to allow calling get_to with a basic_json value // see https://github.com/nlohmann/json/issues/2175 template::value, int>::type = 0> ReferenceType get_ref() @@ -20856,10 +18991,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return get_ref_impl(*this); } - /*! - @brief get a reference value (implicit) - @copydoc get_ref() - */ + /// @brief get a reference value (implicit) + /// @sa https://json.nlohmann.me/api/basic_json/get_ref/ template < typename ReferenceType, typename std::enable_if < std::is_reference::value&& std::is_const::type>::value, int >::type = 0 > @@ -20917,15 +19050,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return get(); } - /*! - @return reference to the binary value - - @throw type_error.302 if the value is not binary - - @sa see @ref is_binary() to check if the value is binary - - @since version 3.8.0 - */ + /// @brief get a binary value + /// @sa https://json.nlohmann.me/api/basic_json/get_binary/ binary_t& get_binary() { if (!is_binary()) @@ -20936,7 +19062,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return *get_ptr(); } - /// @copydoc get_binary() + /// @brief get a binary value + /// @sa https://json.nlohmann.me/api/basic_json/get_binary/ const binary_t& get_binary() const { if (!is_binary()) @@ -20958,32 +19085,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// Access to the JSON value. /// @{ - /*! - @brief access specified array element with bounds checking - - Returns a reference to the element at specified location @a idx, with - bounds checking. - - @param[in] idx index of the element to access - - @return reference to the element at index @a idx - - @throw type_error.304 if the JSON value is not an array; in this case, - calling `at` with an index makes no sense. See example below. - @throw out_of_range.401 if the index @a idx is out of range of the array; - that is, `idx >= size()`. See example below. - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes in the JSON value. - - @complexity Constant. - - @since version 1.0.0 - - @liveexample{The example below shows how array elements can be read and - written using `at()`. It also demonstrates the different exceptions that - can be thrown.,at__size_type} - */ + /// @brief access specified array element with bounds checking + /// @sa https://json.nlohmann.me/api/basic_json/at/ reference at(size_type idx) { // at only works for arrays @@ -21005,32 +19108,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } } - /*! - @brief access specified array element with bounds checking - - Returns a const reference to the element at specified location @a idx, - with bounds checking. - - @param[in] idx index of the element to access - - @return const reference to the element at index @a idx - - @throw type_error.304 if the JSON value is not an array; in this case, - calling `at` with an index makes no sense. See example below. - @throw out_of_range.401 if the index @a idx is out of range of the array; - that is, `idx >= size()`. See example below. - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes in the JSON value. - - @complexity Constant. - - @since version 1.0.0 - - @liveexample{The example below shows how array elements can be read using - `at()`. It also demonstrates the different exceptions that can be thrown., - at__size_type_const} - */ + /// @brief access specified array element with bounds checking + /// @sa https://json.nlohmann.me/api/basic_json/at/ const_reference at(size_type idx) const { // at only works for arrays @@ -21052,36 +19131,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } } - /*! - @brief access specified object element with bounds checking - - Returns a reference to the element at with specified key @a key, with - bounds checking. - - @param[in] key key of the element to access - - @return reference to the element at key @a key - - @throw type_error.304 if the JSON value is not an object; in this case, - calling `at` with a key makes no sense. See example below. - @throw out_of_range.403 if the key @a key is is not stored in the object; - that is, `find(key) == end()`. See example below. - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes in the JSON value. - - @complexity Logarithmic in the size of the container. - - @sa see @ref operator[](const typename object_t::key_type&) for unchecked - access by reference - @sa see @ref value() for access by value with a default value - - @since version 1.0.0 - - @liveexample{The example below shows how object elements can be read and - written using `at()`. It also demonstrates the different exceptions that - can be thrown.,at__object_t_key_type} - */ + /// @brief access specified object element with bounds checking + /// @sa https://json.nlohmann.me/api/basic_json/at/ reference at(const typename object_t::key_type& key) { // at only works for objects @@ -21103,36 +19154,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } } - /*! - @brief access specified object element with bounds checking - - Returns a const reference to the element at with specified key @a key, - with bounds checking. - - @param[in] key key of the element to access - - @return const reference to the element at key @a key - - @throw type_error.304 if the JSON value is not an object; in this case, - calling `at` with a key makes no sense. See example below. - @throw out_of_range.403 if the key @a key is is not stored in the object; - that is, `find(key) == end()`. See example below. - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes in the JSON value. - - @complexity Logarithmic in the size of the container. - - @sa see @ref operator[](const typename object_t::key_type&) for unchecked - access by reference - @sa see @ref value() for access by value with a default value - - @since version 1.0.0 - - @liveexample{The example below shows how object elements can be read using - `at()`. It also demonstrates the different exceptions that can be thrown., - at__object_t_key_type_const} - */ + /// @brief access specified object element with bounds checking + /// @sa https://json.nlohmann.me/api/basic_json/at/ const_reference at(const typename object_t::key_type& key) const { // at only works for objects @@ -21154,31 +19177,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } } - /*! - @brief access specified array element - - Returns a reference to the element at specified location @a idx. - - @note If @a idx is beyond the range of the array (i.e., `idx >= size()`), - then the array is silently filled up with `null` values to make `idx` a - valid reference to the last stored element. - - @param[in] idx index of the element to access - - @return reference to the element at index @a idx - - @throw type_error.305 if the JSON value is not an array or null; in that - cases, using the [] operator with an index makes no sense. - - @complexity Constant if @a idx is in the range of the array. Otherwise - linear in `idx - size()`. - - @liveexample{The example below shows how array elements can be read and - written using `[]` operator. Note the addition of `null` - values.,operatorarray__size_type} - - @since version 1.0.0 - */ + /// @brief access specified array element + /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ reference operator[](size_type idx) { // implicitly convert null value to an empty array @@ -21223,25 +19223,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name()), *this)); } - /*! - @brief access specified array element - - Returns a const reference to the element at specified location @a idx. - - @param[in] idx index of the element to access - - @return const reference to the element at index @a idx - - @throw type_error.305 if the JSON value is not an array; in that case, - using the [] operator with an index makes no sense. - - @complexity Constant. - - @liveexample{The example below shows how array elements can be read using - the `[]` operator.,operatorarray__size_type_const} - - @since version 1.0.0 - */ + /// @brief access specified array element + /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ const_reference operator[](size_type idx) const { // const operator[] only works for arrays @@ -21253,33 +19236,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(305, "cannot use operator[] with a numeric argument with " + std::string(type_name()), *this)); } - /*! - @brief access specified object element - - Returns a reference to the element at with specified key @a key. - - @note If @a key is not found in the object, then it is silently added to - the object and filled with a `null` value to make `key` a valid reference. - In case the value was `null` before, it is converted to an object. - - @param[in] key key of the element to access - - @return reference to the element at key @a key - - @throw type_error.305 if the JSON value is not an object or null; in that - cases, using the [] operator with a key makes no sense. - - @complexity Logarithmic in the size of the container. - - @liveexample{The example below shows how object elements can be read and - written using the `[]` operator.,operatorarray__key_type} - - @sa see @ref at(const typename object_t::key_type&) for access by reference - with range checking - @sa see @ref value() for access by value with a default value - - @since version 1.0.0 - */ + /// @brief access specified object element + /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ reference operator[](const typename object_t::key_type& key) { // implicitly convert null value to an empty object @@ -21299,36 +19257,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this)); } - /*! - @brief read-only access specified object element - - Returns a const reference to the element at with specified key @a key. No - bounds checking is performed. - - @warning If the element with key @a key does not exist, the behavior is - undefined. - - @param[in] key key of the element to access - - @return const reference to the element at key @a key - - @pre The element with key @a key must exist. **This precondition is - enforced with an assertion.** - - @throw type_error.305 if the JSON value is not an object; in that case, - using the [] operator with a key makes no sense. - - @complexity Logarithmic in the size of the container. - - @liveexample{The example below shows how object elements can be read using - the `[]` operator.,operatorarray__key_type_const} - - @sa see @ref at(const typename object_t::key_type&) for access by reference - with range checking - @sa see @ref value() for access by value with a default value - - @since version 1.0.0 - */ + /// @brief access specified object element + /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ const_reference operator[](const typename object_t::key_type& key) const { // const operator[] only works for objects @@ -21341,33 +19271,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this)); } - /*! - @brief access specified object element - - Returns a reference to the element at with specified key @a key. - - @note If @a key is not found in the object, then it is silently added to - the object and filled with a `null` value to make `key` a valid reference. - In case the value was `null` before, it is converted to an object. - - @param[in] key key of the element to access - - @return reference to the element at key @a key - - @throw type_error.305 if the JSON value is not an object or null; in that - cases, using the [] operator with a key makes no sense. - - @complexity Logarithmic in the size of the container. - - @liveexample{The example below shows how object elements can be read and - written using the `[]` operator.,operatorarray__key_type} - - @sa see @ref at(const typename object_t::key_type&) for access by reference - with range checking - @sa see @ref value() for access by value with a default value - - @since version 1.1.0 - */ + /// @brief access specified object element + /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ template JSON_HEDLEY_NON_NULL(2) reference operator[](T* key) @@ -21389,36 +19294,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this)); } - /*! - @brief read-only access specified object element - - Returns a const reference to the element at with specified key @a key. No - bounds checking is performed. - - @warning If the element with key @a key does not exist, the behavior is - undefined. - - @param[in] key key of the element to access - - @return const reference to the element at key @a key - - @pre The element with key @a key must exist. **This precondition is - enforced with an assertion.** - - @throw type_error.305 if the JSON value is not an object; in that case, - using the [] operator with a key makes no sense. - - @complexity Logarithmic in the size of the container. - - @liveexample{The example below shows how object elements can be read using - the `[]` operator.,operatorarray__key_type_const} - - @sa see @ref at(const typename object_t::key_type&) for access by reference - with range checking - @sa see @ref value() for access by value with a default value - - @since version 1.1.0 - */ + /// @brief access specified object element + /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ template JSON_HEDLEY_NON_NULL(2) const_reference operator[](T* key) const @@ -21433,57 +19310,9 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(305, "cannot use operator[] with a string argument with " + std::string(type_name()), *this)); } - /*! - @brief access specified object element with default value - - Returns either a copy of an object's element at the specified key @a key - or a given default value if no element with key @a key exists. - - The function is basically equivalent to executing - @code {.cpp} - try { - return at(key); - } catch(out_of_range) { - return default_value; - } - @endcode - - @note Unlike @ref at(const typename object_t::key_type&), this function - does not throw if the given key @a key was not found. - - @note Unlike @ref operator[](const typename object_t::key_type& key), this - function does not implicitly add an element to the position defined by @a - key. This function is furthermore also applicable to const objects. - - @param[in] key key of the element to access - @param[in] default_value the value to return if @a key is not found - - @tparam ValueType type compatible to JSON values, for instance `int` for - JSON integer numbers, `bool` for JSON booleans, or `std::vector` types for - JSON arrays. Note the type of the expected value at @a key and the default - value @a default_value must be compatible. - - @return copy of the element at key @a key or @a default_value if @a key - is not found - - @throw type_error.302 if @a default_value does not match the type of the - value at @a key - @throw type_error.306 if the JSON value is not an object; in that case, - using `value()` with a key makes no sense. - - @complexity Logarithmic in the size of the container. - - @liveexample{The example below shows how object elements can be queried - with a default value.,basic_json__value} - - @sa see @ref at(const typename object_t::key_type&) for access by reference - with range checking - @sa see @ref operator[](const typename object_t::key_type&) for unchecked - access by reference - - @since version 1.0.0 - */ - // using std::is_convertible in a std::enable_if will fail when using explicit conversions + /// @brief access specified object element with default value + /// @sa https://json.nlohmann.me/api/basic_json/value/ + /// using std::is_convertible in a std::enable_if will fail when using explicit conversions template < class ValueType, typename std::enable_if < detail::is_getable::value && !std::is_same::value, int >::type = 0 > @@ -21505,58 +19334,16 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), *this)); } - /*! - @brief overload for a default value of type const char* - @copydoc basic_json::value(const typename object_t::key_type&, const ValueType&) const - */ + /// @brief access specified object element with default value + /// @sa https://json.nlohmann.me/api/basic_json/value/ + /// overload for a default value of type const char* string_t value(const typename object_t::key_type& key, const char* default_value) const { return value(key, string_t(default_value)); } - /*! - @brief access specified object element via JSON Pointer with default value - - Returns either a copy of an object's element at the specified key @a key - or a given default value if no element with key @a key exists. - - The function is basically equivalent to executing - @code {.cpp} - try { - return at(ptr); - } catch(out_of_range) { - return default_value; - } - @endcode - - @note Unlike @ref at(const json_pointer&), this function does not throw - if the given key @a key was not found. - - @param[in] ptr a JSON pointer to the element to access - @param[in] default_value the value to return if @a ptr found no value - - @tparam ValueType type compatible to JSON values, for instance `int` for - JSON integer numbers, `bool` for JSON booleans, or `std::vector` types for - JSON arrays. Note the type of the expected value at @a key and the default - value @a default_value must be compatible. - - @return copy of the element at key @a key or @a default_value if @a key - is not found - - @throw type_error.302 if @a default_value does not match the type of the - value at @a ptr - @throw type_error.306 if the JSON value is not an object; in that case, - using `value()` with a key makes no sense. - - @complexity Logarithmic in the size of the container. - - @liveexample{The example below shows how object elements can be queried - with a default value.,basic_json__value_ptr} - - @sa see @ref operator[](const json_pointer&) for unchecked access by reference - - @since version 2.0.2 - */ + /// @brief access specified object element via JSON Pointer with default value + /// @sa https://json.nlohmann.me/api/basic_json/value/ template::value, int>::type = 0> ValueType value(const json_pointer& ptr, const ValueType& default_value) const @@ -21578,85 +19365,31 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(306, "cannot use value() with " + std::string(type_name()), *this)); } - /*! - @brief overload for a default value of type const char* - @copydoc basic_json::value(const json_pointer&, ValueType) const - */ + /// @brief access specified object element via JSON Pointer with default value + /// @sa https://json.nlohmann.me/api/basic_json/value/ + /// overload for a default value of type const char* JSON_HEDLEY_NON_NULL(3) string_t value(const json_pointer& ptr, const char* default_value) const { return value(ptr, string_t(default_value)); } - /*! - @brief access the first element - - Returns a reference to the first element in the container. For a JSON - container `c`, the expression `c.front()` is equivalent to `*c.begin()`. - - @return In case of a structured type (array or object), a reference to the - first element is returned. In case of number, string, boolean, or binary - values, a reference to the value is returned. - - @complexity Constant. - - @pre The JSON value must not be `null` (would throw `std::out_of_range`) - or an empty array or object (undefined behavior, **guarded by - assertions**). - @post The JSON value remains unchanged. - - @throw invalid_iterator.214 when called on `null` value - - @liveexample{The following code shows an example for `front()`.,front} - - @sa see @ref back() -- access the last element - - @since version 1.0.0 - */ + /// @brief access the first element + /// @sa https://json.nlohmann.me/api/basic_json/front/ reference front() { return *begin(); } - /*! - @copydoc basic_json::front() - */ + /// @brief access the first element + /// @sa https://json.nlohmann.me/api/basic_json/front/ const_reference front() const { return *cbegin(); } - /*! - @brief access the last element - - Returns a reference to the last element in the container. For a JSON - container `c`, the expression `c.back()` is equivalent to - @code {.cpp} - auto tmp = c.end(); - --tmp; - return *tmp; - @endcode - - @return In case of a structured type (array or object), a reference to the - last element is returned. In case of number, string, boolean, or binary - values, a reference to the value is returned. - - @complexity Constant. - - @pre The JSON value must not be `null` (would throw `std::out_of_range`) - or an empty array or object (undefined behavior, **guarded by - assertions**). - @post The JSON value remains unchanged. - - @throw invalid_iterator.214 when called on a `null` value. See example - below. - - @liveexample{The following code shows an example for `back()`.,back} - - @sa see @ref front() -- access the first element - - @since version 1.0.0 - */ + /// @brief access the last element + /// @sa https://json.nlohmann.me/api/basic_json/back/ reference back() { auto tmp = end(); @@ -21664,9 +19397,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return *tmp; } - /*! - @copydoc basic_json::back() - */ + /// @brief access the last element + /// @sa https://json.nlohmann.me/api/basic_json/back/ const_reference back() const { auto tmp = cend(); @@ -21674,52 +19406,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return *tmp; } - /*! - @brief remove element given an iterator - - Removes the element specified by iterator @a pos. The iterator @a pos must - be valid and dereferenceable. Thus the `end()` iterator (which is valid, - but is not dereferenceable) cannot be used as a value for @a pos. - - If called on a primitive type other than `null`, the resulting JSON value - will be `null`. - - @param[in] pos iterator to the element to remove - @return Iterator following the last removed element. If the iterator @a - pos refers to the last element, the `end()` iterator is returned. - - @tparam IteratorType an @ref iterator or @ref const_iterator - - @post Invalidates iterators and references at or after the point of the - erase, including the `end()` iterator. - - @throw type_error.307 if called on a `null` value; example: `"cannot use - erase() with null"` - @throw invalid_iterator.202 if called on an iterator which does not belong - to the current JSON value; example: `"iterator does not fit current - value"` - @throw invalid_iterator.205 if called on a primitive type with invalid - iterator (i.e., any iterator which is not `begin()`); example: `"iterator - out of range"` - - @complexity The complexity depends on the type: - - objects: amortized constant - - arrays: linear in distance between @a pos and the end of the container - - strings and binary: linear in the length of the member - - other types: constant - - @liveexample{The example shows the result of `erase()` for different JSON - types.,erase__IteratorType} - - @sa see @ref erase(IteratorType, IteratorType) -- removes the elements in - the given range - @sa see @ref erase(const typename object_t::key_type&) -- removes the element - from an object at the given key - @sa see @ref erase(const size_type) -- removes the element from an array at - the given index - - @since version 1.0.0 - */ + /// @brief remove element given an iterator + /// @sa https://json.nlohmann.me/api/basic_json/erase/ template < class IteratorType, typename std::enable_if < std::is_same::value || std::is_same::value, int >::type @@ -21789,52 +19477,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } - /*! - @brief remove elements given an iterator range - - Removes the element specified by the range `[first; last)`. The iterator - @a first does not need to be dereferenceable if `first == last`: erasing - an empty range is a no-op. - - If called on a primitive type other than `null`, the resulting JSON value - will be `null`. - - @param[in] first iterator to the beginning of the range to remove - @param[in] last iterator past the end of the range to remove - @return Iterator following the last removed element. If the iterator @a - second refers to the last element, the `end()` iterator is returned. - - @tparam IteratorType an @ref iterator or @ref const_iterator - - @post Invalidates iterators and references at or after the point of the - erase, including the `end()` iterator. - - @throw type_error.307 if called on a `null` value; example: `"cannot use - erase() with null"` - @throw invalid_iterator.203 if called on iterators which does not belong - to the current JSON value; example: `"iterators do not fit current value"` - @throw invalid_iterator.204 if called on a primitive type with invalid - iterators (i.e., if `first != begin()` and `last != end()`); example: - `"iterators out of range"` - - @complexity The complexity depends on the type: - - objects: `log(size()) + std::distance(first, last)` - - arrays: linear in the distance between @a first and @a last, plus linear - in the distance between @a last and end of the container - - strings and binary: linear in the length of the member - - other types: constant - - @liveexample{The example shows the result of `erase()` for different JSON - types.,erase__IteratorType_IteratorType} - - @sa see @ref erase(IteratorType) -- removes the element at a given position - @sa see @ref erase(const typename object_t::key_type&) -- removes the element - from an object at the given key - @sa see @ref erase(const size_type) -- removes the element from an array at - the given index - - @since version 1.0.0 - */ + /// @brief remove elements given an iterator range + /// @sa https://json.nlohmann.me/api/basic_json/erase/ template < class IteratorType, typename std::enable_if < std::is_same::value || std::is_same::value, int >::type @@ -21907,35 +19551,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } - /*! - @brief remove element from a JSON object given a key - - Removes elements from a JSON object with the key value @a key. - - @param[in] key value of the elements to remove - - @return Number of elements removed. If @a ObjectType is the default - `std::map` type, the return value will always be `0` (@a key was not - found) or `1` (@a key was found). - - @post References and iterators to the erased elements are invalidated. - Other references and iterators are not affected. - - @throw type_error.307 when called on a type other than JSON object; - example: `"cannot use erase() with null"` - - @complexity `log(size()) + count(key)` - - @liveexample{The example shows the effect of `erase()`.,erase__key_type} - - @sa see @ref erase(IteratorType) -- removes the element at a given position - @sa see @ref erase(IteratorType, IteratorType) -- removes the elements in - the given range - @sa see @ref erase(const size_type) -- removes the element from an array at - the given index - - @since version 1.0.0 - */ + /// @brief remove element from a JSON object given a key + /// @sa https://json.nlohmann.me/api/basic_json/erase/ size_type erase(const typename object_t::key_type& key) { // this erase only works for objects @@ -21947,30 +19564,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(307, "cannot use erase() with " + std::string(type_name()), *this)); } - /*! - @brief remove element from a JSON array given an index - - Removes element from a JSON array at the index @a idx. - - @param[in] idx index of the element to remove - - @throw type_error.307 when called on a type other than JSON object; - example: `"cannot use erase() with null"` - @throw out_of_range.401 when `idx >= size()`; example: `"array index 17 - is out of range"` - - @complexity Linear in distance between @a idx and the end of the container. - - @liveexample{The example shows the effect of `erase()`.,erase__size_type} - - @sa see @ref erase(IteratorType) -- removes the element at a given position - @sa see @ref erase(IteratorType, IteratorType) -- removes the elements in - the given range - @sa see @ref erase(const typename object_t::key_type&) -- removes the element - from an object at the given key - - @since version 1.0.0 - */ + /// @brief remove element from a JSON array given an index + /// @sa https://json.nlohmann.me/api/basic_json/erase/ void erase(const size_type idx) { // this erase only works for arrays @@ -21999,30 +19594,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @name lookup /// @{ - /*! - @brief find an element in a JSON object - - Finds an element in a JSON object with key equivalent to @a key. If the - element is not found or the JSON value is not an object, end() is - returned. - - @note This method always returns @ref end() when executed on a JSON type - that is not an object. - - @param[in] key key value of the element to search for. - - @return Iterator to an element with key equivalent to @a key. If no such - element is found or the JSON value is not an object, past-the-end (see - @ref end()) iterator is returned. - - @complexity Logarithmic in the size of the JSON object. - - @liveexample{The example shows how `find()` is used.,find__key_type} - - @sa see @ref contains(KeyT&&) const -- checks whether a key exists - - @since version 1.0.0 - */ + /// @brief find an element in a JSON object + /// @sa https://json.nlohmann.me/api/basic_json/find/ template iterator find(KeyT&& key) { @@ -22036,10 +19609,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } - /*! - @brief find an element in a JSON object - @copydoc find(KeyT&&) - */ + /// @brief find an element in a JSON object + /// @sa https://json.nlohmann.me/api/basic_json/find/ template const_iterator find(KeyT&& key) const { @@ -22053,27 +19624,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } - /*! - @brief returns the number of occurrences of a key in a JSON object - - Returns the number of elements with key @a key. If ObjectType is the - default `std::map` type, the return value will always be `0` (@a key was - not found) or `1` (@a key was found). - - @note This method always returns `0` when executed on a JSON type that is - not an object. - - @param[in] key key value of the element to count - - @return Number of elements with key @a key. If the JSON value is not an - object, the return value will be `0`. - - @complexity Logarithmic in the size of the JSON object. - - @liveexample{The example shows how `count()` is used.,count} - - @since version 1.0.0 - */ + /// @brief returns the number of occurrences of a key in a JSON object + /// @sa https://json.nlohmann.me/api/basic_json/count/ template size_type count(KeyT&& key) const { @@ -22081,31 +19633,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return is_object() ? m_value.object->count(std::forward(key)) : 0; } - /*! - @brief check the existence of an element in a JSON object - - Check whether an element exists in a JSON object with key equivalent to - @a key. If the element is not found or the JSON value is not an object, - false is returned. - - @note This method always returns false when executed on a JSON type - that is not an object. - - @param[in] key key value to check its existence. - - @return true if an element with specified @a key exists. If no such - element with such key is found or the JSON value is not an object, - false is returned. - - @complexity Logarithmic in the size of the JSON object. - - @liveexample{The following code shows an example for `contains()`.,contains} - - @sa see @ref find(KeyT&&) -- returns an iterator to an object element - @sa see @ref contains(const json_pointer&) const -- checks the existence for a JSON pointer - - @since version 3.6.0 - */ + /// @brief check the existence of an element in a JSON object + /// @sa https://json.nlohmann.me/api/basic_json/contains/ template < typename KeyT, typename std::enable_if < !std::is_same::type, json_pointer>::value, int >::type = 0 > bool contains(KeyT && key) const @@ -22113,32 +19642,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return is_object() && m_value.object->find(std::forward(key)) != m_value.object->end(); } - /*! - @brief check the existence of an element in a JSON object given a JSON pointer - - Check whether the given JSON pointer @a ptr can be resolved in the current - JSON value. - - @note This method can be executed on any JSON value type. - - @param[in] ptr JSON pointer to check its existence. - - @return true if the JSON pointer can be resolved to a stored value, false - otherwise. - - @post If `j.contains(ptr)` returns true, it is safe to call `j[ptr]`. - - @throw parse_error.106 if an array index begins with '0' - @throw parse_error.109 if an array index was not a number - - @complexity Logarithmic in the size of the JSON object. - - @liveexample{The following code shows an example for `contains()`.,contains_json_pointer} - - @sa see @ref contains(KeyT &&) const -- checks the existence of a key - - @since version 3.7.0 - */ + /// @brief check the existence of an element in a JSON object given a JSON pointer + /// @sa https://json.nlohmann.me/api/basic_json/contains/ bool contains(const json_pointer& ptr) const { return ptr.contains(this); @@ -22154,30 +19659,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @name iterators /// @{ - /*! - @brief returns an iterator to the first element - - Returns an iterator to the first element. - - @image html range-begin-end.svg "Illustration from cppreference.com" - - @return iterator to the first element - - @complexity Constant. - - @requirement This function helps `basic_json` satisfying the - [Container](https://en.cppreference.com/w/cpp/named_req/Container) - requirements: - - The complexity is constant. - - @liveexample{The following code shows an example for `begin()`.,begin} - - @sa see @ref cbegin() -- returns a const iterator to the beginning - @sa see @ref end() -- returns an iterator to the end - @sa see @ref cend() -- returns a const iterator to the end - - @since version 1.0.0 - */ + /// @brief returns an iterator to the first element + /// @sa https://json.nlohmann.me/api/basic_json/begin/ iterator begin() noexcept { iterator result(this); @@ -22185,39 +19668,15 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } - /*! - @copydoc basic_json::cbegin() - */ + /// @brief returns an iterator to the first element + /// @sa https://json.nlohmann.me/api/basic_json/begin/ const_iterator begin() const noexcept { return cbegin(); } - /*! - @brief returns a const iterator to the first element - - Returns a const iterator to the first element. - - @image html range-begin-end.svg "Illustration from cppreference.com" - - @return const iterator to the first element - - @complexity Constant. - - @requirement This function helps `basic_json` satisfying the - [Container](https://en.cppreference.com/w/cpp/named_req/Container) - requirements: - - The complexity is constant. - - Has the semantics of `const_cast(*this).begin()`. - - @liveexample{The following code shows an example for `cbegin()`.,cbegin} - - @sa see @ref begin() -- returns an iterator to the beginning - @sa see @ref end() -- returns an iterator to the end - @sa see @ref cend() -- returns a const iterator to the end - - @since version 1.0.0 - */ + /// @brief returns a const iterator to the first element + /// @sa https://json.nlohmann.me/api/basic_json/cbegin/ const_iterator cbegin() const noexcept { const_iterator result(this); @@ -22225,30 +19684,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } - /*! - @brief returns an iterator to one past the last element - - Returns an iterator to one past the last element. - - @image html range-begin-end.svg "Illustration from cppreference.com" - - @return iterator one past the last element - - @complexity Constant. - - @requirement This function helps `basic_json` satisfying the - [Container](https://en.cppreference.com/w/cpp/named_req/Container) - requirements: - - The complexity is constant. - - @liveexample{The following code shows an example for `end()`.,end} - - @sa see @ref cend() -- returns a const iterator to the end - @sa see @ref begin() -- returns an iterator to the beginning - @sa see @ref cbegin() -- returns a const iterator to the beginning - - @since version 1.0.0 - */ + /// @brief returns an iterator to one past the last element + /// @sa https://json.nlohmann.me/api/basic_json/end/ iterator end() noexcept { iterator result(this); @@ -22256,326 +19693,96 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } - /*! - @copydoc basic_json::cend() - */ + /// @brief returns an iterator to one past the last element + /// @sa https://json.nlohmann.me/api/basic_json/end/ const_iterator end() const noexcept { return cend(); } - /*! - @brief returns a const iterator to one past the last element - - Returns a const iterator to one past the last element. - - @image html range-begin-end.svg "Illustration from cppreference.com" - - @return const iterator one past the last element - - @complexity Constant. - - @requirement This function helps `basic_json` satisfying the - [Container](https://en.cppreference.com/w/cpp/named_req/Container) - requirements: - - The complexity is constant. - - Has the semantics of `const_cast(*this).end()`. - - @liveexample{The following code shows an example for `cend()`.,cend} - - @sa see @ref end() -- returns an iterator to the end - @sa see @ref begin() -- returns an iterator to the beginning - @sa see @ref cbegin() -- returns a const iterator to the beginning - - @since version 1.0.0 - */ + /// @brief returns an iterator to one past the last element + /// @sa https://json.nlohmann.me/api/basic_json/cend/ const_iterator cend() const noexcept { const_iterator result(this); result.set_end(); - return result; - } - - /*! - @brief returns an iterator to the reverse-beginning - - Returns an iterator to the reverse-beginning; that is, the last element. - - @image html range-rbegin-rend.svg "Illustration from cppreference.com" - - @complexity Constant. - - @requirement This function helps `basic_json` satisfying the - [ReversibleContainer](https://en.cppreference.com/w/cpp/named_req/ReversibleContainer) - requirements: - - The complexity is constant. - - Has the semantics of `reverse_iterator(end())`. - - @liveexample{The following code shows an example for `rbegin()`.,rbegin} - - @sa see @ref crbegin() -- returns a const reverse iterator to the beginning - @sa see @ref rend() -- returns a reverse iterator to the end - @sa see @ref crend() -- returns a const reverse iterator to the end - - @since version 1.0.0 - */ - reverse_iterator rbegin() noexcept - { - return reverse_iterator(end()); - } - - /*! - @copydoc basic_json::crbegin() - */ - const_reverse_iterator rbegin() const noexcept - { - return crbegin(); - } - - /*! - @brief returns an iterator to the reverse-end - - Returns an iterator to the reverse-end; that is, one before the first - element. - - @image html range-rbegin-rend.svg "Illustration from cppreference.com" - - @complexity Constant. - - @requirement This function helps `basic_json` satisfying the - [ReversibleContainer](https://en.cppreference.com/w/cpp/named_req/ReversibleContainer) - requirements: - - The complexity is constant. - - Has the semantics of `reverse_iterator(begin())`. - - @liveexample{The following code shows an example for `rend()`.,rend} - - @sa see @ref crend() -- returns a const reverse iterator to the end - @sa see @ref rbegin() -- returns a reverse iterator to the beginning - @sa see @ref crbegin() -- returns a const reverse iterator to the beginning - - @since version 1.0.0 - */ - reverse_iterator rend() noexcept - { - return reverse_iterator(begin()); - } - - /*! - @copydoc basic_json::crend() - */ - const_reverse_iterator rend() const noexcept - { - return crend(); - } - - /*! - @brief returns a const reverse iterator to the last element - - Returns a const iterator to the reverse-beginning; that is, the last - element. - - @image html range-rbegin-rend.svg "Illustration from cppreference.com" - - @complexity Constant. - - @requirement This function helps `basic_json` satisfying the - [ReversibleContainer](https://en.cppreference.com/w/cpp/named_req/ReversibleContainer) - requirements: - - The complexity is constant. - - Has the semantics of `const_cast(*this).rbegin()`. - - @liveexample{The following code shows an example for `crbegin()`.,crbegin} - - @sa see @ref rbegin() -- returns a reverse iterator to the beginning - @sa see @ref rend() -- returns a reverse iterator to the end - @sa see @ref crend() -- returns a const reverse iterator to the end - - @since version 1.0.0 - */ - const_reverse_iterator crbegin() const noexcept - { - return const_reverse_iterator(cend()); - } - - /*! - @brief returns a const reverse iterator to one before the first - - Returns a const reverse iterator to the reverse-end; that is, one before - the first element. - - @image html range-rbegin-rend.svg "Illustration from cppreference.com" - - @complexity Constant. - - @requirement This function helps `basic_json` satisfying the - [ReversibleContainer](https://en.cppreference.com/w/cpp/named_req/ReversibleContainer) - requirements: - - The complexity is constant. - - Has the semantics of `const_cast(*this).rend()`. - - @liveexample{The following code shows an example for `crend()`.,crend} - - @sa see @ref rend() -- returns a reverse iterator to the end - @sa see @ref rbegin() -- returns a reverse iterator to the beginning - @sa see @ref crbegin() -- returns a const reverse iterator to the beginning - - @since version 1.0.0 - */ - const_reverse_iterator crend() const noexcept - { - return const_reverse_iterator(cbegin()); - } - - public: - /*! - @brief wrapper to access iterator member functions in range-based for - - This function allows to access @ref iterator::key() and @ref - iterator::value() during range-based for loops. In these loops, a - reference to the JSON values is returned, so there is no access to the - underlying iterator. - - For loop without iterator_wrapper: - - @code{cpp} - for (auto it = j_object.begin(); it != j_object.end(); ++it) - { - std::cout << "key: " << it.key() << ", value:" << it.value() << '\n'; - } - @endcode - - Range-based for loop without iterator proxy: - - @code{cpp} - for (auto it : j_object) - { - // "it" is of type json::reference and has no key() member - std::cout << "value: " << it << '\n'; - } - @endcode - - Range-based for loop with iterator proxy: - - @code{cpp} - for (auto it : json::iterator_wrapper(j_object)) - { - std::cout << "key: " << it.key() << ", value:" << it.value() << '\n'; - } - @endcode - - @note When iterating over an array, `key()` will return the index of the - element as string (see example). - - @param[in] ref reference to a JSON value - @return iteration proxy object wrapping @a ref with an interface to use in - range-based for loops - - @liveexample{The following code shows how the wrapper is used,iterator_wrapper} - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes in the JSON value. - - @complexity Constant. - - @note The name of this function is not yet final and may change in the - future. - - @deprecated This stream operator is deprecated and will be removed in - future 4.0.0 of the library. Please use @ref items() instead; - that is, replace `json::iterator_wrapper(j)` with `j.items()`. - */ - JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items()) - static iteration_proxy iterator_wrapper(reference ref) noexcept - { - return ref.items(); + return result; } - /*! - @copydoc iterator_wrapper(reference) - */ - JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items()) - static iteration_proxy iterator_wrapper(const_reference ref) noexcept + /// @brief returns an iterator to the reverse-beginning + /// @sa https://json.nlohmann.me/api/basic_json/rbegin/ + reverse_iterator rbegin() noexcept { - return ref.items(); + return reverse_iterator(end()); } - /*! - @brief helper to access iterator member functions in range-based for - - This function allows to access @ref iterator::key() and @ref - iterator::value() during range-based for loops. In these loops, a - reference to the JSON values is returned, so there is no access to the - underlying iterator. - - For loop without `items()` function: - - @code{cpp} - for (auto it = j_object.begin(); it != j_object.end(); ++it) + /// @brief returns an iterator to the reverse-beginning + /// @sa https://json.nlohmann.me/api/basic_json/rbegin/ + const_reverse_iterator rbegin() const noexcept { - std::cout << "key: " << it.key() << ", value:" << it.value() << '\n'; + return crbegin(); } - @endcode - - Range-based for loop without `items()` function: - @code{cpp} - for (auto it : j_object) + /// @brief returns an iterator to the reverse-end + /// @sa https://json.nlohmann.me/api/basic_json/rend/ + reverse_iterator rend() noexcept { - // "it" is of type json::reference and has no key() member - std::cout << "value: " << it << '\n'; + return reverse_iterator(begin()); } - @endcode - - Range-based for loop with `items()` function: - @code{cpp} - for (auto& el : j_object.items()) + /// @brief returns an iterator to the reverse-end + /// @sa https://json.nlohmann.me/api/basic_json/rend/ + const_reverse_iterator rend() const noexcept { - std::cout << "key: " << el.key() << ", value:" << el.value() << '\n'; + return crend(); } - @endcode - - The `items()` function also allows to use - [structured bindings](https://en.cppreference.com/w/cpp/language/structured_binding) - (C++17): - @code{cpp} - for (auto& [key, val] : j_object.items()) + /// @brief returns a const reverse iterator to the last element + /// @sa https://json.nlohmann.me/api/basic_json/crbegin/ + const_reverse_iterator crbegin() const noexcept { - std::cout << "key: " << key << ", value:" << val << '\n'; + return const_reverse_iterator(cend()); } - @endcode - - @note When iterating over an array, `key()` will return the index of the - element as string (see example). For primitive types (e.g., numbers), - `key()` returns an empty string. - @warning Using `items()` on temporary objects is dangerous. Make sure the - object's lifetime exeeds the iteration. See - for more - information. - - @return iteration proxy object wrapping @a ref with an interface to use in - range-based for loops - - @liveexample{The following code shows how the function is used.,items} + /// @brief returns a const reverse iterator to one before the first + /// @sa https://json.nlohmann.me/api/basic_json/crend/ + const_reverse_iterator crend() const noexcept + { + return const_reverse_iterator(cbegin()); + } - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes in the JSON value. + public: + /// @brief wrapper to access iterator member functions in range-based for + /// @sa https://json.nlohmann.me/api/basic_json/items/ + /// @deprecated This function is deprecated since 3.1.0 and will be removed in + /// version 4.0.0 of the library. Please use @ref items() instead; + /// that is, replace `json::iterator_wrapper(j)` with `j.items()`. + JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items()) + static iteration_proxy iterator_wrapper(reference ref) noexcept + { + return ref.items(); + } - @complexity Constant. + /// @brief wrapper to access iterator member functions in range-based for + /// @sa https://json.nlohmann.me/api/basic_json/items/ + /// @deprecated This function is deprecated since 3.1.0 and will be removed in + /// version 4.0.0 of the library. Please use @ref items() instead; + /// that is, replace `json::iterator_wrapper(j)` with `j.items()`. + JSON_HEDLEY_DEPRECATED_FOR(3.1.0, items()) + static iteration_proxy iterator_wrapper(const_reference ref) noexcept + { + return ref.items(); + } - @since version 3.1.0, structured bindings support since 3.5.0. - */ + /// @brief helper to access iterator member functions in range-based for + /// @sa https://json.nlohmann.me/api/basic_json/items/ iteration_proxy items() noexcept { return iteration_proxy(*this); } - /*! - @copydoc items() - */ + /// @brief helper to access iterator member functions in range-based for + /// @sa https://json.nlohmann.me/api/basic_json/items/ iteration_proxy items() const noexcept { return iteration_proxy(*this); @@ -22591,48 +19798,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @name capacity /// @{ - /*! - @brief checks whether the container is empty. - - Checks if a JSON value has no elements (i.e. whether its @ref size is `0`). - - @return The return value depends on the different types and is - defined as follows: - Value type | return value - ----------- | ------------- - null | `true` - boolean | `false` - string | `false` - number | `false` - binary | `false` - object | result of function `object_t::empty()` - array | result of function `array_t::empty()` - - @liveexample{The following code uses `empty()` to check if a JSON - object contains any elements.,empty} - - @complexity Constant, as long as @ref array_t and @ref object_t satisfy - the Container concept; that is, their `empty()` functions have constant - complexity. - - @iterators No changes. - - @exceptionsafety No-throw guarantee: this function never throws exceptions. - - @note This function does not return whether a string stored as JSON value - is empty - it returns whether the JSON container itself is empty which is - false in the case of a string. - - @requirement This function helps `basic_json` satisfying the - [Container](https://en.cppreference.com/w/cpp/named_req/Container) - requirements: - - The complexity is constant. - - Has the semantics of `begin() == end()`. - - @sa see @ref size() -- returns the number of elements - - @since version 1.0.0 - */ + /// @brief checks whether the container is empty. + /// @sa https://json.nlohmann.me/api/basic_json/empty/ bool empty() const noexcept { switch (m_type) @@ -22670,49 +19837,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } } - /*! - @brief returns the number of elements - - Returns the number of elements in a JSON value. - - @return The return value depends on the different types and is - defined as follows: - Value type | return value - ----------- | ------------- - null | `0` - boolean | `1` - string | `1` - number | `1` - binary | `1` - object | result of function object_t::size() - array | result of function array_t::size() - - @liveexample{The following code calls `size()` on the different value - types.,size} - - @complexity Constant, as long as @ref array_t and @ref object_t satisfy - the Container concept; that is, their size() functions have constant - complexity. - - @iterators No changes. - - @exceptionsafety No-throw guarantee: this function never throws exceptions. - - @note This function does not return the length of a string stored as JSON - value - it returns the number of elements in the JSON value which is 1 in - the case of a string. - - @requirement This function helps `basic_json` satisfying the - [Container](https://en.cppreference.com/w/cpp/named_req/Container) - requirements: - - The complexity is constant. - - Has the semantics of `std::distance(begin(), end())`. - - @sa see @ref empty() -- checks whether the container is empty - @sa see @ref max_size() -- returns the maximal number of elements - - @since version 1.0.0 - */ + /// @brief returns the number of elements + /// @sa https://json.nlohmann.me/api/basic_json/size/ size_type size() const noexcept { switch (m_type) @@ -22750,47 +19876,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } } - /*! - @brief returns the maximum possible number of elements - - Returns the maximum number of elements a JSON value is able to hold due to - system or library implementation limitations, i.e. `std::distance(begin(), - end())` for the JSON value. - - @return The return value depends on the different types and is - defined as follows: - Value type | return value - ----------- | ------------- - null | `0` (same as `size()`) - boolean | `1` (same as `size()`) - string | `1` (same as `size()`) - number | `1` (same as `size()`) - binary | `1` (same as `size()`) - object | result of function `object_t::max_size()` - array | result of function `array_t::max_size()` - - @liveexample{The following code calls `max_size()` on the different value - types. Note the output is implementation specific.,max_size} - - @complexity Constant, as long as @ref array_t and @ref object_t satisfy - the Container concept; that is, their `max_size()` functions have constant - complexity. - - @iterators No changes. - - @exceptionsafety No-throw guarantee: this function never throws exceptions. - - @requirement This function helps `basic_json` satisfying the - [Container](https://en.cppreference.com/w/cpp/named_req/Container) - requirements: - - The complexity is constant. - - Has the semantics of returning `b.size()` where `b` is the largest - possible JSON value. - - @sa see @ref size() -- returns the number of elements - - @since version 1.0.0 - */ + /// @brief returns the maximum possible number of elements + /// @sa https://json.nlohmann.me/api/basic_json/max_size/ size_type max_size() const noexcept { switch (m_type) @@ -22833,43 +19920,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @name modifiers /// @{ - /*! - @brief clears the contents - - Clears the content of a JSON value and resets it to the default value as - if @ref basic_json(value_t) would have been called with the current value - type from @ref type(): - - Value type | initial value - ----------- | ------------- - null | `null` - boolean | `false` - string | `""` - number | `0` - binary | An empty byte vector - object | `{}` - array | `[]` - - @post Has the same effect as calling - @code {.cpp} - *this = basic_json(type()); - @endcode - - @liveexample{The example below shows the effect of `clear()` to different - JSON types.,clear} - - @complexity Linear in the size of the JSON value. - - @iterators All iterators, pointers and references related to this container - are invalidated. - - @exceptionsafety No-throw guarantee: this function never throws exceptions. - - @sa see @ref basic_json(value_t) -- constructor that creates an object with the - same value than calling `clear()` - - @since version 1.0.0 - */ + /// @brief clears the contents + /// @sa https://json.nlohmann.me/api/basic_json/clear/ void clear() noexcept { switch (m_type) @@ -22929,26 +19981,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } } - /*! - @brief add an object to an array - - Appends the given element @a val to the end of the JSON value. If the - function is called on a JSON null value, an empty array is created before - appending @a val. - - @param[in] val the value to add to the JSON array - - @throw type_error.308 when called on a type other than JSON array or - null; example: `"cannot use push_back() with number"` - - @complexity Amortized constant. - - @liveexample{The example shows how `push_back()` and `+=` can be used to - add elements to a JSON array. Note how the `null` value was silently - converted to a JSON array.,push_back} - - @since version 1.0.0 - */ + /// @brief add an object to an array + /// @sa https://json.nlohmann.me/api/basic_json/push_back/ void push_back(basic_json&& val) { // push_back only works for null objects or arrays @@ -22969,23 +20003,19 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec const auto old_capacity = m_value.array->capacity(); m_value.array->push_back(std::move(val)); set_parent(m_value.array->back(), old_capacity); - // if val is moved from, basic_json move constructor marks it null so we do not call the destructor + // if val is moved from, basic_json move constructor marks it null, so we do not call the destructor } - /*! - @brief add an object to an array - @copydoc push_back(basic_json&&) - */ + /// @brief add an object to an array + /// @sa https://json.nlohmann.me/api/basic_json/operator+=/ reference operator+=(basic_json&& val) { push_back(std::move(val)); return *this; } - /*! - @brief add an object to an array - @copydoc push_back(basic_json&&) - */ + /// @brief add an object to an array + /// @sa https://json.nlohmann.me/api/basic_json/push_back/ void push_back(const basic_json& val) { // push_back only works for null objects or arrays @@ -23008,36 +20038,16 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec set_parent(m_value.array->back(), old_capacity); } - /*! - @brief add an object to an array - @copydoc push_back(basic_json&&) - */ + /// @brief add an object to an array + /// @sa https://json.nlohmann.me/api/basic_json/operator+=/ reference operator+=(const basic_json& val) { push_back(val); return *this; } - /*! - @brief add an object to an object - - Inserts the given element @a val to the JSON object. If the function is - called on a JSON null value, an empty object is created before inserting - @a val. - - @param[in] val the value to add to the JSON object - - @throw type_error.308 when called on a type other than JSON object or - null; example: `"cannot use push_back() with number"` - - @complexity Logarithmic in the size of the container, O(log(`size()`)). - - @liveexample{The example shows how `push_back()` and `+=` can be used to - add elements to a JSON object. Note how the `null` value was silently - converted to a JSON object.,push_back__object_t__value} - - @since version 1.0.0 - */ + /// @brief add an object to an object + /// @sa https://json.nlohmann.me/api/basic_json/push_back/ void push_back(const typename object_t::value_type& val) { // push_back only works for null objects or objects @@ -23059,41 +20069,16 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec set_parent(res.first->second); } - /*! - @brief add an object to an object - @copydoc push_back(const typename object_t::value_type&) - */ + /// @brief add an object to an object + /// @sa https://json.nlohmann.me/api/basic_json/operator+=/ reference operator+=(const typename object_t::value_type& val) { push_back(val); return *this; } - /*! - @brief add an object to an object - - This function allows to use `push_back` with an initializer list. In case - - 1. the current value is an object, - 2. the initializer list @a init contains only two elements, and - 3. the first element of @a init is a string, - - @a init is converted into an object element and added using - @ref push_back(const typename object_t::value_type&). Otherwise, @a init - is converted to a JSON value and added using @ref push_back(basic_json&&). - - @param[in] init an initializer list - - @complexity Linear in the size of the initializer list @a init. - - @note This function is required to resolve an ambiguous overload error, - because pairs like `{"key", "value"}` can be both interpreted as - `object_t::value_type` or `std::initializer_list`, see - https://github.com/nlohmann/json/issues/235 for more information. - - @liveexample{The example shows how initializer lists are treated as - objects when possible.,push_back__initializer_list} - */ + /// @brief add an object to an object + /// @sa https://json.nlohmann.me/api/basic_json/push_back/ void push_back(initializer_list_t init) { if (is_object() && init.size() == 2 && (*init.begin())->is_string()) @@ -23108,39 +20093,16 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } } - /*! - @brief add an object to an object - @copydoc push_back(initializer_list_t) - */ + /// @brief add an object to an object + /// @sa https://json.nlohmann.me/api/basic_json/operator+=/ reference operator+=(initializer_list_t init) { push_back(init); return *this; } - /*! - @brief add an object to an array - - Creates a JSON value from the passed parameters @a args to the end of the - JSON value. If the function is called on a JSON null value, an empty array - is created before appending the value created from @a args. - - @param[in] args arguments to forward to a constructor of @ref basic_json - @tparam Args compatible types to create a @ref basic_json object - - @return reference to the inserted element - - @throw type_error.311 when called on a type other than JSON array or - null; example: `"cannot use emplace_back() with number"` - - @complexity Amortized constant. - - @liveexample{The example shows how `push_back()` can be used to add - elements to a JSON array. Note how the `null` value was silently converted - to a JSON array.,emplace_back} - - @since version 2.0.8, returns reference since 3.7.0 - */ + /// @brief add an object to an array + /// @sa https://json.nlohmann.me/api/basic_json/emplace_back/ template reference emplace_back(Args&& ... args) { @@ -23164,33 +20126,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return set_parent(m_value.array->back(), old_capacity); } - /*! - @brief add an object to an object if key does not exist - - Inserts a new element into a JSON object constructed in-place with the - given @a args if there is no element with the key in the container. If the - function is called on a JSON null value, an empty object is created before - appending the value created from @a args. - - @param[in] args arguments to forward to a constructor of @ref basic_json - @tparam Args compatible types to create a @ref basic_json object - - @return a pair consisting of an iterator to the inserted element, or the - already-existing element if no insertion happened, and a bool - denoting whether the insertion took place. - - @throw type_error.311 when called on a type other than JSON object or - null; example: `"cannot use emplace() with number"` - - @complexity Logarithmic in the size of the container, O(log(`size()`)). - - @liveexample{The example shows how `emplace()` can be used to add elements - to a JSON object. Note how the `null` value was silently converted to a - JSON object. Further note how no value is added if there was already one - value stored with the same key.,emplace} - - @since version 2.0.8 - */ + /// @brief add an object to an object if key does not exist + /// @sa https://json.nlohmann.me/api/basic_json/emplace/ template std::pair emplace(Args&& ... args) { @@ -23241,28 +20178,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } - /*! - @brief inserts element - - Inserts element @a val before iterator @a pos. - - @param[in] pos iterator before which the content will be inserted; may be - the end() iterator - @param[in] val element to insert - @return iterator pointing to the inserted @a val. - - @throw type_error.309 if called on JSON values other than arrays; - example: `"cannot use insert() with string"` - @throw invalid_iterator.202 if @a pos is not an iterator of *this; - example: `"iterator does not fit current value"` - - @complexity Constant plus linear in the distance between @a pos and end of - the container. - - @liveexample{The example shows how `insert()` is used.,insert} - - @since version 1.0.0 - */ + /// @brief inserts element into array + /// @sa https://json.nlohmann.me/api/basic_json/insert/ iterator insert(const_iterator pos, const basic_json& val) { // insert only works for arrays @@ -23281,39 +20198,15 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this)); } - /*! - @brief inserts element - @copydoc insert(const_iterator, const basic_json&) - */ + /// @brief inserts element into array + /// @sa https://json.nlohmann.me/api/basic_json/insert/ iterator insert(const_iterator pos, basic_json&& val) { return insert(pos, val); } - /*! - @brief inserts elements - - Inserts @a cnt copies of @a val before iterator @a pos. - - @param[in] pos iterator before which the content will be inserted; may be - the end() iterator - @param[in] cnt number of copies of @a val to insert - @param[in] val element to insert - @return iterator pointing to the first element inserted, or @a pos if - `cnt==0` - - @throw type_error.309 if called on JSON values other than arrays; example: - `"cannot use insert() with string"` - @throw invalid_iterator.202 if @a pos is not an iterator of *this; - example: `"iterator does not fit current value"` - - @complexity Linear in @a cnt plus linear in the distance between @a pos - and end of the container. - - @liveexample{The example shows how `insert()` is used.,insert__count} - - @since version 1.0.0 - */ + /// @brief inserts copies of element into array + /// @sa https://json.nlohmann.me/api/basic_json/insert/ iterator insert(const_iterator pos, size_type cnt, const basic_json& val) { // insert only works for arrays @@ -23332,36 +20225,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec JSON_THROW(type_error::create(309, "cannot use insert() with " + std::string(type_name()), *this)); } - /*! - @brief inserts elements - - Inserts elements from range `[first, last)` before iterator @a pos. - - @param[in] pos iterator before which the content will be inserted; may be - the end() iterator - @param[in] first begin of the range of elements to insert - @param[in] last end of the range of elements to insert - - @throw type_error.309 if called on JSON values other than arrays; example: - `"cannot use insert() with string"` - @throw invalid_iterator.202 if @a pos is not an iterator of *this; - example: `"iterator does not fit current value"` - @throw invalid_iterator.210 if @a first and @a last do not belong to the - same JSON value; example: `"iterators do not fit"` - @throw invalid_iterator.211 if @a first or @a last are iterators into - container for which insert is called; example: `"passed iterators may not - belong to container"` - - @return iterator pointing to the first element inserted, or @a pos if - `first==last` - - @complexity Linear in `std::distance(first, last)` plus linear in the - distance between @a pos and end of the container. - - @liveexample{The example shows how `insert()` is used.,insert__range} - - @since version 1.0.0 - */ + /// @brief inserts range of elements into array + /// @sa https://json.nlohmann.me/api/basic_json/insert/ iterator insert(const_iterator pos, const_iterator first, const_iterator last) { // insert only works for arrays @@ -23391,30 +20256,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return insert_iterator(pos, first.m_it.array_iterator, last.m_it.array_iterator); } - /*! - @brief inserts elements - - Inserts elements from initializer list @a ilist before iterator @a pos. - - @param[in] pos iterator before which the content will be inserted; may be - the end() iterator - @param[in] ilist initializer list to insert the values from - - @throw type_error.309 if called on JSON values other than arrays; example: - `"cannot use insert() with string"` - @throw invalid_iterator.202 if @a pos is not an iterator of *this; - example: `"iterator does not fit current value"` - - @return iterator pointing to the first element inserted, or @a pos if - `ilist` is empty - - @complexity Linear in `ilist.size()` plus linear in the distance between - @a pos and end of the container. - - @liveexample{The example shows how `insert()` is used.,insert__ilist} - - @since version 1.0.0 - */ + /// @brief inserts elements from initializer list into array + /// @sa https://json.nlohmann.me/api/basic_json/insert/ iterator insert(const_iterator pos, initializer_list_t ilist) { // insert only works for arrays @@ -23433,29 +20276,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return insert_iterator(pos, ilist.begin(), ilist.end()); } - /*! - @brief inserts elements - - Inserts elements from range `[first, last)`. - - @param[in] first begin of the range of elements to insert - @param[in] last end of the range of elements to insert - - @throw type_error.309 if called on JSON values other than objects; example: - `"cannot use insert() with string"` - @throw invalid_iterator.202 if iterator @a first or @a last does does not - point to an object; example: `"iterators first and last must point to - objects"` - @throw invalid_iterator.210 if @a first and @a last do not belong to the - same JSON value; example: `"iterators do not fit"` - - @complexity Logarithmic: `O(N*log(size() + N))`, where `N` is the number - of elements to insert. - - @liveexample{The example shows how `insert()` is used.,insert__range_object} - - @since version 3.0.0 - */ + /// @brief inserts range of elements into object + /// @sa https://json.nlohmann.me/api/basic_json/insert/ void insert(const_iterator first, const_iterator last) { // insert only works for objects @@ -23468,91 +20290,27 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec if (JSON_HEDLEY_UNLIKELY(first.m_object != last.m_object)) { JSON_THROW(invalid_iterator::create(210, "iterators do not fit", *this)); - } - - // passed iterators must belong to objects - if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object())) - { - JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", *this)); - } - - m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator); - } - - /*! - @brief updates a JSON object from another object, overwriting existing keys - - Inserts all values from JSON object @a j and overwrites existing keys. - - @param[in] j JSON object to read values from - - @throw type_error.312 if called on JSON values other than objects; example: - `"cannot use update() with string"` - - @complexity O(N*log(size() + N)), where N is the number of elements to - insert. - - @liveexample{The example shows how `update()` is used.,update} - - @sa https://docs.python.org/3.6/library/stdtypes.html#dict.update - - @since version 3.0.0 - */ - void update(const_reference j) - { - // implicitly convert null value to an empty object - if (is_null()) - { - m_type = value_t::object; - m_value.object = create(); - assert_invariant(); - } - - if (JSON_HEDLEY_UNLIKELY(!is_object())) - { - JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(type_name()), *this)); - } - if (JSON_HEDLEY_UNLIKELY(!j.is_object())) - { - JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(j.type_name()), *this)); - } - - for (auto it = j.cbegin(); it != j.cend(); ++it) - { - m_value.object->operator[](it.key()) = it.value(); -#if JSON_DIAGNOSTICS - m_value.object->operator[](it.key()).m_parent = this; -#endif - } - } - - /*! - @brief updates a JSON object from another object, overwriting existing keys - - Inserts all values from from range `[first, last)` and overwrites existing - keys. - - @param[in] first begin of the range of elements to insert - @param[in] last end of the range of elements to insert - - @throw type_error.312 if called on JSON values other than objects; example: - `"cannot use update() with string"` - @throw invalid_iterator.202 if iterator @a first or @a last does does not - point to an object; example: `"iterators first and last must point to - objects"` - @throw invalid_iterator.210 if @a first and @a last do not belong to the - same JSON value; example: `"iterators do not fit"` + } - @complexity O(N*log(size() + N)), where N is the number of elements to - insert. + // passed iterators must belong to objects + if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object())) + { + JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", *this)); + } - @liveexample{The example shows how `update()` is used__range.,update} + m_value.object->insert(first.m_it.object_iterator, last.m_it.object_iterator); + } - @sa https://docs.python.org/3.6/library/stdtypes.html#dict.update + /// @brief updates a JSON object from another object, overwriting existing keys + /// @sa https://json.nlohmann.me/api/basic_json/update/ + void update(const_reference j, bool merge_objects = false) + { + update(j.begin(), j.end(), merge_objects); + } - @since version 3.0.0 - */ - void update(const_iterator first, const_iterator last) + /// @brief updates a JSON object from another object, overwriting existing keys + /// @sa https://json.nlohmann.me/api/basic_json/update/ + void update(const_iterator first, const_iterator last, bool merge_objects = false) { // implicitly convert null value to an empty object if (is_null()) @@ -23574,14 +20332,22 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } // passed iterators must belong to objects - if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object() - || !last.m_object->is_object())) + if (JSON_HEDLEY_UNLIKELY(!first.m_object->is_object())) { - JSON_THROW(invalid_iterator::create(202, "iterators first and last must point to objects", *this)); + JSON_THROW(type_error::create(312, "cannot use update() with " + std::string(first.m_object->type_name()), *first.m_object)); } for (auto it = first; it != last; ++it) { + if (merge_objects && it.value().is_object()) + { + auto it2 = m_value.object->find(it.key()); + if (it2 != m_value.object->end()) + { + it2->second.update(it.value(), true); + continue; + } + } m_value.object->operator[](it.key()) = it.value(); #if JSON_DIAGNOSTICS m_value.object->operator[](it.key()).m_parent = this; @@ -23589,23 +20355,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } } - /*! - @brief exchanges the values - - Exchanges the contents of the JSON value with those of @a other. Does not - invoke any move, copy, or swap operations on individual elements. All - iterators and references remain valid. The past-the-end iterator is - invalidated. - - @param[in,out] other JSON value to exchange the contents with - - @complexity Constant. - - @liveexample{The example below shows how JSON values can be swapped with - `swap()`.,swap__reference} - - @since version 1.0.0 - */ + /// @brief exchanges the values + /// @sa https://json.nlohmann.me/api/basic_json/swap/ void swap(reference other) noexcept ( std::is_nothrow_move_constructible::value&& std::is_nothrow_move_assignable::value&& @@ -23621,24 +20372,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec assert_invariant(); } - /*! - @brief exchanges the values - - Exchanges the contents of the JSON value from @a left with those of @a right. Does not - invoke any move, copy, or swap operations on individual elements. All - iterators and references remain valid. The past-the-end iterator is - invalidated. implemented as a friend function callable via ADL. - - @param[in,out] left JSON value to exchange the contents with - @param[in,out] right JSON value to exchange the contents with - - @complexity Constant. - - @liveexample{The example below shows how JSON values can be swapped with - `swap()`.,swap__reference} - - @since version 1.0.0 - */ + /// @brief exchanges the values + /// @sa https://json.nlohmann.me/api/basic_json/swap/ friend void swap(reference left, reference right) noexcept ( std::is_nothrow_move_constructible::value&& std::is_nothrow_move_assignable::value&& @@ -23649,26 +20384,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec left.swap(right); } - /*! - @brief exchanges the values - - Exchanges the contents of a JSON array with those of @a other. Does not - invoke any move, copy, or swap operations on individual elements. All - iterators and references remain valid. The past-the-end iterator is - invalidated. - - @param[in,out] other array to exchange the contents with - - @throw type_error.310 when JSON value is not an array; example: `"cannot - use swap() with string"` - - @complexity Constant. - - @liveexample{The example below shows how arrays can be swapped with - `swap()`.,swap__array_t} - - @since version 1.0.0 - */ + /// @brief exchanges the values + /// @sa https://json.nlohmann.me/api/basic_json/swap/ void swap(array_t& other) // NOLINT(bugprone-exception-escape) { // swap only works for arrays @@ -23682,26 +20399,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } } - /*! - @brief exchanges the values - - Exchanges the contents of a JSON object with those of @a other. Does not - invoke any move, copy, or swap operations on individual elements. All - iterators and references remain valid. The past-the-end iterator is - invalidated. - - @param[in,out] other object to exchange the contents with - - @throw type_error.310 when JSON value is not an object; example: - `"cannot use swap() with string"` - - @complexity Constant. - - @liveexample{The example below shows how objects can be swapped with - `swap()`.,swap__object_t} - - @since version 1.0.0 - */ + /// @brief exchanges the values + /// @sa https://json.nlohmann.me/api/basic_json/swap/ void swap(object_t& other) // NOLINT(bugprone-exception-escape) { // swap only works for objects @@ -23715,26 +20414,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } } - /*! - @brief exchanges the values - - Exchanges the contents of a JSON string with those of @a other. Does not - invoke any move, copy, or swap operations on individual elements. All - iterators and references remain valid. The past-the-end iterator is - invalidated. - - @param[in,out] other string to exchange the contents with - - @throw type_error.310 when JSON value is not a string; example: `"cannot - use swap() with boolean"` - - @complexity Constant. - - @liveexample{The example below shows how strings can be swapped with - `swap()`.,swap__string_t} - - @since version 1.0.0 - */ + /// @brief exchanges the values + /// @sa https://json.nlohmann.me/api/basic_json/swap/ void swap(string_t& other) // NOLINT(bugprone-exception-escape) { // swap only works for strings @@ -23748,26 +20429,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } } - /*! - @brief exchanges the values - - Exchanges the contents of a JSON string with those of @a other. Does not - invoke any move, copy, or swap operations on individual elements. All - iterators and references remain valid. The past-the-end iterator is - invalidated. - - @param[in,out] other binary to exchange the contents with - - @throw type_error.310 when JSON value is not a string; example: `"cannot - use swap() with boolean"` - - @complexity Constant. - - @liveexample{The example below shows how strings can be swapped with - `swap()`.,swap__binary_t} - - @since version 3.8.0 - */ + /// @brief exchanges the values + /// @sa https://json.nlohmann.me/api/basic_json/swap/ void swap(binary_t& other) // NOLINT(bugprone-exception-escape) { // swap only works for strings @@ -23781,7 +20444,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec } } - /// @copydoc swap(binary_t&) + /// @brief exchanges the values + /// @sa https://json.nlohmann.me/api/basic_json/swap/ void swap(typename binary_t::container_type& other) // NOLINT(bugprone-exception-escape) { // swap only works for strings @@ -23805,61 +20469,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @name lexicographical comparison operators /// @{ - /*! - @brief comparison: equal - - Compares two JSON values for equality according to the following rules: - - Two JSON values are equal if (1) they are from the same type and (2) - their stored values are the same according to their respective - `operator==`. - - Integer and floating-point numbers are automatically converted before - comparison. Note that two NaN values are always treated as unequal. - - Two JSON null values are equal. - - @note Floating-point inside JSON values numbers are compared with - `json::number_float_t::operator==` which is `double::operator==` by - default. To compare floating-point while respecting an epsilon, an alternative - [comparison function](https://github.com/mariokonrad/marnav/blob/master/include/marnav/math/floatingpoint.hpp#L34-#L39) - could be used, for instance - @code {.cpp} - template::value, T>::type> - inline bool is_same(T a, T b, T epsilon = std::numeric_limits::epsilon()) noexcept - { - return std::abs(a - b) <= epsilon; - } - @endcode - Or you can self-defined operator equal function like this: - @code {.cpp} - bool my_equal(const_reference lhs, const_reference rhs) { - const auto lhs_type lhs.type(); - const auto rhs_type rhs.type(); - if (lhs_type == rhs_type) { - switch(lhs_type) - // self_defined case - case value_t::number_float: - return std::abs(lhs - rhs) <= std::numeric_limits::epsilon(); - // other cases remain the same with the original - ... - } - ... - } - @endcode - - @note NaN values never compare equal to themselves or to other NaN values. - - @param[in] lhs first JSON value to consider - @param[in] rhs second JSON value to consider - @return whether the values @a lhs and @a rhs are equal - - @exceptionsafety No-throw guarantee: this function never throws exceptions. - - @complexity Linear. - - @liveexample{The example demonstrates comparing several JSON - types.,operator__equal} - - @since version 1.0.0 - */ + /// @brief comparison: equal + /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ friend bool operator==(const_reference lhs, const_reference rhs) noexcept { #ifdef __GNUC__ @@ -23936,10 +20547,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec #endif } - /*! - @brief comparison: equal - @copydoc operator==(const_reference, const_reference) - */ + /// @brief comparison: equal + /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ template::value, int>::type = 0> friend bool operator==(const_reference lhs, ScalarType rhs) noexcept @@ -23947,10 +20556,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return lhs == basic_json(rhs); } - /*! - @brief comparison: equal - @copydoc operator==(const_reference, const_reference) - */ + /// @brief comparison: equal + /// @sa https://json.nlohmann.me/api/basic_json/operator_eq/ template::value, int>::type = 0> friend bool operator==(ScalarType lhs, const_reference rhs) noexcept @@ -23958,33 +20565,15 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return basic_json(lhs) == rhs; } - /*! - @brief comparison: not equal - - Compares two JSON values for inequality by calculating `not (lhs == rhs)`. - - @param[in] lhs first JSON value to consider - @param[in] rhs second JSON value to consider - @return whether the values @a lhs and @a rhs are not equal - - @complexity Linear. - - @exceptionsafety No-throw guarantee: this function never throws exceptions. - - @liveexample{The example demonstrates comparing several JSON - types.,operator__notequal} - - @since version 1.0.0 - */ + /// @brief comparison: not equal + /// @sa https://json.nlohmann.me/api/basic_json/operator_ne/ friend bool operator!=(const_reference lhs, const_reference rhs) noexcept { return !(lhs == rhs); } - /*! - @brief comparison: not equal - @copydoc operator!=(const_reference, const_reference) - */ + /// @brief comparison: not equal + /// @sa https://json.nlohmann.me/api/basic_json/operator_ne/ template::value, int>::type = 0> friend bool operator!=(const_reference lhs, ScalarType rhs) noexcept @@ -23992,10 +20581,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return lhs != basic_json(rhs); } - /*! - @brief comparison: not equal - @copydoc operator!=(const_reference, const_reference) - */ + /// @brief comparison: not equal + /// @sa https://json.nlohmann.me/api/basic_json/operator_ne/ template::value, int>::type = 0> friend bool operator!=(ScalarType lhs, const_reference rhs) noexcept @@ -24003,32 +20590,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return basic_json(lhs) != rhs; } - /*! - @brief comparison: less than - - Compares whether one JSON value @a lhs is less than another JSON value @a - rhs according to the following rules: - - If @a lhs and @a rhs have the same type, the values are compared using - the default `<` operator. - - Integer and floating-point numbers are automatically converted before - comparison - - In case @a lhs and @a rhs have different types, the values are ignored - and the order of the types is considered, see - @ref operator<(const value_t, const value_t). - - @param[in] lhs first JSON value to consider - @param[in] rhs second JSON value to consider - @return whether @a lhs is less than @a rhs - - @complexity Linear. - - @exceptionsafety No-throw guarantee: this function never throws exceptions. - - @liveexample{The example demonstrates comparing several JSON - types.,operator__less} - - @since version 1.0.0 - */ + /// @brief comparison: less than + /// @sa https://json.nlohmann.me/api/basic_json/operator_lt/ friend bool operator<(const_reference lhs, const_reference rhs) noexcept { const auto lhs_type = lhs.type(); @@ -24103,10 +20666,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return operator<(lhs_type, rhs_type); } - /*! - @brief comparison: less than - @copydoc operator<(const_reference, const_reference) - */ + /// @brief comparison: less than + /// @sa https://json.nlohmann.me/api/basic_json/operator_lt/ template::value, int>::type = 0> friend bool operator<(const_reference lhs, ScalarType rhs) noexcept @@ -24114,10 +20675,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return lhs < basic_json(rhs); } - /*! - @brief comparison: less than - @copydoc operator<(const_reference, const_reference) - */ + /// @brief comparison: less than + /// @sa https://json.nlohmann.me/api/basic_json/operator_lt/ template::value, int>::type = 0> friend bool operator<(ScalarType lhs, const_reference rhs) noexcept @@ -24125,34 +20684,15 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return basic_json(lhs) < rhs; } - /*! - @brief comparison: less than or equal - - Compares whether one JSON value @a lhs is less than or equal to another - JSON value by calculating `not (rhs < lhs)`. - - @param[in] lhs first JSON value to consider - @param[in] rhs second JSON value to consider - @return whether @a lhs is less than or equal to @a rhs - - @complexity Linear. - - @exceptionsafety No-throw guarantee: this function never throws exceptions. - - @liveexample{The example demonstrates comparing several JSON - types.,operator__greater} - - @since version 1.0.0 - */ + /// @brief comparison: less than or equal + /// @sa https://json.nlohmann.me/api/basic_json/operator_le/ friend bool operator<=(const_reference lhs, const_reference rhs) noexcept { return !(rhs < lhs); } - /*! - @brief comparison: less than or equal - @copydoc operator<=(const_reference, const_reference) - */ + /// @brief comparison: less than or equal + /// @sa https://json.nlohmann.me/api/basic_json/operator_le/ template::value, int>::type = 0> friend bool operator<=(const_reference lhs, ScalarType rhs) noexcept @@ -24160,10 +20700,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return lhs <= basic_json(rhs); } - /*! - @brief comparison: less than or equal - @copydoc operator<=(const_reference, const_reference) - */ + /// @brief comparison: less than or equal + /// @sa https://json.nlohmann.me/api/basic_json/operator_le/ template::value, int>::type = 0> friend bool operator<=(ScalarType lhs, const_reference rhs) noexcept @@ -24171,34 +20709,15 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return basic_json(lhs) <= rhs; } - /*! - @brief comparison: greater than - - Compares whether one JSON value @a lhs is greater than another - JSON value by calculating `not (lhs <= rhs)`. - - @param[in] lhs first JSON value to consider - @param[in] rhs second JSON value to consider - @return whether @a lhs is greater than to @a rhs - - @complexity Linear. - - @exceptionsafety No-throw guarantee: this function never throws exceptions. - - @liveexample{The example demonstrates comparing several JSON - types.,operator__lessequal} - - @since version 1.0.0 - */ + /// @brief comparison: greater than + /// @sa https://json.nlohmann.me/api/basic_json/operator_gt/ friend bool operator>(const_reference lhs, const_reference rhs) noexcept { return !(lhs <= rhs); } - /*! - @brief comparison: greater than - @copydoc operator>(const_reference, const_reference) - */ + /// @brief comparison: greater than + /// @sa https://json.nlohmann.me/api/basic_json/operator_gt/ template::value, int>::type = 0> friend bool operator>(const_reference lhs, ScalarType rhs) noexcept @@ -24206,10 +20725,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return lhs > basic_json(rhs); } - /*! - @brief comparison: greater than - @copydoc operator>(const_reference, const_reference) - */ + /// @brief comparison: greater than + /// @sa https://json.nlohmann.me/api/basic_json/operator_gt/ template::value, int>::type = 0> friend bool operator>(ScalarType lhs, const_reference rhs) noexcept @@ -24217,34 +20734,15 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return basic_json(lhs) > rhs; } - /*! - @brief comparison: greater than or equal - - Compares whether one JSON value @a lhs is greater than or equal to another - JSON value by calculating `not (lhs < rhs)`. - - @param[in] lhs first JSON value to consider - @param[in] rhs second JSON value to consider - @return whether @a lhs is greater than or equal to @a rhs - - @complexity Linear. - - @exceptionsafety No-throw guarantee: this function never throws exceptions. - - @liveexample{The example demonstrates comparing several JSON - types.,operator__greaterequal} - - @since version 1.0.0 - */ + /// @brief comparison: greater than or equal + /// @sa https://json.nlohmann.me/api/basic_json/operator_ge/ friend bool operator>=(const_reference lhs, const_reference rhs) noexcept { return !(lhs < rhs); } - /*! - @brief comparison: greater than or equal - @copydoc operator>=(const_reference, const_reference) - */ + /// @brief comparison: greater than or equal + /// @sa https://json.nlohmann.me/api/basic_json/operator_ge/ template::value, int>::type = 0> friend bool operator>=(const_reference lhs, ScalarType rhs) noexcept @@ -24252,10 +20750,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return lhs >= basic_json(rhs); } - /*! - @brief comparison: greater than or equal - @copydoc operator>=(const_reference, const_reference) - */ + /// @brief comparison: greater than or equal + /// @sa https://json.nlohmann.me/api/basic_json/operator_ge/ template::value, int>::type = 0> friend bool operator>=(ScalarType lhs, const_reference rhs) noexcept @@ -24272,37 +20768,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @name serialization /// @{ #ifndef JSON_NO_IO - /*! - @brief serialize to stream - - Serialize the given JSON value @a j to the output stream @a o. The JSON - value will be serialized using the @ref dump member function. - - - The indentation of the output can be controlled with the member variable - `width` of the output stream @a o. For instance, using the manipulator - `std::setw(4)` on @a o sets the indentation level to `4` and the - serialization result is the same as calling `dump(4)`. - - - The indentation character can be controlled with the member variable - `fill` of the output stream @a o. For instance, the manipulator - `std::setfill('\\t')` sets indentation to use a tab character rather than - the default space character. - - @param[in,out] o stream to serialize to - @param[in] j JSON value to serialize - - @return the stream @a o - - @throw type_error.316 if a string stored inside the JSON value is not - UTF-8 encoded - - @complexity Linear. - - @liveexample{The example below shows the serialization with different - parameters to `width` to adjust the indentation level.,operator_serialize} - - @since version 1.0.0; indentation character added in version 3.0.0 - */ + /// @brief serialize to stream + /// @sa https://json.nlohmann.me/api/basic_json/operator_ltlt/ friend std::ostream& operator<<(std::ostream& o, const basic_json& j) { // read width member and use it as indentation parameter if nonzero @@ -24318,14 +20785,12 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return o; } - /*! - @brief serialize to stream - @deprecated This stream operator is deprecated and will be removed in - future 4.0.0 of the library. Please use - @ref operator<<(std::ostream&, const basic_json&) - instead; that is, replace calls like `j >> o;` with `o << j;`. - @since version 1.0.0; deprecated since version 3.0.0 - */ + /// @brief serialize to stream + /// @sa https://json.nlohmann.me/api/basic_json/operator_ltlt/ + /// @deprecated This function is deprecated since 3.0.0 and will be removed in + /// version 4.0.0 of the library. Please use + /// operator<<(std::ostream&, const basic_json&) instead; that is, + /// replace calls like `j >> o;` with `o << j;`. JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator<<(std::ostream&, const basic_json&)) friend std::ostream& operator>>(const basic_json& j, std::ostream& o) { @@ -24342,57 +20807,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @name deserialization /// @{ - /*! - @brief deserialize from a compatible input - - @tparam InputType A compatible input, for instance - - an std::istream object - - a FILE pointer - - a C-style array of characters - - a pointer to a null-terminated string of single byte characters - - an object obj for which begin(obj) and end(obj) produces a valid pair of - iterators. - - @param[in] i input to read from - @param[in] cb a parser callback function of type @ref parser_callback_t - which is used to control the deserialization by filtering unwanted values - (optional) - @param[in] allow_exceptions whether to throw exceptions in case of a - parse error (optional, true by default) - @param[in] ignore_comments whether comments should be ignored and treated - like whitespace (true) or yield a parse error (true); (optional, false by - default) - - @return deserialized JSON value; in case of a parse error and - @a allow_exceptions set to `false`, the return value will be - value_t::discarded. - - @throw parse_error.101 if a parse error occurs; example: `""unexpected end - of input; expected string literal""` - @throw parse_error.102 if to_unicode fails or surrogate error - @throw parse_error.103 if to_unicode fails - - @complexity Linear in the length of the input. The parser is a predictive - LL(1) parser. The complexity can be higher if the parser callback function - @a cb or reading from the input @a i has a super-linear complexity. - - @note A UTF-8 byte order mark is silently ignored. - - @liveexample{The example below demonstrates the `parse()` function reading - from an array.,parse__array__parser_callback_t} - - @liveexample{The example below demonstrates the `parse()` function with - and without callback function.,parse__string__parser_callback_t} - - @liveexample{The example below demonstrates the `parse()` function with - and without callback function.,parse__istream__parser_callback_t} - - @liveexample{The example below demonstrates the `parse()` function reading - from a contiguous container.,parse__contiguouscontainer__parser_callback_t} - - @since version 2.0.3 (contiguous containers); version 3.9.0 allowed to - ignore comments. - */ + /// @brief deserialize from a compatible input + /// @sa https://json.nlohmann.me/api/basic_json/parse/ template JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json parse(InputType&& i, @@ -24405,32 +20821,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } - /*! - @brief deserialize from a pair of character iterators - - The value_type of the iterator must be a integral type with size of 1, 2 or - 4 bytes, which will be interpreted respectively as UTF-8, UTF-16 and UTF-32. - - @param[in] first iterator to start of character range - @param[in] last iterator to end of character range - @param[in] cb a parser callback function of type @ref parser_callback_t - which is used to control the deserialization by filtering unwanted values - (optional) - @param[in] allow_exceptions whether to throw exceptions in case of a - parse error (optional, true by default) - @param[in] ignore_comments whether comments should be ignored and treated - like whitespace (true) or yield a parse error (true); (optional, false by - default) - - @return deserialized JSON value; in case of a parse error and - @a allow_exceptions set to `false`, the return value will be - value_t::discarded. - - @throw parse_error.101 if a parse error occurs; example: `""unexpected end - of input; expected string literal""` - @throw parse_error.102 if to_unicode fails or surrogate error - @throw parse_error.103 if to_unicode fails - */ + /// @brief deserialize from a pair of character iterators + /// @sa https://json.nlohmann.me/api/basic_json/parse/ template JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json parse(IteratorType first, @@ -24456,36 +20848,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } - /*! - @brief check if the input is valid JSON - - Unlike the @ref parse(InputType&&, const parser_callback_t,const bool) - function, this function neither throws an exception in case of invalid JSON - input (i.e., a parse error) nor creates diagnostic information. - - @tparam InputType A compatible input, for instance - - an std::istream object - - a FILE pointer - - a C-style array of characters - - a pointer to a null-terminated string of single byte characters - - an object obj for which begin(obj) and end(obj) produces a valid pair of - iterators. - - @param[in] i input to read from - @param[in] ignore_comments whether comments should be ignored and treated - like whitespace (true) or yield a parse error (true); (optional, false by - default) - - @return Whether the input read from @a i is valid JSON. - - @complexity Linear in the length of the input. The parser is a predictive - LL(1) parser. - - @note A UTF-8 byte order mark is silently ignored. - - @liveexample{The example below demonstrates the `accept()` function reading - from a string.,accept__string} - */ + /// @brief check if the input is valid JSON + /// @sa https://json.nlohmann.me/api/basic_json/accept/ template static bool accept(InputType&& i, const bool ignore_comments = false) @@ -24493,6 +20857,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return parser(detail::input_adapter(std::forward(i)), nullptr, false, ignore_comments).accept(true); } + /// @brief check if the input is valid JSON + /// @sa https://json.nlohmann.me/api/basic_json/accept/ template static bool accept(IteratorType first, IteratorType last, const bool ignore_comments = false) @@ -24508,46 +20874,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return parser(i.get(), nullptr, false, ignore_comments).accept(true); } - /*! - @brief generate SAX events - - The SAX event lister must follow the interface of @ref json_sax. - - This function reads from a compatible input. Examples are: - - an std::istream object - - a FILE pointer - - a C-style array of characters - - a pointer to a null-terminated string of single byte characters - - an object obj for which begin(obj) and end(obj) produces a valid pair of - iterators. - - @param[in] i input to read from - @param[in,out] sax SAX event listener - @param[in] format the format to parse (JSON, CBOR, MessagePack, or UBJSON) - @param[in] strict whether the input has to be consumed completely - @param[in] ignore_comments whether comments should be ignored and treated - like whitespace (true) or yield a parse error (true); (optional, false by - default); only applies to the JSON file format. - - @return return value of the last processed SAX event - - @throw parse_error.101 if a parse error occurs; example: `""unexpected end - of input; expected string literal""` - @throw parse_error.102 if to_unicode fails or surrogate error - @throw parse_error.103 if to_unicode fails - - @complexity Linear in the length of the input. The parser is a predictive - LL(1) parser. The complexity can be higher if the SAX consumer @a sax has - a super-linear complexity. - - @note A UTF-8 byte order mark is silently ignored. - - @liveexample{The example below demonstrates the `sax_parse()` function - reading from string and processing the events with a user-defined SAX - event consumer.,sax_parse} - - @since version 3.2.0 - */ + /// @brief generate SAX events + /// @sa https://json.nlohmann.me/api/basic_json/sax_parse/ template JSON_HEDLEY_NON_NULL(2) static bool sax_parse(InputType&& i, SAX* sax, @@ -24561,6 +20889,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec : detail::binary_reader(std::move(ia)).sax_parse(format, sax, strict); } + /// @brief generate SAX events + /// @sa https://json.nlohmann.me/api/basic_json/sax_parse/ template JSON_HEDLEY_NON_NULL(3) static bool sax_parse(IteratorType first, IteratorType last, SAX* sax, @@ -24574,6 +20904,11 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec : detail::binary_reader(std::move(ia)).sax_parse(format, sax, strict); } + /// @brief generate SAX events + /// @sa https://json.nlohmann.me/api/basic_json/sax_parse/ + /// @deprecated This function is deprecated since 3.8.0 and will be removed in + /// version 4.0.0 of the library. Please use + /// sax_parse(ptr, ptr + len) instead. template JSON_HEDLEY_DEPRECATED_FOR(3.8.0, sax_parse(ptr, ptr + len, ...)) JSON_HEDLEY_NON_NULL(2) @@ -24585,50 +20920,25 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec auto ia = i.get(); return format == input_format_t::json // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) - ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) - // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) - : detail::binary_reader(std::move(ia)).sax_parse(format, sax, strict); - } -#ifndef JSON_NO_IO - /*! - @brief deserialize from stream - @deprecated This stream operator is deprecated and will be removed in - version 4.0.0 of the library. Please use - @ref operator>>(std::istream&, basic_json&) - instead; that is, replace calls like `j << i;` with `i >> j;`. - @since version 1.0.0; deprecated since version 3.0.0 - */ - JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator>>(std::istream&, basic_json&)) - friend std::istream& operator<<(basic_json& j, std::istream& i) - { - return operator>>(i, j); - } - - /*! - @brief deserialize from stream - - Deserializes an input stream to a JSON value. - - @param[in,out] i input stream to read a serialized JSON value from - @param[in,out] j JSON value to write the deserialized input to - - @throw parse_error.101 in case of an unexpected token - @throw parse_error.102 if to_unicode fails or surrogate error - @throw parse_error.103 if to_unicode fails - - @complexity Linear in the length of the input. The parser is a predictive - LL(1) parser. - - @note A UTF-8 byte order mark is silently ignored. - - @liveexample{The example below shows how a JSON value is constructed by - reading a serialization from a stream.,operator_deserialize} - - @sa parse(std::istream&, const parser_callback_t) for a variant with a - parser callback function to filter values while parsing + ? parser(std::move(ia), nullptr, true, ignore_comments).sax_parse(sax, strict) + // NOLINTNEXTLINE(hicpp-move-const-arg,performance-move-const-arg) + : detail::binary_reader(std::move(ia)).sax_parse(format, sax, strict); + } +#ifndef JSON_NO_IO + /// @brief deserialize from stream + /// @sa https://json.nlohmann.me/api/basic_json/operator_gtgt/ + /// @deprecated This stream operator is deprecated since 3.0.0 and will be removed in + /// version 4.0.0 of the library. Please use + /// operator>>(std::istream&, basic_json&) instead; that is, + /// replace calls like `j << i;` with `i >> j;`. + JSON_HEDLEY_DEPRECATED_FOR(3.0.0, operator>>(std::istream&, basic_json&)) + friend std::istream& operator<<(basic_json& j, std::istream& i) + { + return operator>>(i, j); + } - @since version 1.0.0 - */ + /// @brief deserialize from stream + /// @sa https://json.nlohmann.me/api/basic_json/operator_gtgt/ friend std::istream& operator>>(std::istream& i, basic_json& j) { parser(detail::input_adapter(i)).parse(false, j); @@ -24641,63 +20951,32 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec // convenience functions // /////////////////////////// - /*! - @brief return the type as string - - Returns the type name as string to be used in error messages - usually to - indicate that a function was called on a wrong JSON type. - - @return a string representation of a the @a m_type member: - Value type | return value - ----------- | ------------- - null | `"null"` - boolean | `"boolean"` - string | `"string"` - number | `"number"` (for all number types) - object | `"object"` - array | `"array"` - binary | `"binary"` - discarded | `"discarded"` - - @exceptionsafety No-throw guarantee: this function never throws exceptions. - - @complexity Constant. - - @liveexample{The following code exemplifies `type_name()` for all JSON - types.,type_name} - - @sa see @ref type() -- return the type of the JSON value - @sa see @ref operator value_t() -- return the type of the JSON value (implicit) - - @since version 1.0.0, public since 2.1.0, `const char*` and `noexcept` - since 3.0.0 - */ + /// @brief return the type as string + /// @sa https://json.nlohmann.me/api/basic_json/type_name/ JSON_HEDLEY_RETURNS_NON_NULL const char* type_name() const noexcept { + switch (m_type) { - switch (m_type) - { - case value_t::null: - return "null"; - case value_t::object: - return "object"; - case value_t::array: - return "array"; - case value_t::string: - return "string"; - case value_t::boolean: - return "boolean"; - case value_t::binary: - return "binary"; - case value_t::discarded: - return "discarded"; - case value_t::number_integer: - case value_t::number_unsigned: - case value_t::number_float: - default: - return "number"; - } + case value_t::null: + return "null"; + case value_t::object: + return "object"; + case value_t::array: + return "array"; + case value_t::string: + return "string"; + case value_t::boolean: + return "boolean"; + case value_t::binary: + return "binary"; + case value_t::discarded: + return "discarded"; + case value_t::number_integer: + case value_t::number_unsigned: + case value_t::number_float: + default: + return "number"; } } @@ -24726,104 +21005,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @{ public: - /*! - @brief create a CBOR serialization of a given JSON value - - Serializes a given JSON value @a j to a byte vector using the CBOR (Concise - Binary Object Representation) serialization format. CBOR is a binary - serialization format which aims to be more compact than JSON itself, yet - more efficient to parse. - - The library uses the following mapping from JSON values types to - CBOR types according to the CBOR specification (RFC 7049): - - JSON value type | value/range | CBOR type | first byte - --------------- | ------------------------------------------ | ---------------------------------- | --------------- - null | `null` | Null | 0xF6 - boolean | `true` | True | 0xF5 - boolean | `false` | False | 0xF4 - number_integer | -9223372036854775808..-2147483649 | Negative integer (8 bytes follow) | 0x3B - number_integer | -2147483648..-32769 | Negative integer (4 bytes follow) | 0x3A - number_integer | -32768..-129 | Negative integer (2 bytes follow) | 0x39 - number_integer | -128..-25 | Negative integer (1 byte follow) | 0x38 - number_integer | -24..-1 | Negative integer | 0x20..0x37 - number_integer | 0..23 | Integer | 0x00..0x17 - number_integer | 24..255 | Unsigned integer (1 byte follow) | 0x18 - number_integer | 256..65535 | Unsigned integer (2 bytes follow) | 0x19 - number_integer | 65536..4294967295 | Unsigned integer (4 bytes follow) | 0x1A - number_integer | 4294967296..18446744073709551615 | Unsigned integer (8 bytes follow) | 0x1B - number_unsigned | 0..23 | Integer | 0x00..0x17 - number_unsigned | 24..255 | Unsigned integer (1 byte follow) | 0x18 - number_unsigned | 256..65535 | Unsigned integer (2 bytes follow) | 0x19 - number_unsigned | 65536..4294967295 | Unsigned integer (4 bytes follow) | 0x1A - number_unsigned | 4294967296..18446744073709551615 | Unsigned integer (8 bytes follow) | 0x1B - number_float | *any value representable by a float* | Single-Precision Float | 0xFA - number_float | *any value NOT representable by a float* | Double-Precision Float | 0xFB - string | *length*: 0..23 | UTF-8 string | 0x60..0x77 - string | *length*: 23..255 | UTF-8 string (1 byte follow) | 0x78 - string | *length*: 256..65535 | UTF-8 string (2 bytes follow) | 0x79 - string | *length*: 65536..4294967295 | UTF-8 string (4 bytes follow) | 0x7A - string | *length*: 4294967296..18446744073709551615 | UTF-8 string (8 bytes follow) | 0x7B - array | *size*: 0..23 | array | 0x80..0x97 - array | *size*: 23..255 | array (1 byte follow) | 0x98 - array | *size*: 256..65535 | array (2 bytes follow) | 0x99 - array | *size*: 65536..4294967295 | array (4 bytes follow) | 0x9A - array | *size*: 4294967296..18446744073709551615 | array (8 bytes follow) | 0x9B - object | *size*: 0..23 | map | 0xA0..0xB7 - object | *size*: 23..255 | map (1 byte follow) | 0xB8 - object | *size*: 256..65535 | map (2 bytes follow) | 0xB9 - object | *size*: 65536..4294967295 | map (4 bytes follow) | 0xBA - object | *size*: 4294967296..18446744073709551615 | map (8 bytes follow) | 0xBB - binary | *size*: 0..23 | byte string | 0x40..0x57 - binary | *size*: 23..255 | byte string (1 byte follow) | 0x58 - binary | *size*: 256..65535 | byte string (2 bytes follow) | 0x59 - binary | *size*: 65536..4294967295 | byte string (4 bytes follow) | 0x5A - binary | *size*: 4294967296..18446744073709551615 | byte string (8 bytes follow) | 0x5B - - Binary values with subtype are mapped to tagged values (0xD8..0xDB) - depending on the subtype, followed by a byte string, see "binary" cells - in the table above. - - @note The mapping is **complete** in the sense that any JSON value type - can be converted to a CBOR value. - - @note If NaN or Infinity are stored inside a JSON number, they are - serialized properly. This behavior differs from the @ref dump() - function which serializes NaN or Infinity to `null`. - - @note The following CBOR types are not used in the conversion: - - UTF-8 strings terminated by "break" (0x7F) - - arrays terminated by "break" (0x9F) - - maps terminated by "break" (0xBF) - - byte strings terminated by "break" (0x5F) - - date/time (0xC0..0xC1) - - bignum (0xC2..0xC3) - - decimal fraction (0xC4) - - bigfloat (0xC5) - - expected conversions (0xD5..0xD7) - - simple values (0xE0..0xF3, 0xF8) - - undefined (0xF7) - - half-precision floats (0xF9) - - break (0xFF) - - @param[in] j JSON value to serialize - @return CBOR serialization as byte vector - - @complexity Linear in the size of the JSON value @a j. - - @liveexample{The example shows the serialization of a JSON value to a byte - vector in CBOR format.,to_cbor} - - @sa http://cbor.io - @sa see @ref from_cbor(InputType&&, const bool, const bool, const cbor_tag_handler_t) for the - analogous deserialization - @sa see @ref to_msgpack(const basic_json&) for the related MessagePack format - @sa see @ref to_ubjson(const basic_json&, const bool, const bool) for the - related UBJSON format - - @since version 2.0.9; compact representation of floating-point numbers - since version 3.8.0 - */ + /// @brief create a CBOR serialization of a given JSON value + /// @sa https://json.nlohmann.me/api/basic_json/to_cbor/ static std::vector to_cbor(const basic_json& j) { std::vector result; @@ -24831,94 +21014,22 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } + /// @brief create a CBOR serialization of a given JSON value + /// @sa https://json.nlohmann.me/api/basic_json/to_cbor/ static void to_cbor(const basic_json& j, detail::output_adapter o) { binary_writer(o).write_cbor(j); } + /// @brief create a CBOR serialization of a given JSON value + /// @sa https://json.nlohmann.me/api/basic_json/to_cbor/ static void to_cbor(const basic_json& j, detail::output_adapter o) { binary_writer(o).write_cbor(j); } - /*! - @brief create a MessagePack serialization of a given JSON value - - Serializes a given JSON value @a j to a byte vector using the MessagePack - serialization format. MessagePack is a binary serialization format which - aims to be more compact than JSON itself, yet more efficient to parse. - - The library uses the following mapping from JSON values types to - MessagePack types according to the MessagePack specification: - - JSON value type | value/range | MessagePack type | first byte - --------------- | --------------------------------- | ---------------- | ---------- - null | `null` | nil | 0xC0 - boolean | `true` | true | 0xC3 - boolean | `false` | false | 0xC2 - number_integer | -9223372036854775808..-2147483649 | int64 | 0xD3 - number_integer | -2147483648..-32769 | int32 | 0xD2 - number_integer | -32768..-129 | int16 | 0xD1 - number_integer | -128..-33 | int8 | 0xD0 - number_integer | -32..-1 | negative fixint | 0xE0..0xFF - number_integer | 0..127 | positive fixint | 0x00..0x7F - number_integer | 128..255 | uint 8 | 0xCC - number_integer | 256..65535 | uint 16 | 0xCD - number_integer | 65536..4294967295 | uint 32 | 0xCE - number_integer | 4294967296..18446744073709551615 | uint 64 | 0xCF - number_unsigned | 0..127 | positive fixint | 0x00..0x7F - number_unsigned | 128..255 | uint 8 | 0xCC - number_unsigned | 256..65535 | uint 16 | 0xCD - number_unsigned | 65536..4294967295 | uint 32 | 0xCE - number_unsigned | 4294967296..18446744073709551615 | uint 64 | 0xCF - number_float | *any value representable by a float* | float 32 | 0xCA - number_float | *any value NOT representable by a float* | float 64 | 0xCB - string | *length*: 0..31 | fixstr | 0xA0..0xBF - string | *length*: 32..255 | str 8 | 0xD9 - string | *length*: 256..65535 | str 16 | 0xDA - string | *length*: 65536..4294967295 | str 32 | 0xDB - array | *size*: 0..15 | fixarray | 0x90..0x9F - array | *size*: 16..65535 | array 16 | 0xDC - array | *size*: 65536..4294967295 | array 32 | 0xDD - object | *size*: 0..15 | fix map | 0x80..0x8F - object | *size*: 16..65535 | map 16 | 0xDE - object | *size*: 65536..4294967295 | map 32 | 0xDF - binary | *size*: 0..255 | bin 8 | 0xC4 - binary | *size*: 256..65535 | bin 16 | 0xC5 - binary | *size*: 65536..4294967295 | bin 32 | 0xC6 - - @note The mapping is **complete** in the sense that any JSON value type - can be converted to a MessagePack value. - - @note The following values can **not** be converted to a MessagePack value: - - strings with more than 4294967295 bytes - - byte strings with more than 4294967295 bytes - - arrays with more than 4294967295 elements - - objects with more than 4294967295 elements - - @note Any MessagePack output created @ref to_msgpack can be successfully - parsed by @ref from_msgpack. - - @note If NaN or Infinity are stored inside a JSON number, they are - serialized properly. This behavior differs from the @ref dump() - function which serializes NaN or Infinity to `null`. - - @param[in] j JSON value to serialize - @return MessagePack serialization as byte vector - - @complexity Linear in the size of the JSON value @a j. - - @liveexample{The example shows the serialization of a JSON value to a byte - vector in MessagePack format.,to_msgpack} - - @sa http://msgpack.org - @sa see @ref from_msgpack for the analogous deserialization - @sa see @ref to_cbor(const basic_json& for the related CBOR format - @sa see @ref to_ubjson(const basic_json&, const bool, const bool) for the - related UBJSON format - - @since version 2.0.9 - */ + /// @brief create a MessagePack serialization of a given JSON value + /// @sa https://json.nlohmann.me/api/basic_json/to_msgpack/ static std::vector to_msgpack(const basic_json& j) { std::vector result; @@ -24926,102 +21037,22 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } + /// @brief create a MessagePack serialization of a given JSON value + /// @sa https://json.nlohmann.me/api/basic_json/to_msgpack/ static void to_msgpack(const basic_json& j, detail::output_adapter o) { binary_writer(o).write_msgpack(j); } + /// @brief create a MessagePack serialization of a given JSON value + /// @sa https://json.nlohmann.me/api/basic_json/to_msgpack/ static void to_msgpack(const basic_json& j, detail::output_adapter o) { binary_writer(o).write_msgpack(j); } - /*! - @brief create a UBJSON serialization of a given JSON value - - Serializes a given JSON value @a j to a byte vector using the UBJSON - (Universal Binary JSON) serialization format. UBJSON aims to be more compact - than JSON itself, yet more efficient to parse. - - The library uses the following mapping from JSON values types to - UBJSON types according to the UBJSON specification: - - JSON value type | value/range | UBJSON type | marker - --------------- | --------------------------------- | ----------- | ------ - null | `null` | null | `Z` - boolean | `true` | true | `T` - boolean | `false` | false | `F` - number_integer | -9223372036854775808..-2147483649 | int64 | `L` - number_integer | -2147483648..-32769 | int32 | `l` - number_integer | -32768..-129 | int16 | `I` - number_integer | -128..127 | int8 | `i` - number_integer | 128..255 | uint8 | `U` - number_integer | 256..32767 | int16 | `I` - number_integer | 32768..2147483647 | int32 | `l` - number_integer | 2147483648..9223372036854775807 | int64 | `L` - number_unsigned | 0..127 | int8 | `i` - number_unsigned | 128..255 | uint8 | `U` - number_unsigned | 256..32767 | int16 | `I` - number_unsigned | 32768..2147483647 | int32 | `l` - number_unsigned | 2147483648..9223372036854775807 | int64 | `L` - number_unsigned | 2147483649..18446744073709551615 | high-precision | `H` - number_float | *any value* | float64 | `D` - string | *with shortest length indicator* | string | `S` - array | *see notes on optimized format* | array | `[` - object | *see notes on optimized format* | map | `{` - - @note The mapping is **complete** in the sense that any JSON value type - can be converted to a UBJSON value. - - @note The following values can **not** be converted to a UBJSON value: - - strings with more than 9223372036854775807 bytes (theoretical) - - @note The following markers are not used in the conversion: - - `Z`: no-op values are not created. - - `C`: single-byte strings are serialized with `S` markers. - - @note Any UBJSON output created @ref to_ubjson can be successfully parsed - by @ref from_ubjson. - - @note If NaN or Infinity are stored inside a JSON number, they are - serialized properly. This behavior differs from the @ref dump() - function which serializes NaN or Infinity to `null`. - - @note The optimized formats for containers are supported: Parameter - @a use_size adds size information to the beginning of a container and - removes the closing marker. Parameter @a use_type further checks - whether all elements of a container have the same type and adds the - type marker to the beginning of the container. The @a use_type - parameter must only be used together with @a use_size = true. Note - that @a use_size = true alone may result in larger representations - - the benefit of this parameter is that the receiving side is - immediately informed on the number of elements of the container. - - @note If the JSON data contains the binary type, the value stored is a list - of integers, as suggested by the UBJSON documentation. In particular, - this means that serialization and the deserialization of a JSON - containing binary values into UBJSON and back will result in a - different JSON object. - - @param[in] j JSON value to serialize - @param[in] use_size whether to add size annotations to container types - @param[in] use_type whether to add type annotations to container types - (must be combined with @a use_size = true) - @return UBJSON serialization as byte vector - - @complexity Linear in the size of the JSON value @a j. - - @liveexample{The example shows the serialization of a JSON value to a byte - vector in UBJSON format.,to_ubjson} - - @sa http://ubjson.org - @sa see @ref from_ubjson(InputType&&, const bool, const bool) for the - analogous deserialization - @sa see @ref to_cbor(const basic_json& for the related CBOR format - @sa see @ref to_msgpack(const basic_json&) for the related MessagePack format - - @since version 3.1.0 - */ + /// @brief create a UBJSON serialization of a given JSON value + /// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/ static std::vector to_ubjson(const basic_json& j, const bool use_size = false, const bool use_type = false) @@ -25031,75 +21062,24 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } + /// @brief create a UBJSON serialization of a given JSON value + /// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/ static void to_ubjson(const basic_json& j, detail::output_adapter o, const bool use_size = false, const bool use_type = false) { binary_writer(o).write_ubjson(j, use_size, use_type); } + /// @brief create a UBJSON serialization of a given JSON value + /// @sa https://json.nlohmann.me/api/basic_json/to_ubjson/ static void to_ubjson(const basic_json& j, detail::output_adapter o, const bool use_size = false, const bool use_type = false) { binary_writer(o).write_ubjson(j, use_size, use_type); } - - /*! - @brief Serializes the given JSON object `j` to BSON and returns a vector - containing the corresponding BSON-representation. - - BSON (Binary JSON) is a binary format in which zero or more ordered key/value pairs are - stored as a single entity (a so-called document). - - The library uses the following mapping from JSON values types to BSON types: - - JSON value type | value/range | BSON type | marker - --------------- | --------------------------------- | ----------- | ------ - null | `null` | null | 0x0A - boolean | `true`, `false` | boolean | 0x08 - number_integer | -9223372036854775808..-2147483649 | int64 | 0x12 - number_integer | -2147483648..2147483647 | int32 | 0x10 - number_integer | 2147483648..9223372036854775807 | int64 | 0x12 - number_unsigned | 0..2147483647 | int32 | 0x10 - number_unsigned | 2147483648..9223372036854775807 | int64 | 0x12 - number_unsigned | 9223372036854775808..18446744073709551615| -- | -- - number_float | *any value* | double | 0x01 - string | *any value* | string | 0x02 - array | *any value* | document | 0x04 - object | *any value* | document | 0x03 - binary | *any value* | binary | 0x05 - - @warning The mapping is **incomplete**, since only JSON-objects (and things - contained therein) can be serialized to BSON. - Also, integers larger than 9223372036854775807 cannot be serialized to BSON, - and the keys may not contain U+0000, since they are serialized a - zero-terminated c-strings. - - @throw out_of_range.407 if `j.is_number_unsigned() && j.get() > 9223372036854775807` - @throw out_of_range.409 if a key in `j` contains a NULL (U+0000) - @throw type_error.317 if `!j.is_object()` - - @pre The input `j` is required to be an object: `j.is_object() == true`. - - @note Any BSON output created via @ref to_bson can be successfully parsed - by @ref from_bson. - - @param[in] j JSON value to serialize - @return BSON serialization as byte vector - - @complexity Linear in the size of the JSON value @a j. - - @liveexample{The example shows the serialization of a JSON value to a byte - vector in BSON format.,to_bson} - - @sa http://bsonspec.org/spec.html - @sa see @ref from_bson(detail::input_adapter&&, const bool strict) for the - analogous deserialization - @sa see @ref to_ubjson(const basic_json&, const bool, const bool) for the - related UBJSON format - @sa see @ref to_cbor(const basic_json&) for the related CBOR format - @sa see @ref to_msgpack(const basic_json&) for the related MessagePack format - */ + /// @brief create a BSON serialization of a given JSON value + /// @sa https://json.nlohmann.me/api/basic_json/to_bson/ static std::vector to_bson(const basic_json& j) { std::vector result; @@ -25107,130 +21087,22 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } - /*! - @brief Serializes the given JSON object `j` to BSON and forwards the - corresponding BSON-representation to the given output_adapter `o`. - @param j The JSON object to convert to BSON. - @param o The output adapter that receives the binary BSON representation. - @pre The input `j` shall be an object: `j.is_object() == true` - @sa see @ref to_bson(const basic_json&) - */ + /// @brief create a BSON serialization of a given JSON value + /// @sa https://json.nlohmann.me/api/basic_json/to_bson/ static void to_bson(const basic_json& j, detail::output_adapter o) { binary_writer(o).write_bson(j); } - /*! - @copydoc to_bson(const basic_json&, detail::output_adapter) - */ + /// @brief create a BSON serialization of a given JSON value + /// @sa https://json.nlohmann.me/api/basic_json/to_bson/ static void to_bson(const basic_json& j, detail::output_adapter o) { binary_writer(o).write_bson(j); } - - /*! - @brief create a JSON value from an input in CBOR format - - Deserializes a given input @a i to a JSON value using the CBOR (Concise - Binary Object Representation) serialization format. - - The library maps CBOR types to JSON value types as follows: - - CBOR type | JSON value type | first byte - ---------------------- | --------------- | ---------- - Integer | number_unsigned | 0x00..0x17 - Unsigned integer | number_unsigned | 0x18 - Unsigned integer | number_unsigned | 0x19 - Unsigned integer | number_unsigned | 0x1A - Unsigned integer | number_unsigned | 0x1B - Negative integer | number_integer | 0x20..0x37 - Negative integer | number_integer | 0x38 - Negative integer | number_integer | 0x39 - Negative integer | number_integer | 0x3A - Negative integer | number_integer | 0x3B - Byte string | binary | 0x40..0x57 - Byte string | binary | 0x58 - Byte string | binary | 0x59 - Byte string | binary | 0x5A - Byte string | binary | 0x5B - UTF-8 string | string | 0x60..0x77 - UTF-8 string | string | 0x78 - UTF-8 string | string | 0x79 - UTF-8 string | string | 0x7A - UTF-8 string | string | 0x7B - UTF-8 string | string | 0x7F - array | array | 0x80..0x97 - array | array | 0x98 - array | array | 0x99 - array | array | 0x9A - array | array | 0x9B - array | array | 0x9F - map | object | 0xA0..0xB7 - map | object | 0xB8 - map | object | 0xB9 - map | object | 0xBA - map | object | 0xBB - map | object | 0xBF - False | `false` | 0xF4 - True | `true` | 0xF5 - Null | `null` | 0xF6 - Half-Precision Float | number_float | 0xF9 - Single-Precision Float | number_float | 0xFA - Double-Precision Float | number_float | 0xFB - - @warning The mapping is **incomplete** in the sense that not all CBOR - types can be converted to a JSON value. The following CBOR types - are not supported and will yield parse errors (parse_error.112): - - date/time (0xC0..0xC1) - - bignum (0xC2..0xC3) - - decimal fraction (0xC4) - - bigfloat (0xC5) - - expected conversions (0xD5..0xD7) - - simple values (0xE0..0xF3, 0xF8) - - undefined (0xF7) - - @warning CBOR allows map keys of any type, whereas JSON only allows - strings as keys in object values. Therefore, CBOR maps with keys - other than UTF-8 strings are rejected (parse_error.113). - - @note Any CBOR output created @ref to_cbor can be successfully parsed by - @ref from_cbor. - - @param[in] i an input in CBOR format convertible to an input adapter - @param[in] strict whether to expect the input to be consumed until EOF - (true by default) - @param[in] allow_exceptions whether to throw exceptions in case of a - parse error (optional, true by default) - @param[in] tag_handler how to treat CBOR tags (optional, error by default) - - @return deserialized JSON value; in case of a parse error and - @a allow_exceptions set to `false`, the return value will be - value_t::discarded. - - @throw parse_error.110 if the given input ends prematurely or the end of - file was not reached when @a strict was set to true - @throw parse_error.112 if unsupported features from CBOR were - used in the given input @a v or if the input is not valid CBOR - @throw parse_error.113 if a string was expected as map key, but not found - - @complexity Linear in the size of the input @a i. - - @liveexample{The example shows the deserialization of a byte vector in CBOR - format to a JSON value.,from_cbor} - - @sa http://cbor.io - @sa see @ref to_cbor(const basic_json&) for the analogous serialization - @sa see @ref from_msgpack(InputType&&, const bool, const bool) for the - related MessagePack format - @sa see @ref from_ubjson(InputType&&, const bool, const bool) for the - related UBJSON format - - @since version 2.0.9; parameter @a start_index since 2.1.1; changed to - consume input adapters, removed start_index parameter, and added - @a strict parameter since 3.0.0; added @a allow_exceptions parameter - since 3.2.0; added @a tag_handler parameter since 3.9.0. - */ + /// @brief create a JSON value from an input in CBOR format + /// @sa https://json.nlohmann.me/api/basic_json/from_cbor/ template JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_cbor(InputType&& i, @@ -25245,9 +21117,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return res ? result : basic_json(value_t::discarded); } - /*! - @copydoc from_cbor(InputType&&, const bool, const bool, const cbor_tag_handler_t) - */ + /// @brief create a JSON value from an input in CBOR format + /// @sa https://json.nlohmann.me/api/basic_json/from_cbor/ template JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_cbor(IteratorType first, IteratorType last, @@ -25289,92 +21160,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return res ? result : basic_json(value_t::discarded); } - /*! - @brief create a JSON value from an input in MessagePack format - - Deserializes a given input @a i to a JSON value using the MessagePack - serialization format. - - The library maps MessagePack types to JSON value types as follows: - - MessagePack type | JSON value type | first byte - ---------------- | --------------- | ---------- - positive fixint | number_unsigned | 0x00..0x7F - fixmap | object | 0x80..0x8F - fixarray | array | 0x90..0x9F - fixstr | string | 0xA0..0xBF - nil | `null` | 0xC0 - false | `false` | 0xC2 - true | `true` | 0xC3 - float 32 | number_float | 0xCA - float 64 | number_float | 0xCB - uint 8 | number_unsigned | 0xCC - uint 16 | number_unsigned | 0xCD - uint 32 | number_unsigned | 0xCE - uint 64 | number_unsigned | 0xCF - int 8 | number_integer | 0xD0 - int 16 | number_integer | 0xD1 - int 32 | number_integer | 0xD2 - int 64 | number_integer | 0xD3 - str 8 | string | 0xD9 - str 16 | string | 0xDA - str 32 | string | 0xDB - array 16 | array | 0xDC - array 32 | array | 0xDD - map 16 | object | 0xDE - map 32 | object | 0xDF - bin 8 | binary | 0xC4 - bin 16 | binary | 0xC5 - bin 32 | binary | 0xC6 - ext 8 | binary | 0xC7 - ext 16 | binary | 0xC8 - ext 32 | binary | 0xC9 - fixext 1 | binary | 0xD4 - fixext 2 | binary | 0xD5 - fixext 4 | binary | 0xD6 - fixext 8 | binary | 0xD7 - fixext 16 | binary | 0xD8 - negative fixint | number_integer | 0xE0-0xFF - - @note Any MessagePack output created @ref to_msgpack can be successfully - parsed by @ref from_msgpack. - - @param[in] i an input in MessagePack format convertible to an input - adapter - @param[in] strict whether to expect the input to be consumed until EOF - (true by default) - @param[in] allow_exceptions whether to throw exceptions in case of a - parse error (optional, true by default) - - @return deserialized JSON value; in case of a parse error and - @a allow_exceptions set to `false`, the return value will be - value_t::discarded. - - @throw parse_error.110 if the given input ends prematurely or the end of - file was not reached when @a strict was set to true - @throw parse_error.112 if unsupported features from MessagePack were - used in the given input @a i or if the input is not valid MessagePack - @throw parse_error.113 if a string was expected as map key, but not found - - @complexity Linear in the size of the input @a i. - - @liveexample{The example shows the deserialization of a byte vector in - MessagePack format to a JSON value.,from_msgpack} - - @sa http://msgpack.org - @sa see @ref to_msgpack(const basic_json&) for the analogous serialization - @sa see @ref from_cbor(InputType&&, const bool, const bool, const cbor_tag_handler_t) for the - related CBOR format - @sa see @ref from_ubjson(InputType&&, const bool, const bool) for - the related UBJSON format - @sa see @ref from_bson(InputType&&, const bool, const bool) for - the related BSON format - - @since version 2.0.9; parameter @a start_index since 2.1.1; changed to - consume input adapters, removed start_index parameter, and added - @a strict parameter since 3.0.0; added @a allow_exceptions parameter - since 3.2.0 - */ + /// @brief create a JSON value from an input in MessagePack format + /// @sa https://json.nlohmann.me/api/basic_json/from_msgpack/ template JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_msgpack(InputType&& i, @@ -25388,9 +21175,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return res ? result : basic_json(value_t::discarded); } - /*! - @copydoc from_msgpack(InputType&&, const bool, const bool) - */ + /// @brief create a JSON value from an input in MessagePack format + /// @sa https://json.nlohmann.me/api/basic_json/from_msgpack/ template JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_msgpack(IteratorType first, IteratorType last, @@ -25404,7 +21190,6 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return res ? result : basic_json(value_t::discarded); } - template JSON_HEDLEY_WARN_UNUSED_RESULT JSON_HEDLEY_DEPRECATED_FOR(3.8.0, from_msgpack(ptr, ptr + len)) @@ -25429,69 +21214,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return res ? result : basic_json(value_t::discarded); } - - /*! - @brief create a JSON value from an input in UBJSON format - - Deserializes a given input @a i to a JSON value using the UBJSON (Universal - Binary JSON) serialization format. - - The library maps UBJSON types to JSON value types as follows: - - UBJSON type | JSON value type | marker - ----------- | --------------------------------------- | ------ - no-op | *no value, next value is read* | `N` - null | `null` | `Z` - false | `false` | `F` - true | `true` | `T` - float32 | number_float | `d` - float64 | number_float | `D` - uint8 | number_unsigned | `U` - int8 | number_integer | `i` - int16 | number_integer | `I` - int32 | number_integer | `l` - int64 | number_integer | `L` - high-precision number | number_integer, number_unsigned, or number_float - depends on number string | 'H' - string | string | `S` - char | string | `C` - array | array (optimized values are supported) | `[` - object | object (optimized values are supported) | `{` - - @note The mapping is **complete** in the sense that any UBJSON value can - be converted to a JSON value. - - @param[in] i an input in UBJSON format convertible to an input adapter - @param[in] strict whether to expect the input to be consumed until EOF - (true by default) - @param[in] allow_exceptions whether to throw exceptions in case of a - parse error (optional, true by default) - - @return deserialized JSON value; in case of a parse error and - @a allow_exceptions set to `false`, the return value will be - value_t::discarded. - - @throw parse_error.110 if the given input ends prematurely or the end of - file was not reached when @a strict was set to true - @throw parse_error.112 if a parse error occurs - @throw parse_error.113 if a string could not be parsed successfully - - @complexity Linear in the size of the input @a i. - - @liveexample{The example shows the deserialization of a byte vector in - UBJSON format to a JSON value.,from_ubjson} - - @sa http://ubjson.org - @sa see @ref to_ubjson(const basic_json&, const bool, const bool) for the - analogous serialization - @sa see @ref from_cbor(InputType&&, const bool, const bool, const cbor_tag_handler_t) for the - related CBOR format - @sa see @ref from_msgpack(InputType&&, const bool, const bool) for - the related MessagePack format - @sa see @ref from_bson(InputType&&, const bool, const bool) for - the related BSON format - - @since version 3.1.0; added @a allow_exceptions parameter since 3.2.0 - */ + /// @brief create a JSON value from an input in UBJSON format + /// @sa https://json.nlohmann.me/api/basic_json/from_ubjson/ template JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_ubjson(InputType&& i, @@ -25505,9 +21229,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return res ? result : basic_json(value_t::discarded); } - /*! - @copydoc from_ubjson(InputType&&, const bool, const bool) - */ + /// @brief create a JSON value from an input in UBJSON format + /// @sa https://json.nlohmann.me/api/basic_json/from_ubjson/ template JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_ubjson(IteratorType first, IteratorType last, @@ -25545,67 +21268,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return res ? result : basic_json(value_t::discarded); } - - /*! - @brief Create a JSON value from an input in BSON format - - Deserializes a given input @a i to a JSON value using the BSON (Binary JSON) - serialization format. - - The library maps BSON record types to JSON value types as follows: - - BSON type | BSON marker byte | JSON value type - --------------- | ---------------- | --------------------------- - double | 0x01 | number_float - string | 0x02 | string - document | 0x03 | object - array | 0x04 | array - binary | 0x05 | binary - undefined | 0x06 | still unsupported - ObjectId | 0x07 | still unsupported - boolean | 0x08 | boolean - UTC Date-Time | 0x09 | still unsupported - null | 0x0A | null - Regular Expr. | 0x0B | still unsupported - DB Pointer | 0x0C | still unsupported - JavaScript Code | 0x0D | still unsupported - Symbol | 0x0E | still unsupported - JavaScript Code | 0x0F | still unsupported - int32 | 0x10 | number_integer - Timestamp | 0x11 | still unsupported - 128-bit decimal float | 0x13 | still unsupported - Max Key | 0x7F | still unsupported - Min Key | 0xFF | still unsupported - - @warning The mapping is **incomplete**. The unsupported mappings - are indicated in the table above. - - @param[in] i an input in BSON format convertible to an input adapter - @param[in] strict whether to expect the input to be consumed until EOF - (true by default) - @param[in] allow_exceptions whether to throw exceptions in case of a - parse error (optional, true by default) - - @return deserialized JSON value; in case of a parse error and - @a allow_exceptions set to `false`, the return value will be - value_t::discarded. - - @throw parse_error.114 if an unsupported BSON record type is encountered - - @complexity Linear in the size of the input @a i. - - @liveexample{The example shows the deserialization of a byte vector in - BSON format to a JSON value.,from_bson} - - @sa http://bsonspec.org/spec.html - @sa see @ref to_bson(const basic_json&) for the analogous serialization - @sa see @ref from_cbor(InputType&&, const bool, const bool, const cbor_tag_handler_t) for the - related CBOR format - @sa see @ref from_msgpack(InputType&&, const bool, const bool) for - the related MessagePack format - @sa see @ref from_ubjson(InputType&&, const bool, const bool) for the - related UBJSON format - */ + /// @brief create a JSON value from an input in BSON format + /// @sa https://json.nlohmann.me/api/basic_json/from_bson/ template JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_bson(InputType&& i, @@ -25619,9 +21283,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return res ? result : basic_json(value_t::discarded); } - /*! - @copydoc from_bson(InputType&&, const bool, const bool) - */ + /// @brief create a JSON value from an input in BSON format + /// @sa https://json.nlohmann.me/api/basic_json/from_bson/ template JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json from_bson(IteratorType first, IteratorType last, @@ -25667,180 +21330,36 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @name JSON Pointer functions /// @{ - /*! - @brief access specified element via JSON Pointer - - Uses a JSON pointer to retrieve a reference to the respective JSON value. - No bound checking is performed. Similar to @ref operator[](const typename - object_t::key_type&), `null` values are created in arrays and objects if - necessary. - - In particular: - - If the JSON pointer points to an object key that does not exist, it - is created an filled with a `null` value before a reference to it - is returned. - - If the JSON pointer points to an array index that does not exist, it - is created an filled with a `null` value before a reference to it - is returned. All indices between the current maximum and the given - index are also filled with `null`. - - The special value `-` is treated as a synonym for the index past the - end. - - @param[in] ptr a JSON pointer - - @return reference to the element pointed to by @a ptr - - @complexity Constant. - - @throw parse_error.106 if an array index begins with '0' - @throw parse_error.109 if an array index was not a number - @throw out_of_range.404 if the JSON pointer can not be resolved - - @liveexample{The behavior is shown in the example.,operatorjson_pointer} - - @since version 2.0.0 - */ + /// @brief access specified element via JSON Pointer + /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ reference operator[](const json_pointer& ptr) { return ptr.get_unchecked(this); } - /*! - @brief access specified element via JSON Pointer - - Uses a JSON pointer to retrieve a reference to the respective JSON value. - No bound checking is performed. The function does not change the JSON - value; no `null` values are created. In particular, the special value - `-` yields an exception. - - @param[in] ptr JSON pointer to the desired element - - @return const reference to the element pointed to by @a ptr - - @complexity Constant. - - @throw parse_error.106 if an array index begins with '0' - @throw parse_error.109 if an array index was not a number - @throw out_of_range.402 if the array index '-' is used - @throw out_of_range.404 if the JSON pointer can not be resolved - - @liveexample{The behavior is shown in the example.,operatorjson_pointer_const} - - @since version 2.0.0 - */ + /// @brief access specified element via JSON Pointer + /// @sa https://json.nlohmann.me/api/basic_json/operator%5B%5D/ const_reference operator[](const json_pointer& ptr) const { return ptr.get_unchecked(this); } - /*! - @brief access specified element via JSON Pointer - - Returns a reference to the element at with specified JSON pointer @a ptr, - with bounds checking. - - @param[in] ptr JSON pointer to the desired element - - @return reference to the element pointed to by @a ptr - - @throw parse_error.106 if an array index in the passed JSON pointer @a ptr - begins with '0'. See example below. - - @throw parse_error.109 if an array index in the passed JSON pointer @a ptr - is not a number. See example below. - - @throw out_of_range.401 if an array index in the passed JSON pointer @a ptr - is out of range. See example below. - - @throw out_of_range.402 if the array index '-' is used in the passed JSON - pointer @a ptr. As `at` provides checked access (and no elements are - implicitly inserted), the index '-' is always invalid. See example below. - - @throw out_of_range.403 if the JSON pointer describes a key of an object - which cannot be found. See example below. - - @throw out_of_range.404 if the JSON pointer @a ptr can not be resolved. - See example below. - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes in the JSON value. - - @complexity Constant. - - @since version 2.0.0 - - @liveexample{The behavior is shown in the example.,at_json_pointer} - */ + /// @brief access specified element via JSON Pointer + /// @sa https://json.nlohmann.me/api/basic_json/at/ reference at(const json_pointer& ptr) { return ptr.get_checked(this); } - /*! - @brief access specified element via JSON Pointer - - Returns a const reference to the element at with specified JSON pointer @a - ptr, with bounds checking. - - @param[in] ptr JSON pointer to the desired element - - @return reference to the element pointed to by @a ptr - - @throw parse_error.106 if an array index in the passed JSON pointer @a ptr - begins with '0'. See example below. - - @throw parse_error.109 if an array index in the passed JSON pointer @a ptr - is not a number. See example below. - - @throw out_of_range.401 if an array index in the passed JSON pointer @a ptr - is out of range. See example below. - - @throw out_of_range.402 if the array index '-' is used in the passed JSON - pointer @a ptr. As `at` provides checked access (and no elements are - implicitly inserted), the index '-' is always invalid. See example below. - - @throw out_of_range.403 if the JSON pointer describes a key of an object - which cannot be found. See example below. - - @throw out_of_range.404 if the JSON pointer @a ptr can not be resolved. - See example below. - - @exceptionsafety Strong guarantee: if an exception is thrown, there are no - changes in the JSON value. - - @complexity Constant. - - @since version 2.0.0 - - @liveexample{The behavior is shown in the example.,at_json_pointer_const} - */ + /// @brief access specified element via JSON Pointer + /// @sa https://json.nlohmann.me/api/basic_json/at/ const_reference at(const json_pointer& ptr) const { return ptr.get_checked(this); } - /*! - @brief return flattened JSON value - - The function creates a JSON object whose keys are JSON pointers (see [RFC - 6901](https://tools.ietf.org/html/rfc6901)) and whose values are all - primitive. The original JSON value can be restored using the @ref - unflatten() function. - - @return an object that maps JSON pointers to primitive values - - @note Empty objects and arrays are flattened to `null` and will not be - reconstructed correctly by the @ref unflatten() function. - - @complexity Linear in the size the JSON value. - - @liveexample{The following code shows how a JSON object is flattened to an - object whose keys consist of JSON pointers.,flatten} - - @sa see @ref unflatten() for the reverse function - - @since version 2.0.0 - */ + /// @brief return flattened JSON value + /// @sa https://json.nlohmann.me/api/basic_json/flatten/ basic_json flatten() const { basic_json result(value_t::object); @@ -25848,36 +21367,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } - /*! - @brief unflatten a previously flattened JSON value - - The function restores the arbitrary nesting of a JSON value that has been - flattened before using the @ref flatten() function. The JSON value must - meet certain constraints: - 1. The value must be an object. - 2. The keys must be JSON pointers (see - [RFC 6901](https://tools.ietf.org/html/rfc6901)) - 3. The mapped values must be primitive JSON types. - - @return the original JSON from a flattened version - - @note Empty objects and arrays are flattened by @ref flatten() to `null` - values and can not unflattened to their original type. Apart from - this example, for a JSON value `j`, the following is always true: - `j == j.flatten().unflatten()`. - - @complexity Linear in the size the JSON value. - - @throw type_error.314 if value is not an object - @throw type_error.315 if object values are not primitive - - @liveexample{The following code shows how a flattened JSON object is - unflattened into the original nested JSON object.,unflatten} - - @sa see @ref flatten() for the reverse function - - @since version 2.0.0 - */ + /// @brief unflatten a previously flattened JSON value + /// @sa https://json.nlohmann.me/api/basic_json/unflatten/ basic_json unflatten() const { return json_pointer::unflatten(*this); @@ -25892,53 +21383,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @name JSON Patch functions /// @{ - /*! - @brief applies a JSON patch - - [JSON Patch](http://jsonpatch.com) defines a JSON document structure for - expressing a sequence of operations to apply to a JSON) document. With - this function, a JSON Patch is applied to the current JSON value by - executing all operations from the patch. - - @param[in] json_patch JSON patch document - @return patched document - - @note The application of a patch is atomic: Either all operations succeed - and the patched document is returned or an exception is thrown. In - any case, the original value is not changed: the patch is applied - to a copy of the value. - - @throw parse_error.104 if the JSON patch does not consist of an array of - objects - - @throw parse_error.105 if the JSON patch is malformed (e.g., mandatory - attributes are missing); example: `"operation add must have member path"` - - @throw out_of_range.401 if an array index is out of range. - - @throw out_of_range.403 if a JSON pointer inside the patch could not be - resolved successfully in the current JSON value; example: `"key baz not - found"` - - @throw out_of_range.405 if JSON pointer has no parent ("add", "remove", - "move") - - @throw other_error.501 if "test" operation was unsuccessful - - @complexity Linear in the size of the JSON value and the length of the - JSON patch. As usually only a fraction of the JSON value is affected by - the patch, the complexity can usually be neglected. - - @liveexample{The following code shows how a JSON patch is applied to a - value.,patch} - - @sa see @ref diff -- create a JSON patch by comparing two JSON values - - @sa [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902) - @sa [RFC 6901 (JSON Pointer)](https://tools.ietf.org/html/rfc6901) - - @since version 2.0.0 - */ + /// @brief applies a JSON patch + /// @sa https://json.nlohmann.me/api/basic_json/patch/ basic_json patch(const basic_json& json_patch) const { // make a working copy to apply the patch to @@ -26211,39 +21657,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec return result; } - /*! - @brief creates a diff as a JSON patch - - Creates a [JSON Patch](http://jsonpatch.com) so that value @a source can - be changed into the value @a target by calling @ref patch function. - - @invariant For two JSON values @a source and @a target, the following code - yields always `true`: - @code {.cpp} - source.patch(diff(source, target)) == target; - @endcode - - @note Currently, only `remove`, `add`, and `replace` operations are - generated. - - @param[in] source JSON value to compare from - @param[in] target JSON value to compare against - @param[in] path helper value to create JSON pointers - - @return a JSON patch to convert the @a source to @a target - - @complexity Linear in the lengths of @a source and @a target. - - @liveexample{The following code shows how a JSON patch is created as a - diff for two JSON values.,diff} - - @sa see @ref patch -- apply a JSON patch - @sa see @ref merge_patch -- apply a JSON Merge Patch - - @sa [RFC 6902 (JSON Patch)](https://tools.ietf.org/html/rfc6902) - - @since version 2.0.0 - */ + /// @brief creates a diff as a JSON patch + /// @sa https://json.nlohmann.me/api/basic_json/diff/ JSON_HEDLEY_WARN_UNUSED_RESULT static basic_json diff(const basic_json& source, const basic_json& target, const std::string& path = "") @@ -26281,7 +21696,7 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec ++i; } - // i now reached the end of at least one array + // We now reached the end of at least one array // in a second pass, traverse the remaining elements // remove my remaining elements @@ -26386,48 +21801,8 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @name JSON Merge Patch functions /// @{ - /*! - @brief applies a JSON Merge Patch - - The merge patch format is primarily intended for use with the HTTP PATCH - method as a means of describing a set of modifications to a target - resource's content. This function applies a merge patch to the current - JSON value. - - The function implements the following algorithm from Section 2 of - [RFC 7396 (JSON Merge Patch)](https://tools.ietf.org/html/rfc7396): - - ``` - define MergePatch(Target, Patch): - if Patch is an Object: - if Target is not an Object: - Target = {} // Ignore the contents and set it to an empty Object - for each Name/Value pair in Patch: - if Value is null: - if Name exists in Target: - remove the Name/Value pair from Target - else: - Target[Name] = MergePatch(Target[Name], Value) - return Target - else: - return Patch - ``` - - Thereby, `Target` is the current object; that is, the patch is applied to - the current value. - - @param[in] apply_patch the patch to apply - - @complexity Linear in the lengths of @a patch. - - @liveexample{The following code shows how a JSON Merge Patch is applied to - a JSON document.,merge_patch} - - @sa see @ref patch -- apply a JSON patch - @sa [RFC 7396 (JSON Merge Patch)](https://tools.ietf.org/html/rfc7396) - - @since version 3.0.0 - */ + /// @brief applies a JSON Merge Patch + /// @sa https://json.nlohmann.me/api/basic_json/merge_patch/ void merge_patch(const basic_json& apply_patch) { if (apply_patch.is_object()) @@ -26457,50 +21832,37 @@ class basic_json // NOLINT(cppcoreguidelines-special-member-functions,hicpp-spec /// @} }; -/*! -@brief user-defined to_string function for JSON values - -This function implements a user-defined to_string for JSON objects. - -@param[in] j a JSON object -@return a std::string object -*/ - +/// @brief user-defined to_string function for JSON values +/// @sa https://json.nlohmann.me/api/basic_json/to_string/ NLOHMANN_BASIC_JSON_TPL_DECLARATION std::string to_string(const NLOHMANN_BASIC_JSON_TPL& j) { return j.dump(); } + } // namespace nlohmann /////////////////////// // nonmember support // /////////////////////// -// specialization of std::swap, and std::hash -namespace std +namespace std // NOLINT(cert-dcl58-cpp) { -/// hash value for JSON objects -template<> -struct hash +/// @brief hash value for JSON objects +/// @sa https://json.nlohmann.me/api/basic_json/std_hash/ +NLOHMANN_BASIC_JSON_TPL_DECLARATION +struct hash { - /*! - @brief return a hash value for a JSON object - - @since version 1.0.0 - */ - std::size_t operator()(const nlohmann::json& j) const + std::size_t operator()(const nlohmann::NLOHMANN_BASIC_JSON_TPL& j) const { return nlohmann::detail::hash(j); } }; -/// specialization for std::less -/// @note: do not remove the space after '<', -/// see https://github.com/nlohmann/json/pull/679 +// specialization for std::less template<> -struct less<::nlohmann::detail::value_t> +struct less< ::nlohmann::detail::value_t> // do not remove the space after '<', see https://github.com/nlohmann/json/pull/679 { /*! @brief compare two value_t enum values @@ -26516,16 +21878,12 @@ struct less<::nlohmann::detail::value_t> // C++20 prohibit function specialization in the std namespace. #ifndef JSON_HAS_CPP_20 -/*! -@brief exchanges the values of two JSON objects - -@since version 1.0.0 -*/ -template<> -inline void swap(nlohmann::json& j1, nlohmann::json& j2) noexcept( // NOLINT(readability-inconsistent-declaration-parameter-name) - is_nothrow_move_constructible::value&& // NOLINT(misc-redundant-expression) - is_nothrow_move_assignable::value - ) +/// @brief exchanges the values of two JSON objects +/// @sa https://json.nlohmann.me/api/basic_json/std_swap/ +NLOHMANN_BASIC_JSON_TPL_DECLARATION +inline void swap(nlohmann::NLOHMANN_BASIC_JSON_TPL& j1, nlohmann::NLOHMANN_BASIC_JSON_TPL& j2) noexcept( // NOLINT(readability-inconsistent-declaration-parameter-name) + is_nothrow_move_constructible::value&& // NOLINT(misc-redundant-expression) + is_nothrow_move_assignable::value) { j1.swap(j2); } @@ -26534,38 +21892,16 @@ inline void swap(nlohmann::json& j1, nlohmann::json& j2) noexcep } // namespace std -/*! -@brief user-defined string literal for JSON values - -This operator implements a user-defined string literal for JSON objects. It -can be used by adding `"_json"` to a string literal and returns a JSON object -if no parse error occurred. - -@param[in] s a string representation of a JSON object -@param[in] n the length of string @a s -@return a JSON object - -@since version 1.0.0 -*/ +/// @brief user-defined string literal for JSON values +/// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json/ JSON_HEDLEY_NON_NULL(1) inline nlohmann::json operator "" _json(const char* s, std::size_t n) { return nlohmann::json::parse(s, s + n); } -/*! -@brief user-defined string literal for JSON pointer - -This operator implements a user-defined string literal for JSON Pointers. It -can be used by adding `"_json_pointer"` to a string literal and returns a JSON pointer -object if no parse error occurred. - -@param[in] s a string representation of a JSON Pointer -@param[in] n the length of string @a s -@return a JSON pointer object - -@since version 2.0.0 -*/ +/// @brief user-defined string literal for JSON pointer +/// @sa https://json.nlohmann.me/api/basic_json/operator_literal_json_pointer/ JSON_HEDLEY_NON_NULL(1) inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std::size_t n) { @@ -26591,6 +21927,8 @@ inline nlohmann::json::json_pointer operator "" _json_pointer(const char* s, std #undef JSON_HAS_CPP_14 #undef JSON_HAS_CPP_17 #undef JSON_HAS_CPP_20 +#undef JSON_HAS_FILESYSTEM +#undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #undef NLOHMANN_BASIC_JSON_TPL_DECLARATION #undef NLOHMANN_BASIC_JSON_TPL #undef JSON_EXPLICIT From cf17d229628cc2fa71755e0521855c9fa9c92068 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Sun, 17 Apr 2022 23:32:47 +0200 Subject: [PATCH 127/477] reduce number of newlines to exactly 1 (#424) in test for dependency generator --- test/test_depgen.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/test_depgen.sh b/test/test_depgen.sh index 8b780036e9..82474b3c79 100755 --- a/test/test_depgen.sh +++ b/test/test_depgen.sh @@ -25,8 +25,8 @@ run_depgens() { rm -f ${OUTPUT}.1 ${OUTPUT}.2 - $cmd1 $file | awk "${awk_join_lines}" | sed 's/ */ /g' > ${OUTPUT}.1 - $cmd2 $file | awk "${awk_join_lines}" | sed 's/ */ /g' > ${OUTPUT}.2 + $cmd1 $file | awk "${awk_join_lines}" | sed 's/ \+/ /g' | sed '/^$/d;G' > ${OUTPUT}.1 + $cmd2 $file | awk "${awk_join_lines}" | sed 's/ \+/ /g' | sed '/^$/d;G' > ${OUTPUT}.2 diff=$(diff -u ${OUTPUT}.1 ${OUTPUT}.2) From 108e7ca88f5ae0b5f78eb6c10cb996e4b110e80d Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Tue, 19 Apr 2022 10:26:20 +0200 Subject: [PATCH 128/477] various unrelated changes from an unmerged PR --- test/test_MSSM_2L_analytic.m | 18 ++++++++++++++-- test/test_SM_npointfunctions.cpp.in | 4 ++-- test/test_SM_tree_level_spectrum.cpp | 2 +- test/test_pv.cpp | 8 +++---- test/test_pv_crosschecks.cpp | 32 ++++++++++++++++------------ 5 files changed, 41 insertions(+), 23 deletions(-) diff --git a/test/test_MSSM_2L_analytic.m b/test/test_MSSM_2L_analytic.m index 45344d14d4..448f54e9aa 100644 --- a/test/test_MSSM_2L_analytic.m +++ b/test/test_MSSM_2L_analytic.m @@ -74,7 +74,7 @@ ]; CalculatePointNumerical[point_] := - Module[{progr, exec}, + Module[{progr, exec, fortComp}, progr = " #include #include @@ -129,6 +129,16 @@ int main(){ return 0; } "; + fortComp = + Select[ + StringSplit@Import[File["flexiblesusy-config"]], + StringMatchQ[#, "fc=" ~~ __] & + ]; + If[Length[fortComp]===1, + fortComp = Last@StringSplit[First@fortComp, "="], + Print["Could not identify a Fortran compiler"]; Quit[1]; + ]; + fortComp = StringReplace[fortComp, "\"" -> ""]; exec = CreateExecutable[ progr, "exec", "CompileOptions" -> StringJoin[Riffle[ @@ -137,7 +147,11 @@ int main(){ " "]], "Libraries" -> {FileNameJoin[{Directory[], "model_specific", "MSSM_higgs", "libmodel_specific_MSSM_higgs.a"}], FileNameJoin[{Directory[], "src", "libflexisusy.a"}], - "gfortran"} + Switch[fortComp, + "gfortran", "gfortran", + "ifort", "imf", + _, Print["Unknown Fortran compiler " <> fortComp]; Quit[1] + ]} (* , "ShellOutputFunction"->Print, "ShellCommandFunction"->Print *) ]; If[exec === $Failed, diff --git a/test/test_SM_npointfunctions.cpp.in b/test/test_SM_npointfunctions.cpp.in index 4f888db307..45e28df47f 100644 --- a/test/test_SM_npointfunctions.cpp.in +++ b/test/test_SM_npointfunctions.cpp.in @@ -65,7 +65,7 @@ BOOST_DATA_TEST_CASE( test_selfenergies, random_SM_dataset( number_of_random_samples ), index, FS_TEST_SM_PARAMETER_SEQUENCE ) { - Loop_library::set(0); + Loop_library::set(-1); auto input_parameters = wrap_SM_parameters( FS_TEST_SM_PARAMETER_SEQUENCE ); auto model = calculate_spectrum( input_parameters ); @@ -75,7 +75,7 @@ BOOST_DATA_TEST_CASE( test_selfenergies, "There was an error calculating the spectrum: " << problems << "Skipping data point..." ); - if( problems.have_problem() == false ) + if (!problems.have_problem()) { auto fs_selfenergy_hh = model.self_energy_hh_1loop( 0 ); auto np_selfenergy_hh = diff --git a/test/test_SM_tree_level_spectrum.cpp b/test/test_SM_tree_level_spectrum.cpp index a60b6d1b7d..b36dbfad59 100644 --- a/test/test_SM_tree_level_spectrum.cpp +++ b/test/test_SM_tree_level_spectrum.cpp @@ -65,7 +65,7 @@ BOOST_AUTO_TEST_CASE( test_SM_tree_level_masses ) m.calculate_DRbar_masses(); sm.calculate_DRbar_masses(); - const double eps = 1e-15; + static constexpr double eps = 1e-15; CHECK_CLOSE_1(MVP, eps); CHECK_CLOSE_1(MVG, eps); diff --git a/test/test_pv.cpp b/test/test_pv.cpp index eafe6792f7..40d36b7d4a 100644 --- a/test/test_pv.cpp +++ b/test/test_pv.cpp @@ -96,10 +96,10 @@ BOOST_AUTO_TEST_CASE(test_real_parts) BOOST_CHECK_CLOSE_FRACTION(ReB00(2,3,4, 1), -0.24981786818504056, 1e-14); } -const double scale = 100; -const double scale2 = Sqr(scale); -const double p = 91.0; -const double p2 = Sqr(p); +static constexpr double scale = 100; +static constexpr double scale2 = Sqr(scale); +static constexpr double p = 91.0; +static constexpr double p2 = Sqr(p); BOOST_AUTO_TEST_CASE( test_ReA0 ) { diff --git a/test/test_pv_crosschecks.cpp b/test/test_pv_crosschecks.cpp index 9ea9793cc0..5cab0fc950 100644 --- a/test/test_pv_crosschecks.cpp +++ b/test/test_pv_crosschecks.cpp @@ -205,12 +205,15 @@ void check_close_fraction(T a, T b, double tol, double scl=1); template<> void check_close_fraction(double a, double b, double tol, double scl) { - if (a == 0) - BOOST_CHECK_SMALL(b / scl, tol); - else if (b == 0) - BOOST_CHECK_SMALL(a / scl, tol); - else - BOOST_CHECK_CLOSE_FRACTION(a, b, tol); + if (a == 0) { + BOOST_CHECK_SMALL(b / scl, tol); + } + else if (b == 0) { + BOOST_CHECK_SMALL(a / scl, tol); + } + else { + BOOST_CHECK_CLOSE_FRACTION(a, b, tol); + } } template<> @@ -234,8 +237,9 @@ bool check_point(map*>& funcs, string& line, double tol) if (f == funcs.end()) return false; vector args(f->second->nargs); - for (size_t i = 0; i < args.size(); i++) - if (!(ls >> args[i])) return false; + for (size_t i = 0; i < args.size(); i++) { + if (!(ls >> args[i])) return false; + } double s2; U value_from_line; if (!(ls >> s2 >> value_from_line)) return false; @@ -253,7 +257,7 @@ bool check_point(map*>& funcs, string& line, double tol) BOOST_AUTO_TEST_CASE(fflite_generate_points) { cout << scientific << setprecision(17); - const size_t n = 10000; + static constexpr size_t n = 10000; generate_points, complex >(ccfuncs, n); generate_points< double , complex >(rcfuncs, n); generate_points< double , double >(rrfuncs, n); @@ -263,11 +267,11 @@ BOOST_AUTO_TEST_CASE(fflite_generate_points) BOOST_AUTO_TEST_CASE(looptools_check_points) { - string line; - while (getline(cin, line)) - check_point(rrfuncs, line, 1e-15) || - check_point(rcfuncs, line, 1e-15) || - check_point(ccfuncs, line, 1e-15); + string line; + while (getline(cin, line)) + check_point(rrfuncs, line, 1e-15) || + check_point(rcfuncs, line, 1e-15) || + check_point(ccfuncs, line, 1e-15); } #else From 1a9908b1256fa31c3c7aa13d60c9c6e679bbcdc8 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 21 Apr 2022 15:32:39 +0200 Subject: [PATCH 129/477] replace StringJoin @ Riffle with StringRiffle --- meta/AMuon.m | 2 +- meta/BetaFunction.m | 2 +- meta/BrLToLGamma.m | 4 ++-- meta/CXXDiagrams.m | 30 +++++++++++++++--------------- meta/Decays.m | 22 +++++++++++----------- meta/EDM.m | 6 +++--- meta/FFVFormFactors.m | 6 +++--- meta/FSMathLink.m | 2 +- meta/FlexibleSUSY.m | 4 ++-- meta/NPointFunctions.m | 6 +++--- meta/References.m | 2 +- meta/Utils.m | 2 +- 12 files changed, 44 insertions(+), 44 deletions(-) diff --git a/meta/AMuon.m b/meta/AMuon.m index 4845f1ace8..a6b218eaf7 100644 --- a/meta/AMuon.m +++ b/meta/AMuon.m @@ -138,7 +138,7 @@ If[susyParticles === {}, "return 0.;", "return Min(" <> - StringJoin[Riffle[GetMinMass /@ susyParticles, ", "]] <> + StringRiffle[GetMinMass /@ susyParticles, ", "] <> ");" ] ]; diff --git a/meta/BetaFunction.m b/meta/BetaFunction.m index fec302e30f..bd1c796bba 100644 --- a/meta/BetaFunction.m +++ b/meta/BetaFunction.m @@ -184,7 +184,7 @@ ]; result = StringJoin[result] <> "\n" <> target <> " = " <> - StringJoin[Riffle[MapIndexed[(target <> "_" <> ToString[#2[[1]]])&, splitExpr], " + "]] <> + StringRiffle[MapIndexed[(target <> "_" <> ToString[#2[[1]]])&, splitExpr], " + "] <> ";\n"; , result = target <> " = " <> CastTo[RValueToCFormString[expr], type] <> ";\n"; diff --git a/meta/BrLToLGamma.m b/meta/BrLToLGamma.m index c7f52a318d..b7387da865 100644 --- a/meta/BrLToLGamma.m +++ b/meta/BrLToLGamma.m @@ -71,7 +71,7 @@ StringJoin @ Table[", 0", {numberOfIndices1-1}], ""] <> " ", If[numberOfIndices1 =!= 0, - StringJoin @ Riffle[Table[" 0", {numberOfIndices1}], ","] <> " ", + StringRiffle[Table[" 0", {numberOfIndices1}], ","] <> " ", ""] ] <> "};\n" <> "std::array ToString @ numberOfIndices2 <> @@ -82,7 +82,7 @@ StringJoin @ Table[", 0", {numberOfIndices2-1}], ""] <> " ", If[numberOfIndices2 =!= 0, - StringJoin @ Riffle[Table[" 0", {numberOfIndices2}], ","] <> " ", + StringRiffle[Table[" 0", {numberOfIndices2}], ","] <> " ", ""] ] <> "};\n\n" <> "const auto form_factors = calculate_" <> CXXNameOfField[inFermion] <> "_" diff --git a/meta/CXXDiagrams.m b/meta/CXXDiagrams.m index e884fd3e43..c2f45c57e6 100644 --- a/meta/CXXDiagrams.m +++ b/meta/CXXDiagrams.m @@ -178,9 +178,9 @@ * \returns the name of the c++ type corresponding to a * given vertex. **) -CXXNameOfVertex[fields_List] := "Vertex<" <> StringJoin[Riffle[ +CXXNameOfVertex[fields_List] := "Vertex<" <> StringRiffle[ CXXNameOfField[#, prefixNamespace -> "fields"] & /@ fields, - ", "]] <> ">" + ", "] <> ">" (** \brief Returns the appropriate c++ typename to conjugate a * given field as it would be used by ``SARAH`AntiField[]``. @@ -264,7 +264,7 @@ vectors = Select[fields, TreeMasses`IsVector]; ghosts = Select[fields, TreeMasses`IsGhost]; - StringJoin @ Riffle[ + StringRiffle[ ("struct " <> CXXNameOfField[#] <> " {\n" <> TextFormatting`IndentText[ "static constexpr auto particle_type = ParticleType::" <> ParticleTypeAsString[#] <> ";\n" <> @@ -283,7 +283,7 @@ "using sm_flags = boost::mpl::vector_c If[TreeMasses`GetDimension[#] === 1, CConversion`CreateCBoolValue @ TreeMasses`IsSMParticle[#], - StringJoin @ Riffle[CConversion`CreateCBoolValue /@ + StringRiffle[CConversion`CreateCBoolValue /@ TreeMasses`IsSMParticleElementwise[#], ", "] ] <> ">;\n" <> @@ -300,20 +300,20 @@ "using Electron = " <> CXXNameOfField[AtomHead @ TreeMasses`GetSMElectronLepton[]] <> ";\n\n" <> "// Fields that are their own Lorentz conjugates.\n" <> - StringJoin @ Riffle[ + StringRiffle[ ("template<> struct " <> LorentzConjugateOperation[#] <> "<" <> CXXNameOfField[#] <> ">" <> " { using type = " <> CXXNameOfField[#] <> "; };" &) /@ Select[fields, (# == LorentzConjugate[#] &)], "\n"] <> "\n\n" <> "using scalars = boost::mpl::vector<" <> - StringJoin[Riffle[CXXNameOfField /@ scalars, ", "]] <> ">;\n" <> + StringRiffle[CXXNameOfField /@ scalars, ", "] <> ">;\n" <> "using fermions = boost::mpl::vector<" <> - StringJoin[Riffle[CXXNameOfField /@ fermions, ", "]] <> ">;\n" <> + StringRiffle[CXXNameOfField /@ fermions, ", "] <> ">;\n" <> "using vectors = boost::mpl::vector<" <> - StringJoin[Riffle[CXXNameOfField /@ vectors, ", "]] <> ">;\n" <> + StringRiffle[CXXNameOfField /@ vectors, ", "] <> ">;\n" <> "using ghosts = boost::mpl::vector<" <> - StringJoin[Riffle[CXXNameOfField /@ ghosts, ", "]] <> ">;" + StringRiffle[CXXNameOfField /@ ghosts, ", "] <> ">;" ] (** \brief Get the lorentz index of a given indexed field @@ -1265,7 +1265,7 @@ Utils`AssertOrQuit[Sort[cxxVertices] === Sort[Join@@vertexPartition],CreateVertices::errLostVertices]; - Map[StringJoin[Riffle[#, "\n\n"]] &, Transpose /@ vertexPartition, {2}] + Map[StringRiffle[#, "\n\n"] &, Transpose /@ vertexPartition, {2}] ] /; Utils`AssertOrQuit[And[IntegerQ@OptionValue@MaximumVerticesLimit, OptionValue@MaximumVerticesLimit>0],CreateVertices::errMaximumVerticesLimit]; Utils`MakeUnknownInputDefinition@CreateVertices; (** \brief Creates c++ code that makes a function available that @@ -1276,7 +1276,7 @@ **) CreateVertex[fields_List] := Module[{fieldSequence}, - fieldSequence = StringJoin @ Riffle[ + fieldSequence = StringRiffle[ CXXNameOfField[#, prefixNamespace -> "fields"] & /@ fields, ", "]; { @@ -1514,7 +1514,7 @@ ghostMappings = SelfEnergies`ReplaceGhosts[FlexibleSUSY`FSEigenstates]}, massiveFields = TreeMasses`GetParticles[]; - StringJoin @ Riffle[ + StringRiffle[ Module[{fieldInfo = TreeMasses`FieldInfo[#], numberOfIndices}, numberOfIndices = Length @ fieldInfo[[5]]; @@ -1537,7 +1537,7 @@ ghostMappings = SelfEnergies`ReplaceGhosts[FlexibleSUSY`FSEigenstates]}, massiveFields = TreeMasses`GetParticles[]; - StringJoin @ Riffle[ + StringRiffle[ Module[{fieldInfo = TreeMasses`FieldInfo[#], numberOfIndices}, numberOfIndices = Length @ fieldInfo[[5]]; @@ -1575,7 +1575,7 @@ StringJoin @ Table[", 0", {numberOfElectronIndices-1}], ""] <> " ", If[numberOfElectronIndices =!= 0, - StringJoin @ Riffle[Table[" 0", {numberOfElectronIndices}], ","] <> " ", + StringRiffle[Table[" 0", {numberOfElectronIndices}], ","] <> " ", ""] ] <> "};\n") <> @@ -1587,7 +1587,7 @@ StringJoin @ Table[", 0", {numberOfPhotonIndices-1}], ""] <> " ", If[numberOfPhotonIndices =!= 0, - StringJoin @ Riffle[Table[" 0", {numberOfPhotonIndices}], ","] <> " ", + StringRiffle[Table[" 0", {numberOfPhotonIndices}], ","] <> " ", ""] ] <> "};\n") <> diff --git a/meta/Decays.m b/meta/Decays.m index 96dd88a9bf..e25983002d 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -273,12 +273,12 @@ Join[bsmForZdecay, bsmForWdecay], "// List of potential Z boson decay products excluding pure SM decays\n" <> "typedef boost::mpl::list<\n" <> - TextFormatting`IndentText@StringJoin@Riffle[ + TextFormatting`IndentText@StringRiffle[ ("boost::mpl::list<" <> CXXDiagrams`CXXNameOfField[#1, prefixNamespace -> namespace] <> ", " <> CXXDiagrams`CXXNameOfField[#2, prefixNamespace -> namespace] <> ">")& @@@ (Drop[#, {1}]& /@ bsmForZdecay), ",\n" ] <> If[Length@bsmForZdecay > 0, "\n", ""] <> "> BSMForZdecay;\n\n" <> "// List of potential W boson decay products excluding pure SM decays\n" <> "typedef boost::mpl::list<\n" <> - TextFormatting`IndentText@StringJoin@Riffle[ + TextFormatting`IndentText@StringRiffle[ ("boost::mpl::list<" <> CXXDiagrams`CXXNameOfField[#1, prefixNamespace -> namespace] <> ", " <> CXXDiagrams`CXXNameOfField[#2, prefixNamespace -> namespace] <> ">")& @@@ (Drop[#, {1}]& /@ bsmForWdecay), ",\n" ] <> If[Length@bsmForWdecay > 0, "\n", ""] <> "> BSMForWdecay;" } @@ -842,7 +842,7 @@ would violate Ward identity (as at the level of dim 4 CheckOffShellDecay[TreeMasses`GetHiggsBoson[], TreeMasses`GetWBoson[]] || CheckOffShellDecay[TreeMasses`GetHiggsBoson[], TreeMasses`GetZBoson[]], "", "if (context.physical_mass<" <> CXXNameOfField[initialState] <> ">(std::array If[initialStateDim > 1, "1", "0"] <> ">{" <> If[initialStateDim > 1, "gI1", ""] <> "}) < " <> - StringJoin @ Riffle[ + StringRiffle[ MapIndexed[ With[{idx = First[#2]}, "context.physical_mass<" <> CXXNameOfField[#1] <> ">(" <> @@ -856,7 +856,7 @@ would violate Ward identity (as at the level of dim 4 body = "decays.set_decay(" <> CreatePartialWidthCalculationName[decay] <> "(" <> functionArgs <> "), " <> pdgsList <> ", create_process_string<" <> CXXNameOfField[initialState] <> ", " <> StringRiffle[CXXNameOfField/@finalState, ", "] <> ">(" <> If[initialStateDim > 1, "{gI1}", "{}"] <> "," <> - StringJoin @ Riffle[ + StringRiffle[ MapIndexed[ With[{idx = First[#2]}, If[finalStateDims[[idx]] > 1, "{gO" <> ToString[idx] <> "}", "{}"] @@ -882,7 +882,7 @@ would violate Ward identity (as at the level of dim 4 "\nif (context.physical_mass<" <> CXXNameOfField[initialState] <> ">(std::array If[initialStateDim > 1, "1", "0"] <> ">{" <> If[initialStateDim > 1, "gI1", ""] <> "}) > " <> - StringJoin @ Riffle[ + StringRiffle[ MapIndexed[ With[{idx = First[#2]}, "context.physical_mass<" <> CXXNameOfField[#1] <> ">(" <> @@ -1693,7 +1693,7 @@ would violate Ward identity (as at the level of dim 4 verticesForFACp2 = If[Length[#] == 2, List@@Last@#, List@@#]& /@ verticesForFACp2; cppVertices = "using vertex" <> ToString@#1 <> " = Vertex<" <> - (StringJoin@Riffle[CXXDiagrams`CXXNameOfField /@ #2 ,", "] <> ">;\n")& @@@ Transpose[{indices, verticesForFACp2}]; + (StringRiffle[CXXDiagrams`CXXNameOfField /@ #2 ,", "] <> ">;\n")& @@@ Transpose[{indices, verticesForFACp2}]; (* List of {integer, integer} -> Field[integer] *) externalEdges = @@ -1795,7 +1795,7 @@ would violate Ward identity (as at the level of dim 4 "vertex" <> # <> "::evaluate(index" <> # <> ", context);\n" )& /@ indices] <> - "\nif (" <> StringJoin@Riffle[("!vertex" <> # <> "Val.isZero()")& /@ indices, " && "] <> ") {\n" <> + "\nif (" <> StringRiffle[("!vertex" <> # <> "Val.isZero()")& /@ indices, " && "] <> ") {\n" <> TextFormatting`IndentText[ "// internal masses\n" <> mass <> "\n" <> @@ -1810,7 +1810,7 @@ would violate Ward identity (as at the level of dim 4 "if (static_cast(flexibledecay_settings.get(FlexibleDecay_settings::include_higher_order_corrections)) > 0 &&\n" <> TextFormatting`IndentText[ Module[{pos1, pos2}, - StringJoin@Riffle[ + StringRiffle[ MapIndexed[ (pos1 = Position[#1, First@fieldsInLoop, 1]; pos2 = Position[#1, SARAH`bar[First@fieldsInLoop], 1]; @@ -1835,7 +1835,7 @@ would violate Ward identity (as at the level of dim 4 "\nif (static_cast(flexibledecay_settings.get(FlexibleDecay_settings::include_higher_order_corrections)) > 0 &&\n" <> TextFormatting`IndentText[ Module[{pos1, pos2}, - StringJoin@Riffle[ + StringRiffle[ MapIndexed[ (pos1 = Position[#1, First@fieldsInLoop, 1]; pos2 = Position[#1, Susyno`LieGroups`conj[First@fieldsInLoop], 1]; @@ -1875,7 +1875,7 @@ would violate Ward identity (as at the level of dim 4 "if (static_cast(flexibledecay_settings.get(FlexibleDecay_settings::include_higher_order_corrections)) > 0 &&\n" <> TextFormatting`IndentText[ Module[{pos1, pos2}, - StringJoin@Riffle[ + StringRiffle[ MapIndexed[ (pos1 = Position[#1, First@fieldsInLoop, 1]; pos2 = Position[#1, SARAH`bar[First@fieldsInLoop], 1]; @@ -1910,7 +1910,7 @@ would violate Ward identity (as at the level of dim 4 (* diagram information *) "\n// topology " <> FeynArtsTopologyName[topology] <> - "\n// internal particles in the diagram: " <> StringJoin[Riffle[ToString@Part[#, 2]& /@Drop[fieldAssociation, 3], ", "]] <> "\n" <> + "\n// internal particles in the diagram: " <> StringRiffle[ToString@Part[#, 2]& /@Drop[fieldAssociation, 3], ", "] <> "\n" <> "{\n" <> TextFormatting`IndentText[ diff --git a/meta/EDM.m b/meta/EDM.m index 94a2a851d4..e51f2b1258 100644 --- a/meta/EDM.m +++ b/meta/EDM.m @@ -93,7 +93,7 @@ StringJoin @ Table[", 0", {numberOfIndices-1}], ""] <> " ", If[numberOfIndices =!= 0, - StringJoin @ Riffle[Table[" 0", {numberOfIndices}], ","] <> " ", + StringRiffle[Table[" 0", {numberOfIndices}], ","] <> " ", ""] ] <> "};\n\n" <> @@ -101,8 +101,8 @@ "using namespace " <> FlexibleSUSY`FSModelName <> "_cxx_diagrams::fields;\n\n" <> - StringJoin @ Riffle[Module[{graph = #[[1]], diagrams = #[[2]]}, - StringJoin @ Riffle[Module[{diagram = #, indexedDiagram}, + StringRiffle[Module[{graph = #[[1]], diagrams = #[[2]]}, + StringRiffle[Module[{diagram = #, indexedDiagram}, indexedDiagram = CXXDiagrams`IndexDiagramFromGraph[diagram, graph]; "val += " <> diff --git a/meta/FFVFormFactors.m b/meta/FFVFormFactors.m index a1aed37a4a..62d7100bde 100644 --- a/meta/FFVFormFactors.m +++ b/meta/FFVFormFactors.m @@ -149,7 +149,7 @@ StringJoin @ Table[", 0", {numberOfIndices1-1}], ""] <> " ", If[numberOfIndices1 =!= 0, - StringJoin @ Riffle[Table[" 0", {numberOfIndices1}], ", "], + StringRiffle[Table[" 0", {numberOfIndices1}], ", "], ""] ] <> "};\n" <> "std::array ToString @ numberOfIndices2 <> @@ -160,7 +160,7 @@ StringJoin @ Table[", 0", {numberOfIndices2-1}], ""] <> " ", If[numberOfIndices2 =!= 0, - StringJoin @ Riffle[Table[" 0", {numberOfIndices2}], ", "] <> " ", + StringRiffle[Table[" 0", {numberOfIndices2}], ", "] <> " ", ""] ] <> "};\n\n" <> @@ -180,7 +180,7 @@ "val += std::complex " <> ToString @ N @ ReIm @ CXXDiagrams`ExtractColourFactor @ CXXDiagrams`ColorFactorForDiagram[topology, diagram] <> " * FFV_" <> StringJoin @@ (ToString /@ SARAH`getType /@ {EmitterL[diagram], EmitterR[diagram], Spectator[diagram]}) <> "<" <> - StringJoin @ Riffle[CXXDiagrams`CXXNameOfField /@ {Fj, Fi, V, EmitterL[diagram], EmitterR[diagram], Spectator[diagram]}, ","] <> + StringRiffle[CXXDiagrams`CXXNameOfField /@ {Fj, Fi, V, EmitterL[diagram], EmitterR[diagram], Spectator[diagram]}, ","] <> ">::value(indices1, indices2, context, discard_SM_contributions);\n"; End[]; diff --git a/meta/FSMathLink.m b/meta/FSMathLink.m index b3ac960d03..6201b6a06c 100644 --- a/meta/FSMathLink.m +++ b/meta/FSMathLink.m @@ -202,7 +202,7 @@ HeadToStr[sym_] := "\"" <> ToString[sym] <> "\""; HeadsToStr[{}] := ""; -HeadsToStr[l_List] := ", {" <> StringJoin[Riffle[HeadToStr /@ l, ", "]] <> "}"; +HeadsToStr[l_List] := ", {" <> StringRiffle[HeadToStr /@ l, ", "] <> "}"; PutObservable[FlexibleSUSYObservable`BrLToLGamma[p1_[idx1_Integer]->{p2_[idx2_Integer], V_}], type_, link_String, heads_:{}] /; V === TreeMasses`GetPhoton[] := " MLPutFunction(link, \"Rule\", 2); diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index 6e5451fc79..ba3d366335 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -2307,7 +2307,7 @@ corresponding tadpole is real or imaginary (only in models with CP "@CXXDiagrams_PhysicalMassFunctions@" -> physicalMassFunctions, "@defineFieldTraits@" -> defineFieldTraits, "@CXXDiagrams_VertexPrototypes@" -> - StringJoin[Riffle[cxxVerticesParts[[All, 1]], "\n\n"]], + StringRiffle[cxxVerticesParts[[All, 1]], "\n\n"], Sequence @@ GeneralReplacementRules[] }]; @@ -2325,7 +2325,7 @@ corresponding tadpole is real or imaginary (only in models with CP }] & /@ Transpose[{cxxQFTVerticesFiles, cxxVerticesParts}]; WriteOut`ReplaceInFiles[cxxQFTVerticesMakefileTemplates, {"@generatedCXXVerticesFiles@" -> - "\t" <> StringJoin[Riffle[cxxQFTVerticesFiles[[All, 2]], " \\\n\t"]], + "\t" <> StringRiffle[cxxQFTVerticesFiles[[All, 2]], " \\\n\t"], Sequence @@ GeneralReplacementRules[] }]; ]; diff --git a/meta/NPointFunctions.m b/meta/NPointFunctions.m index 1ff71008e7..b26fd5cbdd 100644 --- a/meta/NPointFunctions.m +++ b/meta/NPointFunctions.m @@ -689,7 +689,7 @@ Cases[{opts},Rule[OnShellFlag,x_]:> aoq[x===True || x===False,NPointFunction::errOnShellFlag]]; Cases[{opts},Rule[KeepProcesses,x_]:> - aoq[And@@Map[MemberQ[allProcesses~Append~Null,#]&,If[Head@x===List,x,{x}]],NPointFunction::errKeepProcesses,StringJoin@Riffle[ToString/@allProcesses,",\n "]]]; + aoq[And@@Map[MemberQ[allProcesses~Append~Null,#]&,If[Head@x===List,x,{x}]],NPointFunction::errKeepProcesses,StringRiffle[ToString/@allProcesses,",\n "]]]; True ]; internalNPointFunctionInputCheck // Utils`MakeUnknownInputDefinition; @@ -1778,9 +1778,9 @@ means that one can simply remove them (as well as corresponding It works only for [{___String},_String] input."; StringRiffle::err="`1`"; StringRiffle[strs:{___String},sep_String] := - StringJoin@Riffle[strs,sep]; + StringRiffle[strs,sep]; StringRiffle[strs:{___String},{in_String,sep_String,fin_String}] := - in<>StringJoin@Riffle[strs,sep]<>fin; + in<>StringRiffle[strs,sep]<>fin; StringRiffle[x___] := Utils`AssertOrQuit[False,StringRiffle::err,{x}]; diff --git a/meta/References.m b/meta/References.m index 8184a0261a..f85f3d9873 100644 --- a/meta/References.m +++ b/meta/References.m @@ -38,7 +38,7 @@ CreateCitation[{}] := ""; CreateCitation[refs_List] := - "\\cite{" <> StringJoin[Riffle[refs, ","]] <> "}"; + "\\cite{" <> StringRiffle[refs, ","] <> "}"; CreateCitation[] := CreateCitation[fsreferences]; diff --git a/meta/Utils.m b/meta/Utils.m index ad70bcae8b..2194480fed 100644 --- a/meta/Utils.m +++ b/meta/Utils.m @@ -193,7 +193,7 @@ occurrence of the given rule is replaced (if it exists) or added (if SetAttributes[ApplyAndConcatenate, HoldFirst]; StringJoinWithSeparator[list_List, separator_String, transformer_:ToString] := - StringJoin[Riffle[transformer /@ list, separator]]; + StringRiffle[transformer /@ list, separator]; Zip[list1_List, list2_List] := MapThread[List, {list1, list2}]; From 9c40e67d673e8a929e7aaebbb491f19628cbdacd Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sun, 24 Apr 2022 12:13:18 +0200 Subject: [PATCH 130/477] added new GM2Calc reference --- README.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.rst b/README.rst index 2c046eeabd..4b2d1f5668 100644 --- a/README.rst +++ b/README.rst @@ -37,7 +37,7 @@ modification, extension and reuse. [1910.03595]_. If you use **FlexibleSUSY+GM2Calc** in your work, please cite - [1510.08071]_. + [1510.08071]_ and (if appropriate) [2110.13238]_. If you use **FlexibleDecay** in your work, please cite [2106.05038]_. @@ -1039,3 +1039,4 @@ References .. [1807.03509] `Eur. Phys. J. C78 (2018) no. 10, 874 `_ [`arxiv:1807.03509 `_] .. [1910.03595] `Eur. Phys. J. C80 (2020) no. 3, 186 `_ [`arxiv:1910.03595 `_] .. [2106.05038] [`arxiv:2106.05038 `_] +.. [2110.13238] `Eur. Phys. J. C82 (2022) no. 3, 229 `_ [`arxiv:2110.13238 `_] From 823b78263a946dfa22802163d0c53ab3903255a3 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Fri, 29 Apr 2022 15:17:16 +0200 Subject: [PATCH 131/477] version 2.6.2 --- CHANGES.rst | 33 +++++++++++++++++++++++---------- configure | 2 +- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 973ab84ee5..db55844416 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,10 +1,11 @@ -FlexibleSUSY 2.6.2 [February, ? 2022] -================================== +FlexibleSUSY 2.6.2 [April, 29 2022] +====================================== New features -------- +------------ * Parallelized calculation of decay amplitudes during the mathematica phase. + Example speedup: .. list-table:: @@ -24,16 +25,28 @@ New features Changes ------- -* [commit ae1eae8e4d373eec531d6e5774977da2f12e88c8]: Mathematica-style indexing (starting from 1) of - leptons in `$L' \to L \gamma$` via the mathlink interface. +* [commit ae1eae8e4d]: Mathematica-style indexing (starting from 1) of + leptons in :math:`$L' \to L \gamma$` via the mathlink interface. Fixed bugs ---------- -* [commit 26f5262ad3a8936ae6297305d2ee92a71b17da09]: Branching ratio of `$L' \to L \gamma$` was breaking printing of - observables via the mathlink interface. +* [commit 26f5262ad3]: Branching ratio of :math:`$L' \to L \gamma$` + was breaking printing of observables via the mathlink interface. + +* [commit fd8d59dda8]: Fixed wrong calculation of :math:`$A \to Z \gamma$`. + +* [commit b82d0d2123]: Set SSV decay amplitude to zero if vector boson + is massless. + +* [commit 768c092dff]: Handle colour deltas in models where there are + fundamental (i.e. unconjugated) fields in 3 and -3 representations. + +* [commit 102ae79f0f]: Temporarily enforce calculation of pole masses + in ``FSFindRoot`` and ``FSMinimize``. -* [commit fd8d59dda8fc90182fdfb2255189326341dd8f57]: Fixed wrong calculation of `$A \to Z \gamma$`. +* [commit d16a9b68f1]: Use user-provided precision goal in + ``FSFindRoot`` and ``FSMinimize``. FlexibleSUSY 2.6.1 [July, 08 2021] ================================== @@ -43,8 +56,8 @@ Changes * Removed code computing Higgs effective couplings. This code has been superseded by FlexibleDecay. -* FlexibleDecay: 2-loop QCD corrections to `$\Phi \to \Gamma Z$` applied - only if `$m_Z/m_\Phi < 0.75$`. +* FlexibleDecay: 2-loop QCD corrections to :math:`$\Phi \to \Gamma Z$` applied + only if :math:`$m_Z/m_\Phi < 0.75$`. Fixed bugs ---------- diff --git a/configure b/configure index 34729d1ae0..5d13c2fed8 100755 --- a/configure +++ b/configure @@ -6,7 +6,7 @@ PROGRAM_NAME=FlexibleSUSY FLEXIBLESUSY_MAJOR=2 FLEXIBLESUSY_MINOR=6 -FLEXIBLESUSY_PATCH=1 +FLEXIBLESUSY_PATCH=2 FLEXIBLESUSY_EXTRA="" FLEXIBLESUSY_VERSION="${FLEXIBLESUSY_MAJOR}.${FLEXIBLESUSY_MINOR}.${FLEXIBLESUSY_PATCH}${FLEXIBLESUSY_EXTRA}" GIT_COMMIT=$(git rev-parse HEAD 2> /dev/null || echo unknown) From 004747a3f943306b9e8e92f7446bc34cff4ba8db Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 29 Apr 2022 13:19:17 +0000 Subject: [PATCH 132/477] Bump actions/checkout from 2 to 3 Bumps [actions/checkout](https://github.com/actions/checkout) from 2 to 3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](https://github.com/actions/checkout/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/checkout dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/package-models.yml | 8 ++++---- .github/workflows/static-analysis.yml | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.github/workflows/package-models.yml b/.github/workflows/package-models.yml index 7bf0919e05..85b933c0f9 100644 --- a/.github/workflows/package-models.yml +++ b/.github/workflows/package-models.yml @@ -24,7 +24,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Activate Wolfram Engine env: @@ -80,7 +80,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: repository: FlexibleSUSY/FlexibleSUSY-generated token: ${{ secrets.PAT }} @@ -114,7 +114,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 with: repository: FlexibleSUSY/FlexibleSUSY-slha token: ${{ secrets.PAT }} @@ -148,7 +148,7 @@ jobs: steps: - name: Checkout code - uses: actions/checkout@v2 + uses: actions/checkout@v3 - uses: actions/download-artifact@v2 with: diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 6df43cc93b..935e247964 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -30,7 +30,7 @@ jobs: steps: - name: Checkout - uses: actions/checkout@v2 + uses: actions/checkout@v3 - name: Check scripts run: | From e82102916d91656501d33e77ae2d6d5897e63baa Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 29 Apr 2022 13:19:27 +0000 Subject: [PATCH 133/477] Bump actions/upload-artifact from 2 to 3 Bumps [actions/upload-artifact](https://github.com/actions/upload-artifact) from 2 to 3. - [Release notes](https://github.com/actions/upload-artifact/releases) - [Commits](https://github.com/actions/upload-artifact/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/upload-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/package-models.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/package-models.yml b/.github/workflows/package-models.yml index 85b933c0f9..12b08e11e7 100644 --- a/.github/workflows/package-models.yml +++ b/.github/workflows/package-models.yml @@ -62,13 +62,13 @@ jobs: ./release/generate-slha-output.sh --directory=release/${FS_TAG}-slha - name: Upload artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: models-artifacts_${{ matrix.part }} path: ${{ github.workspace }}/release/${{ env.FS_TAG }} - name: Upload artifacts - uses: actions/upload-artifact@v2 + uses: actions/upload-artifact@v3 with: name: slha-output-artifacts_${{ matrix.part }} path: ${{ github.workspace }}/release/${{ env.FS_TAG }}-slha From 2fa37b662dadcc069451e50391d91d50291f8563 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 29 Apr 2022 13:19:22 +0000 Subject: [PATCH 134/477] Bump actions/download-artifact from 2 to 3 Bumps [actions/download-artifact](https://github.com/actions/download-artifact) from 2 to 3. - [Release notes](https://github.com/actions/download-artifact/releases) - [Commits](https://github.com/actions/download-artifact/compare/v2...v3) --- updated-dependencies: - dependency-name: actions/download-artifact dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .github/workflows/package-models.yml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/package-models.yml b/.github/workflows/package-models.yml index 12b08e11e7..f96d64ce87 100644 --- a/.github/workflows/package-models.yml +++ b/.github/workflows/package-models.yml @@ -85,12 +85,12 @@ jobs: repository: FlexibleSUSY/FlexibleSUSY-generated token: ${{ secrets.PAT }} - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: models-artifacts_1 path: /tmp/models-artifacts - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: models-artifacts_2 path: /tmp/models-artifacts @@ -119,12 +119,12 @@ jobs: repository: FlexibleSUSY/FlexibleSUSY-slha token: ${{ secrets.PAT }} - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: slha-output-artifacts_1 path: /tmp/slha-output-artifacts - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: slha-output-artifacts_2 path: /tmp/slha-output-artifacts @@ -150,12 +150,12 @@ jobs: - name: Checkout code uses: actions/checkout@v3 - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: models-artifacts_1 path: /tmp/models-artifacts - - uses: actions/download-artifact@v2 + - uses: actions/download-artifact@v3 with: name: models-artifacts_2 path: /tmp/models-artifacts From e16cffe4ea006491ab3378aea023980c27fb896a Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Sat, 7 May 2022 17:38:20 +0200 Subject: [PATCH 135/477] implementation of real Li3(x) and Li4(x) from the polylogarithm package 6.12.0 --- src/Li4.cpp | 158 ++++++++++++++++++++++++++++++++++++++++++++--- src/Li4.hpp | 3 + src/trilog.cpp | 130 ++++++++++++++++++++++++++++++++++---- src/trilog.hpp | 3 + src/wrappers.cpp | 8 +++ 5 files changed, 279 insertions(+), 23 deletions(-) diff --git a/src/Li4.cpp b/src/Li4.cpp index 1bdacd4305..75b43eacaa 100644 --- a/src/Li4.cpp +++ b/src/Li4.cpp @@ -32,12 +32,153 @@ namespace { return Complex(z.re*a + b, z.im*a); } + /// Li_4(x) for x in [-1,0] + double li4_neg(double x) noexcept + { + const double cp[] = { + 0.9999999999999999952e+0, -1.8532099956062184217e+0, + 1.1937642574034898249e+0, -3.1817912243893560382e-1, + 3.2268284189261624841e-2, -8.3773570305913850724e-4 + }; + const double cq[] = { + 1.0000000000000000000e+0, -1.9157099956062165688e+0, + 1.3011504531166486419e+0, -3.7975653506939627186e-1, + 4.5822723996558783670e-2, -1.8023912938765272341e-3, + 1.0199621542882314929e-5 + }; + + const double x2 = x*x; + const double x4 = x2*x2; + const double p = cp[0] + x*cp[1] + x2*(cp[2] + x*cp[3]) + + x4*(cp[4] + x*cp[5]); + const double q = cq[0] + x*cq[1] + x2*(cq[2] + x*cq[3]) + + x4*(cq[4] + x*cq[5] + x2*cq[6]); + + return x*p/q; + } + + /// Li_4(x) for x in [0,1/2] + double li4_half(double x) noexcept + { + const double cp[] = { + 1.0000000000000000414e+0, -2.0588072418045364525e+0, + 1.4713328756794826579e+0, -4.2608608613069811474e-1, + 4.2975084278851543150e-2, -6.8314031819918920802e-4 + }; + const double cq[] = { + 1.0000000000000000000e+0, -2.1213072418045207223e+0, + 1.5915688992789175941e+0, -5.0327641401677265813e-1, + 6.1467217495127095177e-2, -1.9061294280193280330e-3 + }; + + const double x2 = x*x; + const double x4 = x2*x2; + const double p = cp[0] + x*cp[1] + x2*(cp[2] + x*cp[3]) + + x4*(cp[4] + x*cp[5]); + const double q = cq[0] + x*cq[1] + x2*(cq[2] + x*cq[3]) + + x4*(cq[4] + x*cq[5]); + + return x*p/q; + } + + /// Li_4(x) for x in [1/2,8/10] + double li4_mid(double x) noexcept + { + const double cp[] = { + 3.2009826406098890447e-9, 9.9999994634837574160e-1, + -2.9144851228299341318e+0, 3.1891031447462342009e+0, + -1.6009125158511117090e+0, 3.5397747039432351193e-1, + -2.5230024124741454735e-2 + }; + const double cq[] = { + 1.0000000000000000000e+0, -2.9769855248411488460e+0, + 3.3628208295110572579e+0, -1.7782471949702788393e+0, + 4.3364007973198649921e-1, -3.9535592340362510549e-2, + 5.7373431535336755591e-4 + }; + + const double x2 = x*x; + const double x4 = x2*x2; + const double p = cp[0] + x*cp[1] + x2*(cp[2] + x*cp[3]) + + x4*(cp[4] + x*cp[5] + x2*cp[6]); + const double q = cq[0] + x*cq[1] + x2*(cq[2] + x*cq[3]) + + x4*(cq[4] + x*cq[5] + x2*cq[6]); + + return p/q; + } + + /// Li_4(x) for x in [8/10,1] + double li4_one(double x) noexcept + { + const double zeta2 = 1.6449340668482264; + const double zeta3 = 1.2020569031595943; + const double zeta4 = 1.0823232337111382; + const double l = std::log(x); + const double l2 = l*l; + + return zeta4 + + l*(zeta3 + + l*(0.5*zeta2 + + l*(11.0/36 - 1.0/6*std::log(std::abs(l)) + + l*(-1.0/48 + + l*(-1.0/1440 + + l2*(1.0/604800 - 1.0/91445760*l2)))))); + } + } // anonymous namespace /** - * @brief Complex polylogarithm \f$\mathrm{Li}_4(z)\f$ + * @brief Real 4-th order polylogarithm \f$\operatorname{Li}_4(x)\f$ + * @param x real argument + * @return \f$\operatorname{Li}_4(x)\f$ + * @author Alexander Voigt + */ +double Li4(double x) noexcept +{ + const double zeta2 = 1.6449340668482264; + const double zeta4 = 1.0823232337111382; + + double app = 0, rest = 0, sgn = 1; + + // transform x to [-1,1] + if (x < -1) { + const double l = std::log(-x); + const double l2 = l*l; + x = 1/x; + rest = -7.0/4*zeta4 + l2*(-0.5*zeta2 - 1.0/24*l2); + sgn = -1; + } else if (x == -1) { + return -7.0/8*zeta4; + } else if (x < 1) { + rest = 0; + sgn = 1; + } else if (x == 1) { + return zeta4; + } else { // x > 1 + const double l = std::log(x); + const double l2 = l*l; + x = 1/x; + rest = 2*zeta4 + l2*(zeta2 - 1.0/24*l2); + sgn = -1; + }; + + if (x < 0) { + app = li4_neg(x); + } else if (x < 0.5) { + app = li4_half(x); + } else if (x < 0.8) { + app = li4_mid(x); + } else { // x <= 1 + app = li4_one(x); + }; + + return rest + sgn*app; +} + +/** + * @brief Complex polylogarithm \f$\operatorname{Li}_4(z)\f$ * @param z_ complex argument - * @return \f$\mathrm{Li}_4(z)\f$ + * @return \f$\operatorname{Li}_4(z)\f$ * @author Alexander Voigt */ std::complex Li4(const std::complex& z_) noexcept @@ -61,14 +202,11 @@ std::complex Li4(const std::complex& z_) noexcept const Complex z = { std::real(z_), std::imag(z_) }; if (z.im == 0) { - if (z.re == 0) { - return 0.0; - } - if (z.re == 1) { - return zeta4; - } - if (z.re == -1) { - return -7.0*PI4/720.0; + if (z.re <= 1) { + return Li4(z.re); + } else { + const double l = std::log(z.re); + return std::complex(Li4(z.re), -1.0/6*PI*l*l*l); } } diff --git a/src/Li4.hpp b/src/Li4.hpp index cd936cfcaa..95857e3ad8 100644 --- a/src/Li4.hpp +++ b/src/Li4.hpp @@ -23,6 +23,9 @@ namespace flexiblesusy { +/// real polylogarithm with n=4 +double Li4(double) noexcept; + /// complex polylogarithm with n=4 std::complex Li4(const std::complex&) noexcept; diff --git a/src/trilog.cpp b/src/trilog.cpp index ac74c0d1c2..b290c59ec8 100644 --- a/src/trilog.cpp +++ b/src/trilog.cpp @@ -43,12 +43,122 @@ namespace { return Complex(z.re*a + b, z.im*a); } + /// Li_3(x) for x in [-1,0] + double li3_neg(double x) noexcept + { + const double cp[] = { + 0.9999999999999999795e+0, -2.0281801754117129576e+0, + 1.4364029887561718540e+0, -4.2240680435713030268e-1, + 4.7296746450884096877e-2, -1.3453536579918419568e-3 + }; + const double cq[] = { + 1.0000000000000000000e+0, -2.1531801754117049035e+0, + 1.6685134736461140517e+0, -5.6684857464584544310e-1, + 8.1999463370623961084e-2, -4.0756048502924149389e-3, + 3.4316398489103212699e-5 + }; + + const double x2 = x*x; + const double x4 = x2*x2; + const double p = cp[0] + x*cp[1] + x2*(cp[2] + x*cp[3]) + + x4*(cp[4] + x*cp[5]); + const double q = cq[0] + x*cq[1] + x2*(cq[2] + x*cq[3]) + + x4*(cq[4] + x*cq[5] + x2*cq[6]); + + return x*p/q; + } + + /// Li_3(x) for x in [0,1/2] + double li3_pos(double x) noexcept + { + const double cp[] = { + 0.9999999999999999893e+0, -2.5224717303769789628e+0, + 2.3204919140887894133e+0, -9.3980973288965037869e-1, + 1.5728950200990509052e-1, -7.5485193983677071129e-3 + }; + const double cq[] = { + 1.0000000000000000000e+0, -2.6474717303769836244e+0, + 2.6143888433492184741e+0, -1.1841788297857667038e+0, + 2.4184938524793651120e-1, -1.8220900115898156346e-2, + 2.4927971540017376759e-4 + }; + + const double x2 = x*x; + const double x4 = x2*x2; + const double p = cp[0] + x*cp[1] + x2*(cp[2] + x*cp[3]) + + x4*(cp[4] + x*cp[5]); + const double q = cq[0] + x*cq[1] + x2*(cq[2] + x*cq[3]) + + x4*(cq[4] + x*cq[5] + x2*cq[6]); + + return x*p/q; + } + } // anonymous namespace /** - * @brief Complex trilogarithm \f$\mathrm{Li}_3(z)\f$ + * @brief Real trilogarithm \f$\operatorname{Li}_3(x)\f$ + * @param x real argument + * @return \f$\operatorname{Li}_3(x)\f$ + * @author Alexander Voigt + */ +double trilog(double x) noexcept +{ + const double zeta2 = 1.6449340668482264; + const double zeta3 = 1.2020569031595943; + double neg = 0, pos = 0, sgn = 0, rest = 0; + + // transformation to [-1,0] and [0,1/2] + if (x < -1) { + const double l = std::log(-x); + neg = li3_neg(1/x); + pos = 0; + sgn = 1; + rest = -l*(zeta2 + 1.0/6*l*l); + } else if (x == -1) { + return -0.75*zeta3; + } else if (x < 0) { + neg = li3_neg(x); + pos = 0; + sgn = 1; + rest = 0; + } else if (x == 0) { + return 0; + } else if (x < 0.5) { + neg = 0; + pos = li3_pos(x); + sgn = 1; + rest = 0; + } else if (x == 0.5) { + return 0.53721319360804020; + } else if (x < 1) { + const double l = std::log(x); + neg = li3_neg((x - 1)/x); + pos = li3_pos(1 - x); + sgn = -1; + rest = zeta3 + l*(zeta2 + l*(-0.5*std::log(1 - x) + 1.0/6*l)); + } else if (x == 1) { + return zeta3; + } else if (x < 2) { + const double l = std::log(x); + neg = li3_neg(1 - x); + pos = li3_pos((x - 1)/x); + sgn = -1; + rest = zeta3 + l*(zeta2 + l*(-0.5*std::log(x - 1) + 1.0/6*l)); + } else { // x >= 2.0 + const double l = std::log(x); + neg = 0; + pos = li3_pos(1/x); + sgn = 1; + rest = l*(2*zeta2 - 1.0/6*l*l); + } + + return rest + sgn*(neg + pos); +} + +/** + * @brief Complex trilogarithm \f$\operatorname{Li}_3(z)\f$ * @param z_ complex argument - * @return \f$\mathrm{Li}_3(z)\f$ + * @return \f$\operatorname{Li}_3(z)\f$ * @author Alexander Voigt */ std::complex trilog(const std::complex& z_) noexcept @@ -71,17 +181,11 @@ std::complex trilog(const std::complex& z_) noexcept const Complex z = { std::real(z_), std::imag(z_) }; if (z.im == 0) { - if (z.re == 0) { - return 0.0; - } - if (z.re == 1) { - return zeta3; - } - if (z.re == -1) { - return -0.75*zeta3; - } - if (z.re == 0.5) { - return 0.53721319360804020; + if (z.re <= 1) { + return trilog(z.re); + } else { + const double l = std::log(z.re); + return std::complex(trilog(z.re), -0.5*PI*l*l); } } diff --git a/src/trilog.hpp b/src/trilog.hpp index e6b3eabc6a..d4948916ed 100644 --- a/src/trilog.hpp +++ b/src/trilog.hpp @@ -23,6 +23,9 @@ namespace flexiblesusy { +/// real trilogarithm +double trilog(double) noexcept; + /// complex trilogarithm std::complex trilog(const std::complex&) noexcept; diff --git a/src/wrappers.cpp b/src/wrappers.cpp index 32523f5392..aeab25138a 100644 --- a/src/wrappers.cpp +++ b/src/wrappers.cpp @@ -143,6 +143,14 @@ double MaxRelDiff(const std::complex& a, const std::complex& b) double PolyLog(int n, double z) noexcept { + switch (n) { + case 1: return -std::log(1.0 - z); + case 2: return dilog(z); + case 3: return trilog(z); + case 4: return Li4(z); + default: break; + } + return std::real(PolyLog(n, std::complex(z, 0.0))); } From 5384e3d3b6e25c790e0bb43b84ca27e7f83b841b Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Thu, 12 May 2022 13:38:07 +0200 Subject: [PATCH 136/477] Implement all polylogarithms (#435) * rename dilog -> Li2, trilog -> Li3 * move Clausen function Cl2 to separate file * adding general polylogarithm implementation from the polylogarithm package 6.12.0 --- meta/Format.m | 8 +- meta/MSSM/Mh2_3loop_DR_SQCD_to_cpp.m | 4 +- meta/MSSM/as2_to_cpp.m | 22 +- meta/MSSM/bquark_to_cpp.m | 24 +- meta/MSSM/tau_to_cpp.m | 24 +- meta/MSSM/tquark_to_cpp.m | 4 +- .../MSSM_higgs/mssm_twoloophiggs.cpp | 12 +- .../MSSM_thresholds/mssm_twoloop_as.cpp | 22 +- .../MSSM_thresholds/mssm_twoloop_mb.cpp | 24 +- .../MSSM_thresholds/mssm_twoloop_mt.cpp | 4 +- .../MSSM_thresholds/mssm_twoloop_mtau.cpp | 24 +- src/Cl2.cpp | 222 ++++++++++++++ src/Cl2.hpp | 32 +++ src/Li.cpp | 232 +++++++++++++++ src/Li.hpp | 20 ++ src/{dilog.cpp => Li2.cpp} | 216 +------------- src/{dilog.hpp => Li2.hpp} | 22 +- src/{trilog.cpp => Li3.cpp} | 12 +- src/{trilog.hpp => Li3.hpp} | 10 +- src/Li5.cpp | 261 +++++++++++++++++ src/Li5.hpp | 22 ++ src/Li6.cpp | 272 ++++++++++++++++++ src/Li6.hpp | 22 ++ src/decays/decay_functions.cpp | 22 +- src/eta.cpp | 102 +++++++ src/eta.hpp | 19 ++ src/factorial.cpp | 91 ++++++ src/factorial.hpp | 19 ++ src/harmonic.cpp | 70 +++++ src/harmonic.hpp | 19 ++ src/module.mk | 30 +- src/threshold_loop_functions.cpp | 17 +- src/wrappers.cpp | 21 +- src/zeta.cpp | 106 +++++++ src/zeta.hpp | 19 ++ templates/a_muon.cpp.in | 10 +- templates/decays/decays.cpp.in | 4 +- test/SOFTSUSY/numerics_legacy.cpp | 6 +- test/test_threshold_loop_functions.cpp | 22 +- 39 files changed, 1686 insertions(+), 406 deletions(-) create mode 100644 src/Cl2.cpp create mode 100644 src/Cl2.hpp create mode 100644 src/Li.cpp create mode 100644 src/Li.hpp rename src/{dilog.cpp => Li2.cpp} (63%) rename src/{dilog.hpp => Li2.hpp} (69%) rename src/{trilog.cpp => Li3.cpp} (97%) rename src/{trilog.hpp => Li3.hpp} (82%) create mode 100644 src/Li5.cpp create mode 100644 src/Li5.hpp create mode 100644 src/Li6.cpp create mode 100644 src/Li6.hpp create mode 100644 src/eta.cpp create mode 100644 src/eta.hpp create mode 100644 src/factorial.cpp create mode 100644 src/factorial.hpp create mode 100644 src/harmonic.cpp create mode 100644 src/harmonic.hpp create mode 100644 src/zeta.cpp create mode 100644 src/zeta.hpp diff --git a/meta/Format.m b/meta/Format.m index 640a78d852..0877c9ab39 100644 --- a/meta/Format.m +++ b/meta/Format.m @@ -412,7 +412,7 @@ useful when assigning large arrays in ANSI C (default values dexp::usage="The symbol dexp is used in the test for ANSI compatible functions in FortranAssign."; diff::usage="The symbol diff is used to format D in MapleAssign."; -dilog::usage="The symbol dilog is used to format PolyLog in MapleAssign."; +Li2::usage="The symbol Li2 is used to format PolyLog in MapleAssign."; dim::usage="The symbol dim is used in the test for ANSI compatible functions in FortranAssign."; dint::usage="The symbol dint is used in the test for ANSI compatible @@ -582,7 +582,7 @@ useful when assigning large arrays in ANSI C (default values amod,and,anint,arccos,arccosh,arccot,arccoth,arccsc,arccsch,arcsec,arcsech,arcsin, arcsinh,arctan,arctanh,asin,asinh,atan,atan2,atanh,bernoulli,Bi,binomial,cabs, ccos,ceil,cexp,char,Ci,clog,cmplx,collect,conjg,cos,cosh,cot,coth,csc,csch,csin, -csqrt,dabs,dacos,dasin,datan,datan2,dble,dcos,dcosh,ddim,denom,dexp,dilog,dim, +csqrt,dabs,dacos,dasin,datan,datan2,dble,dcos,dcosh,ddim,denom,dexp,Li2,dim, dint,dlog,dlog10,dmax1,dmin1,dmod,dnint,dprod,dsign,dsin,dsinh,dsqrt,dtan,dtanh, Ei,erf,erfc,euler,evalf,exp,expand,factor,factorial,false,float,fsolve,GAMMA,iabs, ichar,idim,idint,idnint,ifix,index,infinity,int,isign,len,lge,lgt,lle,llt,log,log10,lnGAMMA, @@ -1268,7 +1268,7 @@ useful when assigning large arrays in ANSI C (default values MD[Length]=nops; MD[Log]=log; MD[LogGamma]=lnGAMMA; MD[Map]=map; MD[Max]=max; MD[Min]=min; MD[Mod]=mod; MD[N]=evalf; MD[NIntegrate]=int; MD[NSolve]=fsolve; MD[Not]=not; MD[Null]=NULL; MD[Numerator]=num; MD[Or]=or; MD[Part]=op; MD[PolyGamma]=Psi; - MD[PolyLog]=dilog; MD[Product]=product; MD[Replace]=subs; MD[ReplaceAll]=subs; + MD[PolyLog]=Li2; MD[Product]=product; MD[Replace]=subs; MD[ReplaceAll]=subs; MD[Roots]=RootOf; MD[Round]=round; MD[Sec]=sec; MD[Sech]=sech; MD[Series]=series; MD[Sign]=sign; MD[Simplify]=simplify; MD[Sin]=sin; MD[Sinh]=sinh; MD[SinIntegral]=Si; MD[Solve]=solve; MD[Sqrt]=sqrt; MD[Sum]=sum; @@ -1798,7 +1798,7 @@ useful when assigning large arrays in ANSI C (default values amod,and,anint,arccos,arccosh,arccot,arccoth,arccsc,arccsch,arcsec,arcsech,arcsin, arcsinh,arctan,arctanh,asin,asinh,atan,atan2,atanh,bernoulli,Bi,binomial,cabs, ccos,ceil,cexp,char,Ci,clog,cmplx,collect,conjg,cos,cosh,cot,coth,csc,csch,csin, -csqrt,dabs,dacos,dasin,datan,datan2,dble,dcos,dcosh,ddim,denom,dexp,dilog,dim, +csqrt,dabs,dacos,dasin,datan,datan2,dble,dcos,dcosh,ddim,denom,dexp,Li2,dim, dint,dlog,dlog10,dmax1,dmin1,dmod,dnint,dprod,dsign,dsin,dsinh,dsqrt,dtan,dtanh, Ei,erf,erfc,euler,evalf,exp,expand,factor,factorial,false,float,fsolve,GAMMA,iabs, ichar,idim,idint,idnint,ifix,index,infinity,int,isign,len,lge,lgt,lle,llt,log,log10,lnGAMMA, diff --git a/meta/MSSM/Mh2_3loop_DR_SQCD_to_cpp.m b/meta/MSSM/Mh2_3loop_DR_SQCD_to_cpp.m index 4854a803e8..d2578f1415 100644 --- a/meta/MSSM/Mh2_3loop_DR_SQCD_to_cpp.m +++ b/meta/MSSM/Mh2_3loop_DR_SQCD_to_cpp.m @@ -58,7 +58,7 @@ Power[x_,-5] :> 1/Symbol["pow" <> ToString[5]][x], Power[x_,-6] :> 1/Symbol["pow" <> ToString[6]][x], Log[x_] :> log[x], - PolyLog[2,x_] :> dilog[x], + PolyLog[2,x_] :> Li2[x], PolyLog[4,1/2] -> N[PolyLog[4,1/2]] }; @@ -70,7 +70,7 @@ Inactive -> Identity; impl = "\ -#include \"dilog.hpp\" +#include \"Li2.hpp\" #include #include diff --git a/meta/MSSM/as2_to_cpp.m b/meta/MSSM/as2_to_cpp.m index 81a448b191..80a7f0e139 100644 --- a/meta/MSSM/as2_to_cpp.m +++ b/meta/MSSM/as2_to_cpp.m @@ -238,11 +238,11 @@ // with the script \"as2_to_cpp.m\". #include \"" <> headerName <> "\" -#include \"dilog.hpp\" +#include \"Cl2.hpp\" +#include \"Li2.hpp\" #include #include #include -#include #include #include @@ -298,14 +298,6 @@ Real LambdaSquared(Real x, Real y) noexcept return power2(1 - x - y) - 4*x*y; } - /// ClausenCl[2,x] - Real ClausenCl2(Real x) noexcept - { - const std::complex img(0.0l, 1.0l); - - return std::imag(dilog(std::exp(img*x))); - } - /// x < 1 && y < 1, LambdaSquared(x,y) > 0 Real PhiPos(Real x, Real y) noexcept { @@ -313,8 +305,8 @@ Real PhiPos(Real x, Real y) noexcept return (-(std::log(x)*std::log(y)) + 2*std::log((1 - lambda + x - y)/2)*std::log((1 - lambda - x + y)/2) - - 2*dilog((1 - lambda + x - y)/2) - - 2*dilog((1 - lambda - x + y)/2) + - 2*Li2((1 - lambda + x - y)/2) + - 2*Li2((1 - lambda - x + y)/2) + power2(Pi)/3)/lambda; } @@ -323,9 +315,9 @@ Real PhiNeg(Real x, Real y) noexcept { const Real lambda = std::sqrt(-LambdaSquared(x,y)); - return 2*(+ ClausenCl2(2*std::acos((1 + x - y)/(2*std::sqrt(x)))) - + ClausenCl2(2*std::acos((1 - x + y)/(2*std::sqrt(y)))) - + ClausenCl2(2*std::acos((-1 + x + y)/(2*std::sqrt(x*y)))))/lambda; + return 2*(+ Cl2(2*std::acos((1 + x - y)/(2*std::sqrt(x)))) + + Cl2(2*std::acos((1 - x + y)/(2*std::sqrt(y)))) + + Cl2(2*std::acos((-1 + x + y)/(2*std::sqrt(x*y)))))/lambda; } Real Phi(Real x, Real y) noexcept diff --git a/meta/MSSM/bquark_to_cpp.m b/meta/MSSM/bquark_to_cpp.m index 0021c927d1..079b4bcc24 100644 --- a/meta/MSSM/bquark_to_cpp.m +++ b/meta/MSSM/bquark_to_cpp.m @@ -154,11 +154,11 @@ // with the script \"bquark_to_cpp.m\". #include \"" <> headerName <> "\" -#include \"dilog.hpp\" +#include \"Cl2.hpp\" +#include \"Li2.hpp\" #include #include #include -#include #include namespace flexiblesusy { @@ -205,7 +205,7 @@ bool is_equal(T a, T b, T prec = std::numeric_limits::epsilon()) noexcept return (6*(mm1*log1u + mm2*log2u) + (-mm1 - mm2)*(7 + pow2(Pi)/6) + - (mm1 - mm2)*(2*dilog(1 - mm1/mm2) + + (mm1 - mm2)*(2*Li2(1 - mm1/mm2) + pow2(log12)/2) + ((mm1 + mm2)*pow2(log12))/2 - 2*(mm1*pow2(log1u) + mm2*pow2(log2u)))/2; @@ -216,14 +216,6 @@ bool is_equal(T a, T b, T prec = std::numeric_limits::epsilon()) noexcept return pow2(1 - x - y) - 4*x*y; } - /// ClausenCl[2,x] - double ClausenCl2(double x) noexcept - { - const std::complex img(0.0, 1.0); - - return std::imag(dilog(std::exp(img*x))); - } - /// x < 1 && y < 1, LambdaSquared(x,y) > 0 double PhiPos(double x, double y) noexcept { @@ -231,8 +223,8 @@ bool is_equal(T a, T b, T prec = std::numeric_limits::epsilon()) noexcept return (-(std::log(x)*std::log(y)) + 2*std::log((1 - lambda + x - y)/2)*std::log((1 - lambda - x + y)/2) - - 2*dilog((1 - lambda + x - y)/2) - - 2*dilog((1 - lambda - x + y)/2) + - 2*Li2((1 - lambda + x - y)/2) + - 2*Li2((1 - lambda - x + y)/2) + pow2(Pi)/3)/lambda; } @@ -241,9 +233,9 @@ bool is_equal(T a, T b, T prec = std::numeric_limits::epsilon()) noexcept { const double lambda = std::sqrt(-LambdaSquared(x,y)); - return 2*(+ ClausenCl2(2*std::acos((1 + x - y)/(2*std::sqrt(x)))) - + ClausenCl2(2*std::acos((1 - x + y)/(2*std::sqrt(y)))) - + ClausenCl2(2*std::acos((-1 + x + y)/(2*std::sqrt(x*y)))))/lambda; + return 2*(+ Cl2(2*std::acos((1 + x - y)/(2*std::sqrt(x)))) + + Cl2(2*std::acos((1 - x + y)/(2*std::sqrt(y)))) + + Cl2(2*std::acos((-1 + x + y)/(2*std::sqrt(x*y)))))/lambda; } double Phi(double x, double y) noexcept diff --git a/meta/MSSM/tau_to_cpp.m b/meta/MSSM/tau_to_cpp.m index a4386acc26..5ad8053aeb 100644 --- a/meta/MSSM/tau_to_cpp.m +++ b/meta/MSSM/tau_to_cpp.m @@ -204,11 +204,11 @@ // with the script \"tau_to_cpp.m\". #include \"" <> headerName <> "\" -#include \"dilog.hpp\" +#include \"Cl2.hpp\" +#include \"Li2.hpp\" #include #include #include -#include #include #include @@ -276,7 +276,7 @@ bool is_equal_rel(T a, T b, T prec = std::numeric_limits::epsilon()) return (6*(mm1*log1u + mm2*log2u) + (-mm1 - mm2)*(7 + power2(Pi)/6) + - (mm1 - mm2)*(2*dilog(1 - mm1/mm2) + + (mm1 - mm2)*(2*Li2(1 - mm1/mm2) + power2(log12)/2) + ((mm1 + mm2)*power2(log12))/2 - 2*(mm1*power2(log1u) + mm2*power2(log2u)))/2; @@ -287,14 +287,6 @@ Real LambdaSquared(Real x, Real y) noexcept return power2(1 - x - y) - 4*x*y; } - /// ClausenCl[2,x] - Real ClausenCl2(Real x) noexcept - { - const std::complex img(0.0l, 1.0l); - - return std::imag(dilog(std::exp(img*x))); - } - /// x < 1 && y < 1, LambdaSquared(x,y) > 0 Real PhiPos(Real x, Real y) noexcept { @@ -302,8 +294,8 @@ Real PhiPos(Real x, Real y) noexcept return (-(std::log(x)*std::log(y)) + 2*std::log((1 - lambda + x - y)/2)*std::log((1 - lambda - x + y)/2) - - 2*dilog((1 - lambda + x - y)/2) - - 2*dilog((1 - lambda - x + y)/2) + - 2*Li2((1 - lambda + x - y)/2) + - 2*Li2((1 - lambda - x + y)/2) + power2(Pi)/3)/lambda; } @@ -312,9 +304,9 @@ Real PhiNeg(Real x, Real y) noexcept { const Real lambda = std::sqrt(-LambdaSquared(x,y)); - return 2*(+ ClausenCl2(2*std::acos((1 + x - y)/(2*std::sqrt(x)))) - + ClausenCl2(2*std::acos((1 - x + y)/(2*std::sqrt(y)))) - + ClausenCl2(2*std::acos((-1 + x + y)/(2*std::sqrt(x*y)))))/lambda; + return 2*(+ Cl2(2*std::acos((1 + x - y)/(2*std::sqrt(x)))) + + Cl2(2*std::acos((1 - x + y)/(2*std::sqrt(y)))) + + Cl2(2*std::acos((-1 + x + y)/(2*std::sqrt(x*y)))))/lambda; } Real Phi(Real x, Real y) noexcept diff --git a/meta/MSSM/tquark_to_cpp.m b/meta/MSSM/tquark_to_cpp.m index 9acb4a2367..9f48a532a4 100644 --- a/meta/MSSM/tquark_to_cpp.m +++ b/meta/MSSM/tquark_to_cpp.m @@ -193,7 +193,7 @@ // with the script \"tquark_to_cpp.m\". #include \"" <> headerName <> "\" -#include \"dilog.hpp\" +#include \"Li2.hpp\" #include #include @@ -258,7 +258,7 @@ bool is_equal_rel(double a, double b, double prec) noexcept return (6*(mm1*log1u + mm2*log2u) + (-mm1 - mm2)*(7 + pow2(Pi)/6.) + - (mm1 - mm2)*(2*dilog(1 - mm1/mm2) + pow2(log12)/2.) + + (mm1 - mm2)*(2*Li2(1 - mm1/mm2) + pow2(log12)/2.) + ((mm1 + mm2)*pow2(log12))/2. - 2*(mm1*pow2(log1u) + mm2*pow2(log2u)))/2.; } diff --git a/model_specific/MSSM_higgs/mssm_twoloophiggs.cpp b/model_specific/MSSM_higgs/mssm_twoloophiggs.cpp index f6ea24551a..49a83ab745 100644 --- a/model_specific/MSSM_higgs/mssm_twoloophiggs.cpp +++ b/model_specific/MSSM_higgs/mssm_twoloophiggs.cpp @@ -19,7 +19,7 @@ #include "mssm_twoloophiggs.hpp" #include "mssm_twoloophiggs.h" #include "config.h" -#include "dilog.hpp" +#include "Li2.hpp" #include #include #include @@ -55,7 +55,7 @@ double phi(double x, double y, double z) const double xm = 0.5 * (1 - (u - v) - lambda); return 1./lambda * (2*logabs(xp)*logabs(xm) - logabs(u)*logabs(v) - - 2*(dilog(xp) + dilog(xm)) + M_PI*M_PI/3.); + 2*(Li2(xp) + Li2(xm)) + M_PI*M_PI/3.); } /// First derivative of phi[t,T,g] w.r.t. T @@ -71,8 +71,8 @@ double dphi_010(double t, double T, double g) const double abbr = (-4*t*T)/g2 + sqr(1 - t/g - T/g); const double rabbr = sqrtabs(abbr); - return ((g + t - T)*(Pi2 - 6*dilog((g - rabbr*g + t - T)/(2.*g)) - - 6*dilog((g - rabbr*g - t + T)/(2.*g)) - + return ((g + t - T)*(Pi2 - 6*Li2((g - rabbr*g + t - T)/(2.*g)) - + 6*Li2((g - rabbr*g - t + T)/(2.*g)) - 3*logabs(t/g)*logabs(T/g) + 6*logabs((g - rabbr*g + t - T)/(2.*g))*logabs((g - rabbr*g - t + T)/(2.*g))) + (3*rabbr*g* ( rabbr*g*((-1 + rabbr)*g + t - T)*logabs(t/g) + @@ -104,8 +104,8 @@ double dphi_001(double g, double t, double T) const double lxmyp = logabs(0.5*(1 - x + yp)); const double lxpym = logabs(0.5*(1 + x + ym)); const double lxpyp = logabs(0.5*(1 + x + yp)); - const double li2xym = dilog(0.5*(1 - x + ym)); - const double li2xyp = dilog(0.5*(1 - x + yp)); + const double li2xym = Li2(0.5*(1 - x + ym)); + const double li2xyp = Li2(0.5*(1 - x + yp)); return ((t*(t - T) - g*(2*t + T) + sqr(g))* (-6*li2xym - 6*li2xyp - 3*lgT*ltT + 6*lxmym*lxmyp + Pi2) diff --git a/model_specific/MSSM_thresholds/mssm_twoloop_as.cpp b/model_specific/MSSM_thresholds/mssm_twoloop_as.cpp index 27580cd928..fddc23f16c 100644 --- a/model_specific/MSSM_thresholds/mssm_twoloop_as.cpp +++ b/model_specific/MSSM_thresholds/mssm_twoloop_as.cpp @@ -20,11 +20,11 @@ // with the script "as2_to_cpp.m". #include "mssm_twoloop_as.hpp" -#include "dilog.hpp" +#include "Cl2.hpp" +#include "Li2.hpp" #include #include #include -#include #include #include @@ -80,14 +80,6 @@ namespace { return power2(1 - x - y) - 4*x*y; } - /// ClausenCl[2,x] - Real ClausenCl2(Real x) noexcept - { - const std::complex img(0.0l, 1.0l); - - return std::imag(dilog(std::exp(img*x))); - } - /// x < 1 && y < 1, LambdaSquared(x,y) > 0 Real PhiPos(Real x, Real y) noexcept { @@ -95,8 +87,8 @@ namespace { return (-(std::log(x)*std::log(y)) + 2*std::log((1 - lambda + x - y)/2)*std::log((1 - lambda - x + y)/2) - - 2*dilog((1 - lambda + x - y)/2) - - 2*dilog((1 - lambda - x + y)/2) + - 2*Li2((1 - lambda + x - y)/2) + - 2*Li2((1 - lambda - x + y)/2) + power2(Pi)/3)/lambda; } @@ -105,9 +97,9 @@ namespace { { const Real lambda = std::sqrt(-LambdaSquared(x,y)); - return 2*(+ ClausenCl2(2*std::acos((1 + x - y)/(2*std::sqrt(x)))) - + ClausenCl2(2*std::acos((1 - x + y)/(2*std::sqrt(y)))) - + ClausenCl2(2*std::acos((-1 + x + y)/(2*std::sqrt(x*y)))))/lambda; + return 2*(+ Cl2(2*std::acos((1 + x - y)/(2*std::sqrt(x)))) + + Cl2(2*std::acos((1 - x + y)/(2*std::sqrt(y)))) + + Cl2(2*std::acos((-1 + x + y)/(2*std::sqrt(x*y)))))/lambda; } Real Phi(Real x, Real y) noexcept diff --git a/model_specific/MSSM_thresholds/mssm_twoloop_mb.cpp b/model_specific/MSSM_thresholds/mssm_twoloop_mb.cpp index 65ab801df6..c326ad0bae 100644 --- a/model_specific/MSSM_thresholds/mssm_twoloop_mb.cpp +++ b/model_specific/MSSM_thresholds/mssm_twoloop_mb.cpp @@ -20,11 +20,11 @@ // with the script "bquark_to_cpp.m". #include "mssm_twoloop_mb.hpp" -#include "dilog.hpp" +#include "Cl2.hpp" +#include "Li2.hpp" #include #include #include -#include #include namespace flexiblesusy { @@ -71,7 +71,7 @@ namespace { return (6*(mm1*log1u + mm2*log2u) + (-mm1 - mm2)*(7 + pow2(Pi)/6) + - (mm1 - mm2)*(2*dilog(1 - mm1/mm2) + + (mm1 - mm2)*(2*Li2(1 - mm1/mm2) + pow2(log12)/2) + ((mm1 + mm2)*pow2(log12))/2 - 2*(mm1*pow2(log1u) + mm2*pow2(log2u)))/2; @@ -82,14 +82,6 @@ namespace { return pow2(1 - x - y) - 4*x*y; } - /// ClausenCl[2,x] - double ClausenCl2(double x) noexcept - { - const std::complex img(0.0, 1.0); - - return std::imag(dilog(std::exp(img*x))); - } - /// x < 1 && y < 1, LambdaSquared(x,y) > 0 double PhiPos(double x, double y) noexcept { @@ -97,8 +89,8 @@ namespace { return (-(std::log(x)*std::log(y)) + 2*std::log((1 - lambda + x - y)/2)*std::log((1 - lambda - x + y)/2) - - 2*dilog((1 - lambda + x - y)/2) - - 2*dilog((1 - lambda - x + y)/2) + - 2*Li2((1 - lambda + x - y)/2) + - 2*Li2((1 - lambda - x + y)/2) + pow2(Pi)/3)/lambda; } @@ -107,9 +99,9 @@ namespace { { const double lambda = std::sqrt(-LambdaSquared(x,y)); - return 2*(+ ClausenCl2(2*std::acos((1 + x - y)/(2*std::sqrt(x)))) - + ClausenCl2(2*std::acos((1 - x + y)/(2*std::sqrt(y)))) - + ClausenCl2(2*std::acos((-1 + x + y)/(2*std::sqrt(x*y)))))/lambda; + return 2*(+ Cl2(2*std::acos((1 + x - y)/(2*std::sqrt(x)))) + + Cl2(2*std::acos((1 - x + y)/(2*std::sqrt(y)))) + + Cl2(2*std::acos((-1 + x + y)/(2*std::sqrt(x*y)))))/lambda; } double Phi(double x, double y) noexcept diff --git a/model_specific/MSSM_thresholds/mssm_twoloop_mt.cpp b/model_specific/MSSM_thresholds/mssm_twoloop_mt.cpp index c591f870fd..bcb42ef3eb 100644 --- a/model_specific/MSSM_thresholds/mssm_twoloop_mt.cpp +++ b/model_specific/MSSM_thresholds/mssm_twoloop_mt.cpp @@ -20,7 +20,7 @@ // with the script "tquark_to_cpp.m". #include "mssm_twoloop_mt.hpp" -#include "dilog.hpp" +#include "Li2.hpp" #include #include @@ -85,7 +85,7 @@ namespace { return (6*(mm1*log1u + mm2*log2u) + (-mm1 - mm2)*(7 + pow2(Pi)/6.) + - (mm1 - mm2)*(2*dilog(1 - mm1/mm2) + pow2(log12)/2.) + + (mm1 - mm2)*(2*Li2(1 - mm1/mm2) + pow2(log12)/2.) + ((mm1 + mm2)*pow2(log12))/2. - 2*(mm1*pow2(log1u) + mm2*pow2(log2u)))/2.; } diff --git a/model_specific/MSSM_thresholds/mssm_twoloop_mtau.cpp b/model_specific/MSSM_thresholds/mssm_twoloop_mtau.cpp index 98235c9f49..c1204c9f80 100644 --- a/model_specific/MSSM_thresholds/mssm_twoloop_mtau.cpp +++ b/model_specific/MSSM_thresholds/mssm_twoloop_mtau.cpp @@ -20,11 +20,11 @@ // with the script "tau_to_cpp.m". #include "mssm_twoloop_mtau.hpp" -#include "dilog.hpp" +#include "Cl2.hpp" +#include "Li2.hpp" #include #include #include -#include #include #include @@ -92,7 +92,7 @@ namespace { return (6*(mm1*log1u + mm2*log2u) + (-mm1 - mm2)*(7 + power2(Pi)/6) + - (mm1 - mm2)*(2*dilog(1 - mm1/mm2) + + (mm1 - mm2)*(2*Li2(1 - mm1/mm2) + power2(log12)/2) + ((mm1 + mm2)*power2(log12))/2 - 2*(mm1*power2(log1u) + mm2*power2(log2u)))/2; @@ -103,14 +103,6 @@ namespace { return power2(1 - x - y) - 4*x*y; } - /// ClausenCl[2,x] - Real ClausenCl2(Real x) noexcept - { - const std::complex img(0.0l, 1.0l); - - return std::imag(dilog(std::exp(img*x))); - } - /// x < 1 && y < 1, LambdaSquared(x,y) > 0 Real PhiPos(Real x, Real y) noexcept { @@ -118,8 +110,8 @@ namespace { return (-(std::log(x)*std::log(y)) + 2*std::log((1 - lambda + x - y)/2)*std::log((1 - lambda - x + y)/2) - - 2*dilog((1 - lambda + x - y)/2) - - 2*dilog((1 - lambda - x + y)/2) + - 2*Li2((1 - lambda + x - y)/2) + - 2*Li2((1 - lambda - x + y)/2) + power2(Pi)/3)/lambda; } @@ -128,9 +120,9 @@ namespace { { const Real lambda = std::sqrt(-LambdaSquared(x,y)); - return 2*(+ ClausenCl2(2*std::acos((1 + x - y)/(2*std::sqrt(x)))) - + ClausenCl2(2*std::acos((1 - x + y)/(2*std::sqrt(y)))) - + ClausenCl2(2*std::acos((-1 + x + y)/(2*std::sqrt(x*y)))))/lambda; + return 2*(+ Cl2(2*std::acos((1 + x - y)/(2*std::sqrt(x)))) + + Cl2(2*std::acos((1 - x + y)/(2*std::sqrt(y)))) + + Cl2(2*std::acos((-1 + x + y)/(2*std::sqrt(x*y)))))/lambda; } Real Phi(Real x, Real y) noexcept diff --git a/src/Cl2.cpp b/src/Cl2.cpp new file mode 100644 index 0000000000..68de5a1317 --- /dev/null +++ b/src/Cl2.cpp @@ -0,0 +1,222 @@ +// ==================================================================== +// This file is part of FlexibleSUSY. +// +// FlexibleSUSY 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. +// +// FlexibleSUSY 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 FlexibleSUSY. If not, see +// . +// ==================================================================== + +#include "Cl2.hpp" +#include + +namespace flexiblesusy { + +/** + * @brief Clausen function \f$\mathrm{Cl}_2(\theta) = \mathrm{Im}(\mathrm{Li}_2(e^{i\theta}))\f$ + * @param x real angle + * @return \f$\mathrm{Cl}_2(\theta)\f$ + * @author Alexander Voigt + * @note Implemented as economized Padé approximation. + */ +double Cl2(double x) noexcept +{ + const double PI = 3.14159265358979324; + const double PI2 = 2*PI, PIH = PI/2, PI28 = PI*PI/8; + double sgn = 1; + + if (x < 0) { + x = -x; + sgn = -1; + } + + if (x >= PI2) { + x = std::fmod(x, PI2); + } + + if (x > PI) { + const double p0 = 6.28125; + const double p1 = 0.0019353071795864769253; + x = (p0 - x) + p1; + sgn = -sgn; + } + + if (x == 0 || x == PI) { + return 0; + } + + double h = 0; + + if (x < PIH) { + const double P[] = { + 2.7951565822419270e-02, -8.8865360514541522e-04, + 6.8282348222485902e-06, -7.5276232403566808e-09 + }; + const double Q[] = { + 1.0000000000000000e+00, -3.6904397961160525e-02, + 3.7342870576106476e-04, -8.7460760866531179e-07 + }; + const double y = x*x; + const double z = y - PI28; + const double z2 = z*z; + const double p = P[0] + z * P[1] + z2 * (P[2] + z * P[3]); + const double q = Q[0] + z * Q[1] + z2 * (Q[2] + z * Q[3]); + + h = x*(1 - std::log(x) + y*p/q/2); + } else { + const double P[] = { + 6.4005702446195512e-01, -2.0641655351338783e-01, + 2.4175305223497718e-02, -1.2355955287855728e-03, + 2.5649833551291124e-05, -1.4783829128773320e-07 + }; + const double Q[] = { + 1.0000000000000000e+00, -2.5299102015666356e-01, + 2.2148751048467057e-02, -7.8183920462457496e-04, + 9.5432542196310670e-06, -1.8184302880448247e-08 + }; + const double y = PI - x; + const double z = y*y - PI28; + const double z2 = z*z; + const double z4 = z2*z2; + const double p = P[0] + z * P[1] + z2 * (P[2] + z * P[3]) + + z4 * (P[4] + z * P[5]); + const double q = Q[0] + z * Q[1] + z2 * (Q[2] + z * Q[3]) + + z4 * (Q[4] + z * Q[5]); + + h = y*p/q; + } + + return sgn*h; +} + +/** + * @brief Clausen function \f$\mathrm{Cl}_2(\theta) = \mathrm{Im}(\mathrm{Li}_2(e^{i\theta}))\f$ with long double precision + * @param x real angle + * @return \f$\mathrm{Cl}_2(\theta)\f$ + * @author Alexander Voigt + * + * Implemented as an economized Padé approximation with a maximum + * error of approximately 3.26e-41 (for long double and quadruple + * precision). + */ +long double Cl2(long double x) noexcept +{ + const long double PI = 3.14159265358979323846264338327950288L; + const long double PI2 = 2*PI, PIH = PI/2, PI28 = PI*PI/8; + long double sgn = 1; + + if (x < 0) { + x = -x; + sgn = -1; + } + + if (x >= PI2) { + x = std::fmod(x, PI2); + } + + if (x > PI) { + const long double p0 = 6.28125L; + const long double p1 = 0.0019353071795864769252867665590057683943L; + x = (p0 - x) + p1; + sgn = -sgn; + } + + if (x == 0 || x == PI) { + return 0; + } + + long double h = 0; + + if (x < PIH) { + const long double P[] = { + 2.795156582241927046412081735910646612854e-02L, + -2.704528039782130831727668760352473119745e-03L, + 1.058576547177802928762582430994046913011e-04L, + -2.147507975446829791077479076828450780219e-06L, + 2.401415296681270093111305488326496124531e-08L, + -1.450571790543608936928129678333156785370e-10L, + 4.280534901040925211965221454555516657749e-13L, + -4.792802237226483806823208684186867186935e-16L, + 8.883657381852830471176782778999368430017e-20L + }; + const long double Q[] = { + 1.000000000000000000000000000000000000000e+00L, + -1.018694323414614410071369720193716012304e-01L, + 4.248408782245281612900840467370146443889e-03L, + -9.337710301347963985908084056584187570954e-05L, + 1.159379163193822053103946363960603543601e-06L, + -8.083352720393357000801675734774176899515e-09L, + 2.949313240431512997069808854213308209519e-11L, + -4.742700419624204182400715964695278593777e-14L, + 2.158380636740175386190809152807629331877e-17L + }; + const long double y = x*x; + const long double z = y - PI28; + const long double z2 = z*z; + const long double z4 = z2*z2; + const long double z8 = z4*z4; + const long double p = P[0] + z * P[1] + z2 * (P[2] + z * P[3]) + + z4 * (P[4] + z * P[5] + z2 * (P[6] + z * P[7])) + z8 * P[8]; + const long double q = Q[0] + z * Q[1] + z2 * (Q[2] + z * Q[3]) + + z4 * (Q[4] + z * Q[5] + z2 * (Q[6] + z * Q[7])) + z8 * Q[8]; + + h = x*(1 - std::log(x) + y*p/q/2); + } else { + const long double P[] = { + 6.400570244619551220929428522356830562481e-01L, + -4.651631624886004423703445967760673575997e-01L, + 1.487130845262105644024901814213146749895e-01L, + -2.749665174801454303884783494225610407035e-02L, + 3.251522465413666561950482170352156048203e-03L, + -2.567438381297475310848635518657180974512e-04L, + 1.372076105130164861564020074178493529151e-05L, + -4.924179093673498700461153483531075799113e-07L, + 1.153267936031337440182387313169828395860e-08L, + -1.667578310677508029208023423625588832295e-10L, + 1.348437292247918547169070120217729056878e-12L, + -5.052245092698477071447850656280954693011e-15L, + 5.600638109466570497480415519182233229048e-18L, + }; + const long double Q[] = { + 1.000000000000000000000000000000000000000e+00L, + -6.572465772185054284667746526549393897676e-01L, + 1.886234634096976582977630140163583172173e-01L, + -3.103347567899737687117030083178445406132e-02L, + 3.230860399291224478336071920154030050234e-03L, + -2.216546569335921728108984951507368387512e-04L, + 1.011949972138985643994631167412420906088e-05L, + -3.033400935206767852937290458763547850384e-07L, + 5.748454611964843057644023468691231929690e-09L, + -6.408350048413952604351408631173781906861e-11L, + 3.678584366662951864267349037579031493395e-13L, + -8.240439699357036167611014086997683837396e-16L, + 3.041049046123062158788159773779755292771e-19L + }; + const long double y = PI - x; + const long double z = y*y - PI28; + const long double z2 = z*z; + const long double z4 = z2*z2; + const long double z8 = z4*z4; + const long double p = P[0] + z * P[1] + z2 * (P[2] + z * P[3]) + + z4 * (P[4] + z * P[5] + z2 * (P[6] + z * P[7])) + + z8 * (P[8] + z * P[9] + z2 * (P[10] + z * P[11]) + z4 * P[12]); + const long double q = Q[0] + z * Q[1] + z2 * (Q[2] + z * Q[3]) + + z4 * (Q[4] + z * Q[5] + z2 * (Q[6] + z * Q[7])) + + z8 * (Q[8] + z * Q[9] + z2 * (Q[10] + z * Q[11]) + z4 * Q[12]); + + h = y*p/q; + } + + return sgn*h; +} + +} // namespace flexiblesusy diff --git a/src/Cl2.hpp b/src/Cl2.hpp new file mode 100644 index 0000000000..42ef81b438 --- /dev/null +++ b/src/Cl2.hpp @@ -0,0 +1,32 @@ +// ==================================================================== +// This file is part of FlexibleSUSY. +// +// FlexibleSUSY 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. +// +// FlexibleSUSY 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 FlexibleSUSY. If not, see +// . +// ==================================================================== + +#ifndef CL2_H +#define CL2_H + +namespace flexiblesusy { + +/// Clausen function Cl_2(x) +double Cl2(double) noexcept; + +/// Clausen function Cl_2(x) +long double Cl2(long double) noexcept; + +} // namespace flexiblesusy + +#endif diff --git a/src/Li.cpp b/src/Li.cpp new file mode 100644 index 0000000000..02d29a22da --- /dev/null +++ b/src/Li.cpp @@ -0,0 +1,232 @@ +// ==================================================================== +// This file is part of Polylogarithm. +// +// Polylogarithm is licenced under the MIT License. +// ==================================================================== + +#include "Li.hpp" +#include "Li2.hpp" +#include "Li3.hpp" +#include "Li4.hpp" +#include "Li5.hpp" +#include "Li6.hpp" +#include "eta.hpp" +#include "factorial.hpp" +#include "harmonic.hpp" +#include "zeta.hpp" +#include +#include +#include +#include + +namespace flexiblesusy { + +namespace { + constexpr double inf = std::numeric_limits::infinity(); + constexpr double nan = std::numeric_limits::quiet_NaN(); + constexpr double PI = 3.1415926535897932; + + constexpr bool is_even(int64_t n) noexcept { return n % 2 == 0; } + + constexpr bool is_finite(const std::complex& z) noexcept + { + return std::isfinite(std::real(z)) && std::isfinite(std::imag(z)); + } + + /// complex logarithm, converts -0.0 to 0.0 + std::complex clog(const std::complex& z) noexcept + { + const double n = std::imag(z)*std::imag(z) + std::real(z)*std::real(z); + double a = std::arg(z); + + if (std::imag(z) == 0.0 && a < 0.0) { + a = -a; + } + + return { 0.5*std::log(n), a }; + } + + /// Series expansion of Li_n(z) in terms of powers of z. + /// Fast convergence for large n >= 12. + std::complex Li_series(int64_t n, const std::complex& z) noexcept + { + std::complex sum(0.0, 0.0), sum_old(0.0, 0.0), p = z; + int64_t k = 0; + + do { + k++; + sum_old = sum; + sum += p; + p *= z*std::pow(k/(1.0 + k), n); + if (!is_finite(p)) { break; } + } while (sum != sum_old && + k < std::numeric_limits::max() - 2); + + return sum; + } + + /// Series expansion of Li_n(z) around z ~ 1, n > 0 + std::complex Li_unity_pos(int64_t n, const std::complex& z) noexcept + { + const std::complex lnz = clog(z); + const std::complex lnz2 = lnz*lnz; + std::complex sum(zeta(n), 0.0), p(1.0, 0.0); + + for (int64_t j = 1; j < n - 1; ++j) { + p *= lnz/static_cast(j); + sum += zeta(n - j)*p; + } + + p *= lnz/static_cast(n - 1); + sum += (harmonic(n - 1) - clog(-lnz))*p; + + p *= lnz/static_cast(n); + sum += zeta(0)*p; + + p *= lnz/static_cast(n + 1); + sum += zeta(-1)*p; + + for (int64_t j = (n + 3); j < std::numeric_limits::max() - 2; j += 2) { + p *= lnz2/static_cast((j - 1)*j); + const auto old_sum = sum; + sum += zeta(n - j)*p; + if (sum == old_sum) { break; } + } + + return sum; + } + + /// returns z^n, treating Re(z) == 0 and Im(z) == 0 in a stable way + std::complex stable_pow(const std::complex& z, int64_t n) noexcept + { + if (std::imag(z) == 0) { + return { std::pow(std::real(z), n), 0.0 }; + } else if (std::real(z) == 0) { + const double p = std::pow(std::imag(z), n); + if (n % 4 == 0) { + return { p, 0.0 }; + } else if (n % 2 == 0) { + return { -p, 0.0 }; + } else if ((n - 1) % 4 == 0) { + return { 0.0, p }; + } + return { 0.0, -p }; + } + return std::pow(z, n); + } + + /// Series expansion of Li_n(z) around z ~ 1, n < 0 + std::complex Li_unity_neg(int64_t n, const std::complex& z) noexcept + { + const std::complex lnz = clog(z); + const std::complex lnz2 = lnz*lnz; + std::complex sum = std::tgamma(1 - n)*stable_pow(-lnz, n - 1); + std::complex lnzk, sum_old, term; + int64_t k; + + if (is_even(n)) { + lnzk = lnz; + k = 1; + } else { + lnzk = lnz2; + sum += zeta(n); + k = 2; + } + + do { + term = zeta(n - k)*inv_fac(k)*lnzk; + if (!is_finite(term)) { break; } + sum_old = sum; + sum += term; + lnzk *= lnz2; + k += 2; + } while (sum != sum_old); + + return sum; + } + + /// returns remainder from inversion formula + std::complex Li_rest(int64_t n, const std::complex& z) noexcept + { + const std::complex lnz = clog(-z); + const std::complex lnz2 = lnz*lnz; + const int64_t kmax = is_even(n) ? n/2 : (n - 1)/2; + std::complex p = is_even(n) ? 1.0 : lnz; + std::complex sum(0.0, 0.0), old_sum; + + for (int64_t k = kmax; k != 0; --k) { + const double ifac = inv_fac(n - 2*k); + if (ifac == 0) { return 2.0*sum; } + sum += neg_eta(2*k)*ifac*p; + p *= lnz2; + if (sum == old_sum) { break; } + } + + return 2.0*sum - p*inv_fac(n); + } + +} // anonymous namespace + +/** + * @brief Complex polylogarithm \f$\operatorname{Li}_n(z)\f$ + * @param n degree of the polylogarithm + * @param z complex argument + * @return \f$\operatorname{Li}_n(z)\f$ + * @author Alexander Voigt + * + * For n < 0 the implementation follows the approach presented in + * [Matthew Roughan: "The Polylogarithm Function in Julia", + * arXiv:2010.09860]. + */ +std::complex Li(int64_t n, const std::complex& z) noexcept +{ + if (std::isnan(std::real(z)) || std::isnan(std::imag(z))) { + return {nan, nan}; + } else if (std::isinf(std::real(z)) || std::isinf(std::imag(z))) { + return {-inf, 0.0}; + } else if (z == 0.0) { + return {0.0, 0.0}; + } else if (z == 1.0) { + if (n <= 0) { + return {inf, inf}; + } + return {zeta(n), 0.0}; + } else if (z == -1.0) { + return {neg_eta(n), 0.0}; + } else if (n < -1) { + // arXiv:2010.09860 + const double nz = std::norm(z); + const double nl = std::norm(clog(z)); + if (4*PI*PI*nz < nl) { + return Li_series(n, z); + } else if (nl < 0.512*0.512*4*PI*PI) { + return Li_unity_neg(n, z); + } + const auto sqrtz = std::sqrt(z); + return std::pow(2.0, n - 1)*(Li(n, sqrtz) + Li(n, -sqrtz)); + } else if (n == -1) { + return z/((1.0 - z)*(1.0 - z)); + } else if (n == 0) { + return z/(1.0 - z); + } else if (n == 1) { + return -clog(1.0 - z); + } else if (n == 2) { + return Li2(z); + } else if (n == 3) { + return Li3(z); + } else if (n == 4) { + return Li4(z); + } else if (n == 5) { + return Li5(z); + } else if (n == 6) { + return Li6(z); + } else if (std::norm(z) <= 0.75*0.75) { + return Li_series(n, z); + } else if (std::norm(z) >= 1.4*1.4) { + const double sgn = is_even(n) ? -1.0 : 1.0; + return sgn*Li_series(n, 1.0/z) + Li_rest(n, z); + } + return Li_unity_pos(n, z); +} + +} // namespace flexiblesusy diff --git a/src/Li.hpp b/src/Li.hpp new file mode 100644 index 0000000000..8d7824e0b2 --- /dev/null +++ b/src/Li.hpp @@ -0,0 +1,20 @@ +// ==================================================================== +// This file is part of Polylogarithm. +// +// Polylogarithm is licenced under the MIT License. +// ==================================================================== + +#ifndef LI_H +#define LI_H + +#include +#include + +namespace flexiblesusy { + +/// complex polylogarithm for arbitrary integer n +std::complex Li(int64_t n, const std::complex&) noexcept; + +} // namespace flexiblesusy + +#endif diff --git a/src/dilog.cpp b/src/Li2.cpp similarity index 63% rename from src/dilog.cpp rename to src/Li2.cpp index d556cad04d..72342e3b8a 100644 --- a/src/dilog.cpp +++ b/src/Li2.cpp @@ -16,7 +16,7 @@ // . // ==================================================================== -#include "dilog.hpp" +#include "Li2.hpp" #include "complex.hpp" #include #include @@ -56,204 +56,6 @@ namespace { } // anonymous namespace -/** - * @brief Clausen function \f$\mathrm{Cl}_2(\theta) = \mathrm{Im}(\mathrm{Li}_2(e^{i\theta}))\f$ - * @param x real angle - * @return \f$\mathrm{Cl}_2(\theta)\f$ - * @author Alexander Voigt - * @note Implemented as economized Padé approximation. - */ -double clausen_2(double x) noexcept -{ - const double PI = 3.14159265358979324; - const double PI2 = 2*PI, PIH = PI/2, PI28 = PI*PI/8; - double sgn = 1; - - if (x < 0) { - x = -x; - sgn = -1; - } - - if (x >= PI2) { - x = std::fmod(x, PI2); - } - - if (x > PI) { - const double p0 = 6.28125; - const double p1 = 0.0019353071795864769253; - x = (p0 - x) + p1; - sgn = -sgn; - } - - if (x == 0 || x == PI) { - return 0; - } - - double h = 0; - - if (x < PIH) { - const double P[] = { - 2.7951565822419270e-02, -8.8865360514541522e-04, - 6.8282348222485902e-06, -7.5276232403566808e-09 - }; - const double Q[] = { - 1.0000000000000000e+00, -3.6904397961160525e-02, - 3.7342870576106476e-04, -8.7460760866531179e-07 - }; - const double y = x*x; - const double z = y - PI28; - const double z2 = z*z; - const double p = P[0] + z * P[1] + z2 * (P[2] + z * P[3]); - const double q = Q[0] + z * Q[1] + z2 * (Q[2] + z * Q[3]); - - h = x*(1 - std::log(x) + y*p/q/2); - } else { - const double P[] = { - 6.4005702446195512e-01, -2.0641655351338783e-01, - 2.4175305223497718e-02, -1.2355955287855728e-03, - 2.5649833551291124e-05, -1.4783829128773320e-07 - }; - const double Q[] = { - 1.0000000000000000e+00, -2.5299102015666356e-01, - 2.2148751048467057e-02, -7.8183920462457496e-04, - 9.5432542196310670e-06, -1.8184302880448247e-08 - }; - const double y = PI - x; - const double z = y*y - PI28; - const double z2 = z*z; - const double z4 = z2*z2; - const double p = P[0] + z * P[1] + z2 * (P[2] + z * P[3]) + - z4 * (P[4] + z * P[5]); - const double q = Q[0] + z * Q[1] + z2 * (Q[2] + z * Q[3]) + - z4 * (Q[4] + z * Q[5]); - - h = y*p/q; - } - - return sgn*h; -} - -/** - * @brief Clausen function \f$\mathrm{Cl}_2(\theta) = \mathrm{Im}(\mathrm{Li}_2(e^{i\theta}))\f$ with long double precision - * @param x real angle - * @return \f$\mathrm{Cl}_2(\theta)\f$ - * @author Alexander Voigt - * - * Implemented as an economized Padé approximation with a maximum - * error of approximately 3.26e-41 (for long double and quadruple - * precision). - */ -long double clausen_2(long double x) noexcept -{ - const long double PI = 3.14159265358979323846264338327950288L; - const long double PI2 = 2*PI, PIH = PI/2, PI28 = PI*PI/8; - long double sgn = 1; - - if (x < 0) { - x = -x; - sgn = -1; - } - - if (x >= PI2) { - x = std::fmod(x, PI2); - } - - if (x > PI) { - const long double p0 = 6.28125L; - const long double p1 = 0.0019353071795864769252867665590057683943L; - x = (p0 - x) + p1; - sgn = -sgn; - } - - if (x == 0 || x == PI) { - return 0; - } - - long double h = 0; - - if (x < PIH) { - const long double P[] = { - 2.795156582241927046412081735910646612854e-02L, - -2.704528039782130831727668760352473119745e-03L, - 1.058576547177802928762582430994046913011e-04L, - -2.147507975446829791077479076828450780219e-06L, - 2.401415296681270093111305488326496124531e-08L, - -1.450571790543608936928129678333156785370e-10L, - 4.280534901040925211965221454555516657749e-13L, - -4.792802237226483806823208684186867186935e-16L, - 8.883657381852830471176782778999368430017e-20L - }; - const long double Q[] = { - 1.000000000000000000000000000000000000000e+00L, - -1.018694323414614410071369720193716012304e-01L, - 4.248408782245281612900840467370146443889e-03L, - -9.337710301347963985908084056584187570954e-05L, - 1.159379163193822053103946363960603543601e-06L, - -8.083352720393357000801675734774176899515e-09L, - 2.949313240431512997069808854213308209519e-11L, - -4.742700419624204182400715964695278593777e-14L, - 2.158380636740175386190809152807629331877e-17L - }; - const long double y = x*x; - const long double z = y - PI28; - const long double z2 = z*z; - const long double z4 = z2*z2; - const long double z8 = z4*z4; - const long double p = P[0] + z * P[1] + z2 * (P[2] + z * P[3]) + - z4 * (P[4] + z * P[5] + z2 * (P[6] + z * P[7])) + z8 * P[8]; - const long double q = Q[0] + z * Q[1] + z2 * (Q[2] + z * Q[3]) + - z4 * (Q[4] + z * Q[5] + z2 * (Q[6] + z * Q[7])) + z8 * Q[8]; - - h = x*(1 - std::log(x) + y*p/q/2); - } else { - const long double P[] = { - 6.400570244619551220929428522356830562481e-01L, - -4.651631624886004423703445967760673575997e-01L, - 1.487130845262105644024901814213146749895e-01L, - -2.749665174801454303884783494225610407035e-02L, - 3.251522465413666561950482170352156048203e-03L, - -2.567438381297475310848635518657180974512e-04L, - 1.372076105130164861564020074178493529151e-05L, - -4.924179093673498700461153483531075799113e-07L, - 1.153267936031337440182387313169828395860e-08L, - -1.667578310677508029208023423625588832295e-10L, - 1.348437292247918547169070120217729056878e-12L, - -5.052245092698477071447850656280954693011e-15L, - 5.600638109466570497480415519182233229048e-18L, - }; - const long double Q[] = { - 1.000000000000000000000000000000000000000e+00L, - -6.572465772185054284667746526549393897676e-01L, - 1.886234634096976582977630140163583172173e-01L, - -3.103347567899737687117030083178445406132e-02L, - 3.230860399291224478336071920154030050234e-03L, - -2.216546569335921728108984951507368387512e-04L, - 1.011949972138985643994631167412420906088e-05L, - -3.033400935206767852937290458763547850384e-07L, - 5.748454611964843057644023468691231929690e-09L, - -6.408350048413952604351408631173781906861e-11L, - 3.678584366662951864267349037579031493395e-13L, - -8.240439699357036167611014086997683837396e-16L, - 3.041049046123062158788159773779755292771e-19L - }; - const long double y = PI - x; - const long double z = y*y - PI28; - const long double z2 = z*z; - const long double z4 = z2*z2; - const long double z8 = z4*z4; - const long double p = P[0] + z * P[1] + z2 * (P[2] + z * P[3]) + - z4 * (P[4] + z * P[5] + z2 * (P[6] + z * P[7])) + - z8 * (P[8] + z * P[9] + z2 * (P[10] + z * P[11]) + z4 * P[12]); - const long double q = Q[0] + z * Q[1] + z2 * (Q[2] + z * Q[3]) + - z4 * (Q[4] + z * Q[5] + z2 * (Q[6] + z * Q[7])) + - z8 * (Q[8] + z * Q[9] + z2 * (Q[10] + z * Q[11]) + z4 * Q[12]); - - h = y*p/q; - } - - return sgn*h; -} - /** * @brief Real dilogarithm \f$\mathrm{Li}_2(x)\f$ * @param x real argument @@ -263,7 +65,7 @@ long double clausen_2(long double x) noexcept * Implemented as an economized Pade approximation with a * maximum error of 4.16e-18. */ -double dilog(double x) noexcept +double Li2(double x) noexcept { const double PI = 3.1415926535897932; const double P[] = { @@ -348,7 +150,7 @@ double dilog(double x) noexcept * error of 2.13e-20 (long double precision) and 1.03e-38 (quadruple * precision), respectively. */ -long double dilog(long double x) noexcept +long double Li2(long double x) noexcept { const long double PI = 3.14159265358979323846264338327950288L; @@ -471,7 +273,7 @@ long double dilog(long double x) noexcept * @author Werner Porod * @note translated to C++ by Alexander Voigt */ -std::complex dilog(const std::complex& z_) noexcept +std::complex Li2(const std::complex& z_) noexcept { const double PI = 3.1415926535897932; const Complex z = { std::real(z_), std::imag(z_) }; @@ -494,10 +296,10 @@ std::complex dilog(const std::complex& z_) noexcept // special cases if (z.im == 0) { if (z.re <= 1) { - return dilog(z.re); + return Li2(z.re); } // z.re > 1 - return { dilog(z.re), -PI*std::log(z.re) }; + return { Li2(z.re), -PI*std::log(z.re) }; } const double nz = norm_sqr(z); @@ -547,7 +349,7 @@ std::complex dilog(const std::complex& z_) noexcept * @author Werner Porod * @note translated to C++ and extended to long double precision by Alexander Voigt */ -std::complex dilog(const std::complex& z_) noexcept +std::complex Li2(const std::complex& z_) noexcept { const long double PI = 3.14159265358979323846264338327950288L; const Complex z = { std::real(z_), std::imag(z_) }; @@ -585,10 +387,10 @@ std::complex dilog(const std::complex& z_) noexcept // special cases if (z.im == 0) { if (z.re <= 1) { - return dilog(z.re); + return Li2(z.re); } // z.re > 1 - return { dilog(z.re), -PI*std::log(z.re) }; + return { Li2(z.re), -PI*std::log(z.re) }; } const long double nz = norm_sqr(z); diff --git a/src/dilog.hpp b/src/Li2.hpp similarity index 69% rename from src/dilog.hpp rename to src/Li2.hpp index 0b566a9500..f5a8790c73 100644 --- a/src/dilog.hpp +++ b/src/Li2.hpp @@ -16,35 +16,25 @@ // . // ==================================================================== -#ifndef DILOG_H -#define DILOG_H +#ifndef LI2_H +#define LI2_H #include -#define DILOGATTR noexcept - namespace flexiblesusy { /// real dilogarithm -double dilog(double) DILOGATTR; +double Li2(double) noexcept; /// real dilogarithm -long double dilog(long double) DILOGATTR; +long double Li2(long double) noexcept; /// complex dilogarithm -std::complex dilog(const std::complex&) DILOGATTR; +std::complex Li2(const std::complex&) noexcept; /// complex dilogarithm -std::complex dilog(const std::complex&) DILOGATTR; - -/// Clausen function Cl_2(x) -double clausen_2(double) DILOGATTR; - -/// Clausen function Cl_2(x) -long double clausen_2(long double) DILOGATTR; +std::complex Li2(const std::complex&) noexcept; } // namespace flexiblesusy -#undef DILOGATTR - #endif diff --git a/src/trilog.cpp b/src/Li3.cpp similarity index 97% rename from src/trilog.cpp rename to src/Li3.cpp index b290c59ec8..8bd1d6026b 100644 --- a/src/trilog.cpp +++ b/src/Li3.cpp @@ -16,7 +16,7 @@ // . // ==================================================================== -#include "trilog.hpp" +#include "Li3.hpp" #include "complex.hpp" #include #include @@ -101,7 +101,7 @@ namespace { * @return \f$\operatorname{Li}_3(x)\f$ * @author Alexander Voigt */ -double trilog(double x) noexcept +double Li3(double x) noexcept { const double zeta2 = 1.6449340668482264; const double zeta3 = 1.2020569031595943; @@ -161,7 +161,7 @@ double trilog(double x) noexcept * @return \f$\operatorname{Li}_3(z)\f$ * @author Alexander Voigt */ -std::complex trilog(const std::complex& z_) noexcept +std::complex Li3(const std::complex& z_) noexcept { const double PI = 3.1415926535897932; const double zeta2 = 1.6449340668482264; @@ -182,10 +182,10 @@ std::complex trilog(const std::complex& z_) noexcept if (z.im == 0) { if (z.re <= 1) { - return trilog(z.re); + return Li3(z.re); } else { const double l = std::log(z.re); - return std::complex(trilog(z.re), -0.5*PI*l*l); + return std::complex(Li3(z.re), -0.5*PI*l*l); } } @@ -247,7 +247,7 @@ std::complex trilog(const std::complex& z_) noexcept * @return \f$\mathrm{Li}_3(z)\f$ * @author Alexander Voigt */ -std::complex trilog(const std::complex& z_) noexcept +std::complex Li3(const std::complex& z_) noexcept { const long double PI = 3.14159265358979323846264338327950288L; const long double zeta2 = 1.64493406684822643647241516664602519L; diff --git a/src/trilog.hpp b/src/Li3.hpp similarity index 82% rename from src/trilog.hpp rename to src/Li3.hpp index d4948916ed..41a2996adb 100644 --- a/src/trilog.hpp +++ b/src/Li3.hpp @@ -16,21 +16,21 @@ // . // ==================================================================== -#ifndef TRILOG_H -#define TRILOG_H +#ifndef LI3_H +#define LI3_H #include namespace flexiblesusy { /// real trilogarithm -double trilog(double) noexcept; +double Li3(double) noexcept; /// complex trilogarithm -std::complex trilog(const std::complex&) noexcept; +std::complex Li3(const std::complex&) noexcept; /// complex trilogarithm (long double precision) -std::complex trilog(const std::complex&) noexcept; +std::complex Li3(const std::complex&) noexcept; } // namespace flexiblesusy diff --git a/src/Li5.cpp b/src/Li5.cpp new file mode 100644 index 0000000000..d11b25f8b1 --- /dev/null +++ b/src/Li5.cpp @@ -0,0 +1,261 @@ +// ==================================================================== +// This file is part of Polylogarithm. +// +// Polylogarithm is licenced under the MIT License. +// ==================================================================== + +#include "Li5.hpp" +#include "complex.hpp" +#include +#include + +namespace flexiblesusy { + +namespace { + + template + Complex horner(const Complex& z, const T (&coeffs)[N]) noexcept + { + static_assert(N >= 2, "more than two coefficients required"); + + const T r = z.re + z.re; + const T s = z.re * z.re + z.im * z.im; + T a = coeffs[N - 1], b = coeffs[N - 2]; + + for (int i = N - 3; i >= 0; --i) { + const T t = a; + a = b + r * a; + b = coeffs[i] - s * t; + } + + return Complex(z.re*a + b, z.im*a); + } + +} // anonymous namespace + +/** + * @brief Complex polylogarithm \f$\operatorname{Li}_5(z)\f$ + * @param z_ complex argument + * @return \f$\operatorname{Li}_5(z)\f$ + * @author Alexander Voigt + */ +std::complex Li5(const std::complex& z_) noexcept +{ + const double PI = 3.1415926535897932; + const double PI2 = PI*PI; + const double PI4 = PI2*PI2; + const double zeta5 = 1.0369277551433699; + const double bf[19] = { + 1.0 , -15.0/32.0 , + 1.3953189300411523e-01, -2.8633777006172840e-02, + 4.0317412551440329e-03, -3.3985018004115226e-04, + 4.5445184621617666e-06, 2.3916808048569012e-06, + -1.2762692600122747e-07, -3.1628984306505932e-08, + 3.2848118445335192e-09, 4.7613713995660579e-10, + -8.0846898171909830e-11, -7.2387648587737207e-12, + 1.9439760115173968e-12, 1.0256978405977236e-13, + -4.6180551009884830e-14, -1.1535857196470580e-15, + 1.0903545401333394e-15 + }; + + const Complex z = { std::real(z_), std::imag(z_) }; + + if (z.im == 0) { + if (z.re == 0) { + return 0.0; + } + if (z.re == 1) { + return zeta5; + } + if (z.re == -1) { + return -15.0*zeta5/16.0; + } + } + + const double nz = norm_sqr(z); + const double pz = arg(z); + const double lnz = 0.5*std::log(nz); + + if (lnz*lnz + pz*pz < 1) { // |log(z)| < 1 + const Complex u(lnz, pz); // log(z) + const Complex u2 = u*u; + const double c0 = zeta5; + const double c1 = 1.0823232337111382; // zeta(4) + const double c2 = 0.60102845157979714; // zeta(3)/2 + const double c3 = 0.27415567780803774; + const Complex c4 = (25.0/12.0 - log(-u))/24.0; + const double c5 = -1.0/240.0; + + const double cs[6] = { + -1.1574074074074074e-04, 2.0667989417989418e-07, + -1.0935444136502338e-09, 8.6986487449450412e-12, + -8.6899587861588824e-14, 1.0081254080218813e-15 + }; + + return c0 + u * c1 + + u2 * (c2 + u * c3 + + u2 * (c4 + u * c5 + + u2 * horner(u2, cs))); + } + + Complex u(0.0, 0.0), rest(0.0, 0.0); + + if (nz <= 1) { + u = -log(1.0 - z); + } else { // nz > 1 + const double arg = pz > 0.0 ? pz - PI : pz + PI; + const Complex lmz(lnz, arg); // log(-z) + const Complex lmz2 = lmz*lmz; + u = -log(1.0 - 1.0/z); + rest = -1.0/360.0*lmz*(7*PI4 + lmz2*(10.0*PI2 + 3.0*lmz2)); + } + + const Complex u2 = u*u; + const Complex u4 = u2*u2; + const Complex u8 = u4*u4; + + return + rest + + u*bf[0] + + u2*(bf[1] + u*bf[2]) + + u4*(bf[3] + u*bf[4] + u2*(bf[5] + u*bf[6])) + + u8*(bf[7] + u*bf[8] + u2*(bf[9] + u*bf[10]) + + u4*(bf[11] + u*bf[12] + u2*(bf[13] + u*bf[14]))) + + u8*u8*(bf[15] + u*bf[16] + u2*(bf[17] + u*bf[18])); +} + +/** + * @brief Complex polylogarithm \f$\operatorname{Li}_5(z)\f$ with long double precision + * @param z_ complex argument + * @return \f$\operatorname{Li}_5(z)\f$ + * @author Alexander Voigt + */ +std::complex Li5(const std::complex& z_) noexcept +{ + const long double PI = 3.14159265358979323846264338327950288L; + const long double PI2 = PI*PI; + const long double PI4 = PI2*PI2; + const long double zeta5 = 1.03692775514336992633136548645703417L; + const long double bf[] = { + 1.0L, + -15.0L/32.0L, + 1.39531893004115226337448559670781893e-01L, + -2.86337770061728395061728395061728395e-02L, + 4.03174125514403292181069958847736626e-03L, + -3.39850180041152263374485596707818930e-04L, + 4.54451846216176664909446003743133026e-06L, + 2.39168080485690118829088702752453967e-06L, + -1.27626926001227465885443518981747128e-07L, + -3.16289843065059324402567872795470007e-08L, + 3.28481184453351916215185742384719818e-09L, + 4.76137139956605790483191328977324967e-10L, + -8.08468981719098302564602603623317490e-11L, + -7.23876485877372069468292158375897580e-12L, + 1.94397601151739684930556492093599766e-12L, + 1.02569784059772359718813559433198981e-13L, + -4.61805510098848301805820862410656158e-14L, + -1.15358571964705800368425114834190972e-15L, + 1.09035454013333939879770883809662643e-15L, + 2.31481363172925263940797103190091493e-18L, + -2.56699170432652921943348919933966693e-17L, +#if LDBL_DIG > 18 + 4.57086206073149690144959626860139115e-19L, + 6.03667796132057058823561033114107090e-19L, + -2.16776249440624129587941717218396578e-20L, + -1.41940966156001652983322668820112130e-20L, + 7.50200095064138625532377521619527234e-22L, + 3.33870453950783971643715159254469304e-22L, + -2.30600404426203476825215151352586388e-23L, + -7.85817324568948189044990646315027350e-24L, + 6.66834530437388085486513704613056895e-25L, + 1.85091565409252971894649796883651603e-25L, + -1.85915294451740855841031840576364891e-26L, + -4.36297464803458904472660817437095794e-27L, + 5.06110760995292844822634895878109349e-28L, + 1.02919182497568782037888979300008731e-28L, + -1.35513912210183166156877853283041765e-29L, + -2.42940596129573826559241540956570701e-30L, + 3.58519739665037052115164738053066333e-31L, + 5.73796581610397206400846538673280837e-32L, + -9.40035936245687345352774520389480989e-33L, + -1.35590280493486311500090284171223034e-33L, + 2.44784384191528918377859141748058708e-34L, + 3.20528849130720958124170712217928968e-35L, + -6.33983878185254827964152375942174520e-36L, + -7.57925545801218291534870941639851689e-37L +#endif + }; + + const Complex z = { std::real(z_), std::imag(z_) }; + + if (z.im == 0) { + if (z.re == 0) { + return 0.0L; + } + if (z.re == 1) { + return zeta5; + } + if (z.re == -1) { + return -15.0L*zeta5/16.0L; + } + } + + const long double nz = norm_sqr(z); + const long double pz = arg(z); + const long double lnz = 0.5L*std::log(nz); + + if (lnz*lnz + pz*pz < 1) { // |log(z)| < 1 + const Complex u(lnz, pz); // log(z) + const Complex u2 = u*u; + const long double c0 = zeta5; + const long double c1 = 1.08232323371113819151600369654116790L; // zeta(4) + const long double c2 = 0.601028451579797142699869080755724995L; // zeta(3)/2 + const long double c3 = 0.274155677808037739412069194441004198L; + const Complex c4 = (25.0L/12.0L - log(-u))/24.0L; + const long double c5 = -1.0L/240.0L; + + const long double cs[] = { + -1.15740740740740740740740740740740741e-04L, + 2.06679894179894179894179894179894180e-07L, + -1.09354441365023375605386187396769407e-09L, + 8.69864874494504124133753763383393013e-12L, + -8.68995878615888235897855907475917096e-14L, + 1.00812540802188133105305292318749173e-15L, + -1.30160058071551887185136369583811112e-17L, +#if LDBL_DIG > 18 + 1.82193858376471817317584461603964703e-19L, + -2.71703945984843566116551019291461834e-21L, + 4.26404710646461092493552846764602135e-23L, + -6.97907523609028772068847244464155123e-25L, + 1.18322350137468824961908885022923872e-26L, + -2.06699310884539801347149709357488995e-28L, + 3.70514089192917181888714449508744051e-30L, + -6.79216396752655546304766934905316826e-32L, + 1.26987457489641744061409835124861589e-33L, + -2.41590408788077922327391223699041147e-35L, + 4.66812326074215685597260023169508118e-37L +#endif + }; + + return c0 + u * c1 + + u2 * (c2 + u * c3 + + u2 * (c4 + u * c5 + + u2 * horner(u2, cs))); + } + + Complex u(0.0L, 0.0L), rest(0.0L, 0.0L); + + if (nz <= 1) { + u = -log(1.0L - z); + } else { // nz > 1 + const long double arg = pz > 0.0 ? pz - PI : pz + PI; + const Complex lmz(lnz, arg); // log(-z) + const Complex lmz2 = lmz*lmz; + u = -log(1.0L - 1.0L/z); + rest = -1.0L/360.0L*lmz*(7*PI4 + lmz2*(10.0L*PI2 + 3.0L*lmz2)); + } + + return rest + u*horner(u, bf); +} + +} // namespace flexiblesusy diff --git a/src/Li5.hpp b/src/Li5.hpp new file mode 100644 index 0000000000..8f8453f823 --- /dev/null +++ b/src/Li5.hpp @@ -0,0 +1,22 @@ +// ==================================================================== +// This file is part of Polylogarithm. +// +// Polylogarithm is licenced under the MIT License. +// ==================================================================== + +#ifndef LI5_H +#define LI5_H + +#include + +namespace flexiblesusy { + +/// complex polylogarithm with n=5 +std::complex Li5(const std::complex&) noexcept; + +/// complex polylogarithm with n=5 with long double precision +std::complex Li5(const std::complex&) noexcept; + +} // namespace flexiblesusy + +#endif diff --git a/src/Li6.cpp b/src/Li6.cpp new file mode 100644 index 0000000000..a3562f90b6 --- /dev/null +++ b/src/Li6.cpp @@ -0,0 +1,272 @@ +// ==================================================================== +// This file is part of Polylogarithm. +// +// Polylogarithm is licenced under the MIT License. +// ==================================================================== + +#include "Li6.hpp" +#include "complex.hpp" +#include +#include + +namespace flexiblesusy { + +namespace { + + template + Complex horner(const Complex& z, const T (&coeffs)[N]) noexcept + { + static_assert(N >= 2, "more than two coefficients required"); + + const T r = z.re + z.re; + const T s = z.re * z.re + z.im * z.im; + T a = coeffs[N - 1], b = coeffs[N - 2]; + + for (int i = N - 3; i >= 0; --i) { + const T t = a; + a = b + r * a; + b = coeffs[i] - s * t; + } + + return Complex(z.re*a + b, z.im*a); + } + +} // anonymous namespace + +/** + * @brief Complex polylogarithm \f$\operatorname{Li}_6(z)\f$ + * @param z_ complex argument + * @return \f$\operatorname{Li}_6(z)\f$ + * @author Alexander Voigt + */ +std::complex Li6(const std::complex& z_) noexcept +{ + const double PI = 3.1415926535897932; + const double PI2 = PI*PI; + const double PI4 = PI2*PI2; + const double PI6 = PI2*PI4; + const double zeta6 = 1.0173430619844491; + const double bf[18] = { + 1.0 , -31.0/64.0 , + 1.5241340877914952e-01, -3.4365555877057613e-02, + 5.7174797239368999e-03, -6.8180453746570645e-04, + 4.9960361948734493e-05, -4.9166051196039048e-07, + -3.0632975161302164e-07, 1.4414599270849095e-08, + 3.7272438230924107e-09, -3.7300867345487607e-10, + -5.1246526816085832e-11, 9.0541930956636683e-12, + 6.7381882615512517e-13, -2.1215831150303135e-13, + -6.8408811719011698e-15, 4.8691178462005581e-15 + }; + + const Complex z = { std::real(z_), std::imag(z_) }; + + if (z.im == 0) { + if (z.re == 0) { + return 0.0; + } + if (z.re == 1) { + return zeta6; + } + if (z.re == -1) { + return -31.0*zeta6/32.0; + } + } + + const double nz = norm_sqr(z); + const double pz = arg(z); + const double lnz = 0.5*std::log(nz); + + if (lnz*lnz + pz*pz < 1) { // |log(z)| < 1 + const Complex u(lnz, pz); // log(z) + const Complex u2 = u*u; + const double c0 = zeta6; + const double c1 = 1.0369277551433699; // zeta(5) + const double c2 = 0.54116161685556910; + const double c3 = 0.20034281719326571; + const double c4 = 0.068538919452009435; + const Complex c5 = (137.0/60.0 - log(-u))/120.0; + const double c6 = -1.0/1440.0; + + const double cs[5] = { + -1.6534391534391534e-05, 2.2964432686654909e-08, + -9.9413128513657614e-11, 6.6912682653423394e-13, + -5.7933058574392549e-15 + }; + + return c0 + u * c1 + + u2 * (c2 + u * c3 + + u2 * (c4 + u * c5 + + u2 * (c6 + + u * horner(u2, cs)))); + } + + Complex u(0.0, 0.0), rest(0.0, 0.0); + double sgn = 1; + + if (nz <= 1) { + u = -log(1.0 - z); + } else { // nz > 1 + const double arg = pz > 0.0 ? pz - PI : pz + PI; + const Complex lmz(lnz, arg); // log(-z) + const Complex lmz2 = lmz*lmz; + u = -log(1.0 - 1.0/z); + rest = -31.0*PI6/15120.0 + lmz2*(-7.0/720.0*PI4 + lmz2*(-1.0/144.0*PI2 - 1.0/720.0*lmz2)); + sgn = -1; + } + + const Complex u2 = u*u; + const Complex u4 = u2*u2; + const Complex u8 = u4*u4; + + return + rest + sgn * ( + u*bf[0] + + u2*(bf[1] + u*bf[2]) + + u4*(bf[3] + u*bf[4] + u2*(bf[5] + u*bf[6])) + + u8*(bf[7] + u*bf[8] + u2*(bf[9] + u*bf[10]) + + u4*(bf[11] + u*bf[12] + u2*(bf[13] + u*bf[14]))) + + u8*u8*(bf[15] + u*bf[16] + u2*bf[17]) + ); +} + +/** + * @brief Complex polylogarithm \f$\operatorname{Li}_6(z)\f$ with long double precision + * @param z_ complex argument + * @return \f$\operatorname{Li}_6(z)\f$ + * @author Alexander Voigt + */ +std::complex Li6(const std::complex& z_) noexcept +{ + const long double PI = 3.14159265358979323846264338327950288L; + const long double PI2 = PI*PI; + const long double PI4 = PI2*PI2; + const long double PI6 = PI2*PI4; + const long double zeta6 = 1.01734306198444913971451792979092053L; + const long double bf[] = { + 1.0L, + -31.0L/64.0L, + 1.52413408779149519890260631001371742e-01L, + -3.43655558770576131687242798353909465e-02L, + 5.71747972393689986282578875171467764e-03L, + -6.81804537465706447187928669410150892e-04L, + 4.99603619487344931145170169621327906e-05L, + -4.91660511960390477202530822164616726e-07L, + -3.06329751613021637853530304310404212e-07L, + 1.44145992708490953612537421448012923e-08L, + 3.72724382309241065768599245664598825e-09L, + -3.73008673454876072077977229159261141e-10L, + -5.12465268160858324340087646115722592e-11L, + 9.05419309566366828868797447620893807e-12L, + 6.73818826155125170776107544938009482e-13L, + -2.12158311503031353185279689296609530e-13L, + -6.84088117190116976639204518781909079e-15L, + 4.86911784620055813206387586512917456e-15L, + -4.84398784998725041650889647473159420e-18L, + -1.10271048491074909370430302576046237e-16L, + 3.33537969169393816624889411840735964e-18L, + 2.47353074886413529791540987487137046e-18L, +#if LDBL_DIG > 18 + -1.43706164342324920216883687134737009e-19L, + -5.50471103350981180614826435059791109e-20L, + 4.74677139173272249791309840662617185e-21L, + 1.21583871780681052243739817416294433e-21L, + -1.41075524035618500414240309078008657e-22L, + -2.66388312532683465965856437677118103e-23L, + 3.96676574286310079767900226081781935e-24L, + 5.78216973585436153112366193481125963e-25L, + -1.07877780631642573172998876995922389e-25L, + -1.24073970867569098990147736977589145e-26L, + 2.87041179178936017042609524684092346e-27L, + 2.62355535630293306165747520383606820e-28L, + -7.52294854657541272615881214134337672e-29L, + -5.44017883796246961820291930722306669e-30L, + 1.95025795325101663793862223381656999e-30L, + 1.09784942822051879961178213597012971e-31L, + -5.01495835741630092074469585415763612e-32L, + -2.12867375043927610535633806917391780e-33L, + 1.28159440165221259409319852281486752e-33L, + 3.87108447330479441622204568697607460e-35L, + -3.25941253155837592741689642881678163e-35L, + -6.25269198847740581093233860701356903e-37L, + 8.25794162051839801918004563317046685e-37L +#endif + }; + + const Complex z = { std::real(z_), std::imag(z_) }; + + if (z.im == 0) { + if (z.re == 0) { + return 0.0L; + } + if (z.re == 1) { + return zeta6; + } + if (z.re == -1) { + return -31.0L*zeta6/32.0L; + } + } + + const long double nz = norm_sqr(z); + const long double pz = arg(z); + const long double lnz = 0.5L*std::log(nz); + + if (lnz*lnz + pz*pz < 1) { // |log(z)| < 1 + const Complex u(lnz, pz); // log(z) + const Complex u2 = u*u; + const long double c0 = zeta6; + const long double c1 = 1.03692775514336992633136548645703417L; // zeta(5) + const long double c2 = 0.541161616855569095758001848270583951L; + const long double c3 = 0.200342817193265714233289693585241665L; + const long double c4 = 0.0685389194520094348530172986102510496L; + const Complex c5 = (137.0L/60.0L - log(-u))/120.0L; + const long double c6 = -1.0L/1440.0L; + + const long double cs[] = { + -1.65343915343915343915343915343915344e-05L, + 2.29644326866549088771310993533215755e-08L, + -9.94131285136576141867147158152449158e-11L, + 6.69126826534233941641349048756456164e-13L, + -5.79330585743925490598570604983944731e-15L, + 5.93014945895224312384148778345583373e-17L, +#if LDBL_DIG > 18 + -6.85052937218694143079665103072690062e-19L, + 8.67589801792722939607545055256974774e-21L, + -1.18132150428192854833283051865852971e-22L, + 1.70561884258584436997421138705840854e-24L, + -2.58484268003343989655128609060798194e-26L, + 4.08008103922306292972099603527323696e-28L, + -6.66771970595289681764999062443512889e-30L, + 1.12276996725126418754155893790528500e-31L, + -1.94061827643615870372790552830090522e-33L, + 3.43209344566599308274080635472598888e-35L, + -6.19462586636097236736900573587284992e-37L +#endif + }; + + return c0 + u * c1 + + u2 * (c2 + u * c3 + + u2 * (c4 + u * c5 + + u2 * (c6 + + u * horner(u2, cs)))); + } + + Complex u(0.0L, 0.0L), rest(0.0L, 0.0L); + long double sgn = 1; + + if (nz <= 1) { + u = -log(1.0L - z); + } else { // nz > 1 + const long double arg = pz > 0.0 ? pz - PI : pz + PI; + const Complex lmz(lnz, arg); // log(-z) + const Complex lmz2 = lmz*lmz; + u = -log(1.0L - 1.0L/z); + rest = -31.0L*PI6/15120.0L + + lmz2*(-7.0L/720.0L*PI4 + + lmz2*(-1.0L/144.0L*PI2 - 1.0L/720.0L*lmz2)); + sgn = -1; + } + + return rest + sgn*u*horner(u, bf); +} + +} // namespace flexiblesusy diff --git a/src/Li6.hpp b/src/Li6.hpp new file mode 100644 index 0000000000..ad32624962 --- /dev/null +++ b/src/Li6.hpp @@ -0,0 +1,22 @@ +// ==================================================================== +// This file is part of Polylogarithm. +// +// Polylogarithm is licenced under the MIT License. +// ==================================================================== + +#ifndef LI6_H +#define LI6_H + +#include + +namespace flexiblesusy { + +/// complex polylogarithm with n=5 +std::complex Li6(const std::complex&) noexcept; + +/// complex polylogarithm with n=5 with long double precision +std::complex Li6(const std::complex&) noexcept; + +} // namespace flexiblesusy + +#endif diff --git a/src/decays/decay_functions.cpp b/src/decays/decay_functions.cpp index 8e9ffaafd0..d72954f44e 100644 --- a/src/decays/decay_functions.cpp +++ b/src/decays/decay_functions.cpp @@ -20,8 +20,8 @@ #include #include "decay_functions.hpp" -#include "dilog.hpp" -#include "trilog.hpp" +#include "Li2.hpp" +#include "Li3.hpp" #include "Li4.hpp" #include "numerics2.hpp" #include "wrappers.hpp" @@ -51,7 +51,7 @@ double calc_A(double b) noexcept const double log_ratio {std::log((1 + b) / (1 - b))}; return (1 + b * b) * - (4. * dilog((1 - b) / (1 + b)) + 2. * dilog(-(1 - b) / (1 + b)) - + (4. * Li2((1 - b) / (1 + b)) + 2. * Li2(-(1 - b) / (1 + b)) - 3. * log_ratio * std::log(2 / (1 + b)) - 2. * log_ratio * log_b) - 3. * b * std::log(4. / (1 - b * b)) - 4. * b * log_b; @@ -176,10 +176,10 @@ std::complex delta_hAA_2loopQCD_for_quark_loop(double mH, double mq, dou const double tau = Sqr(mH/(2.*mq)); const std::complex z = is_zero(tau) ? 1. : (std::sqrt(std::complex(1. - 1./tau))-1.)/(std::sqrt(std::complex(1.-1./tau))+1.); const std::complex ln = std::log(z); - const std::complex li2p = dilog(z); - const std::complex li2m = dilog(-z); - const std::complex li3p = trilog(z); - const std::complex li3m = trilog(-z); + const std::complex li2p = Li2(z); + const std::complex li2m = Li2(-z); + const std::complex li3p = Li3(z); + const std::complex li3m = Li3(-z); const std::complex li4p = Li4(z); const std::complex li4m = Li4(-z); const std::complex p41mz = Power4(1.0-z); @@ -210,10 +210,10 @@ std::complex delta_AhAA_2loopQCD_for_quark_loop(double mAh, double mq, d } const std::complex z = is_zero(tau) ? 1. : (std::sqrt(std::complex(1. - 1./tau))-1.)/(std::sqrt(std::complex(1.-1./tau))+1.); const std::complex ln = std::log(z); - const std::complex li2p = dilog(z); - const std::complex li2m = dilog(-z); - const std::complex li3p = trilog(z); - const std::complex li3m = trilog(-z); + const std::complex li2p = Li2(z); + const std::complex li2m = Li2(-z); + const std::complex li3p = Li3(z); + const std::complex li3m = Li3(-z); const std::complex li4p = Li4(z); const std::complex li4m = Li4(-z); diff --git a/src/eta.cpp b/src/eta.cpp new file mode 100644 index 0000000000..d886bc10f8 --- /dev/null +++ b/src/eta.cpp @@ -0,0 +1,102 @@ +// ==================================================================== +// This file is part of Polylogarithm. +// +// Polylogarithm is licenced under the MIT License. +// ==================================================================== + +#include "eta.hpp" +#include + +namespace flexiblesusy { + +namespace { + +// Table[PolyLog[n,-1], {n,1,54}] +const double NEG_ETA[54] = { + -0.69314718055994531, -0.82246703342411322, -0.90154267736969571, + -0.94703282949724592, -0.97211977044690931, -0.98555109129743510, + -0.99259381992283028, -0.99623300185264790, -0.99809429754160533, + -0.99903950759827157, -0.99951714349806075, -0.99975768514385819, + -0.99987854276326512, -0.99993917034597972, -0.99996955121309924, + -0.99998476421490611, -0.99999237829204101, -0.99999618786961011, + -0.99999809350817168, -0.99999904661158152, -0.99999952325821554, + -0.99999976161323082, -0.99999988080131844, -0.99999994039889239, + -0.99999997019885696, -0.99999998509923200, -0.99999999254955048, + -0.99999999627475340, -0.99999999813736942, -0.99999999906868228, + -0.9999999995343403 , -0.9999999997671699 , -0.9999999998835849 , + -0.9999999999417924 , -0.9999999999708962 , -0.9999999999854481 , + -0.9999999999927240 , -0.9999999999963620 , -0.9999999999981810 , + -0.9999999999990905 , -0.9999999999995453 , -0.9999999999997726 , + -0.9999999999998863 , -0.9999999999999432 , -0.9999999999999716 , + -0.9999999999999858 , -0.9999999999999929 , -0.9999999999999964 , + -0.9999999999999982 , -0.9999999999999991 , -0.9999999999999996 , + -0.9999999999999998 , -0.9999999999999999 , -0.9999999999999999 +}; + +// Table[PolyLog[-2n+1,-1], {n,1,109}] +const double NEG_ETA_NEG_N[] = { + -0.25, 0.125 , -0.25 , 1.0625 , + -7.75 , 86.375 , -1365.25 , + 29049.03125 , -800572.75 , 2.7741322625e7 , + -1.18052913025e9 , 6.05239800516875e10 , -3.67941677853775e12 , + 2.6170760990658388e014, -2.1531418140800295e016, 2.0288775575173016e018, + -2.1708009902623771e020, 2.6173826968455815e022, -3.5324148876863878e024, + 5.3042033406864907e026, -8.8138218364311577e028, 1.6128065107490779e031, + -3.2355470001722734e033, 7.0876727476537493e035, -1.6890450341293966e038, + 4.3639690731216831e040, -1.2185998827061261e043, 3.6670584803153006e045, + -1.1859898526302099e048, 4.1120769493584015e050, -1.5249042436787620e053, + 6.0349693196941307e055, -2.5437161764210696e058, 1.1396923802632288e061, + -5.4180861064753979e063, 2.7283654799994374e066, -1.4529750514918543e069, + 8.1705519371067450e071, -4.8445781606678368e074, 3.0246694206649519e077, + -1.9858807961690493e080, 1.3694474620720087e083, -9.9070382984295808e085, + 7.5103780796592646e088, -5.9598418264260881e091, 4.9455988887500020e094, + -4.2873596927020241e097, 3.8791952037716163e100, -3.6600317773156342e103, + 3.5978775704117284e106, -3.6818662617467813e109, 3.9192743066421374e112, + -4.3363921885063858e115, 4.9833162711780838e118, -5.9438653020209606e121, + 7.3533439019770134e124, -9.4293465716973561e127, 1.2525196404154548e131, + -1.7223787163994400e134, 2.4505178680729537e137, -3.6051616659014189e140, + 5.4813803836499771e143, -8.6083892012122616e146, 1.3957139354298160e150, + -2.3350508860591630e153, 4.0291297374794860e156, -7.1669946227411534e159, + 1.3136385964069363e163, -2.4799083462304252e166, 4.8198083696385558e169, + -9.6400031196958281e172, 1.9833611905147644e176, -4.1959717912682865e179, + 9.1243724595750010e182, -2.0386902382464212e186, 4.6786408066350383e189, + -1.1024400389046488e193, 2.6662916424238258e196, -6.6165585014771755e199, + 1.6841726974970032e203, -4.3957474813006951e206, 1.1760766011899571e210, + -3.2245094671360478e213, 9.0570855543185808e216, -2.6054618058433054e220, + 7.6741449421726560e223, -2.3136880427961752e227, 7.1382598572408242e230, + -2.2530900128907084e234, 7.2736404696018159e237, -2.4010608416429639e241, + 8.1026279414941787e244, -2.7945745738098571e248, 9.8485095122481192e251, + -3.5456055356238575e255, 1.3036999220919921e259, -4.8948166866453784e262, + 1.8761736309852136e266, -7.3399918877807488e269, 2.9303136033539038e273, + -1.1935494277949469e277, 4.9589310621971370e280, -2.1012240064879845e284, + 9.0784179834777353e287, -3.9987113012775244e291, 1.7952380922182709e295, + -8.2136799002055846e298, 3.8290431596908477e302, -1.8184610414701105e306 +}; + +constexpr bool is_even(int64_t n) noexcept { return n % 2 == 0; } + +} // anonymous namespace + +/// negative Dirichlet eta function +double neg_eta(int64_t n) noexcept +{ + if (n < 0) { + if (is_even(n)) { + return 0.0; + } else if (-(1 + n)/2 < sizeof(NEG_ETA_NEG_N)/sizeof(NEG_ETA_NEG_N[0])) { + return NEG_ETA_NEG_N[-(1 + n)/2]; + } else if (is_even((1 - n)/2)) { + return std::numeric_limits::infinity(); + } else { + return -std::numeric_limits::infinity(); + } + } else if (n == 0) { + return -0.5; + } else if (n <= sizeof(NEG_ETA)/sizeof(NEG_ETA[0])) { + return NEG_ETA[n - 1]; + } else { + return -1.0; + } +} + +} // namespace flexiblesusy diff --git a/src/eta.hpp b/src/eta.hpp new file mode 100644 index 0000000000..00e0ef9bc6 --- /dev/null +++ b/src/eta.hpp @@ -0,0 +1,19 @@ +// ==================================================================== +// This file is part of Polylogarithm. +// +// Polylogarithm is licenced under the MIT License. +// ==================================================================== + +#ifndef ETA_H +#define ETA_H + +#include + +namespace flexiblesusy { + +/// negative Dirichlet eta function for arbitrary integer n +double neg_eta(int64_t) noexcept; + +} // namespace flexiblesusy + +#endif diff --git a/src/factorial.cpp b/src/factorial.cpp new file mode 100644 index 0000000000..0add607987 --- /dev/null +++ b/src/factorial.cpp @@ -0,0 +1,91 @@ +// ==================================================================== +// This file is part of Polylogarithm. +// +// Polylogarithm is licenced under the MIT License. +// ==================================================================== + +#include "factorial.hpp" +#include + +namespace flexiblesusy { + +namespace { + +// 1/n! for integer n = 0, 1, 2, ... +const double INVERSE_FACTORIALS[178] = { + 1.0, 1.0, 0.5 , 1.6666666666666667e-001, 4.1666666666666667e-002, + 8.3333333333333333e-003, 1.3888888888888889e-003, 1.9841269841269841e-004, + 2.4801587301587302e-005, 2.7557319223985891e-006, 2.7557319223985891e-007, + 2.5052108385441719e-008, 2.0876756987868099e-009, 1.6059043836821615e-010, + 1.1470745597729725e-011, 7.6471637318198165e-013, 4.7794773323873853e-014, + 2.8114572543455208e-015, 1.5619206968586226e-016, 8.2206352466243297e-018, + 4.1103176233121649e-019, 1.9572941063391261e-020, 8.8967913924505733e-022, + 3.8681701706306840e-023, 1.6117375710961183e-024, 6.4469502843844734e-026, + 2.4795962632247975e-027, 9.1836898637955461e-029, 3.2798892370698379e-030, + 1.1309962886447717e-031, 3.7699876288159056e-033, 1.2161250415535179e-034, + 3.8003907548547436e-036, 1.1516335620771950e-037, 3.3871575355211618e-039, + 9.6775929586318910e-041, 2.6882202662866364e-042, 7.2654601791530713e-044, + 1.9119632050402819e-045, 4.9024697565135434e-047, 1.2256174391283858e-048, + 2.9893108271424045e-050, 7.1174067312914393e-052, 1.6552108677421952e-053, + 3.7618428812322618e-055, 8.3596508471828040e-057, 1.8173154015614791e-058, + 3.8666285139605939e-060, 8.0554760707512373e-062, 1.6439747083165790e-063, + 3.2879494166331581e-065, 6.4469596404571727e-067, 1.2397999308571486e-068, + 2.3392451525606577e-070, 4.3319354677049217e-072, 7.8762463049180395e-074, + 1.4064725544496499e-075, 2.4674957095607893e-077, 4.2543029475186023e-079, + 7.2106829618959360e-081, 1.2017804936493227e-082, 1.9701319568021683e-084, + 3.1776321883905941e-086, 5.0438606164930064e-088, 7.8810322132703225e-090, + 1.2124664943492804e-091, 1.8370704459837582e-093, 2.7418961880354600e-095, + 4.0322002765227352e-097, 5.8437685166996163e-099, 8.3482407381423090e-101, + 1.1758085546679308e-102, 1.6330674370387928e-104, 2.2370786808750587e-106, + 3.0230792984798090e-108, 4.0307723979730787e-110, 5.3036478920698404e-112, + 6.8878544052855070e-114, 8.8305825708788551e-116, 1.1177952621365639e-117, + 1.3972440776707049e-119, 1.7249926884823518e-121, 2.1036496201004290e-123, + 2.5345176145788301e-125, 3.0172828744986072e-127, 3.5497445582336556e-129, + 4.1276099514344832e-131, 4.7443792545223945e-133, 5.3913400619572665e-135, + 6.0576854628733332e-137, 6.7307616254148146e-139, 7.3964413466096864e-141, + 8.0396101593583548e-143, 8.6447421068369406e-145, 9.1965341562095113e-147, + 9.6805622696942224e-149, 1.0083919030931482e-150, 1.0395792815393280e-152, + 1.0607951852442123e-154, 1.0715102881254669e-156, 1.0715102881254669e-158, + 1.0609012753717494e-160, 1.0400992895801465e-162, 1.0098051355147053e-164, + 9.7096647645644744e-167, 9.2472997757756899e-169, 8.7238677129959339e-171, + 8.1531473953233027e-173, 7.5492105512252803e-175, 6.9258812396562204e-177, + 6.2962556724147458e-179, 5.6723024075808521e-181, 5.0645557210543322e-183, + 4.4819077177471967e-185, 3.9314979980238567e-187, 3.4186939113250928e-189, + 2.9471499235561145e-191, 2.5189315585949697e-193, 2.1346877615211607e-195, + 1.7938552617824880e-197, 1.4948793848187400e-199, 1.2354375081146612e-201, + 1.0126536951759518e-203, 8.2329568713492014e-206, 6.6394813478622592e-208, + 5.3115850782898073e-210, 4.2155437129284185e-212, 3.3193257582113532e-214, + 2.5932232486026197e-216, 2.0102505803121083e-218, 1.5463466002400833e-220, + 1.1804172520916666e-222, 8.9425549400883835e-225, 6.7237255188634463e-227, + 5.0177056110921241e-229, 3.7168189711793512e-231, 2.7329551258671700e-233, + 1.9948577561074233e-235, 1.4455490986285676e-237, 1.0399633803083220e-239, + 7.4283098593451574e-242, 5.2683048647837996e-244, 3.7100738484392955e-246, + 2.5944572366708360e-248, 1.8017064143547472e-250, 1.2425561478308602e-252, + 8.5106585467867134e-255, 5.7895636372698731e-257, 3.9118673224796440e-259, + 2.6254143103890228e-261, 1.7502762069260152e-263, 1.1591233158450432e-265, + 7.6258112884542314e-268, 4.9841903846106088e-270, 3.2364872627341615e-272, + 2.0880562985381687e-274, 1.3384976272680569e-276, 8.5254625940640566e-279, + 5.3958624013063649e-281, 3.3936241517650094e-283, 2.1210150948531309e-285, + 1.3174006800330005e-287, 8.1321029631666700e-290, 4.9890202228016380e-292, + 3.0420855017083159e-294, 1.8436881828535248e-296, 1.1106555318394728e-298, + 6.6506319271824716e-301, 3.9587094804657569e-303, 2.3424316452460100e-305, + 1.3779009677917706e-307, 8.0579003964431028e-310, 4.6848258118855249e-312, + 2.7079917987777601e-314, 1.5563171257343449e-316, 8.8932407184819707e-319, + 5.0529776809556651e-321, 2.8547896502574379e-323 +}; + +} // anonymous namespace + +/// negative Dirichlet eta function +double inv_fac(int64_t n) noexcept +{ + if (n < 0) { + return std::numeric_limits::quiet_NaN(); + } else if (n < sizeof(INVERSE_FACTORIALS)/sizeof(INVERSE_FACTORIALS[0])) { + return INVERSE_FACTORIALS[n]; + } else { + return 0.0; + } +} + +} // namespace flexiblesusy diff --git a/src/factorial.hpp b/src/factorial.hpp new file mode 100644 index 0000000000..d32c4801dc --- /dev/null +++ b/src/factorial.hpp @@ -0,0 +1,19 @@ +// ==================================================================== +// This file is part of Polylogarithm. +// +// Polylogarithm is licenced under the MIT License. +// ==================================================================== + +#ifndef FACTORIAL_H +#define FACTORIAL_H + +#include + +namespace flexiblesusy { + +/// returns 1/n! for n >= 0 +double inv_fac(int64_t) noexcept; + +} // namespace flexiblesusy + +#endif diff --git a/src/harmonic.cpp b/src/harmonic.cpp new file mode 100644 index 0000000000..1756ae9a62 --- /dev/null +++ b/src/harmonic.cpp @@ -0,0 +1,70 @@ +// ==================================================================== +// This file is part of Polylogarithm. +// +// Polylogarithm is licenced under the MIT License. +// ==================================================================== + +#include "harmonic.hpp" +#include +#include + +namespace flexiblesusy { + +namespace { + +/// digamma for integer n > 0, following +/// [K.S. Kölbig: Programs for computing the logarithm of the gamma +/// function, and the digamma function, for complex argument, Computer +/// Physics Communications, Volume 4, Issue 2, 1972, Pages 221-226, ISSN +/// 0010-4655, https://doi.org/10.1016/0010-4655(72)90012-4] +double digamma(int64_t n) noexcept +{ + // Table[BernoulliB[2n]/(2 n), {n,1,8}] + const double c[] = { + 0.083333333333333333, -0.0083333333333333333, 0.0039682539682539683, + -0.0041666666666666667, 0.0075757575757575758, -0.021092796092796093, + 0.083333333333333333, -0.44325980392156863 + }; + + if (n <= 0) { + return std::numeric_limits::quiet_NaN(); + } + + double res = 0; + + // map potentially small n to n >= 7 + if (n < 7) { // recurrence formula + for (int64_t nu = 1; nu < 7 - n; ++nu) { + res -= 1.0/(n + nu); + } + res -= 1.0/n; + n = 7.0; + } + + const double t = 1.0/n; + const double t2 = t*t; + + return res + std::log(n) - 0.5*t + - t2*(c[0] + t2*(c[1] + t2*(c[2] + t2*(c[3] + t2*(c[4] + t2*(c[5] + t2*(c[6] + t2*c[7]))))))); +} + +} // anonymous namespace + +/// harmonic number n +double harmonic(int64_t n) noexcept +{ + if (n <= 0) { + return std::numeric_limits::quiet_NaN(); + } else if (n < 20) { + double sum = 1; + for (int64_t k = 2; k <= n; ++k) { + sum += 1.0/k; + } + return sum; + } else { + const double eulergamma = 0.57721566490153286; + return eulergamma + digamma(n + 1); + } +} + +} // namespace flexiblesusy diff --git a/src/harmonic.hpp b/src/harmonic.hpp new file mode 100644 index 0000000000..4a73a3e4bc --- /dev/null +++ b/src/harmonic.hpp @@ -0,0 +1,19 @@ +// ==================================================================== +// This file is part of Polylogarithm. +// +// Polylogarithm is licenced under the MIT License. +// ==================================================================== + +#ifndef HARMONIC_H +#define HARMONIC_H + +#include + +namespace flexiblesusy { + +/// Harmonic number +double harmonic(int64_t) noexcept; + +} // namespace flexiblesusy + +#endif diff --git a/src/module.mk b/src/module.mk index 447683fe50..590d54883b 100644 --- a/src/module.mk +++ b/src/module.mk @@ -10,6 +10,7 @@ LIBFLEXI_SRC := \ $(DIR)/build_info.cpp \ $(DIR)/bvp_solver_problems.cpp \ $(DIR)/ckm.cpp \ + $(DIR)/Cl2.cpp \ $(DIR)/command_line_options.cpp \ $(DIR)/composite_convergence_tester.cpp \ $(DIR)/coupling_monitor.cpp \ @@ -19,14 +20,21 @@ LIBFLEXI_SRC := \ $(DIR)/decays/decay_functions.cpp \ $(DIR)/decays/flexibledecay_settings.cpp \ $(DIR)/decays/one_loop_decay_diagrams.cpp \ - $(DIR)/dilog.cpp \ + $(DIR)/eta.cpp \ + $(DIR)/factorial.cpp \ $(DIR)/global_thread_pool.cpp \ $(DIR)/gm2calc_interface.cpp \ $(DIR)/gsl_multimin_fminimizer.cpp \ $(DIR)/gsl_multiroot_fsolver.cpp \ $(DIR)/gsl_utils.cpp \ $(DIR)/gsl_vector.cpp \ + $(DIR)/harmonic.cpp \ + $(DIR)/Li.cpp \ + $(DIR)/Li2.cpp \ + $(DIR)/Li3.cpp \ $(DIR)/Li4.cpp \ + $(DIR)/Li5.cpp \ + $(DIR)/Li6.cpp \ $(DIR)/logger.cpp \ $(DIR)/loop_libraries/library_softsusy.cpp \ $(DIR)/lowe.cpp \ @@ -52,8 +60,8 @@ LIBFLEXI_SRC := \ $(DIR)/string_utils.cpp \ $(DIR)/threshold_corrections.cpp \ $(DIR)/threshold_loop_functions.cpp \ - $(DIR)/trilog.cpp \ - $(DIR)/wrappers.cpp + $(DIR)/wrappers.cpp \ + $(DIR)/zeta.cpp LIBFLEXI_HDR := \ $(DIR)/array_view.hpp \ @@ -64,6 +72,7 @@ LIBFLEXI_HDR := \ $(DIR)/bvp_solver_problems_format_mathlink.hpp \ $(DIR)/cextensions.hpp \ $(DIR)/ckm.hpp \ + $(DIR)/Cl2.hpp \ $(DIR)/command_line_options.hpp \ $(DIR)/complex.hpp \ $(DIR)/composite_convergence_tester.hpp \ @@ -81,12 +90,13 @@ LIBFLEXI_HDR := \ $(DIR)/decays/flexibledecay_settings.hpp \ $(DIR)/decays/one_loop_decay_diagrams.hpp \ $(DIR)/derivative.hpp \ - $(DIR)/dilog.hpp \ $(DIR)/eigen_utils.hpp \ $(DIR)/eigen_tensor.hpp \ $(DIR)/error.hpp \ + $(DIR)/eta.hpp \ $(DIR)/ew_input.hpp \ $(DIR)/ewsb_solver.hpp \ + $(DIR)/factorial.hpp \ $(DIR)/find_if.hpp \ $(DIR)/fixed_point_iterator.hpp \ $(DIR)/for_each.hpp \ @@ -98,10 +108,16 @@ LIBFLEXI_HDR := \ $(DIR)/gsl_multiroot_fsolver.hpp \ $(DIR)/gsl_utils.hpp \ $(DIR)/gsl_vector.hpp \ - $(DIR)/Li4.hpp \ + $(DIR)/harmonic.hpp \ $(DIR)/loop_corrections.hpp \ $(DIR)/if.hpp \ $(DIR)/initial_guesser.hpp \ + $(DIR)/Li.hpp \ + $(DIR)/Li2.hpp \ + $(DIR)/Li3.hpp \ + $(DIR)/Li4.hpp \ + $(DIR)/Li5.hpp \ + $(DIR)/Li6.hpp \ $(DIR)/linalg2.hpp \ $(DIR)/logger.hpp \ $(DIR)/lowe.h \ @@ -144,9 +160,9 @@ LIBFLEXI_HDR := \ $(DIR)/thread_pool.hpp \ $(DIR)/threshold_corrections.hpp \ $(DIR)/threshold_loop_functions.hpp \ - $(DIR)/trilog.hpp \ $(DIR)/which.hpp \ - $(DIR)/wrappers.hpp + $(DIR)/wrappers.hpp \ + $(DIR)/zeta.hpp ifneq ($(findstring two_scale,$(SOLVERS)),) LIBFLEXI_SRC += \ diff --git a/src/threshold_loop_functions.cpp b/src/threshold_loop_functions.cpp index 64b693e963..4623b09bd2 100644 --- a/src/threshold_loop_functions.cpp +++ b/src/threshold_loop_functions.cpp @@ -17,7 +17,8 @@ // ==================================================================== #include "threshold_loop_functions.hpp" -#include "dilog.hpp" +#include "Cl2.hpp" +#include "Li2.hpp" #include "loop_libraries/loop_library.hpp" #include "logger.hpp" #include "numerics.h" @@ -1306,7 +1307,7 @@ double fth3(double y) noexcept const double ly = std::log(y2); return (-1. + 2*y2 + 2*y4) - *(-z2 - y2*ly + ly*std::log(1. - y2) + dilog(y2)) + *(-z2 - y2*ly + ly*std::log(1. - y2) + Li2(y2)) / sqr(1 - y2); } @@ -1962,21 +1963,21 @@ namespace { if (is_equal(u, v, eps)) { return (- sqr(std::log(u)) + 2*sqr(std::log(0.5*(1 - lambda))) - - 4*dilog(0.5*(1 - lambda)) + - 4*Li2(0.5*(1 - lambda)) + pi23)/lambda; } return (- std::log(u)*std::log(v) + 2*std::log(0.5*(1 - lambda + u - v))*std::log(0.5*(1 - lambda - u + v)) - - 2*dilog(0.5*(1 - lambda + u - v)) - - 2*dilog(0.5*(1 - lambda - u + v)) + - 2*Li2(0.5*(1 - lambda + u - v)) + - 2*Li2(0.5*(1 - lambda - u + v)) + pi23)/lambda; } - /// clausen_2(2*acos(x)) + /// Cl2(2*acos(x)) double cl2acos(double x) noexcept { - return clausen_2(2*std::acos(x)); + return Cl2(2*std::acos(x)); } /// lambda^2(u,v) < 0, u = 1 @@ -1998,7 +1999,7 @@ namespace { const auto lambda = std::sqrt(-lambda_2(u,v)); if (is_equal(u, v, eps)) { - return 4*clausen_2(2*std::asin(std::sqrt(0.25/u)))/lambda; + return 4*Cl2(2*std::asin(std::sqrt(0.25/u)))/lambda; } if (is_equal(u, 1.0, eps)) { diff --git a/src/wrappers.cpp b/src/wrappers.cpp index aeab25138a..30e4fc5247 100644 --- a/src/wrappers.cpp +++ b/src/wrappers.cpp @@ -17,11 +17,12 @@ // ==================================================================== #include "wrappers.hpp" -#include "dilog.hpp" +#include "Li2.hpp" +#include "Li3.hpp" #include "Li4.hpp" +#include "Li.hpp" #include "numerics2.hpp" #include "string_format.hpp" -#include "trilog.hpp" #include #include @@ -145,8 +146,8 @@ double PolyLog(int n, double z) noexcept { switch (n) { case 1: return -std::log(1.0 - z); - case 2: return dilog(z); - case 3: return trilog(z); + case 2: return Li2(z); + case 3: return Li3(z); case 4: return Li4(z); default: break; } @@ -156,17 +157,7 @@ double PolyLog(int n, double z) noexcept std::complex PolyLog(int n, const std::complex& z) noexcept { - switch (n) { - case 1: return -std::log(1.0 - z); - case 2: return dilog(z); - case 3: return trilog(z); - case 4: return Li4(z); - default: break; - } - - ERROR("PolyLog(n != 1|2|3|4) not implemented"); - - return { 0.0, 0.0 }; + return Li(n, z); } double Re(double x) noexcept diff --git a/src/zeta.cpp b/src/zeta.cpp new file mode 100644 index 0000000000..18d9623f69 --- /dev/null +++ b/src/zeta.cpp @@ -0,0 +1,106 @@ +// ==================================================================== +// This file is part of Polylogarithm. +// +// Polylogarithm is licenced under the MIT License. +// ==================================================================== + +#include "zeta.hpp" +#include +#include + +namespace flexiblesusy { + +namespace { + +// zeta(n) for n = 2,...,33 +const double ZETAS_POS[32] = { + 1.6449340668482264, 1.2020569031595943, 1.0823232337111382, + 1.0369277551433699, 1.0173430619844491, 1.0083492773819228, + 1.0040773561979443, 1.0020083928260822, 1.0009945751278181, + 1.0004941886041195, 1.0002460865533080, 1.0001227133475785, + 1.0000612481350587, 1.0000305882363070, 1.0000152822594087, + 1.0000076371976379, 1.0000038172932650, 1.0000019082127166, + 1.0000009539620339, 1.0000004769329868, 1.0000002384505027, + 1.0000001192199260, 1.0000000596081891, 1.0000000298035035, + 1.0000000149015548, 1.0000000074507118, 1.0000000037253340, + 1.0000000018626597, 1.0000000009313274, 1.0000000004656629, + 1.0000000002328312, 1.0000000001164155 +}; + +// zeta(1 - 2n) for n = 1,...,130, i.e. zeta(-1), zeta(-3), zeta(-5), ... +const double ZETAS_NEG[130] = { + -8.3333333333333333e-02, 8.3333333333333333e-03, -3.9682539682539683e-03, + 4.1666666666666667e-03, -7.5757575757575758e-03, 2.1092796092796093e-02, + -8.3333333333333333e-02, 4.4325980392156863e-01, -3.0539543302701197e000, + 2.6456212121212121e001, -2.8146014492753623e002, 3.6075105463980464e003, + -5.4827583333333333e004, 9.7493682385057471e005, -2.0052695796688079e007, + 4.7238486772162990e008, -1.2635724795916667e010, 3.8087931125245369e011, + -1.2850850499305083e013, 4.8241448354850170e014, -2.0040310656516253e016, + 9.1677436031953308e017, -4.5979888343656503e019, 2.5180471921451096e021, + -1.5001733492153929e023, 9.6899578874635941e024, -6.7645882379292821e026, + 5.0890659468662290e028, -4.1147288792557979e030, 3.5666582095375556e032, + -3.3066089876577577e034, 3.2715634236478716e036, -3.4473782558278054e038, + 3.8614279832705259e040, -4.5892974432454332e042, 5.7775386342770432e044, + -7.6919858759507135e046, 1.0813635449971655e049, -1.6029364522008965e051, + 2.5019479041560463e053, -4.1067052335810212e055, 7.0798774408494581e057, + -1.2804546887939509e060, 2.4267340392333524e062, -4.8143218874045769e064, + 9.9875574175727531e066, -2.1645634868435186e069, 4.8962327039620553e071, + -1.1549023923963520e074, 2.8382249570693707e076, -7.2612008803606716e078, + 1.9323514233419812e081, -5.3450160425288624e083, 1.5356028846422423e086, + -4.5789872682265798e088, 1.4162025212194809e091, -4.5400652296092655e093, + 1.5076656758807860e096, -5.1830949148264564e098, 1.8435647427256529e101, + -6.7805554753090959e103, 2.5773326702754605e106, -1.0119112875704598e109, + 4.1016346161542292e111, -1.7155244534032019e114, 7.4003425705269094e116, + -3.2909225357054443e119, 1.5079831534164771e122, -7.1169879188254549e124, + 3.4580429141577772e127, -1.7290907606676748e130, 8.8936991695032969e132, + -4.7038470619636015e135, 2.5571938231060206e138, -1.4284067500443528e141, + 8.1952152218313783e143, -4.8276485422727372e146, 2.9189612374770324e149, + -1.8108932162568904e152, 1.1523577220021169e155, -7.5192311951981770e157, + 5.0294016576411050e160, -3.4473420444477677e163, 2.4207458645868515e166, + -1.7409465920377677e169, 1.2819489863482243e172, -9.6624121108560918e174, + 7.4526910304300896e177, -5.8808393311674371e180, 4.7462718654907615e183, + -3.9169132594772825e186, 3.3045071443226032e189, -2.8492890550994583e192, + 2.5103329345077587e195, -2.2593901995475253e198, 2.0769138004287608e201, + -1.9494732174927259e204, 1.8680731471265914e207, -1.8270752662814577e210, + 1.8235386322595677e213, -1.8568690810125945e216, 1.9287189851195602e219, + -2.0431170460286448e222, 2.2068411644527846e225, -2.4300821796490274e228, + 2.7274887879083470e231, -3.1197421573755085e234, 3.6358938724282600e237, + -4.3168300030760883e240, 5.2204244879387200e243, -6.4292606949769305e246, + 8.0623033870130844e249, -1.0292714737903011e253, 1.3375329699780524e256, + -1.7689480902797380e259, 2.3806479018092397e262, -3.2597127947194185e265, + 4.5404962371601213e268, -6.4328575193147851e271, 9.2687048675749311e274, + -1.3579619500285181e278, 2.0227839736049322e281, -3.0629906992208336e284, + 4.7143085300742652e287, -7.3741045871355758e290, 1.1720962767050827e294, + -1.8928866644685657e297, 3.1055517596048927e300, -5.1754977470366798e303, + 8.7601563446229215e306 +}; + +constexpr bool is_even(int64_t n) noexcept { return n % 2 == 0; } + +} // anonymous namespace + +/// Riemann zeta function for integer arguments +double zeta(int64_t n) noexcept +{ + if (n < 0) { + if (is_even(n)) { + return 0.0; + } else if (-(1 + n)/2 < sizeof(ZETAS_NEG)/sizeof(ZETAS_NEG[0])) { + return ZETAS_NEG[-(1 + n)/2]; + } else if (is_even((1 - n)/2)) { + return std::numeric_limits::infinity(); + } else { + return -std::numeric_limits::infinity(); + } + } else if (n == 0) { + return -0.5; + } else if (n == 1) { + return std::numeric_limits::infinity(); + } else if ((n - 2) < sizeof(ZETAS_POS)/sizeof(ZETAS_POS[0])) { + return ZETAS_POS[n - 2]; + } + + return 1.0/(1.0 - std::pow(0.5, n)); +} + +} // namespace flexiblesusy diff --git a/src/zeta.hpp b/src/zeta.hpp new file mode 100644 index 0000000000..8c7e8d8767 --- /dev/null +++ b/src/zeta.hpp @@ -0,0 +1,19 @@ +// ==================================================================== +// This file is part of Polylogarithm. +// +// Polylogarithm is licenced under the MIT License. +// ==================================================================== + +#ifndef ZETA_H +#define ZETA_H + +#include + +namespace flexiblesusy { + +/// Riemann zeta function for arbitrary integer n +double zeta(int64_t) noexcept; + +} // namespace flexiblesusy + +#endif diff --git a/templates/a_muon.cpp.in b/templates/a_muon.cpp.in index 9c27455660..98c38944d8 100644 --- a/templates/a_muon.cpp.in +++ b/templates/a_muon.cpp.in @@ -29,11 +29,11 @@ #include "cxx_qft/@ModelName@_qft.hpp" #include "@ModelName@_FFV_form_factors.hpp" +#include "Li2.hpp" #include "lowe.h" #include "wrappers.hpp" #include "numerics2.hpp" #include "logger.hpp" -#include "dilog.hpp" #define DERIVEDPARAMETER(p) context.model.p() @@ -179,7 +179,7 @@ double BarZeeLoopFPS(double m) { r2 *= -1; theta2 = Pi; } - return m / y * (dilog(std::polar(r1, theta1)).real() - dilog(std::polar(r2, theta2)).real()); + return m / y * (Li2(std::polar(r1, theta1)).real() - Li2(std::polar(r2, theta2)).real()); } else { const double y = std::sqrt(-1.0+4.0*m); @@ -189,7 +189,7 @@ double BarZeeLoopFPS(double m) { theta1 = std::atan2(y/(2*m), real); theta2 = std::atan2(-y/(2*m), real); - return m / y * (dilog(std::polar(r1, theta1)).imag() - dilog(std::polar(r2, theta2)).imag()); + return m / y * (Li2(std::polar(r1, theta1)).imag() - Li2(std::polar(r2, theta2)).imag()); } } @@ -246,7 +246,7 @@ double BarZeeLoopV(const double m) { theta2 = std::atan2(0, r2); r2 = std::abs(r2); - j = 1/y * (std::log(std::abs(y-1) / (y+1)) * std::log(m) + dilog(std::polar(r1, theta1)).real() - dilog(std::polar(r2, theta2)).real()); + j = 1/y * (std::log(std::abs(y-1) / (y+1)) * std::log(m) + Li2(std::polar(r1, theta1)).real() - Li2(std::polar(r2, theta2)).real()); } else { const double y = std::sqrt(-1.0+4.0*m); @@ -255,7 +255,7 @@ double BarZeeLoopV(const double m) { const double imag = y/(2*m); theta1 = std::atan2(imag, real); theta2 = std::atan2(-imag, real); - j = 1/y * ( (std::atan2(y, -1) - std::atan2(y, 1)) * std::log(m) + dilog(std::polar(r1, theta1)).imag() - dilog(std::polar(r2, theta2)).imag()); + j = 1/y * ( (std::atan2(y, -1) - std::atan2(y, 1)) * std::log(m) + Li2(std::polar(r1, theta1)).imag() - Li2(std::polar(r2, theta2)).imag()); } return BarZeeLoopS(m) + 15.0/2.0 * m * (2.0 + std::log(m)) + m/2 * (19 - 12*m) * j - 9*m * BarZeeLoopFPS(m); diff --git a/templates/decays/decays.cpp.in b/templates/decays/decays.cpp.in index 49e460ce62..b8aac4db89 100644 --- a/templates/decays/decays.cpp.in +++ b/templates/decays/decays.cpp.in @@ -42,8 +42,8 @@ #include "decays/one_loop_decay_diagrams.hpp" #include "concatenate.hpp" #include "decays/decay_functions.hpp" -#include "dilog.hpp" -#include "trilog.hpp" +#include "Li2.hpp" +#include "Li3.hpp" #include "Li4.hpp" #include "config.h" #include "thread_pool.hpp" diff --git a/test/SOFTSUSY/numerics_legacy.cpp b/test/SOFTSUSY/numerics_legacy.cpp index 1d0529ad0f..8656563e9e 100644 --- a/test/SOFTSUSY/numerics_legacy.cpp +++ b/test/SOFTSUSY/numerics_legacy.cpp @@ -7,7 +7,7 @@ */ #include "numerics_legacy.h" -#include "dilog.hpp" +#include "Li2.hpp" #include "utils.h" #include #include @@ -92,11 +92,11 @@ double findMinimum(double ax, double bx, double cx, double (*f)(double), } double dilog(double x) { - return flexiblesusy::dilog(x); + return flexiblesusy::Li2(x); } Complex dilog(const Complex& x) { - return flexiblesusy::dilog(x); + return flexiblesusy::Li2(x); } double fps(double z) { diff --git a/test/test_threshold_loop_functions.cpp b/test/test_threshold_loop_functions.cpp index e938580c61..927ba8c013 100644 --- a/test/test_threshold_loop_functions.cpp +++ b/test/test_threshold_loop_functions.cpp @@ -24,7 +24,7 @@ #include "config.h" #include "threshold_loop_functions.hpp" #include "numerics.h" -#include "dilog.hpp" +#include "Li2.hpp" #include "logger.hpp" #include "benchmark.hpp" @@ -1264,7 +1264,7 @@ double phixyz(double x, double y, double z) return std::real(fac * 1. / lambda_c * (2. * std::log(xplus_c) * std::log(xminus_c) - std::log(u) * std::log(v) - - 2. * (dilog(xplus_c) + dilog(xminus_c)) + + 2. * (Li2(xplus_c) + Li2(xminus_c)) + sqr(PI) / 3.)); } @@ -1289,7 +1289,7 @@ double phixyz(double x, double y, double z) 2. * sqr(std::log(0.5 - 0.5 * complex_sqrt(1. - 4. * my_x / my_z))) - sqr(std::log(my_x / my_z)) - - 4. * dilog(0.5 * + 4. * Li2(0.5 * (1. - complex_sqrt(sqr(1 - 2. * my_x / my_z) - 4. * sqr(my_x) / (sqr(my_z))))))); } @@ -1312,10 +1312,10 @@ double phixyz(double x, double y, double z) std::log(1. - my_x / (2. * my_z) - 0.5 * complex_sqrt((sqr(my_x) - 4. * my_x * my_z) / sqr(my_z))) - - 6. * dilog(0.5 * (2. - complex_sqrt(sqr(my_x) / sqr(my_z) - + 6. * Li2(0.5 * (2. - complex_sqrt(sqr(my_x) / sqr(my_z) - 4. * my_x / my_z) - my_x / my_z)) - - 6. * dilog(0.5 * (-complex_sqrt(sqr(my_x) / sqr(my_z) - + 6. * Li2(0.5 * (-complex_sqrt(sqr(my_x) / sqr(my_z) - 4. * my_x / my_z) + my_x / my_z)))); } @@ -1337,7 +1337,7 @@ double phixyz(double x, double y, double z) 2. * sqr(std::log(0.5 - 0.5 * complex_sqrt(1. - 4. * my_x / my_z))) - sqr(std::log(my_x / my_z)) - - 4. * dilog(0.5 * + 4. * Li2(0.5 * (1. - complex_sqrt(sqr(1 - 2. * my_x / my_z) - 4. * sqr(my_x) / (sqr(my_z))))))); } @@ -1359,10 +1359,10 @@ double phixyz(double x, double y, double z) std::log(1. - my_x / (2. * my_z) - 0.5 * complex_sqrt((sqr(my_x) - 4. * my_x * my_z) / sqr(my_z))) - - 6. * dilog(0.5 * (2. - complex_sqrt(sqr(my_x) / sqr(my_z) - + 6. * Li2(0.5 * (2. - complex_sqrt(sqr(my_x) / sqr(my_z) - 4. * my_x / my_z) - my_x / my_z)) - - 6. * dilog(0.5 * (-complex_sqrt(sqr(my_x) / sqr(my_z) - + 6. * Li2(0.5 * (-complex_sqrt(sqr(my_x) / sqr(my_z) - 4. * my_x / my_z) + my_x / my_z)))); } @@ -1388,10 +1388,10 @@ double phixyz(double x, double y, double z) std::log(1. - my_x / (2. * my_z) - 0.5 * complex_sqrt((sqr(my_x) - 4. * my_x * my_z) / sqr(my_z))) - - 6. * dilog(0.5 * (2. - complex_sqrt(sqr(my_x) / sqr(my_z) - + 6. * Li2(0.5 * (2. - complex_sqrt(sqr(my_x) / sqr(my_z) - 4. * my_x / my_z) - my_x / my_z)) - - 6. * dilog(0.5 * (-complex_sqrt(sqr(my_x) / sqr(my_z) - + 6. * Li2(0.5 * (-complex_sqrt(sqr(my_x) / sqr(my_z) - 4. * my_x / my_z) + my_x / my_z)))); } @@ -1408,7 +1408,7 @@ double phixyz(double x, double y, double z) 2. * sqr(std::log(0.5 - 0.5 * complex_sqrt(1. - 4. * my_x / my_z))) - sqr(std::log(my_x / my_z)) - - 4. * dilog(0.5 * + 4. * Li2(0.5 * (1. - complex_sqrt(sqr(1 - 2. * my_x / my_z) - 4. * sqr(my_x) / (sqr(my_z))))))); } From ed649330ba8696c7e6bb3278df5bf61b9da51513 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 12 May 2022 15:53:16 +0200 Subject: [PATCH 137/477] removed unneeded includes --- templates/decays/decays.cpp.in | 3 --- 1 file changed, 3 deletions(-) diff --git a/templates/decays/decays.cpp.in b/templates/decays/decays.cpp.in index b8aac4db89..8bda319489 100644 --- a/templates/decays/decays.cpp.in +++ b/templates/decays/decays.cpp.in @@ -42,9 +42,6 @@ #include "decays/one_loop_decay_diagrams.hpp" #include "concatenate.hpp" #include "decays/decay_functions.hpp" -#include "Li2.hpp" -#include "Li3.hpp" -#include "Li4.hpp" #include "config.h" #include "thread_pool.hpp" #include "wrappers.hpp" From 9859d9d363f123bd25f0240fcbc70a83241c8236 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 12 May 2022 18:30:43 +0200 Subject: [PATCH 138/477] missing semicolons in code example --- README.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.rst b/README.rst index 4b2d1f5668..d5a3eac2f4 100644 --- a/README.rst +++ b/README.rst @@ -369,10 +369,10 @@ Example ]; (* calculate pole mass spectrum *) - FSCMSSMCalculateSpectrum[handle] + FSCMSSMCalculateSpectrum[handle]; (* calculate observables *) - FSCMSSMCalculateObservables[handle] + FSCMSSMCalculateObservables[handle]; (* close the model handle *) FSCMSSMCloseHandle[handle]; From 68149f84a97ac4f41179846ccdd1ccd3eb491b06 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Sun, 15 May 2022 19:35:24 +0200 Subject: [PATCH 139/477] update slhaea.h fixes #437 --- slhaea/slhaea.h | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/slhaea/slhaea.h b/slhaea/slhaea.h index d7f34dcd2e..1c8bde6f33 100644 --- a/slhaea/slhaea.h +++ b/slhaea/slhaea.h @@ -1525,7 +1525,7 @@ class Block { std::for_each(begin(), end(), MEM_FN(&value_type::uncomment)); } /** Unary predicate that checks if a provided key matches a Line. */ - struct key_matches : public std::unary_function + struct key_matches { explicit key_matches(const key_type& key) : key_(key) {} @@ -2351,7 +2351,7 @@ class Coll * Unary predicate that checks if a provided name matches the name * of a Block. */ - struct key_matches : public std::unary_function + struct key_matches { explicit key_matches(const key_type& blockName) : name_(blockName) {} @@ -2372,7 +2372,7 @@ class Coll * Unary predicate that checks if a provided key matches the block * definition of a Block. */ - struct key_matches_block_def : public std::unary_function + struct key_matches_block_def { explicit key_matches_block_def(const value_type::key_type& key) From cc7948c387967534e912f5f8f4f8c7b631852cf9 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 18 May 2022 10:30:44 +0200 Subject: [PATCH 140/477] add to warning the info about source of Ward identity violation (#434) --- src/decays/decay_amplitudes.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/decays/decay_amplitudes.cpp b/src/decays/decay_amplitudes.cpp index 30fb55f120..ddadc02be3 100644 --- a/src/decays/decay_amplitudes.cpp +++ b/src/decays/decay_amplitudes.cpp @@ -82,7 +82,7 @@ double Decay_amplitude_SVV::square() const if (WI_violation > 0.1) { std::stringstream ss; ss << std::setprecision(2) << 100.*WI_violation; - WARNING("Warning: Ward identity violated in decay of scalar to massless vectors by " + ss.str() + "%"); + WARNING("Warning: Ward identity violated in decay of scalar to massless vectors by " + ss.str() + "% due to higher order effects"); } // use res1 since form_factor_21 is not sensitive to the renormalization // scheme in which the Higgs mass is defined @@ -116,7 +116,7 @@ double Decay_amplitude_SVV::square() const if (WI_violation > 0.1) { std::stringstream ss; ss << std::setprecision(2) << 100.*WI_violation; - WARNING("Warning: Ward identity violated in decay of scalar to massless and massive vector by " + ss.str() + "%"); + WARNING("Warning: Ward identity violated in decay of scalar to massless and massive vector by " + ss.str() + "% due to higher order effects"); } // use res1 since form_factor_21 is not sensitive to the renormalization // scheme in which the Higgs mass is defined From 5481baff90f0db3bca97f8e6fd8116f9f3ef7079 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 14 Apr 2022 12:10:13 +0200 Subject: [PATCH 141/477] removed unused input in MSSMMuBMu --- model_files/MSSMMuBMu/FlexibleSUSY.m.in | 4 ---- model_files/MSSMMuBMu/LesHouches.in.MSSMMuBMu | 2 -- 2 files changed, 6 deletions(-) diff --git a/model_files/MSSMMuBMu/FlexibleSUSY.m.in b/model_files/MSSMMuBMu/FlexibleSUSY.m.in index 7c00fabfac..ad23ec561d 100644 --- a/model_files/MSSMMuBMu/FlexibleSUSY.m.in +++ b/model_files/MSSMMuBMu/FlexibleSUSY.m.in @@ -3,10 +3,6 @@ FSEigenstates = SARAH`EWSB; FSDefaultSARAHModel = MSSM; OnlyLowEnergyFlexibleSUSY = True; -MINPAR = { - {4, Sign[\[Mu]]} -}; - EXTPAR = { {0, MSUSY}, {1, M1Input}, diff --git a/model_files/MSSMMuBMu/LesHouches.in.MSSMMuBMu b/model_files/MSSMMuBMu/LesHouches.in.MSSMMuBMu index 720eb49af0..b43e2c43b1 100644 --- a/model_files/MSSMMuBMu/LesHouches.in.MSSMMuBMu +++ b/model_files/MSSMMuBMu/LesHouches.in.MSSMMuBMu @@ -51,8 +51,6 @@ Block SMINPUTS # Standard Model inputs 22 2.400000000e-03 # mu(2 GeV) MS-bar 23 1.040000000e-01 # ms(2 GeV) MS-bar 24 1.270000000e+00 # mc(mc) MS-bar -Block MINPAR # Input parameters - 4 1 # SignMu Block EXTPAR 0 2000 # Ms 1 2000 # M1(MSUSY) From 02f0d27e6d8bbf1dc95c90d1b53ba5787bbab9c8 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 26 May 2022 17:05:04 +0200 Subject: [PATCH 142/477] reserve known size of the vector --- templates/slha_io.cpp.in | 3 +++ 1 file changed, 3 insertions(+) diff --git a/templates/slha_io.cpp.in b/templates/slha_io.cpp.in index 6c8f4cf150..5dbeb3062a 100644 --- a/templates/slha_io.cpp.in +++ b/templates/slha_io.cpp.in @@ -415,9 +415,11 @@ void @ModelName@_slha_io::set_dcinfo( */ std::vector sort_decays_list(const Decays_list& decays_list) { std::vector decays_list_as_vector; + decays_list_as_vector.reserve(decays_list.size()); for (const auto& el : decays_list) { decays_list_as_vector.push_back(el.second); } + std::sort( decays_list_as_vector.begin(), decays_list_as_vector.end(), @@ -425,6 +427,7 @@ std::vector sort_decays_list(const Decays_list& decays_list) { return d1.get_width() > d2.get_width(); } ); + return decays_list_as_vector; } From bd54134a75e2a57655ea60635835a437e3436a64 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Mon, 6 Jun 2022 13:50:50 +0200 Subject: [PATCH 143/477] Refinements for the BSM W boson pole mass prediction (#409) * using MS-bar fit formula for the SM W boson mass prediction from arXiv:1411.7040 * use model-specific SM-like Higgs pole mass in the calculation of MW in the fit formula Co-authored-by: Wojciech Kotlarski --- CHANGES.rst | 10 + README.rst | 6 +- configure | 4 +- meta/FlexibleSUSY.m | 3 + meta/LoopMasses.m | 21 ++ meta/ThresholdCorrections.m | 16 +- model_specific/SM/module.mk | 2 + model_specific/SM/sm_mw.cpp | 188 ++++++++++++++++++ model_specific/SM/sm_mw.hpp | 36 ++++ model_specific/SM/standard_model.cpp | 23 ++- model_specific/SM/standard_model.hpp | 3 +- ...d_model_two_scale_low_scale_constraint.cpp | 11 +- model_specific/SM/weinberg_angle.cpp | 26 +++ model_specific/SM/weinberg_angle.hpp | 7 + src/ew_input.hpp | 3 +- ...semi_analytic_susy_scale_constraint.cpp.in | 1 + ..._scale_low_scale_spectrum_generator.cpp.in | 1 + .../two_scale_susy_scale_constraint.cpp.in | 1 + templates/weinberg_angle.cpp.in | 12 +- templates/weinberg_angle.hpp.in | 6 +- test/module.mk | 1 + ...MSSMCKM_b_to_s_gamma_internal_spectrum.cpp | 8 +- test/test_CMSSMNoFV_benchmark.cpp | 2 - test/test_CMSSM_mw_calculation.cpp | 44 +++- test/test_MRSSM2CKM_b_to_s_gamma.cpp | 8 +- test/test_MRSSM2_gmm2.cpp | 4 +- test/test_MRSSM2_mw_calculation.cpp | 41 +++- test/test_SM_low_scale_constraint.cpp | 5 + test/test_SM_mw_calculation.cpp | 22 +- test/test_complex_equality.hpp | 18 +- test/test_sm_mw.cpp | 43 ++++ 31 files changed, 517 insertions(+), 59 deletions(-) create mode 100644 model_specific/SM/sm_mw.cpp create mode 100644 model_specific/SM/sm_mw.hpp create mode 100644 test/test_sm_mw.cpp diff --git a/CHANGES.rst b/CHANGES.rst index db55844416..aa5c51d2d7 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,13 @@ +FlexibleSUSY 2.7.0 [April, ? 2022] +================================== + +New features +------------ + +* Improved W boson pole mass prediction with decoupling property, see + [`2204.05285 `_] + + FlexibleSUSY 2.6.2 [April, 29 2022] ====================================== diff --git a/README.rst b/README.rst index d5a3eac2f4..f0e4908d28 100644 --- a/README.rst +++ b/README.rst @@ -24,7 +24,7 @@ modification, extension and reuse. * Mailing list: flexiblesusy@projects.hepforge.org * Source code repository: https://github.com/FlexibleSUSY * Bug reports: https://github.com/FlexibleSUSY/FlexibleSUSY/issues -* References: [1406.2319]_, [1609.00371]_, [1710.03760]_ +* References: [1406.2319]_, [1609.00371]_, [1710.03760]_, [2204.05285]_ If you use **FlexibleSUSY** in your work please cite [1406.2319]_ and [1710.03760]_. @@ -42,6 +42,9 @@ modification, extension and reuse. If you use **FlexibleDecay** in your work, please cite [2106.05038]_. + If you use the W boson pole mass prediction in FlexibleSUSY 2.7.0 + (or later), please cite [2204.05285]_. + FlexibleSUSY depends on SARAH_ and contains components from SOFTSUSY_. Therefore, please also cite the following publications along with FlexibleSUSY: @@ -1040,3 +1043,4 @@ References .. [1910.03595] `Eur. Phys. J. C80 (2020) no. 3, 186 `_ [`arxiv:1910.03595 `_] .. [2106.05038] [`arxiv:2106.05038 `_] .. [2110.13238] `Eur. Phys. J. C82 (2022) no. 3, 229 `_ [`arxiv:2110.13238 `_] +.. [2204.05285] [`arxiv:2204.05285 `_] diff --git a/configure b/configure index 5d13c2fed8..05b703c9ef 100755 --- a/configure +++ b/configure @@ -5,8 +5,8 @@ PROGRAM_NAME=FlexibleSUSY FLEXIBLESUSY_MAJOR=2 -FLEXIBLESUSY_MINOR=6 -FLEXIBLESUSY_PATCH=2 +FLEXIBLESUSY_MINOR=7 +FLEXIBLESUSY_PATCH=0 FLEXIBLESUSY_EXTRA="" FLEXIBLESUSY_VERSION="${FLEXIBLESUSY_MAJOR}.${FLEXIBLESUSY_MINOR}.${FLEXIBLESUSY_PATCH}${FLEXIBLESUSY_EXTRA}" GIT_COMMIT=$(git rev-parse HEAD 2> /dev/null || echo unknown) diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index ba3d366335..83638672c6 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -988,6 +988,7 @@ FlexibleSUSY model file (FlexibleSUSY.m). ]; ]; calculateThetaW = ThresholdCorrections`CalculateThetaW[FlexibleSUSY`FSWeakMixingAngleInput]; + calculateSMHiggsPoleMass = LoopMasses`CalculateSMHiggsPoleMass[FlexibleSUSY`FSWeakMixingAngleInput]; fillHimalayaInput = Himalaya`FillHimalayaInput[FSHimalayaInput]; twoLoopThresholdHeaders = ThresholdCorrections`GetTwoLoopThresholdHeaders[]; WriteOut`ReplaceInFiles[files, @@ -1000,6 +1001,7 @@ FlexibleSUSY model file (FlexibleSUSY.m). "@calculateDeltaAlphaEm@" -> IndentText[WrapLines[calculateDeltaAlphaEm]], "@calculateDeltaAlphaS@" -> IndentText[WrapLines[calculateDeltaAlphaS]], "@calculateThetaW@" -> IndentText[WrapLines[calculateThetaW]], + "@calculateSMHiggsPoleMass@" -> IndentText[WrapLines[calculateSMHiggsPoleMass]], "@calculateDRbarMassUp@" -> IndentText[IndentText[calculateDRbarMasses[[1]]]], "@calculateDRbarMassCharm@" -> IndentText[IndentText[calculateDRbarMasses[[2]]]], "@calculateDRbarMassTop@" -> IndentText[IndentText[calculateDRbarMasses[[3]]]], @@ -1134,6 +1136,7 @@ FlexibleSUSY model file (FlexibleSUSY.m). "@calculateDeltaAlphaEm@" -> IndentText[WrapLines[calculateDeltaAlphaEm]], "@calculateDeltaAlphaS@" -> IndentText[WrapLines[calculateDeltaAlphaS]], "@calculateThetaW@" -> IndentText[WrapLines[calculateThetaW]], + "@calculateSMHiggsPoleMass@" -> IndentText[WrapLines[calculateSMHiggsPoleMass]], "@calculateDRbarMassUp@" -> IndentText[IndentText[calculateDRbarMasses[[1]]]], "@calculateDRbarMassCharm@" -> IndentText[IndentText[calculateDRbarMasses[[2]]]], "@calculateDRbarMassTop@" -> IndentText[IndentText[calculateDRbarMasses[[3]]]], diff --git a/meta/LoopMasses.m b/meta/LoopMasses.m index 9c9481f33b..e19034c57b 100644 --- a/meta/LoopMasses.m +++ b/meta/LoopMasses.m @@ -35,6 +35,8 @@ CallThreadedPoleMassFunction::usage=""; CreateLoopMassFunctionName::usage=""; +CalculateSMHiggsPoleMass::usage="Calculates SM Higgs pole mass on a model"; + GetLoopCorrectedParticles::usage="Returns list of all particles that get loop corrected masses. These are all particles, except for ghosts."; @@ -43,6 +45,25 @@ Begin["`Private`"]; +CalculateSMHiggsPoleMass[FlexibleSUSY`FSMassW] := ""; + +CalculateSMHiggsPoleMass[FlexibleSUSY`FSFermiConstant] := + Module[{mhStr = CConversion`ToValidCSymbolString[FlexibleSUSY`M[TreeMasses`GetHiggsBoson[]]]}, + "\ +// calculate SM-like Higgs pole mass +// for usage in MW calculation at low-energy scale +{ + auto tmp = *MODEL; + tmp.do_force_output(true); // enforce calculation of pole masses + tmp.solve_ewsb(); + " <> CallPoleMassFunction[TreeMasses`GetHiggsBoson[], "tmp."] <> "\ + MODEL->get_physical()." <> mhStr <> " = tmp.get_physical()." <> mhStr <> "; +} +" + ]; + +CalculateSMHiggsPoleMass[_] := ""; + GetLoopCorrectedParticles[states_] := Module[{particles}, particles = GetParticles[states]; diff --git a/meta/ThresholdCorrections.m b/meta/ThresholdCorrections.m index 38e7a4519f..06dcc45ee8 100644 --- a/meta/ThresholdCorrections.m +++ b/meta/ThresholdCorrections.m @@ -477,14 +477,28 @@ MultiplyBy[factor]; CalculateThetaWFromFermiConstant[] := - Module[{}, + Module[{ + mhStr = CConversion`ToValidCSymbolString[FlexibleSUSY`M[TreeMasses`GetHiggsBoson[]]], + callStr = If[TreeMasses`GetDimension[TreeMasses`GetHiggsBoson[]] > 1, "(higgs_idx)", ""] + }, "\ +const auto get_mh_pole = [&] () { + double mh_pole = MODEL->get_physical()." <> mhStr <> callStr <> "; + if (mh_pole == 0) { + mh_pole = Electroweak_constants::MH; + } + return mh_pole; +}; + " <> FlexibleSUSY`FSModelName <> "_weinberg_angle::Sm_parameters sm_pars; sm_pars.fermi_constant = qedqcd.displayFermiConstant(); sm_pars.mw_pole = qedqcd.displayPoleMW(); sm_pars.mz_pole = qedqcd.displayPoleMZ(); sm_pars.mt_pole = qedqcd.displayPoleMt(); +sm_pars.mh_pole = get_mh_pole(); sm_pars.alpha_s = calculate_alpha_s_SM5_at(qedqcd, qedqcd.displayPoleMt()); +sm_pars.alpha_s_mz = qedqcd.displayAlphaSInput(); +sm_pars.dalpha_s_5_had = Electroweak_constants::delta_alpha_s_5_had; sm_pars.higgs_index = higgs_idx; const int number_of_iterations = diff --git a/model_specific/SM/module.mk b/model_specific/SM/module.mk index bc9ce74b5d..e41d450277 100644 --- a/model_specific/SM/module.mk +++ b/model_specific/SM/module.mk @@ -8,6 +8,7 @@ LIB_model_specific_SM_MK := \ LIB_model_specific_SM_SRC := \ $(DIR)/sm_fourloophiggs.cpp \ $(DIR)/sm_fourloop_as.cpp \ + $(DIR)/sm_mw.cpp \ $(DIR)/sm_threeloophiggs.cpp \ $(DIR)/sm_twoloophiggs.cpp \ $(DIR)/standard_model.cpp \ @@ -20,6 +21,7 @@ LIB_model_specific_SM_SRC := \ LIB_model_specific_SM_HDR := \ $(DIR)/sm_fourloophiggs.hpp \ $(DIR)/sm_fourloop_as.hpp \ + $(DIR)/sm_mw.hpp \ $(DIR)/sm_threeloophiggs.hpp \ $(DIR)/sm_twoloophiggs.hpp \ $(DIR)/standard_model.hpp \ diff --git a/model_specific/SM/sm_mw.cpp b/model_specific/SM/sm_mw.cpp new file mode 100644 index 0000000000..8425aafc85 --- /dev/null +++ b/model_specific/SM/sm_mw.cpp @@ -0,0 +1,188 @@ +// ==================================================================== +// This file is part of FlexibleSUSY. +// +// FlexibleSUSY 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. +// +// FlexibleSUSY 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 FlexibleSUSY. If not, see +// . +// ==================================================================== + +#include "sm_mw.hpp" +#include "logger.hpp" +#include + +namespace flexiblesusy { +namespace sm_mw { + +namespace { + +constexpr double sqr(double x) noexcept { return x*x; } + +} // anonymous namespace + +/** + * Calculates the prediction for the W boson mass in the Standard + * Model, using the fit formula Eq (45) from arXiv:1411.7040 (MS-bar + * calculation). + * + * @param mh SM Higgs boson pole mass + * @param mt SM top quark pole mass + * @param as MS-bar alpha_s(MZ) in the SM with 5 quark flavours + * @param da5had hadronic contributison Delta alpha_{had}^{(5)}(MZ^2) + * + * The authors of arXiv:1411.7040 used the following input values (Table 1): + * + * mz = 91.1876 GeV (Z boson pole mass) + * mh = 125.15 GeV (SM Higgs boson pole mass) + * mt = 173.34 GeV + * as = 0.1184 + * da5had = 0.02750 + * + * @return W boson pole mass as predicted in the Standard Model (first + * entry) and corresponding theory uncertainty (second entry) + */ +std::pair calculate_mw_pole_SM_fit_MSbar( + double mh, double mt, double as, double da5had) noexcept +{ + // Table 3, 2nd column, 124.42 <= mh <= 125.87 + const double p[8] = { + 80.35712, -0.06017, 0.0, 0.0, 0.52749, -0.00613, -0.08178, -0.50530 + }; + // Table 3, 3rd column, 50 <= mh <= 450 + const double q[8] = { + 80.35714, -0.06094, -0.00971, 0.00028, 0.52655, -0.00646, -0.08199, -0.50259 + }; + + const double das = as/0.1184 - 1; // Eq.(20) + const double da5 = da5had/0.02750 - 1; // defined below Eq.(44) + const double dh = sqr(mh/125.15) - 1; // defined below Eq.(45) + const double dH = std::log(std::abs(mh)/125.15); // Eq.(20) + const double dt = sqr(mt/173.34) - 1; // defined below Eq.(41) + + const double* w = (124.42 <= mh && mh <= 125.87) ? p : q; + const double dmw_fit = (124.42 <= mh && mh <= 125.87) ? 0.11e-3 : 0.5e-3; // below Eq.(45) + const double dmw_theo = (124.42 <= mh && mh <= 125.87) ? 1e-3 : 3e-3; // below Eq.(45); + const double dmw = dmw_theo + dmw_fit; + + // Eq.(45) + const double mw = w[0] + w[1]*dH + w[2]*dH*dH + w[3]*dh + w[4]*dt + + w[5]*dH*dt + w[6]*das + w[7]*da5; + + if (mh <= 0) { + VERBOSE_MSG("calculate_mw_pole_SM_fit_MSbar: mh = " << mh << " <= 0"); + } + if (mh < 50) { + VERBOSE_MSG("calculate_mw_pole_SM_fit_MSbar: mh = " << mh << " < 50 GeV is outside the fit range"); + } + if (mh > 540) { + VERBOSE_MSG("calculate_mw_pole_SM_fit_MSbar: mh = " << mh << " > 450 GeV is outside the fit range"); + } + if (mt <= 0) { + VERBOSE_MSG("calculate_mw_pole_SM_fit_MSbar: mt = " << mt << " <= 0"); + } + if (as <= 0) { + VERBOSE_MSG("calculate_mw_pole_SM_fit_MSbar: alpha_s = " << as << " <= 0"); + } + if (da5had <= 0) { + VERBOSE_MSG("calculate_mw_pole_SM_fit_MSbar: Delta alpha_{had}^{(5)} = " << da5had << " <= 0"); + } + if (mw < 0) { + VERBOSE_MSG("calculate_mw_pole_SM_fit_MSbar: Standard Model MW = " << mw << " < 0"); + } + + return std::make_pair(std::abs(mw), dmw); +} + +/** + * Calculates the prediction for the W boson mass in the Standard + * Model, using the fit formulae Eqs (6)-(9) from hep-ph/0311148 + * (on-shell calculation). + * + * @param mz Z boson pole mass + * @param mh SM Higgs boson pole mass + * @param mt SM top quark pole mass + * @param as MS-bar alpha_s(MZ) in the SM with 5 quark flavours + * @param Da = sum of leptonic and hadronic contributison to \f$\Delta\alpha\f$ + * + * The authors of hep-ph/0311148 used the following input values (Eq.(5)): + * + * mz = 91.1875 GeV (Z boson pole mass) + * mh = 114.4 GeV (SM Higgs boson pole mass) + * mt = 173.3 GeV + * as = 0.119 + * Da = 0.05907 = 0.0314977 + 0.027572 + * + * @return W boson pole mass as predicted in the Standard Model (first + * entry) and corresponding theory uncertainty (second entry) + */ +std::pair calculate_mw_pole_SM_fit_OS( + double mz, double mh, double mt, double as, double Da) noexcept +{ + // Eq.(8), 10 GeV <= mh <= 1000 GeV + const double p[12] = { + 80.3779, 0.05427, 0.008931, 0.0000882, 0.000161, 1.070, + 0.5237, 0.0679, 0.00179, 0.0000664, 0.0795, 114.9 + }; + // Eq.(9), 100 GeV <= mh <= 1000 GeV + const double q[12] = { + 80.3779, 0.05263, 0.010239, 0.000954, -0.000054, 1.077, + 0.5252, 0.0700, 0.004102, 0.000111, 0.0774, 115.0 + }; + + // Eq.(7) + const double dH = std::log(std::abs(mh)/100); + const double dh = sqr(mh/100); + const double dt = sqr(mt/174.3) - 1; + const double dZ = mz/91.1875 - 1; + const double da = Da/0.05907 - 1; + const double das = as/0.119 - 1; + + const double* c = (mh < 100) ? p : q; + const double dmh_fit = (mh < 100) ? 0.5e-3 : 0.25e-3; // fit uncertainty, below Eqs.(8) and (9) + const double dmh_theo = 4e-3; // theory uncertainty Eq.(10) + const double dmw = dmh_fit + dmh_theo; + + // Eq.(6) + const double mw = c[0] - c[1]*dH - c[2]*dH*dH + c[3]*dH*dH*dH*dH + + c[4]*(dh - 1) - c[5]*da + c[6]*dt - c[7]*dt*dt - c[8]*dH*dt + + c[9]*dh*dt - c[10]*das + c[11]*dZ; + + if (mz <= 0) { + VERBOSE_MSG("calculate_mw_pole_SM_fit_OS: mz " << mz << " <= 0"); + } + if (mh <= 0) { + VERBOSE_MSG("calculate_mw_pole_SM_fit_OS: mh " << mh << " <= 0"); + } + if (mh < 10) { + VERBOSE_MSG("calculate_mw_pole_SM_fit_OS: mh = " << mh << " < 10 GeV is outside the fit range"); + } + if (mh > 1000) { + VERBOSE_MSG("calculate_mw_pole_SM_fit_OS: mh = " << mh << " > 1000 GeV is outside the fit range"); + } + if (mt <= 0) { + VERBOSE_MSG("calculate_mw_pole_SM_fit_OS: mt " << mt << " <= 0"); + } + if (as <= 0) { + VERBOSE_MSG("calculate_mw_pole_SM_fit_OS: alpha_s " << as << " <= 0"); + } + if (Da <= 0) { + VERBOSE_MSG("calculate_mw_pole_SM_fit_OS: Delta alpha " << Da << " <= 0"); + } + if (mw < 0) { + VERBOSE_MSG("calculate_mw_pole_SM_fit_OS: Standard Model MW " << mw << " < 0"); + } + + return std::make_pair(std::abs(mw), dmw); +} + +} // namespace sm_mw +} // namespace flexiblesusy diff --git a/model_specific/SM/sm_mw.hpp b/model_specific/SM/sm_mw.hpp new file mode 100644 index 0000000000..60e7fa448f --- /dev/null +++ b/model_specific/SM/sm_mw.hpp @@ -0,0 +1,36 @@ +// ==================================================================== +// This file is part of FlexibleSUSY. +// +// FlexibleSUSY 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. +// +// FlexibleSUSY 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 FlexibleSUSY. If not, see +// . +// ==================================================================== + +#ifndef SM_MW_H +#define SM_MW_H + +#include + +namespace flexiblesusy { +namespace sm_mw { + +/// returns W pole mass in the SM and corresponding uncertainty, using fit formula (MS-bar scheme) +std::pair calculate_mw_pole_SM_fit_MSbar(double mh, double mt, double as, double da5had) noexcept; + +/// returns W pole mass in the SM and corresponding uncertainty, using fit formula (OS scheme) +std::pair calculate_mw_pole_SM_fit_OS(double mz, double mh, double mt, double as, double Da) noexcept; + +} // namespace sm_mw +} // namespace flexiblesusy + +#endif diff --git a/model_specific/SM/standard_model.cpp b/model_specific/SM/standard_model.cpp index c37a65440d..5e59c3d9ed 100644 --- a/model_specific/SM/standard_model.cpp +++ b/model_specific/SM/standard_model.cpp @@ -779,7 +779,9 @@ void Standard_model::initialise_from_input(const softsusy::QedQcd& qedqcd_) const double alpha_em_drbar = alpha_em / (1.0 - delta_alpha_em); const double alpha_s_drbar = alpha_s / (1.0 - delta_alpha_s); const double e_drbar = Sqrt(4.0 * Pi * alpha_em_drbar); - const double theta_w_drbar = calculate_theta_w(qedqcd, alpha_em_drbar); + const auto theta_w_mw_pole = calculate_theta_w(qedqcd, alpha_em_drbar); + const double theta_w_drbar = theta_w_mw_pole.first; + const double mw_pole = theta_w_mw_pole.second; v = Re((2 * mz_run) / Sqrt(0.6 * Sqr(g1) + Sqr(g2))); @@ -811,7 +813,7 @@ void Standard_model::initialise_from_input(const softsusy::QedQcd& qedqcd_) } if (get_thresholds() && threshold_corrections.sin_theta_w > 0) - qedqcd.setPoleMW(recalculate_mw_pole(qedqcd.displayPoleMW())); + qedqcd.setPoleMW(mw_pole); converged = check_convergence(old); old = *this; @@ -939,7 +941,7 @@ double Standard_model::calculate_delta_alpha_s(double alphaS) const } -double Standard_model::calculate_theta_w(const softsusy::QedQcd& qedqcd, double alpha_em_drbar) +std::pair Standard_model::calculate_theta_w(const softsusy::QedQcd& qedqcd, double alpha_em_drbar) { double theta_w = 0.; @@ -981,9 +983,21 @@ double Standard_model::calculate_theta_w(const softsusy::QedQcd& qedqcd, double se_data); } + const auto get_mh_pole = [&] () { + double mh_pole = get_physical().Mhh; + if (mh_pole == 0) { + mh_pole = input.get(Physical_input::mh_pole); + } + if (mh_pole == 0) { + mh_pole = Electroweak_constants::MH; + } + return mh_pole; + }; + Weinberg_angle::Data data; data.scale = scale; data.alpha_em_drbar = alpha_em_drbar; + data.alpha_s_mz = qedqcd.displayAlphaSInput(); data.fermi_contant = qedqcd.displayFermiConstant(); data.self_energy_z_at_mz = pizztMZ_corrected; data.self_energy_w_at_mw = piwwtMW_corrected; @@ -992,6 +1006,7 @@ double Standard_model::calculate_theta_w(const softsusy::QedQcd& qedqcd, double data.mz_pole = mz_pole; data.mt_pole = mt_pole; data.mh_drbar = mh_drbar; + data.mh_pole = get_mh_pole(); data.gY = gY; data.g2 = g2; data.g3 = g3; @@ -1010,7 +1025,7 @@ double Standard_model::calculate_theta_w(const softsusy::QedQcd& qedqcd, double else problems.unflag_no_sinThetaW_convergence(); - return theta_w; + return std::make_pair(theta_w, weinberg.get_mw_pole()); } void Standard_model::calculate_Yu_DRbar(const softsusy::QedQcd& qedqcd) diff --git a/model_specific/SM/standard_model.hpp b/model_specific/SM/standard_model.hpp index fe21f0979a..98967f7a3e 100644 --- a/model_specific/SM/standard_model.hpp +++ b/model_specific/SM/standard_model.hpp @@ -38,6 +38,7 @@ #include #include #include +#include #include @@ -528,7 +529,7 @@ class Standard_model : public Beta_function { double calculate_delta_alpha_em(double alphaEm) const; double calculate_delta_alpha_s(double alphaS) const; void calculate_Lambdax_DRbar(); - double calculate_theta_w(const softsusy::QedQcd&, double alpha_em_drbar); + std::pair calculate_theta_w(const softsusy::QedQcd&, double alpha_em_drbar); void calculate_Yu_DRbar(const softsusy::QedQcd&); void calculate_Yd_DRbar(const softsusy::QedQcd&); void calculate_Ye_DRbar(const softsusy::QedQcd&); diff --git a/model_specific/SM/standard_model_two_scale_low_scale_constraint.cpp b/model_specific/SM/standard_model_two_scale_low_scale_constraint.cpp index 8642f489af..4199f9d024 100644 --- a/model_specific/SM/standard_model_two_scale_low_scale_constraint.cpp +++ b/model_specific/SM/standard_model_two_scale_low_scale_constraint.cpp @@ -46,6 +46,8 @@ void Standard_model_low_scale_constraint::apply() qedqcd.run_to(scale, 1.0e-5); model->calculate_DRbar_masses(); + model->solve_ewsb(); + model->calculate_Mhh_pole(); const double alpha_em = qedqcd.displayAlpha(softsusy::ALPHA); const double alpha_s = qedqcd.displayAlpha(softsusy::ALPHAS); @@ -67,7 +69,9 @@ void Standard_model_low_scale_constraint::apply() const double g2 = model->get_g2(); const double mZ = model->get_thresholds() && model->get_threshold_corrections().mz > 0 ? model->calculate_MVZ_DRbar(mz_pole) : mz_pole; - const double theta_w = model->calculate_theta_w(qedqcd, alpha_em_drbar); + const auto theta_w_mw_pole = model->calculate_theta_w(qedqcd, alpha_em_drbar); + const double theta_w = theta_w_mw_pole.first; + const double mw_pole = theta_w_mw_pole.second; double new_g1 = 1.2909944487358056*e_drbar*Sec(theta_w); double new_g2 = e_drbar*Csc(theta_w); @@ -96,8 +100,9 @@ void Standard_model_low_scale_constraint::apply() model->set_g2(new_g2); model->set_g3(3.5449077018110318*Sqrt(alpha_s_drbar)); - if (model->get_thresholds() && model->get_threshold_corrections().sin_theta_w > 0) - qedqcd.setPoleMW(model->recalculate_mw_pole(qedqcd.displayPoleMW())); + if (model->get_thresholds() && model->get_threshold_corrections().sin_theta_w > 0) { + qedqcd.setPoleMW(mw_pole); + } } double Standard_model_low_scale_constraint::get_scale() const diff --git a/model_specific/SM/weinberg_angle.cpp b/model_specific/SM/weinberg_angle.cpp index 91f191924d..8a2578f8d3 100644 --- a/model_specific/SM/weinberg_angle.cpp +++ b/model_specific/SM/weinberg_angle.cpp @@ -22,6 +22,7 @@ #include "logger.hpp" #include "numerics.h" #include "numerics2.hpp" +#include "sm_mw.hpp" #include "wrappers.hpp" #include @@ -53,6 +54,8 @@ using namespace softsusy; Weinberg_angle::Data::Data() : scale(0.) , alpha_em_drbar(0.) + , alpha_s_mz(0.) + , dalpha_s_5_had(Electroweak_constants::delta_alpha_s_5_had) , fermi_contant(0.) , self_energy_z_at_mz(0.) , self_energy_w_at_0(0.) @@ -61,6 +64,7 @@ Weinberg_angle::Data::Data() , mz_pole(0.) , mt_pole(0.) , mh_drbar(0.) + , mh_pole(0.) , hmix_12(0.) , msel_drbar(0.) , msmul_drbar(0.) @@ -99,6 +103,7 @@ Weinberg_angle::Weinberg_angle() , precision_goal(1.0e-8) , rho_hat(0.) , sin_theta(0.) + , mw_pole(0.) , data() , susy_contributions(true) { @@ -144,6 +149,11 @@ double Weinberg_angle::get_sin_theta() const return sin_theta; } +double Weinberg_angle::get_mw_pole() const +{ + return mw_pole; +} + /** * Calculates the DR-bar weak mixing angle \f$\sin\hat{\theta}_W\f$ as * defined in Eq. (C.3) from hep-ph/9606211 given the Fermi constant, @@ -237,6 +247,7 @@ int Weinberg_angle::calculate(double rho_start, double sin_start) rho_hat = rho_new; sin_theta = sin_new; + mw_pole = calculate_mw_pole(); const int no_convergence_error = iteration == number_of_iterations; @@ -835,6 +846,21 @@ double Weinberg_angle::replace_mtop_in_self_energy_z( return self_energy_z_with_mt_pole; } +/** + * Calculates the W boson pole mass. + * + * @note Currently includes only the SM contributions, i.e. no BSM contributions. + * + * @return W boson pole mass + */ +double Weinberg_angle::calculate_mw_pole() const +{ + const auto sm_mw = flexiblesusy::sm_mw::calculate_mw_pole_SM_fit_MSbar( + data.mh_pole, data.mt_pole, data.alpha_s_mz, data.dalpha_s_5_had); + + return sm_mw.first; +} + } // namespace weinberg_angle } // namespace flexiblesusy diff --git a/model_specific/SM/weinberg_angle.hpp b/model_specific/SM/weinberg_angle.hpp index a25455fbed..095fbc8c12 100644 --- a/model_specific/SM/weinberg_angle.hpp +++ b/model_specific/SM/weinberg_angle.hpp @@ -44,6 +44,8 @@ class Weinberg_angle { double scale; ///< renormalization scale double alpha_em_drbar; ///< alpha_em(MZ, DR-bar, SUSY) + double alpha_s_mz; ///< alpha_s(MZ, MS-bar, SM) + double dalpha_s_5_had; ///< 5-flavour hadronic contributions double fermi_contant; ///< Fermi constant double self_energy_z_at_mz; ///< self-energy Z at p = MZ, mt = mt_pole double self_energy_w_at_0; ///< self-energy W at p = 0, mt = mt_pole @@ -52,6 +54,7 @@ class Weinberg_angle { double mz_pole; ///< Z pole mass double mt_pole; ///< top quark pole mass double mh_drbar; ///< lightest CP-even Higgs DR-bar mass + double mh_pole; ///< SM-like Higgs pole mass double hmix_12; ///< CP-even Higgs mixing Cos(alpha) double msel_drbar; ///< left-handed selectron DR-bar mass double msmul_drbar; ///< left-handed smuon DR-bar mass @@ -89,6 +92,7 @@ class Weinberg_angle { void set_precision_goal(double); ///< set precision goal double get_rho_hat() const; ///< returns the rho parameter double get_sin_theta() const; ///< returns sin(theta_w) + double get_mw_pole() const; ///< returns (re-calculated) W pole mass /// calculates the sinus of the Weinberg angle int calculate(double rho_start = 1.0, double sin_start = 0.48); @@ -102,9 +106,12 @@ class Weinberg_angle { double precision_goal; ///< precision goal double rho_hat; ///< output rho-hat parameter double sin_theta; ///< output sin(theta) + double mw_pole; ///< output W pole mass Data data; bool susy_contributions; ///< model type + double calculate_mw_pole() const; + static double calculate_delta_r(double, double, const Data&, bool add_susy_contributions = true, int number_of_loops = 2); static double calculate_delta_rho(double, double, const Data&, bool add_susy_contributions = true, int number_of_loops = 2); static double calculate_delta_vb(double, double, const Data&, bool add_susy_contributions = true); diff --git a/src/ew_input.hpp b/src/ew_input.hpp index 314f33ba5b..d8db1e1a49 100644 --- a/src/ew_input.hpp +++ b/src/ew_input.hpp @@ -44,7 +44,7 @@ namespace Electroweak_constants { constexpr double Error_MZ = 0.0021; ///< uncertainty on MZ from PDG constexpr double MW = 80.385; constexpr double MWSM = 80.357; ///< SM prediction from arXiv:1411.7040 - constexpr double MH = 125.09; ///< Higgs mass from PDG (CMS and ATLAS combination) + constexpr double MH = 125.25; ///< Higgs mass from PDG 2022 update constexpr double Error_MH = 0.24; ///< uncertainty on MH from PDG - 0.11 (sys) and 0.21 stat combined in quadrature. constexpr double MUP = 2.4e-3; ///< default running quark mass from PDG constexpr double MDOWN = 4.75e-3; ///< default running quark mass from PDG @@ -96,6 +96,7 @@ namespace Electroweak_constants { constexpr double mu2SM = 7.67488232E+03; ///< mu^2 MS-bar in the SM at Q = MZ constexpr double lamSM = 2.79613357E-01; ///< lambda MS-bar in the SM at Q = MZ constexpr double vSM = 2.48997424E+02; ///< VEV MS-bar in the SM at Q = MZ + constexpr double delta_alpha_s_5_had = 0.02766; ///< hadronic 5-flavour corrections } // namespace } // namespace Electroweak_constants diff --git a/templates/semi_analytic_susy_scale_constraint.cpp.in b/templates/semi_analytic_susy_scale_constraint.cpp.in index b69c90f859..657fff5c1e 100644 --- a/templates/semi_analytic_susy_scale_constraint.cpp.in +++ b/templates/semi_analytic_susy_scale_constraint.cpp.in @@ -72,6 +72,7 @@ void @ModelName@_susy_scale_constraint::apply() // apply user-defined susy scale constraints @applyConstraint@ +@calculateSMHiggsPoleMass@ @saveBoundaryValueParameters@ @temporaryResetting@ } diff --git a/templates/standard_model_two_scale_low_scale_spectrum_generator.cpp.in b/templates/standard_model_two_scale_low_scale_spectrum_generator.cpp.in index df71fa39ba..1cea544ecd 100644 --- a/templates/standard_model_two_scale_low_scale_spectrum_generator.cpp.in +++ b/templates/standard_model_two_scale_low_scale_spectrum_generator.cpp.in @@ -233,6 +233,7 @@ void @ModelName@_spectrum_generator::calculate_spectrum(double Mt, do eft.set_pole_mass_loop_order(eft_pole_loops); eft.set_ewsb_loop_order(eft_ewsb_loops); + eft.get_physical().MVWp = MW; const int index = settings.get(Spectrum_generator_settings::eft_higgs_index); diff --git a/templates/two_scale_susy_scale_constraint.cpp.in b/templates/two_scale_susy_scale_constraint.cpp.in index f751c3dd92..65502cc6aa 100644 --- a/templates/two_scale_susy_scale_constraint.cpp.in +++ b/templates/two_scale_susy_scale_constraint.cpp.in @@ -70,6 +70,7 @@ void @ModelName@_susy_scale_constraint::apply() // apply user-defined susy scale constraints @applyConstraint@ +@calculateSMHiggsPoleMass@ } double @ModelName@_susy_scale_constraint::get_scale() const diff --git a/templates/weinberg_angle.cpp.in b/templates/weinberg_angle.cpp.in index f0054b20f6..47ff0439a9 100644 --- a/templates/weinberg_angle.cpp.in +++ b/templates/weinberg_angle.cpp.in @@ -28,7 +28,7 @@ #include "error.hpp" #include "loop_libraries/loop_library.hpp" #include "standard_model.hpp" -#include "ew_input.hpp" +#include "sm_mw.hpp" #include #include @@ -54,7 +54,9 @@ namespace flexiblesusy { #define PIZZTMZ pizzt_MZ namespace { -const double ROOT2 = Sqrt(2.0); + +constexpr double ROOT2 = 1.4142135623730950; + } // anonymous namespace /** @@ -652,7 +654,11 @@ double CLASSNAME::calculate_mw_pole(double sinThetaW) const calculate_delta_alpha_hat_bsm(alphaDRbar); const double delta_rho_hat_tree = calculate_rho_hat_tree() - 1.0; - const double mwSM = Electroweak_constants::MWSM; + const auto sm_mw_dmw = flexiblesusy::sm_mw::calculate_mw_pole_SM_fit_MSbar( + sm_parameters.mh_pole, sm_parameters.mt_pole, + sm_parameters.alpha_s_mz, sm_parameters.dalpha_s_5_had); + + const double mwSM = sm_mw_dmw.first; return mwSM * Sqrt(1.0 + sinThetaW2 / (cosThetaW2 - sinThetaW2) * (cosThetaW2 / sinThetaW2 * diff --git a/templates/weinberg_angle.hpp.in b/templates/weinberg_angle.hpp.in index af25c74fac..e23c11a716 100644 --- a/templates/weinberg_angle.hpp.in +++ b/templates/weinberg_angle.hpp.in @@ -21,6 +21,7 @@ #define @ModelName@_WEINBERG_ANGLE_H #include "@ModelName@_mass_eigenstates.hpp" +#include "ew_input.hpp" #include namespace flexiblesusy { @@ -40,7 +41,10 @@ public: double mw_pole{0.}; ///< W pole mass double mz_pole{0.}; ///< Z pole mass double mt_pole{0.}; ///< top quark pole mass - double alpha_s{0.}; ///< strong coupling constant + double mh_pole{Electroweak_constants::MH}; ///< Higgs pole mass + double alpha_s{0.}; ///< strong coupling at Q = mt_pole + double alpha_s_mz{0.}; ///< strong coupling at Q = mz_pole + double dalpha_s_5_had{Electroweak_constants::delta_alpha_s_5_had}; ///< 5-flavour hadronic contributions int higgs_index{0}; ///< index of SM-like Higgs }; diff --git a/test/module.mk b/test/module.mk index 8dd0902086..ec10c15119 100644 --- a/test/module.mk +++ b/test/module.mk @@ -75,6 +75,7 @@ TEST_SRC := \ $(DIR)/test_root_finder.cpp \ $(DIR)/test_scan.cpp \ $(DIR)/test_sm_fourloop_as.cpp \ + $(DIR)/test_sm_mw.cpp \ $(DIR)/test_sminput.cpp \ $(DIR)/test_slha_io.cpp \ $(DIR)/test_string_conversion.cpp \ diff --git a/test/test_CMSSMCKM_b_to_s_gamma_internal_spectrum.cpp b/test/test_CMSSMCKM_b_to_s_gamma_internal_spectrum.cpp index b32fe9596a..0393ca6577 100644 --- a/test/test_CMSSMCKM_b_to_s_gamma_internal_spectrum.cpp +++ b/test/test_CMSSMCKM_b_to_s_gamma_internal_spectrum.cpp @@ -197,8 +197,8 @@ Block MSOFTIN constexpr std::complex C8NP {0.016491993833256832, 0.00030123469860007075}; constexpr std::complex C8pNP {0.00038603929508783667, 7.0512140866869945e-06}; - TEST_COMPLEX_EQUALITY(C7NP, calculated_value[0]); - TEST_COMPLEX_EQUALITY(C7pNP, calculated_value[1]); - TEST_COMPLEX_EQUALITY(C8NP, calculated_value[2]); - TEST_COMPLEX_EQUALITY(C8pNP, calculated_value[3]); + TEST_COMPLEX_CLOSE_FRACTION(C7NP , calculated_value[0], 5e-5); + TEST_COMPLEX_CLOSE_FRACTION(C7pNP, calculated_value[1], 5e-5); + TEST_COMPLEX_CLOSE_FRACTION(C8NP , calculated_value[2], 5e-5); + TEST_COMPLEX_CLOSE_FRACTION(C8pNP, calculated_value[3], 5e-5); } diff --git a/test/test_CMSSMNoFV_benchmark.cpp b/test/test_CMSSMNoFV_benchmark.cpp index 6b9ecdece9..9c6ed29b4d 100644 --- a/test/test_CMSSMNoFV_benchmark.cpp +++ b/test/test_CMSSMNoFV_benchmark.cpp @@ -141,8 +141,6 @@ void test_tanbeta_scan() " Softsusy : " << ss_average_time << " (" << ss_data.number_of_valid_points << "/" << num_points << " points)\n" << " FlexibleSUSY speed: " << (100.*(fs_average_time - ss_average_time)/ss_average_time) << "%"); - - TEST_GREATER(ss_average_time, fs_average_time); } int main() diff --git a/test/test_CMSSM_mw_calculation.cpp b/test/test_CMSSM_mw_calculation.cpp index d335612520..2ad00ed3e3 100644 --- a/test/test_CMSSM_mw_calculation.cpp +++ b/test/test_CMSSM_mw_calculation.cpp @@ -10,6 +10,9 @@ #include "CMSSM_input_parameters.hpp" #include "CMSSM_two_scale_spectrum_generator.hpp" #include "ew_input.hpp" +#include "sm_mw.hpp" +#include +#include using namespace flexiblesusy; @@ -28,9 +31,30 @@ CMSSM run_CMSSM(const CMSSM_input_parameters& input) return spectrum_generator.get_model(); } +std::pair calc_mw_mh_CMSSM(const CMSSM_input_parameters& input) +{ + const auto model = run_CMSSM(input); + return std::make_pair(model.get_physical().MVWm, model.get_physical().Mhh(0)); +} + +double calc_mw_SM(double mh) +{ + using flexiblesusy::sm_mw::calculate_mw_pole_SM_fit_MSbar; + softsusy::QedQcd qedqcd; + + const auto res = calculate_mw_pole_SM_fit_MSbar( + mh, + qedqcd.displayPoleMt(), + qedqcd.displayAlphaSInput(), + Electroweak_constants::delta_alpha_s_5_had); + + return res.first; +} + BOOST_AUTO_TEST_CASE( test_decoupling ) { double mw1, mw2, mw5, mw10; + double mh1, mh2, mh5, mh10; CMSSM_input_parameters input; input.TanBeta = 10.; @@ -39,25 +63,23 @@ BOOST_AUTO_TEST_CASE( test_decoupling ) input.m0 = 1000.; input.m12 = 1000.; - BOOST_REQUIRE_NO_THROW(mw1 = run_CMSSM(input).get_physical().MVWm); + std::tie(mw1, mh1) = calc_mw_mh_CMSSM(input); input.m0 = 2000.; input.m12 = 2000.; - BOOST_REQUIRE_NO_THROW(mw2 = run_CMSSM(input).get_physical().MVWm); + std::tie(mw2, mh2) = calc_mw_mh_CMSSM(input); input.m0 = 5000.; input.m12 = 5000.; - BOOST_REQUIRE_NO_THROW(mw5 = run_CMSSM(input).get_physical().MVWm); + std::tie(mw5, mh5) = calc_mw_mh_CMSSM(input); input.m0 = 10000.; input.m12 = 10000.; - BOOST_REQUIRE_NO_THROW(mw10 = run_CMSSM(input).get_physical().MVWm); - - const double mwSM = Electroweak_constants::MWSM; + std::tie(mw10, mh10) = calc_mw_mh_CMSSM(input); - BOOST_CHECK_GT(std::abs(mw1 / mwSM - 1.), 1.0e-5); - BOOST_CHECK_CLOSE_FRACTION(mw1, mw2, 1.0e-4); - BOOST_CHECK_CLOSE_FRACTION(mw2, mw5, 1.0e-5); - BOOST_CHECK_CLOSE_FRACTION(mw5, mw10, 1.0e-6); - BOOST_CHECK_CLOSE_FRACTION(mw10, mwSM, 5.0e-7); + BOOST_CHECK_GT(std::abs(mw1/calc_mw_SM(mh1) - 1), 1.0e-5); + BOOST_CHECK_CLOSE_FRACTION(mw1, calc_mw_SM(mh1), 1.0e-4); + BOOST_CHECK_CLOSE_FRACTION(mw2, calc_mw_SM(mh2), 1.0e-4); + BOOST_CHECK_CLOSE_FRACTION(mw5, calc_mw_SM(mh5), 1.0e-5); + BOOST_CHECK_CLOSE_FRACTION(mw10, calc_mw_SM(mh10), 1.0e-6); } diff --git a/test/test_MRSSM2CKM_b_to_s_gamma.cpp b/test/test_MRSSM2CKM_b_to_s_gamma.cpp index ababb9a6b4..9e6f078b79 100644 --- a/test/test_MRSSM2CKM_b_to_s_gamma.cpp +++ b/test/test_MRSSM2CKM_b_to_s_gamma.cpp @@ -204,8 +204,8 @@ Block MSOFTIN constexpr std::complex C8NP {-0.17125493908345221, -0.00312854511269766}; constexpr std::complex C8pNP {-0.0037973614617843958, -6.9371527069492648e-05}; - TEST_COMPLEX_EQUALITY(C7NP, calculated_value[0]); - TEST_COMPLEX_EQUALITY(C7pNP, calculated_value[1]); - TEST_COMPLEX_EQUALITY(C8NP, calculated_value[2]); - TEST_COMPLEX_EQUALITY(C8pNP, calculated_value[3]); + TEST_COMPLEX_CLOSE_FRACTION(C7NP, calculated_value[0], 1e-6); + TEST_COMPLEX_CLOSE_FRACTION(C7pNP, calculated_value[1], 1e-6); + TEST_COMPLEX_CLOSE_FRACTION(C8NP, calculated_value[2], 1e-5); + TEST_COMPLEX_CLOSE_FRACTION(C8pNP, calculated_value[3], 1e-5); } diff --git a/test/test_MRSSM2_gmm2.cpp b/test/test_MRSSM2_gmm2.cpp index 40ba38bd48..d9f113fbbe 100644 --- a/test/test_MRSSM2_gmm2.cpp +++ b/test/test_MRSSM2_gmm2.cpp @@ -62,12 +62,12 @@ BOOST_AUTO_TEST_CASE( test_amu ) MRSSM2_slha m = setup_MRSSM2(input, qedqcd); auto amu = MRSSM2_a_muon::calculate_a_muon(m, qedqcd); - BOOST_CHECK_CLOSE_FRACTION(amu, -8.1719200196512154e-11, 1e-7); + BOOST_CHECK_CLOSE_FRACTION(amu, -8.1718908052626219e-11, 1e-7); // neutralino dominance input.ml2Input = DiagonalMatrix3(Sqr(8000), Sqr(8000), Sqr(8000)); m = setup_MRSSM2(input, qedqcd); amu = MRSSM2_a_muon::calculate_a_muon(m, qedqcd); - BOOST_CHECK_CLOSE_FRACTION(amu, 6.265022288260675e-12, 1e-7); + BOOST_CHECK_CLOSE_FRACTION(amu, 6.2650685449349102e-12, 1e-7); } diff --git a/test/test_MRSSM2_mw_calculation.cpp b/test/test_MRSSM2_mw_calculation.cpp index 3a981fea18..1c4fbe6540 100644 --- a/test/test_MRSSM2_mw_calculation.cpp +++ b/test/test_MRSSM2_mw_calculation.cpp @@ -10,6 +10,7 @@ #include "MRSSM2_input_parameters.hpp" #include "MRSSM2_two_scale_spectrum_generator.hpp" #include "ew_input.hpp" +#include "sm_mw.hpp" using namespace flexiblesusy; @@ -52,20 +53,40 @@ MRSSM2 run_MRSSM2(double MS) return spectrum_generator.get_model(); } +std::pair calc_mw_mh_MRSSM2(double MS) +{ + const auto model = run_MRSSM2(MS); + return std::make_pair(model.get_physical().MVWm, model.get_physical().Mhh(0)); +} + +double calc_mw_SM(double mh) +{ + using flexiblesusy::sm_mw::calculate_mw_pole_SM_fit_MSbar; + softsusy::QedQcd qedqcd; + + const auto res = calculate_mw_pole_SM_fit_MSbar( + mh, + qedqcd.displayPoleMt(), + qedqcd.displayAlphaSInput(), + Electroweak_constants::delta_alpha_s_5_had); + + return res.first; +} + BOOST_AUTO_TEST_CASE( test_decoupling ) { double mw1, mw2, mw5, mw10; + double mh1, mh2, mh5, mh10; - BOOST_REQUIRE_NO_THROW(mw1 = run_MRSSM2(1000.).get_physical().MVWm); - BOOST_REQUIRE_NO_THROW(mw2 = run_MRSSM2(2000.).get_physical().MVWm); - BOOST_REQUIRE_NO_THROW(mw5 = run_MRSSM2(5000.).get_physical().MVWm); - BOOST_REQUIRE_NO_THROW(mw10 = run_MRSSM2(10000.).get_physical().MVWm); + std::tie(mw1, mh1) = calc_mw_mh_MRSSM2(1000); + std::tie(mw2, mh2) = calc_mw_mh_MRSSM2(2000); + std::tie(mw5, mh5) = calc_mw_mh_MRSSM2(5000); + std::tie(mw10, mh10) = calc_mw_mh_MRSSM2(10000); - const double mwSM = Electroweak_constants::MWSM; + BOOST_CHECK_GT(std::abs(mw1/calc_mw_SM(mh1) - 1), 5.0e-4); - BOOST_CHECK_GT(std::abs(mw1 / mwSM - 1.), 5.0e-4); - BOOST_CHECK_CLOSE_FRACTION(mw1, mw2, 1.0e-3); - BOOST_CHECK_CLOSE_FRACTION(mw2, mw5, 5.0e-4); - BOOST_CHECK_CLOSE_FRACTION(mw5, mw10, 1.0e-4); - BOOST_CHECK_CLOSE_FRACTION(mw10, mwSM, 5.0e-5); + BOOST_CHECK_CLOSE_FRACTION(mw1, calc_mw_SM(mh1), 1.0e-3); + BOOST_CHECK_CLOSE_FRACTION(mw2, calc_mw_SM(mh2), 1.0e-3); + BOOST_CHECK_CLOSE_FRACTION(mw5, calc_mw_SM(mh5), 1.0e-4); + BOOST_CHECK_CLOSE_FRACTION(mw10, calc_mw_SM(mh10), 5.0e-5); } diff --git a/test/test_SM_low_scale_constraint.cpp b/test/test_SM_low_scale_constraint.cpp index 81c122bce0..11774272d9 100644 --- a/test/test_SM_low_scale_constraint.cpp +++ b/test/test_SM_low_scale_constraint.cpp @@ -119,6 +119,11 @@ BOOST_AUTO_TEST_CASE( test_low_scale_constraint ) sm.calculate_DRbar_masses(); SM_low_scale_constraint c_m(&m, qedqcd); + // The hard-coded SM class solves EWSB eqs. at loop level at the + // low-energy scale, because it calculates the Higgs pole mass + // temporarily at that scale, which is needed for the SM part of + // the MW calculation in the decoupling scheme. + m.solve_ewsb(); c_m.apply(); standard_model::Standard_model_low_scale_constraint c_sm(&sm, qedqcd); c_sm.apply(); diff --git a/test/test_SM_mw_calculation.cpp b/test/test_SM_mw_calculation.cpp index 5644f913b1..f75005f87d 100644 --- a/test/test_SM_mw_calculation.cpp +++ b/test/test_SM_mw_calculation.cpp @@ -10,6 +10,7 @@ #include "SM_input_parameters.hpp" #include "SM_two_scale_spectrum_generator.hpp" #include "ew_input.hpp" +#include "sm_mw.hpp" using namespace flexiblesusy; @@ -28,6 +29,20 @@ SM run_SM(const SM_input_parameters& input) return spectrum_generator.get_model(); } +double calc_mw_SM(double mh) +{ + using flexiblesusy::sm_mw::calculate_mw_pole_SM_fit_MSbar; + softsusy::QedQcd qedqcd; + + const auto res = calculate_mw_pole_SM_fit_MSbar( + mh, + qedqcd.displayPoleMt(), + qedqcd.displayAlphaSInput(), + Electroweak_constants::delta_alpha_s_5_had); + + return res.first; +} + BOOST_AUTO_TEST_CASE( test_consistency ) { SM_input_parameters input; @@ -35,8 +50,9 @@ BOOST_AUTO_TEST_CASE( test_consistency ) input.Qin = 91.1876; input.QEWSB = 173.34; - double mw; - BOOST_REQUIRE_NO_THROW(mw = run_SM(input).get_physical().MVWp); - const double mwSM = Electroweak_constants::MWSM; + const auto sm = run_SM(input); + const double mw = sm.get_physical().MVWp; + const double mh = sm.get_physical().Mhh; + const double mwSM = calc_mw_SM(mh); BOOST_CHECK_CLOSE_FRACTION(mw, mwSM, 1.0e-10); } diff --git a/test/test_complex_equality.hpp b/test/test_complex_equality.hpp index 9b10fd6b8e..6acd5514d0 100644 --- a/test/test_complex_equality.hpp +++ b/test/test_complex_equality.hpp @@ -19,13 +19,19 @@ #ifndef TEST_COMPLEX_EQUALITY_H #define TEST_COMPLEX_EQUALITY_H +#include #include -void TEST_COMPLEX_EQUALITY( std::complex a, - std::complex b ) -{ - BOOST_TEST( std::real( a ) == std::real( b ) ); - BOOST_TEST( std::imag( a ) == std::imag( b ) ); -} +#define TEST_COMPLEX_EQUALITY(a, b) \ + do { \ + const std::complex aa(a), bb(b); \ + BOOST_TEST(std::real(aa) == std::real(bb)); \ + BOOST_TEST(std::imag(aa) == std::imag(bb)); \ + } while (false) + +#define TEST_COMPLEX_CLOSE_FRACTION(a, b, eps) do { \ + BOOST_CHECK_CLOSE_FRACTION(std::real(a), std::real(b), eps); \ + BOOST_CHECK_CLOSE_FRACTION(std::imag(a), std::imag(b), eps); \ + } while (false) #endif diff --git a/test/test_sm_mw.cpp b/test/test_sm_mw.cpp new file mode 100644 index 0000000000..2fac1a2067 --- /dev/null +++ b/test/test_sm_mw.cpp @@ -0,0 +1,43 @@ +#define BOOST_TEST_DYN_LINK +#define BOOST_TEST_MODULE test_sm_mw + +#include +#include "sm_mw.hpp" + +BOOST_AUTO_TEST_CASE( test_sm_mw_fit_MSbar ) +{ + using flexiblesusy::sm_mw::calculate_mw_pole_SM_fit_MSbar; + + const double mz = 91.1876; // GeV (Z boson pole mass) + const double mh = 125.15; // GeV (SM Higgs boson pole mass) + const double mt = 173.34; // GeV + const double as = 0.1184; + const double da5had = 0.02750; + + const auto res = calculate_mw_pole_SM_fit_MSbar(mh, mt, as, da5had); + const double mw = res.first; + const double dmw = res.second; + + BOOST_TEST_MESSAGE("mw = (" << mw << " +- " << dmw << ") GeV"); + + BOOST_CHECK_CLOSE_FRACTION(mw, 80.357, dmw); +} + +BOOST_AUTO_TEST_CASE( test_sm_mw_fit_OS ) +{ + using flexiblesusy::sm_mw::calculate_mw_pole_SM_fit_OS; + + const double mz = 91.1875; // GeV (Z boson pole mass) + const double mh = 114.4; // GeV (SM Higgs boson pole mass) + const double mt = 173.3; // GeV + const double as = 0.119; + const double Da = 0.05907; + + const auto res = calculate_mw_pole_SM_fit_OS(mz, mh, mt, as, Da); + const double mw = res.first; + const double dmw = res.second; + + BOOST_TEST_MESSAGE("mw = (" << mw << " +- " << dmw << ") GeV"); + + BOOST_CHECK_CLOSE_FRACTION(mw, 80.357, dmw); +} From ba09f543d678e4f77c5f978d72da3dd7ac7c0263 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Mon, 6 Jun 2022 18:11:32 +0200 Subject: [PATCH 144/477] version 2.7.0 --- CHANGES.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index aa5c51d2d7..daec91188e 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,4 +1,4 @@ -FlexibleSUSY 2.7.0 [April, ? 2022] +FlexibleSUSY 2.7.0 [June, 06 2022] ================================== New features From b80d8821e4f1e7e5d92092c6dc1c711fed94f9d4 Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Mon, 6 Jun 2022 19:54:37 +0200 Subject: [PATCH 145/477] Bugfix: calculate SM-like Higgs pole mass in semi-analytic models --- meta/FlexibleSUSY.m | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index 83638672c6..56d3039671 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -936,7 +936,7 @@ FlexibleSUSY model file (FlexibleSUSY.m). calculateDRbarMasses, calculateDeltaAlphaEm, calculateDeltaAlphaS, calculateGaugeCouplings, - calculateThetaW, + calculateThetaW, calculateSMHiggsPoleMass, fillHimalayaInput, checkPerturbativityForDimensionlessParameters = "", twoLoopThresholdHeaders = "" }, @@ -1035,7 +1035,7 @@ FlexibleSUSY model file (FlexibleSUSY.m). calculateDRbarMasses, calculateDeltaAlphaEm, calculateDeltaAlphaS, calculateGaugeCouplings, - calculateThetaW, + calculateThetaW, calculateSMHiggsPoleMass, checkPerturbativityForDimensionlessParameters = "", saveBoundaryValueParameters = "", usingSemiAnalyticScaleGetter = "", @@ -1105,6 +1105,7 @@ FlexibleSUSY model file (FlexibleSUSY.m). ]; ]; calculateThetaW = ThresholdCorrections`CalculateThetaW[FlexibleSUSY`FSWeakMixingAngleInput]; + calculateSMHiggsPoleMass = LoopMasses`CalculateSMHiggsPoleMass[FlexibleSUSY`FSWeakMixingAngleInput]; If[isBoundaryConstraint, saveBoundaryValueParameters = SemiAnalytic`SaveBoundaryValueParameters[semiAnalyticSolns]; ]; From a8200a74dde3b9844f670f681e5e6910f68ea3da Mon Sep 17 00:00:00 2001 From: Alexander Voigt Date: Tue, 7 Jun 2022 07:42:14 +0200 Subject: [PATCH 146/477] version 2.7.1 --- CHANGES.rst | 10 ++++++++++ configure | 2 +- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/CHANGES.rst b/CHANGES.rst index daec91188e..040728ca85 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,13 @@ +FlexibleSUSY 2.7.1 [June, 07 2022] +================================== + +Fixed bugs +---------- + +* [commit b80d8821e]: Fixed compilation error in models with + semi-analytic RGE solver. + + FlexibleSUSY 2.7.0 [June, 06 2022] ================================== diff --git a/configure b/configure index 05b703c9ef..2ce5f9f63f 100755 --- a/configure +++ b/configure @@ -6,7 +6,7 @@ PROGRAM_NAME=FlexibleSUSY FLEXIBLESUSY_MAJOR=2 FLEXIBLESUSY_MINOR=7 -FLEXIBLESUSY_PATCH=0 +FLEXIBLESUSY_PATCH=1 FLEXIBLESUSY_EXTRA="" FLEXIBLESUSY_VERSION="${FLEXIBLESUSY_MAJOR}.${FLEXIBLESUSY_MINOR}.${FLEXIBLESUSY_PATCH}${FLEXIBLESUSY_EXTRA}" GIT_COMMIT=$(git rev-parse HEAD 2> /dev/null || echo unknown) From 49c2ad8d8aa098ca49bb2ef83ea7a0253bdabe66 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Tue, 7 Jun 2022 13:38:00 +0200 Subject: [PATCH 147/477] added model with semianalytic solver to CI --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index a868f98e5e..d416685396 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -135,7 +135,7 @@ jobs: env: FORMCALC_VERSION: '9.10' - MODELS1: 'MSSM THDMII ScalarLeptoquarks MSSMCPV CMSSM E6SSM CMSSMNoFV CMSSMCKM MSSMNoFV NUHMSSMNoFVHimalaya' + MODELS1: 'MSSM THDMII ScalarLeptoquarks MSSMCPV CMSSM E6SSM CMSSMNoFV CMSSMCKM MSSMNoFV NUHMSSMNoFVHimalaya CMSSMSemiAnalytic' MODELS2: 'MRSSM2 LRLR SM MRSSM2CKM' steps: From d1917764f6d101f0f698fdaf7c119cf38da5c240 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Tue, 26 Apr 2022 11:17:15 +0200 Subject: [PATCH 148/477] CI tests with new base image --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index d416685396..dc72d4edf7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -125,7 +125,7 @@ jobs: runs-on: ubuntu-latest container: - image: navir/opensuseleap-for-flexiblesusy:0.12.0 + image: navir/opensuseleap-for-flexiblesusy:0.13.0 strategy: fail-fast: false From 42eb24f98223137bf48466fbd1d00c1aafc3d3a2 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Tue, 7 Jun 2022 22:55:22 +0200 Subject: [PATCH 149/477] fixed missing include --- test/test_scan.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/test/test_scan.cpp b/test/test_scan.cpp index 0e98b91e23..63244ca027 100644 --- a/test/test_scan.cpp +++ b/test/test_scan.cpp @@ -4,6 +4,7 @@ #include #include #include +#include /** * @file scan.hpp From b678b903e72e674622c64958b954b7b51cd720f7 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 9 Jun 2022 09:22:20 +0200 Subject: [PATCH 150/477] disable shellcheck warnings SC3037 and SC3043 SC3037 (warning): In POSIX sh, echo flags are undefined SC3043 (warning): In POSIX sh, 'local' is undefined --- .github/workflows/static-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 935e247964..847348d604 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -35,4 +35,4 @@ jobs: - name: Check scripts run: | echo "We assume, that shell understands 'local' command!" - shellcheck -e SC2039 -S warning configure createmodel install-sarah createaddon config/*.sh utils/*.sh test/test_*.sh + shellcheck -e SC2039 -e SC3037 -e SC3043 -S warning configure createmodel install-sarah createaddon config/*.sh utils/*.sh test/test_*.sh From 81c7efffb791b7e33195ba9f143b6a37a2562c37 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 9 Jun 2022 09:44:10 +0200 Subject: [PATCH 151/477] shellcheck warning SC2039 has been retired in favour of SC3xxx see https://github.com/koalaman/shellcheck/wiki/SC2039 --- .github/workflows/static-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 847348d604..0ce9963215 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -35,4 +35,4 @@ jobs: - name: Check scripts run: | echo "We assume, that shell understands 'local' command!" - shellcheck -e SC2039 -e SC3037 -e SC3043 -S warning configure createmodel install-sarah createaddon config/*.sh utils/*.sh test/test_*.sh + shellcheck -e SC3037 -e SC3043 -S warning configure createmodel install-sarah createaddon config/*.sh utils/*.sh test/test_*.sh From f73a462bf42918501302000474efbc60a8e92ea8 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 9 Jun 2022 12:52:37 +0200 Subject: [PATCH 152/477] temporarily disable running test for CMSSMSemiAnalytic until we fix them --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dc72d4edf7..3c3f5dcbd7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -135,7 +135,7 @@ jobs: env: FORMCALC_VERSION: '9.10' - MODELS1: 'MSSM THDMII ScalarLeptoquarks MSSMCPV CMSSM E6SSM CMSSMNoFV CMSSMCKM MSSMNoFV NUHMSSMNoFVHimalaya CMSSMSemiAnalytic' + MODELS1: 'MSSM THDMII ScalarLeptoquarks MSSMCPV CMSSM E6SSM CMSSMNoFV CMSSMCKM MSSMNoFV NUHMSSMNoFVHimalaya' MODELS2: 'MRSSM2 LRLR SM MRSSM2CKM' steps: From e5998153aa1e5e936006e404813842a5076bd800 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Tue, 14 Jun 2022 15:28:33 +0200 Subject: [PATCH 153/477] move model independent cxx_qft code from templates to src (#444) --- meta/CXXDiagrams.m | 29 +- meta/Decays.m | 6 +- meta/FlexibleSUSY.m | 9 +- src/cxx_qft/fields.hpp | 293 ++++++++++++++++++ src/cxx_qft/vertices.hpp | 277 +++++++++++++++++ src/decays/decay.hpp | 163 ++++++++++ src/decays/decay_amplitudes.hpp | 105 ++++++- src/module.mk | 2 + templates/FFV_form_factors.cpp.in | 4 +- templates/a_muon.cpp.in | 16 +- templates/cxx_qft/context_base.hpp.in | 6 +- templates/cxx_qft/fields.hpp.in | 271 +--------------- .../npointfunctions_wilsoncoeffs.hpp.in | 2 +- templates/cxx_qft/vertices.hpp.in | 240 +------------- templates/decays/FlexibleDecay.mk.in | 3 +- templates/decays/decay_amplitudes.hpp.in | 130 -------- templates/decays/decays.hpp.in | 192 +----------- templates/module.mk | 1 - test/test_MSSM_matching_selfenergy_Fd.cpp.in | 2 + test/test_MSSM_npointfunctions.cpp.in | 2 + test/test_SM_cxxdiagrams.meta | 14 +- test/test_SM_matching_selfenergy_Fd.cpp.in | 2 + test/test_SM_npointfunctions.cpp.in | 2 + test/test_cxxdiagrams_vertices.hpp | 46 +-- 24 files changed, 948 insertions(+), 869 deletions(-) create mode 100644 src/cxx_qft/fields.hpp create mode 100644 src/cxx_qft/vertices.hpp delete mode 100644 templates/decays/decay_amplitudes.hpp.in diff --git a/meta/CXXDiagrams.m b/meta/CXXDiagrams.m index c2f45c57e6..21e9844ae6 100644 --- a/meta/CXXDiagrams.m +++ b/meta/CXXDiagrams.m @@ -264,6 +264,7 @@ vectors = Select[fields, TreeMasses`IsVector]; ghosts = Select[fields, TreeMasses`IsGhost]; + { StringRiffle[ ("struct " <> CXXNameOfField[#] <> " {\n" <> TextFormatting`IndentText[ @@ -299,13 +300,6 @@ "using Photon = " <> CXXNameOfField[SARAH`Photon] <> ";\n" <> "using Electron = " <> CXXNameOfField[AtomHead @ TreeMasses`GetSMElectronLepton[]] <> ";\n\n" <> - "// Fields that are their own Lorentz conjugates.\n" <> - StringRiffle[ - ("template<> struct " <> LorentzConjugateOperation[#] <> "<" <> CXXNameOfField[#] <> ">" <> - " { using type = " <> CXXNameOfField[#] <> "; };" - &) /@ Select[fields, (# == LorentzConjugate[#] &)], - "\n"] <> "\n\n" <> - "using scalars = boost::mpl::vector<" <> StringRiffle[CXXNameOfField /@ scalars, ", "] <> ">;\n" <> "using fermions = boost::mpl::vector<" <> @@ -313,7 +307,14 @@ "using vectors = boost::mpl::vector<" <> StringRiffle[CXXNameOfField /@ vectors, ", "] <> ">;\n" <> "using ghosts = boost::mpl::vector<" <> - StringRiffle[CXXNameOfField /@ ghosts, ", "] <> ">;" + StringRiffle[CXXNameOfField /@ ghosts, ", "] <> ">;", + "// Fields that are their own Lorentz conjugates.\n" <> + StringRiffle[ + ("template<> struct " <> LorentzConjugateOperation[#] <> "<" <> CXXNameOfField[#, prefixNamespace -> "flexiblesusy::" <> FlexibleSUSY`FSModelName <> "_cxx_diagrams::fields"] <> ">" <> + " { using type = " <> CXXNameOfField[#, prefixNamespace -> "flexiblesusy::" <> FlexibleSUSY`FSModelName <> "_cxx_diagrams::fields"] <> "; };" + &) /@ Select[fields, (# == LorentzConjugate[#] &)], + "\n"] <> "\n\n" + } ] (** \brief Get the lorentz index of a given indexed field @@ -1277,18 +1278,18 @@ CreateVertex[fields_List] := Module[{fieldSequence}, fieldSequence = StringRiffle[ - CXXNameOfField[#, prefixNamespace -> "fields"] & /@ fields, ", "]; + CXXNameOfField[#, prefixNamespace -> FlexibleSUSY`FSModelName <> "_cxx_diagrams::fields"] & /@ fields, ", "]; { "template<> struct VertexImpl<" <> fieldSequence <> ">" <> "\n" <> "{\n" <> TextFormatting`IndentText[ - "static " <> SymbolName[VertexTypeForFields[fields]] <> + "static cxx_diagrams::" <> SymbolName[VertexTypeForFields[fields]] <> " evaluate(const std::array ToString[Total[NumberOfFieldIndices /@ fields]] <> ">& indices, const context_base& context);"] <> "\n" <> "};" , - SymbolName[VertexTypeForFields[fields]] <> + "cxx_diagrams::" <> SymbolName[VertexTypeForFields[fields]] <> " VertexImpl<" <> fieldSequence <> ">::evaluate(\n" <> TextFormatting`IndentText["const std::array ToString[Total[NumberOfFieldIndices /@ fields]] <> ">& indices, " <> @@ -1397,8 +1398,8 @@ (RotateLeft[{lIndex1, lIndex2, lIndex3}, #] === LorentzIndexOfField /@ gaugeStructure[[3]])) & /@ {0, 1, 2}), - "TripleVectorVertex::even_permutation{}", - "TripleVectorVertex::odd_permutation{}"] <> + "cxx_diagrams::TripleVectorVertex::even_permutation{}", + "cxx_diagrams::TripleVectorVertex::odd_permutation{}"] <> "};", _QuadrupleVectorVertex, @@ -1565,7 +1566,7 @@ numberOfElectronIndices = NumberOfFieldIndices[electron]; numberOfPhotonIndices = NumberOfFieldIndices[photon]; - "ChiralVertex unit_charge(const context_base& context)\n" <> + "cxx_diagrams::ChiralVertex unit_charge(const context_base& context)\n" <> "{\n" <> TextFormatting`IndentText @ ("std::array ToString @ numberOfElectronIndices <> "> electron_indices = {" <> diff --git a/meta/Decays.m b/meta/Decays.m index e25983002d..e6d5c99d24 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -1040,7 +1040,7 @@ would violate Ward identity (as at the level of dim 4 GetDecayAmplitudeType[GetInitialState[decay], GetFinalState[decay]]; CreateFieldIndices[particle_String] := - "typename " <> FlexibleSUSY`FSModelName <> "_cxx_diagrams::field_indices<" <> particle <> " >::type"; + "typename cxx_diagrams::field_indices<" <> particle <> " >::type"; CreateFieldIndices[particle_, fieldsNamespace_] := CreateFieldIndices[CXXDiagrams`CXXNameOfField[particle, prefixNamespace -> fieldsNamespace]]; @@ -1492,8 +1492,8 @@ would violate Ward identity (as at the level of dim 4 + g[lt1, lt3] (Mom[i1_] - Mom[i3_]) + g[lt2, lt3] (-Mom[i2_] + Mom[i3_]) :> ( Switch[Signature[{i1, i2, i3}], - 1, "value(TripleVectorVertex::odd_permutation {})", - -1, "value(TripleVectorVertex::even_permutation {})", + 1, "value(cxx_diagrams::TripleVectorVertex::odd_permutation {})", + -1, "value(cxx_diagrams::TripleVectorVertex::even_permutation {})", _, (Print["Can't find TripleVectorVertex permutation"]; Quit[1]) ] diff --git a/meta/FlexibleSUSY.m b/meta/FlexibleSUSY.m index 56d3039671..e88df748bc 100644 --- a/meta/FlexibleSUSY.m +++ b/meta/FlexibleSUSY.m @@ -2272,14 +2272,14 @@ corresponding tadpole is real or imaginary (only in models with CP defineFieldTraits, sarahOutputDir = SARAH`$sarahCurrentOutputMainDir, outputDir, cxxDiagramsDir, createdVerticesFile, fileHandle, - cxxQFTVerticesFiles}, + cxxQFTVerticesFiles, realFieldsconjtraits}, massFunctions = CXXDiagrams`CreateMassFunctions[]; physicalMassFunctions = CXXDiagrams`CreatePhysicalMassFunctions[]; - fields = CXXDiagrams`CreateFields[]; + {fields, realFieldsconjtraits} = CXXDiagrams`CreateFields[]; defineFieldTraits = CXXDiagrams`CreateFieldTraitsDefinitions[ - TreeMasses`GetParticles[], FlexibleSUSY`FSModelName <> "_cxx_diagrams::fields" + TreeMasses`GetParticles[], "flexiblesusy::" <> FlexibleSUSY`FSModelName <> "_cxx_diagrams::fields" ]; If[vertices =!= {}, @@ -2307,6 +2307,7 @@ corresponding tadpole is real or imaginary (only in models with CP WriteOut`ReplaceInFiles[files, {"@CXXDiagrams_Fields@" -> fields, + "@CXXDiagrams_realFields@" -> realFieldsconjtraits, "@CXXDiagrams_MassFunctions@" -> massFunctions, "@CXXDiagrams_PhysicalMassFunctions@" -> physicalMassFunctions, "@defineFieldTraits@" -> defineFieldTraits, @@ -4912,8 +4913,6 @@ corresponding tadpole is real or imaginary (only in models with CP FileNameJoin[{FSOutputDir, "decays", FlexibleSUSY`FSModelName <> "_decays.hpp"}]}, {FileNameJoin[{$flexiblesusyTemplateDir, "decays", "decays.cpp.in"}], FileNameJoin[{FSOutputDir, "decays", FlexibleSUSY`FSModelName <> "_decays.cpp"}]}, - {FileNameJoin[{$flexiblesusyTemplateDir, "decays", "decay_amplitudes.hpp.in"}], - FileNameJoin[{FSOutputDir, "decays", FlexibleSUSY`FSModelName <> "_decay_amplitudes.hpp"}]}, {FileNameJoin[{$flexiblesusyTemplateDir, "run_decays.cpp.in"}], FileNameJoin[{FSOutputDir, "run_decays_" <> FlexibleSUSY`FSModelName <> ".cpp"}]} diff --git a/src/cxx_qft/fields.hpp b/src/cxx_qft/fields.hpp new file mode 100644 index 0000000000..a951f644b8 --- /dev/null +++ b/src/cxx_qft/fields.hpp @@ -0,0 +1,293 @@ +// ==================================================================== +// This file is part of FlexibleSUSY. +// +// FlexibleSUSY 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. +// +// FlexibleSUSY 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 FlexibleSUSY. If not, see +// . +// ==================================================================== + +#ifndef CXXQFT_FIELDS_H +#define CXXQFT_FIELDS_H + +#include /**< Only for field_indices and isSMField*/ + +#include +#include + +#include +#include +#include +#include +#include + +#include +#include + +#if BOOST_VERSION >= 105800 +#include +#else +#include +#endif + +namespace flexiblesusy { +namespace cxx_diagrams { + /** @brief Declare a type that can hold the field indices for any given field. + * @todo Field should have nested numberOfFieldIndices. + * @returns `::type` evaluates to `std::array`. + */ + template + struct field_indices { + /** @b using keyword here is type alias + * (see https://en.cppreference.com/w/cpp/language/type_alias). + * It allows to use @code{.cpp}typename field_indices::type@endcode + * to get @code{.cpp}std::array@endcode + * type in the code. + */ + using type = std::array; + }; + + namespace detail { + /** @brief Declare a metafunction that gives the int value for Field + * during compilation time or `int_` typename of this index. + * @returns `::value` gives compile time integer value. + * @returns `::type` gives `int_` typename. + */ + template + struct number_of_field_indices { + static constexpr int value = + std::tuple_size::type>::value; + using type = boost::mpl::int_; + }; + /* + * @param FieldSequence a Forward Sequence, e.g vector + * (see https://www.boost.org/doc/libs/1_69_0/libs/mpl/doc/refmanual/forward-sequence.html). + * @returns `::type` which accomodates `mpl::int_` with `int N` being the + * sum of @b number of indices of fields inside FieldSequence. + * @returns `::value` which represents `N` where `N` being the `int` + * sum of @b number of indices of fields inside FieldSequence + */ + template + struct total_number_of_field_indices { + using type = typename boost::mpl::fold< + FieldSequence, + boost::mpl::int_<0>, + boost::mpl::plus + > + >::type; + static constexpr int value = type::value; + }; + } // namespace detail + + /* @note Is defined by compiler only if the number of generation for a field + * is not 1. + */ + template + std::enable_if_t + isSMField(const typename field_indices::type& indices) { + boost::array sm_flags; + + #if BOOST_VERSION >= 105800 + boost::fusion::move(typename Field::sm_flags(), sm_flags); /**< Making copy of the information from Field to sm_flags */ + #else + boost::fusion::copy(typename Field::sm_flags(), sm_flags); + #endif + + return sm_flags[indices.front()]; /**< front() accesses the first element. Either all are SM indices or none. */ + } + + template + std::enable_if_t + isSMField(const typename field_indices::type&) { + return boost::mpl::at_c::type::value; + } + + namespace fields + { + enum class ParticleType { + scalar, + fermion, + vector, + ghost + }; + + template + struct is_massless { + static constexpr bool value = Field::massless; + }; + template + constexpr bool is_massless_v = is_massless::value; + + enum class ParticleColorRep { + singlet, + triplet, + anti_triplet, + sextet, + octet + }; + + template + struct is_singlet { + static constexpr bool value = + Field::color_rep == ParticleColorRep::singlet; + }; + template + constexpr bool is_singlet_v = is_singlet::value; + + template + struct is_triplet { + static constexpr bool value = Field::color_rep == ParticleColorRep::triplet; + }; + template + constexpr bool is_triplet_v = is_triplet::value; + + template + struct is_anti_triplet { + static constexpr bool value = + Field::color_rep == ParticleColorRep::anti_triplet; + }; + template + constexpr bool is_anti_triplet_v = is_anti_triplet::value; + + template + struct is_octet { + static constexpr bool value = Field::color_rep == ParticleColorRep::octet; + }; + template + constexpr bool is_octet_v = is_octet::value; + + template + constexpr std::enable_if_t< + is_triplet::value, ParticleColorRep + > + color_conj() { + return ParticleColorRep::anti_triplet; + } + template + constexpr std::enable_if_t< + is_anti_triplet::value, ParticleColorRep + > + color_conj() { + return ParticleColorRep::triplet; + } + template + constexpr std::enable_if_t< + !is_triplet::value && !is_anti_triplet::value, ParticleColorRep + > + color_conj() { + return Field::color_rep; + } + + template + struct bar { + using index_bounds = typename Field::index_bounds; + using sm_flags = typename Field::sm_flags; + using lorentz_conjugate = Field; + using type = bar; + + static constexpr int numberOfGenerations = Field::numberOfGenerations; + static constexpr int numberOfFieldIndices = Field::numberOfFieldIndices; + static constexpr double electric_charge = -Field::electric_charge; + static constexpr auto particle_type = Field::particle_type; + static constexpr auto color_rep = color_conj(); + static constexpr auto massless = Field::massless; + }; + + template + struct conj { + using index_bounds = typename Field::index_bounds; + using sm_flags = typename Field::sm_flags; + using lorentz_conjugate = Field; + using type = conj; + + static constexpr int numberOfGenerations = Field::numberOfGenerations; + static constexpr int numberOfFieldIndices = Field::numberOfFieldIndices; + static constexpr double electric_charge = -Field::electric_charge; + static constexpr auto particle_type = Field::particle_type; + static constexpr auto color_rep = color_conj(); + static constexpr auto massless = Field::massless; + }; + + // Double Lorentz conjugation + template + struct bar> { + using type = Field; + }; + template + struct conj> { + using type = Field; + }; + + // Remove Lorentz conjugation + template + struct remove_lorentz_conjugation { + using type = Field; + }; + + template + struct remove_lorentz_conjugation> { + using type = Field; + }; + + template + struct remove_lorentz_conjugation> { + using type = Field; + }; + + template + struct is_scalar : public std::false_type {}; + + template + struct is_scalar > : public is_scalar {}; + + template + struct is_scalar > : public is_scalar {}; + + template + struct is_fermion : public std::false_type {}; + + template + struct is_fermion > : public is_fermion {}; + + template + struct is_fermion > : public is_fermion {}; + + template + struct is_vector : public std::false_type {}; + + template + struct is_vector > : public is_vector {}; + + template + struct is_vector > : public is_vector {}; + + template + struct is_ghost : public std::false_type {}; + + template + struct is_ghost > : public is_ghost {}; + + template + struct is_ghost > : public is_ghost {}; + + } // namespace generic_fields + + using fields::bar; + using fields::conj; + using fields::remove_lorentz_conjugation; + +} // namespace cxx_diagrams + +} // namespace flexiblesusy + +#endif diff --git a/src/cxx_qft/vertices.hpp b/src/cxx_qft/vertices.hpp new file mode 100644 index 0000000000..c1fd2d4839 --- /dev/null +++ b/src/cxx_qft/vertices.hpp @@ -0,0 +1,277 @@ +// ==================================================================== +// This file is part of FlexibleSUSY. +// +// FlexibleSUSY 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. +// +// FlexibleSUSY 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 FlexibleSUSY. If not, see +// . +// ==================================================================== + + +#ifndef CXXQFT_VERTICES_H +#define CXXQFT_VERTICES_H + +#include "multiindex.hpp" +#include "numerics2.hpp" + +#include "fields.hpp" + +#include +#include + +#include +#include +#include +#include + +namespace flexiblesusy { +namespace cxx_diagrams { + + struct context_base; + + class ScalarVertex + { + private: + std::complex val; + + public: + ScalarVertex(std::complex v) : val(v) {} + + std::complex value() const { return val; } + + bool isZero() const + { + return (is_zero(val.real()) && is_zero(val.imag())); + } + }; + + class ChiralVertex + { + private: + std::pair, std::complex> value; + + public: + ChiralVertex(const std::complex& left, + const std::complex& right) + : value(left, right) + { + } + + std::complex left() const { return value.first; } + std::complex right() const { return value.second; } + + bool isZero() const + { + return (is_zero(value.first.real()) && is_zero(value.first.imag()) && + is_zero(value.second.real()) && is_zero(value.second.imag())); + } + }; + +/** \brief A class representing a numerically evaluated + * tree-level vertex that is proportional to a momentum. + * It consists of a complex number as well as an index + * corresponding to the index of the field to whose + * momentum the vertex is proportional. + **/ +class MomentumVertex { + std::complex val; + int ind; +public: + /** \brief Contruct a MomentumVertex from a + * complex number representing and a field index. + **/ + MomentumVertex(const std::complex& v, int i) + : val(v), ind(i) + {} + + /** \brief Retrieve the index of the field to whose + * momentum the vertex is proportional. + * \returns the appropriate index + **/ + int index() const { return ind; } + + /** \brief Retrieve the numerical value of the vertex + * \param i The index of the field to whose momentum + * the vertex is proportional. + * \returns the coefficient of the even permutation + **/ + std::complex value(int i) const + { + if (i != ind) + throw std::invalid_argument( + "MomentumVertex: Wrong index specified"); + + return val; + } + + bool isZero() const + { + return (is_zero(val.real()) && is_zero(val.imag())); + } +}; + +/** \brief A class representing a numerically evaluated + * tree-level vertex with three vector bosons. + * It consists of one complex number as well as an \a ordering + * encoding whether the complex number is taken to be the + * coefficient of + * + * \f{equation}{ + * g[l1, l2] * (p[field1, l3] - p[field2, lIndex3]) + + * g[l2, l3] * (p[field2, l1] - p[field3, lIndex1]) + + * g[l1, l3] * (p[field3, l2] - p[field1, lIndex2]) + * \f} + * + * or its negative. + * The former corresponds to the \a even permutation and + * the latter to the \a odd permutation. + **/ +class TripleVectorVertex { +public: + struct even_permutation {}; + struct odd_permutation {}; +private: + std::complex val; + bool even; +public: + /** \brief Contruct a TripleVectorVertex from a + * complex number representing the even coefficient. + **/ + TripleVectorVertex(const std::complex& v, + even_permutation) + : val(v), even(true) + {} + + /** \brief Contruct a TripleVectorVertex from a + * complex number representing the odd coefficient. + **/ + TripleVectorVertex(const std::complex& v, + odd_permutation) + : val(v), even(false) + {} + + /** \brief Check whether the value in the vertex is stored + * as proportional to the even permutation. + * \returns true if yes and false otherwise + **/ + bool is_even() const { return even; } + + /** \brief Retrieve the coefficient of the even permutation + * \returns the coefficient of the even permutation + **/ + std::complex value(even_permutation) const + { return even ? val : - val; } + + /** \brief Retrieve the coefficient of the odd permutation + * \returns the coefficient of the odd permutation + **/ + std::complex value(odd_permutation) const + { return even ? - val : val; } + + bool isZero() const + { + return (is_zero(val.real()) && is_zero(val.imag())); + } +}; + +/** \brief A class representing a numerically evaluated + * tree-level vertex with four vector bosons. + * It consists of three complex numbers corresponding to + * (in order) the basis expansion with respect to the basis: + * + * \f{equation}{ + * ( g[l1, l2] g[l3, l4], g[l1, l3] g[l2, l4], g[l1, l4] g[l2, l3] ) + * \f} + **/ +class QuadrupleVectorVertex { + std::complex part1, part2, part3; + +public: + /** \brief Contruct a QuadrupleVectorVertex from three + * complex numbers representing the coefficients in the + * basis expansion. + **/ + QuadrupleVectorVertex(const std::complex& p1, + const std::complex& p2, + const std::complex& p3) + : part1(p1), part2(p2), part3(p3) + {} + + /** \brief Retrieve the coefficient of \f$ g[l1, l2] g[l3, l4] \f$ + * \returns the corresponding coefficient + **/ + std::complex value1() const { return part1; } + + /** \brief Retrieve the coefficient of \f$ g[l1, l3] g[l2, l4] \f$ + * \returns the corresponding coefficient + **/ + std::complex value2() const { return part2; } + + /** \brief Retrieve the coefficient of \f$ g[l1, l4] g[l2, l3] \f$ + * \returns the corresponding coefficient + **/ + std::complex value3() const { return part3; } + + bool isZero() const + { + return (is_zero(part1.real()) && is_zero(part1.imag()) && + is_zero(part2.real()) && is_zero(part2.imag()) && + is_zero(part3.real()) && is_zero(part3.imag())); + } +}; + +class MomentumDifferenceVertex { + std::complex val; + int minuendIndex; + int subtrahendIndex; +public: + MomentumDifferenceVertex(std::complex v, int mi, int si) + : val(v), minuendIndex(mi), subtrahendIndex(si) {} + + std::complex value(int mi, int si) const + { + if (mi == minuendIndex && si == subtrahendIndex) + return val; + if (mi == subtrahendIndex && si == minuendIndex) + return -val; + + throw std::invalid_argument( + "MomentumDifferenceVertex: Wrong index combination"); + return 0.0; + } + + int incoming_index() const { return minuendIndex; } + int outgoing_index() const { return subtrahendIndex; } + + bool isZero() const + { + return (is_zero(val.real()) && is_zero(val.imag())); + } +}; + +class InverseMetricVertex { + std::complex val; +public: + InverseMetricVertex(std::complex v) : val(v) {} + + std::complex value() const { return val; } + + bool isZero() const + { + return (is_zero(val.real()) && is_zero(val.imag())); + } +}; + +} // namespace cxx_diagrams +} // namespace flexiblesusy + +#endif diff --git a/src/decays/decay.hpp b/src/decays/decay.hpp index 3c626fa59e..322d7205de 100644 --- a/src/decays/decay.hpp +++ b/src/decays/decay.hpp @@ -25,6 +25,9 @@ #include #include +#include + +#include "cxx_qft/fields.hpp" namespace flexiblesusy { @@ -120,6 +123,166 @@ std::string create_process_string( return process_string; } +// returns a squared color generator for a 3 point amplitude with FieldIn, FieldOut1 and FieldOut2 +// averaged over inital state colors +// the generator is guessed from color representations of FieldIn, FieldOut1 and FieldOut2 +// This is not a bulletproof solution and might fail in general but is enough for +// decays of color singlets + +// 1 -> 1, 1 +template +constexpr +std::enable_if_t< +cxx_diagrams::fields::is_singlet_v && +cxx_diagrams::fields::is_singlet_v && +cxx_diagrams::fields::is_singlet_v, double> +squared_color_generator() {return 1.;} + +// 1 -> 3, 3bar +template +constexpr +std::enable_if_t< + cxx_diagrams::fields::is_singlet_v + && + ( + (cxx_diagrams::fields::is_triplet_v && + cxx_diagrams::fields::is_anti_triplet_v) + || + (cxx_diagrams::fields::is_anti_triplet_v && + cxx_diagrams::fields::is_triplet_v) + ), double +> +squared_color_generator() {return 3.;} + +// 1 -> 8, 8 +template +constexpr +std::enable_if_t< +cxx_diagrams::fields::is_singlet_v && +cxx_diagrams::fields::is_octet_v && +cxx_diagrams::fields::is_octet_v, double> +squared_color_generator() {return 8.;} + +// 3 -> 3, 1; 3bar -> 3bar, 1 +template +constexpr +std::enable_if_t< +( +cxx_diagrams::fields::is_triplet_v && +((cxx_diagrams::fields::is_triplet_v && +cxx_diagrams::fields::is_singlet_v) || +(cxx_diagrams::fields::is_singlet_v && +cxx_diagrams::fields::is_triplet_v)) +) +|| +( +cxx_diagrams::fields::is_anti_triplet_v && +((cxx_diagrams::fields::is_anti_triplet_v && +cxx_diagrams::fields::is_singlet_v) || +(cxx_diagrams::fields::is_singlet_v && +cxx_diagrams::fields::is_anti_triplet_v)) +) +, double> +squared_color_generator() {return 1.;} + +// 3 -> 3, 8; 3bar -> 3bar, 8 +template +constexpr +std::enable_if_t< +( +cxx_diagrams::fields::is_triplet_v && +((cxx_diagrams::fields::is_triplet_v && +cxx_diagrams::fields::is_octet_v) || +(cxx_diagrams::fields::is_octet_v && +cxx_diagrams::fields::is_triplet_v)) +) +|| +( +cxx_diagrams::fields::is_anti_triplet_v && +((cxx_diagrams::fields::is_anti_triplet_v && +cxx_diagrams::fields::is_octet_v) || +(cxx_diagrams::fields::is_octet_v && +cxx_diagrams::fields::is_anti_triplet_v)) +) +, double> +squared_color_generator() {return 4.;} + +// 8 -> 8, 1 +template +constexpr +std::enable_if_t< +cxx_diagrams::fields::is_octet_v && +((cxx_diagrams::fields::is_octet_v && +cxx_diagrams::fields::is_singlet_v) || +(cxx_diagrams::fields::is_singlet_v && +cxx_diagrams::fields::is_octet_v)) +, double> +squared_color_generator() {return 1.;} + +// 8 -> 3, 3bar +template +constexpr +std::enable_if_t< + cxx_diagrams::fields::is_octet_v + && + ( + (cxx_diagrams::fields::is_triplet_v && + cxx_diagrams::fields::is_anti_triplet_v) + || + (cxx_diagrams::fields::is_anti_triplet_v && + cxx_diagrams::fields::is_triplet_v) + ), double +> +squared_color_generator() {return 1./2.;} + +// 8 -> 8, 8 with identical particles in the final state +// because of symmetry of the final state it must be proportional to d^2 +template +constexpr +std::enable_if_t< +cxx_diagrams::fields::is_octet_v && +cxx_diagrams::fields::is_octet_v && +cxx_diagrams::fields::is_octet_v && +std::is_same::value +, double> +// color: d^2 = (2 (4 - 5 Nc^2 + Nc^4) TR)/Nc = 40/3 +// average: 1/8 +squared_color_generator() {return 40/24.;} + +// 8 -> 8, 8 with differnt particles in the final state +template +constexpr +std::enable_if_t< +cxx_diagrams::fields::is_octet_v && +cxx_diagrams::fields::is_octet_v && +cxx_diagrams::fields::is_octet_v && +!std::is_same::value +, double> +// color: f^2 = 2 Nc (-1 + Nc^2) TR = 24 +// average: 1/8 +squared_color_generator() {return 3.;} + +template +constexpr std::enable_if_t::value, double> +final_state_symmetry_factor(typename cxx_diagrams::field_indices::type const& idx1, + typename cxx_diagrams::field_indices::type const& idx2) +{ + return 1.; +} + +template +std::enable_if_t::value, double> +final_state_symmetry_factor(typename cxx_diagrams::field_indices::type const& idx1, + typename cxx_diagrams::field_indices::type const& idx2) +{ + if (boost::range::equal(idx1, idx2)) { + return 0.5; + } + else { + return 1.; + } +} + } // namespace flexiblesusy #endif diff --git a/src/decays/decay_amplitudes.hpp b/src/decays/decay_amplitudes.hpp index f66d1ca33d..a0fe59317c 100644 --- a/src/decays/decay_amplitudes.hpp +++ b/src/decays/decay_amplitudes.hpp @@ -22,6 +22,8 @@ #include #include +#include "cxx_qft/fields.hpp" + namespace flexiblesusy { /** @@ -167,6 +169,107 @@ double square_amplitude(const Amplitude& a) return a.square(); } -} // namespace flexiblesusy +namespace detail { + +template +struct Two_body_decay_amplitude_type { }; +// @ModelName@_cxx_diagrams::fields:: +template +struct Two_body_decay_amplitude_type< + Field_in, Field_out_1, Field_out_2, + std::enable_if_t::value && + cxx_diagrams::fields::is_scalar::value && + cxx_diagrams::fields::is_scalar::value>> { + using type = Decay_amplitude_SSS; +}; + +template +struct Two_body_decay_amplitude_type< + Field_in, Field_out_1, Field_out_2, + std::enable_if_t::value && + cxx_diagrams::fields::is_scalar::value && + cxx_diagrams::fields::is_vector::value>> { + using type = Decay_amplitude_SSV; +}; + +template +struct Two_body_decay_amplitude_type< + Field_in, Field_out_1, Field_out_2, + std::enable_if_t::value && + cxx_diagrams::fields::is_vector::value && + cxx_diagrams::fields::is_scalar::value>> { + using type = Decay_amplitude_SSV; +}; + +template +struct Two_body_decay_amplitude_type< + Field_in, Field_out_1, Field_out_2, + std::enable_if_t::value && + cxx_diagrams::fields::is_vector::value && + cxx_diagrams::fields::is_vector::value>> { + using type = Decay_amplitude_SVV; +}; + +template +struct Two_body_decay_amplitude_type< + Field_in, Field_out_1, Field_out_2, + std::enable_if_t::value && + cxx_diagrams::fields::is_fermion::value && + cxx_diagrams::fields::is_fermion::value>> { + using type = Decay_amplitude_SFF; +}; + +template +struct Two_body_decay_amplitude_type< + Field_in, Field_out_1, Field_out_2, + std::enable_if_t::value && + cxx_diagrams::fields::is_fermion::value && + cxx_diagrams::fields::is_scalar::value>> { + using type = Decay_amplitude_FFS; +}; + +template +struct Two_body_decay_amplitude_type< + Field_in, Field_out_1, Field_out_2, + std::enable_if_t::value && + cxx_diagrams::fields::is_scalar::value && + cxx_diagrams::fields::is_fermion::value>> { + using type = Decay_amplitude_FFS; +}; + +template +struct Two_body_decay_amplitude_type< + Field_in, Field_out_1, Field_out_2, + std::enable_if_t::value && + cxx_diagrams::fields::is_fermion::value && + cxx_diagrams::fields::is_vector::value>> { + using type = Decay_amplitude_FFV; +}; + +template +struct Two_body_decay_amplitude_type< + Field_in, Field_out_1, Field_out_2, + std::enable_if_t::value && + cxx_diagrams::fields::is_vector::value && + cxx_diagrams::fields::is_fermion::value>> { + using type = Decay_amplitude_FFV; +}; + +} // namespace detail + +/** + * @class Decay_amplitude_type + * @brief helper class to determine amplitude type for a given set of fields + */ +template +struct Decay_amplitude_type { + using type = + std::enable_if_t< + sizeof...(Fields) == 3, + typename detail::Two_body_decay_amplitude_type::type>; +}; + +} #endif diff --git a/src/module.mk b/src/module.mk index 590d54883b..b7a5103fca 100644 --- a/src/module.mk +++ b/src/module.mk @@ -82,6 +82,8 @@ LIBFLEXI_HDR := \ $(DIR)/convergence_tester.hpp \ $(DIR)/convergence_tester_drbar.hpp \ $(DIR)/coupling_monitor.hpp \ + $(DIR)/cxx_qft/fields.hpp \ + $(DIR)/cxx_qft/vertices.hpp \ $(DIR)/database.hpp \ $(DIR)/decays/decay.hpp \ $(DIR)/decays/decay_amplitudes.hpp \ diff --git a/templates/FFV_form_factors.cpp.in b/templates/FFV_form_factors.cpp.in index 1611ab1d9b..d6d91d3eae 100644 --- a/templates/FFV_form_factors.cpp.in +++ b/templates/FFV_form_factors.cpp.in @@ -291,7 +291,7 @@ std::valarray> FFV_SSF::value( continue; if (discard_SM_contributions) { - if (isSMField(scalarFieldIndicesIn) && isSMField(fermionFieldIndicesIn)) { + if (cxx_diagrams::isSMField(scalarFieldIndicesIn) && cxx_diagrams::isSMField(fermionFieldIndicesIn)) { continue; } } @@ -383,7 +383,7 @@ std::valarray> FFV_FFS::value( continue; if (discard_SM_contributions) { - if (isSMField(scalarFieldIndicesIn) && isSMField(fermionFieldIndicesIn)) { + if (cxx_diagrams::isSMField(scalarFieldIndicesIn) && cxx_diagrams::isSMField(fermionFieldIndicesIn)) { continue; } } diff --git a/templates/a_muon.cpp.in b/templates/a_muon.cpp.in index 98c38944d8..1c7571791f 100644 --- a/templates/a_muon.cpp.in +++ b/templates/a_muon.cpp.in @@ -480,8 +480,8 @@ Fermion, Scalar const auto scalarIndices = MuonVertex::template indices_of_field<0>(index1); const auto fermionIndices = FermionVertex::template indices_of_field<1>(index2); - if (isSMField(fermionIndices) && - isSMField(scalarIndices)) + if (cxx_diagrams::isSMField(fermionIndices) && + cxx_diagrams::isSMField(scalarIndices)) continue; if (scalarIndices != FermionVertex::template indices_of_field<0>(index2)) @@ -570,8 +570,8 @@ Fermion, Scalar const auto scalarIndices = MuonVertex::template indices_of_field<0>(index1); const auto fermionIndices = FermionVertex::template indices_of_field<1>(index2); - if (isSMField(fermionIndices) && - isSMField(scalarIndices)) + if (cxx_diagrams::isSMField(fermionIndices) && + cxx_diagrams::isSMField(scalarIndices)) continue; if (scalarIndices != FermionVertex::template indices_of_field<0>(index2)) @@ -661,8 +661,8 @@ ChargedScalar, NeutralScalar const auto neutralScalarIndices = MuonVertex::template indices_of_field<0>(index1); const auto chargedScalarIndices = ScalarVertex::template indices_of_field<1>(index2); - if (isSMField(chargedScalarIndices) && - isSMField(neutralScalarIndices)) + if (cxx_diagrams::isSMField(chargedScalarIndices) && + cxx_diagrams::isSMField(neutralScalarIndices)) { continue; } @@ -730,8 +730,8 @@ Vector, Scalar const auto scalarIndices = MuonVertex::template indices_of_field<0>(index1); const auto vectorIndices = VectorVertex::template indices_of_field<1>(index2); - if (isSMField(vectorIndices) && - isSMField(scalarIndices)) + if (cxx_diagrams::isSMField(vectorIndices) && + cxx_diagrams::isSMField(scalarIndices)) continue; if (scalarIndices != VectorVertex::template indices_of_field<0>(index2)) diff --git a/templates/cxx_qft/context_base.hpp.in b/templates/cxx_qft/context_base.hpp.in index 9fbd08de1d..f399ce1199 100644 --- a/templates/cxx_qft/context_base.hpp.in +++ b/templates/cxx_qft/context_base.hpp.in @@ -32,6 +32,8 @@ namespace flexiblesusy { namespace @ModelName@_cxx_diagrams { +using cxx_diagrams::field_indices; + struct context_base { @ModelName@_mass_eigenstates_interface const& model; ///< The model object. @@ -39,14 +41,14 @@ namespace @ModelName@_cxx_diagrams { double mass(const typename field_indices::type& indices) const { using CleanField = - typename fields::remove_lorentz_conjugation::type; + typename cxx_diagrams::fields::remove_lorentz_conjugation::type; return mass_impl(indices); } template double physical_mass(const typename field_indices::type& indices) const { using CleanField = - typename fields::remove_lorentz_conjugation::type; + typename cxx_diagrams::fields::remove_lorentz_conjugation::type; return physical_mass_impl(indices); } diff --git a/templates/cxx_qft/fields.hpp.in b/templates/cxx_qft/fields.hpp.in index 5d74340222..d6ddf45259 100644 --- a/templates/cxx_qft/fields.hpp.in +++ b/templates/cxx_qft/fields.hpp.in @@ -26,277 +26,32 @@ #ifndef @ModelName@_CXXQFT_FIELDS_H #define @ModelName@_CXXQFT_FIELDS_H -#include /**< Only for field_indices and isSMField*/ - -#include -#include - -#include -#include -#include -#include -#include - -#include -#include - -#if BOOST_VERSION >= 105800 -#include -#else -#include -#endif +#include "cxx_qft/fields.hpp" namespace flexiblesusy { namespace @ModelName@_cxx_diagrams { - /** @brief Declare a type that can hold the field indices for any given field. - * @todo Field should have nested numberOfFieldIndices. - * @returns `::type` evaluates to `std::array`. - */ - template - struct field_indices { - /** @b using keyword here is type alias - * (see https://en.cppreference.com/w/cpp/language/type_alias). - * It allows to use @code{.cpp}typename field_indices::type@endcode - * to get @code{.cpp}std::array@endcode - * type in the code. - */ - using type = std::array; - }; - - namespace detail { - /** @brief Declare a metafunction that gives the int value for Field - * during compilation time or `int_` typename of this index. - * @returns `::value` gives compile time integer value. - * @returns `::type` gives `int_` typename. - */ - template - struct number_of_field_indices { - static constexpr int value = - std::tuple_size::type>::value; - using type = boost::mpl::int_; - }; - /* - * @param FieldSequence a Forward Sequence, e.g vector - * (see https://www.boost.org/doc/libs/1_69_0/libs/mpl/doc/refmanual/forward-sequence.html). - * @returns `::type` which accomodates `mpl::int_` with `int N` being the - * sum of @b number of indices of fields inside FieldSequence. - * @returns `::value` which represents `N` where `N` being the `int` - * sum of @b number of indices of fields inside FieldSequence - */ - template - struct total_number_of_field_indices { - using type = typename boost::mpl::fold< - FieldSequence, - boost::mpl::int_<0>, - boost::mpl::plus - > - >::type; - static constexpr int value = type::value; - }; - } // namespace detail - - /* @note Is defined by compiler only if the number of generation for a field - * is not 1. - */ - template - std::enable_if_t - isSMField(const typename field_indices::type& indices) { - boost::array sm_flags; - - #if BOOST_VERSION >= 105800 - boost::fusion::move(typename Field::sm_flags(), sm_flags); /**< Making copy of the information from Field to sm_flags */ - #else - boost::fusion::copy(typename Field::sm_flags(), sm_flags); - #endif - - return sm_flags[indices.front()]; /**< front() accesses the first element. Either all are SM indices or none. */ - } - - template - std::enable_if_t - isSMField(const typename field_indices::type&) { - return boost::mpl::at_c::type::value; - } - - namespace fields - { - enum class ParticleType { - scalar, - fermion, - vector, - ghost - }; - - template - struct is_massless { - static constexpr bool value = Field::massless; - }; - template - constexpr bool is_massless_v = is_massless::value; - - enum class ParticleColorRep { - singlet, - triplet, - anti_triplet, - sextet, - octet - }; - - template - struct is_singlet { - static constexpr bool value = - Field::color_rep == ParticleColorRep::singlet; - }; - template - constexpr bool is_singlet_v = is_singlet::value; - - template - struct is_triplet { - static constexpr bool value = Field::color_rep == ParticleColorRep::triplet; - }; - template - constexpr bool is_triplet_v = is_triplet::value; - - template - struct is_anti_triplet { - static constexpr bool value = - Field::color_rep == ParticleColorRep::anti_triplet; - }; - template - constexpr bool is_anti_triplet_v = is_anti_triplet::value; - - template - struct is_octet { - static constexpr bool value = Field::color_rep == ParticleColorRep::octet; - }; - template - constexpr bool is_octet_v = is_octet::value; - - template - constexpr std::enable_if_t< - is_triplet::value, ParticleColorRep - > - color_conj() { - return ParticleColorRep::anti_triplet; - } - template - constexpr std::enable_if_t< - is_anti_triplet::value, ParticleColorRep - > - color_conj() { - return ParticleColorRep::triplet; - } - template - constexpr std::enable_if_t< - !is_triplet::value && !is_anti_triplet::value, ParticleColorRep - > - color_conj() { - return Field::color_rep; - } +namespace fields { - template - struct bar { - using index_bounds = typename Field::index_bounds; - using sm_flags = typename Field::sm_flags; - using lorentz_conjugate = Field; - using type = bar; - - static constexpr int numberOfGenerations = Field::numberOfGenerations; - static constexpr int numberOfFieldIndices = Field::numberOfFieldIndices; - static constexpr double electric_charge = -Field::electric_charge; - static constexpr auto particle_type = Field::particle_type; - static constexpr auto color_rep = color_conj(); - static constexpr auto massless = Field::massless; - }; - - template - struct conj { - using index_bounds = typename Field::index_bounds; - using sm_flags = typename Field::sm_flags; - using lorentz_conjugate = Field; - using type = conj; - - static constexpr int numberOfGenerations = Field::numberOfGenerations; - static constexpr int numberOfFieldIndices = Field::numberOfFieldIndices; - static constexpr double electric_charge = -Field::electric_charge; - static constexpr auto particle_type = Field::particle_type; - static constexpr auto color_rep = color_conj(); - static constexpr auto massless = Field::massless; - }; - - // Double Lorentz conjugation - template - struct bar> { - using type = Field; - }; - template - struct conj> { - using type = Field; - }; - - // Remove Lorentz conjugation - template - struct remove_lorentz_conjugation { - using type = Field; - }; - - template - struct remove_lorentz_conjugation> { - using type = Field; - }; - - template - struct remove_lorentz_conjugation> { - using type = Field; - }; +using cxx_diagrams::fields::ParticleType; +using cxx_diagrams::fields::ParticleColorRep; +using cxx_diagrams::fields::conj; +using cxx_diagrams::fields::bar; @CXXDiagrams_Fields@ - template - struct is_scalar : public std::false_type {}; - - template - struct is_scalar > : public is_scalar {}; - - template - struct is_scalar > : public is_scalar {}; +} // namespace fields - template - struct is_fermion : public std::false_type {}; - - template - struct is_fermion > : public is_fermion {}; - - template - struct is_fermion > : public is_fermion {}; - - template - struct is_vector : public std::false_type {}; - - template - struct is_vector > : public is_vector {}; - - template - struct is_vector > : public is_vector {}; - - template - struct is_ghost : public std::false_type {}; +} // namespace @ModelName@_cxx_diagrams - template - struct is_ghost > : public is_ghost {}; +namespace cxx_diagrams { +namespace fields{ - template - struct is_ghost > : public is_ghost {}; +@CXXDiagrams_realFields@ @defineFieldTraits@ - } // namespace fields - - using fields::bar; - using fields::conj; - using fields::remove_lorentz_conjugation; -} // namespace @ModelName@_cxx_diagrams +} // namespace fields +} // namespace cxx_diagrams } // namespace flexiblesusy diff --git a/templates/cxx_qft/npointfunctions_wilsoncoeffs.hpp.in b/templates/cxx_qft/npointfunctions_wilsoncoeffs.hpp.in index e6fc463aae..939c1f89eb 100644 --- a/templates/cxx_qft/npointfunctions_wilsoncoeffs.hpp.in +++ b/templates/cxx_qft/npointfunctions_wilsoncoeffs.hpp.in @@ -191,7 +191,7 @@ struct context_with_vertices : context_base { std::complex vertex(triple_vector, const typename Vertex::indices_type &indices ) const { // FIXME: hardcoded odd permutation to agree with SPheno - return Vertex::evaluate( indices, model ).value( TripleVectorVertex::odd_permutation{} ); + return Vertex::evaluate( indices, model ).value( cxx_diagrams::TripleVectorVertex::odd_permutation{} ); } double scale( void ) const { diff --git a/templates/cxx_qft/vertices.hpp.in b/templates/cxx_qft/vertices.hpp.in index 3582a42d0b..ac99ea3d07 100644 --- a/templates/cxx_qft/vertices.hpp.in +++ b/templates/cxx_qft/vertices.hpp.in @@ -30,6 +30,7 @@ #include "numerics2.hpp" #include "@ModelName@_fields.hpp" +#include "cxx_qft/vertices.hpp" #include #include @@ -42,239 +43,6 @@ namespace flexiblesusy { namespace @ModelName@_cxx_diagrams { - class ScalarVertex - { - private: - std::complex val; - - public: - ScalarVertex(std::complex v) : val(v) {} - - std::complex value() const { return val; } - - bool isZero() const - { - return (is_zero(val.real()) && is_zero(val.imag())); - } - }; - - class ChiralVertex - { - private: - std::pair, std::complex> value; - - public: - ChiralVertex(const std::complex& left, - const std::complex& right) - : value(left, right) - { - } - - std::complex left() const { return value.first; } - std::complex right() const { return value.second; } - - bool isZero() const - { - return (is_zero(value.first.real()) && is_zero(value.first.imag()) && - is_zero(value.second.real()) && is_zero(value.second.imag())); - } - }; - -/** \brief A class representing a numerically evaluated - * tree-level vertex that is proportional to a momentum. - * It consists of a complex number as well as an index - * corresponding to the index of the field to whose - * momentum the vertex is proportional. - **/ -class MomentumVertex { - std::complex val; - int ind; -public: - /** \brief Contruct a MomentumVertex from a - * complex number representing and a field index. - **/ - MomentumVertex(const std::complex& v, int i) - : val(v), ind(i) - {} - - /** \brief Retrieve the index of the field to whose - * momentum the vertex is proportional. - * \returns the appropriate index - **/ - int index() const { return ind; } - - /** \brief Retrieve the numerical value of the vertex - * \param i The index of the field to whose momentum - * the vertex is proportional. - * \returns the coefficient of the even permutation - **/ - std::complex value(int i) const - { - if (i != ind) - throw std::invalid_argument( - "MomentumVertex: Wrong index specified"); - - return val; - } - - bool isZero() const - { - return (is_zero(val.real()) && is_zero(val.imag())); - } -}; - -/** \brief A class representing a numerically evaluated - * tree-level vertex with three vector bosons. - * It consists of one complex number as well as an \a ordering - * encoding whether the complex number is taken to be the - * coefficient of - * - * \f{equation}{ - * g[l1, l2] * (p[field1, l3] - p[field2, lIndex3]) + - * g[l2, l3] * (p[field2, l1] - p[field3, lIndex1]) + - * g[l1, l3] * (p[field3, l2] - p[field1, lIndex2]) - * \f} - * - * or its negative. - * The former corresponds to the \a even permutation and - * the latter to the \a odd permutation. - **/ -class TripleVectorVertex { -public: - struct even_permutation {}; - struct odd_permutation {}; -private: - std::complex val; - bool even; -public: - /** \brief Contruct a TripleVectorVertex from a - * complex number representing the even coefficient. - **/ - TripleVectorVertex(const std::complex& v, - even_permutation) - : val(v), even(true) - {} - - /** \brief Contruct a TripleVectorVertex from a - * complex number representing the odd coefficient. - **/ - TripleVectorVertex(const std::complex& v, - odd_permutation) - : val(v), even(false) - {} - - /** \brief Check whether the value in the vertex is stored - * as proportional to the even permutation. - * \returns true if yes and false otherwise - **/ - bool is_even() const { return even; } - - /** \brief Retrieve the coefficient of the even permutation - * \returns the coefficient of the even permutation - **/ - std::complex value(even_permutation) const - { return even ? val : - val; } - - /** \brief Retrieve the coefficient of the odd permutation - * \returns the coefficient of the odd permutation - **/ - std::complex value(odd_permutation) const - { return even ? - val : val; } - - bool isZero() const - { - return (is_zero(val.real()) && is_zero(val.imag())); - } -}; - -/** \brief A class representing a numerically evaluated - * tree-level vertex with four vector bosons. - * It consists of three complex numbers corresponding to - * (in order) the basis expansion with respect to the basis: - * - * \f{equation}{ - * ( g[l1, l2] g[l3, l4], g[l1, l3] g[l2, l4], g[l1, l4] g[l2, l3] ) - * \f} - **/ -class QuadrupleVectorVertex { - std::complex part1, part2, part3; - -public: - /** \brief Contruct a QuadrupleVectorVertex from three - * complex numbers representing the coefficients in the - * basis expansion. - **/ - QuadrupleVectorVertex(const std::complex& p1, - const std::complex& p2, - const std::complex& p3) - : part1(p1), part2(p2), part3(p3) - {} - - /** \brief Retrieve the coefficient of \f$ g[l1, l2] g[l3, l4] \f$ - * \returns the corresponding coefficient - **/ - std::complex value1() const { return part1; } - - /** \brief Retrieve the coefficient of \f$ g[l1, l3] g[l2, l4] \f$ - * \returns the corresponding coefficient - **/ - std::complex value2() const { return part2; } - - /** \brief Retrieve the coefficient of \f$ g[l1, l4] g[l2, l3] \f$ - * \returns the corresponding coefficient - **/ - std::complex value3() const { return part3; } - - bool isZero() const - { - return (is_zero(part1.real()) && is_zero(part1.imag()) && - is_zero(part2.real()) && is_zero(part2.imag()) && - is_zero(part3.real()) && is_zero(part3.imag())); - } -}; - -class MomentumDifferenceVertex { - std::complex val; - int minuendIndex; - int subtrahendIndex; -public: - MomentumDifferenceVertex(std::complex v, int mi, int si) - : val(v), minuendIndex(mi), subtrahendIndex(si) {} - - std::complex value(int mi, int si) const - { - if (mi == minuendIndex && si == subtrahendIndex) - return val; - if (mi == subtrahendIndex && si == minuendIndex) - return -val; - - throw std::invalid_argument( - "MomentumDifferenceVertex: Wrong index combination"); - return 0.0; - } - - int incoming_index() const { return minuendIndex; } - int outgoing_index() const { return subtrahendIndex; } - - bool isZero() const - { - return (is_zero(val.real()) && is_zero(val.imag())); - } -}; - -class InverseMetricVertex { - std::complex val; -public: - InverseMetricVertex(std::complex v) : val(v) {} - - std::complex value() const { return val; } - - bool isZero() const - { - return (is_zero(val.real()) && is_zero(val.imag())); - } -}; - namespace detail { template struct VertexImpl; } // namespace detail @@ -296,7 +64,7 @@ struct Vertex { > >::type; using indices_type = std::array >::value >; @@ -328,7 +96,7 @@ struct Vertex { >::type; constexpr int offset = - detail::total_number_of_field_indices::value; + cxx_diagrams::detail::total_number_of_field_indices::value; constexpr int length = std::tuple_size::value; result_type result_indices; @@ -352,7 +120,7 @@ struct context_base; namespace detail { @CXXDiagrams_VertexPrototypes@ -ChiralVertex unit_charge(const context_base& context); +cxx_diagrams::ChiralVertex unit_charge(const context_base& context); } // namespace detail inline double unit_charge(const context_base& context) diff --git a/templates/decays/FlexibleDecay.mk.in b/templates/decays/FlexibleDecay.mk.in index 2533ed0f8b..0ca9d7db23 100644 --- a/templates/decays/FlexibleDecay.mk.in +++ b/templates/decays/FlexibleDecay.mk.in @@ -22,8 +22,7 @@ LIB@ModelName@_SRC += \ LIB@ModelName@_HDR += \ $(DIR)/decays/@ModelName@_decay_table.hpp \ - $(DIR)/decays/@ModelName@_decays.hpp \ - $(DIR)/decays/@ModelName@_decay_amplitudes.hpp + $(DIR)/decays/@ModelName@_decays.hpp EXE@ModelName@_SRC += \ $(DIR)/run_decays_@ModelName@.cpp diff --git a/templates/decays/decay_amplitudes.hpp.in b/templates/decays/decay_amplitudes.hpp.in deleted file mode 100644 index d76eaa2117..0000000000 --- a/templates/decays/decay_amplitudes.hpp.in +++ /dev/null @@ -1,130 +0,0 @@ -// ==================================================================== -// This file is part of FlexibleSUSY. -// -// FlexibleSUSY 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. -// -// FlexibleSUSY 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 FlexibleSUSY. If not, see -// . -// ==================================================================== - -#ifndef DECAY_AMPLITUDES_H -#define DECAY_AMPLITUDES_H - -#include "decays/decay_amplitudes.hpp" -#include "cxx_qft/@ModelName@_qft.hpp" - -namespace flexiblesusy { - -namespace detail { - -template -struct Two_body_decay_amplitude_type { }; - -template -struct Two_body_decay_amplitude_type< - Field_in, Field_out_1, Field_out_2, - std::enable_if_t<@ModelName@_cxx_diagrams::fields::is_scalar::value && - @ModelName@_cxx_diagrams::fields::is_scalar::value && - @ModelName@_cxx_diagrams::fields::is_scalar::value>> { - using type = Decay_amplitude_SSS; -}; - -template -struct Two_body_decay_amplitude_type< - Field_in, Field_out_1, Field_out_2, - std::enable_if_t<@ModelName@_cxx_diagrams::fields::is_scalar::value && - @ModelName@_cxx_diagrams::fields::is_scalar::value && - @ModelName@_cxx_diagrams::fields::is_vector::value>> { - using type = Decay_amplitude_SSV; -}; - -template -struct Two_body_decay_amplitude_type< - Field_in, Field_out_1, Field_out_2, - std::enable_if_t<@ModelName@_cxx_diagrams::fields::is_scalar::value && - @ModelName@_cxx_diagrams::fields::is_vector::value && - @ModelName@_cxx_diagrams::fields::is_scalar::value>> { - using type = Decay_amplitude_SSV; -}; - -template -struct Two_body_decay_amplitude_type< - Field_in, Field_out_1, Field_out_2, - std::enable_if_t<@ModelName@_cxx_diagrams::fields::is_scalar::value && - @ModelName@_cxx_diagrams::fields::is_vector::value && - @ModelName@_cxx_diagrams::fields::is_vector::value>> { - using type = Decay_amplitude_SVV; -}; - -template -struct Two_body_decay_amplitude_type< - Field_in, Field_out_1, Field_out_2, - std::enable_if_t<@ModelName@_cxx_diagrams::fields::is_scalar::value && - @ModelName@_cxx_diagrams::fields::is_fermion::value && - @ModelName@_cxx_diagrams::fields::is_fermion::value>> { - using type = Decay_amplitude_SFF; -}; - -template -struct Two_body_decay_amplitude_type< - Field_in, Field_out_1, Field_out_2, - std::enable_if_t<@ModelName@_cxx_diagrams::fields::is_fermion::value && - @ModelName@_cxx_diagrams::fields::is_fermion::value && - @ModelName@_cxx_diagrams::fields::is_scalar::value>> { - using type = Decay_amplitude_FFS; -}; - -template -struct Two_body_decay_amplitude_type< - Field_in, Field_out_1, Field_out_2, - std::enable_if_t<@ModelName@_cxx_diagrams::fields::is_fermion::value && - @ModelName@_cxx_diagrams::fields::is_scalar::value && - @ModelName@_cxx_diagrams::fields::is_fermion::value>> { - using type = Decay_amplitude_FFS; -}; - -template -struct Two_body_decay_amplitude_type< - Field_in, Field_out_1, Field_out_2, - std::enable_if_t<@ModelName@_cxx_diagrams::fields::is_fermion::value && - @ModelName@_cxx_diagrams::fields::is_fermion::value && - @ModelName@_cxx_diagrams::fields::is_vector::value>> { - using type = Decay_amplitude_FFV; -}; - -template -struct Two_body_decay_amplitude_type< - Field_in, Field_out_1, Field_out_2, - std::enable_if_t<@ModelName@_cxx_diagrams::fields::is_fermion::value && - @ModelName@_cxx_diagrams::fields::is_vector::value && - @ModelName@_cxx_diagrams::fields::is_fermion::value>> { - using type = Decay_amplitude_FFV; -}; - -} // namespace detail - -/** - * @class Decay_amplitude_type - * @brief helper class to determine amplitude type for a given set of fields - */ -template -struct Decay_amplitude_type { - using type = - std::enable_if_t< - sizeof...(Fields) == 3, - typename detail::Two_body_decay_amplitude_type::type>; -}; - -} // namespace flexiblesusy - -#endif diff --git a/templates/decays/decays.hpp.in b/templates/decays/decays.hpp.in index 33ecb50118..0bc91b2b0c 100644 --- a/templates/decays/decays.hpp.in +++ b/templates/decays/decays.hpp.in @@ -32,37 +32,16 @@ #include "@ModelName@_mass_eigenstates.hpp" #include "@ModelName@_mass_eigenstates_decoupling_scheme.hpp" #include "cxx_qft/@ModelName@_qft.hpp" -#include "@ModelName@_decay_amplitudes.hpp" #include "decays/flexibledecay_problems.hpp" #include "lowe.h" #include "wrappers.hpp" #include "error.hpp" #include "physical_input.hpp" #include "decays/flexibledecay_settings.hpp" +#include "decays/decay_amplitudes.hpp" namespace flexiblesusy { -template -constexpr std::enable_if_t::value, double> -final_state_symmetry_factor(typename @ModelName@_cxx_diagrams::field_indices::type const& idx1, - typename @ModelName@_cxx_diagrams::field_indices::type const& idx2) -{ - return 1.; -} - -template -std::enable_if_t::value, double> -final_state_symmetry_factor(typename @ModelName@_cxx_diagrams::field_indices::type const& idx1, - typename @ModelName@_cxx_diagrams::field_indices::type const& idx2) -{ - if (boost::range::equal(idx1, idx2)) { - return 0.5; - } - else { - return 1.; - } -} - class @ModelName@_decays { public: @ModelName@_decays() = default; @@ -105,22 +84,22 @@ private: typename Decay_amplitude_type::type calculate_amplitude( const @ModelName@_cxx_diagrams::context_base&, - const typename @ModelName@_cxx_diagrams::field_indices::type&, - const typename @ModelName@_cxx_diagrams::field_indices::type&, - const typename @ModelName@_cxx_diagrams::field_indices::type&) const; + const typename cxx_diagrams::field_indices::type&, + const typename cxx_diagrams::field_indices::type&, + const typename cxx_diagrams::field_indices::type&) const; template double amplitude_squared(@ModelName@_cxx_diagrams::context_base const& context, - typename @ModelName@_cxx_diagrams::field_indices::type const& indexIn, - typename @ModelName@_cxx_diagrams::field_indices::type const& indexOut1, - typename @ModelName@_cxx_diagrams::field_indices::type const& indexOut2) const; + typename cxx_diagrams::field_indices::type const& indexIn, + typename cxx_diagrams::field_indices::type const& indexOut1, + typename cxx_diagrams::field_indices::type const& indexOut2) const; template double get_partial_width( const @ModelName@_cxx_diagrams::context_base&, - typename @ModelName@_cxx_diagrams::field_indices::type const&, - typename @ModelName@_cxx_diagrams::field_indices::type const&, - typename @ModelName@_cxx_diagrams::field_indices::type const&) const; + typename cxx_diagrams::field_indices::type const&, + typename cxx_diagrams::field_indices::type const&, + typename cxx_diagrams::field_indices::type const&) const; }; @calcAmplitudeSpecializationDecls@ @@ -128,9 +107,9 @@ private: template double @ModelName@_decays::amplitude_squared(@ModelName@_cxx_diagrams::context_base const& context, - typename @ModelName@_cxx_diagrams::field_indices::type const& indexIn, - typename @ModelName@_cxx_diagrams::field_indices::type const& indexOut1, - typename @ModelName@_cxx_diagrams::field_indices::type const& indexOut2) const + typename cxx_diagrams::field_indices::type const& indexIn, + typename cxx_diagrams::field_indices::type const& indexOut1, + typename cxx_diagrams::field_indices::type const& indexOut2) const { const auto mat_elem = calculate_amplitude( @@ -138,152 +117,13 @@ double return mat_elem.square(); } -// returns a squared color generator for a 3 point amplitude with FieldIn, FieldOut1 and FieldOut2 -// averaged over inital state colors -// the generator is guessed from color representations of FieldIn, FieldOut1 and FieldOut2 -// This is not a bulletproof solution and might fail in general but is enough for -// decays of color singlets - -// 1 -> 1, 1 -template -constexpr -std::enable_if_t< -@ModelName@_cxx_diagrams::fields::is_singlet_v && -@ModelName@_cxx_diagrams::fields::is_singlet_v && -@ModelName@_cxx_diagrams::fields::is_singlet_v, double> -squared_color_generator() {return 1.;} - -// 1 -> 3, 3bar -template -constexpr -std::enable_if_t< - @ModelName@_cxx_diagrams::fields::is_singlet_v - && - ( - (@ModelName@_cxx_diagrams::fields::is_triplet_v && - @ModelName@_cxx_diagrams::fields::is_anti_triplet_v) - || - (@ModelName@_cxx_diagrams::fields::is_anti_triplet_v && - @ModelName@_cxx_diagrams::fields::is_triplet_v) - ), double -> -squared_color_generator() {return 3.;} - -// 1 -> 8, 8 -template -constexpr -std::enable_if_t< -@ModelName@_cxx_diagrams::fields::is_singlet_v && -@ModelName@_cxx_diagrams::fields::is_octet_v && -@ModelName@_cxx_diagrams::fields::is_octet_v, double> -squared_color_generator() {return 8.;} - -// 3 -> 3, 1; 3bar -> 3bar, 1 -template -constexpr -std::enable_if_t< -( -@ModelName@_cxx_diagrams::fields::is_triplet_v && -((@ModelName@_cxx_diagrams::fields::is_triplet_v && -@ModelName@_cxx_diagrams::fields::is_singlet_v) || -(@ModelName@_cxx_diagrams::fields::is_singlet_v && -@ModelName@_cxx_diagrams::fields::is_triplet_v)) -) -|| -( -@ModelName@_cxx_diagrams::fields::is_anti_triplet_v && -((@ModelName@_cxx_diagrams::fields::is_anti_triplet_v && -@ModelName@_cxx_diagrams::fields::is_singlet_v) || -(@ModelName@_cxx_diagrams::fields::is_singlet_v && -@ModelName@_cxx_diagrams::fields::is_anti_triplet_v)) -) -, double> -squared_color_generator() {return 1.;} - -// 3 -> 3, 8; 3bar -> 3bar, 8 -template -constexpr -std::enable_if_t< -( -@ModelName@_cxx_diagrams::fields::is_triplet_v && -((@ModelName@_cxx_diagrams::fields::is_triplet_v && -@ModelName@_cxx_diagrams::fields::is_octet_v) || -(@ModelName@_cxx_diagrams::fields::is_octet_v && -@ModelName@_cxx_diagrams::fields::is_triplet_v)) -) -|| -( -@ModelName@_cxx_diagrams::fields::is_anti_triplet_v && -((@ModelName@_cxx_diagrams::fields::is_anti_triplet_v && -@ModelName@_cxx_diagrams::fields::is_octet_v) || -(@ModelName@_cxx_diagrams::fields::is_octet_v && -@ModelName@_cxx_diagrams::fields::is_anti_triplet_v)) -) -, double> -squared_color_generator() {return 4.;} - -// 8 -> 8, 1 -template -constexpr -std::enable_if_t< -@ModelName@_cxx_diagrams::fields::is_octet_v && -((@ModelName@_cxx_diagrams::fields::is_octet_v && -@ModelName@_cxx_diagrams::fields::is_singlet_v) || -(@ModelName@_cxx_diagrams::fields::is_singlet_v && -@ModelName@_cxx_diagrams::fields::is_octet_v)) -, double> -squared_color_generator() {return 1.;} - -// 8 -> 3, 3bar -template -constexpr -std::enable_if_t< - @ModelName@_cxx_diagrams::fields::is_octet_v - && - ( - (@ModelName@_cxx_diagrams::fields::is_triplet_v && - @ModelName@_cxx_diagrams::fields::is_anti_triplet_v) - || - (@ModelName@_cxx_diagrams::fields::is_anti_triplet_v && - @ModelName@_cxx_diagrams::fields::is_triplet_v) - ), double -> -squared_color_generator() {return 1./2.;} - -// 8 -> 8, 8 with identical particles in the final state -// because of symmetry of the final state it must be proportional to d^2 -template -constexpr -std::enable_if_t< -@ModelName@_cxx_diagrams::fields::is_octet_v && -@ModelName@_cxx_diagrams::fields::is_octet_v && -@ModelName@_cxx_diagrams::fields::is_octet_v && -std::is_same::value -, double> -// color: d^2 = (2 (4 - 5 Nc^2 + Nc^4) TR)/Nc = 40/3 -// average: 1/8 -squared_color_generator() {return 40/24.;} - -// 8 -> 8, 8 with differnt particles in the final state -template -constexpr -std::enable_if_t< -@ModelName@_cxx_diagrams::fields::is_octet_v && -@ModelName@_cxx_diagrams::fields::is_octet_v && -@ModelName@_cxx_diagrams::fields::is_octet_v && -!std::is_same::value -, double> -// color: f^2 = 2 Nc (-1 + Nc^2) TR = 24 -// average: 1/8 -squared_color_generator() {return 3.;} - // generic decay of FieldIn -> FieldOut1 FieldOut2 template double @ModelName@_decays::get_partial_width( const @ModelName@_cxx_diagrams::context_base& context, - typename @ModelName@_cxx_diagrams::field_indices::type const& indexIn, - typename @ModelName@_cxx_diagrams::field_indices::type const& indexOut1, - typename @ModelName@_cxx_diagrams::field_indices::type const& indexOut2 + typename cxx_diagrams::field_indices::type const& indexIn, + typename cxx_diagrams::field_indices::type const& indexOut1, + typename cxx_diagrams::field_indices::type const& indexOut2 ) const { diff --git a/templates/module.mk b/templates/module.mk index 73a13618c7..3a5f114dc4 100644 --- a/templates/module.mk +++ b/templates/module.mk @@ -14,7 +14,6 @@ BASE_TEMPLATES := \ $(DIR)/decays/decay_table.cpp.in \ $(DIR)/decays/decays.hpp.in \ $(DIR)/decays/decays.cpp.in \ - $(DIR)/decays/decay_amplitudes.hpp.in \ $(DIR)/edm.hpp.in \ $(DIR)/edm.cpp.in \ $(DIR)/FFV_form_factors.hpp.in \ diff --git a/test/test_MSSM_matching_selfenergy_Fd.cpp.in b/test/test_MSSM_matching_selfenergy_Fd.cpp.in index 46dffb9395..ae0001550c 100644 --- a/test/test_MSSM_matching_selfenergy_Fd.cpp.in +++ b/test/test_MSSM_matching_selfenergy_Fd.cpp.in @@ -48,6 +48,8 @@ namespace detail namespace npointfunctions { +using cxx_diagrams::conj; +using cxx_diagrams::bar; @NPointFunctions_Selfenergy_Fd_1loop@ } } diff --git a/test/test_MSSM_npointfunctions.cpp.in b/test/test_MSSM_npointfunctions.cpp.in index 50923f7a9d..d72538a8d6 100644 --- a/test/test_MSSM_npointfunctions.cpp.in +++ b/test/test_MSSM_npointfunctions.cpp.in @@ -48,6 +48,8 @@ namespace detail namespace npointfunctions { +using cxx_diagrams::conj; +using cxx_diagrams::bar; @NPointFunctions_Selfenergy_hh_1loop@ } } diff --git a/test/test_SM_cxxdiagrams.meta b/test/test_SM_cxxdiagrams.meta index f194e09f9f..393eece2cf 100644 --- a/test/test_SM_cxxdiagrams.meta +++ b/test/test_SM_cxxdiagrams.meta @@ -52,30 +52,30 @@ VectorToGhost[field_ ? TreeMasses`IsVector] := Symbol[StringReplace[SymbolName[field], "V" ~~ name_ :> "g" <> name]]; CXXVertexFromFSVertexCalls[ScalarVertex, {fsCall_String}] := - "return ScalarVertex{ " <> fsCall <> "( model_and_indices ) };" + "return cxx_diagrams::ScalarVertex{ " <> fsCall <> "( model_and_indices ) };" CXXVertexFromFSVertexCalls[ChiralVertex, {fsCallPL_String, fsCallPR_String}] := - "return ChiralVertex{ " <> fsCallPL <> "( model_and_indices ), " <> + "return cxx_diagrams::ChiralVertex{ " <> fsCallPL <> "( model_and_indices ), " <> fsCallPR <> "( model_and_indices ) };" (* FIXME: The momentum index is hardcoded *) CXXVertexFromFSVertexCalls[MomentumVertex, {fsCall_String}] := - "return MomentumVertex{ " <> fsCall <> "( model_and_indices ), 1 };" + "return cxx_diagrams::MomentumVertex{ " <> fsCall <> "( model_and_indices ), 1 };" (* FIXME: The permutation is hardcoded *) CXXVertexFromFSVertexCalls[TripleVectorVertex, {fsCall_String}] := - "return TripleVectorVertex{ " <> fsCall <> "( model_and_indices ), "<> - "TripleVectorVertex::odd_permutation{} };" + "return cxx_diagrams::TripleVectorVertex{ " <> fsCall <> "( model_and_indices ), "<> + "cxx_diagrams::TripleVectorVertex::odd_permutation{} };" CXXVertexFromFSVertexCalls[QuadrupleVectorVertex, {fsCall1_String, fsCall2_String, fsCall3_String}] := - "return QuadrupleVectorVertex{ " <> fsCall1 <> "( model_and_indices ), " <> + "return cxx_diagrams::QuadrupleVectorVertex{ " <> fsCall1 <> "( model_and_indices ), " <> fsCall2 <> "( model_and_indices ), " <> fsCall3 <> "( model_and_indices ) };" CXXVertexFromFSVertexCalls[InverseMetricVertex, {fsCall_String}] := - "return InverseMetricVertex{ " <> fsCall <> "( model_and_indices ) };" + "return cxx_diagrams::InverseMetricVertex{ " <> fsCall <> "( model_and_indices ) };" (* Zero vertices are handled differently by CXXDiagrams. Hence we test * them separately. diff --git a/test/test_SM_matching_selfenergy_Fd.cpp.in b/test/test_SM_matching_selfenergy_Fd.cpp.in index 68d4057489..1d983e4174 100644 --- a/test/test_SM_matching_selfenergy_Fd.cpp.in +++ b/test/test_SM_matching_selfenergy_Fd.cpp.in @@ -51,6 +51,8 @@ namespace detail namespace npointfunctions { +using cxx_diagrams::bar; +using cxx_diagrams::conj; @NPointFunctions_Selfenergy_Fd_1loop@ } } diff --git a/test/test_SM_npointfunctions.cpp.in b/test/test_SM_npointfunctions.cpp.in index 45e28df47f..287d643ccb 100644 --- a/test/test_SM_npointfunctions.cpp.in +++ b/test/test_SM_npointfunctions.cpp.in @@ -48,6 +48,8 @@ namespace detail namespace npointfunctions { +using cxx_diagrams::bar; +using cxx_diagrams::conj; @NPointFunctions_Selfenergy_hh_1loop@ } } diff --git a/test/test_cxxdiagrams_vertices.hpp b/test/test_cxxdiagrams_vertices.hpp index 97d2575e40..69b72e1eb3 100644 --- a/test/test_cxxdiagrams_vertices.hpp +++ b/test/test_cxxdiagrams_vertices.hpp @@ -80,32 +80,32 @@ struct test_zero_vertex } } - void test( const SM_cxx_diagrams::ScalarVertex &v ) + void test( const cxx_diagrams::ScalarVertex &v ) { TEST_COMPLEX_EQUALITY( v.value(), 0 ); } - void test( const SM_cxx_diagrams::MomentumVertex &v ) + void test( const cxx_diagrams::MomentumVertex &v ) { TEST_COMPLEX_EQUALITY( v.value( v.index() ), 0 ); } - void test( const SM_cxx_diagrams::MomentumDifferenceVertex &v ) + void test( const cxx_diagrams::MomentumDifferenceVertex &v ) { TEST_COMPLEX_EQUALITY( v.value( v.incoming_index(), v.outgoing_index() ), 0 ); } - void test( const SM_cxx_diagrams::InverseMetricVertex &v ) + void test( const cxx_diagrams::InverseMetricVertex &v ) { TEST_COMPLEX_EQUALITY( v.value(), 0 ); } - void test( const SM_cxx_diagrams::ChiralVertex &v ) + void test( const cxx_diagrams::ChiralVertex &v ) { TEST_COMPLEX_EQUALITY( v.left(), 0 ); TEST_COMPLEX_EQUALITY( v.right(), 0 ); } - void test( const SM_cxx_diagrams::TripleVectorVertex &v ) + void test( const cxx_diagrams::TripleVectorVertex &v ) { TEST_COMPLEX_EQUALITY( v.value( - SM_cxx_diagrams::TripleVectorVertex::even_permutation{} ), 0 ); } + cxx_diagrams::TripleVectorVertex::even_permutation{} ), 0 ); } - void test( const SM_cxx_diagrams::QuadrupleVectorVertex &v ) + void test( const cxx_diagrams::QuadrupleVectorVertex &v ) { TEST_COMPLEX_EQUALITY( v.value1(), 0 ); TEST_COMPLEX_EQUALITY( v.value2(), 0 ); @@ -147,20 +147,20 @@ struct test_vertex_equality } } - void test( const SM_cxx_diagrams::ScalarVertex &v1, - const SM_cxx_diagrams::ScalarVertex &v2 ) + void test( const cxx_diagrams::ScalarVertex &v1, + const cxx_diagrams::ScalarVertex &v2 ) { TEST_COMPLEX_EQUALITY( v1.value(), v2.value() ); } - void test( const SM_cxx_diagrams::MomentumVertex &v1, - const SM_cxx_diagrams::MomentumVertex &v2 ) + void test( const cxx_diagrams::MomentumVertex &v1, + const cxx_diagrams::MomentumVertex &v2 ) { BOOST_TEST( v1.index() == v2.index() ); TEST_COMPLEX_EQUALITY( v1.value( v1.index() ), v2.value( v1.index() ) ); } - void test( const SM_cxx_diagrams::MomentumDifferenceVertex &v1, - const SM_cxx_diagrams::MomentumDifferenceVertex &v2 ) + void test( const cxx_diagrams::MomentumDifferenceVertex &v1, + const cxx_diagrams::MomentumDifferenceVertex &v2 ) { if( v1.incoming_index() == v2.incoming_index() ) { @@ -177,26 +177,26 @@ struct test_vertex_equality ); } - void test( const SM_cxx_diagrams::InverseMetricVertex &v1, - const SM_cxx_diagrams::InverseMetricVertex &v2 ) + void test( const cxx_diagrams::InverseMetricVertex &v1, + const cxx_diagrams::InverseMetricVertex &v2 ) { TEST_COMPLEX_EQUALITY( v1.value(), v2.value() ); } - void test( const SM_cxx_diagrams::ChiralVertex &v1, - const SM_cxx_diagrams::ChiralVertex &v2 ) + void test( const cxx_diagrams::ChiralVertex &v1, + const cxx_diagrams::ChiralVertex &v2 ) { TEST_COMPLEX_EQUALITY( v1.left(), v2.left() ); TEST_COMPLEX_EQUALITY( v1.right(), v2.right() ); } - void test( const SM_cxx_diagrams::TripleVectorVertex &v1, - const SM_cxx_diagrams::TripleVectorVertex &v2 ) + void test( const cxx_diagrams::TripleVectorVertex &v1, + const cxx_diagrams::TripleVectorVertex &v2 ) { - using even = SM_cxx_diagrams::TripleVectorVertex::even_permutation; + using even = cxx_diagrams::TripleVectorVertex::even_permutation; TEST_COMPLEX_EQUALITY( v1.value( even{} ), v2.value( even{} ) ); } - void test( const SM_cxx_diagrams::QuadrupleVectorVertex &v1, - const SM_cxx_diagrams::QuadrupleVectorVertex &v2 ) + void test( const cxx_diagrams::QuadrupleVectorVertex &v1, + const cxx_diagrams::QuadrupleVectorVertex &v2 ) { TEST_COMPLEX_EQUALITY( v1.value1(), v2.value1() ); TEST_COMPLEX_EQUALITY( v1.value2(), v2.value2() ); From c4c1afda357f56c8daa42690e91060ba609fab8e Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 9 Jun 2022 12:54:11 +0200 Subject: [PATCH 154/477] run tests for CMSSMSemiAnalytic --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3c3f5dcbd7..dc72d4edf7 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -135,7 +135,7 @@ jobs: env: FORMCALC_VERSION: '9.10' - MODELS1: 'MSSM THDMII ScalarLeptoquarks MSSMCPV CMSSM E6SSM CMSSMNoFV CMSSMCKM MSSMNoFV NUHMSSMNoFVHimalaya' + MODELS1: 'MSSM THDMII ScalarLeptoquarks MSSMCPV CMSSM E6SSM CMSSMNoFV CMSSMCKM MSSMNoFV NUHMSSMNoFVHimalaya CMSSMSemiAnalytic' MODELS2: 'MRSSM2 LRLR SM MRSSM2CKM' steps: From 129eb4df4d66b0b805e241384256f35bde2b74f0 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Mon, 20 Jun 2022 01:19:19 +0200 Subject: [PATCH 155/477] CI - don't pull the huge image just for shellcheck --- .github/workflows/static-analysis.yml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 0ce9963215..9b91200b35 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -24,11 +24,14 @@ on: jobs: check-scripts: runs-on: ubuntu-latest - container: - image: navir/opensuseleap-for-flexiblesusy:latest steps: + - name: Install shellcheck + run: | + apt-get update -y + apt-get install -y shellcheck + - name: Checkout uses: actions/checkout@v3 From f6b21f8bfe345d8713c41d8080910ef089bf3b3f Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 15 Jun 2022 10:00:29 +0200 Subject: [PATCH 156/477] remove comparison of decays from test_CMSSMSemiAnalytic_spectrum --- test/test_CMSSMSemiAnalytic_spectrum.sh | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/test_CMSSMSemiAnalytic_spectrum.sh b/test/test_CMSSMSemiAnalytic_spectrum.sh index 6a8d25eda2..4409125c86 100755 --- a/test/test_CMSSMSemiAnalytic_spectrum.sh +++ b/test/test_CMSSMSemiAnalytic_spectrum.sh @@ -66,7 +66,8 @@ remove_mixing_and_input_blocks() { | $awk_cmd -f "$remove_block" -v block=EXTPAR \ | $awk_cmd -f "$remove_block" -v block=SPINFO \ | $awk_cmd -f "$remove_block" -v block=MODSEL \ - | $awk_cmd -f "$remove_block" -v block=FlexibleSUSY + | $awk_cmd -f "$remove_block" -v block=FlexibleSUSY \ + | $awk_cmd -f "$remove_block" -v block=DCINFO } remove_extra_blocks() { From b7f7af96b8034fd23f4ed71eadc9a039c9e7a928 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Mon, 20 Jun 2022 11:13:48 +0200 Subject: [PATCH 157/477] added sudo missing in 129eb4df4d66b0b805e241384256f35bde2b74f0 --- .github/workflows/static-analysis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 9b91200b35..af7937e0d6 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -29,8 +29,8 @@ jobs: - name: Install shellcheck run: | - apt-get update -y - apt-get install -y shellcheck + sudo apt-get update -y + sudo apt-get install -y shellcheck - name: Checkout uses: actions/checkout@v3 From 3ebc5d94eca83d14c67f7a0dd21fdc406e3ed992 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Mon, 20 Jun 2022 09:46:03 +0200 Subject: [PATCH 158/477] move lvalue objects --- src/slha_io.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/slha_io.cpp b/src/slha_io.cpp index 855b8a52a5..9a6b49f77c 100644 --- a/src/slha_io.cpp +++ b/src/slha_io.cpp @@ -773,9 +773,9 @@ void SLHA_io::set_block(const std::string& lines, Position position) data->erase(block.name()); if (position == front) { - data->push_front(block); + data->push_front(std::move(block)); } else { - data->push_back(block); + data->push_back(std::move(block)); } } From 66c67a98e04a357edf86deae5ae7d206b795374d Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Tue, 21 Jun 2022 08:46:04 +0200 Subject: [PATCH 159/477] shellcheck v0.8 is only avaliable on ubuntu-22.04 runner --- .github/workflows/static-analysis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index af7937e0d6..066bc9813c 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -23,7 +23,7 @@ on: jobs: check-scripts: - runs-on: ubuntu-latest + runs-on: ubuntu-22.04 steps: From 2b6cd509b01277c641515687fb495c9d11860718 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Tue, 21 Jun 2022 22:54:42 +0200 Subject: [PATCH 160/477] corrected log archive name on CI --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index dc72d4edf7..367243aa1a 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -280,7 +280,7 @@ jobs: uses: actions/upload-artifact@v3 if: failure() with: - name: ${{matrix.CXXCOMPILER}}-${{matrix.LOOPLIBRARY}}_test-logs + name: ${{matrix.CXXCOMPILER}}-${{matrix.PART}}_test-logs path: | config.* test/test_*.log From ed16a05257094610cf357574ea270587161e010e Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 22 Jun 2022 12:39:19 +0200 Subject: [PATCH 161/477] make static const variables constexpr --- src/lowe.cpp | 4 ++-- src/sfermions.cpp | 2 +- templates/decays/decay_table.hpp.in | 2 +- templates/mass_eigenstates.hpp.in | 2 +- templates/mass_eigenstates_decoupling_scheme.hpp.in | 2 +- templates/observables.hpp.in | 2 +- templates/semi_analytic_ewsb_solver.hpp.in | 2 +- templates/soft_parameters.hpp.in | 2 +- templates/susy_parameters.hpp.in | 2 +- templates/two_scale_ewsb_solver.hpp.in | 2 +- 10 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/lowe.cpp b/src/lowe.cpp index 8ba8704814..8d7caa9e33 100644 --- a/src/lowe.cpp +++ b/src/lowe.cpp @@ -254,7 +254,7 @@ double QedQcd::qedBeta() const { /// that if quark masses are running, the number of active quarks will /// be taken into account. double QedQcd::qcdBeta() const { - static const double INVPI = 1.0 / flexiblesusy::Pi; + static constexpr double INVPI = 1.0 / flexiblesusy::Pi; const int quarkFlavours = flavours(get_scale()); const double qb0 = (11.0e0 - (2.0e0 / 3.0e0 * quarkFlavours)) / 4.0; const double qb1 = (102.0e0 - (38.0e0 * quarkFlavours) / 3.0e0) / 16.0; @@ -284,7 +284,7 @@ double QedQcd::qcdBeta() const { /// returns fermion mass beta functions Eigen::Array QedQcd::massBeta() const { - static const double INVPI = 1.0 / flexiblesusy::Pi; + static constexpr double INVPI = 1.0 / flexiblesusy::Pi; // qcd bits: 1,2,3 loop resp. double qg1 = 0., qg2 = 0., qg3 = 0.; diff --git a/src/sfermions.cpp b/src/sfermions.cpp index 46b4756933..9f6ac4ed0e 100644 --- a/src/sfermions.cpp +++ b/src/sfermions.cpp @@ -43,7 +43,7 @@ int sign(double x) noexcept { return x >= 0.0 ? 1 : -1; } namespace sfermions { -static const double oneOverRoot2 = 0.7071067811865475; // 1/sqrt(2.) +static constexpr double oneOverRoot2 = 0.7071067811865475; // 1/sqrt(2.) const double Isospin[NUMBER_OF_MSSM_SPARTICLES] = { 0.5, -0.5, 0.5, -0.5 diff --git a/templates/decays/decay_table.hpp.in b/templates/decays/decay_table.hpp.in index 0233033438..e5b6dcaad9 100644 --- a/templates/decays/decay_table.hpp.in +++ b/templates/decays/decay_table.hpp.in @@ -31,7 +31,7 @@ namespace flexiblesusy { class @ModelName@_decay_table { private: - static const int number_of_decay_particles = @numberOfDecayParticles@; + static constexpr int number_of_decay_particles = @numberOfDecayParticles@; using Table_type = std::array; public: using iterator = Table_type::iterator; diff --git a/templates/mass_eigenstates.hpp.in b/templates/mass_eigenstates.hpp.in index dffc76bedd..6783198ddb 100644 --- a/templates/mass_eigenstates.hpp.in +++ b/templates/mass_eigenstates.hpp.in @@ -69,7 +69,7 @@ public: std::unique_ptr<@ModelName@_mass_eigenstates_interface> clone() const override; /// number of EWSB equations - static const int number_of_ewsb_equations = @numberOfEWSBEquations@; + static constexpr int number_of_ewsb_equations = @numberOfEWSBEquations@; void calculate_DRbar_masses(); void calculate_pole_masses(); diff --git a/templates/mass_eigenstates_decoupling_scheme.hpp.in b/templates/mass_eigenstates_decoupling_scheme.hpp.in index 3dab470a5d..0aadbedd96 100644 --- a/templates/mass_eigenstates_decoupling_scheme.hpp.in +++ b/templates/mass_eigenstates_decoupling_scheme.hpp.in @@ -73,7 +73,7 @@ public: std::unique_ptr<@ModelName@_mass_eigenstates_interface> clone() const override; /// number of EWSB equations - static const int number_of_ewsb_equations = @numberOfEWSBEquations@; + static constexpr int number_of_ewsb_equations = @numberOfEWSBEquations@; void check_pole_masses_for_tachyons(); void do_force_output(bool); diff --git a/templates/observables.hpp.in b/templates/observables.hpp.in index bb90a6eb5c..51b99de315 100644 --- a/templates/observables.hpp.in +++ b/templates/observables.hpp.in @@ -35,7 +35,7 @@ class @ModelName@_mass_eigenstates; class Physical_input; struct @ModelName@_observables { - static const int NUMBER_OF_OBSERVABLES = @numberOfObservables@; + static constexpr int NUMBER_OF_OBSERVABLES = @numberOfObservables@; @ModelName@_observables(); Eigen::ArrayXd get() const; ///< returns vector of all observables diff --git a/templates/semi_analytic_ewsb_solver.hpp.in b/templates/semi_analytic_ewsb_solver.hpp.in index 7f20222143..f880060729 100644 --- a/templates/semi_analytic_ewsb_solver.hpp.in +++ b/templates/semi_analytic_ewsb_solver.hpp.in @@ -64,7 +64,7 @@ public: virtual int solve(@ModelName@_mass_eigenstates&) override; private: - static const int number_of_ewsb_equations = @numberOfEWSBEquations@; + static constexpr int number_of_ewsb_equations = @numberOfEWSBEquations@; using EWSB_vector_t = Eigen::Matrix; class EEWSBStepFailed : public Error { diff --git a/templates/soft_parameters.hpp.in b/templates/soft_parameters.hpp.in index 4fa3721bce..9438d25c8a 100644 --- a/templates/soft_parameters.hpp.in +++ b/templates/soft_parameters.hpp.in @@ -57,7 +57,7 @@ protected: @parameterDef@ private: - static const int numberOfParameters = @numberOfParameters@; + static constexpr int numberOfParameters = @numberOfParameters@; struct Soft_traces { @traceDefs@ diff --git a/templates/susy_parameters.hpp.in b/templates/susy_parameters.hpp.in index 75b4782bc0..423895bacb 100644 --- a/templates/susy_parameters.hpp.in +++ b/templates/susy_parameters.hpp.in @@ -65,7 +65,7 @@ protected: @ModelName@_input_parameters input{}; private: - static const int numberOfParameters = @numberOfParameters@; + static constexpr int numberOfParameters = @numberOfParameters@; struct Susy_traces { @traceDefs@ diff --git a/templates/two_scale_ewsb_solver.hpp.in b/templates/two_scale_ewsb_solver.hpp.in index 4b2aed40a7..fbcf6fff69 100644 --- a/templates/two_scale_ewsb_solver.hpp.in +++ b/templates/two_scale_ewsb_solver.hpp.in @@ -61,7 +61,7 @@ public: virtual int solve(@ModelName@_mass_eigenstates&) override; private: - static const int number_of_ewsb_equations = @numberOfEWSBEquations@; + static constexpr int number_of_ewsb_equations = @numberOfEWSBEquations@; using EWSB_vector_t = Eigen::Matrix; class EEWSBStepFailed : public Error { From f973acc9c75aa6d8bdebdf6a39515b047676db2c Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 22 Jun 2022 19:14:30 +0200 Subject: [PATCH 162/477] static-analysis should rerun if static-analysis.yml changes --- .github/workflows/static-analysis.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/static-analysis.yml b/.github/workflows/static-analysis.yml index 066bc9813c..a082b41568 100644 --- a/.github/workflows/static-analysis.yml +++ b/.github/workflows/static-analysis.yml @@ -3,6 +3,7 @@ name: static analysis on: push: paths: + - '.github/workflows/static-analysis.yml' - 'configure' - 'createmodel' - 'install-sarah' @@ -13,6 +14,7 @@ on: pull_request: paths: + - '.github/workflows/static-analysis.yml' - 'configure' - 'createmodel' - 'install-sarah' From bb41ce24d659b841e36f533e72460398146056ad Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sun, 26 Jun 2022 14:05:56 +0200 Subject: [PATCH 163/477] fixed latex typos in the changelog --- CHANGES.rst | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 040728ca85..c95bcfbc49 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -46,12 +46,12 @@ Changes ------- * [commit ae1eae8e4d]: Mathematica-style indexing (starting from 1) of - leptons in :math:`$L' \to L \gamma$` via the mathlink interface. + leptons in :math:`$l' \to l \gamma$` via the mathlink interface. Fixed bugs ---------- -* [commit 26f5262ad3]: Branching ratio of :math:`$L' \to L \gamma$` +* [commit 26f5262ad3]: Branching ratio of :math:`$l' \to l \gamma$` was breaking printing of observables via the mathlink interface. * [commit fd8d59dda8]: Fixed wrong calculation of :math:`$A \to Z \gamma$`. @@ -76,7 +76,7 @@ Changes * Removed code computing Higgs effective couplings. This code has been superseded by FlexibleDecay. -* FlexibleDecay: 2-loop QCD corrections to :math:`$\Phi \to \Gamma Z$` applied +* FlexibleDecay: 2-loop QCD corrections to :math:`$\Phi \to \gamma Z$` applied only if :math:`$m_Z/m_\Phi < 0.75$`. Fixed bugs From ec325faa0820d3d8077d911608a06e951d2fb8f1 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sun, 26 Jun 2022 14:13:32 +0200 Subject: [PATCH 164/477] corrected latex labels in observables readme --- doc/observables.rst | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/doc/observables.rst b/doc/observables.rst index 0817e4eb5d..ad390a5c48 100644 --- a/doc/observables.rst +++ b/doc/observables.rst @@ -6,17 +6,17 @@ List of observables computed by ``FlexibleSUSY`` - `lepton physics `_: - - muon anomalous magnetic moment :math:`a_\mu` + - muon anomalous magnetic moment :math:`$a_\mu$` - leptons electric dipole moments - `lepton flavour violation `_: - - :math:`\mu \to e \gamma` *(in preparation)* - - :math:`\mu \to e` conversion in nucleus *(in preparation)* + - :math:`$\mu \to e \gamma$` *(in preparation)* + - :math:`$\mu \to e$` conversion in nucleus *(in preparation)* - `b-physics `_: - - :math:`b \to s \gamma` + - :math:`$b \to s \gamma$` - `FlexibleDecay `_ From aeb59c6591ec108e2291c7663ca29aef5c47a8c1 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sat, 2 Jul 2022 09:04:01 +0200 Subject: [PATCH 165/477] decay amplitudes are already 0 initialized by default --- meta/Decays.m | 42 ++---------------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/meta/Decays.m b/meta/Decays.m index e6d5c99d24..46e0677524 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -1040,7 +1040,7 @@ would violate Ward identity (as at the level of dim 4 GetDecayAmplitudeType[GetInitialState[decay], GetFinalState[decay]]; CreateFieldIndices[particle_String] := - "typename cxx_diagrams::field_indices<" <> particle <> " >::type"; + "typename cxx_diagrams::field_indices<" <> particle <> ">::type"; CreateFieldIndices[particle_, fieldsNamespace_] := CreateFieldIndices[CXXDiagrams`CXXNameOfField[particle, prefixNamespace -> fieldsNamespace]]; @@ -1182,40 +1182,6 @@ would violate Ward identity (as at the level of dim 4 _, "" ]; -ZeroDecayAmplitudeFormFactors[decay_FSParticleDecay /; GetDecayAmplitudeType[decay] == "Decay_amplitude_SSS", - structName_] := - structName <> ".form_factor = std::complex(0., 0.);\n"; - -ZeroDecayAmplitudeFormFactors[decay_FSParticleDecay /; GetDecayAmplitudeType[decay] == "Decay_amplitude_SSV", - structName_] := - structName <> ".form_factor = std::complex(0., 0.);\n"; - -ZeroDecayAmplitudeFormFactors[decay_FSParticleDecay /; GetDecayAmplitudeType[decay] == "Decay_amplitude_SVV", - structName_] := - structName <> ".form_factor_g = std::complex(0., 0.);\n" <> - structName <> ".form_factor_11 = std::complex(0., 0.);\n" <> - structName <> ".form_factor_12 = std::complex(0., 0.);\n" <> - structName <> ".form_factor_21 = std::complex(0., 0.);\n" <> - structName <> ".form_factor_22 = std::complex(0., 0.);\n" <> - structName <> ".form_factor_eps = std::complex(0., 0.);\n"; - -ZeroDecayAmplitudeFormFactors[decay_FSParticleDecay /; GetDecayAmplitudeType[decay] == "Decay_amplitude_SFF", - structName_] := - structName <> ".form_factor_left = std::complex(0., 0.);\n" <> - structName <> ".form_factor_right = std::complex(0., 0.);\n"; - -ZeroDecayAmplitudeFormFactors[decay_FSParticleDecay /; GetDecayAmplitudeType[decay] == "Decay_amplitude_FFS", - structName_] := - structName <> ".form_factor_left = std::complex(0., 0.);\n" <> - structName <> ".form_factor_right = std::complex(0., 0.);\n"; - -ZeroDecayAmplitudeFormFactors[decay_FSParticleDecay /; GetDecayAmplitudeType[decay] == "Decay_amplitude_FFV", - structName_] := - structName <> ".form_factor_gam_left = std::complex(0., 0.);\n" <> - structName <> ".form_factor_gam_right = std::complex(0., 0.);\n" <> - structName <> ".form_factor_p_1 = std::complex(0., 0.);\n" <> - structName <> ".form_factor_p_2 = std::complex(0., 0.);\n"; - GetTreeLevelTwoBodyDecayVertex[decay_FSParticleDecay] := Module[{treeLevelDiags, vertices = {}}, treeLevelDiags = GetDecayDiagramsOnlyAtLoopOrder[decay, 0]; @@ -2001,12 +1967,8 @@ that returns a total (sumed over internal insertions) 1-loop amplitude for a giv body = body <> "\n// external particles' masses\n"; body = body <> FillDecayAmplitudeMasses[decay, modelName, returnVar, paramsStruct]; - (* @todo: it might be less verbose to by default initialize amplitude to 0 *) - body = body <> "\n// set the initial value of an amplitude to 0\n"; - body = body <> ZeroDecayAmplitudeFormFactors[decay, returnVar]; - If[IsPossibleTreeLevelDecay[decay, True], - body = body <> "// @todo correct prefactors\n" <> FillTreeLevelDecayAmplitudeFormFactors[decay, modelName, returnVar, paramsStruct] <> "\n"; + body = body <> "\n// @todo correct prefactors\n" <> FillTreeLevelDecayAmplitudeFormFactors[decay, modelName, returnVar, paramsStruct] <> "\n"; ]; If[!IsPossibleTreeLevelDecay[decay, True] && IsPossibleOneLoopDecay[decay], From aecd3e26bc4216510b19a4becfc0d9324070a69c Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 7 Jul 2022 11:52:13 +0200 Subject: [PATCH 166/477] no need for PMNS matrix in the MRSSM2CKM input file since neutinos are massles --- model_files/MRSSM2CKM/LesHouches.in.MRSSM2CKM | 7 ------- 1 file changed, 7 deletions(-) diff --git a/model_files/MRSSM2CKM/LesHouches.in.MRSSM2CKM b/model_files/MRSSM2CKM/LesHouches.in.MRSSM2CKM index 8ffc6cb744..57fd97c51c 100644 --- a/model_files/MRSSM2CKM/LesHouches.in.MRSSM2CKM +++ b/model_files/MRSSM2CKM/LesHouches.in.MRSSM2CKM @@ -60,13 +60,6 @@ Block VCKMIN # CKM matrix input (Wolfenstein parameters) 2 8.180000000e-01 # A(MZ) SM DR-bar 3 2.210000000e-01 # rhobar(MZ) SM DR-bar 4 3.400000000e-01 # etabar(MZ) SM DR-bar -# Block UPMNSIN # PMNS matrix input -# 1 5.837630000e-01 # theta_12 -# 2 7.695840000e-01 # theta_23 -# 3 1.549480000e-01 # theta_13 -# 4 0.000000000e+00 # delta -# 5 0.000000000e+00 # alpha_1 -# 6 0.000000000e+00 # alpha_2 Block MINPAR 3 5 # TanBeta Block EXTPAR From 9b1f96ccee91b7d7779b87bb0286524e3c0bd906 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 7 Jul 2022 11:56:50 +0200 Subject: [PATCH 167/477] Eq. (58) of FD manual should contain running mt --- src/decays/H_SM_decays/decay_AH_to_GG.inc | 11 +++++++---- src/decays/H_SM_decays/decay_H_to_GG.inc | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/decays/H_SM_decays/decay_AH_to_GG.inc b/src/decays/H_SM_decays/decay_AH_to_GG.inc index 3178f2c2f3..a3eaed2d69 100644 --- a/src/decays/H_SM_decays/decay_AH_to_GG.inc +++ b/src/decays/H_SM_decays/decay_AH_to_GG.inc @@ -22,7 +22,7 @@ double CLASSNAME::get_partial_width( const double tau = Sqr(mAh/(2.*context.mass({2}))); if (static_cast(flexibledecay_settings.get(FlexibleDecay_settings::include_higher_order_corrections)) && tau < 0.7) { // number of active light flavours - constexpr int Nf = 5; + static constexpr int Nf = 5; auto qedqcd_ = qedqcd; qedqcd_.to(mAh); // 5-flavour SM alpha_s @@ -45,10 +45,13 @@ double CLASSNAME::get_partial_width( 97./4. - 7./6.*Nf + (33.-2*Nf)/6*LH }; - const double mtpole {qedqcd.displayPoleMt()}; - const double Lt = std::log(Sqr(mu/mtpole)); + const double mt {context.mass({2})}; + const double Lt = std::log(Sqr(mu/mt)); + // eq. D10 of 2207.01032 and 23 of 9807241 const double deltaNNLO { - 237311./864. - 529./24.*zeta2 - 445./8.*zeta3 + 5.*Lt + 51959/96. - 363/8.*zeta2 - 495/8.*zeta3 + Nf*(-473/8. + 11/2.*zeta2 + 5/4.*zeta3 + Lt) + Sqr(Nf)*(251/216. - 1/6.*zeta2) + + (3405/16. - 73/3*Nf + 7/12.*Sqr(Nf))*LH + + (363/16. - 11/4.*Nf + 1/12.*Sqr(Nf))*Sqr(LH) }; const double alpha_s_red = alpha_s_5f/Pi; diff --git a/src/decays/H_SM_decays/decay_H_to_GG.inc b/src/decays/H_SM_decays/decay_H_to_GG.inc index 517462764d..102f8ef5e2 100644 --- a/src/decays/H_SM_decays/decay_H_to_GG.inc +++ b/src/decays/H_SM_decays/decay_H_to_GG.inc @@ -45,7 +45,7 @@ double CLASSNAME::get_partial_width( const double Lt = std::log(Sqr(mu/mt)); // eq. 5 of 0708.0916 - constexpr int Nf = 5; + static constexpr int Nf = 5; const double hnlo0 = 95./4. - 7./6.*Nf + (33 - 2*Nf)/6.*LH; const double hnlo1 = @@ -121,10 +121,13 @@ double CLASSNAME::get_partial_width( 97./4. - 7./6.*Nf + (33.-2*Nf)/6*LH }; - const double mtpole {qedqcd.displayPoleMt()}; - const double Lt = std::log(Sqr(mu/mtpole)); + const double mt {context.mass({2})}; + const double Lt = std::log(Sqr(mu/mt)); + // eq. D10 of 2207.01032 and 23 of 9807241 const double deltaNNLO_P { - 237311./864. - 529./24.*zeta2 - 445./8.*zeta3 + 5.*Lt + 51959/96. - 363/8.*zeta2 - 495/8.*zeta3 + Nf*(-473/8. + 11/2.*zeta2 + 5/4.*zeta3 + Lt) + Sqr(Nf)*(251/216. - 1/6.*zeta2) + + (3405/16. - 73/3*Nf + 7/12.*Sqr(Nf))*LH + + (363/16. - 11/4.*Nf + 1/12.*Sqr(Nf))*Sqr(LH) }; double pseudoscalar_corr = 0.0; From 84a0f3431cfdc41f44ff17648617ea81c5f3dc2f Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Fri, 8 Jul 2022 11:30:05 +0200 Subject: [PATCH 168/477] decays can be enabled is SMHighScale --- model_files/SMHighScale/FlexibleSUSY.m.in | 2 ++ 1 file changed, 2 insertions(+) diff --git a/model_files/SMHighScale/FlexibleSUSY.m.in b/model_files/SMHighScale/FlexibleSUSY.m.in index 613bbb3d03..de0344d13d 100644 --- a/model_files/SMHighScale/FlexibleSUSY.m.in +++ b/model_files/SMHighScale/FlexibleSUSY.m.in @@ -65,3 +65,5 @@ SARAH`ParameterDefinitions = Append[ Cases[SARAH`ParameterDefinitions, {p_ /; p =!= SARAH`\[Lambda], ___}], {SARAH`\[Lambda], { Description -> "SM Higgs Selfcouplings" } } ]; + +FSCalculateDecays = True; From 1ffb4f70534093d839b9b465016d6644ea627c1d Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Wed, 13 Jul 2022 11:44:40 +0200 Subject: [PATCH 169/477] error in H and A to uubar higher order corrections Wrong QED quark charge was used in higher order corrections. The difference is at a level of 0.03%. --- CHANGES.rst | 8 ++++++++ src/decays/H_SM_decays/decay_AH_to_uquq.inc | 4 ++-- src/decays/H_SM_decays/decay_H_to_uquq.inc | 4 ++-- test/test_MRSSM2_FlexibleDecay.cpp | 4 ++-- test/test_MSSMCPV_FlexibleDecay.cpp | 2 +- test/test_MSSM_FlexibleDecay.cpp | 4 ++-- test/test_SM_FlexibleDecay.cpp | 2 +- test/test_THDMII_FlexibleDecay.cpp | 4 ++-- 8 files changed, 20 insertions(+), 12 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index c95bcfbc49..7c8d0351c4 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -1,3 +1,11 @@ +FlexibleSUSY 2.X.X [X, X X] +================================== + +Fixed bugs +---------- + +* [commit ]: Fixed incorect quark charge in some higher order QED corrections to :math:`$H \to u\bar{u}$` and :math:`$A \to u\bar{u}$` + FlexibleSUSY 2.7.1 [June, 07 2022] ================================== diff --git a/src/decays/H_SM_decays/decay_AH_to_uquq.inc b/src/decays/H_SM_decays/decay_AH_to_uquq.inc index 2198b79068..3990322d54 100644 --- a/src/decays/H_SM_decays/decay_AH_to_uquq.inc +++ b/src/decays/H_SM_decays/decay_AH_to_uquq.inc @@ -94,13 +94,13 @@ double CLASSNAME::get_partial_width::type, uq>( 4./3. * alpha_s_red * calc_DeltaAH(betaOS); const double deltaqq_QED_OS_P = - alpha_red * Sqr(dq::electric_charge) * calc_DeltaAH(betaOS); + alpha_red * Sqr(uq::electric_charge) * calc_DeltaAH(betaOS); double deltaqq_QCDxQED_DR = 0.; double deltaPhi2_P = 0.; if (static_cast(flexibledecay_settings.get(FlexibleDecay_settings::include_higher_order_corrections)) > 1) { deltaqq_QCDxQED_DR = - deltaqq_QCDxQED*Sqr(dq::electric_charge)*alpha_red*alpha_s_red; + deltaqq_QCDxQED*Sqr(uq::electric_charge)*alpha_red*alpha_s_red; if ((indexOut1.at(0) < 2 || indexOut2.at(0) < 2)) { const double mtpole = qedqcd.displayPoleMt(); const double lt = std::log(Sqr(mAHOS/mtpole)); diff --git a/src/decays/H_SM_decays/decay_H_to_uquq.inc b/src/decays/H_SM_decays/decay_H_to_uquq.inc index 5e79fd4b92..9da1e1a9ff 100644 --- a/src/decays/H_SM_decays/decay_H_to_uquq.inc +++ b/src/decays/H_SM_decays/decay_H_to_uquq.inc @@ -114,7 +114,7 @@ double CLASSNAME::get_partial_width::type, uq>( 4./3. * alpha_s_red * calc_DeltaAH(betaOS); deltaqq_QED_OS_P = - alpha_red * Sqr(dq::electric_charge) * calc_DeltaAH(betaOS); + alpha_red * Sqr(uq::electric_charge) * calc_DeltaAH(betaOS); } double deltaPhi2_S = 0.; @@ -122,7 +122,7 @@ double CLASSNAME::get_partial_width::type, uq>( double deltaqq_QCDxQED_DR = 0.; if (static_cast(flexibledecay_settings.get(FlexibleDecay_settings::include_higher_order_corrections)) > 1) { deltaqq_QCDxQED_DR = - deltaqq_QCDxQED*Sqr(dq::electric_charge)*alpha_red*alpha_s_red; + deltaqq_QCDxQED*Sqr(uq::electric_charge)*alpha_red*alpha_s_red; if ((indexOut1.at(0) < 2 || indexOut2.at(0) < 2)) { const double mtpole = qedqcd.displayPoleMt(); const double lt = std::log(Sqr(mHOS/mtpole)); diff --git a/test/test_MRSSM2_FlexibleDecay.cpp b/test/test_MRSSM2_FlexibleDecay.cpp index 619a7289cf..c25b617106 100644 --- a/test/test_MRSSM2_FlexibleDecay.cpp +++ b/test/test_MRSSM2_FlexibleDecay.cpp @@ -694,7 +694,7 @@ Block IMVCKM Q= 1.00000000E+03 0.0025634108458618405, 5e-12); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFuFu(&m, 0, 1, 1), - 0.00012285838200009531, 2e-13); + 0.00012289267709167259, 2e-13); // QED corrections // BOOST_CHECK_CLOSE_FRACTION(decays.partial_width_hh_to_barFdFd(&m, 0, 2, 2), // 2.6059181498481999E-003, 5e-15); @@ -729,7 +729,7 @@ Block IMVCKM Q= 1.00000000E+03 BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFdFd(&m, 1, 2, 2), 27.422426128468313, 5e-12); BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFuFu(&m, 1, 1, 1), - 6.5359182777429661e-07, 2e-13); + 6.5374236623950305e-07, 2e-13); // ----------------------------------------------------- // decays without higher-order SM corrections diff --git a/test/test_MSSMCPV_FlexibleDecay.cpp b/test/test_MSSMCPV_FlexibleDecay.cpp index 62e7af4516..1d03861c9c 100644 --- a/test/test_MSSMCPV_FlexibleDecay.cpp +++ b/test/test_MSSMCPV_FlexibleDecay.cpp @@ -826,7 +826,7 @@ Block ImMSOFT Q= 2.00000000E+03 0.0021707237775801919, 6e-13); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFuFu(&m, 1, 1, 1), - 0.00010604105374890464, 2e-13); + 0.00010607114819048992, 2e-13); // h -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFeFe(&m, 1, 2, 2), 0.00022695659608435093, 3e-13); diff --git a/test/test_MSSM_FlexibleDecay.cpp b/test/test_MSSM_FlexibleDecay.cpp index 66303cc3c2..707bf5bfa3 100644 --- a/test/test_MSSM_FlexibleDecay.cpp +++ b/test/test_MSSM_FlexibleDecay.cpp @@ -657,7 +657,7 @@ Block MSOFT Q= 8.64566212E+02 0.0024454872837716721, 7e-13); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFuFu(&m, 0, 1, 1), - 0.00011318500362355447, 3e-13); + 0.00011321683135547809, 3e-13); // h -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFeFe(&m, 0, 2, 2), 0.00026234514953420564, 3e-13); @@ -697,7 +697,7 @@ Block MSOFT Q= 8.64566212E+02 0.14370135383550148, 4e-13); // Ah -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFuFu(&m, 1, 1, 1), - 6.1486066780391835e-06, 3e-13); + 6.1500292100561543e-06, 3e-13); // Ah -> W+ W- BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_conjVWmVWm(&m, 1), 3.926795985114403e-05, 2e-12); diff --git a/test/test_SM_FlexibleDecay.cpp b/test/test_SM_FlexibleDecay.cpp index 82d4f98f46..252d80d538 100644 --- a/test/test_SM_FlexibleDecay.cpp +++ b/test/test_SM_FlexibleDecay.cpp @@ -58,7 +58,7 @@ BOOST_AUTO_TEST_CASE( test_SM_FlexibleDecay ) 0.0023811031255194888, 2e-15); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_HO.partial_width_hh_to_barFuFu(&m, 1, 1), - 0.00011734084746332317, 2e-16); + 0.00011737301687946969, 2e-16); // h -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_HO.partial_width_hh_to_barFeFe(&m, 2, 2), 0.00026184531343741851, 1e-15); diff --git a/test/test_THDMII_FlexibleDecay.cpp b/test/test_THDMII_FlexibleDecay.cpp index 166182b7eb..c0a9693dfb 100644 --- a/test/test_THDMII_FlexibleDecay.cpp +++ b/test/test_THDMII_FlexibleDecay.cpp @@ -272,7 +272,7 @@ Block UERMIX 0.00074272222469849497, 2e-13); // h -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFuFu(&m, 0, 1, 1), - 0.0001199276031491833, 6e-15); + 0.00011996054512932952, 6e-15); // h -> tau+ tau- BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_hh_to_barFeFe(&m, 0, 2, 2), 7.9645089645449552e-05, 1e-15); @@ -302,7 +302,7 @@ Block UERMIX 1.0248504807742072, 2e-15); // Ah -> c cbar BOOST_CHECK_CLOSE_FRACTION(decays_with_HO.partial_width_Ah_to_barFuFu(&m, 1, 1, 1), - 5.1682891827667072e-06, 2e-16); + 5.1697352441808561e-06, 2e-16); // ----------------------------------------------------- // decays without higher-order SM corrections From 8a2b3ba7c4222d9ee992353ca52ac4fde3a4f637 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Thu, 14 Jul 2022 17:56:58 +0200 Subject: [PATCH 170/477] updated CI to Wolfram Engine 13.1 --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 367243aa1a..3de170eb59 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -125,7 +125,7 @@ jobs: runs-on: ubuntu-latest container: - image: navir/opensuseleap-for-flexiblesusy:0.13.0 + image: navir/opensuseleap-for-flexiblesusy:0.14.1 strategy: fail-fast: false From 8116912dd357e58c4b25fc8369d191e3efe79c85 Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Fri, 15 Jul 2022 18:14:03 +0200 Subject: [PATCH 171/477] discard decays which cannot exist at tree-level --- meta/Decays.m | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/meta/Decays.m b/meta/Decays.m index 46e0677524..98afa39fc7 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -417,9 +417,13 @@ would violate Ward identity (as at the level of dim 4 is such a coupling, it must be 0. So for those processes we start generating amplitudes from the 1-loop level. *) minLoops = - If[MemberQ[{TreeMasses`GetHiggsBoson[], TreeMasses`GetPseudoscalarHiggsBoson}, initialParticle] && + If[(MemberQ[{TreeMasses`GetHiggsBoson[], TreeMasses`GetPseudoscalarHiggsBoson}, initialParticle] && (Sort@finalParticles === Sort[{TreeMasses`GetPhoton[], TreeMasses`GetPhoton[]}] || - Sort@finalParticles === Sort[{TreeMasses`GetPhoton[], TreeMasses`GetZBoson[]}]), + Sort@finalParticles === Sort[{TreeMasses`GetPhoton[], TreeMasses`GetZBoson[]}])) + || + (* a photon or a gluon always couples diagonally at the tree-level - e.g. no γXY coupling when X =! Y *) + (MemberQ[finalParticles, TreeMasses`GetPhoton[]] && !MemberQ[finalParticles, initialParticle]) || + (MemberQ[finalParticles, TreeMasses`GetGluon[]] && !MemberQ[finalParticles, initialParticle]), 1, 0 ]; From 2da6ee8250d9a486e616d2217b335621b6b90abe Mon Sep 17 00:00:00 2001 From: Wojciech Kotlarski Date: Sat, 16 Jul 2022 14:38:43 +0200 Subject: [PATCH 172/477] make up-quark decays work in the MRSSM --- meta/Decays.m | 5 ++++- model_files/MRSSM2/FlexibleSUSY.m.in | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/meta/Decays.m b/meta/Decays.m index 98afa39fc7..a4a46802cb 100644 --- a/meta/Decays.m +++ b/meta/Decays.m @@ -435,8 +435,11 @@ would violate Ward identity (as at the level of dim 4 {#[[1]], With[{toposAndDiags = #[[2]]}, {#[[1]], Select[#[[2]], IsSupportedDiagram]}& /@ toposAndDiags]}& /@ diagrams ]; +(* in the MRSSM this 1-loop decay amplitude for Fu crashes the code + {Fu, bar[Fd], conj[SRdp], {Fu, Chi, conj[Su]}, {bar[Fd], bar[Chi], Sd}, {conj[SRdp], Su, conj[Sd]}} + Temporarily disable 1-loop Fu decay *) GetContributingGraphsForDecay[initialParticle_, finalParticles_List] := - GetContributingGraphsForDecay[initialParticle, finalParticles, 1]; + GetContributingGraphsForDecay[initialParticle, finalParticles, If[initialParticle === First@TreeMasses`GetSMUpQuarks[], 0, 1]]; (* defines a fixed ordering for final state particles *) (* @todo decide on what this ordering actually will be *) diff --git a/model_files/MRSSM2/FlexibleSUSY.m.in b/model_files/MRSSM2/FlexibleSUSY.m.in index ec7cc486b0..7179f55f4c 100644 --- a/model_files/MRSSM2/FlexibleSUSY.m.in +++ b/model_files/MRSSM2/FlexibleSUSY.m.in @@ -99,7 +99,7 @@ ExtraSLHAOutputBlocks = { }; FSCalculateDecays = True; -FSDecayParticles = {hh, Ah, Hpm, sigmaO, phiO}; +FSDecayParticles = {hh, Ah, Hpm, sigmaO, phiO, Fu}; DefaultPoleMassPrecision = HighPrecision; HighPoleMassPrecision = {hh, Ah, Hpm}; From 29c677a1e6a83190504cdc9daf4e1a235db56af7 Mon Sep 17 00:00:00 2001 From: Wojtek Date: Fri, 29 Jul 2022 12:55:31 +0200 Subject: [PATCH 173/477] updated CI to Collier 1.2.6 --- .github/workflows/tests.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index 3de170eb59..0a7f533d54 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -125,7 +125,7 @@ jobs: runs-on: ubuntu-latest container: - image: navir/opensuseleap-for-flexiblesusy:0.14.1 + image: navir/opensuseleap-for-flexiblesusy:0.14.2 strategy: fail-fast: false From 56cfb0b8b6c440e0c893a534c4d2a6ab4a91c263 Mon Sep 17 00:00:00 2001 From: Wojtek Date: Mon, 1 Aug 2022 18:06:52 +0200 Subject: [PATCH 174/477] updated JSON library to 3.11.0 --- nlohmann/json.hpp | 5012 ++++++++++++++++++++++++++++++++------------- 1 file changed, 3628 insertions(+), 1384 deletions(-) diff --git a/nlohmann/json.hpp b/nlohmann/json.hpp index cb27e05811..8a8a0a0c7e 100644 --- a/nlohmann/json.hpp +++ b/nlohmann/json.hpp @@ -1,31 +1,10 @@ -/* - __ _____ _____ _____ - __| | __| | | | JSON for Modern C++ -| | |__ | | | | | | version 3.10.5 -|_____|_____|_____|_|___| https://github.com/nlohmann/json - -Licensed under the MIT License . -SPDX-License-Identifier: MIT -Copyright (c) 2013-2022 Niels Lohmann . - -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: - -The above copyright notice and this permission notice shall be included in all -copies or substantial portions of the Software. - -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE -SOFTWARE. -*/ +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT /****************************************************************************\ * Note on documentation: The source files contain links to the online * @@ -33,16 +12,12 @@ SOFTWARE. * contains the most recent documentation and should also be applicable to * * previous versions; documentation for deprecated functions is not * * removed, but marked deprecated. See "Generate documentation" section in * - * file doc/README.md. * + * file docs/README.md. * \****************************************************************************/ #ifndef INCLUDE_NLOHMANN_JSON_HPP_ #define INCLUDE_NLOHMANN_JSON_HPP_ -#define NLOHMANN_JSON_VERSION_MAJOR 3 -#define NLOHMANN_JSON_VERSION_MINOR 10 -#define NLOHMANN_JSON_VERSION_PATCH 5 - #include // all_of, find, for_each #include // nullptr_t, ptrdiff_t, size_t #include // hash, less @@ -58,12 +33,108 @@ SOFTWARE. #include // vector // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + -#include #include +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// This file contains all macro definitions affecting or depending on the ABI + +#ifndef JSON_SKIP_LIBRARY_VERSION_CHECK + #if defined(NLOHMANN_JSON_VERSION_MAJOR) && defined(NLOHMANN_JSON_VERSION_MINOR) && defined(NLOHMANN_JSON_VERSION_PATCH) + #if NLOHMANN_JSON_VERSION_MAJOR != 3 || NLOHMANN_JSON_VERSION_MINOR != 11 || NLOHMANN_JSON_VERSION_PATCH != 0 + #warning "Already included a different version of the library!" + #endif + #endif +#endif + +#define NLOHMANN_JSON_VERSION_MAJOR 3 // NOLINT(modernize-macro-to-enum) +#define NLOHMANN_JSON_VERSION_MINOR 11 // NOLINT(modernize-macro-to-enum) +#define NLOHMANN_JSON_VERSION_PATCH 0 // NOLINT(modernize-macro-to-enum) + +#ifndef JSON_DIAGNOSTICS + #define JSON_DIAGNOSTICS 0 +#endif + +#ifndef JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON + #define JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON 0 +#endif + +#if JSON_DIAGNOSTICS + #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS _diag +#else + #define NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS +#endif + +#if JSON_USE_LEGACY_DISCARDED_VALUE_COMPARISON + #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON _ldvcmp +#else + #define NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON +#endif + +#define NLOHMANN_JSON_ABI_PREFIX_EX(major, minor, patch) \ + json_v ## major ## _ ## minor ## _ ## patch +#define NLOHMANN_JSON_ABI_PREFIX(major, minor, patch) \ + NLOHMANN_JSON_ABI_PREFIX_EX(major, minor, patch) + +#define NLOHMANN_JSON_ABI_CONCAT_EX(a, b, c) a ## b ## c +#define NLOHMANN_JSON_ABI_CONCAT(a, b, c) \ + NLOHMANN_JSON_ABI_CONCAT_EX(a, b, c) + +#define NLOHMANN_JSON_ABI_STRING \ + NLOHMANN_JSON_ABI_CONCAT( \ + NLOHMANN_JSON_ABI_PREFIX( \ + NLOHMANN_JSON_VERSION_MAJOR, \ + NLOHMANN_JSON_VERSION_MINOR, \ + NLOHMANN_JSON_VERSION_PATCH), \ + NLOHMANN_JSON_ABI_TAG_DIAGNOSTICS, \ + NLOHMANN_JSON_ABI_TAG_LEGACY_DISCARDED_VALUE_COMPARISON) + +#ifndef NLOHMANN_JSON_NAMESPACE + #define NLOHMANN_JSON_NAMESPACE nlohmann::NLOHMANN_JSON_ABI_STRING +#endif + +#ifndef NLOHMANN_JSON_NAMESPACE_BEGIN +#define NLOHMANN_JSON_NAMESPACE_BEGIN \ + namespace nlohmann \ + { \ + inline namespace NLOHMANN_JSON_ABI_STRING \ + { +#endif + +#ifndef NLOHMANN_JSON_NAMESPACE_END +#define NLOHMANN_JSON_NAMESPACE_END \ + } /* namespace (abi_string) */ \ + } /* namespace nlohmann */ +#endif + // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + #include // transform @@ -79,14 +150,31 @@ SOFTWARE. #include // valarray // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + +#include // nullptr_t #include // exception #include // runtime_error #include // to_string #include // vector // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + #include // array @@ -94,102 +182,130 @@ SOFTWARE. #include // uint8_t #include // string -namespace nlohmann -{ +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include // declval, pair +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +#include + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { -/////////////////////////// -// JSON type enumeration // -/////////////////////////// -/*! -@brief the JSON type enumeration +template struct make_void +{ + using type = void; +}; +template using void_t = typename make_void::type; -This enumeration collects the different JSON types. It is internally used to -distinguish the stored values, and the functions @ref basic_json::is_null(), -@ref basic_json::is_object(), @ref basic_json::is_array(), -@ref basic_json::is_string(), @ref basic_json::is_boolean(), -@ref basic_json::is_number() (with @ref basic_json::is_number_integer(), -@ref basic_json::is_number_unsigned(), and @ref basic_json::is_number_float()), -@ref basic_json::is_discarded(), @ref basic_json::is_primitive(), and -@ref basic_json::is_structured() rely on it. +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END -@note There are three enumeration entries (number_integer, number_unsigned, and -number_float), because the library distinguishes these three types for numbers: -@ref basic_json::number_unsigned_t is used for unsigned integers, -@ref basic_json::number_integer_t is used for signed integers, and -@ref basic_json::number_float_t is used for floating-point numbers or to -approximate integers which do not fit in the limits of their respective type. -@sa see @ref basic_json::basic_json(const value_t value_type) -- create a JSON -value with the default value for a given type +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ -@since version 1.0.0 -*/ -enum class value_t : std::uint8_t +// https://en.cppreference.com/w/cpp/experimental/is_detected +struct nonesuch { - null, ///< null value - object, ///< object (unordered set of name/value pairs) - array, ///< array (ordered collection of values) - string, ///< string value - boolean, ///< boolean value - number_integer, ///< number value (signed integer) - number_unsigned, ///< number value (unsigned integer) - number_float, ///< number value (floating-point) - binary, ///< binary array (ordered collection of bytes) - discarded ///< discarded by the parser callback function + nonesuch() = delete; + ~nonesuch() = delete; + nonesuch(nonesuch const&) = delete; + nonesuch(nonesuch const&&) = delete; + void operator=(nonesuch const&) = delete; + void operator=(nonesuch&&) = delete; }; -/*! -@brief comparison operator for JSON types - -Returns an ordering that is similar to Python: -- order: null < boolean < number < object < array < string < binary -- furthermore, each type is not smaller than itself -- discarded values are not comparable -- binary is represented as a b"" string in python and directly comparable to a - string; however, making a binary array directly comparable with a string would - be surprising behavior in a JSON file. +template class Op, + class... Args> +struct detector +{ + using value_t = std::false_type; + using type = Default; +}; -@since version 1.0.0 -*/ -inline bool operator<(const value_t lhs, const value_t rhs) noexcept +template class Op, class... Args> +struct detector>, Op, Args...> { - static constexpr std::array order = {{ - 0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */, - 1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */, - 6 /* binary */ - } - }; + using value_t = std::true_type; + using type = Op; +}; - const auto l_index = static_cast(lhs); - const auto r_index = static_cast(rhs); - return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index]; -} -} // namespace detail -} // namespace nlohmann +template class Op, class... Args> +using is_detected = typename detector::value_t; -// #include +template class Op, class... Args> +struct is_detected_lazy : is_detected { }; +template class Op, class... Args> +using detected_t = typename detector::type; -#include -// #include +template class Op, class... Args> +using detected_or = detector; +template class Op, class... Args> +using detected_or_t = typename detected_or::type; + +template class Op, class... Args> +using is_detected_exact = std::is_same>; + +template class Op, class... Args> +using is_detected_convertible = + std::is_convertible, To>; + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END -#include // declval, pair // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-FileCopyrightText: 2016-2021 Evan Nemerson +// SPDX-License-Identifier: MIT + /* Hedley - https://nemequ.github.io/hedley * Created by Evan Nemerson - * - * To the extent possible under law, the author(s) have dedicated all - * copyright and related and neighboring rights to this software to - * the public domain worldwide. This software is distributed without - * any warranty. - * - * For details, see . - * SPDX-License-Identifier: CC0-1.0 */ #if !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < 15) @@ -2223,86 +2339,12 @@ JSON_HEDLEY_DIAGNOSTIC_POP #endif /* !defined(JSON_HEDLEY_VERSION) || (JSON_HEDLEY_VERSION < X) */ -// #include - - -#include - -// #include - - -namespace nlohmann -{ -namespace detail -{ -template struct make_void -{ - using type = void; -}; -template using void_t = typename make_void::type; -} // namespace detail -} // namespace nlohmann - - -// https://en.cppreference.com/w/cpp/experimental/is_detected -namespace nlohmann -{ -namespace detail -{ -struct nonesuch -{ - nonesuch() = delete; - ~nonesuch() = delete; - nonesuch(nonesuch const&) = delete; - nonesuch(nonesuch const&&) = delete; - void operator=(nonesuch const&) = delete; - void operator=(nonesuch&&) = delete; -}; - -template class Op, - class... Args> -struct detector -{ - using value_t = std::false_type; - using type = Default; -}; - -template class Op, class... Args> -struct detector>, Op, Args...> -{ - using value_t = std::true_type; - using type = Op; -}; - -template class Op, class... Args> -using is_detected = typename detector::value_t; - -template class Op, class... Args> -struct is_detected_lazy : is_detected { }; - -template class Op, class... Args> -using detected_t = typename detector::type; - -template class Op, class... Args> -using detected_or = detector; - -template class Op, class... Args> -using detected_or_t = typename detected_or::type; - -template class Op, class... Args> -using is_detected_exact = std::is_same>; -template class Op, class... Args> -using is_detected_convertible = - std::is_convertible, To>; -} // namespace detail -} // namespace nlohmann +// This file contains all internal macro definitions (except those affecting ABI) +// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them +// #include -// This file contains all internal macro definitions -// You MUST include macro_unscope.hpp at the end of json.hpp to undef all of them // exclude unsupported compilers #if !defined(JSON_SKIP_UNSUPPORTED_COMPILER_CHECK) @@ -2334,6 +2376,12 @@ using is_detected_convertible = #define JSON_HAS_CPP_11 #endif +#ifdef __has_include + #if __has_include() + #include + #endif +#endif + #if !defined(JSON_HAS_FILESYSTEM) && !defined(JSON_HAS_EXPERIMENTAL_FILESYSTEM) #ifdef JSON_HAS_CPP_17 #if defined(__cpp_lib_filesystem) @@ -2367,7 +2415,7 @@ using is_detected_convertible = #endif // no filesystem support before MSVC 19.14: https://en.cppreference.com/w/cpp/compiler_support - #if defined(_MSC_VER) && _MSC_VER < 1940 + #if defined(_MSC_VER) && _MSC_VER < 1914 #undef JSON_HAS_FILESYSTEM #undef JSON_HAS_EXPERIMENTAL_FILESYSTEM #endif @@ -2394,6 +2442,38 @@ using is_detected_convertible = #define JSON_HAS_FILESYSTEM 0 #endif +#ifndef JSON_HAS_THREE_WAY_COMPARISON + #if defined(__cpp_impl_three_way_comparison) && __cpp_impl_three_way_comparison >= 201907L \ + && defined(__cpp_lib_three_way_comparison) && __cpp_lib_three_way_comparison >= 201907L + #define JSON_HAS_THREE_WAY_COMPARISON 1 + #else + #define JSON_HAS_THREE_WAY_COMPARISON 0 + #endif +#endif + +#ifndef JSON_HAS_RANGES + // ranges header shipping in GCC 11.1.0 (released 2021-04-27) has syntax error + #if defined(__GLIBCXX__) && __GLIBCXX__ == 20210427 + #define JSON_HAS_RANGES 0 + #elif defined(__cpp_lib_ranges) + #define JSON_HAS_RANGES 1 + #else + #define JSON_HAS_RANGES 0 + #endif +#endif + +#ifdef JSON_HAS_CPP_17 + #define JSON_INLINE_VARIABLE inline +#else + #define JSON_INLINE_VARIABLE +#endif + +#if JSON_HEDLEY_HAS_ATTRIBUTE(no_unique_address) + #define JSON_NO_UNIQUE_ADDRESS [[no_unique_address]] +#else + #define JSON_NO_UNIQUE_ADDRESS +#endif + // disable documentation warnings on clang #if defined(__clang__) #pragma clang diagnostic push @@ -2631,6 +2711,7 @@ using is_detected_convertible = #define NLOHMANN_JSON_TO(v1) nlohmann_json_j[#v1] = nlohmann_json_t.v1; #define NLOHMANN_JSON_FROM(v1) nlohmann_json_j.at(#v1).get_to(nlohmann_json_t.v1); +#define NLOHMANN_JSON_FROM_WITH_DEFAULT(v1) nlohmann_json_t.v1 = nlohmann_json_j.value(#v1, nlohmann_json_default_obj.v1); /*! @brief macro @@ -2641,6 +2722,10 @@ using is_detected_convertible = friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_INTRUSIVE_WITH_DEFAULT(Type, ...) \ + friend void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + friend void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } + /*! @brief macro @def NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE @@ -2650,6 +2735,10 @@ using is_detected_convertible = inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM, __VA_ARGS__)) } +#define NLOHMANN_DEFINE_TYPE_NON_INTRUSIVE_WITH_DEFAULT(Type, ...) \ + inline void to_json(nlohmann::json& nlohmann_json_j, const Type& nlohmann_json_t) { NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_TO, __VA_ARGS__)) } \ + inline void from_json(const nlohmann::json& nlohmann_json_j, Type& nlohmann_json_t) { Type nlohmann_json_default_obj; NLOHMANN_JSON_EXPAND(NLOHMANN_JSON_PASTE(NLOHMANN_JSON_FROM_WITH_DEFAULT, __VA_ARGS__)) } + // inspired from https://stackoverflow.com/a/26745591 // allows to call any std function as if (e.g. with begin): @@ -2699,13 +2788,132 @@ using is_detected_convertible = #define JSON_EXPLICIT explicit #endif -#ifndef JSON_DIAGNOSTICS - #define JSON_DIAGNOSTICS 0 +#ifndef JSON_DISABLE_ENUM_SERIALIZATION + #define JSON_DISABLE_ENUM_SERIALIZATION 0 +#endif + +#ifndef JSON_USE_GLOBAL_UDLS + #define JSON_USE_GLOBAL_UDLS 0 +#endif + +#if JSON_HAS_THREE_WAY_COMPARISON + #include // partial_ordering +#endif + +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ + +/////////////////////////// +// JSON type enumeration // +/////////////////////////// + +/*! +@brief the JSON type enumeration + +This enumeration collects the different JSON types. It is internally used to +distinguish the stored values, and the functions @ref basic_json::is_null(), +@ref basic_json::is_object(), @ref basic_json::is_array(), +@ref basic_json::is_string(), @ref basic_json::is_boolean(), +@ref basic_json::is_number() (with @ref basic_json::is_number_integer(), +@ref basic_json::is_number_unsigned(), and @ref basic_json::is_number_float()), +@ref basic_json::is_discarded(), @ref basic_json::is_primitive(), and +@ref basic_json::is_structured() rely on it. + +@note There are three enumeration entries (number_integer, number_unsigned, and +number_float), because the library distinguishes these three types for numbers: +@ref basic_json::number_unsigned_t is used for unsigned integers, +@ref basic_json::number_integer_t is used for signed integers, and +@ref basic_json::number_float_t is used for floating-point numbers or to +approximate integers which do not fit in the limits of their respective type. + +@sa see @ref basic_json::basic_json(const value_t value_type) -- create a JSON +value with the default value for a given type + +@since version 1.0.0 +*/ +enum class value_t : std::uint8_t +{ + null, ///< null value + object, ///< object (unordered set of name/value pairs) + array, ///< array (ordered collection of values) + string, ///< string value + boolean, ///< boolean value + number_integer, ///< number value (signed integer) + number_unsigned, ///< number value (unsigned integer) + number_float, ///< number value (floating-point) + binary, ///< binary array (ordered collection of bytes) + discarded ///< discarded by the parser callback function +}; + +/*! +@brief comparison operator for JSON types + +Returns an ordering that is similar to Python: +- order: null < boolean < number < object < array < string < binary +- furthermore, each type is not smaller than itself +- discarded values are not comparable +- binary is represented as a b"" string in python and directly comparable to a + string; however, making a binary array directly comparable with a string would + be surprising behavior in a JSON file. + +@since version 1.0.0 +*/ +#if JSON_HAS_THREE_WAY_COMPARISON + inline std::partial_ordering operator<=>(const value_t lhs, const value_t rhs) noexcept // *NOPAD* +#else + inline bool operator<(const value_t lhs, const value_t rhs) noexcept #endif +{ + static constexpr std::array order = {{ + 0 /* null */, 3 /* object */, 4 /* array */, 5 /* string */, + 1 /* boolean */, 2 /* integer */, 2 /* unsigned */, 2 /* float */, + 6 /* binary */ + } + }; + const auto l_index = static_cast(lhs); + const auto r_index = static_cast(rhs); +#if JSON_HAS_THREE_WAY_COMPARISON + if (l_index < order.size() && r_index < order.size()) + { + return order[l_index] <=> order[r_index]; // *NOPAD* + } + return std::partial_ordering::unordered; +#else + return l_index < order.size() && r_index < order.size() && order[l_index] < order[r_index]; +#endif +} -namespace nlohmann +// GCC selects the built-in operator< over an operator rewritten from +// a user-defined spaceship operator +// Clang, MSVC, and ICC select the rewritten candidate +// (see GCC bug https://gcc.gnu.org/bugzilla/show_bug.cgi?id=105200) +#if JSON_HAS_THREE_WAY_COMPARISON && defined(__GNUC__) +inline bool operator<(const value_t lhs, const value_t rhs) noexcept { + return std::is_lt(lhs <=> rhs); // *NOPAD* +} +#endif + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + + + +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { @@ -2722,12 +2930,13 @@ enforced with an assertion.** @since version 2.0.0 */ -inline void replace_substring(std::string& s, const std::string& f, - const std::string& t) +template +inline void replace_substring(StringType& s, const StringType& f, + const StringType& t) { JSON_ASSERT(!f.empty()); for (auto pos = s.find(f); // find first occurrence of f - pos != std::string::npos; // make sure f was found + pos != StringType::npos; // make sure f was found s.replace(pos, f.size(), t), // replace with t, and pos = s.find(f, pos + t.size())) // find next occurrence of f {} @@ -2740,10 +2949,11 @@ inline void replace_substring(std::string& s, const std::string& f, * * Note the order of escaping "~" to "~0" and "/" to "~1" is important. */ -inline std::string escape(std::string s) +template +inline StringType escape(StringType s) { - replace_substring(s, "~", "~0"); - replace_substring(s, "/", "~1"); + replace_substring(s, StringType{"~"}, StringType{"~0"}); + replace_substring(s, StringType{"/"}, StringType{"~1"}); return s; } @@ -2754,24 +2964,36 @@ inline std::string escape(std::string s) * * Note the order of escaping "~1" to "/" and "~0" to "~" is important. */ -static void unescape(std::string& s) +template +static void unescape(StringType& s) { - replace_substring(s, "~1", "/"); - replace_substring(s, "~0", "~"); + replace_substring(s, StringType{"~1"}, StringType{"/"}); + replace_substring(s, StringType{"~0"}, StringType{"~"}); } -} // namespace detail -} // namespace nlohmann +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + #include // size_t -namespace nlohmann -{ +// #include + + +NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { + /// struct to capture the start position of the current token struct position_t { @@ -2789,275 +3011,55 @@ struct position_t } }; -} // namespace detail -} // namespace nlohmann +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END // #include +// #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-FileCopyrightText: 2018 The Abseil Authors +// SPDX-License-Identifier: MIT -namespace nlohmann -{ -namespace detail -{ -//////////////// -// exceptions // -//////////////// -/// @brief general exception of the @ref basic_json class -/// @sa https://json.nlohmann.me/api/basic_json/exception/ -class exception : public std::exception -{ - public: - /// returns the explanatory string - const char* what() const noexcept override - { - return m.what(); - } - /// the id of the exception - const int id; // NOLINT(cppcoreguidelines-non-private-member-variables-in-classes) +#include // size_t +#include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type +#include // index_sequence, make_index_sequence, index_sequence_for - protected: - JSON_HEDLEY_NON_NULL(3) - exception(int id_, const char* what_arg) : id(id_), m(what_arg) {} // NOLINT(bugprone-throw-keyword-missing) +// #include - static std::string name(const std::string& ename, int id_) - { - return "[json.exception." + ename + "." + std::to_string(id_) + "] "; - } - template - static std::string diagnostics(const BasicJsonType& leaf_element) - { -#if JSON_DIAGNOSTICS - std::vector tokens; - for (const auto* current = &leaf_element; current->m_parent != nullptr; current = current->m_parent) - { - switch (current->m_parent->type()) - { - case value_t::array: - { - for (std::size_t i = 0; i < current->m_parent->m_value.array->size(); ++i) - { - if (¤t->m_parent->m_value.array->operator[](i) == current) - { - tokens.emplace_back(std::to_string(i)); - break; - } - } - break; - } +NLOHMANN_JSON_NAMESPACE_BEGIN +namespace detail +{ - case value_t::object: - { - for (const auto& element : *current->m_parent->m_value.object) - { - if (&element.second == current) - { - tokens.emplace_back(element.first.c_str()); - break; - } - } - break; - } +template +using uncvref_t = typename std::remove_cv::type>::type; - case value_t::null: // LCOV_EXCL_LINE - case value_t::string: // LCOV_EXCL_LINE - case value_t::boolean: // LCOV_EXCL_LINE - case value_t::number_integer: // LCOV_EXCL_LINE - case value_t::number_unsigned: // LCOV_EXCL_LINE - case value_t::number_float: // LCOV_EXCL_LINE - case value_t::binary: // LCOV_EXCL_LINE - case value_t::discarded: // LCOV_EXCL_LINE - default: // LCOV_EXCL_LINE - break; // LCOV_EXCL_LINE - } - } +#ifdef JSON_HAS_CPP_14 - if (tokens.empty()) - { - return ""; - } +// the following utilities are natively available in C++14 +using std::enable_if_t; +using std::index_sequence; +using std::make_index_sequence; +using std::index_sequence_for; - return "(" + std::accumulate(tokens.rbegin(), tokens.rend(), std::string{}, - [](const std::string & a, const std::string & b) - { - return a + "/" + detail::escape(b); - }) + ") "; #else - static_cast(leaf_element); - return ""; -#endif - } - - private: - /// an exception object as storage for error messages - std::runtime_error m; -}; - -/// @brief exception indicating a parse error -/// @sa https://json.nlohmann.me/api/basic_json/parse_error/ -class parse_error : public exception -{ - public: - /*! - @brief create a parse error exception - @param[in] id_ the id of the exception - @param[in] pos the position where the error occurred (or with - chars_read_total=0 if the position cannot be - determined) - @param[in] what_arg the explanatory string - @return parse_error object - */ - template - static parse_error create(int id_, const position_t& pos, const std::string& what_arg, const BasicJsonType& context) - { - std::string w = exception::name("parse_error", id_) + "parse error" + - position_string(pos) + ": " + exception::diagnostics(context) + what_arg; - return {id_, pos.chars_read_total, w.c_str()}; - } - - template - static parse_error create(int id_, std::size_t byte_, const std::string& what_arg, const BasicJsonType& context) - { - std::string w = exception::name("parse_error", id_) + "parse error" + - (byte_ != 0 ? (" at byte " + std::to_string(byte_)) : "") + - ": " + exception::diagnostics(context) + what_arg; - return {id_, byte_, w.c_str()}; - } - /*! - @brief byte index of the parse error +// alias templates to reduce boilerplate +template +using enable_if_t = typename std::enable_if::type; - The byte index of the last read character in the input file. +// The following code is taken from https://github.com/abseil/abseil-cpp/blob/10cb35e459f5ecca5b2ff107635da0bfa41011b4/absl/utility/utility.h +// which is part of Google Abseil (https://github.com/abseil/abseil-cpp), licensed under the Apache License 2.0. - @note For an input with n bytes, 1 is the index of the first character and - n+1 is the index of the terminating null byte or the end of file. - This also holds true when reading a byte vector (CBOR or MessagePack). - */ - const std::size_t byte; - - private: - parse_error(int id_, std::size_t byte_, const char* what_arg) - : exception(id_, what_arg), byte(byte_) {} - - static std::string position_string(const position_t& pos) - { - return " at line " + std::to_string(pos.lines_read + 1) + - ", column " + std::to_string(pos.chars_read_current_line); - } -}; - -/// @brief exception indicating errors with iterators -/// @sa https://json.nlohmann.me/api/basic_json/invalid_iterator/ -class invalid_iterator : public exception -{ - public: - template - static invalid_iterator create(int id_, const std::string& what_arg, const BasicJsonType& context) - { - std::string w = exception::name("invalid_iterator", id_) + exception::diagnostics(context) + what_arg; - return {id_, w.c_str()}; - } - - private: - JSON_HEDLEY_NON_NULL(3) - invalid_iterator(int id_, const char* what_arg) - : exception(id_, what_arg) {} -}; - -/// @brief exception indicating executing a member function with a wrong type -/// @sa https://json.nlohmann.me/api/basic_json/type_error/ -class type_error : public exception -{ - public: - template - static type_error create(int id_, const std::string& what_arg, const BasicJsonType& context) - { - std::string w = exception::name("type_error", id_) + exception::diagnostics(context) + what_arg; - return {id_, w.c_str()}; - } - - private: - JSON_HEDLEY_NON_NULL(3) - type_error(int id_, const char* what_arg) : exception(id_, what_arg) {} -}; - -/// @brief exception indicating access out of the defined range -/// @sa https://json.nlohmann.me/api/basic_json/out_of_range/ -class out_of_range : public exception -{ - public: - template - static out_of_range create(int id_, const std::string& what_arg, const BasicJsonType& context) - { - std::string w = exception::name("out_of_range", id_) + exception::diagnostics(context) + what_arg; - return {id_, w.c_str()}; - } - - private: - JSON_HEDLEY_NON_NULL(3) - out_of_range(int id_, const char* what_arg) : exception(id_, what_arg) {} -}; - -/// @brief exception indicating other library errors -/// @sa https://json.nlohmann.me/api/basic_json/other_error/ -class other_error : public exception -{ - public: - template - static other_error create(int id_, const std::string& what_arg, const BasicJsonType& context) - { - std::string w = exception::name("other_error", id_) + exception::diagnostics(context) + what_arg; - return {id_, w.c_str()}; - } - - private: - JSON_HEDLEY_NON_NULL(3) - other_error(int id_, const char* what_arg) : exception(id_, what_arg) {} -}; - -} // namespace detail -} // namespace nlohmann - -// #include - -// #include - - -#include // size_t -#include // conditional, enable_if, false_type, integral_constant, is_constructible, is_integral, is_same, remove_cv, remove_reference, true_type -#include // index_sequence, make_index_sequence, index_sequence_for - -// #include - - -namespace nlohmann -{ -namespace detail -{ - -template -using uncvref_t = typename std::remove_cv::type>::type; - -#ifdef JSON_HAS_CPP_14 - -// the following utilities are natively available in C++14 -using std::enable_if_t; -using std::index_sequence; -using std::make_index_sequence; -using std::index_sequence_for; - -#else - -// alias templates to reduce boilerplate -template -using enable_if_t = typename std::enable_if::type; - -// The following code is taken from https://github.com/abseil/abseil-cpp/blob/10cb35e459f5ecca5b2ff107635da0bfa41011b4/absl/utility/utility.h -// which is part of Google Abseil (https://github.com/abseil/abseil-cpp), licensed under the Apache License 2.0. - -//// START OF CODE FROM GOOGLE ABSEIL +//// START OF CODE FROM GOOGLE ABSEIL // integer_sequence // @@ -3173,25 +3175,25 @@ struct static_const static constexpr T value{}; }; -template -constexpr T static_const::value; // NOLINT(readability-redundant-declaration) - -} // namespace detail -} // namespace nlohmann +#ifndef JSON_HAS_CPP_17 -// #include + template + constexpr T static_const::value; // NOLINT(readability-redundant-declaration) +#endif -namespace nlohmann -{ -namespace detail -{ -// dispatching helper struct -template struct identity_tag {}; } // namespace detail -} // namespace nlohmann +NLOHMANN_JSON_NAMESPACE_END // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + #include // numeric_limits @@ -3199,23 +3201,30 @@ template struct identity_tag {}; #include // declval #include // tuple -// #include - - // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + #include // random_access_iterator_tag +// #include + // #include // #include -namespace nlohmann -{ +NLOHMANN_JSON_NAMESPACE_BEGIN namespace detail { + template struct iterator_types {}; @@ -3254,104 +3263,135 @@ struct iterator_traits::value>> using pointer = T*; using reference = T&; }; -} // namespace detail -} // namespace nlohmann + +} // namespace detail +NLOHMANN_JSON_NAMESPACE_END + +// #include // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + // #include -namespace nlohmann -{ +NLOHMANN_JSON_NAMESPACE_BEGIN + NLOHMANN_CAN_CALL_STD_FUNC_IMPL(begin); -} // namespace nlohmann + +NLOHMANN_JSON_NAMESPACE_END // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + // #include -namespace nlohmann -{ +NLOHMANN_JSON_NAMESPACE_BEGIN + NLOHMANN_CAN_CALL_STD_FUNC_IMPL(end); -} // namespace nlohmann + +NLOHMANN_JSON_NAMESPACE_END // #include // #include // #include +// __ _____ _____ _____ +// __| | __| | | | JSON for Modern C++ +// | | |__ | | | | | | version 3.11.0 +// |_____|_____|_____|_|___| https://github.com/nlohmann/json +// +// SPDX-FileCopyrightText: 2013-2022 Niels Lohmann +// SPDX-License-Identifier: MIT + #ifndef INCLUDE_NLOHMANN_JSON_FWD_HPP_ -#define INCLUDE_NLOHMANN_JSON_FWD_HPP_ + #define INCLUDE_NLOHMANN_JSON_FWD_HPP_ -#include // int64_t, uint64_t -#include // map -#include // allocator -#include // string -#include // vector + #include // int64_t, uint64_t + #include // map + #include // allocator + #include // string + #include // vector -/*! -@brief namespace for Niels Lohmann -@see https://github.com/nlohmann -@since version 1.0.0 -*/ -namespace nlohmann -{ -/*! -@brief default JSONSerializer template argument + // #include -This serializer ignores the template arguments and uses ADL -([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) -for serialization. -*/ -template -struct adl_serializer; - -/// a class to store JSON values -/// @sa https://json.nlohmann.me/api/basic_json/ -template class ObjectType = - std::map, - template class ArrayType = std::vector, - class StringType = std::string, class BooleanType = bool, - class NumberIntegerType = std::int64_t, - class NumberUnsignedType = std::uint64_t, - class NumberFloatType = double, - template class AllocatorType = std::allocator, - template class JSONSerializer = - adl_serializer, - class BinaryType = std::vector> -class basic_json; -/// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document -/// @sa https://json.nlohmann.me/api/json_pointer/ -template -class json_pointer; + /*! + @brief namespace for Niels Lohmann + @see https://github.com/nlohmann + @since version 1.0.0 + */ + NLOHMANN_JSON_NAMESPACE_BEGIN -/*! -@brief default specialization -@sa https://json.nlohmann.me/api/json/ -*/ -using json = basic_json<>; + /*! + @brief default JSONSerializer template argument -/// @brief a minimal map-like container that preserves insertion order -/// @sa https://json.nlohmann.me/api/ordered_map/ -template -struct ordered_map; + This serializer ignores the template arguments and uses ADL + ([argument-dependent lookup](https://en.cppreference.com/w/cpp/language/adl)) + for serialization. + */ + template + struct adl_serializer; + + /// a class to store JSON values + /// @sa https://json.nlohmann.me/api/basic_json/ + template class ObjectType = + std::map, + template class ArrayType = std::vector, + class StringType = std::string, class BooleanType = bool, + class NumberIntegerType = std::int64_t, + class NumberUnsignedType = std::uint64_t, + class NumberFloatType = double, + template class AllocatorType = std::allocator, + template class JSONSerializer = + adl_serializer, + class BinaryType = std::vector> + class basic_json; + + /// @brief JSON Pointer defines a string syntax for identifying a specific value within a JSON document + /// @sa https://json.nlohmann.me/api/json_pointer/ + template + class json_pointer; + + /*! + @brief default specialization + @sa https://json.nlohmann.me/api/json/ + */ + using json = basic_json<>; + + /// @brief a minimal map-like container that preserves insertion order + /// @sa https://json.nlohmann.me/api/ordered_map/ + template + struct ordered_map; -/// @brief specialization that maintains the insertion order of object keys -/// @sa https://json.nlohmann.me/api/ordered_json/ -using ordered_json = basic_json; + /// @brief specialization that maintains the insertion order of object keys + /// @sa https://json.nlohmann.me/api/ordered_json/ + using ordered_json = basic_json; -} // namespace nlohmann + NLOHMANN_JSON_NAMESPACE_END #endif // INCLUDE_NLOHMANN_JSON_FWD_HPP_ -namespace nlohmann -{ +NLOHMANN_JSON_NAMESPACE_BEGIN /*! @brief detail namespace with internal helper functions @@ -3362,6 +3402,7 @@ implementations of some @ref basic_json methods, and meta-programming helpers. */ namespace detail { + ///////////// // helpers // ///////////// @@ -3380,6 +3421,16 @@ template struct is_basic_json : std::false_type {}; NLOHMANN_BASIC_JSON_TPL_DECLARATION struct is_basic_json : std::true_type {}; +// used by exceptions create() member functions +// true_type for pointer to possibly cv-qualified basic_json or std::nullptr_t +// false_type otherwise +template +struct is_basic_json_context : + std::integral_constant < bool, + is_basic_json::type>::type>::value + || std::is_same::value > +{}; + ////////////////////// // json_ref helpers // ////////////////////// @@ -3481,6 +3532,24 @@ struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json::value >> T>::value; }; +template +using detect_key_compare = typename T::key_compare; + +template +struct has_key_compare : std::integral_constant::value> {}; + +// obtains the actual object key comparator +template +struct actual_object_comparator +{ + using object_t = typename BasicJsonType::object_t; + using object_comparator_t = typename BasicJsonType::default_object_comparator_t; + using type = typename std::conditional < has_key_compare::value, + typename object_t::key_compare, object_comparator_t>::type; +}; + +template +using actual_object_comparator_t = typename actual_object_comparator::type; /////////////////// // is_ functions // @@ -3488,10 +3557,10 @@ struct has_to_json < BasicJsonType, T, enable_if_t < !is_basic_json::value >> // https://en.cppreference.com/w/cpp/types/conjunction template struct conjunction : std::true_type { }; -template struct conjunction : B1 { }; -template -struct conjunction -: std::conditional, B1>::type {}; +template struct conjunction : B { }; +template +struct conjunction +: std::conditional(B::value), conjunction, B>::type {}; // https://en.cppreference.com/w/cpp/types/negation template struct negation : std::integral_constant < bool, !B::value > { }; @@ -3655,9 +3724,18 @@ struct is_compatible_string_type template struct is_constructible_string_type { + // launder type through decltype() to fix compilation failure on ICPC +#ifdef __INTEL_COMPILER + using laundered_type = decltype(std::declval()); +#else + using laundered_type = ConstructibleStringType; +#endif + static constexpr auto value = - is_constructible::value; + conjunction < + is_constructible, + is_detected_exact>::value; }; template @@ -3753,89 +3831,692 @@ struct is_compatible_integer_type : is_compatible_integer_type_impl {}; -template -struct is_compatible_type_impl: std::false_type {}; +template +struct is_compatible_type_impl: std::false_type {}; + +template +struct is_compatible_type_impl < + BasicJsonType, CompatibleType, + enable_if_t::value >> +{ + static constexpr bool value = + has_to_json::value; +}; + +template +struct is_compatible_type + : is_compatible_type_impl {}; + +template +struct is_constructible_tuple : std::false_type {}; + +template +struct is_constructible_tuple> : conjunction...> {}; + +template +struct is_json_iterator_of : std::false_type {}; + +template +struct is_json_iterator_of : std::true_type {}; + +template +struct is_json_iterator_of : std::true_type +{}; + +// checks if a given type T is a template specialization of Primary +template