helics  3.0.1
queryHelpers.hpp
1 /*
2 Copyright (c) 2017-2021,
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 <string>
12 #include <type_traits>
13 
14 namespace helics {
15 class HandleManager;
16 class GlobalFederateId;
17 class FederateState;
18 
19 // enumeration of subqueries that cascade and need multiple levels of processing
20 enum Subqueries : std::uint16_t {
21  GENERAL_QUERY = 0,
22  FEDERATE_MAP = 1,
23  CURRENT_TIME_MAP = 2,
24  DEPENDENCY_GRAPH = 3,
25  DATA_FLOW_GRAPH = 4,
26  VERSION_ALL = 5,
27  GLOBAL_STATE = 6,
28  GLOBAL_TIME_DEBUGGING = 7,
29  GLOBAL_FLUSH = 8,
30  GLOBAL_STATUS = 9
31 };
32 
33 } // namespace helics
34 
35 template<typename X, typename Proc>
36 std::string generateStringVector(const X& data, Proc generator)
37 {
38  static_assert(std::is_convertible<decltype(generator(*(data.begin()))), std::string>::value,
39  "generator output must be convertible to std::string");
40  std::string ret{"["};
41  for (auto& ele : data) {
42  ret.append(helics::generateJsonQuotedString(generator(ele)));
43  ret.push_back(',');
44  }
45  if (ret.size() > 1) {
46  ret.back() = ']';
47  } else {
48  ret.push_back(']');
49  }
50  return ret;
51 }
52 
53 template<typename X, typename Proc, typename validator>
54 std::string generateStringVector_if(const X& data, Proc generator, validator valid)
55 {
56  static_assert(std::is_convertible<decltype(generator(*(data.begin()))), std::string>::value,
57  "generator output must be convertible to std::string");
58  std::string ret{"["};
59  for (auto& ele : data) {
60  if (valid(ele)) {
61  ret.append(helics::generateJsonQuotedString(generator(ele)));
62  ret.push_back(',');
63  }
64  }
65  if (ret.size() > 1) {
66  ret.back() = ']';
67  } else {
68  ret.push_back(']');
69  }
70  return ret;
71 }
72 
73 namespace helics {
74 void generateInterfaceConfig(Json::Value& iblock,
75  const helics::HandleManager& hm,
76  const helics::GlobalFederateId& fed);
77 
78 Json::Value generateInterfaceConfig(const helics::HandleManager& hm,
79  const helics::GlobalFederateId& fed);
80 
81 void addFederateTags(Json::Value& v, const helics::FederateState* fed);
82 } // namespace helics
helics::GlobalFederateId
Definition: GlobalFederateId.hpp:68
helics::InterfaceType::FILTER
@ FILTER
handle to a filter
helics::InterfaceType::INPUT
@ INPUT
handle to a input interface
helics::HandleManager
Definition: HandleManager.hpp:22
helics::FederateState
Definition: FederateState.hpp:42
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::InterfaceType::ENDPOINT
@ ENDPOINT
handle to an endpoint
helics::InterfaceType::PUBLICATION
@ PUBLICATION
handle to output interface