helics  3.5.2
queryHelpers.hpp
1 /*
2 Copyright (c) 2017-2024,
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(Json::Value& iblock,
83  const helics::HandleManager& hm,
84  const helics::GlobalFederateId& fed);
85 
86 Json::Value generateInterfaceConfig(const helics::HandleManager& hm,
87  const helics::GlobalFederateId& fed);
88 
89 void addFederateTags(Json::Value& v, const helics::FederateState* fed);
91 std::string generateInterfaceQueryResults(std::string_view request,
92  const HandleManager& handles,
93  const GlobalFederateId fed,
94  const std::function<void(Json::Value&)>& addHeaderInfo);
95 
96 std::string generateInterfaceQueryResults(std::string_view request,
97  const InterfaceInfo& info,
98  const std::function<void(Json::Value&)>& addHeaderInfo);
99 } // namespace helics
Definition: FederateState.hpp:50
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(Json::Value &)> &addHeaderInfo)
Definition: queryHelpers.cpp:208
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