helics  2.8.1
federate_id.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 <cstdint>
10 #include <functional>
11 #include <iosfwd>
12 
13 namespace helics {
15 using identififier_base_type = int32_t;
16 
23  public:
24  using base_type = identififier_base_type;
26  constexpr local_federate_id() = default;
28  constexpr explicit local_federate_id(base_type val) noexcept: fid(val) {}
30  constexpr base_type baseValue() const { return fid; }
32  bool operator==(local_federate_id id) const noexcept { return (fid == id.fid); }
34  bool operator!=(local_federate_id id) const noexcept { return (fid != id.fid); }
36  bool operator<(local_federate_id id) const noexcept { return (fid < id.fid); }
39  bool isValid() const { return (fid != invalid_fid); }
40 
41  private:
42  static constexpr base_type invalid_fid{-2'000'000'000}; //!< defined invalid handle
43  base_type fid{invalid_fid}; //!< the underlying index value
44 };
45 
46 #if defined HELICS_STATIC_CORE_LIBRARY && !defined HELICS_SHARED_LIBRARY
49 std::ostream& operator<<(std::ostream& os, local_federate_id fid);
50 
51 #endif
53 constexpr local_federate_id local_core_id(-259);
54 
55 namespace detail {
57  constexpr identififier_base_type invalid_interface_handle{-1'700'000'000};
58 } // namespace detail
59 
66  public:
67  using base_type = identififier_base_type;
69  constexpr interface_handle() = default;
70 
71  constexpr explicit interface_handle(base_type val) noexcept: hid(val) {}
73  constexpr base_type baseValue() const { return hid; }
75  bool operator==(interface_handle id) const noexcept { return (hid == id.hid); }
77  bool operator!=(interface_handle id) const noexcept { return (hid != id.hid); }
79  bool operator<(interface_handle id) const noexcept { return (hid < id.hid); }
80  bool operator>(interface_handle id) const noexcept { return (hid > id.hid); }
81  bool isValid() const { return (hid != invalid_handle); }
82 
83  private:
84  static constexpr base_type invalid_handle{detail::invalid_interface_handle};
85  base_type hid{invalid_handle};
86 };
87 
88 #if defined HELICS_STATIC_CORE_LIBRARY && !defined HELICS_SHARED_LIBRARY
89 
91 std::ostream& operator<<(std::ostream& os, interface_handle handle);
92 #endif
93 
95 constexpr interface_handle direct_send_handle{-1'745'234};
96 
97 } // namespace helics
98 
99 namespace std {
101 template<>
102 struct hash<helics::local_federate_id> {
104  using result_type =
105  hash<helics::local_federate_id::base_type>::result_type;
106 
107  result_type operator()(argument_type const& key) const noexcept
108  {
109  return std::hash<helics::local_federate_id::base_type>{}(key.baseValue());
110  }
111 };
112 
115 template<>
116 struct hash<helics::interface_handle> {
118  using result_type =
119  hash<helics::interface_handle::base_type>::result_type;
120 
121  result_type operator()(argument_type const& key) const noexcept
122  {
123  return std::hash<helics::interface_handle::base_type>{}(key.baseValue());
124  }
125 };
126 
127 } // namespace std
std::hash< helics::interface_handle >::result_type
hash< helics::interface_handle::base_type >::result_type result_type
the type of the return result
Definition: federate_id.hpp:119
helics::local_federate_id::operator<
bool operator<(local_federate_id id) const noexcept
Definition: federate_id.hpp:36
helics::operator<<
std::ostream & operator<<(std::ostream &os, const ActionMessage &command)
Definition: ActionMessage.cpp:933
helics::local_federate_id
Definition: federate_id.hpp:22
helics::interface_handle::baseValue
constexpr base_type baseValue() const
Definition: federate_id.hpp:73
helics::global_broker_id
Definition: global_federate_id.hpp:26
helics::global_federate_id
Definition: global_federate_id.hpp:68
helics::interface_handle::operator<
bool operator<(interface_handle id) const noexcept
Definition: federate_id.hpp:79
helics::interface_handle::operator!=
bool operator!=(interface_handle id) const noexcept
Definition: federate_id.hpp:77
std::hash< helics::local_federate_id >::operator()
result_type operator()(argument_type const &key) const noexcept
Definition: federate_id.hpp:107
helics::local_federate_id::baseValue
constexpr base_type baseValue() const
Definition: federate_id.hpp:30
std::hash< helics::interface_handle >::operator()
result_type operator()(argument_type const &key) const noexcept
Definition: federate_id.hpp:121
helics::interface_handle::operator==
bool operator==(interface_handle id) const noexcept
Definition: federate_id.hpp:75
helics::route_id
Definition: global_federate_id.hpp:171
helics::identififier_base_type
int32_t identififier_base_type
Definition: federate_id.hpp:15
helics::global_handle
Definition: global_federate_id.hpp:128
helics::direct_send_handle
constexpr interface_handle direct_send_handle
this special handle can be used to directly send a message in a core
Definition: federate_id.hpp:95
helics::local_federate_id::local_federate_id
constexpr local_federate_id(base_type val) noexcept
Definition: federate_id.hpp:28
std::hash< helics::local_federate_id >::result_type
hash< helics::local_federate_id::base_type >::result_type result_type
the type of the return result
Definition: federate_id.hpp:105
helics::interface_handle
Definition: federate_id.hpp:65
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::local_federate_id::isValid
bool isValid() const
Definition: federate_id.hpp:39
helics::local_federate_id::local_federate_id
constexpr local_federate_id()=default
helics::local_federate_id::operator!=
bool operator!=(local_federate_id id) const noexcept
Definition: federate_id.hpp:34
helics::local_federate_id::operator==
bool operator==(local_federate_id id) const noexcept
Definition: federate_id.hpp:32
helics::interface_handle::interface_handle
constexpr interface_handle()=default