helics  2.8.1
addTargets.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 #pragma once
8 
9 #include "configFileHelpers.hpp"
10 
11 #include <string>
12 #include <type_traits>
13 
14 namespace helics {
15 template<typename Callable>
16 void addTargets(const toml::value& section, std::string targetName, Callable callback)
17 {
18  toml::value uval;
19  // There should probably be a static_assert here but there isn't a nice type trait to check that
20  auto targets = toml::find_or(section, targetName, uval);
21  if (!targets.is_uninitialized()) {
22  if (targets.is_array()) {
23  auto& targetArray = targets.as_array();
24  for (const auto& target : targetArray) {
25  callback(target.as_string());
26  }
27  } else {
28  callback(targets.as_string());
29  }
30  }
31  if (targetName.back() == 's') {
32  targetName.pop_back();
33  std::string target;
34  target = toml::find_or(section, targetName, target);
35  if (!target.empty()) {
36  callback(target);
37  }
38  }
39 }
40 
41 template<typename Callable>
42 void addTargets(const Json::Value& section, std::string targetName, Callable callback)
43 {
44  // There should probably be a static_assert here but there isn't a nice type trait to check that
45  if (section.isMember(targetName)) {
46  auto targets = section[targetName];
47  if (targets.isArray()) {
48  for (const auto& target : targets) {
49  callback(target.asString());
50  }
51  } else {
52  callback(targets.asString());
53  }
54  }
55  if (targetName.back() == 's') {
56  targetName.pop_back();
57  if (section.isMember(targetName)) {
58  callback(section[targetName].asString());
59  }
60  }
61 }
62 
63 void processOptions(const toml::value& section,
64  const std::function<int(const std::string&)>& optionConversion,
65  const std::function<int(const std::string&)>& valueConversion,
66  const std::function<void(int, int)>& optionAction);
67 
68 void processOptions(const Json::Value& section,
69  const std::function<int(const std::string&)>& optionConversion,
70  const std::function<int(const std::string&)>& valueConversion,
71  const std::function<void(int, int)>& optionAction);
72 
73 } // namespace helics
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14