helics 3.7.0
Loading...
Searching...
No Matches
queryHelpers.hpp
1/*
2Copyright (c) 2017-2026,
3Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Energy
4Innovation LLC. See the top-level NOTICE for additional details. All rights reserved.
5SPDX-License-Identifier: BSD-3-Clause
6*/
7
8#pragma once
9#include "../common/JsonGeneration.hpp"
10
11#include <functional>
12#include <string>
13#include <string_view>
14#include <type_traits>
15
16namespace helics {
17class HandleManager;
18class GlobalFederateId;
19class FederateState;
20class InterfaceInfo;
21
23enum Subqueries : std::uint16_t {
24 GENERAL_QUERY = 0,
25 FEDERATE_MAP = 1,
26 CURRENT_TIME_MAP = 2,
27 DEPENDENCY_GRAPH = 3,
28 DATA_FLOW_GRAPH = 4,
29 VERSION_ALL = 5,
30 GLOBAL_STATE = 6,
31 GLOBAL_TIME_DEBUGGING = 7,
32 GLOBAL_FLUSH = 8,
33 GLOBAL_STATUS = 9,
34 BARRIERS = 11,
35 UNCONNECTED_INTERFACES = 14
36};
37
39enum class QueryReuse : std::uint8_t { ENABLED = 0, DISABLED = 1 };
40
41} // namespace helics
42
43template<typename X, typename Proc>
44std::string generateStringVector(const X& data, Proc generator)
45{
46 static_assert(std::is_convertible<decltype(generator(*(data.begin()))), std::string>::value,
47 "generator output must be convertible to std::string");
48 std::string ret{"["};
49 for (auto& ele : data) {
50 ret.append(helics::generateJsonQuotedString(generator(ele)));
51 ret.push_back(',');
52 }
53 if (ret.size() > 1) {
54 ret.back() = ']';
55 } else {
56 ret.push_back(']');
57 }
58 return ret;
59}
60
61template<typename X, typename Proc, typename validator>
62std::string generateStringVector_if(const X& data, Proc generator, validator valid)
63{
64 static_assert(std::is_convertible<decltype(generator(*(data.begin()))), std::string>::value,
65 "generator output must be convertible to std::string");
66 std::string ret{"["};
67 for (auto& ele : data) {
68 if (valid(ele)) {
69 ret.append(helics::generateJsonQuotedString(generator(ele)));
70 ret.push_back(',');
71 }
72 }
73 if (ret.size() > 1) {
74 ret.back() = ']';
75 } else {
76 ret.push_back(']');
77 }
78 return ret;
79}
80
81namespace helics {
82void generateInterfaceConfig(nlohmann::json& iblock,
83 const helics::HandleManager& hm,
84 const helics::GlobalFederateId& fed);
85
86nlohmann::json generateInterfaceConfig(const helics::HandleManager& hm,
87 const helics::GlobalFederateId& fed);
88
89void addFederateTags(nlohmann::json& v, const helics::FederateState* fed);
91std::string
92 generateInterfaceQueryResults(std::string_view request,
93 const HandleManager& handles,
94 const GlobalFederateId fed,
95 const std::function<void(nlohmann::json&)>& addHeaderInfo);
96
97std::string
98 generateInterfaceQueryResults(std::string_view request,
99 const InterfaceInfo& info,
100 const std::function<void(nlohmann::json&)>& addHeaderInfo);
101} // namespace helics
Definition FederateState.hpp:51
Definition GlobalFederateId.hpp:75
Definition HandleManager.hpp:25
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition AsyncFedCallInfo.hpp:14
std::string generateInterfaceQueryResults(std::string_view request, const HandleManager &handles, const GlobalFederateId fed, const std::function< void(nlohmann::json &)> &addHeaderInfo)
Definition queryHelpers.cpp:213
Subqueries
enumeration of subqueries that cascade and need multiple levels of processing
Definition queryHelpers.hpp:23
QueryReuse
Enumeration of if query result is reusable.
Definition queryHelpers.hpp:39