| helics 3.6.1

queryHelpers.hpp
1 /*
2 Copyright (c) 2017-2025,
3 Battelle Memorial Institute; Lawrence Livermore National Security, LLC; Alliance for Sustainable
4 Energy, LLC. See the top-level NOTICE for additional details. All rights reserved.
5 SPDX-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
16 namespace helics {
17 class HandleManager;
18 class GlobalFederateId;
19 class FederateState;
20 class InterfaceInfo;
21
23 enum 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
39 enum class QueryReuse : std::uint8_t { ENABLED = 0, DISABLED = 1 };
40
41 } // namespace helics
42
43 template<typename X, typename Proc>
44 std::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
61 template<typename X, typename Proc, typename validator>
62 std::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
81 namespace helics {
82 void generateInterfaceConfig(nlohmann::json& iblock,
83 const helics::HandleManager& hm,
84 const helics::GlobalFederateId& fed);
85
86 nlohmann::json generateInterfaceConfig(const helics::HandleManager& hm,
87 const helics::GlobalFederateId& fed);
88
89 void addFederateTags(nlohmann::json& v, const helics::FederateState* fed);
91 std::string
92 generateInterfaceQueryResults(std::string_view request,
93 const HandleManager& handles,
94 const GlobalFederateId fed,
95 const std::function<void(nlohmann::json&)>& addHeaderInfo);
96
97 std::string
98 generateInterfaceQueryResults(std::string_view request,
99 const InterfaceInfo& info,
100 const std::function<void(nlohmann::json&)>& addHeaderInfo);
101 } // namespace helics
helics::FederateState
Definition: FederateState.hpp:50
helics::GlobalFederateId
Definition: GlobalFederateId.hpp:75
helics::HandleManager
Definition: HandleManager.hpp:25
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::generateInterfaceQueryResults
std::string generateInterfaceQueryResults(std::string_view request, const HandleManager &handles, const GlobalFederateId fed, const std::function< void(nlohmann::json &)> &addHeaderInfo)
Definition: queryHelpers.cpp:213
helics::Subqueries
Subqueries
enumeration of subqueries that cascade and need multiple levels of processing
Definition: queryHelpers.hpp:23
helics::QueryReuse
QueryReuse
Enumeration of if query result is reusable.
Definition: queryHelpers.hpp:39