helics  3.0.1
LocalFederateId.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 IdentifierBaseType = int32_t;
16 
23  public:
24  using BaseType = IdentifierBaseType;
26  constexpr LocalFederateId() = default;
28  constexpr explicit LocalFederateId(BaseType val) noexcept: fid(val) {}
30  constexpr BaseType baseValue() const { return fid; }
32  bool operator==(LocalFederateId id) const noexcept { return (fid == id.fid); }
34  bool operator!=(LocalFederateId id) const noexcept { return (fid != id.fid); }
36  bool operator<(LocalFederateId id) const noexcept { return (fid < id.fid); }
39  bool isValid() const { return (fid != invalid_fid); }
40 
41  private:
42  static constexpr BaseType invalid_fid{-2'000'000'000}; //!< defined invalid handle
43  BaseType 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, LocalFederateId fid);
50 
51 #endif
53 constexpr LocalFederateId gLocalCoreId(-259);
54 
55 namespace detail {
57  constexpr IdentifierBaseType gInvalidInterfaceHandle{-1'700'000'000};
58 } // namespace detail
59 
66  public:
67  using BaseType = IdentifierBaseType;
69  constexpr InterfaceHandle() = default;
70 
71  constexpr explicit InterfaceHandle(BaseType val) noexcept: hid(val) {}
73  constexpr BaseType baseValue() const { return hid; }
75  bool operator==(InterfaceHandle id) const noexcept { return (hid == id.hid); }
77  bool operator!=(InterfaceHandle id) const noexcept { return (hid != id.hid); }
79  bool operator<(InterfaceHandle id) const noexcept { return (hid < id.hid); }
80  bool operator>(InterfaceHandle id) const noexcept { return (hid > id.hid); }
81  bool isValid() const { return (hid != mInvalidHandle); }
83  BaseType* getBaseTypePointer() { return &hid; }
84 
85  private:
86  static constexpr BaseType mInvalidHandle{detail::gInvalidInterfaceHandle};
87  BaseType hid{mInvalidHandle};
88 };
89 
90 #if defined HELICS_STATIC_CORE_LIBRARY && !defined HELICS_SHARED_LIBRARY
91 
93 std::ostream& operator<<(std::ostream& os, InterfaceHandle handle);
94 #endif
95 
97  -1'745'234};
98 
99 } // namespace helics
100 
101 namespace std {
103 template<>
104 struct hash<helics::LocalFederateId> {
106  std::size_t operator()(helics::LocalFederateId const& key) const noexcept
107  {
108  return std::hash<helics::LocalFederateId::BaseType>{}(key.baseValue());
109  }
110 };
111 
114 template<>
115 struct hash<helics::InterfaceHandle> {
117  std::size_t operator()(helics::InterfaceHandle const& key) const noexcept
118  {
119  return std::hash<helics::InterfaceHandle::BaseType>{}(key.baseValue());
120  }
121 };
122 
123 } // namespace std
helics::LocalFederateId::isValid
bool isValid() const
Definition: LocalFederateId.hpp:39
helics::operator<<
std::ostream & operator<<(std::ostream &os, const ActionMessage &command)
Definition: ActionMessage.cpp:913
helics::InterfaceHandle::operator!=
bool operator!=(InterfaceHandle id) const noexcept
Definition: LocalFederateId.hpp:77
helics::LocalFederateId::operator!=
bool operator!=(LocalFederateId id) const noexcept
Definition: LocalFederateId.hpp:34
helics::InterfaceHandle::operator<
bool operator<(InterfaceHandle id) const noexcept
Definition: LocalFederateId.hpp:79
helics::LocalFederateId::operator==
bool operator==(LocalFederateId id) const noexcept
Definition: LocalFederateId.hpp:32
helics::LocalFederateId::baseValue
constexpr BaseType baseValue() const
Definition: LocalFederateId.hpp:30
helics::InterfaceHandle
Definition: LocalFederateId.hpp:65
helics::LocalFederateId::operator<
bool operator<(LocalFederateId id) const noexcept
Definition: LocalFederateId.hpp:36
helics::LocalFederateId::LocalFederateId
constexpr LocalFederateId()=default
helics::GlobalFederateId
Definition: GlobalFederateId.hpp:68
helics::InterfaceHandle::operator==
bool operator==(InterfaceHandle id) const noexcept
Definition: LocalFederateId.hpp:75
helics::route_id
Definition: GlobalFederateId.hpp:168
helics::IdentifierBaseType
int32_t IdentifierBaseType
Definition: LocalFederateId.hpp:15
helics::LocalFederateId::LocalFederateId
constexpr LocalFederateId(BaseType val) noexcept
Definition: LocalFederateId.hpp:28
helics::InterfaceHandle::getBaseTypePointer
BaseType * getBaseTypePointer()
Definition: LocalFederateId.hpp:83
helics::GlobalBrokerId
Definition: GlobalFederateId.hpp:26
std::hash< helics::InterfaceHandle >::operator()
std::size_t operator()(helics::InterfaceHandle const &key) const noexcept
Definition: LocalFederateId.hpp:117
helics::gDirectSendHandle
constexpr InterfaceHandle gDirectSendHandle
this special handle can be used to directly send a message in a core
Definition: LocalFederateId.hpp:96
helics::InterfaceHandle::baseValue
constexpr BaseType baseValue() const
Definition: LocalFederateId.hpp:73
std::hash< helics::LocalFederateId >::operator()
std::size_t operator()(helics::LocalFederateId const &key) const noexcept
Definition: LocalFederateId.hpp:106
helics
the main namespace for the helics co-simulation library User functions will be in the helics namespac...
Definition: AsyncFedCallInfo.hpp:14
helics::LocalFederateId
Definition: LocalFederateId.hpp:22
helics::GlobalHandle
Definition: GlobalFederateId.hpp:128
helics::InterfaceHandle::InterfaceHandle
constexpr InterfaceHandle()=default