helics  3.3.0
HandleManager.hpp
1 /*
2 Copyright (c) 2017-2022,
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 #include "BasicHandleInfo.hpp"
9 #include "Core.hpp"
10 #include "helicsTime.hpp"
11 
12 #include <deque>
13 #include <string>
14 #include <string_view>
15 #include <unordered_map>
16 #include <unordered_set>
17 #include <utility>
18 #include <vector>
19 
20 namespace helics {
21 
26  private:
34  std::deque<BasicHandleInfo> handles;
35  std::unordered_map<std::string_view, InterfaceHandle> publications;
38  std::unordered_map<std::string_view, InterfaceHandle> endpoints;
39  std::unordered_map<std::string_view, InterfaceHandle> inputs;
40  std::unordered_map<std::string_view, InterfaceHandle> filters;
41  std::unordered_map<std::string_view, InterfaceHandle> translators;
42  std::unordered_map<std::uint64_t, int32_t> unique_ids;
43  std::unordered_map<std::string_view, std::vector<std::string_view>> aliases;
45  std::unordered_set<std::string> alias_names;
46  public:
48  HandleManager() = default;
51  InterfaceType what,
52  std::string_view key,
53  std::string_view type,
54  std::string_view units);
57  InterfaceHandle local_id,
58  InterfaceType what,
59  std::string_view key,
60  std::string_view type,
61  std::string_view units);
62 
63  void addHandle(const BasicHandleInfo& otherHandle);
65  void addHandleAtIndex(const BasicHandleInfo& otherHandle, int32_t index);
67  void removeHandle(GlobalHandle handle);
69  BasicHandleInfo* getHandleInfo(int32_t index);
71  const BasicHandleInfo* getHandleInfo(int32_t index) const;
75  const BasicHandleInfo* getHandleInfo(InterfaceHandle handle) const;
79  const BasicHandleInfo* findHandle(GlobalHandle id) const;
80 
81  void setHandleOption(InterfaceHandle handle, int32_t option, int32_t val);
82 
83  int32_t getHandleOption(InterfaceHandle handle, int32_t option) const;
85  BasicHandleInfo* getEndpoint(std::string_view name);
87  const BasicHandleInfo* getEndpoint(std::string_view name) const;
93  const BasicHandleInfo* getEndpoint(InterfaceHandle handle) const;
95  const BasicHandleInfo* getFilter(std::string_view name) const;
96  BasicHandleInfo* getFilter(std::string_view name);
100 
101  const BasicHandleInfo* getTranslator(std::string_view name) const;
102  BasicHandleInfo* getTranslator(std::string_view name);
105  BasicHandleInfo* getTranslator(InterfaceHandle handle);
106 
108  BasicHandleInfo* getPublication(std::string_view name);
109  const BasicHandleInfo* getPublication(std::string_view name) const;
113  BasicHandleInfo* getInput(std::string_view name);
114  const BasicHandleInfo* getInput(std::string_view name) const;
115  LocalFederateId getLocalFedID(InterfaceHandle handle) const;
116 
117  BasicHandleInfo& operator[](size_t index) { return handles[index]; }
118  const BasicHandleInfo& operator[](size_t index) const { return handles[index]; }
123  void addAlias(std::string_view interfaceName, std::string_view alias);
124  auto begin() { return handles.begin(); }
125  auto end() { return handles.end(); }
126  auto begin() const { return handles.begin(); }
127  auto end() const { return handles.end(); }
128  auto size() const { return handles.size(); }
129 
130  private:
131  void addSearchFields(const BasicHandleInfo& handle, int32_t index);
132  std::string generateName(InterfaceType what) const;
133  // alias must be a stable string_view here
134  void addPublicationAlias(std::string_view interfaceName, std::string_view alias);
135  // alias must be a stable string_view here
136  void addInputAlias(std::string_view interfaceName, std::string_view alias);
137  // alias must be a stable string_view here
138  void addEndpointAlias(std::string_view interfaceName, std::string_view alias);
139  // alias must be a stable string_view here
140  void addFilterAlias(std::string_view interfaceName, std::string_view alias);
145  bool addAliasName(std::string_view interfaceName, std::string_view alias);
146 };
147 
148 } // namespace helics
HELICS_HANDLE_OPTION_ONLY_TRANSMIT_ON_CHANGE
@ HELICS_HANDLE_OPTION_ONLY_TRANSMIT_ON_CHANGE
Definition: helics_enums.h:340
helics::HandleManager::findHandle
BasicHandleInfo * findHandle(GlobalHandle id)
Definition: HandleManager.cpp:129
helics::HandleManager::addHandle
BasicHandleInfo & addHandle(GlobalFederateId fed_id, InterfaceType what, std::string_view key, std::string_view type, std::string_view units)
Definition: HandleManager.cpp:12
helics::optional_flag
@ optional_flag
flag indicating that a connection is optional and may not be matched
Definition: flagOperations.hpp:53
helics::HandleManager::getFilter
const BasicHandleInfo * getFilter(std::string_view name) const
Definition: HandleManager.cpp:305
HELICS_HANDLE_OPTION_ONLY_UPDATE_ON_CHANGE
@ HELICS_HANDLE_OPTION_ONLY_UPDATE_ON_CHANGE
Definition: helics_enums.h:342
helics::InterfaceType
InterfaceType
Definition: CoreTypes.hpp:99
helics::InterfaceHandle
Definition: LocalFederateId.hpp:65
helics::GlobalFederateId
Definition: GlobalFederateId.hpp:72
helics::InterfaceType::FILTER
@ FILTER
handle to a filter
helics::only_transmit_on_change_flag
@ only_transmit_on_change_flag
indicator that the interface should only transmit on change
Definition: flagOperations.hpp:62
helics::InterfaceType::INPUT
@ INPUT
handle to a input interface
HELICS_HANDLE_OPTION_CONNECTION_OPTIONAL
@ HELICS_HANDLE_OPTION_CONNECTION_OPTIONAL
Definition: helics_enums.h:326
helics::only_update_on_change_flag
@ only_update_on_change_flag
flag indicating that the values should only be updated on change
Definition: flagOperations.hpp:49
helics::HandleManager
Definition: HandleManager.hpp:25
helics::setActionFlag
void setActionFlag(FlagContainer &M, FlagIndex flag)
Definition: flagOperations.hpp:130
helics::HandleManager::removeHandle
void removeHandle(GlobalHandle handle)
Definition: HandleManager.cpp:46
helics::BasicHandleInfo
Definition: BasicHandleInfo.hpp:20
HELICS_HANDLE_OPTION_CONNECTION_REQUIRED
@ HELICS_HANDLE_OPTION_CONNECTION_REQUIRED
Definition: helics_enums.h:323
helics::HandleManager::HandleManager
HandleManager()=default
helics::HandleManager::getHandleInfo
BasicHandleInfo * getHandleInfo(int32_t index)
Definition: HandleManager.cpp:93
helics::InterfaceType::TRANSLATOR
@ TRANSLATOR
handle to a translator object
helics::HandleManager::getEndpoint
BasicHandleInfo * getEndpoint(std::string_view name)
Definition: HandleManager.cpp:203
helics::InterfaceHandle::baseValue
constexpr BaseType baseValue() const
Definition: LocalFederateId.hpp:73
helics::single_connection_flag
@ single_connection_flag
flag indicating that the interface accepts only a single connection
Definition: flagOperations.hpp:47
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::clearActionFlag
void clearActionFlag(FlagContainer &M, FlagIndex flag)
Definition: flagOperations.hpp:153
helics::checkActionFlag
bool checkActionFlag(uint16_t flags, FlagIndex flag)
Definition: flagOperations.hpp:138
helics::LocalFederateId
Definition: LocalFederateId.hpp:22
HELICS_HANDLE_OPTION_SINGLE_CONNECTION_ONLY
@ HELICS_HANDLE_OPTION_SINGLE_CONNECTION_ONLY
Definition: helics_enums.h:328
helics::required_flag
@ required_flag
flag indicating that an action or match is required
Definition: flagOperations.hpp:45
helics::GlobalHandle
Definition: GlobalFederateId.hpp:144
helics::HandleManager::getPublication
BasicHandleInfo * getPublication(std::string_view name)
Definition: HandleManager.cpp:247
helicsTime.hpp
helics::HandleManager::addAlias
void addAlias(std::string_view interfaceName, std::string_view alias)
Definition: HandleManager.cpp:369
helics::HandleManager::addHandleAtIndex
void addHandleAtIndex(const BasicHandleInfo &otherHandle, int32_t index)
Definition: HandleManager.cpp:78
helics::InterfaceType::PUBLICATION
@ PUBLICATION
handle to output interface
helics::isValidIndex
bool isValidIndex(sizeType testSize, const SizedDataType &vec)
Definition: core-data.hpp:171